3#include "cusp/transpose.h"
28template<
class real_type>
29thrust::host_vector<real_type> normalize_weights_and_compute_abscissas(
const RealGrid1d<real_type>& g, thrust::host_vector<real_type>&
weights)
32 unsigned Nx_new =
weights.size()/g.n();
33 for(
unsigned i=0;i<
weights.size(); i++)
34 weights[i] *= (real_type)g.N()/(real_type)Nx_new;
36 thrust::host_vector<real_type> boundaries(Nx_new+1), abs(g.n()*Nx_new);
37 boundaries[0] = g.x0();
38 for(
unsigned i=0; i<Nx_new; i++)
40 boundaries[i+1] = boundaries[i] + g.lx()/(real_type)Nx_new/
weights[g.n()*i];
41 for(
unsigned j=0; j<g.n(); j++)
43 abs[i*g.n()+j] = (boundaries[i+1]+boundaries[i])/2. +
44 (boundaries[i+1]-boundaries[i])/2.*g.dlt().abscissas()[j];
59template<
class real_type>
71 abscissas.resize(
N_new(g_old.
N(), g_old.
bcx()));
72 do_generate(g_old,
weights,abscissas);
78 unsigned N_new(
unsigned N_old,
bc bcx)
const
80 return do_N_new(N_old, bcx);
89 virtual void do_generate(
const RealGrid1d<real_type>& g, thrust::host_vector<real_type>&
weights, thrust::host_vector<real_type>& abscissas)
const =0;
90 virtual unsigned do_N_new(
unsigned N_old,
bc bcx)
const =0;
96template<
class real_type>
101 virtual void do_generate(
const RealGrid1d<real_type>& g, thrust::host_vector<real_type>&
weights, thrust::host_vector<real_type>& abscissas)
const override final{
103 abscissas=dg::create::abscissas(g);
105 virtual unsigned do_N_new(
unsigned N_old,
bc bcx)
const override final{
113template<
class real_type>
121 assert( multiple>= 1);
126 virtual void do_generate(
const RealGrid1d<real_type>& g, thrust::host_vector<real_type>&
weights, thrust::host_vector<real_type>& abscissas)
const override final
128 thrust::host_vector< real_type> left( g.n()*g.N()*m_, 1);
129 for(
unsigned k=0; k<left.size(); k++)
130 left[k] = (real_type)m_;
132 abscissas = dg::detail::normalize_weights_and_compute_abscissas( g,
weights);
134 virtual unsigned do_N_new(
unsigned N_old,
bc bcx)
const override final{
151template<
class real_type>
159 assert( multiple>= 1);
164 std::vector<real_type> simpsons_weights(
unsigned N,
double h)
const
168 std::vector<real_type> simpson( N, h);
171 simpson[0] = simpson[1] = h/2.;
174 simpson[0]=1./3. * h;
175 for(
unsigned i=0; i<(N-3)/2; i++)
177 simpson[2*i+1] = 4./3. * h;
178 simpson[2*i+2] = 2./3. * h;
182 simpson[N-2] = 4./3. * h;
183 simpson[N-1] = 1./3. * h;
187 simpson[N-4] = N==4 ? 3./8.*h : (1./3.+3./8.)*h;
188 simpson[N-3] = (9./8.)*h;
189 simpson[N-2] = (9./8.)*h;
190 simpson[N-1] = (3./8.)*h;
194 virtual void do_generate(
const RealGrid1d<real_type>& g, thrust::host_vector<real_type>&
weights, thrust::host_vector<real_type>& abscissas)
const override final
196 thrust::host_vector<real_type> old = dg::create::abscissas(g);
203 abscissas.resize( g.size()*m_M);
206 unsigned NLeft = m_M/2;
207 double hxleft = (old[0] - g.x0())/(
double)(NLeft+1);
208 abscissas[0] = g.x0()+hxleft;
211 std::vector<real_type> sim = simpsons_weights( NLeft+1, hxleft);
213 for(
unsigned k=1; k<=NLeft; k++)
216 abscissas[idx] = abscissas[idx-1]+hxleft;
220 unsigned NMiddle = m_M;
221 for(
unsigned i=0; i<old.size()-1; i++)
223 double hxmiddle = (old[i+1] - old[i])/(
double)NMiddle;
224 sim = simpsons_weights( NMiddle+1, hxmiddle);
226 for(
unsigned k=1; k<=NMiddle; k++)
229 abscissas[idx] = abscissas[idx-1]+hxmiddle;
233 unsigned NRight = m_M - 1 - m_M/2;
234 double hxright = (g.x1() - old[g.size()-1] )/(
double)(NRight+1);
237 sim = simpsons_weights( NRight+1, hxright);
239 for(
unsigned k=1; k<=NRight; k++)
242 abscissas[idx] = abscissas[idx-1]+hxright;
247 RealGrid1d<real_type> nGrid( g.x0(), g.x1(), g.n(), g.N()*m_M);
251 virtual unsigned do_N_new(
unsigned N_old,
bc bcx)
const override final{
259template<
class real_type>
271 RealEquidistRefinement(
unsigned add_x,
unsigned node,
unsigned howmany=1): add_x_(add_x), node_(node), howm_(howmany){ }
274 unsigned add_x_, node_, howm_;
275 virtual void do_generate(
const RealGrid1d<real_type>& g, thrust::host_vector<real_type>&
weights, thrust::host_vector<real_type>& abscissas)
const override final
277 if( add_x_ == 0 || howm_ == 0)
279 thrust::host_vector<real_type> w_( g.size(), 1);
280 abscissas = dg::create::abscissas(g);
284 weights = equidist_ref( add_x_, node_, g.n(), g.N(), g.bcx(), howm_);
285 abscissas = detail::normalize_weights_and_compute_abscissas( g,
weights);
287 virtual unsigned do_N_new(
unsigned N_old,
bc bcx)
const override final
289 if( bcx ==
dg::PER)
return N_old + 2*add_x_*howm_;
290 return N_old + add_x_*howm_;
292 thrust::host_vector<real_type> equidist_ref(
unsigned add_x,
unsigned node,
unsigned n,
unsigned N,
dg::bc bcx,
unsigned howmany)
const
296 if( node_ != 0 && node_ != N)
297 assert( howm_ <= node_ && howm_ <= N-node_);
298 if( add_x_ == 0 || howm_ == 0)
300 thrust::host_vector<real_type> w_( n*N, 1);
304 thrust::host_vector< real_type> left( n*N+n*add_x_*howm_, 1), right(left);
305 for(
unsigned i=0; i<(add_x_+1)*howm_; i++)
306 for(
unsigned k=0; k<n; k++)
307 left[i*n+k] = add_x_ + 1;
309 for(
unsigned i=0; i<right.size(); i++)
310 right[i] = left[ (left.size()-1)-i];
311 thrust::host_vector< real_type> both( n*N+2*n*add_x_*howm_, 1);
312 for(
unsigned i=0; i<left.size(); i++)
314 for(
unsigned i=0; i<right.size(); i++)
315 both[i+n*add_x_*howm_] *= right[i];
316 if( node_ == 0 && bcx !=
dg::PER) {
return left; }
317 else if( node_ == N && bcx !=
dg::PER) {
return right; }
318 else if((node_ == N || node_ == 0) && bcx ==
dg::PER) {
return both; }
321 thrust::host_vector<real_type> w_ = both;
323 for(
unsigned i=0; i<both.size(); i++)
324 w_[((howm_*add_x_+node_)*n+i)%both.size()] = both[i];
334template<
class real_type>
349 unsigned add_x_, node_;
350 virtual void do_generate(
const RealGrid1d<real_type>& g, thrust::host_vector<real_type>&
weights, thrust::host_vector<real_type>& abscissas)
const override final
354 thrust::host_vector<real_type> w_( g.size(), 1);
355 abscissas= dg::create::abscissas(g);
359 weights = exponential_ref( add_x_, node_, g.n(), g.N(), g.bcx());
360 abscissas = detail::normalize_weights_and_compute_abscissas( g,
weights);
362 virtual unsigned do_N_new(
unsigned N_old,
bc bcx)
const override final
364 if( bcx ==
dg::PER)
return N_old + 2*add_x_;
365 return N_old + add_x_;
367 thrust::host_vector<real_type> exponential_ref(
unsigned add_x,
unsigned node,
unsigned n,
unsigned N,
dg::bc bcx)
const
371 thrust::host_vector<real_type> w_( n*N, 1);
376 thrust::host_vector< real_type> left( n*N+n*add_x_, 1), right(left);
377 for(
unsigned k=0; k<n; k++)
378 left[k] = pow( 2, add_x_);
379 for(
unsigned i=0; i<add_x_; i++)
380 for(
unsigned k=0; k<n; k++)
381 left[(i+1)*n+k] = pow( 2, add_x_-i);
383 for(
unsigned i=0; i<right.size(); i++)
384 right[i] = left[ (left.size()-1)-i];
385 thrust::host_vector< real_type> both( n*N+2*n*add_x_, 1);
386 for(
unsigned i=0; i<left.size(); i++)
388 for(
unsigned i=0; i<right.size(); i++)
389 both[i+n*add_x_] *= right[i];
390 if( node_ == 0 && bcx !=
dg::PER) {
return left; }
391 else if( node_ == N && bcx !=
dg::PER) {
return right; }
392 else if((node_ == N || node_ == 0) && bcx ==
dg::PER) {
return both; }
395 thrust::host_vector<real_type> w_ = both;
397 for(
unsigned i=0; i<both.size(); i++)
398 w_[((add_x_+node_)*n+i)%both.size()] = both[i];
417template<
class real_type>
421 unsigned n,
unsigned Nx,
unsigned Ny,
bc bcx =
dg::PER,
bc bcy =
dg::PER) :
dg::
aGeometry2d( {
x0,
x1,
n, refX.
N_new(
Nx,
bcx),
bcx}, {
y0,
y1,
n, refY.N_new(
Ny,
bcy),
bcy}), refX_(refX), refY_(refY), w_(2), a_(2)
423 construct_weights_and_abscissas(
n,
Nx,
n,
Ny);
429 std::vector<thrust::host_vector<real_type> > w_, a_;
430 void construct_weights_and_abscissas(
unsigned nx,
unsigned Nx,
unsigned ny,
unsigned Ny)
434 thrust::host_vector<real_type> wx, ax, wy, ay;
435 refX_->generate(
gx, wx, ax);
436 refY_->generate(
gy, wy, ay);
437 w_[0].resize(this->
size()), w_[1].resize(this->
size());
438 a_[0].resize(this->
size()), a_[1].resize(this->
size());
440 for(
unsigned i=0; i<wy.size(); i++)
441 for(
unsigned j=0; j<wx.size(); j++)
443 w_[0][i*wx.size()+j] = wx[j];
444 w_[1][i*wx.size()+j] = wy[i];
445 a_[0][i*wx.size()+j] = ax[j];
446 a_[1][i*wx.size()+j] = ay[i];
449 virtual void do_set(
unsigned nx,
unsigned Nx,
unsigned ny,
unsigned Ny)
override final{
451 construct_weights_and_abscissas(
nx,
Nx,
ny,
Ny);
453 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_metric()const override final{
454 SparseTensor<thrust::host_vector<real_type> > t(*
this);
455 t.values().push_back( w_[0]);
456 t.values().push_back( w_[1]);
459 t.idx(0,0)=2, t.idx(1,1)=3;
462 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_jacobian()const override final{
463 SparseTensor<thrust::host_vector<real_type> > t(*
this);
464 t.values().push_back( w_[0]);
465 t.values().push_back( w_[1]);
466 t.idx(0,0)=2, t.idx(1,1)=3;
469 virtual std::vector<thrust::host_vector<real_type> > do_compute_map()const override final{
478template<
class real_type>
483 dg::
aGeometry3d( {
x0,
x1,
n, refX.
N_new(
Nx,
bcx),
bcx}, {
y0,
y1, refY.N_new(
Ny,
bcy),
bcy}, {
z0,
z1, 1, refZ.N_new(
Nz,
bcz),
bcz}), refX_(refX), refY_(refY), refZ_(refZ), w_(3), a_(3)
485 construct_weights_and_abscissas(
n,
Nx,
n,
Ny,1,
Nz);
491 std::vector<thrust::host_vector<real_type> > w_, a_;
492 void construct_weights_and_abscissas(
unsigned nx,
unsigned Nx,
unsigned ny,
unsigned Ny,
unsigned nz,
unsigned Nz)
497 thrust::host_vector<real_type> w[3], a[3];
498 refX_->generate(
gx, w[0], a[0]);
499 refY_->generate(
gy, w[1], a[1]);
500 refZ_->generate(
gz, w[2], a[2]);
501 w_[0].resize(this->
size()), w_[1].resize(this->
size()), w_[2].resize(this->
size());
502 a_[0].resize(this->
size()), a_[1].resize(this->
size()), a_[2].resize(this->
size());
504 for(
unsigned s=0; s<w[2].size(); s++)
505 for(
unsigned i=0; i<w[1].size(); i++)
506 for(
unsigned j=0; j<w[0].size(); j++)
508 w_[0][(s*w[1].size()+i)*w[0].
size()+j] = w[0][j];
509 w_[1][(s*w[1].size()+i)*w[0].
size()+j] = w[1][i];
510 w_[2][(s*w[1].size()+i)*w[0].
size()+j] = w[2][s];
511 a_[0][(s*w[1].size()+i)*w[0].
size()+j] = a[0][j];
512 a_[1][(s*w[1].size()+i)*w[0].
size()+j] = a[1][i];
513 a_[2][(s*w[1].size()+i)*w[0].
size()+j] = a[1][s];
516 virtual void do_set(
unsigned nx,
unsigned Nx,
unsigned ny,
unsigned Ny,
unsigned nz,
unsigned Nz)
override final{
518 construct_weights_and_abscissas(
nx,
Nx,
ny,
Ny,
nz,
Nz);
520 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_metric()const override final {
521 SparseTensor<thrust::host_vector<real_type> > t(*
this);
522 t.values().resize( 4, t.values()[0]);
526 t.idx(0,0)=1, t.idx(1,1)=2, t.idx(2,2)=3;
529 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_jacobian()const override final{
530 SparseTensor<thrust::host_vector<real_type> > t(*
this);
531 t.values().push_back( w_[0]);
532 t.values().push_back( w_[1]);
533 t.values().push_back( w_[2]);
534 t.idx(0,0)=2, t.idx(1,1)=3, t.idx(2,2)=4;
537 virtual std::vector<thrust::host_vector<real_type> > do_compute_map()const override final {
static DG_DEVICE double one(double x)
Definition: functions.h:20
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
Definition: blas1.h:164
void pointwiseDivide(get_value_type< ContainerType > alpha, const ContainerType1 &x1, const ContainerType2 &x2, get_value_type< ContainerType > beta, ContainerType &y)
Definition: blas1.h:428
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
thrust::host_vector< real_type > evaluate(UnaryOp f, const RealGrid1d< real_type > &g)
Evaluate a 1d function on grid coordinates.
Definition: evaluation.h:67
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...
Manager class that invokes the clone() method on the managed ptr when copied.
Definition: memory.h:19
Refined RealCartesian grid.
Definition: refined_grid.h:419
RealCartesianRefinedGrid2d(const aRealRefinement1d< real_type > &refX, const aRealRefinement1d< real_type > &refY, real_type x0, real_type x1, real_type y0, real_type y1, unsigned n, unsigned Nx, unsigned Ny, bc bcx=dg::PER, bc bcy=dg::PER)
Definition: refined_grid.h:420
virtual RealCartesianRefinedGrid2d * clone() const
Geometries are cloneable.
Definition: refined_grid.h:426
Refined RealCartesian grid.
Definition: refined_grid.h:480
RealCartesianRefinedGrid3d(const aRealRefinement1d< real_type > &refX, const aRealRefinement1d< real_type > &refY, aRealRefinement1d< real_type > &refZ, real_type x0, real_type x1, real_type y0, real_type y1, real_type z0, real_type z1, unsigned n, unsigned Nx, unsigned Ny, unsigned Nz, bc bcx=dg::PER, bc bcy=dg::PER, bc bcz=dg::PER)
Definition: refined_grid.h:481
virtual RealCartesianRefinedGrid3d * clone() const
Geometries are cloneable.
Definition: refined_grid.h:488
Cell refinement around a given node.
Definition: refined_grid.h:261
RealEquidistRefinement(unsigned add_x, unsigned node, unsigned howmany=1)
Divide a number of cells left and right of a node into an equidistant number of new cells.
Definition: refined_grid.h:271
virtual RealEquidistRefinement * clone() const
Definition: refined_grid.h:272
The exponential refinement around a node.
Definition: refined_grid.h:336
virtual RealExponentialRefinement * clone() const
Definition: refined_grid.h:347
RealExponentialRefinement(unsigned add_x, unsigned node)
Construct exponential refinement.
Definition: refined_grid.h:346
Insert equidistant points in between dG nodes.
Definition: refined_grid.h:153
RealFemRefinement(unsigned multiple)
Refine every cell in the grid by an integer number of new cells.
Definition: refined_grid.h:158
virtual RealFemRefinement * clone() const
Definition: refined_grid.h:161
1D grid
Definition: grid.h:80
bc bcx() const
boundary conditions
Definition: grid.h:147
unsigned N() const
number of cells
Definition: grid.h:135
No refinement.
Definition: refined_grid.h:98
virtual RealIdentityRefinement * clone() const
Definition: refined_grid.h:99
Multiply every cell in the grid by a factor.
Definition: refined_grid.h:115
RealLinearRefinement(unsigned multiple)
Refine every cell in the grid by an integer number of new cells.
Definition: refined_grid.h:120
virtual RealLinearRefinement * clone() const
Definition: refined_grid.h:123
This is the abstract interface class for a two-dimensional Geometry.
Definition: base_geometry.h:15
This is the abstract interface class for a three-dimensional Geometry.
Definition: base_geometry.h:89
Abstract base class for 1d grid refinement that increases the number of grid cells of a fixed basis g...
Definition: refined_grid.h:61
aRealRefinement1d(const aRealRefinement1d &src)=default
virtual aRealRefinement1d * clone() const =0
aRealRefinement1d & operator=(const aRealRefinement1d &src)=default
aRealRefinement1d()=default
void generate(const RealGrid1d< real_type > &g_old, thrust::host_vector< real_type > &weights, thrust::host_vector< real_type > &abscissas) const
Generate the grid transformation.
Definition: refined_grid.h:68
virtual ~aRealRefinement1d()=default
unsigned N_new(unsigned N_old, bc bcx) const
the new number of cells
Definition: refined_grid.h:78
unsigned n() const
number of polynomial coefficients in x
Definition: grid.h:336
real_type x0() const
Left boundary in x.
Definition: grid.h:288
real_type y1() const
Right boundary in y.
Definition: grid.h:306
const RealGrid1d< real_type > & gy() const
The y-axis grid.
Definition: grid.h:379
unsigned ny() const
number of polynomial coefficients in y
Definition: grid.h:340
bc bcx() const
boundary conditions in x
Definition: grid.h:358
unsigned size() const
The total number of points.
Definition: grid.h:424
real_type y0() const
left boundary in y
Definition: grid.h:300
unsigned Nx() const
number of cells in x
Definition: grid.h:346
bc bcy() const
boundary conditions in y
Definition: grid.h:364
real_type x1() const
Right boundary in x.
Definition: grid.h:294
virtual void do_set(unsigned new_nx, unsigned new_Nx, unsigned new_ny, unsigned new_Ny)=0
const RealGrid1d< real_type > & gx() const
The x-axis grid.
Definition: grid.h:377
unsigned nx() const
number of polynomial coefficients in x
Definition: grid.h:338
unsigned Ny() const
number of cells in y
Definition: grid.h:352
real_type y0() const
left boundary in y
Definition: grid.h:547
unsigned size() const
The total number of points.
Definition: grid.h:670
const RealGrid1d< real_type > & gz() const
The z-axis grid.
Definition: grid.h:664
unsigned nz() const
number of polynomial coefficients in z
Definition: grid.h:616
bc bcz() const
boundary conditions in z
Definition: grid.h:652
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 RealGrid1d< real_type > & gx() const
The x-axis grid.
Definition: grid.h:660
real_type x0() const
left boundary in x
Definition: grid.h:534
real_type y1() const
right boundary in y
Definition: grid.h:553
const RealGrid1d< real_type > & gy() const
The y-axis grid.
Definition: grid.h:662
real_type z0() const
left boundary in z
Definition: grid.h:560
virtual void do_set(unsigned new_nx, unsigned new_Nx, unsigned new_ny, unsigned new_Ny, unsigned new_nz, unsigned new_Nz)=0
unsigned n() const
number of polynomial coefficients in x
Definition: grid.h:610
real_type x1() const
right boundary in x
Definition: grid.h:540
unsigned Ny() const
number of points in y
Definition: grid.h:628
bc bcy() const
boundary conditions in y
Definition: grid.h:646
bc bcx() const
boundary conditions in x
Definition: grid.h:640
real_type z1() const
right boundary in z
Definition: grid.h:566
unsigned Nz() const
number of points in z
Definition: grid.h:634
unsigned nx() const
number of polynomial coefficients in x
Definition: grid.h:612
Creation functions for integration weights and their inverse.