Peano
Loading...
Searching...
No Matches
FOSOCCZ4Solver.py
Go to the documentation of this file.
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
3"""
4
5from typing import Dict, List, Union
6
7import exahype2.api
8
9from . import initialvalues
10from .CCZ4SolverBase import CCZ4SolverBase
11
12
14 """!
15
16 Solver for the Einstein equations in the first-/second-order reconstructed
17 CCZ4 formulation
18
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.
29
30 ## Ping-pong with the reconstruction solver
31
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
41 condition forever.
42
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.
47
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.
55
56 @ref page_exagrype_fo_so_project_plan for the design and its status.
57
58 ## Shortcomings
59
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
68 not available yet.
69 - Checkpoints do not cover auxiliary variables, i.e. the solver cannot
70 write checkpoints.
71
72 """
73
74 Unknowns = {
75 "G": 6,
76 "K": 6,
77 "theta": 1,
78 "Z": 3,
79 "lapse": 1,
80 "shift": 3,
81 "b": 3,
82 "Kex": 1,
83 "phi": 1,
84 }
85 """!
86
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.
90
91 """
92
93 DerivativeUnknowns = {
94 "dLapse": 3,
95 "dxShift": 3,
96 "dyShift": 3,
97 "dzShift": 3,
98 "dxG": 6,
99 "dyG": 6,
100 "dzG": 6,
101 "P": 3,
102 }
103 """!
104
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.
108
109 """
110
112 self,
113 name: str,
114 parameters: Dict[str, Union[int, float]] = None,
115 initial_condition: exahype2.api.InitPointWisely = None,
116 ):
117 """!
118
119 Create a second-order reconstructed CCZ4 solver
120
121 @param name: str
122 Name of the solver (@ref exahype2.api.Solver).
123
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.
128
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().
135
136 """
137 super().__init__(name, self.Unknowns, parameters)
138 self.add_pde_term(
140 initial_condition
141 if initial_condition is not None
142 else initialvalues.gauge_wave()
143 )
144 )
146 "Derivatives",
148 mode=exahype2.api.AuxiliaryVariables.Mode.CHANGING_ON_FACES,
149 data_name="DerivativeVariables",
150 )
152
153 @property
154 def task_graph_title_suffix(self) -> str:
155 return " (CCZ4 part)"
156
157 def advected_quantities(self) -> List[str]:
158 """!
159
160 The unknowns whose advection terms the kernels omit
161
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.
165 via
166
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(),
173 )
174 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
175
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()).
183
184 @return List[str]
185 Names of unknowns
186 (@ref exagrype.api.FOSOCCZ4Solver.FOSOCCZ4Solver.Unknowns).
187
188 """
189 excluded = set()
190 if self._parameters["CCZ4b"] == 0 or self._parameters["CCZ4s"] == 0:
191 excluded |= {"shift", "b"}
192 return [name for name in self.Unknowns if name not in excluded]
193
195 return "::exagrype::ccz4::enforceCCZ4constraintsOfEvolvedVariables(Q);"
196
197 @classmethod
199 return sum(cls.Unknowns.values())
200
201 @classmethod
202 def _number_of_derivatives(cls) -> int:
203 return sum(cls.DerivativeUnknowns.values())
204
205 def _ncp_implementation(self) -> str:
206 """! The secondary entries are the auxiliary variables"""
207 return """
208 ::exagrype::ccz4::ncpSecondOrder(
209 BTimesDeltaQ,
210 Q, derivatives,
211 deltaQ, deltaDerivatives,
212 normal, CCZ4LapseType, CCZ4c, CCZ4e, CCZ4f, CCZ4b, CCZ4s, CCZ4mu
213 );
214"""
215
216 def _source_implementation(self) -> str:
217 return f"""
218 tarch::memset(S, 0, {sum(self.Unknowns.values())} * sizeof(double));
219 ::exagrype::ccz4::sourceSecondOrder(
220 S,
221 Q, derivatives,
222 CCZ4LapseType, CCZ4c, CCZ4e, CCZ4f, CCZ4b, CCZ4s, CCZ4itau, CCZ4eta, CCZ4k1, CCZ4k2, CCZ4k3
223 );
224"""
225
227 self, initial_condition: exahype2.api.InitPointWisely
229 """!
230
231 The initial condition fills 58 entries; we split them up
232
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.
237
238 """
239 if initial_condition.implementation is None:
240 raise ValueError(
241 f"Solver {self.name}: the initial condition needs an implementation "
242 "which fills the 58 entries of the first-order formulation"
243 )
244 evolved = self._number_of_evolved_entries()
246 implementation=f"""
247 double initialValues[{self.NUMBER_OF_CCZ4_ENTRIES}];
248 {{
249 double* __restrict__ Q = initialValues;
250{initial_condition.implementation}
251 }}
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];
254"""
255 )
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.
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.
__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...
Definition Solver.py:916
add_auxiliary_variables(self, "AuxiliaryVariables" auxiliary)
Attach a set of auxiliary variables to the solver.
Definition Solver.py:776