Discontinuous Galerkin Library
#include "dg/algorithm.h"
poisson.h
Go to the documentation of this file.
1#ifndef _DG_POISSON_CUH
2#define _DG_POISSON_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{
20
32template< class Geometry, class Matrix, class Container >
33struct Poisson
34{
35 using geometry_type = Geometry;
36 using matrix_type = Matrix;
37 using container_type = Container;
39 Poisson() = default;
45 Poisson( const Geometry& g);
53 Poisson( const Geometry& g, bc bcx, bc bcy);
63 Poisson( const Geometry& g, bc bcxlhs, bc bcylhs, bc bcxrhs, bc bcyrhs );
74 template<class ContainerType0, class ContainerType1, class ContainerType2>
75 void operator()( const ContainerType0& lhs, const ContainerType1& rhs, ContainerType2& result);
82 template<class ContainerType0>
83 void set_chi( const ContainerType0& new_chi) {
84 dg::blas1::pointwiseDivide( new_chi, m_perp_vol, m_chi);
85 }
86
93 const Matrix& dxlhs() const {
94 return m_dxlhs;
95 }
102 const Matrix& dylhs() const {
103 return m_dylhs;
104 }
111 const Matrix& dxrhs() const {
112 return m_dxrhs;}
119 const Matrix& dyrhs() {
120 return m_dyrhs;
121 }
122
123 private:
124 Container m_dxlhslhs, m_dxrhsrhs, m_dylhslhs, m_dyrhsrhs, m_helper;
125 Matrix m_dxlhs, m_dylhs, m_dxrhs, m_dyrhs;
126 Container m_chi, m_perp_vol;
127};
128
130//idea: backward transform lhs and rhs and then use bdxf and bdyf , then forward transform
131//needs less memory!! and is faster
132template< class Geometry, class Matrix, class Container>
134 Poisson( g, g.bcx(), g.bcy(), g.bcx(), g.bcy()){}
135
136template< class Geometry, class Matrix, class Container>
137Poisson<Geometry, Matrix, Container>::Poisson( const Geometry& g, bc bcx, bc bcy):
138 Poisson( g, bcx, bcy, bcx, bcy){}
139
140template< class Geometry, class Matrix, class Container>
141Poisson<Geometry, Matrix, Container>::Poisson( const Geometry& g, bc bcxlhs, bc bcylhs, bc bcxrhs, bc bcyrhs):
142 m_dxlhslhs( dg::evaluate( one, g) ), m_dxrhsrhs(m_dxlhslhs), m_dylhslhs(m_dxlhslhs), m_dyrhsrhs( m_dxlhslhs), m_helper( m_dxlhslhs),
143 m_dxlhs(dg::create::dx( g, bcxlhs, dg::centered)),
144 m_dylhs(dg::create::dy( g, bcylhs, dg::centered)),
145 m_dxrhs(dg::create::dx( g, bcxrhs, dg::centered)),
146 m_dyrhs(dg::create::dy( g, bcyrhs, dg::centered))
147{
148 m_chi = m_perp_vol = dg::tensor::volume2d(g.metric());
149 dg::blas1::pointwiseDivide( 1., m_perp_vol, m_chi);
150}
151
152template< class Geometry, class Matrix, class Container>
153template<class ContainerType0, class ContainerType1, class ContainerType2>
154void Poisson< Geometry, Matrix, Container>::operator()( const ContainerType0& lhs, const ContainerType1& rhs, ContainerType2& result)
155{
156 blas2::symv( m_dxlhs, lhs, m_dxlhslhs); //dx_lhs lhs
157 blas2::symv( m_dylhs, lhs, m_dylhslhs); //dy_lhs lhs
158 blas2::symv( m_dxrhs, rhs, m_dxrhsrhs); //dx_rhs rhs
159 blas2::symv( m_dyrhs, rhs, m_dyrhsrhs); //dy_rhs rhs
160
161 blas1::pointwiseDot( 1., m_dxlhslhs, m_dyrhsrhs, -1., m_dylhslhs, m_dxrhsrhs, 0., result);
162 blas1::pointwiseDot( m_chi, result, result);
163}
165
166}//namespace dg
167
168#endif //_DG_POISSON_CUH
Convenience functions to create 2D derivatives.
enums
Function discretization routines.
static DG_DEVICE double one(double x)
Definition: functions.h:20
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...
Direct discretization of Poisson bracket .
Definition: poisson.h:34
const Matrix & dylhs() const
Return internally used y - derivative.
Definition: poisson.h:102
const Matrix & dxrhs() const
Return internally used x - derivative.
Definition: poisson.h:111
const Matrix & dxlhs() const
Return internally used x - derivative.
Definition: poisson.h:93
Poisson(const Geometry &g, bc bcx, bc bcy)
Create Poisson on a grid using different boundary conditions.
Geometry geometry_type
Definition: poisson.h:35
Poisson(const Geometry &g, bc bcxlhs, bc bcylhs, bc bcxrhs, bc bcyrhs)
Create Poisson on a grid using different boundary conditions.
const Matrix & dyrhs()
Return internally used y - derivative.
Definition: poisson.h:119
get_value_type< Container > value_type
Definition: poisson.h:38
Poisson(const Geometry &g)
Create Poisson on a grid.
Container container_type
Definition: poisson.h:37
void set_chi(const ContainerType0 &new_chi)
Change Chi.
Definition: poisson.h:83
Matrix matrix_type
Definition: poisson.h:36
Poisson()=default
void operator()(const ContainerType0 &lhs, const ContainerType1 &rhs, ContainerType2 &result)
Compute poisson's bracket.