Template Numerical Library version\ main:481315e2
|
Solver of ODEs with the first order of accuracy. More...
#include <TNL/Solvers/ODE/Merson.h>
Public Types | |
using | DeviceType = typename Vector::DeviceType |
Device where the solver is supposed to be executed. | |
using | DofVectorType = TNL::Containers::Vector< RealType, DeviceType, IndexType > |
Alias for type of unknown variable \( \vec x \). | |
using | IndexType = typename Vector::IndexType |
Type for indexing. | |
using | RealType = typename Vector::RealType |
Type of floating-point arithemtics. | |
using | SolverMonitorType = SolverMonitor |
Type of object used for monitoring the convergence. | |
using | VectorType = Vector |
Type of unknown variable \( \vec x \). | |
![]() | |
using | IndexType = Index |
Indexing type. | |
using | RealType = Real |
Type of the floating-point arithmetics. | |
using | SolverMonitorType = SolverMonitor |
Type of the monitor of the convergence of the solver. | |
![]() | |
using | SolverMonitorType = SolverMonitor |
Type of an object used for monitoring of the convergence. | |
Public Member Functions | |
Merson ()=default | |
Default constructor. | |
const RealType & | getAdaptivity () const |
Getter of the parameter controlling the adaptive choice of the integration time step. | |
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 > | |
bool | solve (VectorType &u, RHSFunction &&f) |
Solve ODE given by a lambda function. | |
void | writeGrids (const DofVectorType &u) |
![]() | |
ExplicitSolver ()=default | |
Default constructor. | |
bool | checkNextIteration () |
Checks if the solver is allowed to do the next iteration. | |
const RealType & | getMaxTau () const |
Getter of maximal value of the time step. | |
const RealType & | getStopTime () const |
Getter of the time where the evolution computation shall by stopped. | |
const RealType & | getTau () const |
Getter of the time step used for the computation. | |
const RealType & | getTime () const |
Getter of the current time of the evolution computed by the solver. | |
void | refreshSolverMonitor (bool force=false) |
This method refreshes the solver monitor. | |
void | setMaxTau (const RealType &maxTau) |
Setter of maximal value of the time step. | |
void | setStopTime (const RealType &stopTime) |
Setter of the time where the evolution computation shall by stopped. | |
void | setTau (const RealType &tau) |
Setter of the time step used for the computation. | |
void | setTestingMode (bool testingMode) |
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. | |
![]() | |
IterativeSolver ()=default | |
Default constructor. | |
bool | checkConvergence () |
Checks whether the convergence occurred already. | |
bool | checkNextIteration () |
Checks if the solver is allowed to do the next iteration. | |
const Real & | getConvergenceResidue () const |
Gets the the convergence threshold. | |
const Real & | getDivergenceResidue () const |
Gets the limit for the divergence criterion. | |
const Index & | getIterations () const |
Gets the number of iterations performed by the solver so far. | |
const Index & | getMaxIterations () const |
Gets the maximal number of iterations the solver is allowed to perform. | |
const Index & | getMinIterations () const |
Gets the minimal number of iterations the solver is supposed to do. | |
const Real & | getResidue () const |
Gets the residue reached at the current iteration. | |
bool | nextIteration () |
Proceeds to the next iteration. | |
void | resetIterations () |
Sets the the number of the current iterations to zero. | |
void | setConvergenceResidue (const Real &convergenceResidue) |
Sets the threshold for the convergence. | |
void | setDivergenceResidue (const Real &divergenceResidue) |
Sets the residue limit for the divergence criterion. | |
void | setMaxIterations (const Index &maxIterations) |
Sets the maximal number of iterations the solver is allowed to perform. | |
void | setMinIterations (const Index &minIterations) |
Sets the minimal number of iterations the solver is supposed to do. | |
void | setRefreshRate (const Index &refreshRate) |
Sets the refresh rate (in milliseconds) for the solver monitor. | |
void | setResidue (const Real &residue) |
Sets the residue reached at the current iteration. | |
void | setSolverMonitor (SolverMonitorType &solverMonitor) |
Sets the solver monitor object. | |
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 | |
DofVectorType | _k1 |
DofVectorType | _k2 |
DofVectorType | _k3 |
DofVectorType | _k4 |
DofVectorType | _k5 |
DofVectorType | _kAux |
RealType | adaptivity = 0.00001 |
![]() | |
RealType | maxTau = std::numeric_limits< RealType >::max() |
bool | stopOnSteadyState = false |
RealType | stopTime |
RealType | tau = 0.0 |
bool | testingMode = false |
RealType | time = 0.0 |
![]() | |
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 |
std::ofstream | residualHistoryFile |
std::string | residualHistoryFileName = "" |
SolverMonitor * | solverMonitor = nullptr |
Solver of ODEs with the first order of accuracy.
This solver is based on the Euler method for solving of ordinary differential equations having the following form:
\( \frac{d \vec u}{dt} = \vec f( t, \vec u) \text{ on } (0,T) \)
\( \vec u( 0 ) = \vec u_{ini} \). It is supposed to be used when the unknown \( \vec x \in R^n \) is expressed by a Containers::Vector.
For problems where \( \vec x\) is represented by TNL::Containers::StaticVector, see TNL::Solvers::ODE::StaticMerson<Containers::StaticVector<Size_,Real>>. For problems where \( x\) is represented by floating-point number, see TNL::Solvers::ODE::StaticMerson.
The following example demonstrates the use the solvers:
Vector | is type of vector storing \( \vec x \in R^n \), mostly TNL::Containers::Vector or TNL::Containers::VectorView. |
using TNL::Solvers::ODE::Merson< Vector, SolverMonitor >::DofVectorType = TNL::Containers::Vector< RealType, DeviceType, IndexType > |
Alias for type of unknown variable \( \vec x \).
Note, VectorType can be TNL::Containers::VectorView but DofVectorType is always TNL::Containers::Vector.
using TNL::Solvers::ODE::Merson< Vector, SolverMonitor >::SolverMonitorType = SolverMonitor |
Type of object used for monitoring the convergence.
|
static |
Static method for setup of configuration parameters.
config | is the config description. |
prefix | is the prefix of the configuration parameters for this solver. |
auto TNL::Solvers::ODE::Merson< Vector, SolverMonitor >::getAdaptivity | ( | ) | const |
Getter of the parameter controlling the adaptive choice of the integration time step.
void TNL::Solvers::ODE::Merson< Vector, SolverMonitor >::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::Merson< Vector, SolverMonitor >::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. |
bool TNL::Solvers::ODE::Merson< Vector, SolverMonitor >::solve | ( | VectorType & | u, |
RHSFunction && | f | ||
) |
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: Vector VectorType Type of unknown variable . Definition Merson.h:62 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. |
true
if steady state solution has been reached, false
otherwise.