Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
amrex::MLCGSolverT< MF > Class Template Reference

CG-family solvers (BiCGStab or CG) for use as the bottom solver in MLMG. More...

#include <AMReX_MLCGSolver.H>

Public Types

enum struct  Type { BiCGStab , CG }
 
using FAB = typename MLLinOpT< MF >::FAB
 
using RT = typename MLLinOpT< MF >::RT
 

Public Member Functions

 MLCGSolverT (MLLinOpT< MF > &_lp, Type _typ=Type::BiCGStab)
 Construct a solver bound to _lp.
 
 ~MLCGSolverT ()
 
 MLCGSolverT (const MLCGSolverT< MF > &rhs)=delete
 
 MLCGSolverT (MLCGSolverT< MF > &&rhs)=delete
 
MLCGSolverT< MF > & operator= (const MLCGSolverT< MF > &rhs)=delete
 
MLCGSolverT< MF > & operator= (MLCGSolverT< MF > &&rhs)=delete
 
void setSolver (Type _typ) noexcept
 Switch between BiCGStab and CG after construction.
 
int solve (MF &solnL, const MF &rhsL, RT eps_rel, RT eps_abs)
 Solve Lp(solnL)=rhsL to the requested tolerance.
 
void setVerbose (int _verbose)
 Control how much logging is emitted (0 = silent).
 
int getVerbose () const
 Current verbosity level.
 
void setMaxIter (int _maxiter)
 Cap the number of Krylov iterations performed.
 
int getMaxIter () const
 Current iteration cap.
 
void setPrintIdentation (std::string s)
 Prefix printed messages (e.g., to indent per level).
 
void setInitSolnZeroed (bool _sol_zeroed)
 
bool getInitSolnZeroed () const
 Whether setInitSolnZeroed(true) was requested.
 
void setNGhost (int _nghost)
 Set the number of grow cells used when allocating temporaries.
 
int getNGhost ()
 Current grow-cell count (same in every direction).
 
RT dotxy (const MF &r, const MF &z, bool local=false)
 Dot product helper; set local to true to skip the MPI reduction.
 
RT norm_inf (const MF &res, bool local=false)
 Infinity norm helper; set local to true to skip the MPI reduction.
 
int solve_bicgstab (MF &solnL, const MF &rhsL, RT eps_rel, RT eps_abs)
 Raw BiCGStab implementation mirroring the high-level solve() signature.
 
int solve_cg (MF &solnL, const MF &rhsL, RT eps_rel, RT eps_abs)
 Raw CG implementation mirroring the high-level solve() signature.
 
int getNumIters () const noexcept
 Iteration count from the last solve* call (or -1 if unused).
 

Detailed Description

template<typename MF>
class amrex::MLCGSolverT< MF >

CG-family solvers (BiCGStab or CG) for use as the bottom solver in MLMG.

Member Typedef Documentation

◆ FAB

template<typename MF >
using amrex::MLCGSolverT< MF >::FAB = typename MLLinOpT<MF>::FAB

◆ RT

template<typename MF >
using amrex::MLCGSolverT< MF >::RT = typename MLLinOpT<MF>::RT

Member Enumeration Documentation

◆ Type

template<typename MF >
enum struct amrex::MLCGSolverT::Type
strong
Enumerator
BiCGStab 
CG 

Constructor & Destructor Documentation

◆ MLCGSolverT() [1/3]

template<typename MF >
amrex::MLCGSolverT< MF >::MLCGSolverT ( MLLinOpT< MF > &  _lp,
Type  _typ = Type::BiCGStab 
)

Construct a solver bound to _lp.

Parameters
_lpLinear operator that supplies apply/normalization hooks.
_typSolver flavor (BiCGStab by default).

◆ ~MLCGSolverT()

template<typename MF >
amrex::MLCGSolverT< MF >::~MLCGSolverT ( )
default

◆ MLCGSolverT() [2/3]

template<typename MF >
amrex::MLCGSolverT< MF >::MLCGSolverT ( const MLCGSolverT< MF > &  rhs)
delete

◆ MLCGSolverT() [3/3]

template<typename MF >
amrex::MLCGSolverT< MF >::MLCGSolverT ( MLCGSolverT< MF > &&  rhs)
delete

Member Function Documentation

◆ dotxy()

template<typename MF >
auto amrex::MLCGSolverT< MF >::dotxy ( const MF &  r,
const MF &  z,
bool  local = false 
)

Dot product helper; set local to true to skip the MPI reduction.

Parameters
rFirst vector.
zSecond vector.
localTrue to limit the operation to local data only.
Returns
Dot product of r and z (globally reduced unless local is true).

◆ getInitSolnZeroed()

template<typename MF >
bool amrex::MLCGSolverT< MF >::getInitSolnZeroed ( ) const
inline

Whether setInitSolnZeroed(true) was requested.

◆ getMaxIter()

template<typename MF >
int amrex::MLCGSolverT< MF >::getMaxIter ( ) const
inline

Current iteration cap.

◆ getNGhost()

template<typename MF >
int amrex::MLCGSolverT< MF >::getNGhost ( )
inline

Current grow-cell count (same in every direction).

◆ getNumIters()

template<typename MF >
int amrex::MLCGSolverT< MF >::getNumIters ( ) const
inlinenoexcept

Iteration count from the last solve* call (or -1 if unused).

◆ getVerbose()

template<typename MF >
int amrex::MLCGSolverT< MF >::getVerbose ( ) const
inline

Current verbosity level.

◆ norm_inf()

template<typename MF >
auto amrex::MLCGSolverT< MF >::norm_inf ( const MF &  res,
bool  local = false 
)

Infinity norm helper; set local to true to skip the MPI reduction.

Parameters
resVector whose infinity norm is measured.
localTrue to limit the operation to local data only.
Returns
Infinity norm of res (globally reduced unless local is true).

◆ operator=() [1/2]

template<typename MF >
MLCGSolverT< MF > & amrex::MLCGSolverT< MF >::operator= ( const MLCGSolverT< MF > &  rhs)
delete

◆ operator=() [2/2]

template<typename MF >
MLCGSolverT< MF > & amrex::MLCGSolverT< MF >::operator= ( MLCGSolverT< MF > &&  rhs)
delete

◆ setInitSolnZeroed()

template<typename MF >
void amrex::MLCGSolverT< MF >::setInitSolnZeroed ( bool  _sol_zeroed)
inline

Is the initial guess provided to the solver zero? If so, set this to true so the solver can skip extra work. Default is false.

Parameters
_sol_zeroedTrue if the initial guess is zero everywhere.

◆ setMaxIter()

template<typename MF >
void amrex::MLCGSolverT< MF >::setMaxIter ( int  _maxiter)
inline

Cap the number of Krylov iterations performed.

Parameters
_maxiterMaximum number of BiCGStab/CG iterations.

◆ setNGhost()

template<typename MF >
void amrex::MLCGSolverT< MF >::setNGhost ( int  _nghost)
inline

Set the number of grow cells used when allocating temporaries.

Parameters
_nghostGrow-cell count applied uniformly in each direction.

◆ setPrintIdentation()

template<typename MF >
void amrex::MLCGSolverT< MF >::setPrintIdentation ( std::string  s)
inline

Prefix printed messages (e.g., to indent per level).

Parameters
sString inserted at the beginning of each log line.

◆ setSolver()

template<typename MF >
void amrex::MLCGSolverT< MF >::setSolver ( Type  _typ)
inlinenoexcept

Switch between BiCGStab and CG after construction.

Parameters
_typNew solver flavor.

◆ setVerbose()

template<typename MF >
void amrex::MLCGSolverT< MF >::setVerbose ( int  _verbose)
inline

Control how much logging is emitted (0 = silent).

Parameters
_verboseVerbosity level printed by the solver.

◆ solve()

template<typename MF >
int amrex::MLCGSolverT< MF >::solve ( MF &  solnL,
const MF &  rhsL,
RT  eps_rel,
RT  eps_abs 
)

Solve Lp(solnL)=rhsL to the requested tolerance.

Parameters
solnLOn input: initial guess; on output: solution.
rhsLRight-hand side.
eps_relRelative tolerance on the residual.
eps_absAbsolute tolerance on the residual.
Returns
0 success; 1 breakdown (BiCGStab: rho = 0; CG: rho = 0 or p^T q = 0); 2 BiCGStab only: rh^T v = 0; 3 BiCGStab only: t^T t = 0 in the omega update; 4 BiCGStab only: omega = 0; 8 non-convergence (iteration limit reached); 9 non-convergence but residual improved vs. the initial guess.

◆ solve_bicgstab()

template<typename MF >
int amrex::MLCGSolverT< MF >::solve_bicgstab ( MF &  solnL,
const MF &  rhsL,
RT  eps_rel,
RT  eps_abs 
)

Raw BiCGStab implementation mirroring the high-level solve() signature.

Parameters
solnLSolution vector (initial guess on input).
rhsLRight-hand side.
eps_relRelative residual tolerance.
eps_absAbsolute residual tolerance.
Returns
Same status codes as solve().

◆ solve_cg()

template<typename MF >
int amrex::MLCGSolverT< MF >::solve_cg ( MF &  solnL,
const MF &  rhsL,
RT  eps_rel,
RT  eps_abs 
)

Raw CG implementation mirroring the high-level solve() signature.

Parameters
solnLSolution vector (initial guess on input).
rhsLRight-hand side.
eps_relRelative residual tolerance.
eps_absAbsolute residual tolerance.
Returns
Same status codes as solve().

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