3#include "cusp/transpose.h"
19template<
class real_type>
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
32 thrust::host_vector<real_type> wx, ax, wy, ay;
34 do_generateX(gx,g_old.
inner_Nx(), wx,ax);
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);
41 for(
unsigned i=0; i<wy.size(); i++)
42 for(
unsigned j=0; j<wx.size(); j++)
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];
55 unsigned nx_new(
unsigned Nx_old, real_type fx_old)
const
57 return do_Nx_new(Nx_old, fx_old);
59 unsigned ny_new(
unsigned Ny_old, real_type fy_old)
const
61 return do_Ny_new(Ny_old, fy_old);
63 real_type
fx_new(
unsigned Nx_old, real_type fx_old)
const
65 return do_fx_new(Nx_old, fx_old);
67 real_type
fy_new(
unsigned Ny_old, real_type fy_old)
const
69 return do_fy_new(Ny_old, fy_old);
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;
89template<
class real_type>
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);
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);
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; }
113template<
class real_type>
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){ }
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
123 equi.generate(gx,
weights,abscissas);
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
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);
133 equi0.generate( RealGrid1d<real_type>( g.x0(), g.x1(), g.n(), g.N(),
dg::PER),
weights, abscissas);
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);
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);
142 equi0.generate( RealGrid1d<real_type>(g.x1()-g.outer_N()*g.h(),g.x1() , g.n(), g.outer_N(),
dg::DIR), w3,a3);
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();
152 abscissas = detail::normalize_weights_and_compute_abscissas( g.grid(),
weights);
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_;
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_;
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_);
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_);
175template<
class real_type>
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){ }
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
185 equi.generate(gx,
weights,abscissas);
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
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);
197 expo0.generate( RealGrid1d<real_type>(g.x0(),g.x1(),g.n(), g.inner_N(),
dg::PER), w2,a2);
198 expo0.generate( RealGrid1d<real_type>(g.x0(),g.x1(),g.n(), g.outer_N(),
dg::DIR), w3,a3);
200 thrust::host_vector<real_type> wtot( g.size() + 4*g.n()*add_x_);
201 for(
unsigned i=0; i<w1.size() ; 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];
209 abscissas = detail::normalize_weights_and_compute_abscissas( g.grid(),
weights);
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_;
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_;
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_);
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_);
240template<
class real_type>
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)
250 RealGridX2d<real_type> g(
x0,
x1,
y0,
y1,
fx,
fy,
n,
Nx,
Ny,
bcx,
bcy);
251 ref.
generate(g,w_[0],w_[1],abs_[0],abs_[1]);
256 std::vector<thrust::host_vector<real_type> > w_,abs_;
259 t.values().push_back( w_[0]);
260 t.values().push_back( w_[1]);
263 t.idx(0,0)=2, t.idx(1,1)=3;
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;
273 virtual std::vector<thrust::host_vector<real_type> > do_compute_map()const override final{
282template<
class real_type>
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,
291 ref.fx_new(
Nx,
fx), ref.fy_new(
Ny,
fy),
295 RealGridX2d<real_type> g(
x0,
x1,
y0,
y1,
fx,
fy,
n,
Nx,
Ny,
bcx,
bcy);
296 ref.
generate(g,w_[0],w_[1],abs_[0],abs_[1]);
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++)
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];
312 std::vector<thrust::host_vector<real_type> > w_,abs_;
315 t.values().push_back( w_[0]);
316 t.values().push_back( w_[1]);
319 t.idx(0,0)=2, t.idx(1,1)=3;
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;
329 virtual std::vector<thrust::host_vector<real_type> > do_compute_map()const override final {
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.