Discontinuous Galerkin Library
#include "dg/algorithm.h"
derivativesX.h
Go to the documentation of this file.
1#pragma once
2
3#include "gridX.h"
4#include "dxX.h"
5#include "../blas.h"
6
10namespace dg{
11
12template<class Matrix>
14{
15 Composite( ):m1(), m2(), dual(false){ }
16 template<class Matrix2>
17 Composite( const Composite<Matrix2>& src):m1(src.m1), m2(src.m2), dual(src.dual){}
18 Composite( const Matrix& m):m1(m), m2(m), dual(false){ }
19 Composite( const Matrix& m1, const Matrix& m2):m1(m1), m2(m2), dual(true){ }
20 template<class Matrix2>
22 *this = c; return *this;}
23 template< class ContainerType1, class ContainerType2>
24 void symv( const ContainerType1& v1, ContainerType2& v2) const
25 {
26 dg::blas2::symv( m1, v1, v2); //computes first part
27 if( dual)
28 dg::blas2::symv( m2, v1, v2); //computes second part
29 }
30 template< class ContainerType>
31 void symv( get_value_type<ContainerType> alpha, const ContainerType& v1, get_value_type<ContainerType> beta, ContainerType& v2) const
32 {
33 dg::blas2::symv( alpha, m1, v1, beta, v2); //computes first part
34 if( dual)
35 dg::blas2::symv( alpha, m2, v1, beta, v2); //computes second part
36 }
37 void display( std::ostream& os = std::cout) const
38 {
39 if( dual)
40 {
41 os << " dual matrix: \n";
42 os << " INNER MATRIX\n";
43 m1.display( os);
44 os << " OUTER MATRIX\n";
45 m2.display( os);
46 }
47 else
48 {
49 os << "single matrix: \n";
50 m1.display(os);
51 }
52 }
53 Matrix m1, m2;
54 bool dual;
55};
57template <class Matrix>
58struct TensorTraits<Composite<Matrix> >
59{
62};
64
65
69namespace create{
70
73
74//dx, dy, jumpX, jumpY
75
85template<class real_type>
87{
89 dx = dx_normed( g.n(), g.Nx(), g.hx(), bcx, dir);
90 dx.set_left_size( g.n()*g.Ny());
91 return dx;
92}
93
102template<class real_type>
104
114template<class real_type>
116{
117 EllSparseBlockMat<real_type> dy_inner, dy_outer;
118 RealGridX1d<real_type> g1d_inner( g.y0(), g.y1(), g.fy(), g.n(), g.Ny(), bcy);
119 RealGrid1d<real_type> g1d_outer( g.y0(), g.y1(), g.n(), g.Ny(), bcy);
120 dy_inner = dx( g1d_inner, bcy, dir);
121 dy_outer = dx( g1d_outer, bcy, dir);
122 dy_inner.right_size = g.n()*g.Nx();
123 dy_inner.right_range[0] = 0;
124 dy_inner.right_range[1] = g.n()*g.inner_Nx();
125 dy_outer.right_range[0] = g.n()*g.inner_Nx();
126 dy_outer.right_range[1] = g.n()*g.Nx();
127 dy_outer.right_size = g.n()*g.Nx();
128
129 Composite<EllSparseBlockMat<real_type> > c( dy_inner, dy_outer);
130 return c;
131}
132
141template<class real_type>
143
152template<class real_type>
154{
156 jx = jump( g.n(), g.Nx(), g.hx(), bcx);
157 jx.set_left_size( g.n()*g.Ny());
158 return jx;
159}
160
169template<class real_type>
171{
172 EllSparseBlockMat<real_type> jy_inner, jy_outer;
173 RealGridX1d<real_type> g1d_inner( g.y0(), g.y1(), g.fy(), g.n(), g.Ny(), bcy);
174 RealGrid1d<real_type> g1d_outer( g.y0(), g.y1(), g.n(), g.Ny(), bcy);
175 jy_inner = jump( g1d_inner, bcy);
176 jy_outer = jump( g1d_outer, bcy);
177 jy_inner.right_size = g.n()*g.Nx();
178 jy_inner.right_range[0] = 0;
179 jy_inner.right_range[1] = g.n()*g.inner_Nx();
180 jy_outer.right_range[0] = g.n()*g.inner_Nx();
181 jy_outer.right_range[1] = g.n()*g.Nx();
182 jy_outer.right_size = g.n()*g.Nx();
183
184 Composite<EllSparseBlockMat<real_type> > c( jy_inner, jy_outer);
185 return c;
186}
187
195template<class real_type>
197{
198 return jumpX( g, g.bcx());
199}
200
208template<class real_type>
210{
211 return jumpY( g, g.bcy());
212}
213
215//jumpX, jumpY, jumpZ, dx, dy, dz
224template<class real_type>
226{
228 jx = jump( g.n(), g.Nx(), g.hx(), bcx);
229 jx.set_left_size( g.n()*g.Ny()*g.Nz());
230 return jx;
231}
232
241template<class real_type>
243{
244 EllSparseBlockMat<real_type> jy_inner, jy_outer;
245 RealGridX1d<real_type> g1d_inner( g.y0(), g.y1(), g.fy(), g.n(), g.Ny(), bcy);
246 RealGrid1d<real_type> g1d_outer( g.y0(), g.y1(), g.n(), g.Ny(), bcy);
247 jy_inner = jump( g1d_inner, bcy);
248 jy_outer = jump( g1d_outer, bcy);
249 jy_inner.right_size = g.n()*g.Nx();
250 jy_inner.right_range[0] = 0;
251 jy_inner.right_range[1] = g.n()*g.inner_Nx();
252 jy_outer.right_range[0] = g.n()*g.inner_Nx();
253 jy_outer.right_range[1] = g.n()*g.Nx();
254 jy_outer.right_size = g.n()*g.Nx();
255 jy_inner.left_size = g.Nz();
256 jy_outer.left_size = g.Nz();
257
258 Composite<EllSparseBlockMat<real_type> > c( jy_inner, jy_outer);
259 return c;
260}
261
270template<class real_type>
272{
274 jz = jump( 1, g.Nz(), g.hz(), bcz);
275 jz.set_right_size( g.n()*g.Nx()*g.n()*g.Ny());
276 return jz;
277}
278
286template<class real_type>
288{
289 return jumpX( g, g.bcx());
290}
291
299template<class real_type>
301{
302 return jumpY( g, g.bcy());
303}
304
312template<class real_type>
314{
315 return jumpZ( g, g.bcz());
316}
317
318
328template<class real_type>
330{
332 dx = dx_normed( g.n(), g.Nx(), g.hx(), bcx, dir);
333 dx.set_left_size( g.n()*g.Ny()*g.Nz());
334 return dx;
335}
336
345template<class real_type>
347
357template<class real_type>
359{
360 EllSparseBlockMat<real_type> dy_inner, dy_outer;
361 RealGridX1d<real_type> g1d_inner( g.y0(), g.y1(), g.fy(), g.n(), g.Ny(), bcy);
362 RealGrid1d<real_type> g1d_outer( g.y0(), g.y1(), g.n(), g.Ny(), bcy);
363 dy_inner = dx( g1d_inner, bcy, dir);
364 dy_outer = dx( g1d_outer, bcy, dir);
365 dy_inner.right_size = g.n()*g.Nx();
366 dy_inner.right_range[0] = 0;
367 dy_inner.right_range[1] = g.n()*g.inner_Nx();
368 dy_outer.right_range[0] = g.n()*g.inner_Nx();
369 dy_outer.right_range[1] = g.n()*g.Nx();
370 dy_outer.right_size = g.n()*g.Nx();
371 dy_inner.left_size = g.Nz();
372 dy_outer.left_size = g.Nz();
373
374 Composite<EllSparseBlockMat<real_type> > c( dy_inner, dy_outer);
375 return c;
376}
377
386template<class real_type>
388
398template<class real_type>
400{
402 dz = dx_normed( 1, g.Nz(), g.hz(), bcz, dir);
403 dz.set_right_size( g.n()*g.n()*g.Nx()*g.Ny());
404 return dz;
405
406}
407
416template<class real_type>
418
419
420
422
423} //namespace create
424
425} //namespace dg
426
Simple 1d derivatives on X-point topology.
base X-point topology classes
void symv(MatrixType &&M, const ContainerType1 &x, ContainerType2 &y)
Definition: blas2.h:287
EllSparseBlockMat< real_type > dz(const aRealTopology3d< real_type > &g, bc bcz, direction dir=centered)
Create 3d derivative in z-direction.
Definition: derivatives.h:308
EllSparseBlockMat< real_type > dx(const aRealTopology2d< real_type > &g, bc bcx, direction dir=centered)
Create 2d derivative in x-direction.
Definition: derivatives.h:33
EllSparseBlockMat< real_type > jumpZ(const aRealTopology3d< real_type > &g, bc bcz)
Matrix that contains jump terms in Z direction in 3D.
Definition: derivatives.h:190
bc
Switch between boundary conditions.
Definition: enums.h:15
EllSparseBlockMat< real_type > jumpX(const aRealTopology2d< real_type > &g, bc bcx)
Matrix that contains 2d jump terms in X direction.
Definition: derivatives.h:95
EllSparseBlockMat< real_type > dy(const aRealTopology2d< real_type > &g, bc bcy, direction dir=centered)
Create 2d derivative in y-direction.
Definition: derivatives.h:65
direction
Direction of a discrete derivative.
Definition: enums.h:97
EllSparseBlockMat< real_type > jumpY(const aRealTopology2d< real_type > &g, bc bcy)
Matrix that contains 2d jump terms in Y direction.
Definition: derivatives.h:112
@ centered
centered derivative (cell to the left and right and current cell)
Definition: enums.h:100
EllSparseBlockMat< real_type > dx_normed(int n, int N, real_type h, bc bcx, direction dir)
Create and assemble a host Matrix for normed derivative in 1d.
Definition: dx.h:402
EllSparseBlockMat< real_type > jump(int n, int N, real_type h, bc bcx)
Create and assemble a host Matrix for the jump terms in 1d.
Definition: dx.h:310
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition: tensor_traits.h:38
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Definition: derivativesX.h:14
Composite & operator=(const Composite< Matrix2 > &src)
Definition: derivativesX.h:21
bool dual
Definition: derivativesX.h:54
void symv(get_value_type< ContainerType > alpha, const ContainerType &v1, get_value_type< ContainerType > beta, ContainerType &v2) const
Definition: derivativesX.h:31
Matrix m1
Definition: derivativesX.h:53
Composite(const Matrix &m1, const Matrix &m2)
Definition: derivativesX.h:19
Composite(const Composite< Matrix2 > &src)
Definition: derivativesX.h:17
Composite()
Definition: derivativesX.h:15
void symv(const ContainerType1 &v1, ContainerType2 &v2) const
Definition: derivativesX.h:24
Matrix m2
Definition: derivativesX.h:53
void display(std::ostream &os=std::cout) const
Definition: derivativesX.h:37
Composite(const Matrix &m)
Definition: derivativesX.h:18
Ell Sparse Block Matrix format.
Definition: sparseblockmat.h:46
void set_right_size(int new_right_size)
Set right_size = new_right_size; set_default_range();
Definition: sparseblockmat.h:110
void set_left_size(int new_left_size)
Set left_size = new_left_size;
Definition: sparseblockmat.h:115
int left_size
size of the left Kronecker delta
Definition: sparseblockmat.h:134
thrust::host_vector< int > right_range
range (can be used to apply the matrix to only part of the right rows
Definition: sparseblockmat.h:129
int right_size
size of the right Kronecker delta (is e.g 1 for a x - derivative)
Definition: sparseblockmat.h:135
1D grid
Definition: grid.h:80
1D grid for X-point topology
Definition: gridX.h:68
Indicates that the type has a member function with the same name and interface (up to the matrix itse...
Definition: matrix_categories.h:26
The vector traits.
Definition: tensor_traits.h:31
NotATensorTag tensor_category
Definition: tensor_traits.h:33
void value_type
Definition: tensor_traits.h:32
A 2D grid class with X-point topology.
Definition: gridX.h:257
real_type hx() const
cell size in x
Definition: gridX.h:304
real_type y0() const
left boundary in y
Definition: gridX.h:280
bc bcy() const
boundary conditions in y
Definition: gridX.h:376
real_type y1() const
Right boundary in y.
Definition: gridX.h:286
unsigned Nx() const
number of cells in x
Definition: gridX.h:334
bc bcx() const
boundary conditions in x
Definition: gridX.h:370
unsigned inner_Nx() const
number of topological cells in x
Definition: gridX.h:340
unsigned Ny() const
number of cells in y
Definition: gridX.h:352
real_type fy() const
partition factor in y
Definition: gridX.h:322
unsigned n() const
number of polynomial coefficients in x and y
Definition: gridX.h:328
A 3D grid class with X-point topology.
Definition: gridX.h:541
bc bcx() const
boundary conditions in x
Definition: gridX.h:687
unsigned n() const
number of polynomial coefficients in x and y
Definition: gridX.h:639
real_type y1() const
right boundary in y
Definition: gridX.h:570
real_type hx() const
cell size in x
Definition: gridX.h:609
unsigned Nz() const
number of points in z
Definition: gridX.h:681
unsigned Ny() const
number of cells in y
Definition: gridX.h:663
real_type hz() const
cell size in z
Definition: gridX.h:621
unsigned Nx() const
number of points in x
Definition: gridX.h:645
bc bcy() const
boundary conditions in y
Definition: gridX.h:693
real_type y0() const
left boundary in y
Definition: gridX.h:564
unsigned inner_Nx() const
number of topological cells in x
Definition: gridX.h:651
real_type fy() const
partition factor in y
Definition: gridX.h:633
bc bcz() const
boundary conditions in z
Definition: gridX.h:699