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

Computation of \( \vec x = f(A)\vec b\) for self-adjoint positive definite \( A\). More...

Public Types

using container_type = ContainerType
 
using value_type = dg::get_value_type< ContainerType >
 

Public Member Functions

 MatrixFunction ()=default
 Construct empty. More...
 
template<class MatrixType >
 MatrixFunction (MatrixType &A, const ContainerType &weights, value_type eps_rel, value_type nrmb_correction=1., unsigned max_iter=500, std::function< value_type(value_type)> f_inner=[](value_type x){return x;})
 Construct from matrix. 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 Lanczos iterations in latest call to operator() More...
 
void set_benchmark (bool benchmark, std::string message="Function")
 Set or unset performance timings during iterations. More...
 
template<class UnaryOp , class ContainerType0 , class ContainerType1 >
void operator() (UnaryOp f_outer, const ContainerType0 b, ContainerType1 &x)
 Apply matrix function. More...
 

Detailed Description

template<class ContainerType>
struct dg::mat::MatrixFunction< ContainerType >

Computation of \( \vec x = f(A)\vec b\) for self-adjoint positive definite \( A\).

where \( f(x) = f_{outer}(f_{inner}(x))\) is composed of an inner pre-factor function \(f_{inner}(x)\) and an outer \( f_{outer}(x)\) function. The rational for this design choice is maintain flexibility when using this class in one of our exponential integrators where the outer function is set by the time integrator itself while \( f_{inner}\) can be set by the user. Outside the exponential time integrator \( f_{inner}\) has no use and left as the default identity.

The class is a convenience wrapper that uses dg::mat::UniversalLanczos combined with dg::mat::make_FuncEigen_Te1( f) in its "universal" stopping criterion

Attention
Just as in the Lanczos or PCG methods the matrix \( A\) needs to be positive-definite (i.e. it won't work for negative definite)

Member Typedef Documentation

◆ container_type

template<class ContainerType >
using dg::mat::MatrixFunction< ContainerType >::container_type = ContainerType

◆ value_type

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

Constructor & Destructor Documentation

◆ MatrixFunction() [1/2]

template<class ContainerType >
dg::mat::MatrixFunction< ContainerType >::MatrixFunction ( )
default

Construct empty.

◆ MatrixFunction() [2/2]

template<class ContainerType >
template<class MatrixType >
dg::mat::MatrixFunction< ContainerType >::MatrixFunction ( MatrixType &  A,
const ContainerType &  weights,
value_type  eps_rel,
value_type  nrmb_correction = 1.,
unsigned  max_iter = 500,
std::function< value_type(value_type)>  f_inner = [](value_type x){return x;} 
)
inline

Construct from matrix.

Template Parameters
MatrixType
Parameters
Aself-adjoint matrix; is stored by reference
weightsthe weights in which A is self-adjoint
eps_relrelative accuracy of solution
nrmb_correctionabsolute accuracy in units of eps_rel
max_iterMaximum number of iterations in Lanczos tridiagonalization
f_innerthe inner "pre-factor" function (useful only in connection with a exponential integrator where f_outer is set by the integrator)

Member Function Documentation

◆ construct()

template<class ContainerType >
template<class ... Params>
void dg::mat::MatrixFunction< 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_iter()

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

Get the number of Lanczos iterations in latest call to operator()

◆ operator()()

template<class ContainerType >
template<class UnaryOp , class ContainerType0 , class ContainerType1 >
void dg::mat::MatrixFunction< ContainerType >::operator() ( UnaryOp  f_outer,
const ContainerType0  b,
ContainerType1 &  x 
)
inline

Apply matrix function.

Parameters
f_outerMatrix function to apply together with f_inner from constructor
binput vector
xoutput vector, contains \( x = f(A) \vec b\)

◆ set_benchmark()

template<class ContainerType >
void dg::mat::MatrixFunction< ContainerType >::set_benchmark ( bool  benchmark,
std::string  message = "Function" 
)
inline

Set or unset performance timings during iterations.

Parameters
benchmarkIf true, additional output will be written to std::cout during solution
messageAn optional identifier that is printed together with the benchmark (intended use is to distinguish different messages in the output)

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