GEOSX
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
geosx::KrylovSolver< VECTOR > Class Template Referenceabstract

Base class for Krylov solvers. More...

#include <KrylovSolver.hpp>

Inheritance diagram for geosx::KrylovSolver< VECTOR >:
Inheritance graph
[legend]

Public Types

using Base = LinearOperator< VECTOR >
 Base type.
 
using Vector = typename Base::Vector
 Alias for template parameter.
 
- Public Types inherited from geosx::LinearOperator< VECTOR >
using Vector = VECTOR
 Alias for template parameter.
 

Public Member Functions

 KrylovSolver (LinearOperator< Vector > const &matrix, LinearOperator< Vector > const &precond, real64 const tolerance, localIndex const maxIterations, integer const verbosity)
 Constructor. More...
 
virtual ~KrylovSolver () override=default
 Virtual destructor.
 
virtual void solve (Vector const &b, Vector &x) const =0
 Solve preconditioned system. More...
 
virtual void apply (Vector const &src, Vector &dst) const override final
 Apply operator to a vector. More...
 
virtual globalIndex numGlobalRows () const override final
 Get the number of global rows. More...
 
virtual globalIndex numGlobalCols () const override final
 Get the number of global columns. More...
 
LinearSolverResult const & result () const
 Get result of a linear solve. More...
 
arrayView1d< real64 const > history () const
 Get convergence history of a linear solve. More...
 
integer getLogLevel () const
 Get log level. More...
 
virtual string methodName () const =0
 Get name of the Krylov subspace method. More...
 
- Public Member Functions inherited from geosx::LinearOperator< VECTOR >
 LinearOperator ()=default
 Constructor.
 
virtual ~LinearOperator ()=default
 Destructor.
 
virtual void apply (Vector const &src, Vector &dst) const =0
 Apply operator to a vector. More...
 
virtual void residual (Vector const &x, Vector const &b, Vector &r) const
 Compute residual r = Ax - b. More...
 

Static Public Member Functions

static std::unique_ptr< KrylovSolver< VECTOR > > Create (LinearSolverParameters const &parameters, LinearOperator< VECTOR > const &matrix, LinearOperator< VECTOR > const &precond)
 Factory method for instantiating Krylov solver objects. More...
 

Protected Types

using VectorTemp = typename VectorStorageHelper< VECTOR >::type
 Alias for vector type that can be used for temporaries.
 

Protected Member Functions

void logProgress (localIndex const iter, real64 const rnorm) const
 Output iteration progress (called by implementations). More...
 
void logResult () const
 Output convergence result (called by implementations).
 

Static Protected Member Functions

static VectorTemp createTempVector (Vector const &src)
 Helper function to create temporary vectors based on a source vector. More...
 

Protected Attributes

LinearOperator< Vector > const & m_operator
 reference to the operator to be solved
 
LinearOperator< Vector > const & m_precond
 reference to the preconditioning operator
 
real64 m_tolerance
 relative residual norm reduction tolerance
 
localIndex m_maxIterations
 maximum number of Krylov iterations
 
integer m_logLevel
 solver verbosity level
 
LinearSolverResult m_result
 results of a solve
 
array1d< real64m_residualNorms
 Absolute residual norms at each iteration (if available)
 

Detailed Description

template<typename VECTOR>
class geosx::KrylovSolver< VECTOR >

Base class for Krylov solvers.

Template Parameters
VECTORtype of vector handled by this solver

Definition at line 39 of file KrylovSolver.hpp.

Constructor & Destructor Documentation

◆ KrylovSolver()

template<typename VECTOR>
geosx::KrylovSolver< VECTOR >::KrylovSolver ( LinearOperator< Vector > const &  matrix,
LinearOperator< Vector > const &  precond,
real64 const  tolerance,
localIndex const  maxIterations,
integer const  verbosity 
)

Constructor.

Parameters
[in]matrixreference to the system matrix.
[in]precondreference to the preconditioning operator.
[in]tolerancerelative residual norm reduction tolerance.
[in]maxIterationsmaximum number of Krylov iterations.
[in]verbositysolver verbosity level.

Member Function Documentation

◆ apply()

template<typename VECTOR>
virtual void geosx::KrylovSolver< VECTOR >::apply ( Vector const &  src,
Vector dst 
) const
inlinefinaloverridevirtual

Apply operator to a vector.

Parameters
srcInput vector (src).
dstOutput vector (dst).

Definition at line 93 of file KrylovSolver.hpp.

◆ Create()

template<typename VECTOR>
static std::unique_ptr< KrylovSolver< VECTOR > > geosx::KrylovSolver< VECTOR >::Create ( LinearSolverParameters const &  parameters,
LinearOperator< VECTOR > const &  matrix,
LinearOperator< VECTOR > const &  precond 
)
static

Factory method for instantiating Krylov solver objects.

Parameters
parameterssolver parameters (only .solverType, .logLevel, .isSymmetric and .krylov fields are used)
matrixlinear operator to solve (can be a matrix or a matrix-free operator)
precondpreconditioning operator (must be set up by the user prior to calling solve()/apply())
Returns
an owning pointer to the newly instantiated solver

◆ createTempVector()

template<typename VECTOR>
static VectorTemp geosx::KrylovSolver< VECTOR >::createTempVector ( Vector const &  src)
inlinestaticprotected

Helper function to create temporary vectors based on a source vector.

Parameters
srcthe source vector, whose size and parallel distribution will be used
Returns
the new vector

The main purpose is to deal with BlockVector/View/Wrapper hierarchy.

Definition at line 188 of file KrylovSolver.hpp.

◆ getLogLevel()

template<typename VECTOR>
integer geosx::KrylovSolver< VECTOR >::getLogLevel ( ) const
inline

Get log level.

Returns
integer value of the log level

Definition at line 130 of file KrylovSolver.hpp.

◆ history()

template<typename VECTOR>
arrayView1d< real64 const > geosx::KrylovSolver< VECTOR >::history ( ) const
inline

Get convergence history of a linear solve.

Returns
array containing residual norms of every iteration (including initial)

Definition at line 121 of file KrylovSolver.hpp.

◆ logProgress()

template<typename VECTOR>
void geosx::KrylovSolver< VECTOR >::logProgress ( localIndex const  iter,
real64 const  rnorm 
) const
inlineprotected

Output iteration progress (called by implementations).

Parameters
itercurrent iteration number
rnormcurrent residual norm

Definition at line 198 of file KrylovSolver.hpp.

◆ methodName()

template<typename VECTOR>
virtual string geosx::KrylovSolver< VECTOR >::methodName ( ) const
pure virtual

Get name of the Krylov subspace method.

Returns
the abbreviated name of the method

Implemented in geosx::GMRESsolver< VECTOR >, geosx::BiCGSTABsolver< VECTOR >, and geosx::CGsolver< VECTOR >.

◆ numGlobalCols()

template<typename VECTOR>
virtual globalIndex geosx::KrylovSolver< VECTOR >::numGlobalCols ( ) const
inlinefinaloverridevirtual

Get the number of global columns.

Returns
Number of global columns in the operator.

Implements geosx::LinearOperator< VECTOR >.

Definition at line 103 of file KrylovSolver.hpp.

◆ numGlobalRows()

template<typename VECTOR>
virtual globalIndex geosx::KrylovSolver< VECTOR >::numGlobalRows ( ) const
inlinefinaloverridevirtual

Get the number of global rows.

Returns
Number of global rows in the operator.

Implements geosx::LinearOperator< VECTOR >.

Definition at line 98 of file KrylovSolver.hpp.

◆ result()

template<typename VECTOR>
LinearSolverResult const& geosx::KrylovSolver< VECTOR >::result ( ) const
inline

Get result of a linear solve.

Returns
struct containing status and various statistics of the last solve

Definition at line 112 of file KrylovSolver.hpp.

◆ solve()

template<typename VECTOR>
virtual void geosx::KrylovSolver< VECTOR >::solve ( Vector const &  b,
Vector x 
) const
pure virtual

Solve preconditioned system.

Parameters
[in]bsystem right hand side.
[in,out]xsystem solution (input = initial guess, output = solution).

The documentation for this class was generated from the following file: