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

PCG Solver class for solving \( (y-\alpha\hat I(t,y)) = \rho\). More...

Public Types

using container_type = ContainerType
 
using value_type = get_value_type< ContainerType >
 

Public Member Functions

 DefaultSolver ()
 No memory allocation. More...
 
template<class Implicit >
 DefaultSolver (Implicit &im, const ContainerType &copyable, unsigned max_iter, value_type eps)
 
template<class ... Params>
void construct (Params &&...ps)
 Perfect forward parameters to one of the constructors. More...
 
void set_benchmark (bool benchmark)
 Set or unset performance timings during iterations. More...
 
void operator() (value_type alpha, value_type time, ContainerType &y, const ContainerType &ys)
 

Detailed Description

template<class ContainerType>
struct dg::DefaultSolver< ContainerType >

PCG Solver class for solving \( (y-\alpha\hat I(t,y)) = \rho\).

for given t, alpha and rho. \( \hat I\) must be linear self-adjoint positive definite as it uses a conjugate gradient solver to invert the equation.

Note
This struct is a simple wrapper. It exists because self-adjoint operators appear quite often in practice and is not actually the recommended default way of writing a solver for the implicit time part. It is better to start with the following code and adapt from there
auto solver = [&eps = eps, &im = im, pcg = dg::PCG<ContainerType>( y0, 1000)]
( value_type alpha, value_type time, ContainerType& y, const
ContainerType& ys) mutable
{
auto wrapper = [a = alpha, t = time, &i = im]( const auto& x, auto& y){
i( t, x, y);
dg::blas1::axpby( 1., x, -a, y);
};
dg::blas1::copy( ys, y); // take rhs as initial guess
pcg.solve( wrapper, y, ys, im.precond(), im.weights(), eps);
};
Preconditioned conjugate gradient method to solve .
Definition: pcg.h:57
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
Definition: blas1.h:164
void axpby(get_value_type< ContainerType > alpha, const ContainerType1 &x, get_value_type< ContainerType > beta, ContainerType &y)
Definition: blas1.h:231
@ y
y direction
@ x
x direction
get_value_type< ContainerType > value_type
Definition: implicit.h:62
See also
In general it is recommended to write your own solver using a wrapper lambda like the above and one of the existing solvers like dg::PCG, dg::LGMRES or dg::AndersonAcceleration
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
ImExMultistep ImplicitMultistep ARKStep DIRKStep

Member Typedef Documentation

◆ container_type

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

◆ value_type

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

value type of vectors

Constructor & Destructor Documentation

◆ DefaultSolver() [1/2]

template<class ContainerType >
dg::DefaultSolver< ContainerType >::DefaultSolver ( )
inline

No memory allocation.

◆ DefaultSolver() [2/2]

template<class ContainerType >
template<class Implicit >
dg::DefaultSolver< ContainerType >::DefaultSolver ( Implicit &  im,
const ContainerType &  copyable,
unsigned  max_iter,
value_type  eps 
)
inline

it does not matter what values copyable contains, but its size is important; the solve method can only be called with vectors of the same size)

Template Parameters
ImplicitThe self-adjoint, positive definite implicit part of the right hand side. Has signature void operator()(value_type, const ContainerType&, ContainerType&) The first argument is the time, the second is the input vector, which the functor may not override, and the third is the output, i.e. y' = I(t, y) translates to I(t, y, y'). The two ContainerType arguments never alias each other in calls to the functor. Also needs the WeightType weights() and PreconditionerType precond() member functions.
Parameters
imThe implicit part of the differential equation. Stored as a std::function.
Attention
make sure that im lives throughout the lifetime of this object, else we'll get a dangling reference
Parameters
copyableforwarded to constructor of dg::PCG
max_itermaximum iteration number in cg, forwarded to constructor of dg::PCG
epsrelative and absolute accuracy parameter, used in the solve method of dg::PCG

Member Function Documentation

◆ construct()

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

Perfect forward parameters to one of the constructors.

Template Parameters
Paramsdeduced by the compiler
Parameters
psparameters forwarded to constructors

◆ operator()()

template<class ContainerType >
void dg::DefaultSolver< ContainerType >::operator() ( value_type  alpha,
value_type  time,
ContainerType &  y,
const ContainerType &  ys 
)
inline

◆ set_benchmark()

template<class ContainerType >
void dg::DefaultSolver< ContainerType >::set_benchmark ( bool  benchmark)
inline

Set or unset performance timings during iterations.

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

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