|
Template Numerical Library version\ main:deb1488
|
Base class for iterative solvers. More...
#include <TNL/Solvers/IterativeSolver.h>
Public Types | |
| using | SolverMonitorType = SolverMonitor |
| Type of an object used for monitoring of the convergence. | |
Public Member Functions | |
| IterativeSolver ()=default | |
| Default constructor. | |
| virtual bool | checkConvergence () const |
| Checks whether the convergence occurred already. | |
| virtual bool | checkNextIteration () const |
| Checks if the solver is allowed to do the next iteration. | |
| const Real & | getConvergenceResidue () const |
| Gets the threshold for convergence based on residue. | |
| const Real & | getDivergenceResidue () const |
| Gets the threshold for divergence based on residue. | |
| 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. | |
| virtual 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 convergence based on residue. | |
| void | setDivergenceResidue (const Real &divergenceResidue) |
| Sets the threshold for divergence based on residue. | |
| 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="") |
| This method defines configuration entries for setup of the iterative solver. | |
Protected Attributes | |
| 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 |
Base class for iterative solvers.
| Real | is a floating point type used for computations. |
| Index | is an indexing type. |
| SolverMonitor | is type of an object used for monitoring of the convergence. |
|
nodiscardvirtual |
Checks whether the convergence occurred already.
If the convergence did not occur yet, a message is printed to the stderr output.
Reimplemented in TNL::Solvers::ODE::ExplicitSolver< Real, Index, SolverMonitor >, and TNL::Solvers::ODE::ExplicitSolver< Vector::RealType, Vector::IndexType, SolverMonitor >.
|
nodiscardvirtual |
Checks if the solver is allowed to do the next iteration.
Reimplemented in TNL::Solvers::ODE::ExplicitSolver< Real, Index, SolverMonitor >, and TNL::Solvers::ODE::ExplicitSolver< Vector::RealType, Vector::IndexType, SolverMonitor >.
|
static |
This method defines configuration entries for setup of the iterative solver.
The following entries are defined:
max-iterations - maximal number of iterations the solver may perform.
min-iterations - minimal number of iterations the solver must perform.
convergence-residue - convergence occurs when the residue drops bellow this limit.
divergence-residue - divergence occurs when the residue exceeds given limit.
refresh-rate - number of milliseconds between solver monitor refreshes.
residual-history-file - path to the file where the residual history will be saved.
| config | contains description of configuration parameters. |
| prefix | is a prefix of particular configuration entries. |
|
nodiscard |
Gets the threshold for convergence based on residue.
|
nodiscard |
Gets the threshold for divergence based on residue.
See setDivergenceResidue.
|
nodiscard |
Gets the number of iterations performed by the solver so far.
|
nodiscard |
Gets the maximal number of iterations the solver is allowed to perform.
See setMaxIterations.
|
nodiscard |
Gets the minimal number of iterations the solver is supposed to do.
|
nodiscard |
Gets the residue reached at the current iteration.
Note that the exact meaning of the value may be specific to the actual algorithm, but in general, the residue is used to check for the convergence and divergence.
|
virtual |
Proceeds to the next iteration.
Reimplemented in TNL::Solvers::ODE::ExplicitSolver< Real, Index, SolverMonitor >, and TNL::Solvers::ODE::ExplicitSolver< Vector::RealType, Vector::IndexType, SolverMonitor >.
| void TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::setConvergenceResidue | ( | const Real & | convergenceResidue | ) |
Sets the threshold for convergence based on residue.
The convergence occurs when the residue drops bellow this threshold.
| convergenceResidue | the threshold for convergence. |
| void TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::setDivergenceResidue | ( | const Real & | divergenceResidue | ) |
Sets the threshold for divergence based on residue.
The divergence occurs when the residue exceeds the threshold.
| divergenceResidue | the threshold for divergence. |
| void TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::setMaxIterations | ( | const Index & | maxIterations | ) |
Sets the maximal number of iterations the solver is allowed to perform.
If the number of iterations performed by the solver exceeds given limit, the divergence occurs.
| maxIterations | maximal number of allowed iterations. |
| void TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::setMinIterations | ( | const Index & | minIterations | ) |
Sets the minimal number of iterations the solver is supposed to do.
| minIterations | minimal number of iterations the solver is supposed to do. |
| void TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::setRefreshRate | ( | const Index & | refreshRate | ) |
Sets the refresh rate (in milliseconds) for the solver monitor.
| refreshRate | of the solver monitor in milliseconds. |
| void TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::setResidue | ( | const Real & | residue | ) |
Sets the residue reached at the current iteration.
This method is intended to be used from subclasses to report the current residue. The exact meaning of the value may be specific to the actual algorithm, but in general, the residue is used to check for the convergence and divergence.
| residue | reached at the current iteration. |
| void TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::setSolverMonitor | ( | SolverMonitorType & | solverMonitor | ) |
Sets the solver monitor object.
The solver monitor is an object for monitoring the status of the iterative solver. Usually it prints the number of iterations, current residue or elapsed time.
| solverMonitor | is an object for monitoring the iterative solver. |
| bool TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::setup | ( | const Config::ParameterContainer & | parameters, |
| const std::string & | prefix = "" ) |
Method for setup of the iterative solver based on configuration parameters.
| parameters | contains values of the define configuration entries. |
| prefix | is a prefix of particular configuration entries. |