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

Preconditioned conjugate gradient solver. More...

#include <AMReX_PCG.H>

Public Types

using RT = typename M::RT
 

Public Member Functions

 PCG ()=default
 
void define (M &linop)
 
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 setInitialGuessNonzero (bool flag)
 
void setVerbose (int v)
 Sets verbosity.
 
void setMaxIters (int niters)
 Sets the max number of iterations.
 
int getNumIters () const
 Gets the number of iterations.
 
int getStatus () const
 Gets the solver status.
 
RT getResidualNorm () const
 Gets the 2-norm of the residual.
 

Detailed Description

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

Preconditioned conjugate gradient solver.

Requires a symmetric positive definite operator and preconditioner. The operator type M must provide the same interface as for amrex::GMRES: makeVecRHS, makeVecLHS, norm2, dotProduct, assign, increment, linComb, scale, setToZero, apply and precond.

Member Typedef Documentation

◆ RT

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

Constructor & Destructor Documentation

◆ PCG()

template<typename V , typename M >
amrex::PCG< V, M >::PCG ( )
default

Member Function Documentation

◆ define()

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

Defines with a reference to M. It's the user's responsibility to keep the M object alive for PCG to be functional. This function must be called before solve() can be called.

◆ getNumIters()

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

Gets the number of iterations.

◆ getResidualNorm()

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

Gets the 2-norm of the residual.

◆ getStatus()

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

Gets the solver status.

0 converged, 1 max iterations reached, 2 p.Ap is zero or has changed sign (A not definite), 3 r.z is zero or has changed sign (preconditioner not definite). The sign is taken from the first r.z, so negative definite systems are solved as well. A NaN or infinity counts as the matching breakdown.

◆ setInitialGuessNonzero()

template<typename V , typename M >
void amrex::PCG< V, M >::setInitialGuessNonzero ( bool  flag)
inline

Use a_sol passed to solve() as the initial guess (default: false, i.e., start from zero).

◆ setMaxIters()

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

Sets the max number of iterations.

◆ setVerbose()

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

Sets verbosity.

◆ solve()

template<typename V , typename M >
void amrex::PCG< 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.

The initial guess is zero unless setInitialGuessNonzero(true) was called, in which case it is the value of a_sol on entry.

Parameters
a_solunknowns, i.e., x in A x = b.
a_rhsRHS, i.e., b in A x = b.
a_tol_relrelative tolerance, relative to the initial residual norm, which is ||b|| for a zero initial guess.
a_tol_absabsolute tolerance.
a_itsoptional argument specifying the maximum number of iterations.

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