Discontinuous Galerkin Library
#include "dg/algorithm.h"
base_geometry.h
Go to the documentation of this file.
1#pragma once
2
3#include "grid.h"
4#include "tensor.h"
5
6namespace dg
7{
8
11
13template<class real_type>
14struct aRealGeometry2d : public aRealTopology2d<real_type>
15{
28 return do_compute_jacobian();
29 }
43 return do_compute_metric();
44 }
56 std::vector<thrust::host_vector<real_type> > map()const{
57 return do_compute_map();
58 }
60 virtual aRealGeometry2d* clone()const=0;
62 virtual ~aRealGeometry2d() = default;
63 protected:
66 aRealGeometry2d( const aRealGeometry2d& src) = default;
68 aRealGeometry2d& operator=( const aRealGeometry2d& src) = default;
69 private:
70 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_metric()const {
72 }
73 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_jacobian()const {
75 }
76 virtual std::vector<thrust::host_vector<real_type> > do_compute_map()const{
77 std::vector<thrust::host_vector<real_type> > map(2);
78 map[0] = dg::evaluate(dg::cooX2d, *this);
79 map[1] = dg::evaluate(dg::cooY2d, *this);
80 return map;
81 }
82
83
84};
85
87template<class real_type>
88struct aRealGeometry3d : public aRealTopology3d<real_type>
89{
104 return do_compute_jacobian();
105 }
121 return do_compute_metric();
122 }
135 std::vector<thrust::host_vector<real_type> > map()const{
136 return do_compute_map();
137 }
139 virtual aRealGeometry3d* clone()const=0;
141 virtual ~aRealGeometry3d() = default;
142 protected:
145 aRealGeometry3d( const aRealGeometry3d& src) = default;
148 private:
149 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_metric()const {
151 }
152 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_jacobian()const {
154 }
155 virtual std::vector<thrust::host_vector<real_type> > do_compute_map()const{
156 std::vector<thrust::host_vector<real_type> > map(3);
157 map[0] = dg::evaluate(dg::cooX3d, *this);
158 map[1] = dg::evaluate(dg::cooY3d, *this);
159 map[2] = dg::evaluate(dg::cooZ3d, *this);
160 return map;
161 }
162};
163
178template<class real_type>
179struct aRealProductGeometry3d : public aRealGeometry3d<real_type>
180{
188 return do_perp_grid();
189 }
191 virtual ~aRealProductGeometry3d() = default;
193 virtual aRealProductGeometry3d* clone()const=0;
194 protected:
200 private:
201 virtual aRealGeometry2d<real_type>* do_perp_grid()const=0;
202};
204
207
213template<class real_type>
215{
217 RealCartesianGrid2d( real_type x0, real_type x1, real_type y0, real_type y1, unsigned n, unsigned Nx, unsigned Ny, bc bcx = PER, bc bcy = PER): dg::aRealGeometry2d<real_type>({x0,x1,n,Nx,bcx},{y0,y1,n,Ny,bcy}){}
218
226 virtual RealCartesianGrid2d<real_type>* clone()const override final{
227 return new RealCartesianGrid2d<real_type>(*this);
228 }
229 private:
230 virtual void do_set(unsigned nx, unsigned Nx, unsigned ny, unsigned Ny) override final{
232 }
233};
234
238template<class real_type>
240{
244 RealCartesianGrid3d( 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): dg::aRealProductGeometry3d<real_type>({x0,x1,n,Nx,bcx}, {y0,y1,n,Ny,bcy},{z0,z1,1,Nz,bcz}){}
245
253 virtual RealCartesianGrid3d* clone()const override final{
254 return new RealCartesianGrid3d(*this);
255 }
256 private:
257 virtual RealCartesianGrid2d<real_type>* do_perp_grid() const override final{
258 return new RealCartesianGrid2d<real_type>(this->gx(), this->gy());
259 }
260 virtual void do_set(unsigned nx, unsigned Nx, unsigned ny, unsigned Ny, unsigned nz, unsigned Nz) override final{
262 }
263};
264
269template<class real_type>
271{
276 RealCylindricalGrid3d( 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): dg::aRealProductGeometry3d<real_type>({x0,x1,n,Nx,bcx},{y0,y1,n,Ny,bcy},{z0,z1,1,Nz,bcz}){}
279 virtual RealCylindricalGrid3d* clone()const override final{
280 return new RealCylindricalGrid3d(*this);
281 }
282 private:
283 virtual RealCartesianGrid2d<real_type>* do_perp_grid() const override final{
284 return new RealCartesianGrid2d<real_type>(this->gx(), this->gy());
285 }
286 virtual SparseTensor<thrust::host_vector<real_type> > do_compute_metric()const override final{
287 SparseTensor<thrust::host_vector<real_type> > metric(*this);
288 thrust::host_vector<real_type> R = dg::evaluate(dg::cooX3d, *this);
289 for( unsigned i = 0; i<this->size(); i++)
290 R[i] = 1./R[i]/R[i];
291 metric.idx(2,2)=2;
292 metric.values().push_back( R);
293 return metric;
294 }
295 virtual void do_set(unsigned nx, unsigned Nx, unsigned ny,unsigned Ny, unsigned nz,unsigned Nz) override final {
297 }
298};
299
301
310#ifndef MPI_VERSION
311namespace x{
312using aGeometry2d = aGeometry2d ;
313using aGeometry3d = aGeometry3d ;
318}//namespace x
319#endif //MPI_VERSION
320
322
323} //namespace dg
base topology classes
static DG_DEVICE double cooY2d(double x, double y)
Definition: functions.h:45
static DG_DEVICE double cooZ3d(double x, double y, double z)
Definition: functions.h:49
static DG_DEVICE double cooY3d(double x, double y, double z)
Definition: functions.h:47
static DG_DEVICE double cooX2d(double x, double y)
Definition: functions.h:40
static DG_DEVICE double cooX3d(double x, double y, double z)
Definition: functions.h:42
bc
Switch between boundary conditions.
Definition: enums.h:15
@ PER
periodic boundaries
Definition: enums.h:16
@ x
x direction
thrust::host_vector< real_type > evaluate(UnaryOp f, const RealGrid1d< real_type > &g)
Evaluate a 1d function on grid coordinates.
Definition: evaluation.h:67
CartesianMPIGrid3d CartesianGrid3d
Definition: mpi_base.h:269
aMPIGeometry3d aGeometry3d
Definition: mpi_base.h:266
CylindricalMPIGrid3d CylindricalGrid3d
Definition: mpi_base.h:270
CartesianMPIGrid2d CartesianGrid2d
Definition: mpi_base.h:268
aProductMPIGeometry3d aProductGeometry3d
Definition: mpi_base.h:267
aMPIGeometry2d aGeometry2d
Definition: mpi_base.h:265
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
two-dimensional Grid with Cartesian metric
Definition: base_geometry.h:215
RealCartesianGrid2d(RealGrid1d< real_type > gx, RealGrid1d< real_type > gy)
Construct a 2d grid as the product of two 1d grids.
Definition: base_geometry.h:220
RealCartesianGrid2d(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: base_geometry.h:217
virtual RealCartesianGrid2d< real_type > * clone() const override final
Geometries are cloneable.
Definition: base_geometry.h:226
RealCartesianGrid2d(const dg::RealGrid2d< real_type > &g)
Construct from existing topology.
Definition: base_geometry.h:225
three-dimensional Grid with Cartesian metric
Definition: base_geometry.h:240
RealCartesianGrid3d(RealGrid1d< real_type > gx, RealGrid1d< real_type > gy, RealGrid1d< real_type > gz)
Construct a 3d topology as the product of three 1d grids.
Definition: base_geometry.h:247
RealCartesianGrid3d(const dg::RealGrid3d< real_type > &g)
Implicit type conversion from Grid3d.
Definition: base_geometry.h:252
virtual RealCartesianGrid3d * clone() const override final
Geometries are cloneable.
Definition: base_geometry.h:253
RealCartesianGrid3d(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: base_geometry.h:244
three-dimensional Grid with Cylindrical metric
Definition: base_geometry.h:271
virtual RealCylindricalGrid3d * clone() const override final
Geometries are cloneable.
Definition: base_geometry.h:279
RealCylindricalGrid3d(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: base_geometry.h:276
RealCylindricalGrid3d(RealGrid1d< real_type > gx, RealGrid1d< real_type > gy, RealGrid1d< real_type > gz)
Construct a 3d topology as the product of three 1d grids.
Definition: base_geometry.h:278
1D grid
Definition: grid.h:80
The simplest implementation of aRealTopology2d.
Definition: grid.h:818
The simplest implementation of aRealTopology3d.
Definition: grid.h:844
Class for 2x2 and 3x3 matrices sharing elements.
Definition: tensor.h:66
This is the abstract interface class for a two-dimensional Geometry.
Definition: base_geometry.h:15
SparseTensor< thrust::host_vector< real_type > > jacobian() const
The Jacobian of the coordinate transformation from physical to computational space.
Definition: base_geometry.h:27
std::vector< thrust::host_vector< real_type > > map() const
The coordinate map from computational to physical space.
Definition: base_geometry.h:56
aRealGeometry2d & operator=(const aRealGeometry2d &src)=default
virtual aRealGeometry2d * clone() const =0
Geometries are cloneable.
virtual ~aRealGeometry2d()=default
allow deletion through base class pointer
aRealGeometry2d(const aRealGeometry2d &src)=default
SparseTensor< thrust::host_vector< real_type > > metric() const
The (inverse) metric tensor of the coordinate system.
Definition: base_geometry.h:42
This is the abstract interface class for a three-dimensional Geometry.
Definition: base_geometry.h:89
SparseTensor< thrust::host_vector< real_type > > jacobian() const
The Jacobian of the coordinate transformation from physical to computational space.
Definition: base_geometry.h:103
aRealGeometry3d(const aRealGeometry3d &src)=default
aRealGeometry3d & operator=(const aRealGeometry3d &src)=default
SparseTensor< thrust::host_vector< real_type > > metric() const
The (inverse) metric tensor of the coordinate system.
Definition: base_geometry.h:120
virtual aRealGeometry3d * clone() const =0
Geometries are cloneable.
virtual ~aRealGeometry3d()=default
allow deletion through base class pointer
std::vector< thrust::host_vector< real_type > > map() const
The coordinate map from computational to physical space.
Definition: base_geometry.h:135
A 3d product space Geometry .
Definition: base_geometry.h:180
aRealProductGeometry3d & operator=(const aRealProductGeometry3d &src)=default
aRealGeometry2d< real_type > * perp_grid() const
The grid made up by the first two dimensions.
Definition: base_geometry.h:187
virtual aRealProductGeometry3d * clone() const =0
Geometries are cloneable.
aRealProductGeometry3d(const aRealProductGeometry3d &src)=default
virtual ~aRealProductGeometry3d()=default
allow deletion through base class pointer
An abstract base class for two-dimensional grids.
Definition: grid.h:277
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
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
An abstract base class for three-dimensional grids.
Definition: grid.h:523
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