Discontinuous Galerkin Library
#include "dg/algorithm.h"
fem_weights.h
Go to the documentation of this file.
1#pragma once
2#include "weights.h"
3
8namespace dg {
9namespace create{
11namespace detail
12{
13template<class real_type>
14std::vector<real_type> fem_weights( const DLT<real_type>& dlt)
15{
16 std::vector<real_type> x = dlt.abscissas();
17 std::vector<real_type> w = x;
18 unsigned n = x.size();
19 if( n== 1)
20 w[0] = 2;
21 else
22 {
23 w[0] = 0.5*(x[1] - (x[n-1]-2));
24 w[n-1] = 0.5*((x[0]+2) - x[n-2]);
25 for( unsigned i=1; i<n-1; i++)
26 w[i] = 0.5*(x[i+1]-x[i-1]);
27 }
28 return w;
29}
30}//namespace detail
32
35
52template<class real_type>
53thrust::host_vector<real_type> fem_weights( const RealGrid1d<real_type>& g)
54{
55 thrust::host_vector<real_type> v( g.size());
56 std::vector<real_type> w = detail::fem_weights(g.dlt());
57 for( unsigned i=0; i<g.N(); i++)
58 for( unsigned j=0; j<g.n(); j++)
59 v[i*g.n() + j] = g.h()/2.*w[j];
60 return v;
61}
63template<class real_type>
64thrust::host_vector<real_type> fem_inv_weights( const RealGrid1d<real_type>& g)
65{
66 thrust::host_vector<real_type> v = fem_weights( g);
67 for( unsigned i=0; i<g.size(); i++)
68 v[i] = 1./v[i];
69 return v;
70}
71
73template<class real_type>
74thrust::host_vector<real_type> fem_weights( const aRealTopology2d<real_type>& g)
75{
76 thrust::host_vector<real_type> v( g.size());
77 std::vector<real_type> wx = detail::fem_weights(g.dltx());
78 std::vector<real_type> wy = detail::fem_weights(g.dlty());
79 for( unsigned i=0; i<g.size(); i++)
80 v[i] = g.hx()*g.hy()/4.*
81 wx[i%g.nx()]*
82 wy[(i/(g.nx()*g.Nx()))%g.ny()];
83 return v;
84}
86template<class real_type>
87thrust::host_vector<real_type> fem_inv_weights( const aRealTopology2d<real_type>& g)
88{
89 thrust::host_vector<real_type> v = fem_weights( g);
90 for( unsigned i=0; i<g.size(); i++)
91 v[i] = 1./v[i];
92 return v;
93}
94
96template<class real_type>
97thrust::host_vector<real_type> fem_weights( const aRealTopology3d<real_type>& g)
98{
99 thrust::host_vector<real_type> v( g.size());
100 std::vector<real_type> wx = detail::fem_weights(g.dltx());
101 std::vector<real_type> wy = detail::fem_weights(g.dlty());
102 std::vector<real_type> wz = detail::fem_weights(g.dltz());
103 for( unsigned i=0; i<g.size(); i++)
104 v[i] = g.hx()*g.hy()*g.hz()/8.*
105 wx[i%g.nx()]*
106 wy[(i/(g.nx()*g.Nx()))%g.ny()]*
107 wz[(i/(g.nx()*g.ny()*g.Nx()*g.Ny()))%g.nz()];
108 return v;
109}
110
112template<class real_type>
113thrust::host_vector<real_type> fem_inv_weights( const aRealTopology3d<real_type>& g)
114{
115 thrust::host_vector<real_type> v = fem_weights( g);
116 for( unsigned i=0; i<g.size(); i++)
117 v[i] = 1./v[i];
118 return v;
119}
121}//namespace create
122}//namespace dg
@ x
x direction
thrust::host_vector< real_type > fem_inv_weights(const RealGrid1d< real_type > &g)
inverse finite element weight coefficients
Definition: fem_weights.h:64
thrust::host_vector< real_type > fem_weights(const aRealTopology3d< real_type > &g)
finite element weight coefficients
Definition: fem_weights.h:97
thrust::host_vector< real_type > fem_weights(const RealGrid1d< real_type > &g)
finite element weight coefficients
Definition: fem_weights.h:53
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
Creation functions for integration weights and their inverse.