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

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

Public Types

using container_type = ContainerType
 

Public Member Functions

 Average (const aTopology2d &g, enum coo2d direction, std::string mode="exact")
 Prepare internal workspace. More...
 
 Average (const aTopology3d &g, enum coo3d direction, std::string mode="exact")
 Prepare internal workspace. More...
 
void operator() (const ContainerType &src, ContainerType &res, bool extend=true)
 Compute the average as configured in the constructor. More...
 

Detailed Description

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

Topological average computations in a Cartesian topology.

\[ \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 \]

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.

Note
The integrals include the dG weights but not the volume element (does not know about geometry)
const dg::Grid2d g( 0, lx, 0, ly, n, Nx, Ny);
const dg::DVec vector = dg::evaluate( function ,g);
dg::DVec average_y;
std::cout << "Averaging y ... \n";
pol( vector, average_y, false);
@ y
y direction
thrust::host_vector< real_type > evaluate(UnaryOp f, const RealGrid1d< real_type > &g)
Evaluate a 1d function on grid coordinates.
Definition: evaluation.h:67
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
Topological average computations in a Cartesian topology.
Definition: average.h:53

Member Typedef Documentation

◆ container_type

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

Constructor & Destructor Documentation

◆ Average() [1/2]

template<class ContainerType >
dg::Average< ContainerType >::Average ( const aTopology2d g,
enum coo2d  direction,
std::string  mode = "exact" 
)
inline

Prepare internal workspace.

Parameters
gthe grid from which to take the dimensionality and sizes
directionthe direction or plane over which to average when calling operator() (at the moment cannot be coo3d::xz or coo3d::y)
modeeither "exact" ( uses the exact and reproducible dot product for the summation) or "simple" (uses inexact but much faster direct summation) use simple if you do not need the reproducibility
Note
computing in "exact" mode is especially difficult if the averaged direction is small compared to the remaining dimensions and for GPUs in general, expect to gain a factor 10-1000 (no joke) from going to "simple" mode in these cases

◆ Average() [2/2]

template<class ContainerType >
dg::Average< ContainerType >::Average ( const aTopology3d g,
enum coo3d  direction,
std::string  mode = "exact" 
)
inline

Prepare internal workspace.

Parameters
gthe grid from which to take the dimensionality and sizes
directionthe direction or plane over which to average when calling operator() (at the moment cannot be coo3d::xz or coo3d::y)
modeeither "exact" ( uses the exact and reproducible dot product for the summation) or "simple" (uses inexact but much faster direct summation) use simple if you do not need the reproducibility
Note
computing in "exact" mode is especially difficult if the averaged direction is small compared to the remaining dimensions and for GPUs in general, expect to gain a factor 10-1000 (no joke) from going to "simple" mode in these cases

Member Function Documentation

◆ operator()()

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

Compute the average as configured in the constructor.

The compuatation is based on the exact, reproducible scalar product provided in the dg::exblas library. It is divided in two steps

  • average the input field over the direction or plane given in the constructor
  • 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: