Discontinuous Galerkin Library
#include "dg/algorithm.h"
mpi_evaluation.h
Go to the documentation of this file.
1#pragma once
2
4#include "mpi_grid.h"
5#include "evaluation.h"
6
10namespace dg
11{
12
13
16
35template< class BinaryOp,class real_type>
37{
38 //since the local grid is not binary compatible we have to use this implementation
40 int dims[2], periods[2], coords[2];
41 MPI_Cart_get( g.communicator(), 2, dims, periods, coords);
42 thrust::host_vector<real_type> absx( l.nx()*l.Nx());
43 thrust::host_vector<real_type> absy( l.ny()*l.Ny());
44 for( unsigned i=0; i<l.Nx(); i++)
45 for( unsigned j=0; j<l.nx(); j++)
46 {
47 unsigned coord = i+l.Nx()*coords[0];
48 real_type xmiddle = DG_FMA( g.hx(), (real_type)(coord), g.x0());
49 real_type h2 = g.hx()/2.;
50 real_type absj = 1.+g.dltx().abscissas()[j];
51 absx[i*l.nx()+j] = DG_FMA( h2, absj, xmiddle);
52 }
53 for( unsigned i=0; i<l.Ny(); i++)
54 for( unsigned j=0; j<l.ny(); j++)
55 {
56 unsigned coord = i+l.Ny()*coords[1];
57 real_type ymiddle = DG_FMA( g.hy(), (real_type)(coord), g.y0());
58 real_type h2 = g.hy()/2.;
59 real_type absj = 1.+g.dlty().abscissas()[j];
60 absy[i*l.ny()+j] = DG_FMA( h2, absj, ymiddle );
61 }
62
63 thrust::host_vector<real_type> w( l.size());
64 for( unsigned i=0; i<l.Ny(); i++)
65 for( unsigned k=0; k<l.ny(); k++)
66 for( unsigned j=0; j<l.Nx(); j++)
67 for( unsigned r=0; r<l.nx(); r++)
68 w[ ((i*l.ny()+k)*l.Nx() + j)*l.nx() + r] = f( absx[j*l.nx()+r], absy[i*l.ny()+k]);
70 return v;
71};
73template<class real_type>
74MPI_Vector<thrust::host_vector<real_type> > evaluate( real_type(f)(real_type, real_type), const aRealMPITopology2d<real_type>& g)
75{
76 return evaluate<real_type(real_type, real_type)>( *f, g);
77};
79
98template< class TernaryOp,class real_type>
100{
101 //since the local grid is not binary compatible we have to use this implementation
102 //abscissas
104 int dims[3], periods[3], coords[3];
105 MPI_Cart_get( g.communicator(), 3, dims, periods, coords);
106 thrust::host_vector<real_type> absx( l.nx()*l.Nx());
107 thrust::host_vector<real_type> absy( l.ny()*l.Ny());
108 thrust::host_vector<real_type> absz( l.nz()*l.Nz());
109 for( unsigned i=0; i<l.Nx(); i++)
110 for( unsigned j=0; j<l.nx(); j++)
111 {
112 unsigned coord = i+l.Nx()*coords[0];
113 real_type xmiddle = DG_FMA( g.hx(), (real_type)(coord), g.x0());
114 real_type h2 = g.hx()/2.;
115 real_type absj = 1.+g.dltx().abscissas()[j];
116 absx[i*l.nx()+j] = DG_FMA( h2, absj, xmiddle);
117 }
118 for( unsigned i=0; i<l.Ny(); i++)
119 for( unsigned j=0; j<l.ny(); j++)
120 {
121 unsigned coord = i+l.Ny()*coords[1];
122 real_type ymiddle = DG_FMA( g.hy(), (real_type)(coord), g.y0());
123 real_type h2 = g.hy()/2.;
124 real_type absj = 1.+g.dlty().abscissas()[j];
125 absy[i*l.ny()+j] = DG_FMA( h2, absj, ymiddle );
126 }
127 for( unsigned i=0; i<l.Nz(); i++)
128 for( unsigned j=0; j<l.nz(); j++)
129 {
130 unsigned coord = i+l.Nz()*coords[2];
131 real_type zmiddle = DG_FMA( g.hz(), (real_type)(coord), g.z0());
132 real_type h2 = g.hz()/2.;
133 real_type absj = 1.+g.dltz().abscissas()[j];
134 absz[i*l.nz()+j] = DG_FMA( h2, absj, zmiddle );
135 }
136
137 thrust::host_vector<real_type> w( l.size());
138 for( unsigned s=0; s<l.Nz(); s++)
139 for( unsigned m=0; m<l.nz(); m++)
140 for( unsigned i=0; i<l.Ny(); i++)
141 for( unsigned k=0; k<l.ny(); k++)
142 for( unsigned j=0; j<l.Nx(); j++)
143 for( unsigned r=0; r<l.nx(); r++)
144 w[ ((((s*l.nz()+m)*l.Ny()+i)*l.ny()+k)*l.Nx() + j)*l.nx() + r] =
145 f( absx[j*l.nx()+r], absy[i*l.ny()+k], absz[s*l.nz()+m]);
147 return v;
148};
150template<class real_type>
151MPI_Vector<thrust::host_vector<real_type> > evaluate( real_type(f)(real_type, real_type, real_type), const aRealMPITopology3d<real_type>& g)
152{
153 return evaluate<real_type(real_type, real_type, real_type)>( *f, g);
154};
156//
158
167template<class real_type>
168MPI_Vector<thrust::host_vector<real_type> > global2local( const thrust::host_vector<real_type>& global, const aRealMPITopology3d<real_type>& g)
169{
170 assert( global.size() == g.global().size());
172 thrust::host_vector<real_type> temp(l.size());
173 int dims[3], periods[3], coords[3];
174 MPI_Cart_get( g.communicator(), 3, dims, periods, coords);
175 //for( unsigned pz=0; pz<dims[2]; pz++)
176 for( unsigned s=0; s<l.nz()*l.Nz(); s++)
177 //for( unsigned py=0; py<dims[1]; py++)
178 for( unsigned i=0; i<l.ny()*l.Ny(); i++)
179 //for( unsigned px=0; px<dims[0]; px++)
180 for( unsigned j=0; j<l.nx()*l.Nx(); j++)
181 {
182 unsigned idx1 = (s*l.ny()*l.Ny()+i)*l.nx()*l.Nx() + j;
183 unsigned idx2 = ((((coords[2]*l.nz()*l.Nz()+s)*dims[1]
184 +coords[1])*l.ny()*l.Ny()+i)*dims[0]
185 +coords[0])*l.nx()*l.Nx() + j;
186 temp[idx1] = global[idx2];
187 }
189}
194template<class real_type>
195MPI_Vector<thrust::host_vector<real_type> > global2local( const thrust::host_vector<real_type>& global, const aRealMPITopology2d<real_type>& g)
196{
197 assert( global.size() == g.global().size());
199 thrust::host_vector<real_type> temp(l.size());
200 int dims[2], periods[2], coords[2];
201 MPI_Cart_get( g.communicator(), 2, dims, periods, coords);
202 //for( unsigned py=0; py<dims[1]; py++)
203 for( unsigned i=0; i<l.ny()*l.Ny(); i++)
204 //for( unsigned px=0; px<dims[0]; px++)
205 for( unsigned j=0; j<l.nx()*l.Nx(); j++)
206 {
207 unsigned idx1 = i*l.nx()*l.Nx() + j;
208 unsigned idx2 = ((coords[1]*l.ny()*l.Ny()+i)*dims[0]
209 + coords[0])*l.nx()*l.Nx() + j;
210 temp[idx1] = global[idx2];
211 }
213}
214
215}//namespace dg
216
Function discretization routines.
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 > > global2local(const thrust::host_vector< real_type > &global, const aRealMPITopology3d< real_type > &g)
Take the relevant local part of a global vector.
Definition: mpi_evaluation.h:168
MPI Grid objects.
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
mpi Vector class
Definition: mpi_vector.h:32
The simplest implementation of aRealTopology2d.
Definition: grid.h:818
The simplest implementation of aRealTopology3d.
Definition: grid.h:844
2D MPI abstract grid class
Definition: mpi_grid.h:45
real_type hy() const
Return global hy.
Definition: mpi_grid.h:98
const DLT< real_type > & dltx() const
discrete legendre transformation in x
Definition: mpi_grid.h:140
const RealGrid2d< real_type > & local() const
Return a non-MPI grid local for the calling process.
Definition: mpi_grid.h:252
real_type hx() const
Return global hx.
Definition: mpi_grid.h:92
real_type y0() const
Return global y0.
Definition: mpi_grid.h:68
const DLT< real_type > & dlty() const
discrete legendre transformation in y
Definition: mpi_grid.h:142
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
3D MPI Grid class
Definition: mpi_grid.h:329
real_type hz() const
Return global hz.
Definition: mpi_grid.h:406
MPI_Comm communicator() const
Return mpi cartesian communicator that is used in this grid.
Definition: mpi_grid.h:459
const DLT< real_type > & dltz() const
Definition: mpi_grid.h:473
const RealGrid3d< real_type > & global() const
Return the global non-MPI grid.
Definition: mpi_grid.h:562
const DLT< real_type > & dlty() const
Definition: mpi_grid.h:472
real_type hy() const
Return global hy.
Definition: mpi_grid.h:400
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
real_type hx() const
Return global hx.
Definition: mpi_grid.h:394
real_type y0() const
Return global y0.
Definition: mpi_grid.h:352
real_type x0() const
Return global x0.
Definition: mpi_grid.h:340
const DLT< real_type > & dltx() const
Definition: mpi_grid.h:471
unsigned ny() const
number of polynomial coefficients in y
Definition: grid.h:340
unsigned size() const
The total number of points.
Definition: grid.h:424
unsigned Nx() const
number of cells in x
Definition: grid.h:346
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
unsigned size() const
The total number of points.
Definition: grid.h:670
unsigned nz() const
number of polynomial coefficients in z
Definition: grid.h:616
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
unsigned Ny() const
number of points in y
Definition: grid.h:628
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