Discontinuous Galerkin Library
#include "dg/algorithm.h"
mpi_base.h
Go to the documentation of this file.
1#pragma once
2
3#include "mpi_grid.h"
4#include "base_geometry.h"
5#include "tensor.h"
6
7namespace dg
8{
9
12
16template<class real_type>
17struct aRealMPIGeometry2d : public aRealMPITopology2d<real_type>
18{
21 return do_compute_jacobian();
22 }
25 return do_compute_metric();
26 }
28 std::vector<MPI_Vector<thrust::host_vector<real_type>> > map()const{
29 return do_compute_map();
30 }
32 virtual aRealMPIGeometry2d* clone()const=0;
36 virtual ~aRealMPIGeometry2d() = default;
37 protected:
40 aRealMPIGeometry2d( const aRealMPIGeometry2d& src) = default;
43 private:
44 virtual SparseTensor<MPI_Vector<thrust::host_vector<real_type>> > do_compute_metric()const {
46 }
47 virtual SparseTensor<MPI_Vector<thrust::host_vector<real_type>> > do_compute_jacobian()const {
49 }
50 virtual std::vector<MPI_Vector<thrust::host_vector<real_type>> > do_compute_map()const{
51 std::vector<MPI_Vector<thrust::host_vector<real_type>>> map(2);
52 map[0] = dg::evaluate(dg::cooX2d, *this);
53 map[1] = dg::evaluate(dg::cooY2d, *this);
54 return map;
55 }
56};
57
61template<class real_type>
62struct aRealMPIGeometry3d : public aRealMPITopology3d<real_type>
63{
66 return do_compute_jacobian();
67 }
70 return do_compute_metric();
71 }
73 std::vector<MPI_Vector<thrust::host_vector<real_type>> > map()const{
74 return do_compute_map();
75 }
77 virtual aRealMPIGeometry3d* clone()const=0;
81 virtual ~aRealMPIGeometry3d() = default;
82 protected:
85 aRealMPIGeometry3d( const aRealMPIGeometry3d& src) = default;
88 private:
89 virtual SparseTensor<MPI_Vector<thrust::host_vector<real_type>> > do_compute_metric()const {
91 }
92 virtual SparseTensor<MPI_Vector<thrust::host_vector<real_type>> > do_compute_jacobian()const {
94 }
95 virtual std::vector<MPI_Vector<thrust::host_vector<real_type>> > do_compute_map()const{
96 std::vector<MPI_Vector<thrust::host_vector<real_type>>> map(3);
97 map[0] = dg::evaluate(dg::cooX3d, *this);
98 map[1] = dg::evaluate(dg::cooY3d, *this);
99 map[2] = dg::evaluate(dg::cooZ3d, *this);
100 return map;
101 }
102};
103
105template<class real_type>
107{
115 return do_perp_grid();
116 }
118 virtual ~aRealProductMPIGeometry3d() = default;
121 protected:
127 private:
128 virtual aRealMPIGeometry2d<real_type>* do_perp_grid()const=0;
129};
130
132
135
139template<class real_type>
141{
144 RealCartesianMPIGrid2d( real_type x0, real_type x1, real_type y0, real_type y1, unsigned n, unsigned Nx, unsigned Ny, MPI_Comm comm): aRealMPIGeometry2d<real_type>( {x0, x1, n, Nx, dg::PER}, {y0, y1, n, Ny, dg::PER}, comm){}
145
149 RealCartesianMPIGrid2d( real_type x0, real_type x1, real_type y0, real_type y1, unsigned n, unsigned Nx, unsigned Ny, bc bcx, bc bcy, MPI_Comm comm):dg::aRealMPIGeometry2d<real_type>( {x0, x1, n, Nx, bcx}, {y0, y1, n, Ny, bcy}, comm){}
156 virtual RealCartesianMPIGrid2d* clone()const override final{return new RealCartesianMPIGrid2d(*this);}
157 virtual RealCartesianGrid2d<real_type>* global_geometry()const override final{
159 this->global().gx(), this->global().gy());
160 }
161 private:
162 virtual void do_set(unsigned nx, unsigned Nx, unsigned ny, unsigned Ny) override final{
164 }
165
166};
167
171template<class real_type>
173{
177 RealCartesianMPIGrid3d( 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, MPI_Comm comm): aRealProductMPIGeometry3d<real_type>( {x0, x1, n, Nx, dg::PER}, {y0, y1, n, Ny, dg::PER}, {z0, z1, 1, Nz, dg::PER}, comm){}
178
182 RealCartesianMPIGrid3d( 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, bc bcy, bc bcz, MPI_Comm comm):aRealProductMPIGeometry3d<real_type>( {x0, x1, n, Nx, bcx}, {y0, y1, n, Ny, bcy}, {z0, z1, 1, Nz, bcz}, comm){}
183
187 virtual RealCartesianMPIGrid3d* clone()const override final{
188 return new RealCartesianMPIGrid3d(*this);
189 }
193 virtual RealCartesianGrid3d<real_type>* global_geometry()const override final{
195 this->global().gx(), this->global().gy(), this->global().gz());
196 }
197
198 private:
199 virtual RealCartesianMPIGrid2d<real_type>* do_perp_grid()const override final{
200 return new RealCartesianMPIGrid2d<real_type>( this->global().gx(), this->global().gy(), this->get_perp_comm( ));
201 }
202 virtual void do_set(unsigned nx, unsigned Nx, unsigned ny,unsigned Ny, unsigned nz,unsigned Nz)override final{
204 }
205};
206
210template<class real_type>
212{
218 RealCylindricalMPIGrid3d( 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, bc bcy, bc bcz, MPI_Comm comm):aRealProductMPIGeometry3d<real_type>( {x0, x1, n, Nx, bcx}, {y0, y1, n, Ny, bcy}, {z0, z1, 1, Nz, bcz}, comm){}
224 RealCylindricalMPIGrid3d( 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, bc bcy, MPI_Comm comm):aRealProductMPIGeometry3d<real_type>( {x0, x1, n, Nx, bcx}, {y0, y1, n, Ny, bcy}, {z0, z1, 1, Nz, dg::PER}, comm){}
225
229
230 virtual RealCylindricalMPIGrid3d<real_type>* clone()const override final{
231 return new RealCylindricalMPIGrid3d(*this);
232 }
233 virtual RealCylindricalGrid3d<real_type>* global_geometry()const override final{
235 this->global().gx(), this->global().gy(), this->global().gz());
236 }
237 private:
238 virtual RealCartesianMPIGrid2d<real_type>* do_perp_grid()const override final{
239 return new RealCartesianMPIGrid2d<real_type>( this->global().gx(), this->global().gy(), this->get_perp_comm( ));
240 }
241 virtual SparseTensor<MPI_Vector<thrust::host_vector<real_type>> > do_compute_metric()const override final{
242 SparseTensor<MPI_Vector<thrust::host_vector<real_type>>> metric(*this);
243 MPI_Vector<thrust::host_vector<real_type>> R = dg::evaluate(dg::cooX3d, *this);
244 for( unsigned i = 0; i<this->local().size(); i++)
245 R.data()[i] = 1./R.data()[i]/R.data()[i];
246 metric.idx(2,2)=2;
247 metric.values().push_back(R);
248 return metric;
249 }
250 virtual void do_set(unsigned nx, unsigned Nx, unsigned ny,unsigned Ny, unsigned nz,unsigned Nz) override final{
252 }
253};
254
264namespace x{
271}//namespace x
273
274}//namespace dg
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
dg::aRealProductMPIGeometry3d< double > aProductMPIGeometry3d
Definition: mpi_base.h:260
dg::RealCartesianMPIGrid3d< double > CartesianMPIGrid3d
Definition: mpi_base.h:262
dg::RealCartesianMPIGrid2d< double > CartesianMPIGrid2d
Definition: mpi_base.h:261
dg::aRealMPIGeometry2d< double > aMPIGeometry2d
Definition: mpi_base.h:258
dg::RealCylindricalMPIGrid3d< double > CylindricalMPIGrid3d
Definition: mpi_base.h:263
dg::aRealMPIGeometry3d< double > aMPIGeometry3d
Definition: mpi_base.h:259
MPI Grid objects.
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
three-dimensional Grid with Cartesian metric
Definition: base_geometry.h:240
The mpi version of RealCartesianGrid2d.
Definition: mpi_base.h:141
virtual RealCartesianMPIGrid2d * clone() const override final
Geometries are cloneable.
Definition: mpi_base.h:156
RealCartesianMPIGrid2d(real_type x0, real_type x1, real_type y0, real_type y1, unsigned n, unsigned Nx, unsigned Ny, bc bcx, bc bcy, MPI_Comm comm)
Equal polynomial coefficients.
Definition: mpi_base.h:149
RealCartesianMPIGrid2d(real_type x0, real_type x1, real_type y0, real_type y1, unsigned n, unsigned Nx, unsigned Ny, MPI_Comm comm)
Equal polynomial coefficients.
Definition: mpi_base.h:144
virtual RealCartesianGrid2d< real_type > * global_geometry() const override final
Construct the global non-MPI geometry.
Definition: mpi_base.h:157
RealCartesianMPIGrid2d(const dg::RealMPIGrid2d< real_type > &g)
Implicit type conversion from MPIGrid2d.
Definition: mpi_base.h:155
RealCartesianMPIGrid2d(RealGrid1d< real_type > gx, RealGrid1d< real_type > gy, MPI_Comm comm)
Construct a 2d grid as the product of two 1d grids.
Definition: mpi_base.h:152
The mpi version of RealCartesianGrid3d.
Definition: mpi_base.h:173
RealCartesianMPIGrid3d(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, MPI_Comm comm)
Equal polynomial coefficients.
Definition: mpi_base.h:177
virtual RealCartesianMPIGrid3d * clone() const override final
Geometries are cloneable.
Definition: mpi_base.h:187
RealCartesianMPIGrid3d(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, bc bcy, bc bcz, MPI_Comm comm)
Equal polynomial coefficients.
Definition: mpi_base.h:182
RealCartesianMPIGrid3d(RealGrid1d< real_type > gx, RealGrid1d< real_type > gy, RealGrid1d< real_type > gz, MPI_Comm comm)
Construct a 3d topology as the product of three 1d grids.
Definition: mpi_base.h:192
virtual RealCartesianGrid3d< real_type > * global_geometry() const override final
Construct the global non-MPI geometry.
Definition: mpi_base.h:193
RealCartesianMPIGrid3d(const dg::RealMPIGrid3d< real_type > &g)
Implicit type conversion from RealMPIGrid3d.
Definition: mpi_base.h:186
three-dimensional Grid with Cylindrical metric
Definition: base_geometry.h:271
the mpi version of RealCylindricalGrid3d
Definition: mpi_base.h:212
virtual RealCylindricalGrid3d< real_type > * global_geometry() const override final
Construct the global non-MPI geometry.
Definition: mpi_base.h:233
RealCylindricalMPIGrid3d(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, bc bcy, bc bcz, MPI_Comm comm)
Equal polynomial coefficients.
Definition: mpi_base.h:218
virtual RealCylindricalMPIGrid3d< real_type > * clone() const override final
Geometries are cloneable.
Definition: mpi_base.h:230
RealCylindricalMPIGrid3d(RealGrid1d< real_type > gx, RealGrid1d< real_type > gy, RealGrid1d< real_type > gz, MPI_Comm comm)
Construct a 3d topology as the product of three 1d grids.
Definition: mpi_base.h:228
RealCylindricalMPIGrid3d(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, bc bcy, MPI_Comm comm)
Equal polynomial coefficients.
Definition: mpi_base.h:224
1D grid
Definition: grid.h:80
The simplest implementation of aRealMPITopology2d.
Definition: mpi_grid.h:691
The simplest implementation of aRealMPITopology3d.
Definition: mpi_grid.h:727
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
This is the abstract interface class for a three-dimensional Geometry.
Definition: base_geometry.h:89
This is the abstract interface class for a two-dimensional Geometry.
Definition: mpi_base.h:18
virtual aRealMPIGeometry2d * clone() const =0
Geometries are cloneable.
SparseTensor< MPI_Vector< thrust::host_vector< real_type > > > jacobian() const
The Jacobian of the coordinate transformation from physical to computational space.
Definition: mpi_base.h:20
aRealMPIGeometry2d & operator=(const aRealMPIGeometry2d &src)=default
aRealMPIGeometry2d(const aRealMPIGeometry2d &src)=default
SparseTensor< MPI_Vector< thrust::host_vector< real_type > > > metric() const
The (inverse) metric tensor of the coordinate system.
Definition: mpi_base.h:24
std::vector< MPI_Vector< thrust::host_vector< real_type > > > map() const
The coordinate map from computational to physical space.
Definition: mpi_base.h:28
virtual ~aRealMPIGeometry2d()=default
allow deletion through base class pointer
virtual aRealGeometry2d< real_type > * global_geometry() const =0
Construct the global non-MPI geometry.
This is the abstract interface class for a three-dimensional MPIGeometry.
Definition: mpi_base.h:63
aRealMPIGeometry3d(const aRealMPIGeometry3d &src)=default
aRealMPIGeometry3d & operator=(const aRealMPIGeometry3d &src)=default
SparseTensor< MPI_Vector< thrust::host_vector< real_type > > > jacobian() const
The Jacobian of the coordinate transformation from physical to computational space.
Definition: mpi_base.h:65
virtual aRealMPIGeometry3d * clone() const =0
Geometries are cloneable.
virtual aRealGeometry3d< real_type > * global_geometry() const =0
Construct the global non-MPI geometry.
SparseTensor< MPI_Vector< thrust::host_vector< real_type > > > metric() const
The (inverse) metric tensor of the coordinate system.
Definition: mpi_base.h:69
virtual ~aRealMPIGeometry3d()=default
allow deletion through base class pointer
std::vector< MPI_Vector< thrust::host_vector< real_type > > > map() const
The coordinate map from computational to physical space.
Definition: mpi_base.h:73
2D MPI abstract grid class
Definition: mpi_grid.h:45
real_type x1() const
Return global x1.
Definition: mpi_grid.h:62
unsigned n() const
Return n.
Definition: mpi_grid.h:104
bc bcy() const
global y boundary
Definition: mpi_grid.h:132
unsigned nx() const
number of polynomial coefficients in x
Definition: mpi_grid.h:106
unsigned ny() const
number of polynomial coefficients in y
Definition: mpi_grid.h:108
real_type y0() const
Return global y0.
Definition: mpi_grid.h:68
unsigned Nx() const
Return the global number of cells.
Definition: mpi_grid.h:114
unsigned Ny() const
Return the global number of cells.
Definition: mpi_grid.h:120
real_type y1() const
Return global y1.
Definition: mpi_grid.h:74
virtual void do_set(unsigned new_nx, unsigned new_Nx, unsigned new_ny, unsigned new_Ny)=0
This function has an implementation.
MPI_Comm communicator() const
Return mpi cartesian communicator that is used in this grid.
Definition: mpi_grid.h:138
const RealGrid2d< real_type > & global() const
Return the global non-MPI grid.
Definition: mpi_grid.h:262
real_type x0() const
Return global x0.
Definition: mpi_grid.h:56
bc bcx() const
global x boundary
Definition: mpi_grid.h:126
3D MPI Grid class
Definition: mpi_grid.h:329
bc bcz() const
global z boundary
Definition: mpi_grid.h:454
MPI_Comm get_perp_comm() const
MPI Cartesian communicator in the first two dimensions (x and y)
Definition: mpi_grid.h:464
unsigned nz() const
number of polynomial coefficients in z
Definition: mpi_grid.h:418
unsigned Nz() const
Return the global number of cells.
Definition: mpi_grid.h:436
real_type x1() const
Return global x1.
Definition: mpi_grid.h:346
unsigned Ny() const
Return the global number of cells.
Definition: mpi_grid.h:430
MPI_Comm communicator() const
Return mpi cartesian communicator that is used in this grid.
Definition: mpi_grid.h:459
real_type y1() const
Return global y1.
Definition: mpi_grid.h:358
bc bcy() const
global y boundary
Definition: mpi_grid.h:448
const RealGrid3d< real_type > & global() const
Return the global non-MPI grid.
Definition: mpi_grid.h:562
real_type z1() const
Return global z1.
Definition: mpi_grid.h:370
unsigned n() const
Return n.
Definition: mpi_grid.h:412
bc bcx() const
global x boundary
Definition: mpi_grid.h:442
virtual void do_set(unsigned new_nx, unsigned new_Nx, unsigned new_ny, unsigned new_Ny, unsigned new_nz, unsigned new_Nz)=0
unsigned ny() const
number of polynomial coefficients in y
Definition: mpi_grid.h:416
real_type z0() const
Return global z0.
Definition: mpi_grid.h:364
const RealGrid3d< real_type > & local() const
Return a non-MPI grid local for the calling process.
Definition: mpi_grid.h:560
unsigned Nx() const
Return the global number of cells.
Definition: mpi_grid.h:424
unsigned nx() const
number of polynomial coefficients in x
Definition: mpi_grid.h:414
real_type y0() const
Return global y0.
Definition: mpi_grid.h:352
real_type x0() const
Return global x0.
Definition: mpi_grid.h:340
A 3d product space Geometry .
Definition: mpi_base.h:107
aRealProductMPIGeometry3d & operator=(const aRealProductMPIGeometry3d &src)=default
virtual ~aRealProductMPIGeometry3d()=default
allow deletion through base class pointer
virtual aRealProductMPIGeometry3d * clone() const =0
Geometries are cloneable.
aRealProductMPIGeometry3d(const aRealProductMPIGeometry3d &src)=default
aRealMPIGeometry2d< real_type > * perp_grid() const
The grid made up by the first two dimensions.
Definition: mpi_base.h:114