KASKADE 7 development version
Loading...
Searching...
No Matches
Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor > Class Template Reference

(regularized) preconditioned conjugate gradient method More...

#include <cgImplementation.hh>

Inheritance diagram for Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >:
Kaskade::DoNotMeasureTime

Public Types

typedef X domain_type
 The domain type of the operator to be inverted.
typedef Xstar range_type
 The range type of the operator to be inverted.
typedef X::field_type field_type
 The field type of the operator to be inverted.
typedef ScalarTraits< field_type >::Real Real
 the real field type corresponding to field_type

Public Member Functions

 CGBase (SymmetricLinearOperator< X, Xstar > &op_, SymmetricPreconditioner< X, Xstar > &prec_, PCGTerminationCriterion< Real > &terminate_, int verbose_=0, double eps_=1e-15, Timings &timer_=Timings::instance())
 Set up conjugate gradient solver.
 CGBase (Dune::LinearOperator< X, Xstar > &op_, Dune::Preconditioner< X, Xstar > &prec_, DualPairing< X, Xstar > const &dp_, PCGTerminationCriterion< Real > &terminate_, int verbose_=0, double eps_=1e-15, Timings &timer_=Timings::instance())
 Set up conjugate gradient solver.
 CGBase (Dune::LinearOperator< X, Xstar > &op_, Dune::Preconditioner< X, Xstar > &prec_, DualPairing< X, Xstar > const &dp_, PCGTerminationCriterion< Real > &terminate_, Functor f_, int verbose_=0, double eps_=1e-15, Timings &timer_=Timings::instance())
 Set up conjugate gradient solver with a functor for an initial regularization guess.
void apply (X &u, Xstar &b)
virtual void apply (X &u, Xstar &b, Real tolerance, Dune::InverseOperatorResult &res)
virtual void apply (X &u, Xstar &b, Dune::InverseOperatorResult &res)
int cgLoop (X &u, Xstar &b, Dune::InverseOperatorResult &res)
bool encounteredNonConvexity () const
double getSolutionEnergyNormEstimate ()
virtual Dune::SolverCategory::Category category () const override
 returns the category of the operator
Real cond (Real *kappaUpper=nullptr) const
 Condition number estimate \( \kappa(B^{-1} A) \) of the preconditioned system.
void resumeCGTimer ()
void resumeMVTimer ()
void resumeDPTimer ()
void resumeAPTimer ()
void resumePRTimer ()
void stopCGTimer ()
void stopMVTimer ()
void stopDPTimer ()
void stopAPTimer ()
void stopPRTimer ()
void printTimers ()

Detailed Description

template<class X, class Xstar, CGImplementationType impl = CGImplementationType::STANDARD, class TimerPolicy = DoNotMeasureTime, class Functor = DoNotAlwaysRegularize>
class Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >

(regularized) preconditioned conjugate gradient method

This implements a preconditioned IterateType::CG iteration for an operator \( A: X\to x^* \), preconditioned by a preconditioner \( B^{-1}: X^* \to X \). The termination is based on a policy (see PCGTerminationCriterion), allowing both simple residual-based and sophisticated error-estimation based criteria (e.g. Strakos-Tichy).

The implementation follows Deuflhard/Weiser, Section 5.3.3.

The class offers two operator/preconditioner interfaces: a SymmetricLinearOperator / SymmetricPreconditioner pair (with a zero dual pairing, yielding the efficient simultaneous evaluation of matrix-vector products and dual pairings), and a generic Dune::LinearOperator / Dune::Preconditioner pair with an explicit dual pairing. The termination is policy-based (PCGTerminationCriterion), the TimerPolicy template parameter switches the (optional) timing of the sub-operations, and the regularized variants detect nonconvexity of the underlying quadratic form.

Template Parameters
Xthe type of vectors from the primal space
Xstarthe type of vectors from the dual space
implthe CG variant to be used (STANDARD, TRUNCATED, REGULARIZED or HYBRID)
TimerPolicyenable timers for dual pairings, axpy-operations, matrix-vector products and preconditioners with struct MeasureTime (recording into Kaskade's Timings facility); the default DoNotMeasureTime measures nothing.
Functora functor used for a heuristic initial guess of the regularization parameter (advanced use)

Definition at line 280 of file cgImplementation.hh.

Member Typedef Documentation

◆ domain_type

template<class X, class Xstar, CGImplementationType impl = CGImplementationType::STANDARD, class TimerPolicy = DoNotMeasureTime, class Functor = DoNotAlwaysRegularize>
typedef X Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >::domain_type

The domain type of the operator to be inverted.

Definition at line 289 of file cgImplementation.hh.

◆ field_type

template<class X, class Xstar, CGImplementationType impl = CGImplementationType::STANDARD, class TimerPolicy = DoNotMeasureTime, class Functor = DoNotAlwaysRegularize>
typedef X::field_type Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >::field_type

The field type of the operator to be inverted.

Definition at line 293 of file cgImplementation.hh.

◆ range_type

template<class X, class Xstar, CGImplementationType impl = CGImplementationType::STANDARD, class TimerPolicy = DoNotMeasureTime, class Functor = DoNotAlwaysRegularize>
typedef Xstar Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >::range_type

The range type of the operator to be inverted.

Definition at line 291 of file cgImplementation.hh.

◆ Real

template<class X, class Xstar, CGImplementationType impl = CGImplementationType::STANDARD, class TimerPolicy = DoNotMeasureTime, class Functor = DoNotAlwaysRegularize>
typedef ScalarTraits<field_type>::Real Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >::Real

the real field type corresponding to field_type

Definition at line 298 of file cgImplementation.hh.

Constructor & Destructor Documentation

◆ CGBase() [1/3]

template<class X, class Xstar, CGImplementationType impl = CGImplementationType::STANDARD, class TimerPolicy = DoNotMeasureTime, class Functor = DoNotAlwaysRegularize>
Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >::CGBase ( SymmetricLinearOperator< X, Xstar > & op_,
SymmetricPreconditioner< X, Xstar > & prec_,
PCGTerminationCriterion< Real > & terminate_,
int verbose_ = 0,
double eps_ = 1e-15,
Timings & timer_ = Timings::instance() )
inline

Set up conjugate gradient solver.

Parameters
opthe symmetric positive definite linear operator. In case a matrix is to be used, wrap the matrix into the SymmetricMatrixOperator interface.
precthe preconditioner
terminatethe termination criterion. The object has to exist during the lifetime of the cg object as it is referenced.
verbosecontrols the verbosity of logging to std::cout. 0 means no output at all (default). Values in 0,1,2 are valid.
timer_the Timings instance to record timing sections into, if the TimerPolicy collects timings (defaults to the global one).

Definition at line 313 of file cgImplementation.hh.

◆ CGBase() [2/3]

template<class X, class Xstar, CGImplementationType impl = CGImplementationType::STANDARD, class TimerPolicy = DoNotMeasureTime, class Functor = DoNotAlwaysRegularize>
Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >::CGBase ( Dune::LinearOperator< X, Xstar > & op_,
Dune::Preconditioner< X, Xstar > & prec_,
DualPairing< X, Xstar > const & dp_,
PCGTerminationCriterion< Real > & terminate_,
int verbose_ = 0,
double eps_ = 1e-15,
Timings & timer_ = Timings::instance() )
inline

Set up conjugate gradient solver.

Parameters
opthe (in fact symmetric positive definite) operator
precthe preconditioner
dpthe dual pairing with respect to which the operator is symmetric
terminatethe termination criterion. The object has to exist during the lifetime of the cg object as it is referenced.
verbosecontrols the verbosity of logging to std::cout. 0 means no output at all (default). Values in 0,1,2 are valid.
timer_the Timings instance to record timing sections into, if the TimerPolicy collects timings (defaults to the global one).

Definition at line 340 of file cgImplementation.hh.

◆ CGBase() [3/3]

template<class X, class Xstar, CGImplementationType impl = CGImplementationType::STANDARD, class TimerPolicy = DoNotMeasureTime, class Functor = DoNotAlwaysRegularize>
Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >::CGBase ( Dune::LinearOperator< X, Xstar > & op_,
Dune::Preconditioner< X, Xstar > & prec_,
DualPairing< X, Xstar > const & dp_,
PCGTerminationCriterion< Real > & terminate_,
Functor f_,
int verbose_ = 0,
double eps_ = 1e-15,
Timings & timer_ = Timings::instance() )
inline

Set up conjugate gradient solver with a functor for an initial regularization guess.

Parameters
opthe (in fact symmetric positive definite) operator
precthe preconditioner
dpthe dual pairing with respect to which the operator is symmetric
terminatethe termination criterion. The object has to exist during the lifetime of the cg object as it is referenced.
ffunctor used for a heuristic initial guess of the regularization parameter
verbosecontrols the verbosity of logging to std::cout. 0 means no output at all (default). Values in 0,1,2 are valid.
timer_the Timings instance to record timing sections into, if the TimerPolicy collects timings (defaults to the global one).

Definition at line 369 of file cgImplementation.hh.

Member Function Documentation

◆ apply() [1/3]

template<class X, class Xstar, CGImplementationType impl = CGImplementationType::STANDARD, class TimerPolicy = DoNotMeasureTime, class Functor = DoNotAlwaysRegularize>
void Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >::apply ( X & u,
Xstar & b )
inline

◆ apply() [2/3]

template<class X, class Xstar, CGImplementationType impl = CGImplementationType::STANDARD, class TimerPolicy = DoNotMeasureTime, class Functor = DoNotAlwaysRegularize>
virtual void Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >::apply ( X & u,
Xstar & b,
Dune::InverseOperatorResult & res )
inlinevirtual

Definition at line 403 of file cgImplementation.hh.

◆ apply() [3/3]

template<class X, class Xstar, CGImplementationType impl = CGImplementationType::STANDARD, class TimerPolicy = DoNotMeasureTime, class Functor = DoNotAlwaysRegularize>
virtual void Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >::apply ( X & u,
Xstar & b,
Real tolerance,
Dune::InverseOperatorResult & res )
inlinevirtual
Parameters
uinitial guess
bright hand side
tolerancetolerance of the termination criterion
rescontains, number of iterations, residual reduction, ...

Definition at line 397 of file cgImplementation.hh.

◆ category()

template<class X, class Xstar, CGImplementationType impl = CGImplementationType::STANDARD, class TimerPolicy = DoNotMeasureTime, class Functor = DoNotAlwaysRegularize>
virtual Dune::SolverCategory::Category Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >::category ( ) const
inlineoverridevirtual

returns the category of the operator

From the Dune doxygen documentation it is unclear what this is supposed to mean. We return a dummy here.

Definition at line 638 of file cgImplementation.hh.

◆ cgLoop()

template<class X, class Xstar, CGImplementationType impl = CGImplementationType::STANDARD, class TimerPolicy = DoNotMeasureTime, class Functor = DoNotAlwaysRegularize>
int Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >::cgLoop ( X & u,
Xstar & b,
Dune::InverseOperatorResult & res )
inline

◆ cond()

template<class X, class Xstar, CGImplementationType impl = CGImplementationType::STANDARD, class TimerPolicy = DoNotMeasureTime, class Functor = DoNotAlwaysRegularize>
Real Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >::cond ( Real * kappaUpper = nullptr) const
inline

Condition number estimate \( \kappa(B^{-1} A) \) of the preconditioned system.

After a call to apply(), this returns a lower bound on the condition number \( \kappa(B^{-1} A) \) of the preconditioned operator, computed from the Lanczos (Ritz) values of the Krylov space built during the CG iteration.

The CG coefficients \( \alpha_i = \sigma_i / \langle q_i, A q_i\rangle \) and \( \beta_{i+1} = \sigma_{i+1}/\sigma_i \) with \( \sigma_i = \langle r_i, B^{-1} r_i\rangle \) collected during the iteration define the symmetric tridiagonal Lanczos matrix \( T_k \) of the preconditioned operator \( B^{-1} A \) restricted to the Krylov space, with

\[ d_i = \frac{1}{\alpha_i} + \frac{\beta_i}{\alpha_{i-1}},\quad e_i = \frac{\sqrt{\beta_{i+1}}}{\alpha_i}. \]

Its eigenvalues (computed via LAPACK stev) are the Ritz values of \( B^{-1}A \) in that Krylov space. Since the Ritz values converge monotonically towards the extremal eigenvalues of \( B^{-1}A \) from the inside, \( \lambda_{\min}(T_k) \) is an upper bound on \( \lambda_{\min}(B^{-1}A) \) and \( \lambda_{\max}(T_k) \) a lower bound on \( \lambda_{\max}(B^{-1}A) \), hence the returned quotient is a lower bound on \( \kappa \) that becomes sharper with every iteration.

Parameters
kappaUpperif non-null, an upper bound on the true condition number is stored there, obtained from the residual-based error bound on the extremal Ritz values (Saad). Thus the caller obtains the interval \( [\mathrm{cond}(), \kappa_{\mathrm{upper}}] \) containing the true \( \kappa \).
Exceptions
DetailedExceptionif the condition estimate is not well-defined, i.e. if the solver is not a STANDARD CG implementation (for TRUNCATED, REGULARIZED and HYBRID variants the coefficients do not describe \( B^{-1}A \) on an unmodified Krylov space), or if the iteration did not produce usable coefficients (no or a single step, or premature termination).

Definition at line 676 of file cgImplementation.hh.

◆ encounteredNonConvexity()

template<class X, class Xstar, CGImplementationType impl = CGImplementationType::STANDARD, class TimerPolicy = DoNotMeasureTime, class Functor = DoNotAlwaysRegularize>
bool Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >::encounteredNonConvexity ( ) const
inline

Definition at line 625 of file cgImplementation.hh.

◆ getSolutionEnergyNormEstimate()

template<class X, class Xstar, CGImplementationType impl = CGImplementationType::STANDARD, class TimerPolicy = DoNotMeasureTime, class Functor = DoNotAlwaysRegularize>
double Kaskade::CGBase< X, Xstar, impl, TimerPolicy, Functor >::getSolutionEnergyNormEstimate ( )
inline

Definition at line 630 of file cgImplementation.hh.

◆ printTimers()

void Kaskade::DoNotMeasureTime::printTimers ( )
inlineinherited

◆ resumeAPTimer()

void Kaskade::DoNotMeasureTime::resumeAPTimer ( )
inlineinherited

◆ resumeCGTimer()

void Kaskade::DoNotMeasureTime::resumeCGTimer ( )
inlineinherited

◆ resumeDPTimer()

void Kaskade::DoNotMeasureTime::resumeDPTimer ( )
inlineinherited

◆ resumeMVTimer()

void Kaskade::DoNotMeasureTime::resumeMVTimer ( )
inlineinherited

◆ resumePRTimer()

void Kaskade::DoNotMeasureTime::resumePRTimer ( )
inlineinherited

◆ stopAPTimer()

void Kaskade::DoNotMeasureTime::stopAPTimer ( )
inlineinherited

◆ stopCGTimer()

void Kaskade::DoNotMeasureTime::stopCGTimer ( )
inlineinherited

◆ stopDPTimer()

void Kaskade::DoNotMeasureTime::stopDPTimer ( )
inlineinherited

◆ stopMVTimer()

void Kaskade::DoNotMeasureTime::stopMVTimer ( )
inlineinherited

◆ stopPRTimer()

void Kaskade::DoNotMeasureTime::stopPRTimer ( )
inlineinherited

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