Discontinuous Galerkin Library
#include "dg/algorithm.h"
Loading...
Searching...
No Matches
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
11#endif
12
17namespace dg
18{
19
31template< class Geometry, class Matrix, class Container >
32struct Poisson
33{
34 using geometry_type = Geometry;
38 Poisson() = default;
44 Poisson( const Geometry& g);
52 Poisson( const Geometry& g, bc bcx, bc bcy);
62 Poisson( const Geometry& g, bc bcxlhs, bc bcylhs, bc bcxrhs, bc bcyrhs );
73 template<class ContainerType0, class ContainerType1, class ContainerType2>
74 void operator()( const ContainerType0& lhs, const ContainerType1& rhs, ContainerType2& result);
81 template<class ContainerType0>
82 void set_chi( const ContainerType0& new_chi) {
83 dg::blas1::pointwiseDivide( new_chi, m_perp_vol, m_chi);
84 }
85
92 const Matrix& dxlhs() const {
93 return m_dxlhs;
94 }
101 const Matrix& dylhs() const {
102 return m_dylhs;
103 }
110 const Matrix& dxrhs() const {
111 return m_dxrhs;}
118 const Matrix& dyrhs() {
119 return m_dyrhs;
120 }
121
122 private:
123 Container m_dxlhslhs, m_dxrhsrhs, m_dylhslhs, m_dyrhsrhs, m_helper;
124 Matrix m_dxlhs, m_dylhs, m_dxrhs, m_dyrhs;
125 Container m_chi, m_perp_vol;
126};
127
129//idea: backward transform lhs and rhs and then use bdxf and bdyf , then forward transform
130//needs less memory!! and is faster
131template< class Geometry, class Matrix, class Container>
133 Poisson( g, g.bcx(), g.bcy(), g.bcx(), g.bcy()){}
134
135template< class Geometry, class Matrix, class Container>
136Poisson<Geometry, Matrix, Container>::Poisson( const Geometry& g, bc bcx, bc bcy):
137 Poisson( g, bcx, bcy, bcx, bcy){}
138
139template< class Geometry, class Matrix, class Container>
140Poisson<Geometry, Matrix, Container>::Poisson( const Geometry& g, bc bcxlhs, bc bcylhs, bc bcxrhs, bc bcyrhs):
141 m_dxlhslhs( dg::evaluate( one, g) ), m_dxrhsrhs(m_dxlhslhs), m_dylhslhs(m_dxlhslhs), m_dyrhsrhs( m_dxlhslhs), m_helper( m_dxlhslhs),
142 m_dxlhs(dg::create::dx( g, bcxlhs, dg::centered)),
143 m_dylhs(dg::create::dy( g, bcylhs, dg::centered)),
144 m_dxrhs(dg::create::dx( g, bcxrhs, dg::centered)),
145 m_dyrhs(dg::create::dy( g, bcyrhs, dg::centered))
146{
147 m_chi = m_perp_vol = dg::tensor::volume2d(g.metric());
148 dg::blas1::pointwiseDivide( 1., m_perp_vol, m_chi);
149}
150
151template< class Geometry, class Matrix, class Container>
152template<class ContainerType0, class ContainerType1, class ContainerType2>
153void Poisson< Geometry, Matrix, Container>::operator()( const ContainerType0& lhs, const ContainerType1& rhs, ContainerType2& result)
154{
155 blas2::symv( m_dxlhs, lhs, m_dxlhslhs); //dx_lhs lhs
156 blas2::symv( m_dylhs, lhs, m_dylhslhs); //dy_lhs lhs
157 blas2::symv( m_dxrhs, rhs, m_dxrhsrhs); //dx_rhs rhs
158 blas2::symv( m_dyrhs, rhs, m_dyrhsrhs); //dy_rhs rhs
159
160 blas1::pointwiseDot( 1., m_dxlhslhs, m_dyrhsrhs, -1., m_dylhslhs, m_dxrhsrhs, 0., result);
161 blas1::pointwiseDot( m_chi, result, result);
162}
164
165}//namespace dg
166
167#endif //_DG_POISSON_CUH
enums
Function discretization routines.
DG_DEVICE T one(T, Ts ...)
Definition functions.h:24
void pointwiseDot(value_type alpha, const ContainerType1 &x1, const ContainerType2 &x2, value_type1 beta, ContainerType &y)
Definition blas1.h:406
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
dg::HVec Container
dg::bc bcy
dg::bc bcx
Function discretization routines for mpi vectors.
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Ell Sparse Block Matrix format.
Definition sparseblockmat.h:46
Direct discretization of Poisson bracket .
Definition poisson.h:33
const Matrix & dylhs() const
Return internally used y - derivative.
Definition poisson.h:101
const Matrix & dxrhs() const
Return internally used x - derivative.
Definition poisson.h:110
const Matrix & dxlhs() const
Return internally used x - derivative.
Definition poisson.h:92
Poisson(const Geometry &g, bc bcx, bc bcy)
Create Poisson on a grid using different boundary conditions.
Geometry geometry_type
Definition poisson.h:34
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:118
get_value_type< Container > value_type
Definition poisson.h:37
Poisson(const Geometry &g)
Create Poisson on a grid.
Container container_type
Definition poisson.h:36
void set_chi(const ContainerType0 &new_chi)
Change Chi.
Definition poisson.h:82
Poisson()=default
void operator()(const ContainerType0 &lhs, const ContainerType1 &rhs, ContainerType2 &result)
Compute poisson's bracket.