Template Numerical Library version\ main:161afe73
Searching...
No Matches
TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor > Class Template Reference

Base class for iterative solvers. More...

#include <TNL/Solvers/IterativeSolver.h>

Inheritance diagram for TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >:
[legend]
Collaboration diagram for TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >:
[legend]

## Public Types

using SolverMonitorType = SolverMonitor
Type of an object used for monitoring of the convergence.

## Public Member Functions

IterativeSolver ()=default
Default constructor.

bool checkConvergence ()
Checks whether the convergence occurred already. More...

bool checkNextIteration ()
Checks if the solver is allowed to do the next iteration. More...

const RealgetConvergenceResidue () const
Gets the the convergence threshold. More...

const RealgetDivergenceResidue () const
Gets the limit for the divergence criterion. More...

const Index & getIterations () const
Gets the number of iterations performed by the solver so far. More...

const Index & getMaxIterations () const
Gets the maximal number of iterations the solver is allowed to perform. More...

const Index & getMinIterations () const
Gets the minimal number of iterations the solver is supposed to do. More...

const RealgetResidue () const
Gets the residue reached at the current iteration. More...

bool nextIteration ()
Proceeds to the next iteration. More...

void resetIterations ()
Sets the the number of the current iterations to zero.

void setConvergenceResidue (const Real &convergenceResidue)
Sets the threshold for the convergence. More...

void setDivergenceResidue (const Real &divergenceResidue)
Sets the residue limit for the divergence criterion. More...

void setMaxIterations (const Index &maxIterations)
Sets the maximal number of iterations the solver is allowed to perform. More...

void setMinIterations (const Index &minIterations)
Sets the minimal number of iterations the solver is supposed to do. More...

void setRefreshRate (const Index &refreshRate)
Sets the refresh rate (in milliseconds) for the solver monitor. More...

void setResidue (const Real &residue)
Sets the residue reached at the current iteration. More...

void setSolverMonitor (SolverMonitorType &solverMonitor)
Sets the solver monitor object. More...

bool setup (const Config::ParameterContainer &parameters, const String &prefix="")
Method for setup of the iterative solver based on configuration parameters. More...

## Static Public Member Functions

static void configSetup (Config::ConfigDescription &config, const String &prefix="")
This method defines configuration entries for setup of the iterative solver. More...

## 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

String residualHistoryFileName = ""

SolverMonitorsolverMonitor = nullptr

## Detailed Description

template<typename Real, typename Index, typename SolverMonitor = IterativeSolverMonitor< Real, Index >>
class TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >

Base class for iterative solvers.

Template Parameters
 Real is a floating point type used for computations. Index is an indexing type. IterativeSolverMonitor< Real, Index > is type of an object used for monitoring of the convergence.

## ◆ checkConvergence()

template<typename Real , typename Index , typename SolverMonitor >
 bool TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::checkConvergence

Checks whether the convergence occurred already.

Returns
true if the convergence already occured.
false if the convergence did not occur yet.

## ◆ checkNextIteration()

template<typename Real , typename Index , typename SolverMonitor >
 bool TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::checkNextIteration

Checks if the solver is allowed to do the next iteration.

Returns
true true if the solver is allowed to do the next iteration.
false if the solver is not allowed to do the next iteration. This may happen because the divergence occurred.

## ◆ configSetup()

template<typename Real , typename Index , typename SolverMonitor >
 void TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::configSetup ( Config::ConfigDescription & config, const String & prefix = "" )
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.

Parameters
 config contains description of configuration parameters. prefix is a prefix of particular configuration entries.

## ◆ getConvergenceResidue()

template<typename Real , typename Index , typename SolverMonitor >
 const Real & TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::getConvergenceResidue

Gets the the convergence threshold.

Returns
the convergence threshold.

## ◆ getDivergenceResidue()

template<typename Real , typename Index , typename SolverMonitor >
 const Real & TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::getDivergenceResidue

Gets the limit for the divergence criterion.

Returns
the residue limit fo the divergence.

## ◆ getIterations()

template<typename Real , typename Index , typename SolverMonitor >
 const Index & TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::getIterations

Gets the number of iterations performed by the solver so far.

Returns
number of iterations performed so far.

## ◆ getMaxIterations()

template<typename Real , typename Index , typename SolverMonitor >
 const Index & TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::getMaxIterations

Gets the maximal number of iterations the solver is allowed to perform.

Returns
maximal number of allowed iterations.

## ◆ getMinIterations()

template<typename Real , typename Index , typename SolverMonitor >
 const Index & TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::getMinIterations

Gets the minimal number of iterations the solver is supposed to do.

Returns
minimal number of iterations the solver is supposed to do.

## ◆ getResidue()

template<typename Real , typename Index , typename SolverMonitor >
 const Real & TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::getResidue

Gets the residue reached at the current iteration.

Returns
residue reached at the current iteration.

## ◆ nextIteration()

template<typename Real , typename Index , typename SolverMonitor >
 bool TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::nextIteration

Proceeds to the next iteration.

Returns
true if the solver is allowed to do the next iteration.
false if the solver is not allowed to do the next iteration. This may happen because the divergence occurred.

## ◆ setConvergenceResidue()

template<typename Real , typename Index , typename SolverMonitor >
 void TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::setConvergenceResidue ( const Real & convergenceResidue )

Sets the threshold for the convergence.

The convergence occurs when the residue drops bellow this limit.

Parameters
 convergenceResidue is threshold for the convergence.

## ◆ setDivergenceResidue()

template<typename Real , typename Index , typename SolverMonitor >
 void TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::setDivergenceResidue ( const Real & divergenceResidue )

Sets the residue limit for the divergence criterion.

The divergence occurs when the residue exceeds the limit.

Parameters
 divergenceResidue the residue limit of the divergence.

## ◆ setMaxIterations()

template<typename Real , typename Index , typename SolverMonitor >
 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.

Parameters
 maxIterations maximal number of allowed iterations.

## ◆ setMinIterations()

template<typename Real , typename Index , typename SolverMonitor >
 void TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::setMinIterations ( const Index & minIterations )

Sets the minimal number of iterations the solver is supposed to do.

Parameters
 minIterations minimal number of iterations the solver is supposed to do.

## ◆ setRefreshRate()

template<typename Real , typename Index , typename SolverMonitor >
 void TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::setRefreshRate ( const Index & refreshRate )

Sets the refresh rate (in milliseconds) for the solver monitor.

Parameters
 refreshRate of the solver monitor in milliseconds.

## ◆ setResidue()

template<typename Real , typename Index , typename SolverMonitor >
 void TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::setResidue ( const Real & residue )

Sets the residue reached at the current iteration.

Parameters
 residue reached at the current iteration.

## ◆ setSolverMonitor()

template<typename Real , typename Index , typename SolverMonitor >
 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.

Parameters
 solverMonitor is an object for monitoring the iterative solver.

## ◆ setup()

template<typename Real , typename Index , typename SolverMonitor >
 bool TNL::Solvers::IterativeSolver< Real, Index, SolverMonitor >::setup ( const Config::ParameterContainer & parameters, const String & prefix = "" )

Method for setup of the iterative solver based on configuration parameters.

Parameters
 parameters contains values of the define configuration entries. prefix is a prefix of particular configuration entries.

The documentation for this class was generated from the following files:
• src/TNL/Solvers/IterativeSolver.h
• src/TNL/Solvers/IterativeSolver.hpp