Discontinuous Galerkin Library
#include "dg/algorithm.h"
arakawa.h
Go to the documentation of this file.
1#ifndef _DG_ARAKAWA_CUH
2#define _DG_ARAKAWA_CUH
3
4#include "blas.h"
5#include "topology/geometry.h"
6#include "enums.h"
9#ifdef MPI_VERSION
12#endif
13
18namespace dg
19{
34template< class Geometry, class Matrix, class Container >
36{
37 using geometry_type = Geometry;
38 using matrix_type = Matrix;
39 using container_type = Container;
41 ArakawaX() = default;
47 ArakawaX( const Geometry& g);
55 ArakawaX( const Geometry& g, bc bcx, bc bcy);
56
63 template<class ...Params>
64 void construct( Params&& ...ps)
65 {
66 //construct and swap
67 *this = ArakawaX( std::forward<Params>( ps)...);
68 }
69
81 template<class ContainerType0, class ContainerType1, class ContainerType2>
82 void operator()( const ContainerType0& lhs, const ContainerType1& rhs, ContainerType2& result){
83 return this->operator()( 1., lhs, rhs, 0., result);
84 }
85 template<class ContainerType0, class ContainerType1, class ContainerType2>
86 void operator()( value_type alpha, const ContainerType0& lhs, const ContainerType1& rhs, value_type beta, ContainerType2& result);
93 template<class ContainerType0>
94 void set_chi( const ContainerType0& new_chi) {
95 dg::blas1::pointwiseDivide( new_chi, m_perp_vol, m_chi);
96 }
97
104 const Matrix& dx() const {
105 return m_bdxf;
106 }
113 const Matrix& dy() const {
114 return m_bdyf;
115 }
116
117 private:
118 Container m_dxlhs, m_dxrhs, m_dylhs, m_dyrhs, m_helper;
119 Matrix m_bdxf, m_bdyf;
120 Container m_chi, m_perp_vol;
121};
123template<class Geometry, class Matrix, class Container>
125 ArakawaX( g, g.bcx(), g.bcy()) { }
126
127template<class Geometry, class Matrix, class Container>
128ArakawaX<Geometry, Matrix, Container>::ArakawaX( const Geometry& g, bc bcx, bc bcy):
129 m_dxlhs( dg::construct<Container>(dg::evaluate( one, g)) ), m_dxrhs(m_dxlhs), m_dylhs(m_dxlhs), m_dyrhs( m_dxlhs), m_helper( m_dxlhs),
130 m_bdxf(dg::create::dx( g, bcx, dg::centered)),
131 m_bdyf(dg::create::dy( g, bcy, dg::centered))
132{
133 m_chi = m_perp_vol = dg::tensor::volume2d(g.metric());
134 dg::blas1::pointwiseDivide( 1., m_perp_vol, m_chi);
135}
136
137template<class T>
138struct ArakawaFunctor
139{
141 void operator()(T lhs, T rhs, T dxlhs, T& dylhs, T& dxrhs, T& dyrhs) const
142 {
143 T result = T(0);
144 result = DG_FMA( (1./3.)*dxlhs, dyrhs, result);
145 result = DG_FMA( -(1./3.)*dylhs, dxrhs, result);
146 T temp = T(0);
147 temp = DG_FMA( (1./3.)*lhs, dyrhs, temp);
148 dyrhs = result;
149 temp = DG_FMA( -(1./3.)*dylhs, rhs, temp);
150 dylhs = temp;
151 temp = T(0);
152 temp = DG_FMA( (1./3.)*dxlhs, rhs, temp);
153 temp = DG_FMA( -(1./3.)*lhs, dxrhs, temp);
154 dxrhs = temp;
155 }
156};
157
158template< class Geometry, class Matrix, class Container>
159template<class ContainerType0, class ContainerType1, class ContainerType2>
160void ArakawaX< Geometry, Matrix, Container>::operator()( value_type alpha, const ContainerType0& lhs, const ContainerType1& rhs, value_type beta, ContainerType2& result)
161{
162 //compute derivatives in x-space
163 blas2::symv( m_bdxf, lhs, m_dxlhs);
164 blas2::symv( m_bdyf, lhs, m_dylhs);
165 blas2::symv( m_bdxf, rhs, m_dxrhs);
166 blas2::symv( m_bdyf, rhs, m_dyrhs);
167 blas1::subroutine( ArakawaFunctor<get_value_type<Container>>(), lhs, rhs, m_dxlhs, m_dylhs, m_dxrhs, m_dyrhs);
168
169 blas2::symv( 1., m_bdxf, m_dylhs, 1., m_dyrhs);
170 blas2::symv( 1., m_bdyf, m_dxrhs, 1., m_dyrhs);
171 blas1::pointwiseDot( alpha, m_chi, m_dyrhs, beta, result);
172}
174
175}//namespace dg
176
177#endif //_DG_ARAKAWA_CUH
Convenience functions to create 2D derivatives.
enums
Function discretization routines.
#define DG_DEVICE
Expands to __host__ __device__ if compiled with nvcc else is empty.
Definition: functions.h:9
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 subroutine(Subroutine f, ContainerType &&x, ContainerTypes &&... xs)
; Customizable and generic blas1 function
Definition: blas1.h:618
void pointwiseDivide(get_value_type< ContainerType > alpha, const ContainerType1 &x1, const ContainerType2 &x2, get_value_type< ContainerType > beta, ContainerType &y)
Definition: blas1.h:428
void pointwiseDot(get_value_type< ContainerType > alpha, const ContainerType1 &x1, const ContainerType2 &x2, get_value_type< ContainerType > beta, ContainerType &y)
Definition: blas1.h:336
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
@ centered
centered derivative (cell to the left and right and current cell)
Definition: enums.h:100
thrust::host_vector< real_type > evaluate(UnaryOp f, const RealGrid1d< real_type > &g)
Evaluate a 1d function on grid coordinates.
Definition: evaluation.h:67
ContainerType volume2d(const SparseTensor< ContainerType > &t)
Definition: multiply.h:379
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...
Arakawa's scheme for Poisson bracket .
Definition: arakawa.h:36
void set_chi(const ContainerType0 &new_chi)
Change Chi.
Definition: arakawa.h:94
ArakawaX(const Geometry &g)
Create Arakawa on a grid.
void construct(Params &&...ps)
Perfect forward parameters to one of the constructors.
Definition: arakawa.h:64
ArakawaX(const Geometry &g, bc bcx, bc bcy)
Create Arakawa on a grid using different boundary conditions.
const Matrix & dy() const
Return internally used y - derivative.
Definition: arakawa.h:113
Matrix matrix_type
Definition: arakawa.h:38
Container container_type
Definition: arakawa.h:39
void operator()(const ContainerType0 &lhs, const ContainerType1 &rhs, ContainerType2 &result)
Compute Poisson bracket.
Definition: arakawa.h:82
const Matrix & dx() const
Return internally used x - derivative.
Definition: arakawa.h:104
ArakawaX()=default
void operator()(value_type alpha, const ContainerType0 &lhs, const ContainerType1 &rhs, value_type beta, ContainerType2 &result)
Geometry geometry_type
Definition: arakawa.h:37
get_value_type< Container > value_type
Definition: arakawa.h:40