Discontinuous Galerkin Library
#include "dg/algorithm.h"
advection.h
Go to the documentation of this file.
1#ifndef _DG_ADVECTION_H
2#define _DG_ADVECTION_H
3#include "blas.h"
4#include "topology/geometry.h"
5#include "enums.h"
8#ifdef MPI_VERSION
11#endif
16namespace dg
17{
18
19 //MW this scheme cannot be formulated as a weak form
20
42template< class Geometry, class Matrix, class Container >
44{
45 using geometry_type = Geometry;
46 using matrix_type = Matrix;
47 using container_type = Container;
49 Advection() = default;
54 Advection( const Geometry& g);
61 Advection( const Geometry& g, bc bcx, bc bcy);
62
69 template<class ...Params>
70 void construct( Params&& ...ps)
71 {
72 //construct and swap
73 *this = Advection( std::forward<Params>( ps)...);
74 }
75
88 template<class ContainerType0, class ContainerType1, class ContainerType2, class ContainerType3>
89 void upwind( value_type alpha, const ContainerType0& vx, const ContainerType1& vy, const ContainerType2& f, value_type beta, ContainerType3& result);
90
91 private:
92 Container m_temp0, m_temp1;
93 Matrix m_dxf, m_dyf, m_dxb, m_dyb;
94};
95
97template<class Geometry, class Matrix, class Container>
99 Advection( g, g.bcx(), g.bcy()) { }
100
101template<class Geometry, class Matrix, class Container>
102Advection<Geometry, Matrix, Container>::Advection( const Geometry& g, bc bcx, bc bcy):
103 m_temp0( dg::construct<Container>(dg::evaluate( one, g)) ), m_temp1(m_temp0),
104 m_dxf(dg::create::dx( g, bcx, dg::forward)),
105 m_dyf(dg::create::dy( g, bcy, dg::forward)),
106 m_dxb(dg::create::dx( g, bcx, dg::backward)),
107 m_dyb(dg::create::dy( g, bcy, dg::backward))
108{
109}
110
111template< class Geometry, class Matrix, class Container>
112template<class ContainerType0, class ContainerType1, class ContainerType2, class ContainerType3>
113void Advection<Geometry, Matrix, Container>::upwind( value_type alpha, const ContainerType0& vx, const ContainerType1& vy, const ContainerType2& f, value_type beta, ContainerType3& result)
114{
115 blas2::symv( m_dxb, f, m_temp0);
116 blas2::symv( m_dxf, f, m_temp1);
117 blas1::evaluate( result, dg::Axpby<value_type>( alpha, beta), dg::UpwindProduct(), vx, m_temp0, m_temp1);
118 blas2::symv( m_dyb, f, m_temp0);
119 blas2::symv( m_dyf, f, m_temp1);
120 blas1::evaluate( result, dg::Axpby<value_type>( alpha, 1.), dg::UpwindProduct(), vy, m_temp0, m_temp1);
121}
123
124}//namespace dg
125
126
127#endif //_DG_ADVECTION_H
Convenience functions to create 2D derivatives.
enums
Function discretization routines.
ContainerType construct(const from_ContainerType &from, Params &&... ps)
Generic way to construct an object of ContainerType given a from_ContainerType object and optional ad...
Definition: blas1.h:696
static DG_DEVICE double one(double x)
Definition: functions.h:20
void evaluate(ContainerType &y, BinarySubroutine f, Functor g, const ContainerType0 &x0, const ContainerTypes &...xs)
Definition: blas1.h:556
void symv(MatrixType &&M, const ContainerType1 &x, ContainerType2 &y)
Definition: blas2.h:287
EllSparseBlockMat< real_type > dx(const aRealTopology2d< real_type > &g, bc bcx, direction dir=centered)
Create 2d derivative in x-direction.
Definition: derivatives.h:33
bc
Switch between boundary conditions.
Definition: enums.h:15
EllSparseBlockMat< real_type > dy(const aRealTopology2d< real_type > &g, bc bcy, direction dir=centered)
Create 2d derivative in y-direction.
Definition: derivatives.h:65
@ backward
backward derivative (cell to the left and current cell)
Definition: enums.h:99
@ forward
forward derivative (cell to the right and current cell)
Definition: enums.h:98
thrust::host_vector< real_type > evaluate(UnaryOp f, const RealGrid1d< real_type > &g)
Evaluate a 1d function on grid coordinates.
Definition: evaluation.h:67
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition: tensor_traits.h:38
Function discretization routines for mpi vectors.
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Upwind discretization of advection operator
Definition: advection.h:44
void upwind(value_type alpha, const ContainerType0 &vx, const ContainerType1 &vy, const ContainerType2 &f, value_type beta, ContainerType3 &result)
Compute Advection term .
Container container_type
Definition: advection.h:47
void construct(Params &&...ps)
Perfect forward parameters to one of the constructors.
Definition: advection.h:70
Advection(const Geometry &g, bc bcx, bc bcy)
Create Advection on a grid using different boundary conditions.
get_value_type< Container > value_type
Definition: advection.h:48
Advection(const Geometry &g)
Create Arakawa on a grid.
Advection()=default
Matrix matrix_type
Definition: advection.h:46
Geometry geometry_type
Definition: advection.h:45
Definition: subroutines.h:245
Definition: functors.h:371