Peano
Loading...
Searching...
No Matches
CellIntegral.h
Go to the documentation of this file.
1// This file is part of the ExaHyPE2 project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
5
6#include <vector>
7#include <algorithm>
8
9#include "DGUtils.h"
10#include "Functors.h"
11
12#include "tarch/la/Vector.h"
14
17
18#include "exahype2/CellData.h"
20#include "tarch/timing/Watch.h"
21
22
23namespace exahype2 {
24 namespace dg {
25 /*
26 * Volumetric kernel for Gauss-Legendre shape functions using functors
27 *
28 * Computes the @f$ \hat Q @f$ from the generic Discontinuous Galerkin
29 * explanation. That is the volumetric part of the weak formulation. It
30 * does not include the previous time step's solution, and it is not (yet)
31 * multiplied with the time step size or the inverse of the mass matrix.
32 *
33 * The whole implementation works cell-wisely, i.e. runs through cell by
34 * cell. Within each cell, it works dof-wisely, i.e. it runs through each
35 * individual dof and accumulates all the PDE contriutions to this dof.
36 * This second loop is for loop over node, and the d-dimensional index
37 * of node if given by index.
38 *
39 *
40 * ## Solver flavour
41 *
42 * We rely on Gauss-Legendre quadrature nodes on tensor product spaces, i.e.
43 * we exploit the fact that the mass matrix has diagonal form. Consequently,
44 * we can construct all involved cell-local operators on-the-fly by
45 * multiplying their 1d counterparts.
46 *
47 * We run over the patches on by one (patchwise). We do not exploit that we
48 * have to do the same operation for all dofs of all patches.
49 *
50 * We evaluate all operators in-situ, i.e. get their output and apply it
51 * immediately. See the discussion below that each dof's flux evaluation
52 * needs all the fluxes in that row of dofs. Consequently, we evaluate
53 * each flux p times if we have p quadrature points per axis. This is
54 * redundant work. In return, in-situ implies that we don't have to store
55 * data temporarily.
56 *
57 *
58 * ## Flux evaluation
59 *
60 * This version of the volumetric kernel uses the Gauss Legendre property,
61 * i.e. the orthogonality of the polynomials, plus the tensor product style
62 * of the shape functions aggressively.
63 *
64 * For the flux, we first loop over the dimensions (dim) as we have
65 * fluxes in all d directions. We are interested how the dof in the
66 * position index changes due to all the fluxes around. So we want to
67 * find out what happens if we test against the test function @f$ \phi @f$
68 * in the index dof.
69 *
70 * For the flux, tensor products and orthogonality means that the flux
71 * in x-direction in any point really only interferes with the unknowns
72 * along the x-direction along this same line: We test @f$ F(Q) \partial_x \phi @f$
73 * and assume that @f$ \phi = \phi _{1d}(x)\phi _{1d}(y)\phi _{1d}(z) @f$.
74 * Furthermore, lets represent @f$ F(Q) @f$ with the same polynomials,
75 * too. In the product of the flux with the test function (which now
76 * consists of 2d ingredients), all the polynomials besides the @f$ \partial _x \phi(x) @f$
77 * are orthogonal - the fact that the polynomials have been chosen as
78 * orthogonal ones means that their derivatives are obviously not automatically
79 * orthogonal.
80 *
81 * So all the shape functions spanning F where the y and z coordinates do
82 * not match cancel out in the example above if the test functions don't
83 * have the same coordinates. We are left with all the shapes along the
84 * x-axis within the cubic cell. Analogous arguments hold for y and z.
85 *
86 *
87 * ## Algebraic source
88 *
89 * The treatment of the source term is close to trivial: We assume that
90 * we can represent the source @f$ S(Q) @f$ in the shape space. Again,
91 * we exploit the orthogonality. If we want to test what the impact of
92 * the source is if we test against the index-th test function, the
93 * orthogonality implies that we only have take S(Q) in index multiplied
94 * with its shape function. We get a mass matrix entry.
95 *
96 *
97 * ## Non-conservative product
98 *
99 * The non-conservative product once again relies on a very crude numerical
100 * approximation: We assume that @f$ B_x(Q) \partial _x Q @f$ can be
101 * represented within our orthogonal shape space. Consequently, it is
102 * tried exactly in the same way as the algebraic source.
103 *
104 * This approach seems to be super inaccurate, but we have to keep in mind
105 * that B can be highly non-linear. So we don't know anything about the
106 * analytical shape of @f$ B_x(Q) \partial _x Q @f$ anyway: It could be
107 * any type of polynomial. So it is convenient to assume that it is once
108 * again from the same space as @f$ \phi @f$.
109 *
110 *
111 * ## Signs in front of the individual terms
112 *
113 * We rely on the formulation as discussed on the page Discontinuous
114 * Galerkin. See dg.h or the doxygen html pages for details. One important
115 * fact to keep in mind is that this routine computes $\partial _t Q$.
116 * However, all PDE terms besides the source arise on the left-hand side of
117 * the PDE, i.e. on the same side as the time derivative. We therefore have
118 * to bring these terms to the right which gives us an additional minus
119 * sign.
120 *
121 * Here's the rationale behind the volumetric terms:
122 *
123 * - The source term is already on the right-hand side in our PDE
124 * formulation. Therefore, we can simply add it.
125 * - The flux is on the left-hand side of the PDE formulation where we find
126 * a term @f$ div F(Q) @f$. We bring the derivative
127 * over to the test function and then bring the whole term to the
128 * right-hand side Both steps yield a minus sign, which means that the
129 * minus signs cancel out.
130 * - The ncp enters the volumetric term as it is. No partial derivative is
131 * exploited. It hence enters the solution with its original sign.
132 * However, we have to bring it to the right-hand side for the time
133 * derivatives. Therefore, we need a minus sign here.
134 *
135 *
136 * ## Arguments
137 *
138 * @param cellData The routine computes the DG cell contributions over
139 * multiple cells in one go. cellData is the wrapper around these cells,
140 * i.e. holds the pointers to input and ouput data, time step sizes, ...
141 * However, all cells carry the same polynomial degree and solve the
142 * same PDE.
143 *
144 * @param order Order of underlying dg polynomials. This specifies the number
145 * of nodes in each dimension, which is order+1 (you need two points to specify
146 * a linear polynomial for example). The order has to be the same for all cells
147 * handed over via cellData.
148 *
149 * @param unknowns Mumber of unknowns whose values must be updated. If you
150 * solve a PDE with n eqations over a function Q with n+m entries, then n
151 * is the number of unknonws that evolve according to the hyperbolic system
152 * of PDEs, and m are auxiliary (material) parameters. They do not change due
153 * to the PDE (though any user function might want to alter them).
154 *
155 * @param auxiliaryVariables. Auxiliary variables. See description of unknowns.
156 *
157 * @param quadratureNodes Location of quadrature nodes along one dimension in a
158 * reference element (length). We usually expect the nodes to be
159 * Gauss-Legendre or Gauss-Lobatto quadrature points, but we don't really
160 * bake these considerations into the present routine. However, we do
161 * hardcode the information that we work with a Cartesian tensor product
162 * layout of the dofs, i.e. the (x,y,z) position can be computed per
163 * entry with y and z being independent of x. See getQuadraturePoint()
164 * for some documentation.
165 *
166 */
169 const int order,
170 const int unknowns,
171 const int auxiliaryVariables,
172 Flux flux,
173 NonConservativeProduct nonconservativeProduct,
174 Source source,
175 PointSources pointSources,
176 const double* __restrict__ QuadratureNodes1d,
177 const double* __restrict__ MassMatrixDiagonal1d,
178 const double* __restrict__ StiffnessMatrix1d,
179 const double* __restrict__ DerivativeOperator1d,
180 bool evaluateFlux,
181 bool evaluateNonconservativeProduct,
182 bool evaluateSource,
183 bool evaluatePointSources
184 );
185
186
187 template <
188 typename Solver,
189 int order,
190 int unknowns,
191 int auxiliaryVariables
192 >
195 bool evaluateFlux,
196 bool evaluateNonconservativeProduct,
197 bool evaluateSource,
198 bool evaluatePointSources
199 );
200
201 template <
202 typename Solver,
203 int order,
204 int unknowns,
205 int auxiliaryVariables
206 >
209 bool evaluateFlux,
210 bool evaluateNonconservativeProduct,
211 bool evaluateSource,
212 bool evaluatePointSources,
213 tarch::timing::Measurement& measurement
214 );
215
244 const int order,
245 const int unknowns,
246 const int auxiliaryVariables,
247 const double* __restrict__ MassMatrixDiagonal1d
248 );
249
250
257 const int order,
258 const int unknowns,
259 const int auxiliaryVariables,
260 MaxEigenvalue maxEigenvalue,
261 const double* __restrict__ QuadratureNodes1d
262 );
263
264 namespace internal {
276 const double* __restrict__ cellQin,
277 const int order,
278 const int unknowns,
279 const int auxiliaryVariables,
281 double* __restrict__ cellQout
282 );
283 }
284 }
285}
286
287
288#include "CellIntegral.cpph"
289
290
Definition dg.py:1
void copySolution(const double *__restrict__ cellQin, const int order, const int unknowns, const int auxiliaryVariables, const tarch::la::Vector< Dimensions, int > &node, double *__restrict__ cellQout)
Copy solution over for one node.
void cellIntegral_patchwise_in_situ_GaussLegendre(::exahype2::CellData< double, double > &cellData, bool evaluateFlux, bool evaluateNonconservativeProduct, bool evaluateSource, bool evaluatePointSources)
std::function< void(const double *__restrict__ Q, const double *__restrict__ dQdx, const tarch::la::Vector< Dimensions, double > &x, double t, double dt, int normal, double *__restrict__ F) NonConservativeProduct)
Definition Functors.h:54
void multiplyWithInvertedMassMatrix_GaussLegendre(::exahype2::CellData< double, double > &cellData, const int order, const int unknowns, const int auxiliaryVariables, const double *__restrict__ MassMatrixDiagonal1d)
Final step of DG algorithm.
std::function< std::vector< PointSource >(const double *__restrict__ Q, const tarch::la::Vector< Dimensions, double > &cellCentre, const tarch::la::Vector< Dimensions, double > &h, double t, double dt) PointSources)
This is the only routine within the DG framework which accepts the dimensions of the underlying cell ...
Definition Functors.h:87
void reduceMaxEigenvalue_patchwise_functors(::exahype2::CellData< double, double > &cellData, const int order, const int unknowns, const int auxiliaryVariables, MaxEigenvalue maxEigenvalue, const double *__restrict__ QuadratureNodes1d)
Compute the maximum eigenvalues over a sequence of cells and store the result in the respective CellD...
std::function< void(const double *__restrict__ Q, const tarch::la::Vector< Dimensions, double > &x, double t, double dt, int normal, double *maxEigenvalue) MaxEigenvalue)
Definition Functors.h:96
void cellIntegral_patchwise_in_situ_GaussLegendre_functors(::exahype2::CellData< double, double > &cellData, const int order, const int unknowns, const int auxiliaryVariables, Flux flux, NonConservativeProduct nonconservativeProduct, Source source, PointSources pointSources, const double *__restrict__ QuadratureNodes1d, const double *__restrict__ MassMatrixDiagonal1d, const double *__restrict__ StiffnessMatrix1d, const double *__restrict__ DerivativeOperator1d, bool evaluateFlux, bool evaluateNonconservativeProduct, bool evaluateSource, bool evaluatePointSources)
std::function< void(const double *__restrict__ Q, const tarch::la::Vector< Dimensions, double > &x, double t, double dt, double *__restrict__ S) Source)
Source functor.
Definition Functors.h:75
std::function< void(const double *__restrict__ Q, const tarch::la::Vector< Dimensions, double > &x, double t, double dt, int normal, double *__restrict__ F) Flux)
Flux functor.
Definition Functors.h:44
This file is part of the multigrid project within Peano 4.
Definition __init__.py:1
Representation of a number of cells which contains all information that's required to process the sto...
Definition CellData.h:78
Simple vector class.
Definition Vector.h:159