Discontinuous Galerkin Library
#include "dg/algorithm.h"
weights.h
Go to the documentation of this file.
1#pragma once
2
3#include <thrust/host_vector.h>
4#include "grid.h"
5#include "../enums.h"
6
12namespace dg{
13namespace create{
14
17
40template<class real_type>
41thrust::host_vector<real_type> weights( const RealGrid1d<real_type>& g)
42{
43 thrust::host_vector<real_type> v( g.size());
44 for( unsigned i=0; i<g.N(); i++)
45 for( unsigned j=0; j<g.n(); j++)
46 v[i*g.n() + j] = g.h()/2.*g.dlt().weights()[j];
47 return v;
48}
50template<class real_type>
51thrust::host_vector<real_type> inv_weights( const RealGrid1d<real_type>& g)
52{
53 thrust::host_vector<real_type> v = weights( g);
54 for( unsigned i=0; i<g.size(); i++)
55 v[i] = 1./v[i];
56 return v;
57}
58
61template<class real_type>
62thrust::host_vector<real_type> weights( const aRealTopology2d<real_type>& g)
63{
64 thrust::host_vector<real_type> v( g.size());
65 for( unsigned i=0; i<g.size(); i++)
66 v[i] = g.hx()*g.hy()/4.*
67 g.dlty().weights()[(i/(g.nx()*g.Nx()))%g.ny()]*
68 g.dltx().weights()[i%g.nx()];
69 return v;
70}
72template<class real_type>
73thrust::host_vector<real_type> inv_weights( const aRealTopology2d<real_type>& g)
74{
75 thrust::host_vector<real_type> v = weights( g);
76 for( unsigned i=0; i<g.size(); i++)
77 v[i] = 1./v[i];
78 return v;
79}
80
82template<class real_type>
83thrust::host_vector<real_type> weights( const aRealTopology2d<real_type>& g, enum coo2d coo)
84{
85 thrust::host_vector<real_type> w( g.size());
86 if( coo == coo2d::x) {
87 for( unsigned i=0; i<g.size(); i++)
88 w[i] = g.hx()/2.* g.dltx().weights()[i%g.nx()];
89 }
90 else if( coo == coo2d::y) {
91 for( unsigned i=0; i<g.size(); i++)
92 w[i] = g.hy()/2.* g.dlty().weights()[(i/(g.nx()*g.Nx()))%g.ny()];
93 }
94 return w;
95}
96
97
100template<class real_type>
101thrust::host_vector<real_type> weights( const aRealTopology3d<real_type>& g)
102{
103 // this implementation is binary compatible with nz = 1 old implementation
104 thrust::host_vector<real_type> v( g.size());
105 for( unsigned i=0; i<g.size(); i++)
106 v[i] = g.hx()*g.hy()*g.hz()/4.*
107 (g.dltz().weights()[(i/(g.nx()*g.ny()*g.Nx()*g.Ny()))%g.nz()]/2.)*
108 g.dlty().weights()[(i/(g.nx()*g.Nx()))%g.ny()]*
109 g.dltx().weights()[i%g.nx()];
110 return v;
111}
112
114template<class real_type>
115thrust::host_vector<real_type> inv_weights( const aRealTopology3d<real_type>& g)
116{
117 thrust::host_vector<real_type> v = weights( g);
118 for( unsigned i=0; i<g.size(); i++)
119 v[i] = 1./v[i];
120 return v;
121}
122
124template<class real_type>
125thrust::host_vector<real_type> weights( const aRealTopology3d<real_type>& g, enum coo3d coo)
126{
127 thrust::host_vector<real_type> w( g.size());
128 if( coo == coo3d::x) {
129 for( unsigned i=0; i<g.size(); i++)
130 w[i] = g.hx()/2.* g.dltx().weights()[i%g.nx()];
131 }
132 else if( coo == coo3d::y) {
133 for( unsigned i=0; i<g.size(); i++)
134 w[i] = g.hy()/2.* g.dlty().weights()[(i/(g.nx()*g.Nx()))%g.ny()];
135 }
136 else if( coo == coo3d::z) {
137 for( unsigned i=0; i<g.size(); i++)
138 w[i] = g.hz()/2.* g.dltz().weights()[(i/(g.nx()*g.Nx()*g.ny()*g.Ny()))%g.nz()];
139 }
140 else if( coo == coo3d::xy) {
141 for( unsigned i=0; i<g.size(); i++)
142 {
143 w[i] = g.hx()/2.* g.dltx().weights()[i%g.nx()];
144 w[i]*= g.hy()/2.* g.dlty().weights()[(i/(g.nx()*g.Nx()))%g.ny()];
145 }
146 }
147 else if( coo == coo3d::yz) {
148 for( unsigned i=0; i<g.size(); i++)
149 {
150 w[i] = g.hy()/2.* g.dlty().weights()[(i/(g.nx()*g.Nx()))%g.ny()];
151 w[i]*= g.hz()/2.* g.dltz().weights()[(i/(g.nx()*g.Nx()*g.ny()*g.Ny()))%g.nz()];
152 }
153 }
154 else if( coo == coo3d::xz) {
155 for( unsigned i=0; i<g.size(); i++)
156 {
157 w[i] = g.hx()/2.* g.dltx().weights()[i%g.nx()];
158 w[i]*= g.hz()/2.* g.dltz().weights()[(i/(g.nx()*g.Nx()*g.ny()*g.Ny()))%g.nz()];
159 }
160 }
161 return w;
162}
163
165}//namespace create
166}//namespace dg
base topology classes
coo3d
3d contra- and covariant coordinates
Definition: enums.h:177
coo2d
2d coordinates
Definition: enums.h:171
@ yz
yz plane
@ xy
xy plane
@ y
y direction
@ x
x direction
@ xz
xz plane
@ z
z direction
@ y
y direction
@ x
x direction
MPI_Vector< thrust::host_vector< real_type > > weights(const aRealMPITopology2d< real_type > &g)
Nodal weight coefficients.
Definition: mpi_weights.h:22
MPI_Vector< thrust::host_vector< real_type > > inv_weights(const aRealMPITopology2d< real_type > &g)
inverse nodal weight coefficients
Definition: mpi_weights.h:29
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
1D grid
Definition: grid.h:80
real_type h() const
cell size
Definition: grid.h:129
unsigned n() const
number of polynomial coefficients
Definition: grid.h:141
const DLT< real_type > & dlt() const
the discrete legendre transformation
Definition: grid.h:197
unsigned size() const
n()*N() (Total number of grid points)
Definition: grid.h:191
unsigned N() const
number of cells
Definition: grid.h:135
An abstract base class for two-dimensional grids.
Definition: grid.h:277
const DLT< real_type > & dltx() const
discrete legendre trafo
Definition: grid.h:372
const DLT< real_type > & dlty() const
discrete legendre transformation in y
Definition: grid.h:374
real_type hy() const
cell size in y
Definition: grid.h:330
unsigned ny() const
number of polynomial coefficients in y
Definition: grid.h:340
unsigned size() const
The total number of points.
Definition: grid.h:424
real_type hx() const
cell size in x
Definition: grid.h:324
unsigned Nx() const
number of cells in x
Definition: grid.h:346
unsigned nx() const
number of polynomial coefficients in x
Definition: grid.h:338
An abstract base class for three-dimensional grids.
Definition: grid.h:523
unsigned size() const
The total number of points.
Definition: grid.h:670
const DLT< real_type > & dltz() const
discrete legendre transformation in z
Definition: grid.h:658
const DLT< real_type > & dltx() const
discrete legendre transformation in x
Definition: grid.h:654
unsigned nz() const
number of polynomial coefficients in z
Definition: grid.h:616
unsigned Nx() const
number of points in x
Definition: grid.h:622
unsigned ny() const
number of polynomial coefficients in y
Definition: grid.h:614
const DLT< real_type > & dlty() const
discrete legendre transformation in y
Definition: grid.h:656
real_type hy() const
cell size in y
Definition: grid.h:598
real_type hx() const
cell size in x
Definition: grid.h:592
unsigned Ny() const
number of points in y
Definition: grid.h:628
real_type hz() const
cell size in z
Definition: grid.h:604
unsigned nx() const
number of polynomial coefficients in x
Definition: grid.h:612