CEPS  24.01
Cardiac ElectroPhysiology Simulator
AbstractOdeSolver Class Referenceabstract

Detailed Description

Solves ODE systems $y'=f(t,y)$.

For several numerical schemes, the evolution function is split between a linear and a non linear part.

\[ y'=f(t,y) = f_{NL}(t,y) + f_{L}(t,)y \]

Class usage:

1./ If used with "free" non-member functions (than can exist on their own), or static member functions:

mySolver = ceps::getNew<DerivatedFromAbstractOdeSolver>(...);
mySolver->setEvolutionFunction(myNonLinearPartFunction,myLinearPartFunction);
# or
mySolver->setEvolutionFunction(myNonLinearPartFunction);
mySolver->initialize(sizeOfInitialCondition,initialCondition);
for(CepsInt i=0; i<nSteps; i++,t+=dt)
mySolver->takeOneStep(t,dt);
CepsReal* sol = mySolver->getSolution();
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
int32_t CepsInt
Need 32 bit integer.
Definition: CepsTypes.hpp:106

2./ If used with AbstractIonicModel for cardiac problems, the solver is either for Gate or Misc variables, so the interaction with ionic model and the numerical scheme itself may change. This is why you need to select the right initialization method.

See also
ionicModelSolver

Definition at line 68 of file AbstractOdeSolver.hpp.

#include <AbstractOdeSolver.hpp>

Inheritance diagram for AbstractOdeSolver:
[legend]

Public Types

using RateFunction = ceps::Function< void(CepsReal, CepsReal *, CepsReal *, CepsUInt)>
 Typedef for function f(t,y) More...
 

Public Member Functions

 AbstractOdeSolver ()
 Constructor. More...
 
virtual ~AbstractOdeSolver ()
 Destructor. More...
 
virtual void initialize (CepsReal *y0, CepsUInt n, RateFunction *nonlinearFunc, RateFunction *linearFunc=nullptr, CepsBool copy=false)
 Allocate data arrays and sets initial condition with given data. More...
 
CepsUInt getNbMultiSteps () const
 Tells how many time steps the method covers. More...
 
CepsUInt getNbSubSteps () const
 Tells if several intermediate steps are needed to get to $y^{n+1}$. More...
 
CepsRealgetSolution () const
 Returns a pointer to the solution. Size is the same as y0 argument in initialize. More...
 
virtual void takeOneStep (CepsReal t, CepsReal dt)=0
 Make a full ode step : must be defined in every child class. More...
 
virtual void takeOneSubStep (CepsReal t, CepsReal dt)
 Progress by a substep, for RK methods. Does nothing by default. More...
 

Protected Member Functions

virtual void shiftDataArraysForNextStep ()
 Rotates the pointers on data such that yN becomes yN-1, etc... More...
 
void evaluateDerivative (CepsReal t, CepsReal *y, CepsReal *dty, CepsUInt n, CepsBool nLinPart=true)
 Selects and computes $f(t,y)$ depending on how it was passed to the class. More...
 
CepsReal phi1 (CepsReal x) const
 Function $\varphi_1$ used in exponential schemes. More...
 

Protected Attributes

CepsUInt m_ySize
 Function $\varphi_n$ used in exponential schemes. Return all phi_n until n, starting at phi0. More...
 
CepsRealm_yNp1
 Solution at time $t^{n+1}$. More...
 
CepsVector< CepsReal * > m_yNm
 Solution at time $t^n$ and before. More...
 
CepsUInt m_nbMultiSteps
 Number of steps for multi step solvers. More...
 
CepsUInt m_nbSubSteps
 Number of sub steps (eg RK solvers) More...
 
CepsUInt m_currentStep
 Ongoing step. More...
 
RateFunctionm_fL
 Linear function to call in evaluateDerivative. More...
 
RateFunctionm_fNL
 Non-linear function to call in evaluateDerivative. More...
 
CepsBool m_ownedSolData
 Flag for destructor. More...
 
CepsBool m_initialized
 Check at deallocation. More...
 

Member Typedef Documentation

◆ RateFunction

Typedef for function f(t,y)

Definition at line 74 of file AbstractOdeSolver.hpp.

Constructor & Destructor Documentation

◆ AbstractOdeSolver()

AbstractOdeSolver::AbstractOdeSolver ( )

Constructor.

Definition at line 32 of file AbstractOdeSolver.cpp.

◆ ~AbstractOdeSolver()

AbstractOdeSolver::~AbstractOdeSolver ( )
virtual

Destructor.

Definition at line 45 of file AbstractOdeSolver.cpp.

Member Function Documentation

◆ evaluateDerivative()

void AbstractOdeSolver::evaluateDerivative ( CepsReal  t,
CepsReal y,
CepsReal dty,
CepsUInt  n,
CepsBool  nLinPart = true 
)
protected

Selects and computes $f(t,y)$ depending on how it was passed to the class.

Either through classes like AbstractIonicModel, or manually via setEvolutionFunction(...)

Parameters
ttime t^n
yvalues at t^n
dtyresult array
nsize of arrays
nLinParttrue to compute the non-linear part of the evolution function, false for the linear part

Definition at line 136 of file AbstractOdeSolver.cpp.

◆ getNbMultiSteps()

CepsUInt AbstractOdeSolver::getNbMultiSteps ( ) const

Tells how many time steps the method covers.

Definition at line 98 of file AbstractOdeSolver.cpp.

◆ getNbSubSteps()

CepsUInt AbstractOdeSolver::getNbSubSteps ( ) const

Tells if several intermediate steps are needed to get to $y^{n+1}$.

Definition at line 104 of file AbstractOdeSolver.cpp.

◆ getSolution()

CepsReal * AbstractOdeSolver::getSolution ( ) const

Returns a pointer to the solution. Size is the same as y0 argument in initialize.

Definition at line 110 of file AbstractOdeSolver.cpp.

◆ initialize()

void AbstractOdeSolver::initialize ( CepsReal y0,
CepsUInt  n,
AbstractOdeSolver::RateFunction nonLinearFunc,
AbstractOdeSolver::RateFunction linearFunc = nullptr,
CepsBool  copy = false 
)
virtual

Allocate data arrays and sets initial condition with given data.

This method assumes a single step ODE solver, and should be overloaded for multi-step solvers.

Parameters
[in]y0initial data
[in]nallocation size for each array
[in]nonLinearFuncPointer to ceps::Function f'(t,y)
See also
MemberFunction
Parameters
[in]linearFuncPointer to ceps::Function f'(t,y)
See also
MemberFunction
Parameters
[in]copyif false, the array y0 will be used to store yn (thus overwritten) be careful with the delete statement! There will be arrays for times $t^n$ and $t^{n+1}$, and, if needed, other arrays for multi-step methods

Reimplemented in SBDFOdeSolver, RushLarsenOdeSolver, RungeKuttaOdeSolver, FBEOdeSolver, and ExponentialAdamsBashforthOdeSolver.

Definition at line 57 of file AbstractOdeSolver.cpp.

◆ phi1()

CepsReal AbstractOdeSolver::phi1 ( CepsReal  x) const
protected

Function $\varphi_1$ used in exponential schemes.

$\varphi_1(x) = \displaystyle\frac{\mathrm{e}^x-1}{x}$

Definition at line 152 of file AbstractOdeSolver.cpp.

◆ shiftDataArraysForNextStep()

void AbstractOdeSolver::shiftDataArraysForNextStep ( )
protectedvirtual

Rotates the pointers on data such that yN becomes yN-1, etc...

Reimplemented in ExponentialAdamsBashforthOdeSolver, SBDFOdeSolver, and RushLarsenOdeSolver.

Definition at line 124 of file AbstractOdeSolver.cpp.

◆ takeOneStep()

virtual void AbstractOdeSolver::takeOneStep ( CepsReal  t,
CepsReal  dt 
)
pure virtual

Make a full ode step : must be defined in every child class.

Parameters
[in]ttime $t^n$
[in]dtode time step

Implemented in SBDFOdeSolver, RushLarsenOdeSolver, RungeKuttaOdeSolver, FBEOdeSolver, and ExponentialAdamsBashforthOdeSolver.

◆ takeOneSubStep()

void AbstractOdeSolver::takeOneSubStep ( CepsReal  t,
CepsReal  dt 
)
virtual

Progress by a substep, for RK methods. Does nothing by default.

Reimplemented in RungeKuttaOdeSolver.

Definition at line 116 of file AbstractOdeSolver.cpp.

Field Documentation

◆ m_currentStep

CepsUInt AbstractOdeSolver::m_currentStep
protected

Ongoing step.

Definition at line 176 of file AbstractOdeSolver.hpp.

◆ m_fL

RateFunction* AbstractOdeSolver::m_fL
protected

Linear function to call in evaluateDerivative.

Definition at line 178 of file AbstractOdeSolver.hpp.

◆ m_fNL

RateFunction* AbstractOdeSolver::m_fNL
protected

Non-linear function to call in evaluateDerivative.

Definition at line 179 of file AbstractOdeSolver.hpp.

◆ m_initialized

CepsBool AbstractOdeSolver::m_initialized
protected

Check at deallocation.

Definition at line 182 of file AbstractOdeSolver.hpp.

◆ m_nbMultiSteps

CepsUInt AbstractOdeSolver::m_nbMultiSteps
protected

Number of steps for multi step solvers.

Definition at line 174 of file AbstractOdeSolver.hpp.

◆ m_nbSubSteps

CepsUInt AbstractOdeSolver::m_nbSubSteps
protected

Number of sub steps (eg RK solvers)

Definition at line 175 of file AbstractOdeSolver.hpp.

◆ m_ownedSolData

CepsBool AbstractOdeSolver::m_ownedSolData
protected

Flag for destructor.

Definition at line 181 of file AbstractOdeSolver.hpp.

◆ m_yNm

CepsVector<CepsReal*> AbstractOdeSolver::m_yNm
protected

Solution at time $t^n$ and before.

Definition at line 172 of file AbstractOdeSolver.hpp.

◆ m_yNp1

CepsReal* AbstractOdeSolver::m_yNp1
protected

Solution at time $t^{n+1}$.

Definition at line 171 of file AbstractOdeSolver.hpp.

◆ m_ySize

CepsUInt AbstractOdeSolver::m_ySize
protected

Function $\varphi_n$ used in exponential schemes. Return all phi_n until n, starting at phi0.

$\varphi_n(x) = \displaystyle\frac{\varphi_{n-1}(x)-1}{x}$ Size of solution vector

Definition at line 170 of file AbstractOdeSolver.hpp.


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