Discontinuous Galerkin Library
#include "dg/algorithm.h"
Loading...
Searching...
No Matches

Topological average computations in a Cartesian topology. More...

Public Types

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

Public Member Functions

 Average ()=default
 No allocation.
 
template<class Topology , size_t Md>
 Average (const Topology &g, std::array< unsigned, Md > axes)
 Average along given axes.
 
template<class Topology , typename = std::enable_if_t<Topology::ndim() == 2>>
 Average (const Topology &g, enum coo2d axes)
 Average along given axes.
 
template<class Topology , typename = std::enable_if_t<Topology::ndim() == 3>>
 Average (const Topology &g, enum coo3d axes)
 Average along given axes.
 
template<class Topology , typename = std::enable_if_t<Topology::ndim() == 3>>
 Average (const Topology &g, std::array< enum coo3d, 2 > axes)
 Average along given axes.
 
void operator() (const ContainerType &src, ContainerType &res, bool extend=true)
 Compute the average as configured in the constructor.
 

Detailed Description

template<class IMatrix, class ContainerType>
struct dg::Average< IMatrix, ContainerType >

Topological average computations in a Cartesian topology.

\begin{align} \langle f \rangle_x := \frac{1}{L_x}\int_0^{L_x}dx f \quad \langle f \rangle_y := \frac{1}{L_y}\int_0^{L_y}dy f \quad \langle f \rangle_z := \frac{1}{L_z}\int_0^{L_z}dz f \\ \langle f \rangle_{xy} := \frac{1}{L_xL_y}\int_0^{L_x}\int_0^{L_y}dxdy f \quad \langle f \rangle_{xz} := \frac{1}{L_xL_z}\int_0^{L_x}\int_0^{L_z}dxdz f \quad \langle f \rangle_{yz} := \frac{1}{L_yL_z}\int_0^{L_y}\int_0^{L_z}dydz f \quad \end{align}

Given a Cartesian topology it is possible to define a partial reduction of a given vector. In two dimensions for example we can define a reduction over all points that are neighbors in the x (or y) direction. We are then left with Ny (Nx) points. In three dimensions we can define the reduction along the x, y, z directions but also over all points in the xy (xz or yz) planes. We are left with two- (respectively three-)dimensional vectors.

See also
Average is essentially a dg::create::projection(std::array<unsigned,Md>,const aRealTopology<real_type,Nd>&) scaled with the inverse area
Note
The integrals include the dG weights but not the volume element (does not know about geometry)
const dg::x::DVec vector = dg::evaluate( function ,g);
dg::x::DVec average_y;
pol( vector, average_y, false);
const dg::x::DVec w1d = dg::create::weights( g.gx());
dg::x::DVec solution = dg::evaluate( pol_average, g.gx());
dg::blas1::axpby( 1., solution, -1., average_y);
double res = sqrt( dg::blas2::dot( average_y, w1d, average_y));
INFO("Distance to solution is: "<<res<<"\t(Should be 0)");
CHECK_THAT( res, WithinAbs( 0.0, 1e-13));

Member Typedef Documentation

◆ container_type

template<class IMatrix , class ContainerType >
using dg::Average< IMatrix, ContainerType >::container_type = ContainerType

◆ value_type

template<class IMatrix , class ContainerType >
using dg::Average< IMatrix, ContainerType >::value_type = dg::get_value_type<ContainerType>

Constructor & Destructor Documentation

◆ Average() [1/5]

template<class IMatrix , class ContainerType >
dg::Average< IMatrix, ContainerType >::Average ( )
default

No allocation.

◆ Average() [2/5]

template<class IMatrix , class ContainerType >
template<class Topology , size_t Md>
dg::Average< IMatrix, ContainerType >::Average ( const Topology & g,
std::array< unsigned, Md > axes )
inline

Average along given axes.

Template Parameters
MdNumber of dimensions to reduce Md<Topology::ndim()
Parameters
axesAxis numbers in g_old along which to reduce axes[i]<g_old.ndim(). Can be a named dimension from dg::coo2d or dg::coo3d
gGrid of the old, un-reduced vectors
See also
dg::create::projection

◆ Average() [3/5]

template<class IMatrix , class ContainerType >
template<class Topology , typename = std::enable_if_t<Topology::ndim() == 2>>
dg::Average< IMatrix, ContainerType >::Average ( const Topology & g,
enum coo2d axes )
inline

Average along given axes.

Template Parameters
MdNumber of dimensions to reduce Md<Topology::ndim()
Parameters
axesAxis numbers in g_old along which to reduce axes[i]<g_old.ndim(). Can be a named dimension from dg::coo2d or dg::coo3d
gGrid of the old, un-reduced vectors
See also
dg::create::projection

◆ Average() [4/5]

template<class IMatrix , class ContainerType >
template<class Topology , typename = std::enable_if_t<Topology::ndim() == 3>>
dg::Average< IMatrix, ContainerType >::Average ( const Topology & g,
enum coo3d axes )
inline

Average along given axes.

Template Parameters
MdNumber of dimensions to reduce Md<Topology::ndim()
Parameters
axesAxis numbers in g_old along which to reduce axes[i]<g_old.ndim(). Can be a named dimension from dg::coo2d or dg::coo3d
gGrid of the old, un-reduced vectors
See also
dg::create::projection

◆ Average() [5/5]

template<class IMatrix , class ContainerType >
template<class Topology , typename = std::enable_if_t<Topology::ndim() == 3>>
dg::Average< IMatrix, ContainerType >::Average ( const Topology & g,
std::array< enum coo3d, 2 > axes )
inline

Average along given axes.

Template Parameters
MdNumber of dimensions to reduce Md<Topology::ndim()
Parameters
axesAxis numbers in g_old along which to reduce axes[i]<g_old.ndim(). Can be a named dimension from dg::coo2d or dg::coo3d
gGrid of the old, un-reduced vectors
See also
dg::create::projection

Member Function Documentation

◆ operator()()

template<class IMatrix , class ContainerType >
void dg::Average< IMatrix, ContainerType >::operator() ( const ContainerType & src,
ContainerType & res,
bool extend = true )
inline

Compute the average as configured in the constructor.

The compuatation is divided in two steps:

  1. average the input field over the direction or plane given in the constructor
  2. [optionally] extend the lower dimensional result back to the original dimensionality
Parameters
srcSource Vector (must have the same size as the grid given in the constructor)
resresult Vector (if extend==true, res must have same size as src vector, else it gets properly resized, may alias src)
extendif true the average is extended back to the original dimensionality, if false, this step is skipped

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