Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
vulpes::la::LinearSolver Class Reference

A linear solver class wrapping PETSc KSP solvers. More...

#include <linear_solver.hpp>

Public Types

enum  Type {
  CG , GMRES , BiCGStab , MINRES ,
  PrecondOnly
}
 Enumeration of available solver types. More...
enum  PrecondType {
  NoPrecond , Jacobi , SOR , ASM ,
  BlockJacobi , BoomerAMG , EuclidILU , LU ,
  Cholesky , SuperLU , MUMPS , GAMG
}
 Enumeration of available preconditioner types. More...

Public Member Functions

 LinearSolver (Type solver_type=CG, PrecondType pc_type=Jacobi)
 Construct a LinearSolver with specified solver and preconditioner types.
 LinearSolver (const LinearSolver &)=delete
LinearSolver & operator= (const LinearSolver &)=delete
void setType (Type solver_type)
 Set the type of the linear solver.
void setPreconditioner (PrecondType pc_type)
 Set the type of the preconditioner.
void setTolerances (PetscReal rtol, PetscReal abstol, PetscReal dtol, PetscInt maxits)
 Set the solver tolerances.
void setRelativeTolerance (PetscReal rtol)
 Set the relative tolerance.
void setAbsoluteTolerance (PetscReal abstol)
 Set the absolute tolerance.
void setMaxIterations (PetscInt maxits)
 Set the maximum iterations.
void setInitialGuessNonzero (bool nonzero)
 Set the initial guess to nonzero.
void setGMRESRestart (PetscInt restart)
 Set the GMRES restart parameter.
void setSORParameters (PetscReal omega, PetscInt iterations=1, PetscReal rtol=0.0)
 Set the SOR parameters.
void setOptionsBoomerAMG (DataBoomerAMG data)
 Set options for the BoomerAMG preconditioner.
void setOptionsGAMG (const DataGAMG &data)
 Set options for the GAMG preconditioner.
void setOperators (const SparseMatrix &A)
 Set the system matrix.
void setOperators (const SparseMatrix &A, const SparseMatrix &P)
 Set the system matrix and preconditioner matrix.
void solve (const Vector &b, Vector &x)
 Solve the linear system Ax = b.
void applyPreconditioner (const Vector &b, Vector &x)
 Apply the preconditioner only, x = P^{-1} b: the result of solve() for type PrecondOnly, without its collective convergence check. Aborts if this rank's preconditioner failed (e.g. a zero pivot).
PetscInt getIterationCount ()
 Get the number of iterations taken by the solver.
void setNormType (KSPNormType type)
 Set the norm type for convergence testing.
PetscReal getResidualNorm ()
 Get the residual norm after the solve.
KSPConvergedReason getConvergenceReason ()
 Get the convergence reason.
PC getPC ()
 Get the preconditioner.
const auto & getKSP () const
 Get the KSP object.
void printConvergenceInfo ()
 Print convergence information.
 ~LinearSolver ()

Protected Member Functions

void init (Type solver_type=CG, PrecondType pc_type=Jacobi)
void setUp ()
 Set up the KSP, applying the solver specific level smoother.

Protected Attributes

KSP m_ksp
bool m_point_block_smoother = false
 Use point-block Jacobi on the GAMG levels, see DataGAMG.

Detailed Description

A linear solver class wrapping PETSc KSP solvers.

This class provides an interface to set up and solve linear systems using various Krylov subspace methods and preconditioners available in PETSc. Default tolerances: relative 1e-8, absolute 1e-10, at most 1000 iterations. KSPSetFromOptions is not called, so -ksp_* command-line options are ignored.

Member Enumeration Documentation

◆ PrecondType

Enumeration of available preconditioner types.

Enumerator
NoPrecond 
Jacobi 
SOR 
ASM 
BlockJacobi 
BoomerAMG 
EuclidILU 
LU 
Cholesky 
SuperLU 
MUMPS 
GAMG 

◆ Type

Enumeration of available solver types.

Enumerator
CG 
GMRES 
BiCGStab 
MINRES 
PrecondOnly 

Constructor & Destructor Documentation

◆ LinearSolver() [1/2]

vulpes::la::LinearSolver::LinearSolver ( Type solver_type = CG,
PrecondType pc_type = Jacobi )
explicit

Construct a LinearSolver with specified solver and preconditioner types.

Parameters
solver_typeThe type of the linear solver
pc_typeThe type of the preconditioner

◆ LinearSolver() [2/2]

vulpes::la::LinearSolver::LinearSolver ( const LinearSolver & )
delete

◆ ~LinearSolver()

vulpes::la::LinearSolver::~LinearSolver ( )

Member Function Documentation

◆ applyPreconditioner()

void vulpes::la::LinearSolver::applyPreconditioner ( const Vector & b,
Vector & x )

Apply the preconditioner only, x = P^{-1} b: the result of solve() for type PrecondOnly, without its collective convergence check. Aborts if this rank's preconditioner failed (e.g. a zero pivot).

◆ getConvergenceReason()

KSPConvergedReason vulpes::la::LinearSolver::getConvergenceReason ( )

Get the convergence reason.

◆ getIterationCount()

PetscInt vulpes::la::LinearSolver::getIterationCount ( )

Get the number of iterations taken by the solver.

◆ getKSP()

const auto & vulpes::la::LinearSolver::getKSP ( ) const
inline

Get the KSP object.

◆ getPC()

PC vulpes::la::LinearSolver::getPC ( )

Get the preconditioner.

◆ getResidualNorm()

PetscReal vulpes::la::LinearSolver::getResidualNorm ( )

Get the residual norm after the solve.

◆ init()

void vulpes::la::LinearSolver::init ( Type solver_type = CG,
PrecondType pc_type = Jacobi )
protected

◆ operator=()

LinearSolver & vulpes::la::LinearSolver::operator= ( const LinearSolver & )
delete

◆ printConvergenceInfo()

void vulpes::la::LinearSolver::printConvergenceInfo ( )

Print convergence information.

◆ setAbsoluteTolerance()

void vulpes::la::LinearSolver::setAbsoluteTolerance ( PetscReal abstol)

Set the absolute tolerance.

◆ setGMRESRestart()

void vulpes::la::LinearSolver::setGMRESRestart ( PetscInt restart)

Set the GMRES restart parameter.

◆ setInitialGuessNonzero()

void vulpes::la::LinearSolver::setInitialGuessNonzero ( bool nonzero)

Set the initial guess to nonzero.

◆ setMaxIterations()

void vulpes::la::LinearSolver::setMaxIterations ( PetscInt maxits)

Set the maximum iterations.

◆ setNormType()

void vulpes::la::LinearSolver::setNormType ( KSPNormType type)

Set the norm type for convergence testing.

◆ setOperators() [1/2]

void vulpes::la::LinearSolver::setOperators ( const SparseMatrix & A)

Set the system matrix.

◆ setOperators() [2/2]

void vulpes::la::LinearSolver::setOperators ( const SparseMatrix & A,
const SparseMatrix & P )

Set the system matrix and preconditioner matrix.

◆ setOptionsBoomerAMG()

void vulpes::la::LinearSolver::setOptionsBoomerAMG ( DataBoomerAMG data)

Set options for the BoomerAMG preconditioner.

◆ setOptionsGAMG()

void vulpes::la::LinearSolver::setOptionsGAMG ( const DataGAMG & data)

Set options for the GAMG preconditioner.

◆ setPreconditioner()

void vulpes::la::LinearSolver::setPreconditioner ( PrecondType pc_type)

Set the type of the preconditioner.

◆ setRelativeTolerance()

void vulpes::la::LinearSolver::setRelativeTolerance ( PetscReal rtol)

Set the relative tolerance.

◆ setSORParameters()

void vulpes::la::LinearSolver::setSORParameters ( PetscReal omega,
PetscInt iterations = 1,
PetscReal rtol = 0.0 )

Set the SOR parameters.

◆ setTolerances()

void vulpes::la::LinearSolver::setTolerances ( PetscReal rtol,
PetscReal abstol,
PetscReal dtol,
PetscInt maxits )

Set the solver tolerances.

Parameters
rtolRelative tolerance
abstolAbsolute tolerance
dtolDivergence tolerance
maxitsMaximum iterations

◆ setType()

void vulpes::la::LinearSolver::setType ( Type solver_type)

Set the type of the linear solver.

Parameters
solver_typeThe type of the linear solver

◆ setUp()

void vulpes::la::LinearSolver::setUp ( )
protected

Set up the KSP, applying the solver specific level smoother.

◆ solve()

void vulpes::la::LinearSolver::solve ( const Vector & b,
Vector & x )

Solve the linear system Ax = b.

Parameters
bThe right-hand side vector
xThe solution vector

Member Data Documentation

◆ m_ksp

KSP vulpes::la::LinearSolver::m_ksp
protected

◆ m_point_block_smoother

bool vulpes::la::LinearSolver::m_point_block_smoother = false
protected

Use point-block Jacobi on the GAMG levels, see DataGAMG.


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