Template Numerical Library version\ main:481315e2
|
Solver of ODEs with the first order of accuracy. More...
#include <TNL/Solvers/ODE/StaticEuler.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__ | StaticEuler ()=default |
Default constructor. | |
__cuda_callable__ const RealType & | getCourantNumber () const |
Getter for the Courant number. | |
__cuda_callable__ void | setCourantNumber (const RealType &c) |
This method sets the Courant number in the CFL condition. | |
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. | |
![]() | |
__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 | courantNumber = 0.0 |
DofVectorType | k1 |
![]() | |
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 Euler method 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::StaticEuler<Containers::StaticVector<Size_,Real>>. For problems where \( \vec x\) is represented by TNL::Containers::Vector, or TNL::Containers::VectorView, see TNL::Solvers::ODE::Euler.
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__ auto TNL::Solvers::ODE::StaticEuler< Real >::getCourantNumber | ( | ) | const |
Getter for the Courant number.
__cuda_callable__ void TNL::Solvers::ODE::StaticEuler< Real >::setCourantNumber | ( | const RealType & | c | ) |
This method sets the Courant number in the CFL condition.
This method sets the constant \( C \) in the Courant–Friedrichs–Lewy condition. It means that
\[ \Delta t = \frac{C}{\| f( t,x )\|}, \]
.
if \( C > 0\). If \( C = 0 \) the time step stays fixed.
c | is the Courant number. |
bool TNL::Solvers::ODE::StaticEuler< 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::StaticEuler< 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.