Extension: Matrix functions
#include "dg/matrix/matrix.h"
dg::mat::MCG< ContainerType > Class Template Reference

EXPERIMENTAL Tridiagonalize \(A\) and approximate \(f(A)b \approx R f(\tilde T) e_1\) via CG algorithm. A is self-adjoint in the weights \( W\). More...

Public Types

using value_type = dg::get_value_type< ContainerType >
 value type of the ContainerType class More...
 
using HCooMatrix = cusp::coo_matrix< int, value_type, cusp::host_memory >
 
using HDiaMatrix = cusp::dia_matrix< int, value_type, cusp::host_memory >
 
using HVec = dg::HVec
 

Public Member Functions

 MCG ()
 Allocate nothing, Call construct method before usage. More...
 
 MCG (const ContainerType &copyable, unsigned max_iterations)
 Allocate memory for the mcg method. More...
 
void set_max (unsigned new_max)
 Set the maximum number of iterations. More...
 
unsigned get_max () const
 Get the current maximum number of iterations. More...
 
void set_verbose (bool verbose)
 Set or unset debugging output during iterations. More...
 
value_type get_bnorm () const
 Norm of b from last call to operator() More...
 
template<class ... Params>
void construct (Params &&...ps)
 Perfect forward parameters to one of the constructors. More...
 
unsigned get_iter () const
 Get the number of iterations in the last call to operator() (size of T) More...
 
template<class MatrixType , class DiaMatrixType , class ContainerType0 , class ContainerType1 , class ContainerType2 >
void Ry (MatrixType &&A, const DiaMatrixType &T, const ContainerType0 &y, ContainerType1 &x, const ContainerType2 &b)
 Compute x = R y. More...
 
template<class MatrixType , class ContainerType0 , class ContainerType1 >
const HDiaMatrixoperator() (MatrixType &&A, const ContainerType0 &b, const ContainerType1 &weights, value_type eps=1e-12, value_type nrmb_correction=1., value_type res_fac=1.)
 Tridiagonalize the system \( A\vec b\) using CG. More...
 
HVec make_e1 ()
 Return the vector \( \vec e_1\) with size get_iter() More...
 

Detailed Description

template<class ContainerType>
class dg::mat::MCG< ContainerType >

EXPERIMENTAL Tridiagonalize \(A\) and approximate \(f(A)b \approx R f(\tilde T) e_1\) via CG algorithm. A is self-adjoint in the weights \( W\).

Attention
This class has the exact same result as the corresponding UniversalLanczos class. Its use is for mere experimental purposes.

This class is based on the approach of the paper An iterative solution method for solving f(A)x = b, using Krylov subspace information obtained for the symmetric positive definite matrix A by H. A. Van Der Vorst

Note
The approximation relies on Projection \(x = f(A) b \approx R f(\tilde T) e_1\), where \(\tilde T\) and \(R\) are the tridiagonal and orthogonal matrix of the CG solve respectively and \(e_1\) is the normalized unit vector.

Member Typedef Documentation

◆ HCooMatrix

template<class ContainerType >
using dg::mat::MCG< ContainerType >::HCooMatrix = cusp::coo_matrix<int, value_type, cusp::host_memory>

◆ HDiaMatrix

template<class ContainerType >
using dg::mat::MCG< ContainerType >::HDiaMatrix = cusp::dia_matrix<int, value_type, cusp::host_memory>

◆ HVec

template<class ContainerType >
using dg::mat::MCG< ContainerType >::HVec = dg::HVec

◆ value_type

template<class ContainerType >
using dg::mat::MCG< ContainerType >::value_type = dg::get_value_type<ContainerType>

value type of the ContainerType class

Constructor & Destructor Documentation

◆ MCG() [1/2]

template<class ContainerType >
dg::mat::MCG< ContainerType >::MCG ( )
inline

Allocate nothing, Call construct method before usage.

◆ MCG() [2/2]

template<class ContainerType >
dg::mat::MCG< ContainerType >::MCG ( const ContainerType &  copyable,
unsigned  max_iterations 
)
inline

Allocate memory for the mcg method.

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

Member Function Documentation

◆ construct()

template<class ContainerType >
template<class ... Params>
void dg::mat::MCG< ContainerType >::construct ( Params &&...  ps)
inline

Perfect forward parameters to one of the constructors.

Template Parameters
Paramsdeduced by the compiler
Parameters
psparameters forwarded to constructors

◆ get_bnorm()

template<class ContainerType >
value_type dg::mat::MCG< ContainerType >::get_bnorm ( ) const
inline

Norm of b from last call to operator()

Returns
bnorm

◆ get_iter()

template<class ContainerType >
unsigned dg::mat::MCG< ContainerType >::get_iter ( ) const
inline

Get the number of iterations in the last call to operator() (size of T)

Returns
the number of iterations in the last call to operator()

◆ get_max()

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

Get the current maximum number of iterations.

Returns
the current maximum

◆ make_e1()

template<class ContainerType >
HVec dg::mat::MCG< ContainerType >::make_e1 ( )
inline

Return the vector \( \vec e_1\) with size get_iter()

Parameters
itersize
Returns
e_1

◆ operator()()

template<class ContainerType >
template<class MatrixType , class ContainerType0 , class ContainerType1 >
const HDiaMatrix & dg::mat::MCG< ContainerType >::operator() ( MatrixType &&  A,
const ContainerType0 &  b,
const ContainerType1 &  weights,
value_type  eps = 1e-12,
value_type  nrmb_correction = 1.,
value_type  res_fac = 1. 
)
inline

Tridiagonalize the system \( A\vec b\) using CG.

Parameters
AA self-adjoint, positive definit matrix
bThe right hand side vector.
weightsWeights that define the scalar product in which A is self-adjoint and in which the error norm is computed.
epsrelative accuracy of residual
nrmb_correctionthe absolute error C in units of eps to be respected
res_facfactor that is multiplied to the norm of the residual. Used to account for specific matrix function and operator in the convergence criterium
Returns
The tridiagonal matrix \( T\) with size get_iter()
Note
So far only ordinary convergence criterium of CG method, in particular for \( A x = b \). If used for matrix function computation, \( f(A) x = b \), the parameter eps should be multiplied with appropriate factors to account for the different convergence criteria. The Matrix R and T of the tridiagonalization are further used for computing matrix functions. The x vector must be initialized with 0 if used for tridiagonalization.

◆ Ry()

template<class ContainerType >
template<class MatrixType , class DiaMatrixType , class ContainerType0 , class ContainerType1 , class ContainerType2 >
void dg::mat::MCG< ContainerType >::Ry ( MatrixType &&  A,
const DiaMatrixType &  T,
const ContainerType0 &  y,
ContainerType1 &  x,
const ContainerType2 &  b 
)
inline

Compute x = R y.

Parameters
AA self-adjoint, positive definit matrix
TT non-symmetric tridiagonal Matrix from MCG tridiagonalization
y(host) vector with v.size() = iter. Must have size of T.num_rows. Typically \( T^{(-1)} e_1 \) or \( f(T^{(-1)}) e_1 \)
xContains the matrix approximation \(x = Ry \) (output)
bThe right hand side vector.

◆ set_max()

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

Set the maximum number of iterations.

Parameters
new_maxNew maximum number

◆ set_verbose()

template<class ContainerType >
void dg::mat::MCG< ContainerType >::set_verbose ( bool  verbose)
inline

Set or unset debugging output during iterations.

Parameters
verboseIf true, additional output will be written to std::cout during solution

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