OGS 6.2.1-710-gde5194452.dirty.20191209112531
MathLib::ODE::ConcreteODESolver< Implementation, NumEquations > Class Template Referencefinal

Detailed Description

template<typename Implementation, unsigned NumEquations>
class MathLib::ODE::ConcreteODESolver< Implementation, NumEquations >

ODE solver with a bounds-safe interface using a concrete implementation.

This class makes contact between the abstract ODESolver interface and a certain solver Implementation.

The interface of this class inherits the array bounds checking from ODESolver. Its methods forward calls to the Implementation erasing array bounds info by passing std::array and Eigen::Matrix arguments as raw pointers.

Thus the Implementation does not need template to be templated which makes it possible for Implementation to use the pimpl idiom whereby the headers of external libraries only have to be included in the final cpp file. Thereby our namespaces do not get polluted with symbols from external libraries.

Template Parameters
NumEquationsthe number of equations in the ODE system.
Implementationa concrete ODE solver implementation used as a backend.

Definition at line 55 of file ConcreteODESolver.h.

#include <ConcreteODESolver.h>

Inheritance diagram for MathLib::ODE::ConcreteODESolver< Implementation, NumEquations >:
Collaboration diagram for MathLib::ODE::ConcreteODESolver< Implementation, NumEquations >:

Public Member Functions

void setFunction (Function< NumEquations > f, JacobianFunction< NumEquations > df) override
 
void setTolerance (const std::array< double, NumEquations > &abstol, const double reltol) override
 
void setTolerance (const double abstol, const double reltol) override
 
void setIC (const double t0, std::initializer_list< double > const &y0) override
 
void setIC (const double t0, Eigen::Matrix< double, NumEquations, 1, Eigen::ColMajor > const &y0) override
 
void preSolve () override
 
bool solve (const double t) override
 
MappedConstVector< NumEquations > getSolution () const override
 Returns the solution vector y. More...
 
double getTime () const override
 
Eigen::Matrix< double, NumEquations, 1, Eigen::ColMajor > getYDot (const double t, const MappedConstVector< NumEquations > &y) const override
 
- Public Member Functions inherited from MathLib::ODE::ODESolver< NumEquations >
virtual unsigned getNumberOfEquations () const
 Returns the number of equations. More...
 
virtual ~ODESolver ()=default
 

Private Member Functions

 ConcreteODESolver (BaseLib::ConfigTree const &config)
 Instances of this class shall only be constructed by createODESolver(). More...
 

Friends

std::unique_ptr< ODESolver< NumEquations > > createODESolver (BaseLib::ConfigTree const &config)
 

Constructor & Destructor Documentation

◆ ConcreteODESolver()

template<typename Implementation , unsigned NumEquations>
MathLib::ODE::ConcreteODESolver< Implementation, NumEquations >::ConcreteODESolver ( BaseLib::ConfigTree const &  config)
inlineexplicitprivate

Instances of this class shall only be constructed by createODESolver().

Definition at line 108 of file ConcreteODESolver.h.

109  : Implementation{config, NumEquations}
110  {
111  }

Member Function Documentation

◆ getSolution()

template<typename Implementation , unsigned NumEquations>
MappedConstVector<NumEquations> MathLib::ODE::ConcreteODESolver< Implementation, NumEquations >::getSolution ( ) const
inlineoverridevirtual

Returns the solution vector y.

Implements MathLib::ODE::ODESolver< NumEquations >.

Definition at line 93 of file ConcreteODESolver.h.

94  {
95  return MappedConstVector<NumEquations>{Implementation::getSolution()};
96  }

◆ getTime()

template<typename Implementation , unsigned NumEquations>
double MathLib::ODE::ConcreteODESolver< Implementation, NumEquations >::getTime ( ) const
inlineoverridevirtual

Returns the time that the solver has reached.

The return value should be equal to the time t passed to solve() if everything went fine.

Implements MathLib::ODE::ODESolver< NumEquations >.

Definition at line 97 of file ConcreteODESolver.h.

97 { return Implementation::getTime(); }

◆ getYDot()

template<typename Implementation , unsigned NumEquations>
Eigen::Matrix<double, NumEquations, 1, Eigen::ColMajor> MathLib::ODE::ConcreteODESolver< Implementation, NumEquations >::getYDot ( const double  t,
const MappedConstVector< NumEquations > &  y 
) const
inlineoverridevirtual

Computes $ \dot y = f(t,y) $.

This method is provided for convenience only.

Implements MathLib::ODE::ODESolver< NumEquations >.

Definition at line 98 of file ConcreteODESolver.h.

100  {
101  Eigen::Matrix<double, NumEquations, 1, Eigen::ColMajor> y_dot;
102  Implementation::getYDot(t, y.data(), y_dot.data());
103  return y_dot;
104  }

◆ preSolve()

template<typename Implementation , unsigned NumEquations>
void MathLib::ODE::ConcreteODESolver< Implementation, NumEquations >::preSolve ( )
inlineoverridevirtual

Finishes setting up the ODE solver, makes it ready to solve the provided ODE.

This method applies settings to the ODE solver, hence it has to be called after calling setters.

Note
preSolve() has to be called once before calling solve, it is not necessary to call it after each setter.

Implements MathLib::ODE::ODESolver< NumEquations >.

Definition at line 91 of file ConcreteODESolver.h.

91 { Implementation::preSolve(); }

◆ setFunction()

template<typename Implementation , unsigned NumEquations>
void MathLib::ODE::ConcreteODESolver< Implementation, NumEquations >::setFunction ( Function< NumEquations >  f,
JacobianFunction< NumEquations >  df 
)
inlineoverridevirtual

Sets functions that compute $\dot y$ and the Jacobian $\partial \dot y/\partial y$.

If no Jacobian function shall be set, nullptr can be passed fo df.

Remarks
solve() cannot be directly called after this method, rather preSolve() has to be called first!

Implements MathLib::ODE::ODESolver< NumEquations >.

Definition at line 59 of file ConcreteODESolver.h.

61  {
62  Implementation::setFunction(
63  std::make_unique<detail::FunctionHandlesImpl<NumEquations>>(f, df));
64  }

◆ setIC() [1/2]

template<typename Implementation , unsigned NumEquations>
void MathLib::ODE::ConcreteODESolver< Implementation, NumEquations >::setIC ( const double  t0,
std::initializer_list< double > const &  y0 
)
inlineoverridevirtual

Sets the conditions.

Parameters
t0initial time.
y0initial values.
Remarks
solve() cannot be directly called after this method, rather preSolve() has to be called first!

Implements MathLib::ODE::ODESolver< NumEquations >.

Definition at line 77 of file ConcreteODESolver.h.

79  {
80  assert(y0.size() == NumEquations);
81  Implementation::setIC(t0, y0.begin());
82  }

◆ setIC() [2/2]

template<typename Implementation , unsigned NumEquations>
void MathLib::ODE::ConcreteODESolver< Implementation, NumEquations >::setIC ( const double  t0,
Eigen::Matrix< double, NumEquations, 1, Eigen::ColMajor > const &  y0 
)
inlineoverridevirtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Implements MathLib::ODE::ODESolver< NumEquations >.

Definition at line 84 of file ConcreteODESolver.h.

87  {
88  Implementation::setIC(t0, y0.data());
89  }

◆ setTolerance() [1/2]

template<typename Implementation , unsigned NumEquations>
void MathLib::ODE::ConcreteODESolver< Implementation, NumEquations >::setTolerance ( const std::array< double, NumEquations > &  abstol,
const double  reltol 
)
inlineoverridevirtual

Sets the tolerances for the ODE solver.

Parameters
abstolabsolute tolerance, one value each equation.
reltolrelative tolerance.
Remarks
solve() cannot be directly called after this method, rather preSolve() has to be called first!

Implements MathLib::ODE::ODESolver< NumEquations >.

Definition at line 66 of file ConcreteODESolver.h.

68  {
69  Implementation::setTolerance(abstol.data(), reltol);
70  }

◆ setTolerance() [2/2]

template<typename Implementation , unsigned NumEquations>
void MathLib::ODE::ConcreteODESolver< Implementation, NumEquations >::setTolerance ( const double  abstol,
const double  reltol 
)
inlineoverridevirtual

Sets the tolerances for the ODE solver.

Parameters
abstolabsolute tolerance, one value for all equations.
reltolrelative tolerance.
Remarks
solve() cannot be directly called after this method, rather preSolve() has to be called first!

Implements MathLib::ODE::ODESolver< NumEquations >.

Definition at line 72 of file ConcreteODESolver.h.

73  {
74  Implementation::setTolerance(abstol, reltol);
75  }

◆ solve()

template<typename Implementation , unsigned NumEquations>
bool MathLib::ODE::ConcreteODESolver< Implementation, NumEquations >::solve ( const double  t)
inlineoverridevirtual

Solves the ODE from the set initial condition to time t.

Returns
true or false indicating whether solving succeeded.
Precondition
preSolve() has to be called before this method.

Implements MathLib::ODE::ODESolver< NumEquations >.

Definition at line 92 of file ConcreteODESolver.h.

92 { return Implementation::solve(t); }

Friends And Related Function Documentation

◆ createODESolver

template<typename Implementation , unsigned NumEquations>
std::unique_ptr<ODESolver<NumEquations> > createODESolver ( BaseLib::ConfigTree const &  config)
friend

Creates a new ODESolver instance from the given config.

Template Parameters
NumEquationsthe number of equations in the ODE system to be solved.

Definition at line 40 of file ODESolverBuilder.h.

42 {
43 #ifdef CVODE_FOUND
44  return std::unique_ptr<ODESolver<NumEquations>>(
45  new ConcreteODESolver<CVodeSolver, NumEquations>(config));
46 #endif
47  (void)config; // Unused parameter warning if no library is available.
48 
49  OGS_FATAL(
50  "No ODE solver could be created. Maybe it is because you did not build"
51  " OGS6 with support for any external ODE solver library.");
52 }
#define OGS_FATAL(fmt,...)
Definition: Error.h:64

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