5#include <thrust/host_vector.h>
67template<
class real_type>
69template<
class real_type>
78template<
class real_type>
111 real_type
x0()
const {
return x0_;}
117 real_type
x1()
const {
return x1_;}
123 real_type
lx()
const {
return x1_-x0_;}
129 real_type
h()
const {
return lx()/(real_type)Nx_;}
135 unsigned N()
const {
return Nx_;}
141 unsigned n()
const {
return n_;}
191 unsigned size()
const {
return n_*Nx_;}
198 void display( std::ostream& os = std::cout)
const
200 os <<
"Topology parameters are: \n"
204 <<
" x0 = "<<x0_<<
"\n"
205 <<
" x1 = "<<x1_<<
"\n"
206 <<
" lx = "<<
lx()<<
"\n"
207 <<
"Boundary conditions in x are: \n"
208 <<
" "<<
bc2str(bcx_)<<
"\n";
214 void shift(
bool& negative, real_type& x)
const
216 shift( negative,
x, bcx_);
226 real_type
N = floor((
x-x0_)/(x1_-x0_));
230 while( (
x<x0_) || (
x>x1_) )
236 negative = !negative;
241 negative = !negative;
257 if( !std::isfinite(
x) )
return false;
259 if( (
x>=x0_ &&
x <= x1_))
return true;
275template<
class real_type>
288 real_type
x0()
const {
return gx_.x0();}
294 real_type
x1()
const {
return gx_.x1();}
300 real_type
y0()
const {
return gy_.x0();}
306 real_type
y1()
const {
return gy_.x1();}
312 real_type
lx()
const {
return gx_.lx();}
318 real_type
ly()
const {
return gy_.lx();}
324 real_type
hx()
const {
return gx_.h();}
330 real_type
hy()
const {
return gy_.h();}
336 unsigned n()
const {
return gx_.n();}
338 unsigned nx()
const {
return gx_.n();}
340 unsigned ny()
const {
return gy_.n();}
346 unsigned Nx()
const {
return gx_.N();}
352 unsigned Ny()
const {
return gy_.N();}
390 if( fx != 1 || fy != 1)
391 do_set(
nx(), round(fx*(real_type)
Nx()),
ny(), round(fy*(real_type)
Ny()));
401 void set(
unsigned new_n,
unsigned new_Nx,
unsigned new_Ny) {
402 set( new_n, new_Nx, new_n, new_Ny);
412 void set(
unsigned new_nx,
unsigned new_Nx,
unsigned new_ny,
unsigned new_Ny) {
413 if( new_nx==
nx() && new_Nx==
Nx() && new_ny==
ny() && new_Ny ==
Ny())
415 do_set(new_nx,new_Nx,new_ny,new_Ny);
424 unsigned size()
const {
return gx_.size()*gy_.size();}
430 void display( std::ostream& os = std::cout)
const
432 os <<
"Topology parameters are: \n"
433 <<
" nx = "<<
nx()<<
"\n"
434 <<
" ny = "<<
ny()<<
"\n"
435 <<
" Nx = "<<
Nx()<<
"\n"
436 <<
" Ny = "<<
Ny()<<
"\n"
437 <<
" hx = "<<
hx()<<
"\n"
438 <<
" hy = "<<
hy()<<
"\n"
439 <<
" x0 = "<<
x0()<<
"\n"
440 <<
" x1 = "<<
x1()<<
"\n"
441 <<
" y0 = "<<
y0()<<
"\n"
442 <<
" y1 = "<<
y1()<<
"\n"
443 <<
" lx = "<<
lx()<<
"\n"
444 <<
" ly = "<<
ly()<<
"\n"
445 <<
"Boundary conditions in x are: \n"
447 <<
"Boundary conditions in y are: \n"
454 void shift(
bool& negative, real_type& x, real_type& y)
const
466 gx_.shift( negative,
x,
bcx);
467 gy_.shift( negative,
y,
bcy);
480 if( gx_.contains(
x) && gy_.contains(
y))
return true;
484 template<
class Vector>
508 virtual void do_set(
unsigned new_nx,
unsigned new_Nx,
unsigned new_ny,
521template<
class real_type>
534 real_type
x0()
const {
return gx_.x0();}
540 real_type
x1()
const {
return gx_.x1();}
547 real_type
y0()
const {
return gy_.x0();}
553 real_type
y1()
const {
return gy_.x1();}
560 real_type
z0()
const {
return gz_.x0();}
566 real_type
z1()
const {
return gz_.x1();}
573 real_type
lx()
const {
return gx_.lx();}
579 real_type
ly()
const {
return gy_.lx();}
585 real_type
lz()
const {
return gz_.lx();}
592 real_type
hx()
const {
return gx_.h();}
598 real_type
hy()
const {
return gy_.h();}
604 real_type
hz()
const {
return gz_.h();}
610 unsigned n()
const {
return gx_.n();}
612 unsigned nx()
const {
return gx_.n();}
614 unsigned ny()
const {
return gy_.n();}
616 unsigned nz()
const {
return gz_.n();}
622 unsigned Nx()
const {
return gx_.N();}
628 unsigned Ny()
const {
return gy_.N();}
634 unsigned Nz()
const {
return gz_.N();}
670 unsigned size()
const {
return gx_.size()*gy_.size()*gz_.size();}
676 void display( std::ostream& os = std::cout)
const
678 os <<
"Topology parameters are: \n"
679 <<
" nx = "<<
nx()<<
"\n"
680 <<
" ny = "<<
ny()<<
"\n"
681 <<
" nz = "<<
nz()<<
"\n"
682 <<
" Nx = "<<
Nx()<<
"\n"
683 <<
" Ny = "<<
Ny()<<
"\n"
684 <<
" Nz = "<<
Nz()<<
"\n"
685 <<
" hx = "<<
hx()<<
"\n"
686 <<
" hy = "<<
hy()<<
"\n"
687 <<
" hz = "<<
hz()<<
"\n"
688 <<
" x0 = "<<
x0()<<
"\n"
689 <<
" x1 = "<<
x1()<<
"\n"
690 <<
" y0 = "<<
y0()<<
"\n"
691 <<
" y1 = "<<
y1()<<
"\n"
692 <<
" z0 = "<<
z0()<<
"\n"
693 <<
" z1 = "<<
z1()<<
"\n"
694 <<
" lx = "<<
lx()<<
"\n"
695 <<
" ly = "<<
ly()<<
"\n"
696 <<
" lz = "<<
lz()<<
"\n"
697 <<
"Boundary conditions in x are: \n"
699 <<
"Boundary conditions in y are: \n"
701 <<
"Boundary conditions in z are: \n"
710 void shift(
bool& negative, real_type& x, real_type& y, real_type& z)
const
724 gx_.shift( negative,
x,
bcx);
725 gy_.shift( negative,
y,
bcy);
726 gz_.shift( negative,
z,
bcz);
739 bool contains( real_type x, real_type y, real_type z)
const
741 if( gx_.contains(
x) && gy_.contains(
y) && gz_.contains(
z))
746 template<
class Vector>
752 if( fx != 1 || fy != 1)
754 round(fy*(real_type)
Ny()),
nz(),
Nz());
766 void set(
unsigned new_n,
unsigned new_Nx,
unsigned new_Ny,
unsigned new_Nz) {
767 set(new_n,new_Nx,new_n,new_Ny,1,new_Nz);
779 void set(
unsigned new_nx,
unsigned new_Nx,
unsigned new_ny,
unsigned new_Ny,
unsigned new_nz,
unsigned new_Nz) {
780 if( new_nx==
nx() && new_Nx ==
Nx() && new_ny ==
ny() && new_Ny ==
Ny() && new_nz ==
nz() && new_Nz==
Nz())
782 do_set(new_nx,new_Nx,new_ny,new_Ny,new_nz,new_Nz);
806 virtual void do_set(
unsigned new_nx,
unsigned new_Nx,
unsigned new_ny,
unsigned new_Ny,
unsigned new_nz,
unsigned new_Nz)=0;
816template<
class real_type>
831 virtual void do_set(
unsigned nx,
unsigned Nx,
unsigned ny,
unsigned Ny)
override final{
842template<
class real_type>
847 RealGrid3d( 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 =
PER,
bc bcy =
PER,
bc bcz=
PER):
848 aRealTopology3d<real_type>({
x0,
x1,
n,
Nx,
bcx},{
y0,
y1,
n,
Ny,
bcy},{
z0,
z1,1,
Nz,
bcz}) { }
856 virtual void do_set(
unsigned nx,
unsigned Nx,
unsigned ny,
unsigned Ny,
857 unsigned nz,
unsigned Nz)
override final{
863template<
class real_type>
866 gx_.set(new_nx, new_Nx);
867 gy_.set(new_ny, new_Ny);
869template<
class real_type>
872 gx_.set(new_nx, new_Nx);
873 gy_.set(new_ny, new_Ny);
874 gz_.set(new_nz, new_Nz);
877template<
class Topology>
878using get_host_vector =
typename Topology::host_vector;
880template<
class Topology>
881using get_host_grid =
typename Topology::host_grid;
Struct holding coefficients for Discrete Legendre Transformation (DLT) related operations.
Definition: dlt.h:23
The discrete legendre trafo class.
bc
Switch between boundary conditions.
Definition: enums.h:15
static std::string bc2str(bc bcx)
write a string describing boundary condition to an output stream
Definition: enums.h:37
@ NEU_DIR
Neumann on left, Dirichlet on right boundary.
Definition: enums.h:19
@ PER
periodic boundaries
Definition: enums.h:16
@ DIR
homogeneous dirichlet boundaries
Definition: enums.h:17
@ DIR_NEU
Dirichlet on left, Neumann on right boundary.
Definition: enums.h:18
dg::RealGrid1d< double > Grid1d
Definition: grid.h:887
MPIGrid3d Grid3d
Definition: mpi_grid.h:760
aMPITopology3d aTopology3d
Definition: mpi_grid.h:762
MPIGrid2d Grid2d
Definition: mpi_grid.h:759
aMPITopology2d aTopology2d
Definition: mpi_grid.h:761
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
bc bcx() const
boundary conditions
Definition: grid.h:147
unsigned n() const
number of polynomial coefficients
Definition: grid.h:141
void set(unsigned n, unsigned N)
reset the cell numbers in the grid
Definition: grid.h:168
real_type lx() const
total length of interval
Definition: grid.h:123
const DLT< real_type > & dlt() const
the discrete legendre transformation
Definition: grid.h:197
void shift(bool &negative, real_type &x) const
Shift any point coordinate to a corresponding grid coordinate according to the boundary condition.
Definition: grid.h:214
unsigned size() const
n()*N() (Total number of grid points)
Definition: grid.h:191
void set(real_type x0, real_type x1, unsigned n, unsigned N, bc bcx)
Reset all values of the grid.
Definition: grid.h:183
void shift(bool &negative, real_type &x, bc bcx) const
Shift any point coordinate to a corresponding grid coordinate according to the boundary condition.
Definition: grid.h:222
RealGrid1d()=default
construct an empty grid this leaves the access functions undefined
real_type value_type
Definition: grid.h:81
real_type x1() const
right boundary
Definition: grid.h:117
unsigned N() const
number of cells
Definition: grid.h:135
real_type x0() const
left boundary
Definition: grid.h:111
void display(std::ostream &os=std::cout) const
Definition: grid.h:198
bool contains(real_type x) const
Check if the grid contains a point.
Definition: grid.h:255
thrust::host_vector< real_type > host_vector
The host vector type used by host functions like evaluate.
Definition: grid.h:83
RealGrid1d(real_type x0, real_type x1, unsigned n, unsigned N, bc bcx=PER)
1D grid
Definition: grid.h:100
void set(real_type x0, real_type x1, bc bcx)
reset the boundaries of the grid
Definition: grid.h:156
The simplest implementation of aRealTopology2d.
Definition: grid.h:818
RealGrid2d(const aRealTopology2d< real_type > &src)
allow explicit type conversion from any other topology
Definition: grid.h:829
RealGrid2d(real_type x0, real_type x1, real_type y0, real_type y1, unsigned n, unsigned Nx, unsigned Ny, bc bcx=PER, bc bcy=PER)
Equal polynomial coefficients.
Definition: grid.h:821
RealGrid2d(RealGrid1d< real_type > gx, RealGrid1d< real_type > gy)
Construct a 2d grid as the product of two 1d grids.
Definition: grid.h:825
The simplest implementation of aRealTopology3d.
Definition: grid.h:844
RealGrid3d(const aRealTopology3d< real_type > &src)
allow explicit type conversion from any other topology
Definition: grid.h:854
RealGrid3d(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=PER, bc bcy=PER, bc bcz=PER)
Equal polynomial coefficients.
Definition: grid.h:847
RealGrid3d(RealGrid1d< real_type > gx, RealGrid1d< real_type > gy, RealGrid1d< real_type > gz)
Construct a 3d topology as the product of three 1d grids.
Definition: grid.h:850
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
unsigned n() const
number of polynomial coefficients in x
Definition: grid.h:336
thrust::host_vector< real_type > host_vector
The host vector type used by host functions like evaluate.
Definition: grid.h:280
void shift(bool &negative, real_type &x, real_type &y, bc bcx, bc bcy) const
Shift any point coordinate to a corresponding grid coordinate according to the boundary condition.
Definition: grid.h:464
void shift(bool &negative, real_type &x, real_type &y) const
Shift any point coordinate to a corresponding grid coordinate according to the boundary condition.
Definition: grid.h:454
real_type ly() const
length of y
Definition: grid.h:318
~aRealTopology2d()=default
disallow destruction through base class pointer
real_type x0() const
Left boundary in x.
Definition: grid.h:288
const DLT< real_type > & dlty() const
discrete legendre transformation in y
Definition: grid.h:374
bool contains(const Vector &x) const
Shortcut for contains( x[0], x[1])
Definition: grid.h:485
void display(std::ostream &os=std::cout) const
Display.
Definition: grid.h:430
real_type y1() const
Right boundary in y.
Definition: grid.h:306
void set(unsigned new_n, unsigned new_Nx, unsigned new_Ny)
Set the number of polynomials and cells.
Definition: grid.h:401
aRealTopology2d & operator=(const aRealTopology2d &src)=default
real_type hy() const
cell size in y
Definition: grid.h:330
const RealGrid1d< real_type > & gy() const
The y-axis grid.
Definition: grid.h:379
real_type value_type
Definition: grid.h:278
unsigned ny() const
number of polynomial coefficients in y
Definition: grid.h:340
bool contains(real_type x, real_type y) const
Check if the grid contains a point.
Definition: grid.h:478
void multiplyCellNumbers(real_type fx, real_type fy)
Multiply the number of cells with a given factor.
Definition: grid.h:389
bc bcx() const
boundary conditions in x
Definition: grid.h:358
unsigned size() const
The total number of points.
Definition: grid.h:424
aRealTopology2d(const aRealTopology2d &src)=default
real_type hx() const
cell size in x
Definition: grid.h:324
real_type y0() const
left boundary in y
Definition: grid.h:300
aRealTopology2d(RealGrid1d< real_type > gx, RealGrid1d< real_type > gy)
Construct a 2d grid as the product of two 1d grids.
Definition: grid.h:500
real_type lx() const
length of x
Definition: grid.h:312
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
void set(unsigned new_nx, unsigned new_Nx, unsigned new_ny, unsigned new_Ny)
Set the number of polynomials and cells.
Definition: grid.h:412
unsigned Ny() const
number of cells in y
Definition: grid.h:352
An abstract base class for three-dimensional grids.
Definition: grid.h:523
real_type y0() const
left boundary in y
Definition: grid.h:547
real_type value_type
Definition: grid.h:524
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 RealGrid1d< real_type > & gz() const
The z-axis grid.
Definition: grid.h:664
const DLT< real_type > & dltx() const
discrete legendre transformation in x
Definition: grid.h:654
void multiplyCellNumbers(real_type fx, real_type fy)
Multiply the number of cells with a given factor.
Definition: grid.h:751
aRealTopology3d(RealGrid1d< real_type > gx, RealGrid1d< real_type > gy, RealGrid1d< real_type > gz)
Construct a 3d topology as the product of three 1d grids.
Definition: grid.h:797
real_type lx() const
length in x
Definition: grid.h:573
bool contains(const Vector &x) const
Shortcut for contains( x[0], x[1], x[2])
Definition: grid.h:747
unsigned nz() const
number of polynomial coefficients in z
Definition: grid.h:616
bc bcz() const
boundary conditions in z
Definition: grid.h:652
thrust::host_vector< real_type > host_vector
The host vector type used by host functions like evaluate.
Definition: grid.h:526
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
void shift(bool &negative, real_type &x, real_type &y, real_type &z) const
Shift any point coordinate to a corresponding grid coordinate according to the boundary condition.
Definition: grid.h:710
const RealGrid1d< real_type > & gx() const
The x-axis grid.
Definition: grid.h:660
const DLT< real_type > & dlty() const
discrete legendre transformation in y
Definition: grid.h:656
real_type x0() const
left boundary in x
Definition: grid.h:534
real_type hy() const
cell size in y
Definition: grid.h:598
void set(unsigned new_nx, unsigned new_Nx, unsigned new_ny, unsigned new_Ny, unsigned new_nz, unsigned new_Nz)
Set the number of polynomials and cells.
Definition: grid.h:779
real_type y1() const
right boundary in y
Definition: grid.h:553
aRealTopology3d(const aRealTopology3d &src)=default
bool contains(real_type x, real_type y, real_type z) const
Check if the grid contains a point.
Definition: grid.h:739
real_type hx() const
cell size in x
Definition: grid.h:592
real_type ly() const
length in y
Definition: grid.h:579
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
void set(unsigned new_n, unsigned new_Nx, unsigned new_Ny, unsigned new_Nz)
Set the number of polynomials and cells.
Definition: grid.h:766
aRealTopology3d & operator=(const aRealTopology3d &src)=default
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 hz() const
cell size in z
Definition: grid.h:604
~aRealTopology3d()=default
disallow deletion through base class pointer
real_type z1() const
right boundary in z
Definition: grid.h:566
real_type lz() const
length in z
Definition: grid.h:585
unsigned Nz() const
number of points in z
Definition: grid.h:634
void display(std::ostream &os=std::cout) const
Display.
Definition: grid.h:676
unsigned nx() const
number of polynomial coefficients in x
Definition: grid.h:612
void shift(bool &negative, real_type &x, real_type &y, real_type &z, bc bcx, bc bcy, bc bcz) const
Shift any point coordinate to a corresponding grid coordinate according to the boundary condition.
Definition: grid.h:722