Template Numerical Library version\ main:df396df
|
Base class for iterative solvers of systems of linear equations. More...
#include <TNL/Solvers/Linear/LinearSolver.h>
Public Types | |
using | ConstVectorViewType = typename Traits< Matrix >::ConstVectorViewType |
Type for constant vector view. | |
using | DeviceType = typename Matrix::DeviceType |
Device where the solver will run on and auxillary data will alloacted on. | |
using | IndexType = typename Matrix::IndexType |
Type for indexing. | |
using | MatrixPointer = std::shared_ptr< std::add_const_t< MatrixType > > |
Type of shared pointer to the matrix. | |
using | MatrixType = Matrix |
Type of the matrix representing the linear system. | |
using | PreconditionerPointer = std::shared_ptr< std::add_const_t< PreconditionerType > > |
Type of shared pointer to the preconditioner. | |
using | PreconditionerType = Preconditioners::Preconditioner< MatrixType > |
Type of preconditioner. | |
using | RealType = typename Matrix::RealType |
Floating point type used for computations. | |
using | VectorViewType = typename Traits< Matrix >::VectorViewType |
Type for vector view. | |
Public Types inherited from TNL::Solvers::IterativeSolver< Matrix::RealType, Matrix::IndexType > | |
using | SolverMonitorType |
Type of an object used for monitoring of the convergence. | |
Public Member Functions | |
virtual | ~LinearSolver () |
Default destructor. | |
void | setMatrix (const MatrixPointer &matrix) |
Set the matrix of the linear system. | |
void | setPreconditioner (const PreconditionerPointer &preconditioner) |
Set the preconditioner. | |
virtual bool | setup (const Config::ParameterContainer ¶meters, const String &prefix="") |
Method for setup of the linear iterative solver based on configuration parameters. | |
virtual bool | solve (ConstVectorViewType b, VectorViewType x)=0 |
Method for solving a linear system. | |
Public Member Functions inherited from TNL::Solvers::IterativeSolver< Matrix::RealType, Matrix::IndexType > | |
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 Matrix::RealType & | getConvergenceResidue () const |
Gets the the convergence threshold. | |
const Matrix::RealType & | getDivergenceResidue () const |
Gets the limit for the divergence criterion. | |
const Matrix::IndexType & | getIterations () const |
Gets the number of iterations performed by the solver so far. | |
const Matrix::IndexType & | getMaxIterations () const |
Gets the maximal number of iterations the solver is allowed to perform. | |
const Matrix::IndexType & | getMinIterations () const |
Gets the minimal number of iterations the solver is supposed to do. | |
const Matrix::RealType & | 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 Matrix::RealType &convergenceResidue) |
Sets the threshold for the convergence. | |
void | setDivergenceResidue (const Matrix::RealType &divergenceResidue) |
Sets the residue limit for the divergence criterion. | |
void | setMaxIterations (const Matrix::IndexType &maxIterations) |
Sets the maximal number of iterations the solver is allowed to perform. | |
void | setMinIterations (const Matrix::IndexType &minIterations) |
Sets the minimal number of iterations the solver is supposed to do. | |
void | setRefreshRate (const Matrix::IndexType &refreshRate) |
Sets the refresh rate (in milliseconds) for the solver monitor. | |
void | setResidue (const Matrix::RealType &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 String &prefix="") |
This method defines configuration entries for setup of the linear iterative solver. | |
Static Public Member Functions inherited from TNL::Solvers::IterativeSolver< Matrix::RealType, Matrix::IndexType > | |
static void | configSetup (Config::ConfigDescription &config, const std::string &prefix="") |
This method defines configuration entries for setup of the iterative solver. | |
Protected Attributes | |
MatrixPointer | matrix = nullptr |
PreconditionerPointer | preconditioner = nullptr |
Protected Attributes inherited from TNL::Solvers::IterativeSolver< Matrix::RealType, Matrix::IndexType > | |
Matrix::RealType | convergenceResidue |
Matrix::IndexType | currentIteration |
Matrix::RealType | currentResidue |
Matrix::RealType | divergenceResidue |
Matrix::IndexType | maxIterations |
Matrix::IndexType | minIterations |
Matrix::IndexType | refreshRate |
std::ofstream | residualHistoryFile |
std::string | residualHistoryFileName |
IterativeSolverMonitor< Matrix::RealType, Matrix::IndexType > * | solverMonitor |
Base class for iterative solvers of systems of linear equations.
To use the linear solver, one needs to first set the matrix of the linear system by means of the method LinearSolver::setMatrix. Afterward, one may call the method LinearSolver::solve which accepts the right-hand side vector b and a vector x to which the solution will be stored. One may also use appropriate preconditioner to speed-up the convergence - see the method LinearSolver::setPreconditioner.
Matrix | is type of matrix representing the linear system. |
The following example demonstrates the use iterative linear solvers:
The result looks as follows:
See also TNL::Solvers::IterativeSolverMonitor for monitoring of iterative solvers.
using TNL::Solvers::Linear::LinearSolver< Matrix >::DeviceType = typename Matrix::DeviceType |
Device where the solver will run on and auxillary data will alloacted on.
See Devices::Host or Devices::Cuda.
|
inlinestatic |
This method defines configuration entries for setup of the linear iterative solver.
See IterativeSolver::configSetup.
config | contains description of configuration parameters. |
prefix | is a prefix of particular configuration entries. |
|
inline |
Set the matrix of the linear system.
matrix | is a shared pointer to the matrix of the linear system |
|
inline |
Set the preconditioner.
preconditioner | is a shared pointer to preconditioner. |
|
inlinevirtual |
Method for setup of the linear iterative solver based on configuration parameters.
parameters | contains values of the define configuration entries. |
prefix | is a prefix of particular configuration entries. |
Reimplemented in TNL::Solvers::Linear::BICGStab< Matrix >, TNL::Solvers::Linear::BICGStabL< Matrix >, TNL::Solvers::Linear::GMRES< Matrix >, TNL::Solvers::Linear::IDRs< Matrix >, TNL::Solvers::Linear::Jacobi< Matrix >, and TNL::Solvers::Linear::SOR< Matrix >.
|
pure virtual |
Method for solving a linear system.
The linear system is defined by the matrix given by the method LinearSolver::setMatrix and by the right-hand side vector represented by the vector b. The result is stored in the vector b. The solver can be accelerated with appropriate preconditioner set by the methods LinearSolver::setPreconditioner.
b | vector with the right-hand side of the linear system. |
x | vector for the solution of the linear system. |
Implemented in TNL::Solvers::Linear::BICGStab< Matrix >, TNL::Solvers::Linear::BICGStabL< Matrix >, TNL::Solvers::Linear::CG< Matrix >, TNL::Solvers::Linear::GMRES< Matrix >, TNL::Solvers::Linear::IDRs< Matrix >, TNL::Solvers::Linear::Jacobi< Matrix >, TNL::Solvers::Linear::SOR< Matrix >, and TNL::Solvers::Linear::TFQMR< Matrix >.