MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
mfem::IterativeSolver Class Reference

Abstract base class for iterative solver. More...

#include <solvers.hpp>

Inheritance diagram for mfem::IterativeSolver:
[legend]
Collaboration diagram for mfem::IterativeSolver:
[legend]

Classes

struct  PrintLevel
 Settings for the output behavior of the IterativeSolver. More...
 

Public Member Functions

 IterativeSolver ()
 
 IterativeSolver (MPI_Comm comm_)
 
virtual void SetPreconditioner (Solver &pr)
 This should be called before SetOperator.
 
virtual void SetOperator (const Operator &op) override
 Also calls SetOperator for the preconditioner if there is one.
 
void SetMonitor (IterativeSolverMonitor &m)
 Set the iterative solver monitor.
 
MPI_Comm GetComm () const
 Return the associated MPI communicator, or MPI_COMM_NULL if no communicator is set.
 
Convergence

Termination criteria for the iterative solvers.

While the convergence criterion is solver specific, most of the provided iterative solvers use one of the following criteria

\( ||r||_X \leq tol_{rel}||r_0||_X \),

\( ||r||_X \leq tol_{abs} \),

\( ||r||_X \leq \max\{ tol_{abs}, tol_{rel} ||r_0||_X \} \),

where X denotes the space in which the norm is measured. The choice of X depends on the specific iterative solver.

void SetRelTol (real_t rtol)
 
void SetAbsTol (real_t atol)
 
void SetMaxIter (int max_it)
 
Reporting

These options control the internal reporting behavior into mfem::out and mfem::err of the iterative solvers.

virtual void SetPrintLevel (int print_lvl)
 Legacy method to set the level of verbosity of the solver output.
 
virtual void SetPrintLevel (PrintLevel)
 Set the level of verbosity of the solver output.
 
Solver statistics.

These are valid after the call to Mult().

int GetNumIterations () const
 Returns the number of iterations taken during the last call to Mult()
 
bool GetConverged () const
 Returns true if the last call to Mult() converged successfully.
 
real_t GetInitialNorm () const
 Returns the initial residual norm from the last call to Mult().
 
real_t GetFinalNorm () const
 Returns the final residual norm after termination of the solver during the last call to Mult().
 
real_t GetFinalRelNorm () const
 Returns the final residual norm after termination of the solver during the last call to Mult(), divided by the initial residual norm. Returns -1 if one of these norms is left undefined by the solver.
 
- Public Member Functions inherited from mfem::Solver
 Solver (int s=0, bool iter_mode=false)
 Initialize a square Solver with size s.
 
 Solver (int h, int w, bool iter_mode=false)
 Initialize a Solver with height h and width w.
 
- Public Member Functions inherited from mfem::Operator
void InitTVectors (const Operator *Po, const Operator *Ri, const Operator *Pi, Vector &x, Vector &b, Vector &X, Vector &B) const
 Initializes memory for true vectors of linear system.
 
 Operator (int s=0)
 Construct a square Operator with given size s (default 0).
 
 Operator (int h, int w)
 Construct an Operator with the given height (output size) and width (input size).
 
int Height () const
 Get the height (size of output) of the Operator. Synonym with NumRows().
 
int NumRows () const
 Get the number of rows (size of output) of the Operator. Synonym with Height().
 
int Width () const
 Get the width (size of input) of the Operator. Synonym with NumCols().
 
int NumCols () const
 Get the number of columns (size of input) of the Operator. Synonym with Width().
 
virtual MemoryClass GetMemoryClass () const
 Return the MemoryClass preferred by the Operator.
 
virtual void Mult (const Vector &x, Vector &y) const =0
 Operator application: y=A(x).
 
virtual void MultTranspose (const Vector &x, Vector &y) const
 Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an error.
 
virtual void AddMult (const Vector &x, Vector &y, const real_t a=1.0) const
 Operator application: y+=A(x) (default) or y+=a*A(x).
 
virtual void AddMultTranspose (const Vector &x, Vector &y, const real_t a=1.0) const
 Operator transpose application: y+=A^t(x) (default) or y+=a*A^t(x).
 
virtual void ArrayMult (const Array< const Vector * > &X, Array< Vector * > &Y) const
 Operator application on a matrix: Y=A(X).
 
virtual void ArrayMultTranspose (const Array< const Vector * > &X, Array< Vector * > &Y) const
 Action of the transpose operator on a matrix: Y=A^t(X).
 
virtual void ArrayAddMult (const Array< const Vector * > &X, Array< Vector * > &Y, const real_t a=1.0) const
 Operator application on a matrix: Y+=A(X) (default) or Y+=a*A(X).
 
virtual void ArrayAddMultTranspose (const Array< const Vector * > &X, Array< Vector * > &Y, const real_t a=1.0) const
 Operator transpose application on a matrix: Y+=A^t(X) (default) or Y+=a*A^t(X).
 
virtual OperatorGetGradient (const Vector &x) const
 Evaluate the gradient operator at the point x. The default behavior in class Operator is to generate an error.
 
virtual void AssembleDiagonal (Vector &diag) const
 Computes the diagonal entries into diag. Typically, this operation only makes sense for linear Operators. In some cases, only an approximation of the diagonal is computed.
 
virtual const OperatorGetProlongation () const
 Prolongation operator from linear algebra (linear system) vectors, to input vectors for the operator. NULL means identity.
 
virtual const OperatorGetRestriction () const
 Restriction operator from input vectors for the operator to linear algebra (linear system) vectors. NULL means identity.
 
virtual const OperatorGetOutputProlongation () const
 Prolongation operator from linear algebra (linear system) vectors, to output vectors for the operator. NULL means identity.
 
virtual const OperatorGetOutputRestrictionTranspose () const
 Transpose of GetOutputRestriction, directly available in this form to facilitate matrix-free RAP-type operators.
 
virtual const OperatorGetOutputRestriction () const
 Restriction operator from output vectors for the operator to linear algebra (linear system) vectors. NULL means identity.
 
void FormLinearSystem (const Array< int > &ess_tdof_list, Vector &x, Vector &b, Operator *&A, Vector &X, Vector &B, int copy_interior=0)
 Form a constrained linear system using a matrix-free approach.
 
void FormRectangularLinearSystem (const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, Vector &x, Vector &b, Operator *&A, Vector &X, Vector &B)
 Form a column-constrained linear system using a matrix-free approach.
 
virtual void RecoverFEMSolution (const Vector &X, const Vector &b, Vector &x)
 Reconstruct a solution vector x (e.g. a GridFunction) from the solution X of a constrained linear system obtained from Operator::FormLinearSystem() or Operator::FormRectangularLinearSystem().
 
void FormSystemOperator (const Array< int > &ess_tdof_list, Operator *&A)
 Return in A a parallel (on truedofs) version of this square operator.
 
void FormRectangularSystemOperator (const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, Operator *&A)
 Return in A a parallel (on truedofs) version of this rectangular operator (including constraints).
 
void FormDiscreteOperator (Operator *&A)
 Return in A a parallel (on truedofs) version of this rectangular operator.
 
void PrintMatlab (std::ostream &out, int n, int m=0) const
 Prints operator with input size n and output size m in Matlab format.
 
virtual void PrintMatlab (std::ostream &out) const
 Prints operator in Matlab format.
 
virtual ~Operator ()
 Virtual destructor.
 
Type GetType () const
 Return the type ID of the Operator class.
 

Protected Member Functions

virtual real_t Dot (const Vector &x, const Vector &y) const
 Return the standard (l2, i.e., Euclidean) inner product of x and y.
 
real_t Norm (const Vector &x) const
 Return the inner product norm of x, using the inner product defined by Dot()
 
void Monitor (int it, real_t norm, const Vector &r, const Vector &x, bool final=false) const
 Monitor both the residual r and the solution x.
 
- Protected Member Functions inherited from mfem::Operator
void FormConstrainedSystemOperator (const Array< int > &ess_tdof_list, ConstrainedOperator *&Aout)
 see FormSystemOperator()
 
void FormRectangularConstrainedSystemOperator (const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, RectangularConstrainedOperator *&Aout)
 see FormRectangularSystemOperator()
 
OperatorSetupRAP (const Operator *Pi, const Operator *Po)
 Returns RAP Operator of this, using input/output Prolongation matrices Pi corresponds to "P", Po corresponds to "Rt".
 

Protected Attributes

const Operatoroper
 
Solverprec
 
IterativeSolverMonitormonitor = nullptr
 
Convergence (protected attributes)
int max_iter
 Limit for the number of iterations the solver is allowed to do.
 
real_t rel_tol
 Relative tolerance.
 
real_t abs_tol
 Absolute tolerance.
 
Solver statistics (protected attributes)

Every IterativeSolver is expected to define these in its Mult() call.

int final_iter = -1
 
bool converged = false
 
real_t initial_norm = -1.0
 
real_t final_norm = -1.0
 
- Protected Attributes inherited from mfem::Operator
int height
 Dimension of the output / number of rows in the matrix.
 
int width
 Dimension of the input / number of columns in the matrix.
 

Reporting (protected attributes and member functions)

int print_level = -1
 (DEPRECATED) Legacy print level definition, which is left for compatibility with custom iterative solvers.
 
PrintLevel print_options
 Output behavior for the iterative solver.
 
PrintLevel FromLegacyPrintLevel (int)
 Convert a legacy print level integer to a PrintLevel object.
 
static int GuessLegacyPrintLevel (PrintLevel)
 Use some heuristics to guess a legacy print level corresponding to the given PrintLevel.
 

Additional Inherited Members

- Public Types inherited from mfem::Operator
enum  DiagonalPolicy { DIAG_ZERO , DIAG_ONE , DIAG_KEEP }
 Defines operator diagonal policy upon elimination of rows and/or columns. More...
 
enum  Type {
  ANY_TYPE , MFEM_SPARSEMAT , Hypre_ParCSR , PETSC_MATAIJ ,
  PETSC_MATIS , PETSC_MATSHELL , PETSC_MATNEST , PETSC_MATHYPRE ,
  PETSC_MATGENERIC , Complex_Operator , MFEM_ComplexSparseMat , Complex_Hypre_ParCSR ,
  Complex_DenseMat , MFEM_Block_Matrix , MFEM_Block_Operator
}
 Enumeration defining IDs for some classes derived from Operator. More...
 
- Public Attributes inherited from mfem::Solver
bool iterative_mode
 If true, use the second argument of Mult() as an initial guess.
 

Detailed Description

Abstract base class for iterative solver.

Definition at line 66 of file solvers.hpp.

Constructor & Destructor Documentation

◆ IterativeSolver() [1/2]

mfem::IterativeSolver::IterativeSolver ( )

Definition at line 28 of file solvers.cpp.

◆ IterativeSolver() [2/2]

mfem::IterativeSolver::IterativeSolver ( MPI_Comm comm_)

Definition at line 42 of file solvers.cpp.

Member Function Documentation

◆ Dot()

real_t mfem::IterativeSolver::Dot ( const Vector & x,
const Vector & y ) const
protectedvirtual

Return the standard (l2, i.e., Euclidean) inner product of x and y.

Overriding this method in a derived class enables a custom inner product.

Definition at line 55 of file solvers.cpp.

◆ FromLegacyPrintLevel()

IterativeSolver::PrintLevel mfem::IterativeSolver::FromLegacyPrintLevel ( int print_level_)
protected

Convert a legacy print level integer to a PrintLevel object.

Definition at line 114 of file solvers.cpp.

◆ GetComm()

MPI_Comm mfem::IterativeSolver::GetComm ( ) const
inline

Return the associated MPI communicator, or MPI_COMM_NULL if no communicator is set.

Definition at line 302 of file solvers.hpp.

◆ GetConverged()

bool mfem::IterativeSolver::GetConverged ( ) const
inline

Returns true if the last call to Mult() converged successfully.

Definition at line 262 of file solvers.hpp.

◆ GetFinalNorm()

real_t mfem::IterativeSolver::GetFinalNorm ( ) const
inline

Returns the final residual norm after termination of the solver during the last call to Mult().

This function returns the norm of the residual (or preconditioned residual, depending on the solver), corresponding to the returned solution.

Definition at line 275 of file solvers.hpp.

◆ GetFinalRelNorm()

real_t mfem::IterativeSolver::GetFinalRelNorm ( ) const
inline

Returns the final residual norm after termination of the solver during the last call to Mult(), divided by the initial residual norm. Returns -1 if one of these norms is left undefined by the solver.

See also
GetFinalNorm(), GetInitialNorm()

Definition at line 281 of file solvers.hpp.

◆ GetInitialNorm()

real_t mfem::IterativeSolver::GetInitialNorm ( ) const
inline

Returns the initial residual norm from the last call to Mult().

This function returns the norm of the residual (or preconditioned residual, depending on the solver), computed before the start of the iteration.

Definition at line 268 of file solvers.hpp.

◆ GetNumIterations()

int mfem::IterativeSolver::GetNumIterations ( ) const
inline

Returns the number of iterations taken during the last call to Mult()

Definition at line 260 of file solvers.hpp.

◆ GuessLegacyPrintLevel()

int mfem::IterativeSolver::GuessLegacyPrintLevel ( PrintLevel print_options_)
staticprotected

Use some heuristics to guess a legacy print level corresponding to the given PrintLevel.

Definition at line 149 of file solvers.cpp.

◆ Monitor()

void mfem::IterativeSolver::Monitor ( int it,
real_t norm,
const Vector & r,
const Vector & x,
bool final = false ) const
protected

Monitor both the residual r and the solution x.

Definition at line 190 of file solvers.cpp.

◆ Norm()

real_t mfem::IterativeSolver::Norm ( const Vector & x) const
inlineprotected

Return the inner product norm of x, using the inner product defined by Dot()

Definition at line 180 of file solvers.hpp.

◆ SetAbsTol()

void mfem::IterativeSolver::SetAbsTol ( real_t atol)
inline

Definition at line 210 of file solvers.hpp.

◆ SetMaxIter()

void mfem::IterativeSolver::SetMaxIter ( int max_it)
inline

Definition at line 211 of file solvers.hpp.

◆ SetMonitor()

void mfem::IterativeSolver::SetMonitor ( IterativeSolverMonitor & m)
inline

Set the iterative solver monitor.

Definition at line 296 of file solvers.hpp.

◆ SetOperator()

void mfem::IterativeSolver::SetOperator ( const Operator & op)
overridevirtual

◆ SetPreconditioner()

void mfem::IterativeSolver::SetPreconditioner ( Solver & pr)
virtual

◆ SetPrintLevel() [1/2]

void mfem::IterativeSolver::SetPrintLevel ( int print_lvl)
virtual

Legacy method to set the level of verbosity of the solver output.

This is the old way to control what information will be printed to mfem::out and mfem::err. The behavior for the print level for all iterative solvers is:

  • -1: Suppress all outputs.
  • 0: Print information about all detected issues (e.g. no convergence).
  • 1: Same as level 0, but with detailed information about each iteration.
  • 2: Print detected issues and a summary when the solver terminates.
  • 3: Same as 2, but print also the first and last iterations.
  • >3: Custom print options which are dependent on the specific solver.

In parallel, only rank 0 produces output.

Note
It is recommended to use SetPrintLevel(PrintLevel) instead.
Some derived classes, like KINSolver, redefine this method and use their own set of print level constants.

Reimplemented in mfem::KINSolver.

Definition at line 71 of file solvers.cpp.

◆ SetPrintLevel() [2/2]

void mfem::IterativeSolver::SetPrintLevel ( PrintLevel options)
virtual

Set the level of verbosity of the solver output.

In parallel, only rank 0 produces outputs. Errors are output to mfem::err and all other information to mfem::out.

Note
Not all subclasses of IterativeSolver support all possible options.
Some derived classes, like KINSolver, disable this method in favor of SetPrintLevel(int).
See also
PrintLevel for possible options.

Reimplemented in mfem::KINSolver.

Definition at line 92 of file solvers.cpp.

◆ SetRelTol()

void mfem::IterativeSolver::SetRelTol ( real_t rtol)
inline

Definition at line 209 of file solvers.hpp.

Member Data Documentation

◆ abs_tol

real_t mfem::IterativeSolver::abs_tol
protected

Absolute tolerance.

Definition at line 158 of file solvers.hpp.

◆ converged

bool mfem::IterativeSolver::converged = false
mutableprotected

Definition at line 167 of file solvers.hpp.

◆ final_iter

int mfem::IterativeSolver::final_iter = -1
mutableprotected

Definition at line 166 of file solvers.hpp.

◆ final_norm

real_t mfem::IterativeSolver::final_norm = -1.0
protected

Definition at line 168 of file solvers.hpp.

◆ initial_norm

real_t mfem::IterativeSolver::initial_norm = -1.0
mutableprotected

Definition at line 168 of file solvers.hpp.

◆ max_iter

int mfem::IterativeSolver::max_iter
protected

Limit for the number of iterations the solver is allowed to do.

Definition at line 152 of file solvers.hpp.

◆ monitor

IterativeSolverMonitor* mfem::IterativeSolver::monitor = nullptr
protected

Definition at line 123 of file solvers.hpp.

◆ oper

const Operator* mfem::IterativeSolver::oper
protected

Definition at line 121 of file solvers.hpp.

◆ prec

Solver* mfem::IterativeSolver::prec
protected

Definition at line 122 of file solvers.hpp.

◆ print_level

int mfem::IterativeSolver::print_level = -1
protected

(DEPRECATED) Legacy print level definition, which is left for compatibility with custom iterative solvers.

Deprecated
print_options should be used instead.

Definition at line 131 of file solvers.hpp.

◆ print_options

PrintLevel mfem::IterativeSolver::print_options
protected

Output behavior for the iterative solver.

This primarily controls the output behavior of the iterative solvers provided by this library. This member must be synchronized with print_level to ensure compatibility with custom iterative solvers.

Definition at line 138 of file solvers.hpp.

◆ rel_tol

real_t mfem::IterativeSolver::rel_tol
protected

Relative tolerance.

Definition at line 155 of file solvers.hpp.


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