Discontinuous Galerkin Library
#include "dg/algorithm.h"
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
11#endif
12
17namespace dg
18{
33template< class Geometry, class Matrix, class Container >
35{
36 using geometry_type = Geometry;
37 using matrix_type = Matrix;
38 using container_type = Container;
40 ArakawaX() = default;
46 ArakawaX( const Geometry& g);
54 ArakawaX( const Geometry& g, bc bcx, bc bcy);
55
62 template<class ...Params>
63 void construct( Params&& ...ps)
64 {
65 //construct and swap
66 *this = ArakawaX( std::forward<Params>( ps)...);
67 }
68
80 template<class ContainerType0, class ContainerType1, class ContainerType2>
81 void operator()( const ContainerType0& lhs, const ContainerType1& rhs, ContainerType2& result){
82 return this->operator()( 1., lhs, rhs, 0., result);
83 }
84 template<class ContainerType0, class ContainerType1, class ContainerType2>
85 void operator()( value_type alpha, const ContainerType0& lhs, const ContainerType1& rhs, value_type beta, ContainerType2& result);
92 template<class ContainerType0>
93 void set_chi( const ContainerType0& new_chi) {
94 dg::blas1::pointwiseDivide( new_chi, m_perp_vol, m_chi);
95 }
96
103 const Matrix& dx() const {
104 return m_bdxf;
105 }
112 const Matrix& dy() const {
113 return m_bdyf;
114 }
115
116 private:
117 Container m_dxlhs, m_dxrhs, m_dylhs, m_dyrhs, m_helper;
118 Matrix m_bdxf, m_bdyf;
119 Container m_chi, m_perp_vol;
120};
122template<class Geometry, class Matrix, class Container>
124 ArakawaX( g, g.bcx(), g.bcy()) { }
125
126template<class Geometry, class Matrix, class Container>
127ArakawaX<Geometry, Matrix, Container>::ArakawaX( const Geometry& g, bc bcx, bc bcy):
128 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),
129 m_bdxf(dg::create::dx( g, bcx, dg::centered)),
130 m_bdyf(dg::create::dy( g, bcy, dg::centered))
131{
132 m_chi = m_perp_vol = dg::tensor::volume2d(g.metric());
133 dg::blas1::pointwiseDivide( 1., m_perp_vol, m_chi);
134}
135
136template<class T>
137struct ArakawaFunctor
138{
140 void operator()(T lhs, T rhs, T dxlhs, T& dylhs, T& dxrhs, T& dyrhs) const
141 {
142 T result = T(0);
143 result = DG_FMA( (1./3.)*dxlhs, dyrhs, result);
144 result = DG_FMA( -(1./3.)*dylhs, dxrhs, result);
145 T temp = T(0);
146 temp = DG_FMA( (1./3.)*lhs, dyrhs, temp);
147 dyrhs = result;
148 temp = DG_FMA( -(1./3.)*dylhs, rhs, temp);
149 dylhs = temp;
150 temp = T(0);
151 temp = DG_FMA( (1./3.)*dxlhs, rhs, temp);
152 temp = DG_FMA( -(1./3.)*lhs, dxrhs, temp);
153 dxrhs = temp;
154 }
155};
156
157template< class Geometry, class Matrix, class Container>
158template<class ContainerType0, class ContainerType1, class ContainerType2>
159void ArakawaX< Geometry, Matrix, Container>::operator()( value_type alpha, const ContainerType0& lhs, const ContainerType1& rhs, value_type beta, ContainerType2& result)
160{
161 //compute derivatives in x-space
162 blas2::symv( m_bdxf, lhs, m_dxlhs);
163 blas2::symv( m_bdyf, lhs, m_dylhs);
164 blas2::symv( m_bdxf, rhs, m_dxrhs);
165 blas2::symv( m_bdyf, rhs, m_dyrhs);
166 blas1::subroutine( ArakawaFunctor<get_value_type<Container>>(), lhs, rhs, m_dxlhs, m_dylhs, m_dxrhs, m_dyrhs);
167
168 blas2::symv( 1., m_bdxf, m_dylhs, 1., m_dyrhs);
169 blas2::symv( 1., m_bdyf, m_dxrhs, 1., m_dyrhs);
170 blas1::pointwiseDot( alpha, m_chi, m_dyrhs, beta, result);
171}
173
174}//namespace dg
175
176#endif //_DG_ARAKAWA_CUH
enums
Function discretization routines.
DG_DEVICE T one(T x, Ts ...xs)
Definition functions.h:24
void pointwiseDot(value_type alpha, const ContainerType1 &x1, const ContainerType2 &x2, value_type1 beta, ContainerType &y)
Definition blas1.h:406
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:792
void subroutine(Subroutine f, ContainerType &&x, ContainerTypes &&... xs)
; Customizable and generic blas1 function
Definition blas1.h:677
void pointwiseDivide(value_type alpha, const ContainerType1 &x1, const ContainerType2 &x2, value_type1 beta, ContainerType &y)
Definition blas1.h:495
void symv(MatrixType &&M, const ContainerType1 &x, ContainerType2 &y)
Definition blas2.h:325
auto dx(const Topology &g, dg::bc bc, dg::direction dir=centered)
Definition derivativesT.h:14
auto dy(const Topology &g, dg::bc bc, dg::direction dir=centered)
Short for dg::create::derivative( 1, g, bc, dir);
Definition derivativesT.h:21
bc
Switch between boundary conditions.
Definition enums.h:15
@ centered
centered derivative (cell to the left and right and current cell)
Definition enums.h:100
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition tensor_traits.h:45
auto evaluate(Functor &&f, const Topology &g)
Evaluate a function on grid coordinates
Definition evaluation.h:74
ContainerType volume2d(const SparseTensor< ContainerType > &t)
Definition multiply.h:362
#define DG_DEVICE
Expands to __host__ __device__ if compiled with nvcc else is empty.
Definition dg_doc.h:378
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:35
void set_chi(const ContainerType0 &new_chi)
Change Chi.
Definition arakawa.h:93
ArakawaX(const Geometry &g)
Create Arakawa on a grid.
void construct(Params &&...ps)
Perfect forward parameters to one of the constructors.
Definition arakawa.h:63
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:112
Matrix matrix_type
Definition arakawa.h:37
Container container_type
Definition arakawa.h:38
void operator()(const ContainerType0 &lhs, const ContainerType1 &rhs, ContainerType2 &result)
Compute Poisson bracket.
Definition arakawa.h:81
const Matrix & dx() const
Return internally used x - derivative.
Definition arakawa.h:103
ArakawaX()=default
void operator()(value_type alpha, const ContainerType0 &lhs, const ContainerType1 &rhs, value_type beta, ContainerType2 &result)
Geometry geometry_type
Definition arakawa.h:36
get_value_type< Container > value_type
Definition arakawa.h:39