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["Probe_Evaluate right hand side stage 1"].action_sets
57
58
60 solver = _solver()
61 scheme = _lopsided(solver)
62 assert scheme.overlap == 3
63 assert solver._patch_with_halo.dim == (11, 11, 11)
64 # The velocity is an auxiliary variable, i.e. it follows the two unknowns
65 assert scheme.advection_velocity == [2, 3, 4]
66 assert scheme.advected_quantities == [0, 1]
67 tasks = _tasks(solver, tmp_path)
68 for stage in range(2):
69 action_sets = tasks[f"Probe_Evaluate right hand side stage {stage}"].action_sets
70 assert [type(action_set) for action_set in action_sets] == [
73 ]
74 body = action_sets[1].get_body_of_operation(
75 peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
76 )
77 assert "::exahype2::fd::addLopsidedAdvection(" in body
78 assert "constexpr int advectionVelocity[] = { 2, 3, 4 };" in body
79 assert "constexpr int advectedQuantities[] = { 0, 1 };" in body
80 # Estimate slot of the stage: stage * 2 unknowns * 5^3 grid cells
81 assert f"fineGridCellProbeQRhsEstimates.value + {stage * 2 * 125};" in body
82
83
85 with pytest.raises(ValueError):
86 _scheme(
87 _solver(),
88 right_hand_side_kernel=Kernel.CentralDifferencesWithLopsidedAdvection,
89 advected_quantities=["u"],
90 )
91 with pytest.raises(ValueError):
92 _scheme(
93 _solver(),
94 right_hand_side_kernel=Kernel.CentralDifferencesWithLopsidedAdvection,
95 advection_velocity="v",
96 )
97
98
100 with pytest.raises(ValueError):
101 _scheme(_solver(), advection_velocity="v", advected_quantities=["u"])
102
103
105 with pytest.raises(TypeError):
106 _scheme(_solver(), right_hand_side_kernel="lopsided")
107
108
110 with pytest.raises(ValueError):
111 _scheme(
112 _solver(),
113 right_hand_side_kernel=Kernel.CentralDifferencesWithLopsidedAdvection,
114 advection_velocity="v",
115 advected_quantities=["v"],
116 )
117
118
120 solver = _solver()
121 _scheme(
122 solver,
123 right_hand_side_kernel=Kernel.CentralDifferencesWithLopsidedAdvection,
124 advection_velocity=[2, 3],
125 advected_quantities=["u"],
126 )
127 with pytest.raises(ValueError):
128 _tasks(solver, tmp_path)
129
130
132 solver = _solver()
133 resolve = exahype2.api.rkfd4.resolve_quantities
134 assert resolve(solver, ["u", 1]) == [0, 1]
135 assert resolve(solver, ["v"], include_auxiliary_variables=True) == [2, 3, 4]
136 for quantities in (["v"], [2], [], [True], [1.5]):
137 with pytest.raises((ValueError, TypeError)):
138 resolve(solver, quantities)
139
140
142 solver = exagrype.api.CCZ4Solver("CCZ4", parameters={"CCZ4bs": 1.0, "CCZ4sk": 1.0})
144 solver,
145 10,
146 4,
147 kreiss_oliger_sigma=1.0,
148 right_hand_side_kernel=Kernel.CentralDifferencesWithLopsidedAdvection,
149 advection_velocity=exagrype.api.CCZ4Solver.ADVECTION_VELOCITY,
150 advected_quantities=solver.lopsided_advection_quantities(),
151 )
152 assert scheme.advection_velocity == [17, 18, 19]
153 # Everything but G (0-5), lapse (16), shift (17-19), phi (54) and K0 (58)
154 assert scheme.advected_quantities == list(range(6, 16)) + list(range(20, 54)) + [
155 55,
156 56,
157 57,
158 ]
159 # Without the advection of the shift, b and the derivatives of the shift
160 # are not advected
161 assert "b" not in exagrype.api.CCZ4Solver("CCZ4").lopsided_advection_quantities()
162
163
165 solver = exagrype.api.CCZ4Solver("CCZ4", parameters={"CCZ4bs": 1.0, "CCZ4sk": 1.0})
166 solver.numerical_scheme = exagrype.api.FD4WithKODissipation(
167 solver,
168 5,
169 2,
170 kreiss_oliger_sigma=1.0,
171 right_hand_side_kernel=Kernel.CentralDifferencesWithLopsidedAdvection,
172 advection_velocity="shift",
173 advected_quantities=solver.lopsided_advection_quantities(),
174 )
175 assert solver.numerical_scheme.overlap == 3
176 tasks = _tasks(solver, tmp_path)
177 assert [
178 type(action_set)
179 for action_set in tasks["CCZ4_Evaluate right hand side stage 0"].action_sets
180 ] == [
184 ]
Solver for the Einstein equations in the first-order CCZ4 formulation.
Definition CCZ4Solver.py:16
Fourth-order Finite Differences with Kreiss-Oliger dissipation.
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.
Evaluate the right-hand side of one Runge-Kutta stage over a patch.
Represents a Peano 4 project.
Definition Project.py:23
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