Fluid Dynamics Library
Public Member Functions | Protected Member Functions | Protected Attributes
fdl::MACPCGSolver< scalar_t > Class Template Reference

Conjugate gradient solver for MAC grid linear algebra. More...

#include <macpcgsolver.hpp>

List of all members.

Public Member Functions

 MACPCGSolver (int nx, int ny, int nz)
 Allocate scratch space for linear system with given MAC dimensions.
 MACPCGSolver (const MACPCGSolver< scalar_t > &S)
 Copy constructor.
virtual void resize (int nx, int ny, int nz)
 Reallocate solver space for given MAC dimensions.
int xdim () const
int ydim () const
int zdim () const
void setTolerance (scalar_t tol)
void setMaxIter (unsigned max)
scalar_t getTolerance () const
unsigned getMaxIter () const
unsigned LastIter () const
 Number of iterations that cgsolve() has performed.
scalar_t ResNorm () const
 $\ell^2$-norm of
void pcgsolve (MACPrecond< scalar_t > &A, const MACVector< scalar_t > &b, MACVector< scalar_t > &x)
 Conjugate gradient for $Ax = b$.

Protected Member Functions

scalar_t macheps ()
 Estimate "machine epsilon.".

Protected Attributes

int nx_
int ny_
int nz_
MACVector< scalar_t > res
 Residue vector in iterative linear solver.
MACVector< scalar_t > p0
MACVector< scalar_t > p1
MACVector< scalar_t > q
MACVector< scalar_t > z
scalar_t tol_
 Stopping tolerance.
unsigned maxiter_
 Iteration bound.
scalar_t rnorm_
 Current residue norm.
unsigned iter_
 Iteration counter.

Detailed Description

template<typename scalar_t>
class fdl::MACPCGSolver< scalar_t >

Conjugate gradient solver for MAC grid linear algebra.

The main utility of the class is to encapsulate (and manage) the scratch vectors used in the iterative algorithm. Hence the salient constructor parameters are the MAC grid dimensions. However dimension checking for all terms is performed at the outset of each call to of cgsolve(). Dimension mismatch will throw a standar error.

Convergence is measured by the usual criterion

\[ \|\rho_n\|_{\ell^2} \leq \epsilon_{\mathrm{tol}} \]

where $\rho_n$ denotes the residue vector of the n-th iteration, and $\epsilon_{\mathrm{tol}}$ is set by setTolerance. Failure to converge is handled in one of two ways:

  1. do nothing (default),
  2. throw a standard exception. The latter behavior is enforced by passing the definition -DABORT_ON_DIVERGENCE when compiling the solver.

The tolerance $\epsilon_{\mathrm{tol}}$ is initialized in dependence on "machine epsilon," specifically

\[ \epsilon_{\mathrm{tol}} = \sqrt{\epsilon_{\mathrm{mach}}}, \]

for the template paramter.

Definition at line 58 of file macpcgsolver.hpp.


Member Function Documentation

template<typename scalar_t>
void fdl::MACPCGSolver< scalar_t >::pcgsolve ( MACPrecond< scalar_t > &  A,
const MACVector< scalar_t > &  rhs,
MACVector< scalar_t > &  soln 
)

Conjugate gradient for $Ax = b$.

Follows structure of Algorithm 10.2.1 from Matrix Computations.

Definition at line 159 of file macpcgsolver.hpp.


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