Discontinuous Galerkin Library
#include "dg/algorithm.h"
dg::EVE< ContainerType > Class Template Reference

The Eigen-Value-Estimator (EVE) finds largest Eigenvalue of \( M^{-1}Ax = \lambda_\max x\). More...

Public Types

using container_type = ContainerType
 
using value_type = get_value_type< ContainerType >
 

Public Member Functions

 EVE ()=default
 Allocate nothing, Call construct method before usage. More...
 
 EVE (const ContainerType &copyable, unsigned max_iter=100)
 Allocate memory for the pcg method. More...
 
void construct (const ContainerType &copyable, unsigned max_iter=100)
 Allocate memory for the pcg method. More...
 
void set_max (unsigned new_max)
 Set maximum number of iterations. More...
 
unsigned get_max () const
 Get maximum number of iterations. More...
 
void set_throw_on_fail (bool throw_on_fail)
 Set or unset a throw on failure-to-converge. More...
 
template<class MatrixType0 , class ContainerType0 , class ContainerType1 , class MatrixType1 , class ContainerType2 >
unsigned solve (MatrixType0 &&A, ContainerType0 &x, const ContainerType1 &b, MatrixType1 &&P, const ContainerType2 &W, value_type &ev_max, value_type eps_ev=1e-12)
 Preconditioned CG to estimate maximum Eigenvalue of the generalized problem \( PAx = \lambda x\). More...
 

Detailed Description

template<class ContainerType>
class dg::EVE< ContainerType >

The Eigen-Value-Estimator (EVE) finds largest Eigenvalue of \( M^{-1}Ax = \lambda_\max x\).

Estimate largest Eigenvalue of a symmetric positive definite matrix \( A\) with possible preconditioner \( M^{-1}\) using the conjugate gradient (CG) method. The unpreconditioned version is the algorithm suggested in Tichy, On error estimation in the conjugate gradient method: Normwise backward error, Proceedings of the Conference Algoritmy, 323-332, 2016 . The reason this works also for the preconditioned CG method is because preconditioned CG is equivalent to applying the unpreconditioned CG method to \( \bar A\bar x = \bar b\) with \( \bar A := {E^{-1}}^\mathrm{T} A E^{-1} \), \( \bar x := Ex\) and \( \bar b := {E^{-1}}^\mathrm{T}\), where \( M^{-1} = {E^{-1}}^\mathrm{T} E^{-1}\) is the preconditioner. The maximum Eigenvalue of \( M^{-1} A\) is the same as the maximum EV of \( {E^{-1}}^\mathrm{T} A E^{-1} \)

Attention
beware the sign: a negative definite matrix does not work in Conjugate gradient
Template Parameters
ContainerTypeAny class for which a specialization of TensorTraits exists and which fulfills the requirements of the there defined data and execution policies derived from AnyVectorTag and AnyPolicyTag. Among others
  • dg::HVec (serial), dg::DVec (cuda / omp), dg::MHVec (mpi + serial) or dg::MDVec (mpi + cuda / omp)
  • std::vector<dg::DVec> (vector of shared device vectors), std::array<double, 4> (array of 4 doubles) or std::map < std::string, dg::DVec> ( a map of named vectors)
  • double (scalar) and other primitive types ...
If there are several ContainerTypes in the argument list, then TensorTraits must exist for all of them
See also
See The dg dispatch system for a detailed explanation of our type dispatch system

Member Typedef Documentation

◆ container_type

template<class ContainerType >
using dg::EVE< ContainerType >::container_type = ContainerType

◆ value_type

template<class ContainerType >
using dg::EVE< ContainerType >::value_type = get_value_type<ContainerType>

value type of the ContainerType class

Constructor & Destructor Documentation

◆ EVE() [1/2]

template<class ContainerType >
dg::EVE< ContainerType >::EVE ( )
default

Allocate nothing, Call construct method before usage.

◆ EVE() [2/2]

template<class ContainerType >
dg::EVE< ContainerType >::EVE ( const ContainerType &  copyable,
unsigned  max_iter = 100 
)
inline

Allocate memory for the pcg method.

Parameters
copyableA ContainerType must be copy-constructible from this
max_iterMaximum number of iterations to be used

Member Function Documentation

◆ construct()

template<class ContainerType >
void dg::EVE< ContainerType >::construct ( const ContainerType &  copyable,
unsigned  max_iter = 100 
)
inline

Allocate memory for the pcg method.

Parameters
copyableA ContainerType must be copy-constructible from this
max_iterMaximum number of iterations to be used

◆ get_max()

template<class ContainerType >
unsigned dg::EVE< ContainerType >::get_max ( ) const
inline

Get maximum number of iterations.

◆ set_max()

template<class ContainerType >
void dg::EVE< ContainerType >::set_max ( unsigned  new_max)
inline

Set maximum number of iterations.

◆ set_throw_on_fail()

template<class ContainerType >
void dg::EVE< ContainerType >::set_throw_on_fail ( bool  throw_on_fail)
inline

Set or unset a throw on failure-to-converge.

Parameters
throw_on_failIf true, the solve method will thow a dg::Fail if it is unable to converge
Note
the default value is true

◆ solve()

template<class ContainerType >
template<class MatrixType0 , class ContainerType0 , class ContainerType1 , class MatrixType1 , class ContainerType2 >
unsigned dg::EVE< ContainerType >::solve ( MatrixType0 &&  A,
ContainerType0 &  x,
const ContainerType1 &  b,
MatrixType1 &&  P,
const ContainerType2 &  W,
value_type ev_max,
value_type  eps_ev = 1e-12 
)

Preconditioned CG to estimate maximum Eigenvalue of the generalized problem \( PAx = \lambda x\).

where \( P\) is the preconditioner.

Note
This is just a regular PCG algorithm which updates an estimate for the largest Eigenvalue in each iteration and returns once the change is marginal. This means on output x is the same as after the same number of iterations of a regular PCG method. The original algorithm is suggested in Tichy, On error estimation in the conjugate gradient method: Normwise backward error, Proceedings of the Conference Algorithmy, 323-332, 2016
Parameters
AA symmetric, positive definit matrix
xContains an initial value on input and the solution on output.
bThe right hand side vector. x and b may be the same vector.
PThe preconditioner ( \( M^{-1}\) in the above notation)
WThe weights in which A and P are self-adjoint
ev_max(output) maximum Eigenvalue on output
eps_evThe desired accuracy of the largest Eigenvalue
Returns
Number of iterations used to achieve desired precision or max_iterations
Note
The method will throw dg::Fail if the desired accuracy is not reached within max_iterations You can unset this behaviour with the set_throw_on_fail member
Template Parameters
MatrixTypeAny class for which a specialization of TensorTraits exists and defines a tensor_category derived from AnyMatrixTag. Furthermore, any functor/lambda type with signature void operator()( const ContainerType0&, ContainerType1&) . For example In case of SelfMadeMatrixTag only those blas2 functions that have a corresponding member function in the Matrix class (e.g. symv( const ContainerType0&, ContainerType1&); ) can be called. If a Container has the RecursiveVectorTag, then the matrix is applied to each of the elements unless the type has the SelfMadeMatrixTag or is a Functor type.
ContainerTypeAny class for which a specialization of TensorTraits exists and which fulfills the requirements of the there defined data and execution policies derived from AnyVectorTag and AnyPolicyTag. Among others
  • dg::HVec (serial), dg::DVec (cuda / omp), dg::MHVec (mpi + serial) or dg::MDVec (mpi + cuda / omp)
  • std::vector<dg::DVec> (vector of shared device vectors), std::array<double, 4> (array of 4 doubles) or std::map < std::string, dg::DVec> ( a map of named vectors)
  • double (scalar) and other primitive types ...
If there are several ContainerTypes in the argument list, then TensorTraits must exist for all of them
See also
See The dg dispatch system for a detailed explanation of our type dispatch system

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