Peano
Loading...
Searching...
No Matches
CCZ4SolverBase.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
5import enum
6from typing import Dict, List, Union
7
8import exahype2.api
9import peano4.api
12
13
15 """!
16
17 Everything the first-order and the second-order CCZ4 solvers share
18
19 The base class hosts the CCZ4 parameters, the PDE terms (which delegate
20 to the kernels in exagrype::ccz4) and the optional enforcement of the
21 CCZ4 constraints. The initial condition is up to the user. The kernels
22 always work on the 58 entries of CCZ4, see
23 exagrype.api.FOCCZ4Solver.Unknowns, which they take as two pointers:
24 one to the 25 primary and one to the 33 secondary entries. The two
25 subclasses differ only in where the secondary entries live:
26
27 - exagrype.api.FOCCZ4Solver evolves all 58 as unknowns. The secondary
28 entries follow the primary ones, i.e. the pointers are Q and Q+25.
29 - exagrype.api.FOSOCCZ4Solver evolves 25 unknowns, and the other 33
30 entries are auxiliary variables, i.e. they live in separate memory.
31
32 The subclasses therefore override the hooks _ncp_implementation() and
33 _source_implementation(), which call the kernel of their formulation.
34 The base class appends the advection terms to the non-conservative
35 product if the numerical scheme does not add them
36 (@ref exagrype.api.CCZ4SolverBase.CCZ4SolverBase.ncp_adds_advection()).
37
38 @ref exagrype.api.FOCCZ4Solver, @ref exagrype.api.FOSOCCZ4Solver
39
40 """
41
42 NUMBER_OF_CCZ4_ENTRIES = 58
43 """! Number of entries which the kernels in exagrype::ccz4 work on """
44
45 class EnforceCCZ4Constraint(enum.Enum):
46 """!
47
48 When to push the solution back onto the algebraic CCZ4 constraints
49
50 - No: never. This is the default.
51 - OnlyFinalSolution: after each task which writes a new solution
52 (exahype2.api.Solver.SolutionUpdateTaskTag), i.e. once per time
53 step.
54 - IntermediateSteps: in addition after each task which writes an
55 intermediate solution (exahype2.api.Solver.IntermediateSolutionUpdateTag),
56 i.e. after each Runge-Kutta stage. For single-step schemes such as
57 the Finite Volumes, this is the same as OnlyFinalSolution.
58
59 @ref exagrype.api.CCZ4SolverBase.CCZ4SolverBase.enforce_ccz4_constraint()
60
61 """
62
63 No = 0
64 OnlyFinalSolution = 1
65 IntermediateSteps = 2
66
67 DefaultParameters = {
68 "CCZ4LapseType": 0,
69 "CCZ4c": 1.0,
70 "CCZ4e": 1.0,
71 "CCZ4f": 0.75,
72 "CCZ4b": 1,
73 "CCZ4s": 0,
74 "CCZ4itau": 1.0,
75 "CCZ4eta": 1.0,
76 "CCZ4k1": 0.1,
77 "CCZ4k2": 0.0,
78 "CCZ4k3": 0.5,
79 "CCZ4GLMc": 1.2,
80 "CCZ4GLMd": 2.0,
81 "CCZ4mu": 0.2,
82 }
83 """!
84
85 Default values of the CCZ4 parameters, taken from the legacy ExaGRyPE
86 gauge wave setup: harmonic slicing (CCZ4LapseType=0) and a shift which
87 does not evolve (CCZ4s=0). The legacy black hole runs use 1+log slicing
88 (CCZ4LapseType=1) and the Gamma driver (CCZ4s=1) in its shifting shift
89 variant (CCZ4b=1, which only matters once the shift evolves). Integer
90 values become int constants of the generated solver class, all others
91 double constants.
92
93 The integer parameters are switches:
94
95 - CCZ4LapseType: 0 for harmonic slicing, 1 for 1+log slicing.
96 - CCZ4b: variant of the Gamma driver, if the shift evolves. 1 is the
97 shifting shift, i.e. the equations of the shift, of b and of the
98 derivatives of the shift hold their advection terms. 0 is the
99 non-shifting shift without these terms
100 (exagrype::ccz4::ncpFirstOrder()).
101 - CCZ4s: 1 evolves the shift (Gamma driver), 0 freezes it.
102
103 Whether the first-order or the second-order formulation is solved is
104 not a parameter: Pick exagrype.api.FOCCZ4Solver or
105 exagrype.api.FOSOCCZ4Solver.
106
107 Why there are 58 entries, why the switches are integers and why there
108 are no parameters CCZ4ds and CCZ4xi is written down in
109 src/exagrype/ccz4/adrs/0001-ccz4-has-58-entries-and-integer-switches.md.
110
111 """
112
113 Switches = ("CCZ4LapseType", "CCZ4b", "CCZ4s")
114 """!
115
116 The integer parameters which accept 0 and 1 only.
117
118 """
119
120 ADVECTION_VELOCITY = "shift"
121 """!
122
123 The variable which advects the unknowns, i.e. the velocity of the
124 advection terms, whoever adds them: the lopsided advection of the
125 numerical scheme or the non-conservative product
126 (@ref exagrype.api.CCZ4SolverBase.CCZ4SolverBase.advected_quantities()).
127
128 """
129
131 self,
132 name: str,
133 unknowns: Dict[str, int],
134 parameters: Dict[str, Union[int, float]] = None,
135 ):
136 """!
137
138 Create a CCZ4 solver
139
140 @param name: str
141 Name of the solver (@ref exahype2.api.Solver).
142
143 @param unknowns: Dict[str, int]
144 The evolved unknowns of the subclass (@ref exahype2.api.Solver).
145 The subclass has to add all entries of CCZ4 that it does not evolve
146 as auxiliary variables, so the entries add up to 58.
147
148 @param parameters: Dict[str, Union[int, float]]
149 CCZ4 parameters that differ from DefaultParameters, e.g.
150 {"CCZ4k1": 0.0}. Keys which are not in DefaultParameters are
151 rejected, as they most likely are typos. The switches
152 (@ref exagrype.api.CCZ4SolverBase.CCZ4SolverBase.Switches) have
153 to be the integers 0 or 1.
154
155 The solver has no initial condition. Add one as for any other solver,
156 e.g. solver.add_pde_term(exagrype.api.initialvalues.gauge_wave()), or
157 your own exahype2.api.InitPointWisely.
158
159 """
160 super().__init__(name, unknowns=unknowns)
161
162 self._enforce_ccz4_constraint = CCZ4SolverBase.EnforceCCZ4Constraint.No
163
165 for key, value in (parameters or {}).items():
166 if key not in self.DefaultParameters:
167 raise KeyError(
168 f"Solver {name}: unknown CCZ4 parameter {key!r}. "
169 f"Available parameters are {list(self.DefaultParameters)}."
170 )
171 if key in self.Switches and (
172 isinstance(value, bool)
173 or not isinstance(value, int)
174 or value not in (0, 1)
175 ):
176 raise TypeError(
177 f"Solver {name}: CCZ4 parameter {key!r} is an integer "
178 f"switch, i.e. has to be 0 or 1, but got {value!r}"
179 )
180 self._parameters[key] = value
181
183 'static_assert(Dimensions == 3, "CCZ4 (ExaGRyPE) is three-dimensional only");'
184 )
185 for key, value in self._parameters.items():
186 cpp_type = (
187 "int" if isinstance(self.DefaultParameters[key], int) else "double"
188 )
190 f"static constexpr {cpp_type} {key} = {value};"
191 )
192
194 """
195#include "exagrype/ccz4/Kernels.h"
196#include "exahype2/fd/CentralAdvection.h"
197#include "exagrype/initialvalues/InitialValues.h"
198#include "exagrype/initialvalues/ApplyTwoPunctures.h"
199"""
200 )
201
204
205 def advected_quantities(self) -> List[str]:
206 """!
207
208 The unknowns whose advection terms the kernels of exagrype::ccz4 leave out
209
210 The kernels hold no advection terms @f$ \\beta^k \\partial _k Q_q @f$
211 which need the derivative of the advected unknown q itself. This list
212 is the only place which defines these unknowns. Either the numerical
213 scheme adds their advection with lopsided stencils, e.g. via
214
215 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
216 exahype2.api.rkfd4.CentralDifferencesWithRungeKutta(
217 solver, patch_size, rk_order=4,
218 right_hand_side_kernel = exahype2.api.rkfd4.CentralDifferencesWithRungeKutta.RightHandSideKernel.CentralDifferencesWithLopsidedAdvection,
219 advection_velocity = exagrype.api.FOCCZ4Solver.ADVECTION_VELOCITY,
220 advected_quantities = solver.advected_quantities(),
221 )
222 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
223
224 These are all unknowns besides the conformal metric G, the lapse,
225 the shift and phi: The advection terms of the metric, the lapse,
226 the shift and phi are part of the algebraic source
227 (exagrype::ccz4::sourceFirstOrder()), which expresses them through the
228 auxiliary unknowns, i.e. the first derivatives.
229
230 or the solver appends it to the non-conservative product, discretised
231 with the central differences of the scheme
232 (exahype2::fd::addCentralAdvection()), if the scheme adds none. The
233 solver rejects a scheme which advects other quantities
234 (@ref exagrype.api.CCZ4SolverBase.CCZ4SolverBase.ncp_adds_advection()).
235
236 The advection of b and of the derivatives of the shift (dxShift,
237 dyShift, dzShift) belongs to the shifting shift only, i.e. the
238 routine leaves these unknowns out unless CCZ4s=1 and CCZ4b=1.
239
240 The equation of b holds the time derivative of Ghat (the unknown
241 Z), which comprises the advection of Ghat. The shifting shift
242 subtracts this advection again, i.e. only the advection of b itself
243 is left, which is added as for any other unknown. The non-shifting
244 shift (CCZ4b=0) keeps the advection of Ghat in the equation of b.
245 Who advects each quantity on its own cannot add it there, so the
246 kernel does so with the derivatives it is given
247 (src/exagrype/ccz4/adrs/0002-ccz4b-selects-the-shifting-or-the-non-shifting-shift.md).
248
249 @return List[str]
250 Names of unknowns
251 (@ref exagrype.api.FOCCZ4Solver.FOCCZ4Solver.Unknowns).
252
253 """
254 excluded = {"G", "lapse", "shift", "phi"}
255 if self._parameters["CCZ4b"] == 0 or self._parameters["CCZ4s"] == 0:
256 excluded |= {"b", "dxShift", "dyShift", "dzShift"}
257 return [name for name in self.Unknowns if name not in excluded]
258
259 def ncp_adds_advection(self) -> bool:
260 """!
261
262 Whether the non-conservative product has to add the advection terms
263
264 The advection terms @f$ \\beta^k \\partial _k Q_q @f$ of the unknowns
265 of advected_quantities() are added either by the numerical
266 scheme or by the non-conservative product, never by both. You choose
267 the formulation (the solver class) and whether the Finite Differences
268 use lopsided advection (the kernel of the numerical scheme). The
269 solver decides which fits this choice, and
270 generate_solver_realisation() registers the non-conservative product
271 accordingly:
272
273 - exahype2.api.rkfd4.CentralDifferencesWithRungeKutta (and its
274 subclass exagrype.api.FD4WithKODissipation) with the kernel
275 CentralDifferences adds no advection terms. The non-conservative
276 product adds them, discretised with the central differences of
277 the scheme.
278 - The same scheme with CentralDifferencesWithLopsidedAdvection adds
279 the advection itself, and the non-conservative product adds none.
280 The scheme has to advect exactly
281 @ref exagrype.api.CCZ4SolverBase.CCZ4SolverBase.advected_quantities()
282 with ADVECTION_VELOCITY. Otherwise, it would add some terms twice or
283 miss some, and the routine raises a ValueError.
284 - The Finite Volumes of exahype2.api.fv add no advection terms, and
285 the non-conservative product adds none either, i.e. they solve CCZ4
286 without these advection terms, as before
287 (@ref exagrype.api.FOCCZ4Solver). Whether the non-conservative
288 product should add them is open.
289
290 The rationale is written down in
291 src/exagrype/ccz4/adrs/0003-the-solver-picks-who-adds-the-advection.md.
292
293 @return bool
294 True if the non-conservative product has to add the advection terms.
295
296 """
297 scheme = self.numerical_scheme
298 match scheme:
299 case (
302 ):
303 return False
305 Kernel = (
306 exahype2.api.rkfd4.CentralDifferencesWithRungeKutta.RightHandSideKernel
307 )
308 if scheme.right_hand_side_kernel == Kernel.CentralDifferences:
309 return True
310 velocity, advected = self._advection_indices()
311 if scheme.advection_velocity != velocity or sorted(
312 scheme.advected_quantities
313 ) != sorted(advected):
314 raise ValueError(
315 f"Solver {self.name}: the lopsided advection of the "
316 f"numerical scheme advects the quantities "
317 f"{scheme.advected_quantities} with the velocity "
318 f"{scheme.advection_velocity}, but the kernels leave the "
319 f"quantities {advected} to the scheme, to be advected "
320 f"with the velocity {velocity}. Pass "
321 f"advection_velocity={type(self).__name__}.ADVECTION_VELOCITY "
322 f"and advected_quantities=solver.advected_quantities() "
323 f"to the scheme, or use its kernel CentralDifferences "
324 f"instead, which lets the solver add the advection."
325 )
326 return False
327 case _:
328 raise TypeError(
329 f"Solver {self.name}: cannot decide who adds the advection "
330 f"terms for the numerical scheme {type(scheme).__name__}. "
331 "Supported are exahype2.api.fv.RusanovWithExplicitEuler, "
332 "exahype2.api.fv.RusanovWithOptimisticExplicitEuler and "
333 "exahype2.api.rkfd4.CentralDifferencesWithRungeKutta."
334 )
335
337 """!
338 Indices of the velocity components (ADVECTION_VELOCITY) and of the
339 advected unknowns (advected_quantities()) within Q, in the
340 form both the lopsided advection of the scheme and
341 exahype2::fd::addCentralAdvection() take them
342 """
343 resolve = exahype2.api.rkfd4.resolve_quantities
344 return (
345 resolve(self, [self.ADVECTION_VELOCITY]),
346 resolve(self, self.advected_quantities()),
347 )
348
349 def enforce_ccz4_constraint(self, value: "CCZ4SolverBase.EnforceCCZ4Constraint"):
350 """!
351
352 Set when the solver pushes the solution back onto the CCZ4 constraints
353
354 By default, the solver does not enforce the constraints. If you
355 switch the enforcement on, generate_solver_realisation() inserts a
356 task which applies exagrype::ccz4::enforceCCZ4constraints() to each
357 volume or grid point after each tagged solution update of the
358 numerical scheme.
359
360 @param value: CCZ4SolverBase.EnforceCCZ4Constraint
361 No, OnlyFinalSolution or IntermediateSteps.
362
363 """
364 if not isinstance(value, CCZ4SolverBase.EnforceCCZ4Constraint):
365 raise TypeError(
366 f"Solver {self.name}: enforce_ccz4_constraint() expects a "
367 f"CCZ4SolverBase.EnforceCCZ4Constraint, but got {value!r}"
368 )
369 self._enforce_ccz4_constraint = value
370
372 self,
373 exahype2_project,
374 peano_project,
375 setup_simulation,
376 time_step,
377 plot,
378 mesh_adaptation,
379 add_global_tasks=True,
380 ):
381 """!
382
383 Create the solver's task graphs and insert the constraint enforcement
384
385 The routine first registers the non-conservative product, with the
386 advection terms if the numerical scheme does not add them
387 (@ref exagrype.api.CCZ4SolverBase.CCZ4SolverBase.ncp_adds_advection()).
388 The solver cannot do this earlier, as the numerical scheme is
389 assigned after the solver has been created. Afterwards, the routine
390 calls the superclass, which lets the grid construction, the
391 numerical scheme and the plotter add their tasks and generates the
392 solver class with the PDE terms. If the constraint enforcement is
393 switched on
394 (enforce_ccz4_constraint()), it afterwards inserts the enforcement
395 after each tagged solution update of the numerical scheme. Which
396 patch a tagged task writes and which guard it uses depends on the
397 scheme, so the routine distinguishes the schemes explicitly
398 (@ref page_exahype2_solver_manipulate_solver_steps). It raises an
399 exception for any other scheme.
400
401 All insertions work on the patch which the tagged tasks write and
402 use the cell guard:
403
404 - exahype2.api.fv.RusanovWithExplicitEuler: one task after Update
405 cell.
406 - exahype2.api.fv.RusanovWithOptimisticExplicitEuler: one task after
407 both Update cell and Insert patch interior. Each cell runs exactly
408 one of the two, so the task constrains every cell once, after its
409 update.
410 - exahype2.api.rkfd4.CentralDifferencesWithRungeKutta and its
411 subclass exagrype.api.FD4WithKODissipation: one task after
412 Complete time step and, for IntermediateSteps, one task after each
413 Prepare stage k on the stage input.
414
415 The scheme's log of the time stepping graph does not show the
416 enforcement. With TEXT or VISUALISATION logging, the routine hence
417 logs the graph once more.
418
419 """
422 exahype2_project,
423 peano_project,
424 setup_simulation,
425 time_step,
426 plot,
427 mesh_adaptation,
428 add_global_tasks,
429 )
431 if self._enforce_ccz4_constraint == Enforce.No:
432 return
433
434
436 scheme = self.numerical_scheme
437 match scheme:
438 case (
441 ):
442 stage_input = None
444 stage_input = self._stage_input
445 case _:
446 raise TypeError(
447 f"Solver {self.name}: cannot enforce the CCZ4 constraints for "
448 f"the numerical scheme {type(scheme).__name__}. Supported are "
449 "exahype2.api.fv.RusanovWithExplicitEuler, "
450 "exahype2.api.fv.RusanovWithOptimisticExplicitEuler and "
451 "exahype2.api.rkfd4.CentralDifferencesWithRungeKutta."
452 )
453
454
457 time_step,
459 time_step, exahype2.api.Solver.SolutionUpdateTaskTag
460 ),
461 self._patch,
462 )
463
464 if (
465 self._enforce_ccz4_constraint == Enforce.IntermediateSteps
466 and stage_input is not None
467 ):
468 for anchor in self._tasks_of_this_solver(
469 time_step, exahype2.api.Solver.IntermediateSolutionUpdateTag
470 ):
471 self._insert_constraint_enforcement(time_step, [anchor], stage_input)
472
473 title = (
474 f"Time stepping task graph for {self.name} with CCZ4 constraint enforcement"
475 )
476 if peano4.api.Logger().is_visualisation:
477 time_step.visualise(title=title)
478 if peano4.api.Logger().is_text:
479 time_step.log_as_text(title=title)
480
481 def _tasks_of_this_solver(self, time_step, tag):
482 """!
483 Tasks of time_step which carry tag and belong to this solver, as the
484 graph holds the tasks of all solvers
485 """
486 return [
487 task
488 for task in time_step.find_tasks(tag)
489 if task.name.startswith(self.name + "_")
490 ]
491
492 def _insert_constraint_enforcement(self, time_step, anchors, patch):
493 """!
494
495 Insert the enforcement of the CCZ4 constraints after anchors
496
497 The routine creates a task which applies
498 exagrype::ccz4::enforceCCZ4constraints() to each volume or grid point
499 of patch, and inserts it directly after all anchors via
500 peano4.api.taskgraph.Graph.insert_after(). The anchors' successors,
501 e.g. the projection onto the faces, hence see the constrained data
502 only. The task uses the solver's cell guard: If several anchors
503 write patch, each cell is updated by one of them, and the task runs
504 once per cell after all of them.
505
506 @param time_step: peano4.api.taskgraph.Graph
507 The time stepping task graph which holds the anchors.
508
509 @param anchors: List[peano4.api.taskgraph.Task]
510 The tasks which write patch. If the list is empty, the routine
511 does nothing.
512
513 @param patch: peano4.api.datamodel.Patch
514 The cell data which the anchors write, i.e. the solution or a
515 stage input.
516
517 """
518 if not anchors:
519 return
520 anchor_names = " and ".join(
521 anchor.name[len(self.name) + 1 :] for anchor in anchors
522 )
524 name=f"{self.name}_Enforce CCZ4 constraints after {anchor_names}",
525 entity=peano4.api.taskgraph.Task.GridEntity.CELL,
526 )
527
528 task.use_cell(patch, peano4.api.taskgraph.Task.DataAccess.READ_AND_WRITE)
529 task.add_action_set(
530 toolbox.blockstructured.api.ApplyPointWiselyToPatch(
531 patch=patch,
532 implementation=self._enforcement_implementation(),
533 guard=self.grid_selector.createCellGuard(),
534 additional_includes=self._get_default_includes()
536 )
537 )
538 time_step.insert_after(anchors, task)
539
541 """!
542 C++ which pushes the unknowns Q of one volume back onto the constraints.
543 Hook for the subclasses, as the unknowns they evolve differ.
544 """
545 return "::exagrype::ccz4::enforceCCZ4constraints(Q);"
546
547 @property
548 def parameters(self) -> Dict[str, Union[int, float]]:
549 """!
550 The CCZ4 parameters the solver is generated with (read-only copy).
551 """
552 return dict(self._parameters)
553
555 """!
556
557 Register the source and the maximum eigenvalue
558
559 The terms are stateless, i.e. static functions: they only use the
560 compile-time constants of the solver and the kernels of
561 exagrype::ccz4. Both the Finite Volumes (exahype2.api.fv) and the
562 Finite Differences (exahype2.api.rkfd4) call stateless terms. The
563 non-conservative product is not registered here: which one fits
564 depends on the numerical scheme, which is assigned after the solver
565 has been created, so generate_solver_realisation() registers it
566 (@ref exagrype.api.CCZ4SolverBase.CCZ4SolverBase._register_non_conservative_product()).
567
568 """
569 self.add_pde_term(
571 implementation=self._source_implementation(), stateless=True
572 )
573 )
574 self.add_pde_term(
576 implementation=self._max_eigenvalue_implementation(), stateless=True
577 )
578 )
579
580 def _register_non_conservative_product(self, advection: bool):
581 """!
582
583 Register the non-conservative product, with or without the advection terms
584
585 generate_solver_realisation() calls this routine, as the
586 non-conservative product depends on the numerical scheme
587 (@ref exagrype.api.CCZ4SolverBase.CCZ4SolverBase.ncp_adds_advection()).
588 The term calls the kernel of the formulation (_ncp_implementation())
589 and, if advection is set, adds the advection terms of
590 advected_quantities() with ADVECTION_VELOCITY
591 (_advection_implementation()). It replaces the term of a former
592 realisation, so a project can be generated several times.
593
594 Any other non-conservative product, i.e. one added through
595 add_pde_term(), is rejected: The solver would replace it silently, and
596 it could add advection terms which the scheme adds as well, or miss
597 them (src/exagrype/ccz4/adrs/0003-the-solver-picks-who-adds-the-advection.md).
598 Whoever needs another non-conservative product derives a solver class
599 and overrides _ncp_implementation().
600
601 @param advection: bool
602 Whether the term adds the advection terms.
603
604 """
605 name = exahype2.api.NonconservativeProduct.NAME
606 foreign = [
607 term
608 for term in self.pde_terms
609 if term.name == name and term is not self._non_conservative_product
610 ]
611 if foreign:
612 raise ValueError(
613 f"Solver {self.name}: a non-conservative product has been added "
614 f"with add_pde_term(). {type(self).__name__} registers its "
615 f"non-conservative product itself when it is realised, as the "
616 f"advection terms depend on the numerical scheme "
617 f"(ncp_adds_advection()), and would replace yours. Derive a "
618 f"solver class from {type(self).__name__} and override "
619 f"_ncp_implementation() instead."
620 )
621 implementation = self._ncp_implementation()
622 if advection:
623 implementation += self._advection_implementation()
625 implementation=implementation, stateless=True
626 )
628
629 def _ncp_implementation(self) -> str:
630 """!
631
632 C++ which calls the non-conservative product kernel
633
634 The Finite Volume kernels hand over the jump deltaQ along one normal,
635 the fourth-order Finite Differences of exahype2.api.rkfd4 the
636 derivative along one normal times the mesh width. This is what
637 exagrype::ccz4::ncpFirstOrder() and ncpSecondOrder() expect.
638 Hook for the subclasses, as they select the formulation.
639
640 """
641 raise NotImplementedError
642
644 """!
645
646 C++ which adds the advection terms to the non-conservative product
647
648 The term adds @f$ \\beta^n \\partial _n Q_q @f$ for the normal n of the
649 call and each unknown q of advected_quantities(),
650 discretised with the derivative the scheme hands over
651 (exahype2::fd::addCentralAdvection()). The indices are those which
652 the lopsided advection of a scheme gets, so either way the same
653 terms are added. Both formulations hold the unknowns in Q, and Q
654 holds the shift.
655
656 """
657 velocity, quantities = self._advection_indices()
658 return f"""
659 {{
660 constexpr int velocity[] = {{{", ".join(str(i) for i in velocity)}}};
661 constexpr int quantities[] = {{{", ".join(str(i) for i in quantities)}}};
662 ::exahype2::fd::addCentralAdvection(Q, deltaQ, BTimesDeltaQ, normal, velocity, quantities, {len(quantities)});
663 }}
664"""
665
666 def _source_implementation(self) -> str:
667 """!
668 C++ which calls the source term kernel. Hook for the subclasses.
669 """
670 raise NotImplementedError
671
673 return """
674 ::exagrype::ccz4::maxEigenvalue(Q, normal, CCZ4e, CCZ4GLMc, CCZ4GLMd, lambdaMax);
675"""
When to push the solution back onto the algebraic CCZ4 constraints.
Everything the first-order and the second-order CCZ4 solvers share.
str _ncp_implementation(self)
C++ which calls the non-conservative product kernel.
str _source_implementation(self)
C++ which calls the source term kernel.
__init__(self, str name, Dict[str, int] unknowns, Dict[str, Union[int, float]] parameters=None)
Create a CCZ4 solver.
_register_non_conservative_product(self, bool advection)
Register the non-conservative product, with or without the advection terms.
generate_solver_realisation(self, exahype2_project, peano_project, setup_simulation, time_step, plot, mesh_adaptation, add_global_tasks=True)
Create the solver's task graphs and insert the constraint enforcement.
Dict[str, Union[int, float]] parameters(self)
The CCZ4 parameters the solver is generated with (read-only copy).
_register_pde_terms(self)
Register the source and the maximum eigenvalue.
_advection_indices(self)
Indices of the velocity components (ADVECTION_VELOCITY) and of the advected unknowns (advected_quanti...
_enforce_ccz4_constraint
One task after all writers of the new solution: The optimistic Finite Volumes write it in one of two ...
_patch
One task after all writers of the new solution: The optimistic Finite Volumes write it in one of two ...
_tasks_of_this_solver(self, time_step, tag)
Tasks of time_step which carry tag and belong to this solver, as the graph holds the tasks of all sol...
str _advection_implementation(self)
C++ which adds the advection terms to the non-conservative product.
_insert_constraint_enforcement(self, time_step, anchors, patch)
Insert the enforcement of the CCZ4 constraints after anchors.
str _enforcement_implementation(self)
C++ which pushes the unknowns Q of one volume back onto the constraints.
enforce_ccz4_constraint(self, "CCZ4SolverBase.EnforceCCZ4Constraint" value)
Set when the solver pushes the solution back onto the CCZ4 constraints.
List[str] advected_quantities(self)
The unknowns whose advection terms the kernels of exagrype.ccz4 leave out.
bool ncp_adds_advection(self)
Whether the non-conservative product has to add the advection terms.
The maximum absolute eigenvalue of the flux Jacobian in a given direction, i.e.
The non-conservative product B(Q) applied to a jump deltaQ in a given direction, i....
Abstract base class for all ExaHyPE 2 solvers.
Definition Solver.py:17
"Solver.NumericalScheme" numerical_scheme(self)
Definition Solver.py:660
add_abstract_solver_attribute(self, str declaration)
Add a raw C++ member attribute declaration to the generated Abstract<SolverName> class (.
Definition Solver.py:947
str _get_default_includes(self)
Includes every generated action set can rely on being available, regardless of which action sets a co...
Definition Solver.py:832
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_user_solver_includes(self, str value)
Add further includes to this property, if your solver requires some additional routines from other he...
Definition Solver.py:825
pde_terms
True iff at least one PDE term has no implementation.
Definition Solver.py:907
str name(self)
Unique solver name.
Definition Solver.py:653
The algebraic, volume-distributed source term S(Q) of a hyperbolic PDE - as opposed to PointSource,...
Finite Volumes with a Rusanov Riemann solver and explicit Euler time stepping, realised over a block-...
Finite Volumes with a Rusanov Riemann solver and optimistic explicit Euler time stepping,...
Fourth-order central Finite Differences with explicit Runge-Kutta time stepping, realised over a bloc...
Singleton logger for the Peano 4 Python API.
Definition Logger.py:37
One task within a peano4.api.taskgraph.Graph.
Definition Task.py:8
The task graph abstraction allows users to formalise their solver steps over small task graphs which ...
Definition __init__.py:1