Discontinuous Galerkin Library
#include "dg/algorithm.h"
refined_gridX.h
Go to the documentation of this file.
1#pragma once
2
3#include "cusp/transpose.h"
4#include "interpolation.h"
5#include "evaluationX.h"
6#include "weightsX.h"
7#include "gridX.h"
8#include "base_geometryX.h"
9#include "refined_grid.h"
10
11
12namespace dg
13{
16
19template<class real_type>
21{
30 void generate( const RealGridX2d<real_type>& g_old, thrust::host_vector<real_type>& weightsX, thrust::host_vector<real_type>& weightsY, thrust::host_vector<real_type>& abscissasX, thrust::host_vector<real_type>& abscissasY) const
31 {
32 thrust::host_vector<real_type> wx, ax, wy, ay;
33 RealGrid1d<real_type> gx( g_old.x0(), g_old.x1(), g_old.n(), g_old.Nx(), g_old.bcx());
34 do_generateX(gx,g_old.inner_Nx(), wx,ax);
35 RealGridX1d<real_type> gy( g_old.y0(), g_old.y1(), g_old.fy(), g_old.n(), g_old.Ny(), g_old.bcy());
36 do_generateY(gy,wy,ay);
37 unsigned size=wx.size()*wy.size();
38 weightsX.resize(size), weightsY.resize(size);
39 abscissasX.resize(size), abscissasY.resize(size);
40 //now make product space
41 for( unsigned i=0; i<wy.size(); i++)
42 for( unsigned j=0; j<wx.size(); j++)
43 {
44 weightsX[i*wx.size()+j] = wx[j];
45 weightsY[i*wx.size()+j] = wy[i];
46 abscissasX[i*wx.size()+j] = ax[j];
47 abscissasY[i*wx.size()+j] = ay[i];
48 }
49 }
50
55 unsigned nx_new( unsigned Nx_old, real_type fx_old) const
56 {
57 return do_Nx_new(Nx_old, fx_old);
58 }
59 unsigned ny_new( unsigned Ny_old, real_type fy_old) const
60 {
61 return do_Ny_new(Ny_old, fy_old);
62 }
63 real_type fx_new( unsigned Nx_old, real_type fx_old) const
64 {
65 return do_fx_new(Nx_old, fx_old);
66 }
67 real_type fy_new( unsigned Ny_old, real_type fy_old) const
68 {
69 return do_fy_new(Ny_old, fy_old);
70 }
71 virtual aRealRefinementX2d* clone()const=0;
72 virtual ~aRealRefinementX2d() = default;
73 protected:
74 aRealRefinementX2d() = default;
77 private:
78 virtual void do_generateX( const RealGrid1d<real_type>& gx, unsigned nodeXX, thrust::host_vector<real_type>& weights, thrust::host_vector<real_type>& abscissas) const =0;
79 virtual void do_generateY( const RealGridX1d<real_type>& gy, thrust::host_vector<real_type>& weights, thrust::host_vector<real_type>& abscissas) const =0;
80 virtual unsigned do_Nx_new( unsigned Nx_old, real_type fx) const =0;
81 virtual unsigned do_Ny_new( unsigned Ny_old, real_type fy) const =0;
82 virtual real_type do_fx_new( unsigned Nx_old, real_type fx) const =0;
83 virtual real_type do_fy_new( unsigned Ny_old, real_type fy) const =0;
84};
85
89template<class real_type>
91{
92 virtual RealIdentityXRefinement* clone()const override final{
93 return new RealIdentityXRefinement(*this);
94 }
95 private:
96 virtual void do_generateX( const RealGrid1d<real_type>& g, unsigned nodeXX, thrust::host_vector<real_type>& weights, thrust::host_vector<real_type>& abscissas) const override final{
98 abscissas=dg::create::abscissas(g);
99 }
100 virtual void do_generateY( const RealGridX1d<real_type>& g, thrust::host_vector<real_type>& weights, thrust::host_vector<real_type>& abscissas) const override final{
102 abscissas=dg::create::abscissas(g);
103 }
104 virtual unsigned do_Nx_new( unsigned Nx_old, real_type fx) const override final{ return Nx_old; }
105 virtual unsigned do_Ny_new( unsigned Ny_old, real_type fy) const override final{ return Ny_old; }
106 virtual real_type do_fx_new( unsigned Nx_old, real_type fx) const override final{ return fx; }
107 virtual real_type do_fy_new( unsigned Ny_old, real_type fy) const override final{ return fy; }
108};
109
113template<class real_type>
115{
116 RealEquidistXRefinement( unsigned add_x, unsigned add_y, unsigned howmanyX=1, unsigned howmanyY=1): add_x_(add_x), howm_x_(howmanyX), add_y_(add_y), howm_y_(howmanyY){ }
117 virtual RealEquidistXRefinement* clone()const override final{return new RealEquidistXRefinement(*this);}
118 private:
119 unsigned add_x_, howm_x_, add_y_, howm_y_;
120 virtual void do_generateX( const RealGrid1d<real_type>& gx, unsigned nodeXX, thrust::host_vector<real_type>& weights, thrust::host_vector<real_type>& abscissas) const override final
121 {
122 RealEquidistRefinement<real_type> equi(add_x_, nodeXX, howm_x_);
123 equi.generate(gx,weights,abscissas);
124 }
125 virtual void do_generateY( const RealGridX1d<real_type>& g, thrust::host_vector<real_type>& weights, thrust::host_vector<real_type>& abscissas) const override final
126 {
127 RealEquidistRefinement<real_type> equi0(add_y_,0,howm_y_);
128 if( add_y_ == 0 || howm_y_ == 0) {
129 equi0.generate(g.grid(), weights, abscissas);
130 return;
131 }
132 if( g.f() == 0) {
133 equi0.generate( RealGrid1d<real_type>( g.x0(), g.x1(), g.n(), g.N(), dg::PER), weights, abscissas);
134 return;
135 }
136 thrust::host_vector<real_type> w1, w2, w3;
137 thrust::host_vector<real_type> a1, a2, a3;
138 unsigned node1 = g.outer_N();
139 RealEquidistRefinement<real_type> equi1(add_y_, node1, howm_y_);
140 equi1.generate( RealGrid1d<real_type>(g.x0() ,g.x0()+g.outer_N()*g.h(), g.n(), g.outer_N(), dg::DIR), w1,a1); //left side
141 equi0.generate( RealGrid1d<real_type>(g.x0()+g.outer_N()*g.h(),g.x1()-g.outer_N()*g.h(), g.n(), g.inner_N(), dg::PER), w2,a2);//inner side
142 equi0.generate( RealGrid1d<real_type>(g.x1()-g.outer_N()*g.h(),g.x1() , g.n(), g.outer_N(), dg::DIR), w3,a3);//right side
143 //now combine and unnormalize weights
144 thrust::host_vector<real_type> wtot( w1.size() + w2.size() + w3.size()), atot( wtot);
145 for( unsigned i=0; i<w1.size() ; i++)
146 wtot[i] = w1[i]*equi1.N_new( g.outer_N(), dg::DIR)/g.outer_N();
147 for( unsigned i=0; i<w2.size(); i++)
148 wtot[w1.size()+i] = w2[i]*equi0.N_new( g.inner_N(), dg::PER)/g.inner_N();
149 for( unsigned i=0; i<w3.size(); i++)
150 wtot[w1.size()+w2.size()+i] = w3[i]*equi0.N_new( g.outer_N(), dg::DIR)/g.outer_N();
151 weights = wtot;
152 abscissas = detail::normalize_weights_and_compute_abscissas( g.grid(), weights);
153 }
154 virtual unsigned do_Ny_new( unsigned Ny, real_type fy) const override final{
155 if( fy==0 ) return Ny + 2*add_y_;
156 return Ny + 4*add_y_;
157 }
158 virtual unsigned do_Nx_new( unsigned Nx, real_type fx) const override final{
159 if( fx==0 ) return Nx + add_x_;
160 return Nx + 2*add_x_;
161 }
162 virtual real_type do_fx_new( unsigned Nx, real_type fx) const override final{
163 if( fx==0 ) return 0;
164 return (fx*(real_type)Nx + (real_type)add_x_)/(real_type)(Nx+2.*add_x_);
165 }
166 virtual real_type do_fy_new( unsigned Ny, real_type fy) const override final{
167 if( fy==0 ) return 0;
168 return (fy*(real_type)Ny + (real_type)add_y_)/(real_type)(Ny+4.*add_y_);
169 }
170};
171
175template<class real_type>
177{
178 RealExponentialXRefinement( unsigned add_x, unsigned add_y, unsigned howmanyX=1, unsigned howmanyY=1): add_x_(add_x), howm_x_(howmanyX), add_y_(add_y), howm_y_(howmanyY){ }
180 private:
181 unsigned add_x_, howm_x_, add_y_, howm_y_;
182 virtual void do_generateX( const RealGrid1d<real_type>& gx, unsigned nodeXX, thrust::host_vector<real_type>& weights, thrust::host_vector<real_type>& abscissas) const override final
183 {
184 RealEquidistRefinement<real_type> equi(add_x_, nodeXX, howm_x_);
185 equi.generate(gx,weights,abscissas);
186 }
187 virtual void do_generateY( const RealGridX1d<real_type>& g, thrust::host_vector<real_type>& weights, thrust::host_vector<real_type>& abscissas) const override final
188 {
189 RealExponentialRefinement<real_type> expo0( add_x_, 0);
190 if( add_y_ == 0) { return expo0.generate( g.grid(), weights, abscissas); }
191 if( g.f() == 0) { return expo0.generate( RealGrid1d<real_type>( g.x0(), g.x1(), g.n(), g.N(), dg::PER), weights, abscissas); }
192 thrust::host_vector<real_type> w1, w2, w3;
193 thrust::host_vector<real_type> a1, a2, a3;
194 unsigned node1 = g.outer_N();
195 RealExponentialRefinement<real_type> expo1( add_y_, node1);
196 expo1.generate( RealGrid1d<real_type>(g.x0(),g.x1(),g.n(), g.outer_N(), dg::DIR), w1,a1); //left side
197 expo0.generate( RealGrid1d<real_type>(g.x0(),g.x1(),g.n(), g.inner_N(), dg::PER), w2,a2); //inner side
198 expo0.generate( RealGrid1d<real_type>(g.x0(),g.x1(),g.n(), g.outer_N(), dg::DIR), w3,a3); //right side
199 //now combine unnormalized weights
200 thrust::host_vector<real_type> wtot( g.size() + 4*g.n()*add_x_);
201 for( unsigned i=0; i<w1.size() ; i++)
202 wtot[i] = w1[i];
203 for( unsigned i=0; i<w2.size(); i++)
204 wtot[w1.size()+i] = w2[i];
205 for( unsigned i=0; i<w3.size(); i++)
206 wtot[w1.size()+w2.size()+i] = w3[i];
207 weights = wtot;
208
209 abscissas = detail::normalize_weights_and_compute_abscissas( g.grid(), weights);
210 }
211 virtual unsigned do_Ny_new( unsigned Ny, real_type fy) const override final{
212 if( fy==0 ) return Ny + 2*add_y_;
213 return Ny + 4*add_y_;
214 }
215 virtual unsigned do_Nx_new( unsigned Nx, real_type fx) const override final{
216 if( fx==0 ) return Nx + add_x_;
217 return Nx + 2*add_x_;
218 }
219 virtual real_type do_fx_new( unsigned Nx, real_type fx) const override final{
220 if( fx==0 ) return 0;
221 return (fx*(real_type)Nx + (real_type)add_x_)/(real_type)(Nx+2.*add_x_);
222 }
223 virtual real_type do_fy_new( unsigned Ny, real_type fy) const override final{
224 if( fy==0 ) return 0;
225 return (fy*(real_type)Ny + (real_type)add_y_)/(real_type)(Ny+4.*add_y_);
226 }
227};
228
234
235
240template<class real_type>
242{
244 real_type x0, real_type x1, real_type y0, real_type y1,
245 real_type fx, real_type fy,
246 unsigned n, unsigned Nx, unsigned Ny,
248 ref.fx_new(Nx, fx), ref.fy_new(Ny, fy), n, ref.nx_new(Nx, fx), ref.ny_new(Ny, fy), bcx, bcy), w_(2), abs_(2)
249 {
251 ref.generate(g,w_[0],w_[1],abs_[0],abs_[1]);
252 }
253
254 virtual RealCartesianRefinedGridX2d* clone()const override final{return new RealCartesianRefinedGridX2d(*this);}
255 private:
256 std::vector<thrust::host_vector<real_type> > w_,abs_;
257 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_metric()const override final{
259 t.values().push_back( w_[0]);
260 t.values().push_back( w_[1]);
261 dg::blas1::pointwiseDot( w_[0], w_[0], t.values()[2]);
262 dg::blas1::pointwiseDot( w_[1], w_[1], t.values()[3]);
263 t.idx(0,0)=2, t.idx(1,1)=3;
264 return t;
265 }
266 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_jacobian()const override final{
267 SparseTensor<thrust::host_vector<real_type> > t(*this);
268 t.values().push_back( w_[0]);
269 t.values().push_back( w_[1]);
270 t.idx(0,0)=2, t.idx(1,1)=3;
271 return t;
272 }
273 virtual std::vector<thrust::host_vector<real_type> > do_compute_map()const override final{
274 return abs_;
275 }
276};
277
282template<class real_type>
284{
286 real_type x0, real_type x1, real_type y0, real_type y1, real_type z0, real_type z1,
287 real_type fx, real_type fy,
288 unsigned n, unsigned Nx, unsigned Ny, unsigned Nz,
290 x0, x1, y0, y1,z0,z1,
291 ref.fx_new(Nx, fx), ref.fy_new(Ny, fy),
292 n, ref.nx_new(Nx, fx), ref.ny_new(Ny, fy), Nz,
293 bcx, bcy, bcz), w_(2), abs_(2)
294 {
296 ref.generate(g,w_[0],w_[1],abs_[0],abs_[1]);
297 //lift to 3d
298 w_[0].resize(this->size()), w_[1].resize(this->size()), abs_[0].resize(this->size()), abs_[1].resize(this->size());
299 unsigned size2d=this->n()*this->n()*this->Nx()*this->Ny();
300 for( unsigned i=1; i<Nz; i++)
301 for(unsigned k=0; k<size2d; k++)
302 {
303 w_[0][i*size2d+k]=w_[0][k];
304 w_[1][i*size2d+k]=w_[1][k];
305 abs_[0][i*size2d+k]=abs_[0][k];
306 abs_[1][i*size2d+k]=abs_[1][k];
307 }
308 }
309
311 private:
312 std::vector<thrust::host_vector<real_type> > w_,abs_;
313 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_metric()const override final {
315 t.values().push_back( w_[0]);
316 t.values().push_back( w_[1]);
317 dg::blas1::pointwiseDot( w_[0], w_[0], t.values()[2]);
318 dg::blas1::pointwiseDot( w_[1], w_[1], t.values()[3]);
319 t.idx(0,0)=2, t.idx(1,1)=3;
320 return t;
321 }
322 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_jacobian()const override final {
323 SparseTensor<thrust::host_vector<real_type> > t(*this);
324 t.values().push_back( w_[0]);
325 t.values().push_back( w_[1]);
326 t.idx(0,0)=2, t.idx(1,1)=3;
327 return t;
328 }
329 virtual std::vector<thrust::host_vector<real_type> > do_compute_map()const override final {
330 return abs_;
331 }
332};
333
339
340
341}//namespace dg
Function discretization routines on X-point topology.
base X-point topology classes
void pointwiseDot(get_value_type< ContainerType > alpha, const ContainerType1 &x1, const ContainerType2 &x2, get_value_type< ContainerType > beta, ContainerType &y)
Definition: blas1.h:336
bc
Switch between boundary conditions.
Definition: enums.h:15
@ PER
periodic boundaries
Definition: enums.h:16
@ DIR
homogeneous dirichlet boundaries
Definition: enums.h:17
MPI_Vector< thrust::host_vector< real_type > > weights(const aRealMPITopology2d< real_type > &g)
Nodal weight coefficients.
Definition: mpi_weights.h:22
1D, 2D and 3D interpolation matrix creation functions
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Refined X-point grid.
Definition: refined_gridX.h:242
RealCartesianRefinedGridX2d(const aRealRefinementX2d< real_type > &ref, real_type x0, real_type x1, real_type y0, real_type y1, real_type fx, real_type fy, unsigned n, unsigned Nx, unsigned Ny, bc bcx=dg::PER, bc bcy=dg::PER)
Definition: refined_gridX.h:243
virtual RealCartesianRefinedGridX2d * clone() const override final
Geometries are cloneable.
Definition: refined_gridX.h:254
Refined X-point grid.
Definition: refined_gridX.h:284
RealCartesianRefinedGridX3d(const aRealRefinementX2d< real_type > &ref, real_type x0, real_type x1, real_type y0, real_type y1, real_type z0, real_type z1, real_type fx, real_type fy, unsigned n, unsigned Nx, unsigned Ny, unsigned Nz, bc bcx=dg::PER, bc bcy=dg::PER, bc bcz=dg::PER)
Definition: refined_gridX.h:285
virtual RealCartesianRefinedGridX3d * clone() const
Geometries are cloneable.
Definition: refined_gridX.h:310
Cell refinement around a given node.
Definition: refined_grid.h:261
RealEquidistant cell refinement around the X-point.
Definition: refined_gridX.h:115
virtual RealEquidistXRefinement * clone() const override final
Definition: refined_gridX.h:117
RealEquidistXRefinement(unsigned add_x, unsigned add_y, unsigned howmanyX=1, unsigned howmanyY=1)
Definition: refined_gridX.h:116
The exponential refinement around the X-point.
Definition: refined_gridX.h:177
RealExponentialXRefinement(unsigned add_x, unsigned add_y, unsigned howmanyX=1, unsigned howmanyY=1)
Definition: refined_gridX.h:178
virtual RealExponentialXRefinement * clone() const
Definition: refined_gridX.h:179
1D grid
Definition: grid.h:80
1D grid for X-point topology
Definition: gridX.h:68
The simplest implementation of aRealTopologyX2d.
Definition: gridX.h:514
No refinement.
Definition: refined_gridX.h:91
virtual RealIdentityXRefinement * clone() const override final
Definition: refined_gridX.h:92
Class for 2x2 and 3x3 matrices sharing elements.
Definition: tensor.h:66
This is the abstract interface class for a two-dimensional RealGeometryX.
Definition: base_geometryX.h:18
This is the abstract interface class for a three-dimensional RealGeometryX.
Definition: base_geometryX.h:63
Abstract base class for 2d grid refinement that increases the number of grid cells of a fixed basis g...
Definition: refined_gridX.h:21
aRealRefinementX2d()=default
unsigned nx_new(unsigned Nx_old, real_type fx_old) const
the new number of cells
Definition: refined_gridX.h:55
aRealRefinementX2d(const aRealRefinementX2d &src)=default
aRealRefinementX2d & operator=(const aRealRefinementX2d &src)=default
unsigned ny_new(unsigned Ny_old, real_type fy_old) const
Definition: refined_gridX.h:59
real_type fy_new(unsigned Ny_old, real_type fy_old) const
Definition: refined_gridX.h:67
void generate(const RealGridX2d< real_type > &g_old, thrust::host_vector< real_type > &weightsX, thrust::host_vector< real_type > &weightsY, thrust::host_vector< real_type > &abscissasX, thrust::host_vector< real_type > &abscissasY) const
Generate the grid transformation.
Definition: refined_gridX.h:30
virtual ~aRealRefinementX2d()=default
real_type fx_new(unsigned Nx_old, real_type fx_old) const
Definition: refined_gridX.h:63
virtual aRealRefinementX2d * clone() const =0
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
real_type x1() const
Right boundary in x.
Definition: gridX.h:274
real_type x0() const
Left boundary in x.
Definition: gridX.h:268
real_type fx() const
partition factor in x
Definition: gridX.h:316
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
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 z1() const
right boundary in z
Definition: gridX.h:583
real_type fx() const
partition factor in x
Definition: gridX.h:627
unsigned Nz() const
number of points in z
Definition: gridX.h:681
unsigned Ny() const
number of cells in y
Definition: gridX.h:663
unsigned Nx() const
number of points in x
Definition: gridX.h:645
bc bcy() const
boundary conditions in y
Definition: gridX.h:693
unsigned size() const
real_typehe total number of points
Definition: gridX.h:719
real_type z0() const
left boundary in z
Definition: gridX.h:577
real_type y0() const
left boundary in y
Definition: gridX.h:564
real_type x0() const
left boundary in x
Definition: gridX.h:551
real_type x1() const
right boundary in x
Definition: gridX.h:557
real_type fy() const
partition factor in y
Definition: gridX.h:633
bc bcz() const
boundary conditions in z
Definition: gridX.h:699
Creation functions for integration weights and their inverse on X-point topology.