Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
amrex::GMRES< V, M > Class Template Reference

GMRES. More...

#include <AMReX_GMRES.H>

Public Types

using RT = typename M::RT
 

Public Member Functions

 GMRES ()
 Construct a GMRES solver with the default restart length.
 
void define (M &linop)
 Bind the solver to a linear operator.
 
void solve (V &a_sol, V const &a_rhs, RT a_tol_rel, RT a_tol_abs, int a_its=-1)
 Solve the linear system.
 
void setVerbose (int v)
 Set verbosity level v (0 = silent).
 
void setRestartLength (int rl)
 Set the Krylov restart length.
 
void setMaxIters (int niters)
 Cap the number of iterations performed by solve().
 
int getNumIters () const
 Number of iterations executed by the last solve().
 
int getStatus () const
 Status flag from the last solve() (0 success, >0 failure).
 
RT getResidualNorm () const
 Final residual 2-norm from the last solve().
 

Detailed Description

template<typename V, typename M>
class amrex::GMRES< V, M >

GMRES.

This class implements the GMRES algorithm. The template parameter V is for a linear algebra vector class. For example, it could be amrex::MultiFab. The other template parameter M is for a linear operator class with a number of required member functions. Note that conceptually M contains a matrix. However, it does not mean it needs to have a member variable storing the matrix, because GMRES only needs the matrix vector product, not the matrix itself.

Template Parameters
Vlinear algebra vector. It must be default constructible, move constructible, and move assignable.
Mlinear operator. A list of required member functions for M is shown below. Here RT (typename M::RT) is either double or float. Examples of implementation for V being a single-component MultiFab are also given below.
  • void apply(V& Ax, V const& x)
    Ax = A(x), where A is the linear operator performing matrix vector product. Here x is made with the makeVecLHS function. Therefore, it may have ghost cells and it's safe to cast it with const_cast<V&>(x) and do ghost cell exchange, if necessary.
  • void assign(V& lhs, V const& rhs)
    lhs = rhs. For example, MultiFab::Copy(lhs,rhs,0,0,1,0).
  • RT dotProduct(V const& v1, V const& v2)
    returns v1 * v2. For example, MultiFab::Dot(v1,0,v2,0,1,0).
  • void increment(V& lhs, V const& rhs, RT a)
    lhs += a * rhs. For example, MultiFab::Saxpy(lhs,a,rhs,0,0,1,0).
  • void linComb(V& lhs, RT a, V const& rhs_a, RT b, V const& rhs_b)
    lhs = a * rhs_a + b * rhs_b. For example, MultiFab::LinComb(lhs,a,rhs_a,0,b,rhs_b,0,0,1,0).
  • V makeVecRHS()
    returns a V object that is suitable as RHS in M x = b. The reason we distinguish between LHS and RHS is M might need the distinction for efficiency. For example, if V is MultiFab, we might need the x in the LHS of M x = b to have ghost cells for efficiency, whereas no ghost cells are needed for the RHS (i.e., b). An example of the implementation might be return MultiFab(grids,dmap,1,0).
  • V makeVecLHS()
    returns a V object that is suitable as LHS in M x = b. See the description for makeVecRHS for more details. An example of the implementation might be return MultiFab(grids,dmap,1,1).
  • RT norm2(V const& v)
    returns the 2-norm of v. For example, return v.norm2().
  • void precond(V& lhs, V const& rhs)
    applies right-preconditioning, i.e., solve P(lhs) = rhs, where P is an approximation to A If there is no preconditioner, P = I and thus this function should do lhs = rhs.
  • void scale(V& v, RT fac)
    scales v by fac. For example, v.mult(fac).
  • void setToZero(V& v)
    v = 0. For example, v.setVal(0).

Member Typedef Documentation

◆ RT

template<typename V , typename M >
using amrex::GMRES< V, M >::RT = typename M::RT

Constructor & Destructor Documentation

◆ GMRES()

template<typename V , typename M >
amrex::GMRES< V, M >::GMRES ( )

Construct a GMRES solver with the default restart length.

Member Function Documentation

◆ define()

template<typename V , typename M >
void amrex::GMRES< V, M >::define ( M &  linop)

Bind the solver to a linear operator.

It's the caller's responsibility to keep linop alive for as long as the solver is in use. Call this before solve().

Parameters
linopLinear operator providing the required GMRES hooks.

◆ getNumIters()

template<typename V , typename M >
int amrex::GMRES< V, M >::getNumIters ( ) const
inline

Number of iterations executed by the last solve().

◆ getResidualNorm()

template<typename V , typename M >
RT amrex::GMRES< V, M >::getResidualNorm ( ) const
inline

Final residual 2-norm from the last solve().

◆ getStatus()

template<typename V , typename M >
int amrex::GMRES< V, M >::getStatus ( ) const
inline

Status flag from the last solve() (0 success, >0 failure).

◆ setMaxIters()

template<typename V , typename M >
void amrex::GMRES< V, M >::setMaxIters ( int  niters)
inline

Cap the number of iterations performed by solve().

Parameters
nitersMaximum iterations; negative preserves the previous limit.

◆ setRestartLength()

template<typename V , typename M >
void amrex::GMRES< V, M >::setRestartLength ( int  rl)

Set the Krylov restart length.

Parameters
rlNumber of Krylov vectors retained between restarts.

◆ setVerbose()

template<typename V , typename M >
void amrex::GMRES< V, M >::setVerbose ( int  v)
inline

Set verbosity level v (0 = silent).

◆ solve()

template<typename V , typename M >
void amrex::GMRES< V, M >::solve ( V &  a_sol,
V const &  a_rhs,
RT  a_tol_rel,
RT  a_tol_abs,
int  a_its = -1 
)

Solve the linear system.

Parameters
a_solunknowns, i.e., x in A x = b.
a_rhsRHS, i.e., b in A x = b.
a_tol_relrelative tolerance.
a_tol_absabsolute tolerance.
a_itsoptional argument specifying the maximum number of iterations.

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