libpspm
OdeSolver Class Reference

#include <ode_solver.h>

Public Member Functions

 OdeSolver (std::string method, double t_start, double rtol, double atol)
 
 ~OdeSolver ()
 
void reset (double t_start, double rtol, double atol)
 
template<class Functor , class AfterStep >
void step_to (double t_stop, double &t, std::vector< double > &y, Functor &derivs, AfterStep &after_step)
 
int get_fn_evals ()
 

Public Attributes

struct {
   double   abs_tol = 1e-8
 
   double   rel_tol = 1e-8
 
control
 

Private Attributes

SolverType type
 
void * solver = nullptr
 
int nfe_cumm = 0
 

Detailed Description

Definition at line 14 of file ode_solver.h.

Constructor & Destructor Documentation

◆ OdeSolver()

OdeSolver::OdeSolver ( std::string  method,
double  t_start,
double  rtol,
double  atol 
)
inline

Definition at line 27 of file ode_solver.h.

27  {
28  if (method == "rk45ck") type = ODE_RKCK45;
29  else if (method == "lsoda") type = ODE_LSODA;
30  else {
31  throw std::runtime_error("Fatal: Unknown ODE method " + method); //exit(1);
32  }
33  reset(t_start, rtol, atol);
34  }
void reset(double t_start, double rtol, double atol)
Definition: ode_solver.h:42
SolverType type
Definition: ode_solver.h:16
Here is the call graph for this function:

◆ ~OdeSolver()

OdeSolver::~OdeSolver ( )
inline

Definition at line 36 of file ode_solver.h.

36  {
37  if (type == ODE_RKCK45) delete static_cast<RKCK45*>(solver);
38  else if (type == ODE_LSODA) delete static_cast<LSODA*>(solver);
39  }
SolverType type
Definition: ode_solver.h:16
void * solver
Definition: ode_solver.h:17
Definition: rkck45.h:47
Definition: lsoda.h:38

Member Function Documentation

◆ get_fn_evals()

int OdeSolver::get_fn_evals ( )
inline

Definition at line 92 of file ode_solver.h.

92  {
93  if (type == ODE_RKCK45) return static_cast<RKCK45*>(solver)->get_fn_evals();
94  else if (type == ODE_LSODA) return nfe_cumm;
95  else return -1;
96  }
int get_fn_evals()
Definition: ode_solver.h:92
SolverType type
Definition: ode_solver.h:16
void * solver
Definition: ode_solver.h:17
Definition: rkck45.h:47
int nfe_cumm
Definition: ode_solver.h:18

◆ reset()

void OdeSolver::reset ( double  t_start,
double  rtol,
double  atol 
)
inline

Definition at line 42 of file ode_solver.h.

42  {
43  nfe_cumm = 0;
44  control.abs_tol = atol;
45  control.rel_tol = rtol;
46  if (type == ODE_RKCK45){
47  RKCK45* sol = static_cast<RKCK45*>(solver);
48  delete sol; sol = nullptr;
49  solver = new RKCK45(t_start, rtol, 1e-8);
50  }
51  else if (type == ODE_LSODA){
52  LSODA* sol = static_cast<LSODA*>(solver);
53  delete sol; sol = nullptr;
54  solver = new LSODA();
55  }
56  }
struct OdeSolver::@0 control
SolverType type
Definition: ode_solver.h:16
void * solver
Definition: ode_solver.h:17
Definition: rkck45.h:47
Definition: lsoda.h:38
int nfe_cumm
Definition: ode_solver.h:18
Here is the caller graph for this function:

◆ step_to()

template<class Functor , class AfterStep >
void OdeSolver::step_to ( double  t_stop,
double &  t,
std::vector< double > &  y,
Functor &  derivs,
AfterStep &  after_step 
)
inline

Definition at line 60 of file ode_solver.h.

60  {
61  if (t_stop == t || y.size() == 0) return;
62 
63  if (type == ODE_RKCK45){
64  RKCK45 * sol = static_cast<RKCK45*>(solver);
65  sol->Step_to(t_stop, t, y, derivs, after_step);
66  }
67  else if (type == ODE_LSODA ){
68  LSODA* sol = static_cast<LSODA*>(solver);
69  sol->set_istate(1); // forces re-initialization
70  sol->lsoda_update(derivs, after_step, y.size(), y, &t, t_stop, nullptr, control.rel_tol, control.abs_tol);
71  if(sol->get_istate() <= 0) {
72  std::cerr << "LSODA Error: istate = " << sol->get_istate() << std::endl;
73  return;
74  }
75  nfe_cumm += sol->get_fncalls();
76  }
77 
78  //else if (type == ODE_LSODA ){
81  //LSODA * sol = new LSODA();
82  //sol->lsoda_update(derivs, y.size(), y, &t, t_stop, nullptr, control.rel_tol, control.abs_tol);
83  //if(sol->get_istate() <= 0) {
84  //std::cerr << "LSODA Error: istate = " << sol->get_istate() << std::endl;
85  //return;
86  //}
87  //nfe_cumm += sol->get_fncalls();
88  //delete sol;
89  //}
90  }
int get_fncalls()
Definition: lsoda.cpp:848
void lsoda_update(Functor &derivs, AfterStep &after_step, const size_t neq, std::vector< double > &y, double *t, const double tout, void *const _data, double rtol=1e-6, double atol=1e-6)
Definition: lsoda.tpp:1257
struct OdeSolver::@0 control
void Step_to(double t_stop, double &x, container &y, functor &derivs, AfterStep &after_step)
Definition: rkck45.tpp:149
SolverType type
Definition: ode_solver.h:16
void * solver
Definition: ode_solver.h:17
Definition: rkck45.h:47
Definition: lsoda.h:38
int nfe_cumm
Definition: ode_solver.h:18
void set_istate(int n)
Definition: lsoda.cpp:857
int get_istate() const
Definition: lsoda.cpp:853
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ abs_tol

double OdeSolver::abs_tol = 1e-8

Definition at line 22 of file ode_solver.h.

◆ control

struct { ... } OdeSolver::control

◆ nfe_cumm

int OdeSolver::nfe_cumm = 0
private

Definition at line 18 of file ode_solver.h.

◆ rel_tol

double OdeSolver::rel_tol = 1e-8

Definition at line 23 of file ode_solver.h.

◆ solver

void* OdeSolver::solver = nullptr
private

Definition at line 17 of file ode_solver.h.

◆ type

SolverType OdeSolver::type
private

Definition at line 16 of file ode_solver.h.


The documentation for this class was generated from the following file: