Peano
Loading...
Searching...
No Matches
FD4WithKODissipation.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 List, Union
6
7import exahype2.api
9
10from .actionsets import AddKreissOligerDissipation
11
12
14 """!
15
16 Fourth-order Finite Differences with Kreiss-Oliger dissipation
17
18 The numerical scheme is exahype2.api.rkfd4.CentralDifferencesWithRungeKutta
19 plus a Kreiss-Oliger dissipation of sixth order on top: Per Runge-Kutta
20 stage, it first evaluates the plain fourth-order right-hand side and
21 then adds
22
23 @f$ \\frac{\\sigma}{64 \\Delta x_d} (Q_{i-3} - 6 Q_{i-2} + 15 Q_{i-1} - 20 Q_i + 15 Q_{i+1} - 6 Q_{i+2} + Q_{i+3}) @f$
24
25 per axis d to the selected quantities (@ref
26 exagrype.api.actionsets.AddKreissOligerDissipation). Both kernels read
27 the same stage input, i.e. the outcome is the right-hand side with
28 dissipation. The dissipation stencil reaches three grid cells into the
29 neighbouring patches, so the scheme widens the halo from two to three
30 grid cells. Everything else is inherited.
31
32 To use the dissipation, replace the numerical scheme of a solver:
33
34 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35 solver.numerical_scheme = exagrype.api.FD4WithKODissipation(solver, patch_size=9, rk_order=4, kreiss_oliger_sigma=8.0)
36 solver.grid_construction = exahype2.api.rkfd4.SetupSimulationOverRegularGrid(solver, volume_size=0.04)
37 solver.plotter = exahype2.api.rkfd4.PlotAsVTKFile(solver, time_in_between_plots=0.1)
38 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39
40 The grid construction and the plotter remain those of
41 exahype2.api.rkfd4. The legacy ExaGRyPE runs used
42 kreiss_oliger_sigma=8.0. The scheme is three-dimensional only, as it
43 relies on exagrype::ccz4::addKreissOligerDissipation().
44
45 """
46
47 HALO_SIZE = 3
48
50 self,
51 solver: exahype2.api.Solver,
52 patch_size: int,
53 rk_order: int,
54 kreiss_oliger_sigma: float,
55 quantities: List[Union[str, int]] = None,
56 time_step_size: float = None,
57 cfl_constant: float = 0.5,
58 right_hand_side_kernel: exahype2.api.rkfd4.CentralDifferencesWithRungeKutta.RightHandSideKernel = exahype2.api.rkfd4.CentralDifferencesWithRungeKutta.RightHandSideKernel.CentralDifferences,
59 advection_velocity=None,
60 advected_quantities=None,
61 ):
62 """!
63
64 @param solver: exahype2.api.Solver
65 The solver this numerical scheme realises.
66
67 @param patch_size: int
68 Number of grid cells per axis within one patch. Has to be at least
69 HALO_SIZE=3.
70
71 @param rk_order: int
72 Order of the Runge-Kutta scheme, i.e. its number of stages.
73
74 @param kreiss_oliger_sigma: float
75 Scaling of the Kreiss-Oliger dissipation. Has to be non-negative.
76
77 @param quantities: List[str or int] or None
78 The unknowns which are subject to the dissipation. None, the
79 default, selects all unknowns. A string is the name of an unknown
80 as passed to the solver (e.g. "lapse" or "G" for exagrype.api.CCZ4Solver)
81 and selects all of its entries. An int is the index of one entry
82 of the unknowns. Auxiliary variables do not evolve in time and
83 hence cannot be selected.
84
85 @param time_step_size: float or None
86 Fixed time step size. If None, the time step size is adaptive.
87
88 @param cfl_constant: float
89 CFL constant for adaptive time step sizes.
90
91 @param right_hand_side_kernel: exahype2.api.rkfd4.CentralDifferencesWithRungeKutta.RightHandSideKernel
92 The kernel which evaluates the right-hand side before the
93 dissipation is added, @see
94 exahype2.api.rkfd4.CentralDifferencesWithRungeKutta.
95
96 @param advection_velocity: str or List[str or int] or None
97 Only for lopsided advection, @see
98 exahype2.api.rkfd4.CentralDifferencesWithRungeKutta.
99
100 @param advected_quantities: List[str or int] or None
101 Only for lopsided advection, @see
102 exahype2.api.rkfd4.CentralDifferencesWithRungeKutta.
103
104 """
105 super().__init__(
106 solver,
107 patch_size,
108 rk_order,
109 time_step_size=time_step_size,
110 cfl_constant=cfl_constant,
111 right_hand_side_kernel=right_hand_side_kernel,
112 advection_velocity=advection_velocity,
113 advected_quantities=advected_quantities,
114 )
115 if kreiss_oliger_sigma < 0.0:
116 raise ValueError(
117 f"Solver {solver.name}: kreiss_oliger_sigma has to be non-negative, "
118 f"but got {kreiss_oliger_sigma}"
119 )
120 self.kreiss_oliger_sigma = kreiss_oliger_sigma
122 list(range(solver.unknowns))
123 if quantities is None
124 else exahype2.api.rkfd4.Quantities.resolve_quantities(solver, quantities)
125 )
126
127 def _right_hand_side_action_sets(self, stage, cell_guard):
128 """!
129 The plain right-hand side of the superclass, followed by the dissipation
130 """
131 return super()._right_hand_side_action_sets(stage, cell_guard) + [
134 stage,
137 guard=cell_guard,
138 )
139 ]
Fourth-order Finite Differences with Kreiss-Oliger dissipation.
__init__(self, exahype2.api.Solver solver, int patch_size, int rk_order, float kreiss_oliger_sigma, List[Union[str, int]] quantities=None, float time_step_size=None, float cfl_constant=0.5, exahype2.api.rkfd4.CentralDifferencesWithRungeKutta.RightHandSideKernel right_hand_side_kernel=exahype2.api.rkfd4.CentralDifferencesWithRungeKutta.RightHandSideKernel.CentralDifferences, advection_velocity=None, advected_quantities=None)
_right_hand_side_action_sets(self, stage, cell_guard)
The plain right-hand side of the superclass, followed by the dissipation.
Add the Kreiss-Oliger dissipation to the right-hand side of one Runge-Kutta stage.
Fourth-order central Finite Differences with explicit Runge-Kutta time stepping, realised over a bloc...
Fourth-order Finite Differences with explicit Runge-Kutta time stepping over block-structured meshes.
Definition __init__.py:1