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

1D grid More...

Public Types

using value_type = real_type
 
using host_vector = thrust::host_vector< real_type >
 The host vector type used by host functions like evaluate. More...
 
using host_grid = RealGrid1d< real_type >
 

Public Member Functions

 RealGrid1d ()=default
 construct an empty grid this leaves the access functions undefined More...
 
 RealGrid1d (real_type x0, real_type x1, unsigned n, unsigned N, bc bcx=PER)
 1D grid More...
 
real_type x0 () const
 left boundary More...
 
real_type x1 () const
 right boundary More...
 
real_type lx () const
 total length of interval More...
 
real_type h () const
 cell size More...
 
unsigned N () const
 number of cells More...
 
unsigned n () const
 number of polynomial coefficients More...
 
bc bcx () const
 boundary conditions More...
 
void set (real_type x0, real_type x1, bc bcx)
 reset the boundaries of the grid More...
 
void set (unsigned n, unsigned N)
 reset the cell numbers in the grid More...
 
void set (real_type x0, real_type x1, unsigned n, unsigned N, bc bcx)
 Reset all values of the grid. More...
 
unsigned size () const
 n()*N() (Total number of grid points) More...
 
const DLT< real_type > & dlt () const
 the discrete legendre transformation More...
 
void display (std::ostream &os=std::cout) const
 
void shift (bool &negative, real_type &x) const
 Shift any point coordinate to a corresponding grid coordinate according to the boundary condition. More...
 
void shift (bool &negative, real_type &x, bc bcx) const
 Shift any point coordinate to a corresponding grid coordinate according to the boundary condition. More...
 
bool contains (real_type x) const
 Check if the grid contains a point. More...
 

Detailed Description

template<class real_type>
struct dg::RealGrid1d< real_type >

1D grid

This code snippet demonstrates how to discretize and integrate a function

// create a one-dimensional grid on the domain [0,2] with 3 polynomial coefficients and 20 cells
dg::Grid1d g1d( 0, 2, 3, 20);
// create the Gaussian weights (volume form) for the integration
const dg::HVec w1d = dg::create::weights( g1d);
// discretize the exponential function on the grid
const dg::HVec vec = dg::evaluate( exp, g1d);
// now compute the scalar product (the integral)
double integral = dg::blas1::dot( w1d, vec);
// integral is now: e^2-1
get_value_type< ContainerType1 > dot(const ContainerType1 &x, const ContainerType2 &y)
Binary reproducible Euclidean dot product between two vectors
Definition: blas1.h:87
thrust::host_vector< real_type > evaluate(UnaryOp f, const RealGrid1d< real_type > &g)
Evaluate a 1d function on grid coordinates.
Definition: evaluation.h:67
MPI_Vector< thrust::host_vector< real_type > > weights(const aRealMPITopology2d< real_type > &g)
Nodal weight coefficients.
Definition: mpi_weights.h:22
thrust::host_vector< double > HVec
Host Vector.
Definition: typedefs.h:19

Member Typedef Documentation

◆ host_grid

template<class real_type >
using dg::RealGrid1d< real_type >::host_grid = RealGrid1d<real_type>

◆ host_vector

template<class real_type >
using dg::RealGrid1d< real_type >::host_vector = thrust::host_vector<real_type>

The host vector type used by host functions like evaluate.

◆ value_type

template<class real_type >
using dg::RealGrid1d< real_type >::value_type = real_type

Constructor & Destructor Documentation

◆ RealGrid1d() [1/2]

template<class real_type >
dg::RealGrid1d< real_type >::RealGrid1d ( )
default

construct an empty grid this leaves the access functions undefined

◆ RealGrid1d() [2/2]

template<class real_type >
dg::RealGrid1d< real_type >::RealGrid1d ( real_type  x0,
real_type  x1,
unsigned  n,
unsigned  N,
bc  bcx = PER 
)
inline

1D grid

Parameters
x0left boundary
x1right boundary
n# of polynomial coefficients (1<=n<=20, note that the library is optimized for n=3 )
N# of cells
bcxboundary conditions

Member Function Documentation

◆ bcx()

template<class real_type >
bc dg::RealGrid1d< real_type >::bcx ( ) const
inline

boundary conditions

Returns

◆ contains()

template<class real_type >
bool dg::RealGrid1d< real_type >::contains ( real_type  x) const
inline

Check if the grid contains a point.

Note
Does not consider periodicity!!
Parameters
xpoint to check
Returns
true if x0()<=x<=x1(), false else
Attention
returns false if x is NaN or INF

◆ display()

template<class real_type >
void dg::RealGrid1d< real_type >::display ( std::ostream &  os = std::cout) const
inline

◆ dlt()

template<class real_type >
const DLT< real_type > & dg::RealGrid1d< real_type >::dlt ( ) const
inline

the discrete legendre transformation

Returns

◆ h()

template<class real_type >
real_type dg::RealGrid1d< real_type >::h ( ) const
inline

cell size

Returns

◆ lx()

template<class real_type >
real_type dg::RealGrid1d< real_type >::lx ( ) const
inline

total length of interval

Returns

◆ N()

template<class real_type >
unsigned dg::RealGrid1d< real_type >::N ( ) const
inline

number of cells

Returns

◆ n()

template<class real_type >
unsigned dg::RealGrid1d< real_type >::n ( ) const
inline

number of polynomial coefficients

Returns

◆ set() [1/3]

template<class real_type >
void dg::RealGrid1d< real_type >::set ( real_type  x0,
real_type  x1,
bc  bcx 
)
inline

reset the boundaries of the grid

Parameters
x0new left boundary
x1new right boundary ( > x0)
bcxnew boundary condition

◆ set() [2/3]

template<class real_type >
void dg::RealGrid1d< real_type >::set ( real_type  x0,
real_type  x1,
unsigned  n,
unsigned  N,
bc  bcx 
)
inline

Reset all values of the grid.

Parameters
x0new left boundary
x1new right boundary
nnew # of polynomial coefficients
Nnew # of cells
bcxnew boundary condition

◆ set() [3/3]

template<class real_type >
void dg::RealGrid1d< real_type >::set ( unsigned  n,
unsigned  N 
)
inline

reset the cell numbers in the grid

Parameters
nnew # of polynomial coefficients (0<n<21)
Nnew # of cells (>0)

◆ shift() [1/2]

template<class real_type >
void dg::RealGrid1d< real_type >::shift ( bool &  negative,
real_type &  x 
) const
inline

Shift any point coordinate to a corresponding grid coordinate according to the boundary condition.

If the given point is already inside the grid, the function does nothing, else along each dimension the following happens: check the boundary condition. If dg::PER, the point will be shifted topologically back onto the domain (modulo operation). Else the point will be mirrored at the closest boundary. If the boundary is a Dirichlet boundary (happens for dg::DIR, dg::DIR_NEU and dg::NEU_DIR; the latter two apply dg::DIR to the respective left or right boundary ) an additional sign flag is swapped. This process is repeated until the result lies inside the grid. This function forms the basis for extending/periodifying a function discretized on the grid beyond the grid boundaries.

See also
interpolate
Note
For periodic boundaries the right boundary point is considered outside the grid and is shifted to the left boundary point.
Parameters
negativeswap value if there was a sign swap (happens when a point is mirrored along a Dirichlet boundary)
xpoint to shift (inout) the result is guaranteed to lie inside the grid

◆ shift() [2/2]

template<class real_type >
void dg::RealGrid1d< real_type >::shift ( bool &  negative,
real_type &  x,
bc  bcx 
) const
inline

Shift any point coordinate to a corresponding grid coordinate according to the boundary condition.

If the given point is already inside the grid, the function does nothing, else along each dimension the following happens: check the boundary condition. If dg::PER, the point will be shifted topologically back onto the domain (modulo operation). Else the point will be mirrored at the closest boundary. If the boundary is a Dirichlet boundary (happens for dg::DIR, dg::DIR_NEU and dg::NEU_DIR; the latter two apply dg::DIR to the respective left or right boundary ) an additional sign flag is swapped. This process is repeated until the result lies inside the grid. This function forms the basis for extending/periodifying a function discretized on the grid beyond the grid boundaries.

See also
interpolate
Note
For periodic boundaries the right boundary point is considered outside the grid and is shifted to the left boundary point.
Parameters
negativeswap value if there was a sign swap (happens when a point is mirrored along a Dirichlet boundary)
xpoint to shift (inout) the result is guaranteed to lie inside the grid
bcxoverrule grid internal boundary condition with this value

◆ size()

template<class real_type >
unsigned dg::RealGrid1d< real_type >::size ( ) const
inline

n()*N() (Total number of grid points)

◆ x0()

template<class real_type >
real_type dg::RealGrid1d< real_type >::x0 ( ) const
inline

left boundary

Returns

◆ x1()

template<class real_type >
real_type dg::RealGrid1d< real_type >::x1 ( ) const
inline

right boundary

Returns

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