Discontinuous Galerkin Library
#include "dg/algorithm.h"
transform.h
Go to the documentation of this file.
1#pragma once
3#include "multiply.h"
4#include "base_geometry.h"
5#include "weights.h"
6
7
8namespace dg
9{
32template< class Functor, class real_type>
33thrust::host_vector<real_type> pullback( const Functor& f, const aRealGeometry2d<real_type>& g)
34{
35 std::vector<thrust::host_vector<real_type> > map = g.map();
36 thrust::host_vector<real_type> vec( g.size());
37 for( unsigned i=0; i<g.size(); i++)
38 vec[i] = f( map[0][i], map[1][i]);
39 return vec;
40}
41
47template< class Functor, class real_type>
48thrust::host_vector<real_type> pullback( const Functor& f, const aRealGeometry3d<real_type>& g)
49{
50 std::vector<thrust::host_vector<real_type> > map = g.map();
51 thrust::host_vector<real_type> vec( g.size());
52 for( unsigned i=0; i<g.size(); i++)
53 vec[i] = f( map[0][i], map[1][i], map[2][i]);
54 return vec;
55}
56
57#ifdef MPI_VERSION
58
61template< class Functor, class real_type>
63{
64 std::vector<MPI_Vector<thrust::host_vector<real_type> > > map = g.map();
65 thrust::host_vector<real_type> vec( g.local().size());
66 for( unsigned i=0; i<g.local().size(); i++)
67 vec[i] = f( map[0].data()[i], map[1].data()[i]);
69}
70
76template< class Functor, class real_type>
78{
79 std::vector<MPI_Vector<thrust::host_vector<real_type> > > map = g.map();
80 thrust::host_vector<real_type> vec( g.local().size());
81 for( unsigned i=0; i<g.local().size(); i++)
82 vec[i] = f( map[0].data()[i], map[1].data()[i], map[2].data()[i]);
84}
85
86#endif //MPI_VERSION
87
106template<class Functor1, class Functor2, class container, class Geometry>
107void pushForwardPerp( const Functor1& vR, const Functor2& vZ,
108 container& vx, container& vy,
109 const Geometry& g)
110{
111 using host_vec = get_host_vector<Geometry>;
112 host_vec out1 = pullback( vR, g);
113 host_vec out2 = pullback( vZ, g);
114 dg::tensor::multiply2d(g.jacobian(), out1, out2, out1, out2);
115 dg::assign( out1, vx);
116 dg::assign( out2, vy);
117}
118
140template<class Functor1, class Functor2, class Functor3, class container, class Geometry>
141void pushForward( const Functor1& vR, const Functor2& vZ, const Functor3& vPhi,
142 container& vx, container& vy, container& vz,
143 const Geometry& g)
144{
145 using host_vec = get_host_vector<Geometry>;
146 host_vec out1 = pullback( vR, g);
147 host_vec out2 = pullback( vZ, g);
148 host_vec out3 = pullback( vPhi, g);
149 dg::tensor::multiply3d(g.jacobian(), out1, out2, out3, out1, out2, out3);
150 dg::assign( out1, vx);
151 dg::assign( out2, vy);
152 dg::assign( out3, vz);
153}
154
177template<class FunctorRR, class FunctorRZ, class FunctorZZ, class container, class Geometry>
178void pushForwardPerp( const FunctorRR& chiRR, const FunctorRZ& chiRZ, const FunctorZZ& chiZZ,
180 const Geometry& g)
181{
182 using host_vec = get_host_vector<Geometry>;
183 host_vec chiRR_ = pullback( chiRR, g);
184 host_vec chiRZ_ = pullback( chiRZ, g);
185 host_vec chiZZ_ = pullback( chiZZ, g);
186
187 const dg::SparseTensor<container> jac = g.jacobian();
188 std::vector<container> values( 5);
189 dg::assign( dg::evaluate( dg::zero,g), values[0]);
190 dg::assign( dg::evaluate( dg::one, g), values[1]);
191 dg::assign( chiRR_, values[2]);
192 dg::assign( chiRZ_, values[3]);
193 dg::assign( chiZZ_, values[4]);
194 chi.idx(0,0)=2, chi.idx(0,1)=chi.idx(1,0)=3, chi.idx(1,1)=4;
195 chi.idx(2,0)=chi.idx(2,1)=chi.idx(0,2)=chi.idx(1,2) = 0;
196 chi.idx(2,2)=1;
197 chi.values() = values;
198 //we do not need 3rd dimension here
199 container tmp00(jac.value(0,0)), tmp01(tmp00), tmp10(tmp00), tmp11(tmp00);
200 // multiply Chi*J^T -> tmp ( Matrix-Matrix multiplication: "line x column")
201 dg::tensor::multiply2d( chi, jac.value(0,0), jac.value(0,1), tmp00, tmp10);
202 dg::tensor::multiply2d( chi, jac.value(1,0), jac.value(1,1), tmp01, tmp11);
203 // multiply J * tmp -> Chi
204 dg::tensor::multiply2d( jac, tmp00, tmp10, chi.values()[2], chi.values()[3]);
205 dg::tensor::multiply2d( jac, tmp01, tmp11, chi.values()[3], chi.values()[4]);
206}
207
208namespace create{
211
212
213//Note that for the volume function to work properly all 2d grids must set the g_22 element to 1!!
214
224template< class Geometry>
225get_host_vector<Geometry> volume( const Geometry& g)
226{
227 using host_vector = get_host_vector<Geometry>;
228 host_vector vol = dg::tensor::volume(g.metric());
229 host_vector weights = dg::create::weights( g);
231 return vol;
232}
233
243template< class Geometry>
244get_host_vector<Geometry> inv_volume( const Geometry& g)
245{
246 using host_vector = get_host_vector<Geometry>;
247 using real_type = get_value_type<host_vector>;
248 host_vector vol = volume(g);
250 return vol;
251}
252
254}//namespace create
255
256} //namespace dg
void assign(const from_ContainerType &from, ContainerType &to, Params &&... ps)
Generic way to assign the contents of a from_ContainerType object to a ContainerType object optionall...
Definition: blas1.h:665
static DG_DEVICE double one(double x)
Definition: functions.h:20
static DG_DEVICE double zero(double x)
Definition: functions.h:29
void transform(const ContainerType1 &x, ContainerType &y, UnaryOp op)
Definition: blas1.h:524
void pointwiseDot(get_value_type< ContainerType > alpha, const ContainerType1 &x1, const ContainerType2 &x2, get_value_type< ContainerType > beta, ContainerType &y)
Definition: blas1.h:336
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
get_host_vector< Geometry > volume(const Geometry &g)
Create the volume element on the grid (including weights!!)
Definition: transform.h:225
get_host_vector< Geometry > inv_volume(const Geometry &g)
Create the inverse volume element on the grid (including weights!!)
Definition: transform.h:244
thrust::host_vector< real_type > pullback(const Functor &f, const aRealGeometryX2d< real_type > &g)
Definition: base_geometryX.h:147
void pushForwardPerp(const Functor1 &vR, const Functor2 &vZ, container &vx, container &vy, const Geometry &g)
Definition: transform.h:107
void pushForward(const Functor1 &vR, const Functor2 &vZ, const Functor3 &vPhi, container &vx, container &vy, container &vz, const Geometry &g)
Definition: transform.h:141
void multiply2d(const ContainerTypeL &lambda, const SparseTensor< ContainerType0 > &t, const ContainerType1 &in0, const ContainerType2 &in1, const ContainerTypeM &mu, ContainerType3 &out0, ContainerType4 &out1)
Definition: multiply.h:230
ContainerType volume(const SparseTensor< ContainerType > &t)
Definition: multiply.h:406
void multiply3d(const ContainerTypeL &lambda, const SparseTensor< ContainerType0 > &t, const ContainerType1 &in0, const ContainerType2 &in1, const ContainerType3 &in2, const ContainerTypeM &mu, ContainerType4 &out0, ContainerType5 &out1, ContainerType6 &out2)
Definition: multiply.h:256
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition: tensor_traits.h:38
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Definition: functors.h:134
mpi Vector class
Definition: mpi_vector.h:32
Class for 2x2 and 3x3 matrices sharing elements.
Definition: tensor.h:66
int idx(unsigned i, unsigned j) const
read index into the values array at the given position
Definition: tensor.h:134
std::vector< container > & values()
Return write access to the values array.
Definition: tensor.h:166
const container & value(size_t i, size_t j) const
Read access the underlying container.
Definition: tensor.h:156
This is the abstract interface class for a two-dimensional Geometry.
Definition: base_geometry.h:15
std::vector< thrust::host_vector< real_type > > map() const
The coordinate map from computational to physical space.
Definition: base_geometry.h:56
This is the abstract interface class for a three-dimensional Geometry.
Definition: base_geometry.h:89
std::vector< thrust::host_vector< real_type > > map() const
The coordinate map from computational to physical space.
Definition: base_geometry.h:135
This is the abstract interface class for a two-dimensional Geometry.
Definition: mpi_base.h:18
std::vector< MPI_Vector< thrust::host_vector< real_type > > > map() const
The coordinate map from computational to physical space.
Definition: mpi_base.h:28
This is the abstract interface class for a three-dimensional MPIGeometry.
Definition: mpi_base.h:63
std::vector< MPI_Vector< thrust::host_vector< real_type > > > map() const
The coordinate map from computational to physical space.
Definition: mpi_base.h:73
const RealGrid2d< real_type > & local() const
Return a non-MPI grid local for the calling process.
Definition: mpi_grid.h:252
MPI_Comm communicator() const
Return mpi cartesian communicator that is used in this grid.
Definition: mpi_grid.h:138
MPI_Comm communicator() const
Return mpi cartesian communicator that is used in this grid.
Definition: mpi_grid.h:459
const RealGrid3d< real_type > & local() const
Return a non-MPI grid local for the calling process.
Definition: mpi_grid.h:560
unsigned size() const
The total number of points.
Definition: grid.h:424
unsigned size() const
The total number of points.
Definition: grid.h:670
Creation functions for integration weights and their inverse.