Template Numerical Library version\ main:0c33d623
|
Solver of ODEs with the first order of accuracy. More...
#include <TNL/Solvers/ODE/StaticMerson.h>
Public Types | |
using | DofVectorType = VectorType |
Alias for type of unknown variable \( x \). | |
using | IndexType = int |
Type for indexing. | |
using | RealType = Real |
Type of floating-point arithemtics. | |
using | VectorType = Real |
Type of unknown variable \( x \). | |
![]() | |
using | IndexType = int |
Indexing type. | |
using | RealType = Real |
Type of the floating-point arithmetics or static vector. | |
Public Member Functions | |
__cuda_callable__ | StaticMerson ()=default |
Default constructor. | |
__cuda_callable__ const RealType & | getAdaptivity () const |
Getter of the parameter controlling the adaptive choice of the integration time step. | |
__cuda_callable__ void | setAdaptivity (const RealType &adaptivity) |
Setter of the parameter controlling the adaptive choice of the integration time step. | |
bool | setup (const Config::ParameterContainer ¶meters, const std::string &prefix="") |
Method for setup of the explicit solver based on configuration parameters. | |
template<typename RHSFunction , typename... Args> | |
__cuda_callable__ bool | solve (VectorType &u, RHSFunction &&f, Args... args) |
Solve ODE given by a lambda function. | |
template<typename RHSFunction , typename... Args> | |
bool __cuda_callable__ | solve (VectorType &u, RHSFunction &&rhsFunction, Args... args) |
![]() | |
__cuda_callable__ | StaticExplicitSolver ()=default |
Default constructor. | |
bool __cuda_callable__ | checkNextIteration () |
Checks if the solver is allowed to do the next iteration. | |
__cuda_callable__ const RealType & | getMaxTau () const |
Getter of maximal value of the time step. | |
__cuda_callable__ const RealType & | getStopTime () const |
Getter of the time where the evolution computation shall by stopped. | |
__cuda_callable__ const RealType & | getTau () const |
Getter of the time step used for the computation. | |
__cuda_callable__ const RealType & | getTime () const |
Getter of the current time of the evolution computed by the solver. | |
__cuda_callable__ void | setMaxTau (const RealType &maxTau) |
Setter of maximal value of the time step. | |
__cuda_callable__ void | setStopTime (const RealType &stopTime) |
Setter of the time where the evolution computation shall by stopped. | |
__cuda_callable__ void | setTau (const RealType &tau) |
Setter of the time step used for the computation. | |
__cuda_callable__ void | setTestingMode (bool testingMode) |
__cuda_callable__ void | setTime (const RealType &t) |
Settter of the current time of the evolution computed by the solver. | |
bool | setup (const Config::ParameterContainer ¶meters, const std::string &prefix="") |
Method for setup of the iterative solver based on configuration parameters. | |
![]() | |
__cuda_callable__ | StaticIterativeSolver ()=default |
Default constructor. | |
__cuda_callable__ bool | checkConvergence () |
Checks whether the convergence occurred already. | |
__cuda_callable__ bool | checkNextIteration () |
Checks if the solver is allowed to do the next iteration. | |
__cuda_callable__ const Real & | getConvergenceResidue () const |
Gets the the convergence threshold. | |
__cuda_callable__ const Real & | getDivergenceResidue () const |
Gets the limit for the divergence criterion. | |
__cuda_callable__ const Index & | getIterations () const |
Gets the number of iterations performed by the solver so far. | |
__cuda_callable__ const Index & | getMaxIterations () const |
Gets the maximal number of iterations the solver is allowed to perform. | |
__cuda_callable__ const Index & | getMinIterations () const |
Gets the minimal number of iterations the solver is supposed to do. | |
__cuda_callable__ const Real & | getResidue () const |
Gets the residue reached at the current iteration. | |
__cuda_callable__ bool | nextIteration () |
Proceeds to the next iteration. | |
__cuda_callable__ void | resetIterations () |
Sets the the number of the current iterations to zero. | |
__cuda_callable__ void | setConvergenceResidue (const Real &convergenceResidue) |
Sets the threshold for the convergence. | |
__cuda_callable__ void | setDivergenceResidue (const Real &divergenceResidue) |
Sets the residue limit for the divergence criterion. | |
__cuda_callable__ void | setMaxIterations (const Index &maxIterations) |
Sets the maximal number of iterations the solver is allowed to perform. | |
__cuda_callable__ void | setMinIterations (const Index &minIterations) |
Sets the minimal number of iterations the solver is supposed to do. | |
__cuda_callable__ void | setResidue (const Real &residue) |
Sets the residue reached at the current iteration. | |
bool | setup (const Config::ParameterContainer ¶meters, const std::string &prefix="") |
Method for setup of the iterative solver based on configuration parameters. | |
Static Public Member Functions | |
static void | configSetup (Config::ConfigDescription &config, const std::string &prefix="") |
Static method for setup of configuration parameters. | |
![]() | |
static void | configSetup (Config::ConfigDescription &config, const std::string &prefix="") |
This method defines configuration entries for setup of the iterative solver. | |
![]() | |
static void | configSetup (Config::ConfigDescription &config, const std::string &prefix="") |
This method defines configuration entries for setup of the iterative solver. | |
Protected Attributes | |
RealType | adaptivity = 0.00001 |
DofVectorType | k1 |
DofVectorType | k2 |
DofVectorType | k3 |
DofVectorType | k4 |
DofVectorType | k5 |
DofVectorType | kAux |
![]() | |
RealType | maxTau |
bool | stopOnSteadyState |
RealType | stopTime |
RealType | tau |
bool | testingMode |
RealType | time |
![]() | |
Real | convergenceResidue = 1e-6 |
Index | currentIteration = 0 |
Real | currentResidue = 0 |
Real | divergenceResidue = std::numeric_limits< Real >::max() |
Index | maxIterations = 1000000000 |
Index | minIterations = 0 |
Index | refreshRate = 1 |
Solver of ODEs with the first order of accuracy.
This solver is based on the Runge-Kutta-Merson method with adaptive choice of the integration time step for solving of ordinary differential equations having the following form:
\( \frac{d u}{dt} = f( t, u) \text{ on } (0,T) \)
\( u( 0 ) = u_{ini} \).
It is supposed to be used when the unknown \( x \in R \) is expressed by a scalar, i.e. by a numeric type like double
or float
.
For problems where \( \vec x\) is represented by TNL::Containers::StaticVector, see TNL::Solvers::ODE::StaticMerson<Containers::StaticVector<Size_,Real>>. For problems where \( \vec x\) is represented by TNL::Containers::Vector, or TNL::Containers::VectorView, see TNL::Solvers::ODE::Merson.
The following example demonstrates the use the solvers:
The result looks as follows:
Since this variant of the Euler solver is static, it can be used even inside of GPU kernels and so combined with TNL::Algorithms::parallelFor as demonstrated by the following example:
Real | is floating point number type, it is type of \( x \) in this case. |
|
static |
Static method for setup of configuration parameters.
config | is the config description. |
prefix | is the prefix of the configuration parameters for this solver. |
__cuda_callable__ const Real & TNL::Solvers::ODE::StaticMerson< Real >::getAdaptivity | ( | ) | const |
Getter of the parameter controlling the adaptive choice of the integration time step.
void __cuda_callable__ TNL::Solvers::ODE::StaticMerson< Real >::setAdaptivity | ( | const RealType & | adaptivity | ) |
Setter of the parameter controlling the adaptive choice of the integration time step.
The smaller the parammeter is the smaller the intergation time step tends to be. Reasonable values for this parameters are approximately from interval \( [10^{-12},10^{-2}] \).
adaptivity | new value of the parameter controlling the adaptive choice of integration time step. |
bool TNL::Solvers::ODE::StaticMerson< Real >::setup | ( | const Config::ParameterContainer & | parameters, |
const std::string & | prefix = "" |
||
) |
Method for setup of the explicit solver based on configuration parameters.
parameters | is the container for configuration parameters. |
prefix | is the prefix of the configuration parameters for this solver. |
__cuda_callable__ bool TNL::Solvers::ODE::StaticMerson< Real >::solve | ( | VectorType & | u, |
RHSFunction && | f, | ||
Args... | args | ||
) |
Solve ODE given by a lambda function.
RHSFunction | is type of a lambda function representing the right-hand side of the ODE system. The definition of the lambda function reads as: where t is the current time of the evolution, tau is the current time step, u is the solution at the current time, fu is variable/static vector into which the lambda function is suppsed to evaluate the function \( f(t, \vec x) \) at the current time \( t \). |
u | is a variable/static vector representing the solution of the ODE system at current time. |
f | is the lambda function representing the right-hand side of the ODE system. |
args | are user define arguments which are passed to the lambda function f . |
true
if steady state solution has been reached, false
otherwise.