Discontinuous Galerkin Library
#include "dg/algorithm.h"
Level 1: Vectors, Matrices and basic operations
Collaboration diagram for Level 1: Vectors, Matrices and basic operations:

Modules

 Basic container independent subroutines
 
 Useful Typedefs
 
 Sparse matrix formats
 
 Dense matrix formats
 
 Vector view
 
 MPI backend
 
 The tag dispatch system
 

Functions

template<class from_ContainerType , class ContainerType , class ... Params>
void dg::assign (const from_ContainerType &from, ContainerType &to, Params &&... ps)
 Generic way to assign the contents of a from_ContainerType object to a ContainerType object optionally given additional parameters. More...
 
template<class ContainerType , class from_ContainerType , class ... Params>
ContainerType dg::construct (const from_ContainerType &from, Params &&... ps)
 Generic way to construct an object of ContainerType given a from_ContainerType object and optional additional parameters. More...
 
template<class MatrixType , class ContainerType1 , class ContainerType2 >
void dg::apply (get_value_type< ContainerType1 > alpha, MatrixType &&M, const ContainerType1 &x, get_value_type< ContainerType1 > beta, ContainerType2 &y)
 \( y = \alpha M(x) + \beta y \); (alias for dg::blas2::symv) More...
 
template<class MatrixType , class ContainerType1 , class ContainerType2 >
void dg::apply (MatrixType &&M, const ContainerType1 &x, ContainerType2 &y)
 \( y = M( x)\); (alias for dg::blas2::symv) More...
 

Detailed Description

Function Documentation

◆ apply() [1/2]

template<class MatrixType , class ContainerType1 , class ContainerType2 >
void dg::apply ( get_value_type< ContainerType1 >  alpha,
MatrixType &&  M,
const ContainerType1 &  x,
get_value_type< ContainerType1 >  beta,
ContainerType2 &  y 
)
inline

\( y = \alpha M(x) + \beta y \); (alias for dg::blas2::symv)

This Alias exists for code readability: if your matrix is not actually a matrix but a functor then it may seem unnatural to write blas2::symv in your code especially if M is non-linear.

◆ apply() [2/2]

template<class MatrixType , class ContainerType1 , class ContainerType2 >
void dg::apply ( MatrixType &&  M,
const ContainerType1 &  x,
ContainerType2 &  y 
)
inline

\( y = M( x)\); (alias for dg::blas2::symv)

This Alias exists for code readability: if your matrix is not actually a matrix but a functor then it may seem unnatural to write blas2::symv in your code especially if M is non-linear.

◆ assign()

template<class from_ContainerType , class ContainerType , class ... Params>
void dg::assign ( const from_ContainerType &  from,
ContainerType &  to,
Params &&...  ps 
)
inline

Generic way to assign the contents of a from_ContainerType object to a ContainerType object optionally given additional parameters.

The idea of this function is to convert between types with the same data layout but different execution policies (e.g. from a thrust::host_vector to a thrust::device_vector). If the layout differs, additional parameters can be used to achieve what you want.

For example

dg::HVec host( 100, 1.);
dg::DVec device(100);
dg::assign( host, device );
//let us construct a std::vector of 3 dg::DVec from a host vector
std::vector<dg::DVec> device_vec(3);
dg::assign( host, device_vec, 3);
void assign(const from_ContainerType &from, ContainerType &to, Params &&... ps)
Generic way to assign the contents of a from_ContainerType object to a ContainerType object optionall...
Definition: blas1.h:665
thrust::host_vector< double > HVec
Host Vector.
Definition: typedefs.h:19
thrust::device_vector< double > DVec
Device Vector. The device can be an OpenMP parallelized cpu or a gpu. This depends on the value of th...
Definition: typedefs.h:23
Parameters
fromsource vector
totarget vector contains a copy of from on output (memory is automatically resized if necessary)
psadditional parameters usable for the transfer operation
Note
it is possible to assign a from_ContainerType to a std::array<ContainerType, N> (all elements are initialized with from_ContainerType) and also a std::vector<ContainerType> ( the desired size of the std::vector must be provided as an additional parameter)
Template Parameters
from_ContainerTypemust have the same data policy derived from AnyVectorTag as ContainerType (with the exception of std::array and std::vector) but can have different execution policy
Paramsin some cases additional parameters that are necessary to assign objects of Type ContainerType
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

◆ construct()

template<class ContainerType , class from_ContainerType , class ... Params>
ContainerType dg::construct ( const from_ContainerType &  from,
Params &&...  ps 
)
inline

Generic way to construct an object of ContainerType given a from_ContainerType object and optional additional parameters.

The idea of this function is to convert between types with the same data layout but different execution policies (e.g. from a thrust::host_vector to a thrust::device_vector) If the layout differs, additional parameters can be used to achieve what you want.

For example

dg::HVec host( 100, 1.);
dg::DVec device = dg::construct<dg::DVec>( host );
std::array<dg::DVec, 3> device_arr = dg::construct<std::array<dg::DVec, 3>>( host );
//let us construct a std::vector of 3 dg::DVec from a host vector
std::vector<dg::DVec> device_vec = dg::construct<std::vector<dg::DVec>>( host, 3);
Parameters
fromsource vector
psadditional parameters necessary to construct a ContainerType object
Returns
from converted to the new format (memory is allocated accordingly)
Note
it is possible to construct a std::array<ContainerType, N> (all elements are initialized with from_ContainerType) and also a std::vector<ContainerType> ( the desired size of the std::vector must be provided as an additional parameter) given a from_ContainerType
Template Parameters
from_ContainerTypemust have the same data policy derived from AnyVectorTag as ContainerType (with the exception of std::array and std::vector) but can have different execution policy
Paramsin some cases additional parameters that are necessary to construct objects of Type ContainerType
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