Discontinuous Galerkin Library
#include "dg/algorithm.h"
|
Solve. More...
Public Types | |
using | geometry_type = Geometry |
using | matrix_type = Matrix |
using | container_type = Container |
using | value_type = get_value_type< Container > |
Public Member Functions | |
MultigridCG2d ()=default | |
Allocate nothing, Call construct method before usage. More... | |
template<class ... ContainerParams> | |
MultigridCG2d (const Geometry &grid, const unsigned stages, ContainerParams &&... ps) | |
Construct the grids and the interpolation/projection operators. More... | |
template<class ... Params> | |
void | construct (Params &&...ps) |
Perfect forward parameters to one of the constructors. More... | |
template<class ContainerType0 > | |
void | project (const ContainerType0 &src, std::vector< ContainerType0 > &out) const |
Project vector to all involved grids. More... | |
template<class ContainerType0 > | |
std::vector< ContainerType0 > | project (const ContainerType0 &src) const |
Project vector to all involved grids (allocate memory version) More... | |
unsigned | stages () const |
unsigned | num_stages () const |
const Geometry & | grid (unsigned stage) const |
return the grid at given stage More... | |
unsigned | max_iter () const |
void | set_max_iter (unsigned new_max) |
Set the maximum number of iterations allowed at stage 0. More... | |
void | set_benchmark (bool benchmark, std::string message="Nested Iterations") |
Set or unset performance timings during iterations. More... | |
const Container & | copyable () const |
Return an object of same size as the object used for construction on the finest grid. More... | |
template<class MatrixType , class ContainerType0 , class ContainerType1 > | |
std::vector< unsigned > | solve (std::vector< MatrixType > &ops, ContainerType0 &x, const ContainerType1 &b, value_type eps) |
Nested iterations. More... | |
template<class MatrixType , class ContainerType0 , class ContainerType1 > | |
std::vector< unsigned > | solve (std::vector< MatrixType > &ops, ContainerType0 &x, const ContainerType1 &b, std::vector< value_type > eps) |
Nested iterations. More... | |
Solve.
\[ \hat O \phi = \rho \]
for self-adjoint \(\hat O\)
using dg::nested_iterations
with dg::PCG
solvers for any operator \(\hat O\) that is self-adjoint in appropriate weights \(W\) We refine the grids in the first two dimensions (2d / x and y)
dg::Elliptic
and dg::Helmholtz
classes are self-adjoint so these are the intended target operators. dg::PCG
solver are taken from the precond()
and weights()
method in the MatrixType
classGeometry | A type that is or derives from one of the abstract geometry base classes ( aGeometry2d , aGeometry3d , aMPIGeometry2d , ...). Geometry determines which Matrix and Container types can be used: |
Matrix | A class for which the dg::blas2::symv functions are callable in connection with the Container class and to which the return type of dg::create::dx() can be converted using dg::blas2::transfer . The Matrix type can be one of:
|
Container | A data container class for which the blas1 functionality is overloaded and to which the return type of blas1::subroutine() can be converted using dg::assign . We assume that Container is copyable/assignable and has a swap member function. In connection with Geometry this is one of
|
Extrapolation
to generate an initial guess using dg::MultigridCG2d< Geometry, Matrix, Container >::container_type = Container |
using dg::MultigridCG2d< Geometry, Matrix, Container >::geometry_type = Geometry |
using dg::MultigridCG2d< Geometry, Matrix, Container >::matrix_type = Matrix |
using dg::MultigridCG2d< Geometry, Matrix, Container >::value_type = get_value_type<Container> |
|
default |
Allocate nothing, Call construct
method before usage.
|
inline |
Construct the grids and the interpolation/projection operators.
grid | the original grid (Nx() and Ny() must be evenly divisable by pow(2, stages-1) |
stages | number of grids in total (The second grid contains half the points of the original grids, The third grid contains half of the second grid ...). Must be >= 1. A good number to start is 3. |
ps | parameters necessary for dg::construct to construct a Container from a dg::HVec |
|
inline |
Perfect forward parameters to one of the constructors.
Params | deduced by the compiler |
ps | parameters forwarded to constructors |
|
inline |
Return an object of same size as the object used for construction on the finest grid.
|
inline |
return the grid at given stage
stage | must fulfill 0 <= stage < stages() |
|
inline |
The maximum number of iterations allowed at stage 0 (if the solution method returns this number, failure is indicated)
|
inline |
stages
)
|
inline |
Project vector to all involved grids (allocate memory version)
src | the input vector |
|
inline |
Project vector to all involved grids.
src | the input vector (may alias first element of out) |
out | the input vector projected to all grids ( index 0 contains a copy of src, 1 is the projetion to the first coarse grid, 2 is the next coarser grid, ...) |
out
is not resized
|
inline |
Set or unset performance timings during iterations.
benchmark | If true, additional output will be written to std::cout during solution |
message | An optional identifier that is printed together with the benchmark (intended use is to distinguish different messages in the output) |
|
inline |
Set the maximum number of iterations allowed at stage 0.
By default this number is the grid size. However, for large simulations you may want to prevent the solver from iterating to that number in case of failure.
new_max | new maximum number of iterations allowed at stage 0 |
|
inline |
Nested iterations.
Equivalent to the following
dg::nested_iterations
dg::PCG
solver is taken from the weights()
and precond()
method in the MatrixType
class ops | Index 0 is the MatrixType on the original grid, 1 on the half grid, 2 on the quarter grid, ... ops [u].precond() and ops [u].weights() need to be callable! |
x | (read/write) contains initial guess on input and the solution on output (if the initial guess is good enough the solve may return immediately) |
b | The right hand side |
eps | the accuracy: iteration stops if \( ||b - Ax|| < \epsilon( ||b|| + 1) \). If needed (and it is recommended to tune these values) the accuracy can be set for each stage separately. Per default the same accuracy is used at all stages but \( \epsilon_i = 0.5\epsilon_0\) for i > 0 may be a good value as well. |
MatrixType | Any 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
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. |
ContainerType | Any 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
ContainerTypes in the argument list, then TensorTraits must exist for all of them |
|
inline |
Nested iterations.
Equivalent to the following
dg::nested_iterations
dg::PCG
solver is taken from the weights()
and precond()
method in the MatrixType
class ops | Index 0 is the MatrixType on the original grid, 1 on the half grid, 2 on the quarter grid, ... ops [u].precond() and ops [u].weights() need to be callable! |
x | (read/write) contains initial guess on input and the solution on output (if the initial guess is good enough the solve may return immediately) |
b | The right hand side |
eps | the accuracy: iteration stops if \( ||b - Ax|| < \epsilon( ||b|| + 1) \). If needed (and it is recommended to tune these values) the accuracy can be set for each stage separately. Per default the same accuracy is used at all stages but \( \epsilon_i = 0.5\epsilon_0\) for i > 0 may be a good value as well. |
MatrixType | Any 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
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. |
ContainerType | Any 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
ContainerTypes in the argument list, then TensorTraits must exist for all of them |
|
inline |
num_stages
)