1""" This file is part of the ExaGRyPE project. For conditions of distribution and
2 use, please see the copyright notice at www.peano-framework.org
5from typing
import Dict, List, Union
9from .
import initialvalues
10from .CCZ4SolverBase
import CCZ4SolverBase
16 Solver for the Einstein equations in the first-/second-order reconstructed
19 The solver evolves the first 25 of the 58 CCZ4 unknowns (see
20 Unknowns), i.e. the conformal metric, the extrinsic curvature, the
21 gauge and the auxiliary evolution variables. The remaining 33 entries
22 (DerivativeUnknowns) are the first derivatives of the lapse, the shift,
23 the conformal metric and phi. They are not evolved but held as
24 auxiliary variables (@ref exahype2.api.AuxiliaryVariables) named
25 "Derivatives". The PDE terms hand the 25 unknowns and, as a second
26 pointer, the 33 auxiliary variables to the very same kernels as the
27 first-order solver exagrype.api.FOCCZ4Solver. The second-order kernels set the time derivative of the 33
28 derivatives to zero, and the solver does not even ask for it.
30 ## Ping-pong with the reconstruction solver
32 Nobody updates the derivatives on their own. A second solver,
33 exagrype.api.FOSOReconstructionSolver, does this. Do not create the pair
34 yourself, but use exagrype.api.FOSOSolver, which hosts this solver (as
35 ccz4) and its partner. The reconstruction solver
36 runs in front of each stage of the
37 Runge-Kutta scheme of this solver, recomputes the 33 derivatives from the
38 25 unknowns of the stage and projects them onto the faces, so this solver
39 finds them with a halo when it evaluates the stage. Without the
40 reconstruction, the solver sees the derivatives of the initial
43 The solver works with exahype2.api.rkfd4.CentralDifferencesWithRungeKutta
44 (and its subclass exagrype.api.FD4WithKODissipation) and with
45 exahype2.api.fv.RusanovWithExplicitEuler. The latter reconstructs the
46 derivatives with second-order central differences.
48 For Finite Differences, the numerical scheme has to have a halo of at least three grid cells:
49 The solver needs the derivatives one layer outside of its cell (the
50 fluxes and non-conservative products on the cell's faces use the values
51 left and right of the face), and the stencil of the reconstruction
52 reaches two layers further out. The plain scheme has a halo of two;
53 lopsided advection or exagrype.api.FD4WithKODissipation widen it to
54 three. The reconstruction solver rejects a smaller halo.
56 @ref page_exagrype_fo_so_project_plan for the design and its status.
60 - The source holds no advection terms. They are added either by the
61 Finite Differences with lopsided advection
62 (@ref exagrype.api.FOSOCCZ4Solver.FOSOCCZ4Solver.advected_quantities())
63 or by the non-conservative product
64 (@ref exagrype.api.CCZ4SolverBase.CCZ4SolverBase.ncp_adds_advection()).
65 The Finite Volumes add none of them.
66 - Only the two schemes above are supported.
67 - Black holes (TwoPunctures), tracers and the ADM/Psi4 postprocessing are
69 - Checkpoints do not cover auxiliary variables, i.e. the solver cannot
87 The 25 evolved unknowns in the order the kernels in exagrype::ccz4
88 expect them, i.e. the first 25 entries of
89 exagrype.api.FOCCZ4Solver.Unknowns.
93 DerivativeUnknowns = {
105 The 33 entries of CCZ4 which this solver does not evolve, in the order the
106 kernels expect them behind the unknowns. They are the auxiliary variables
107 "Derivatives" and the 33 unknowns of exagrype.api.FOSOReconstructionSolver.
114 parameters: Dict[str, Union[int, float]] =
None,
119 Create a second-order reconstructed CCZ4 solver
122 Name of the solver (@ref exahype2.api.Solver).
124 @param parameters: Dict[str, Union[int, float]]
125 CCZ4 parameters that differ from DefaultParameters, e.g.
126 {"CCZ4k1": 0.0}. Keys which are not in DefaultParameters are
127 rejected, as they most likely are typos.
129 @param initial_condition: exahype2.api.InitPointWisely
130 Initial condition. It fills the 58 entries of the first-order
131 formulation, i.e. it can be any routine from
132 exagrype.api.initialvalues. The solver takes the first 25 as its
133 unknowns, and uses the other 33 as the initial value of the
134 derivatives. Defaults to exagrype.api.initialvalues.gauge_wave().
141 if initial_condition
is not None
142 else initialvalues.gauge_wave()
148 mode=exahype2.api.AuxiliaryVariables.Mode.CHANGING_ON_FACES,
149 data_name=
"DerivativeVariables",
155 return " (CCZ4 part)"
160 The unknowns whose advection terms the kernels omit
162 exagrype::ccz4::sourceSecondOrder() and exagrype::ccz4::ncpSecondOrder() omit
163 the advection @f$ \\beta^k \\partial _k Q @f$ of all 25 evolved
164 unknowns, so the numerical scheme has to add it for all of them, e.g.
167 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
168 exahype2.api.rkfd4.CentralDifferencesWithRungeKutta(
169 solver, patch_size, rk_order=4,
170 right_hand_side_kernel = exahype2.api.rkfd4.CentralDifferencesWithRungeKutta.RightHandSideKernel.CentralDifferencesWithLopsidedAdvection,
171 advection_velocity = exagrype.api.FOSOCCZ4Solver.ADVECTION_VELOCITY,
172 advected_quantities = solver.advected_quantities(),
174 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
176 The advection of the shift and of b belongs to the shifting shift
177 only, i.e. the routine leaves them out unless CCZ4s=1 and CCZ4b=1
178 (@ref exagrype.api.CCZ4SolverBase.CCZ4SolverBase.advected_quantities()
179 explains what the non-shifting shift does to the equation of b).
180 Either the numerical scheme or the non-conservative product adds the
181 advection of the unknowns returned
182 (@ref exagrype.api.CCZ4SolverBase.CCZ4SolverBase.ncp_adds_advection()).
186 (@ref exagrype.api.FOSOCCZ4Solver.FOSOCCZ4Solver.Unknowns).
191 excluded |= {
"shift",
"b"}
192 return [name
for name
in self.
Unknowns if name
not in excluded]
195 return "::exagrype::ccz4::enforceCCZ4constraintsOfEvolvedVariables(Q);"
206 """! The secondary entries are the auxiliary variables"""
208 ::exagrype::ccz4::ncpSecondOrder(
211 deltaQ, deltaDerivatives,
212 normal, CCZ4LapseType, CCZ4c, CCZ4e, CCZ4f, CCZ4b, CCZ4s, CCZ4mu
218 tarch::memset(S, 0, {sum(self.Unknowns.values())} * sizeof(double));
219 ::exagrype::ccz4::sourceSecondOrder(
222 CCZ4LapseType, CCZ4c, CCZ4e, CCZ4f, CCZ4b, CCZ4s, CCZ4itau, CCZ4eta, CCZ4k1, CCZ4k2, CCZ4k3
231 The initial condition fills 58 entries; we split them up
233 The routine wraps the user's implementation. It runs the
234 implementation on a local array of 58 entries (the implementation
235 sees it as Q) and then copies the first 25 entries onto Q and the
236 other 33 onto the derivatives.
239 if initial_condition.implementation
is None:
241 f
"Solver {self.name}: the initial condition needs an implementation "
242 "which fills the 58 entries of the first-order formulation"
247 double initialValues[{self.NUMBER_OF_CCZ4_ENTRIES}];
249 double* __restrict__ Q = initialValues;
250{initial_condition.implementation}
252 for (int i = 0; i < {evolved}; i++) Q[i] = initialValues[i];
253 for (int i = 0; i < {self._number_of_derivatives()}; i++) derivatives[i] = initialValues[{evolved} + i];
Everything the first-order and the second-order CCZ4 solvers share.
Solver for the Einstein equations in the first-/second-order reconstructed CCZ4 formulation.
List[str] advected_quantities(self)
The unknowns whose advection terms the kernels omit.
int _number_of_derivatives(cls)
str task_graph_title_suffix(self)
str _ncp_implementation(self)
The secondary entries are the auxiliary variables.
exahype2.api.InitPointWisely _adapt_initial_condition(self, exahype2.api.InitPointWisely initial_condition)
The initial condition fills 58 entries; we split them up.
str _source_implementation(self)
C++ which calls the source term kernel.
str _enforcement_implementation(self)
C++ which pushes the unknowns Q of one volume back onto the constraints.
int _number_of_evolved_entries(cls)
__init__(self, str name, Dict[str, Union[int, float]] parameters=None, exahype2.api.InitPointWisely initial_condition=None)
Create a second-order reconstructed CCZ4 solver.
A set of auxiliary variables of a solver.
Point-wise initial condition: given the physical position of a single degree of freedom,...
add_pde_term(self, PDETerm term)
Register a PDE term with this solver, or replace the one already registered under the same name and s...
add_auxiliary_variables(self, "AuxiliaryVariables" auxiliary)
Attach a set of auxiliary variables to the solver.