Peano
Loading...
Searching...
No Matches
test_rkfd4_lopsided_advection.py
Go to the documentation of this file.
1import types
2
3import pytest
4
5import peano4.api
8
9import exahype2.api
10import exagrype.api
11
12Kernel = exahype2.api.rkfd4.CentralDifferencesWithRungeKutta.RightHandSideKernel
13
14
15def _solver():
16 solver = exahype2.api.Solver("Probe", {"u": 2, "v": 3})
17 solver.add_pde_term(exahype2.api.InitPointWisely(implementation="Q[0] = 0.0;"))
18 return solver
19
20
21def _scheme(solver, **arguments):
23 solver, patch_size=5, rk_order=2, time_step_size=0.1, **arguments
24 )
25 solver.numerical_scheme = scheme
26 return scheme
27
28
29def _lopsided(solver, **arguments):
30 return _scheme(
31 solver,
32 right_hand_side_kernel=Kernel.CentralDifferencesWithLopsidedAdvection,
33 advection_velocity="v",
34 advected_quantities=["u"],
35 **arguments,
36 )
37
38
39def _tasks(solver, directory):
40 exahype2_project = types.SimpleNamespace(periodic_BC=[True, True, True])
41 peano_project = peano4.api.Project(["probe"], "probe", str(directory))
42 time_step = peano4.api.taskgraph.Graph()
43 solver.numerical_scheme.construct_output(exahype2_project, peano_project, time_step)
44 return {task.name: task for task in time_step.tasks}
45
46
48 solver = _solver()
49 scheme = _scheme(solver)
50 assert scheme.right_hand_side_kernel == Kernel.CentralDifferences
51 assert scheme.overlap == 2
52 tasks = _tasks(solver, tmp_path)
53 assert [
54 type(action_set)
55 for action_set in tasks[
56 "Probe_Evaluate Runge-Kutta right hand side stage 1"
57 ].action_sets
59 assert "Probe_Add lopsided advection stage 1" not in tasks
60
61
63 solver = _solver()
64 scheme = _lopsided(solver)
65 assert scheme.overlap == 3
66 assert solver._patch_with_halo.dim == (11, 11, 11)
67 # The velocity is an unknown, i.e. it follows u
68 assert scheme.advection_velocity == [2, 3, 4]
69 assert scheme.advected_quantities == [0, 1]
70 tasks = _tasks(solver, tmp_path)
71 for stage in range(2):
72 # One task per action set, so the compiler can run them in parallel to
73 # the tasks of other solvers. They form a chain.
74 evaluation = tasks[f"Probe_Evaluate Runge-Kutta right hand side stage {stage}"]
75 advection = tasks[f"Probe_Add lopsided advection stage {stage}"]
76 assert [type(a) for a in evaluation.action_sets] == [
78 ]
79 assert [type(a) for a in advection.action_sets] == [
81 ]
82 assert advection.dependencies == [evaluation]
83 body = advection.action_sets[0].get_body_of_operation(
84 peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
85 )
86 assert "::exahype2::fd::addLopsidedAdvection(" in body
87 assert "constexpr int advectionVelocity[] = { 2, 3, 4 };" in body
88 assert "constexpr int advectedQuantities[] = { 0, 1 };" in body
89 # Estimate slot of the stage: stage * 5 unknowns * 5^3 grid cells
90 assert f"fineGridCellProbeQRhsEstimates.value + {stage * 5 * 125};" in body
91
92
94 with pytest.raises(ValueError):
95 _scheme(
96 _solver(),
97 right_hand_side_kernel=Kernel.CentralDifferencesWithLopsidedAdvection,
98 advected_quantities=["u"],
99 )
100 with pytest.raises(ValueError):
101 _scheme(
102 _solver(),
103 right_hand_side_kernel=Kernel.CentralDifferencesWithLopsidedAdvection,
104 advection_velocity="v",
105 )
106
107
109 with pytest.raises(ValueError):
110 _scheme(_solver(), advection_velocity="v", advected_quantities=["u"])
111
112
114 with pytest.raises(TypeError):
115 _scheme(_solver(), right_hand_side_kernel="lopsided")
116
117
119 with pytest.raises(ValueError):
120 _scheme(
121 _solver(),
122 right_hand_side_kernel=Kernel.CentralDifferencesWithLopsidedAdvection,
123 advection_velocity="v",
124 advected_quantities=["w"],
125 )
126
127
129 solver = _solver()
130 _scheme(
131 solver,
132 right_hand_side_kernel=Kernel.CentralDifferencesWithLopsidedAdvection,
133 advection_velocity=[2, 3],
134 advected_quantities=["u"],
135 )
136 with pytest.raises(ValueError):
137 _tasks(solver, tmp_path)
138
139
141 solver = _solver()
142 resolve = exahype2.api.rkfd4.resolve_quantities
143 assert resolve(solver, ["u", 1]) == [0, 1]
144 assert resolve(solver, ["v"]) == [2, 3, 4]
145 for quantities in (["w"], [5], [], [True], [1.5]):
146 with pytest.raises((ValueError, TypeError)):
147 resolve(solver, quantities)
148
149
151 solver = exagrype.api.FOCCZ4Solver("CCZ4", parameters={"CCZ4b": 1, "CCZ4s": 1})
153 solver,
154 10,
155 4,
156 kreiss_oliger_sigma=1.0,
157 right_hand_side_kernel=Kernel.CentralDifferencesWithLopsidedAdvection,
158 advection_velocity=exagrype.api.FOCCZ4Solver.ADVECTION_VELOCITY,
159 advected_quantities=solver.advected_quantities(),
160 )
161 assert scheme.advection_velocity == [17, 18, 19]
162 # Everything but G (0-5), lapse (16), shift (17-19) and phi (24)
163 assert scheme.advected_quantities == (
164 list(range(6, 16)) + list(range(20, 24)) + list(range(25, 58))
165 )
166 # Without the advection of the shift, b and the derivatives of the shift
167 # are not advected
168 assert "b" not in exagrype.api.FOCCZ4Solver("CCZ4").advected_quantities()
169 # The non-shifting shift advects everything but b and the derivatives of
170 # the shift, too
171 non_shifting = exagrype.api.FOCCZ4Solver(
172 "CCZ4", parameters={"CCZ4b": 0, "CCZ4s": 1}
173 ).advected_quantities()
174 shifting = solver.advected_quantities()
175 assert set(shifting) - set(non_shifting) == {"b", "dxShift", "dyShift", "dzShift"}
176
177
179 solver = exagrype.api.FOCCZ4Solver("CCZ4", parameters={"CCZ4b": 1, "CCZ4s": 1})
180 solver.numerical_scheme = exagrype.api.FD4WithKODissipation(
181 solver,
182 5,
183 2,
184 kreiss_oliger_sigma=1.0,
185 right_hand_side_kernel=Kernel.CentralDifferencesWithLopsidedAdvection,
186 advection_velocity="shift",
187 advected_quantities=solver.advected_quantities(),
188 )
189 assert solver.numerical_scheme.overlap == 3
190 tasks = _tasks(solver, tmp_path)
191 chain = [
192 "CCZ4_Evaluate Runge-Kutta right hand side stage 0",
193 "CCZ4_Add lopsided advection stage 0",
194 "CCZ4_Add Kreiss-Oliger dissipation stage 0",
195 ]
196 assert [[type(a) for a in tasks[name].action_sets] for name in chain] == [
200 ]
201 assert tasks[chain[1]].dependencies == [tasks[chain[0]]]
202 assert tasks[chain[2]].dependencies == [tasks[chain[1]]]
Fourth-order Finite Differences with Kreiss-Oliger dissipation.
Solver for the Einstein equations in the first-order CCZ4 formulation.
Add the Kreiss-Oliger dissipation to the right-hand side of one Runge-Kutta stage.
Point-wise initial condition: given the physical position of a single degree of freedom,...
Abstract base class for all ExaHyPE 2 solvers.
Definition Solver.py:17
Fourth-order central Finite Differences with explicit Runge-Kutta time stepping, realised over a bloc...
Add advection terms with lopsided stencils to the right-hand side of one Runge-Kutta stage.
Represents a Peano 4 project.
Definition Project.py:26
Holds a sequence of Task instances.
Definition Graph.py:9
This file is part of the ExaGRyPE project.
Definition __init__.py:1
The Python-side model of "what happens during one mesh sweep".
Definition __init__.py:1
The task graph abstraction allows users to formalise their solver steps over small task graphs which ...
Definition __init__.py:1