12def _solver(time_step_size=None, rk_order=3, boundary="dirichlet"):
16 "dirichlet", "sommerfeld", or None for a solver without boundary
17 condition term, i.e. for a domain that is periodic along all axes.
21 solver.add_pde_term(
exahype2.api.Flux(implementation=
"F[0] = Q[0]; F[1] = Q[1];"))
23 if boundary ==
"dirichlet":
25 exahype2.api.DirichletBoundaryConditions(implementation=
"Q[0] = 0.0;")
27 elif boundary ==
"sommerfeld":
29 exahype2.api.SommerfeldBoundaryConditions(implementation=
"Q[0] = 0.0;")
32 solver, patch_size=4, rk_order=rk_order, time_step_size=time_step_size
38 exahype2_project = types.SimpleNamespace(periodic_BC=list(periodic_BC))
41 solver.numerical_scheme.construct_output(exahype2_project, peano_project, time_step)
42 return {task.name: task
for task
in time_step.tasks}
47 assert set(tasks) == {
48 "Probe_Apply Dirichlet BCs stage 0",
49 "Probe_Apply Dirichlet BCs stage 1",
50 "Probe_Apply Dirichlet BCs stage 2",
51 "Probe_Reconstruct stage 0",
52 "Probe_Reconstruct stage 1",
53 "Probe_Reconstruct stage 2",
54 "Probe_Disable load balancing",
55 "Probe_Evaluate Runge-Kutta right hand side stage 0",
56 "Probe_Evaluate Runge-Kutta right hand side stage 1",
57 "Probe_Evaluate Runge-Kutta right hand side stage 2",
58 "Probe_Prepare stage 1",
59 "Probe_Prepare stage 2",
60 "Probe_Complete time step",
61 "Probe_Project stage 1 onto faces",
62 "Probe_Project stage 2 onto faces",
63 "Probe_Project solution onto faces",
64 "Probe_Roll over stage 1 faces",
65 "Probe_Roll over stage 2 faces",
66 "Probe_Roll over solution faces",
67 "Probe_Compute max eigenvalue",
68 "Probe_Reduce max eigenvalue",
69 "Probe_Compute time step size",
70 f
"Probe_{exahype2.api.Solver.NumericalScheme.DYNAMIC_MESH_REFINEMENT_TASK_NAME}",
78 tasks[
"Probe_Complete time step"]
79 in tasks[
"Probe_Project solution onto faces"].dependencies
82 tasks[
"Probe_Project solution onto faces"]
83 in tasks[
"Probe_Compute max eigenvalue"].dependencies
86 tasks[
"Probe_Compute max eigenvalue"]
87 not in tasks[
"Probe_Roll over solution faces"].dependencies
92 tasks[
"Probe_Compute max eigenvalue"]
93 in tasks[
"Probe_Reduce max eigenvalue"].dependencies
96 tasks[
"Probe_Reduce max eigenvalue"]
97 in tasks[
"Probe_Compute time step size"].dependencies
101 tasks[f
"Probe_Prepare stage {stage}"]
102 in tasks[f
"Probe_Project stage {stage} onto faces"].dependencies
106 tasks[f
"Probe_Project stage {stage} onto faces"]
107 in tasks[f
"Probe_Roll over stage {stage} faces"].dependencies
111 tasks[f
"Probe_Roll over stage {stage} faces"]
112 in tasks[f
"Probe_Reconstruct stage {stage}"].dependencies
116 tasks[
"Probe_Roll over stage 1 faces"]
117 in tasks[
"Probe_Apply Dirichlet BCs stage 1"].dependencies
120 tasks[
"Probe_Apply Dirichlet BCs stage 1"]
121 in tasks[
"Probe_Reconstruct stage 1"].dependencies
124 tasks[
"Probe_Roll over solution faces"]
125 in tasks[
"Probe_Compute time step size"].dependencies
129 tasks[
"Probe_Disable load balancing"]
130 in tasks[
"Probe_Apply Dirichlet BCs stage 0"].dependencies
134 type(a).__name__
for a
in tasks[
"Probe_Reconstruct stage 1"].action_sets
136 "InterpolateHangingFaces",
137 "ReconstructPatchWithHalo",
140 type(a).__name__
for a
in tasks[
"Probe_Project stage 1 onto faces"].action_sets
141 ] == [
"ProjectPatchOntoFaces",
"RestrictHangingFaces"]
145 "Probe_Evaluate Runge-Kutta right hand side stage 1",
146 "Probe_Roll over stage 1 faces",
148 assert len(tasks[name].action_sets) == 1, name
152 return {name
for name, task
in tasks.items()
if tag
in task.tags}
158 final =
_tagged(tasks, exahype2.api.Solver.SolutionUpdateTaskTag)
159 intermediate =
_tagged(tasks, exahype2.api.Solver.IntermediateSolutionUpdateTag)
160 assert set(final) == {
"Probe_Complete time step"}
161 assert set(intermediate) == {
"Probe_Prepare stage 1",
"Probe_Prepare stage 2"}
162 tagged = final | intermediate
168 for action_set
in tasks[name].action_sets
174 [action_set] = tasks[
"Probe_Apply Dirichlet BCs stage 2"].action_sets
175 body = action_set.get_body_of_operation(
176 peano4.api.solversteps.ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME
180 "repositories::instanceOfProbe.getMinTimeStamp() + 1.0 * "
181 "repositories::instanceOfProbe.getMinTimeStepSize()," in body
187 _solver(rk_order=2, boundary=
None), tmp_path, periodic_BC=(
True,
True,
True)
189 assert not any(
"Dirichlet" in name
for name
in tasks)
195 for task
in tasks.values()
196 for action_set
in task.action_sets
201 with pytest.raises(ValueError, match=
"all axes are periodic"):
208 for name, task
in tasks.items()
209 for action_set
in task.action_sets
216 assert not any(
"Dirichlet" in name
for name
in tasks)
218 assert set(roll_overs) == {
219 "Probe_Roll over stage 1 faces",
220 "Probe_Roll over stage 2 faces",
221 "Probe_Roll over solution faces",
225 for name, increment
in [
226 (
"Probe_Roll over stage 1 faces",
"0.5"),
227 (
"Probe_Roll over stage 2 faces",
"0.5"),
228 (
"Probe_Roll over solution faces",
"0.0"),
230 action_set = roll_overs[name]
235 body = action_set.get_body_of_operation(
236 peano4.api.solversteps.ActionSet.OPERATION_TOUCH_FACE_LAST_TIME
238 assert "::exahype2::blockstructured::applySommerfeldBoundaryConditions(" in body
240 f
"{increment} * repositories::instanceOfProbe.getMinTimeStepSize()," in body
242 assert "tarch::la::Vector<Dimensions, double>({0.0, 0.0, 0.0})" in body
244 assert body.index(
"applySommerfeldBoundaryConditions") < body.index(
250 solver =
_solver(rk_order=3, boundary=
"sommerfeld")
253 solver.numerical_scheme.butcher_tableau,
254 "relative_time_step_sizes",
255 lambda: [0.0, 1.0, 0.5],
257 with pytest.raises(ValueError, match=
"decrease"):
264 solver.numerical_scheme.butcher_tableau,
265 "relative_time_step_sizes",
266 lambda: [0.0, 1.0, 0.5],
269 assert "Probe_Apply Dirichlet BCs stage 2" in tasks
273 solver =
_solver(rk_order=4, boundary=
None)
275 tableau = solver.numerical_scheme.butcher_tableau
277 def combination(task_name):
280 for action_set
in tasks[task_name].action_sets
287 for stage
in range(1, 4):
288 action_set = combination(f
"Probe_Prepare stage {stage}")
289 assert action_set.weights == tableau.weight_matrix()[stage]
290 assert action_set.output
is solver._stage_input
291 final = combination(
"Probe_Complete time step")
292 assert final.weights == tableau.final_estimate_weights()
293 assert final.output
is solver._patch
298 kernels = tmp_path /
"kernels"
302 "Probe_fd4_eigenvalue_2d",
303 "Probe_fd4_eigenvalue_3d",
304 "rungekutta_linear_combination",
306 assert (kernels / (name +
".h")).exists(), name
307 assert (kernels / (name +
".cpph")).exists(), name
308 wrapper = (kernels /
"Probe_fd4.h").read_text()
309 assert '#include "Probe_fd4_2d.h"' in wrapper
310 assert '#include "Probe_fd4_eigenvalue_3d.h"' in wrapper
311 assert "Probe_rightHandSideWithFD4" in (kernels /
"Probe_fd4_2d.cpph").read_text()
315 solver =
_solver(time_step_size=0.01, boundary=
None)
317 assert not (tmp_path /
"kernels" /
"Probe_fd4_eigenvalue_2d.h").exists()
320 for task
in tasks.values()
321 for action_set
in task.action_sets
323 [time_step_size] = tasks[
"Probe_Compute time step size"].action_sets
325 "const double admissibleTimeStepSize = 0.01;"
326 in time_step_size.get_body_of_unprepareTraversal()
331 solver =
_solver(rk_order=4, boundary=
None)
333 [action_set] = tasks[
334 "Probe_Evaluate Runge-Kutta right hand side stage 2"
336 body = action_set.get_body_of_operation(
337 peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
340 assert "getMinTimeStamp() + 0.6666666666666666 * timeStepSize" in body
341 assert "fineGridCellProbeQRhsEstimates.value + 64;" in body
342 assert "fineGridCellProbeQRhsEstimates.value + 256;" in body
344 "Probe_rightHandSideWithFD4<\n 4,\n 2,\n 2,\n 0\n>(\n patchData,\n [&]("
353 solver, patch_size=4, rk_order=2
355 with pytest.raises(AssertionError):
361 Peano's stacks require that each stored datum is loaded by the next
362 sweep which uses it. The reconstruction of a later stage is the last
363 reader of the stage input, as the next combination writes it from
364 scratch, so it must not store it.
366 solver =
_solver(rk_order=4, boundary=
None)
368 Access = peano4.api.taskgraph.Task.DataAccess
370 tasks[
"Probe_Reconstruct stage 0"].cell_data_access[solver._patch]
371 == Access.READ_AND_WRITE
373 for stage
in range(1, 4):
374 reconstruction = tasks[f
"Probe_Reconstruct stage {stage}"]
376 reconstruction.cell_data_access[solver._stage_input]
377 == Access.READ_AND_DISCARD
380 tasks[f
"Probe_Prepare stage {stage}"].cell_data_access[solver._stage_input]
385@pytest.mark.parametrize("time_step_size", [None, 0.01])
387 tmp_path, time_step_size
389 solver =
_solver(rk_order=2, boundary=
None, time_step_size=time_step_size)
391 task = tasks[
"Probe_Compute time step size"]
392 assert task.entity == peano4.api.taskgraph.Task.GridEntity.GLOBAL_END_OF_STEP
393 assert not task.cell_data
395 assert not any(task
in other.dependencies
for other
in tasks.values())
400 f
"Probe_{exahype2.api.Solver.NumericalScheme.DYNAMIC_MESH_REFINEMENT_TASK_NAME}"
407 Access = peano4.api.taskgraph.Task.DataAccess
409 def access_to_estimates(name):
412 for data, access
in tasks[name].cell_data_access.items()
413 if data.name.endswith(
"RhsEstimates")
419 access_to_estimates(
"Probe_Evaluate Runge-Kutta right hand side stage 0")
420 == Access.READ_AND_WRITE
423 access_to_estimates(
"Probe_Evaluate Runge-Kutta right hand side stage 1")
424 == Access.READ_AND_WRITE
426 assert access_to_estimates(
"Probe_Prepare stage 1") == Access.READ_AND_WRITE
427 assert access_to_estimates(
"Probe_Prepare stage 2") == Access.READ_AND_WRITE
428 assert access_to_estimates(
"Probe_Complete time step") == Access.READ_AND_DISCARD
The conservative flux F(Q) of a hyperbolic PDE.
The maximum absolute eigenvalue of the flux Jacobian in a given direction, i.e.
Abstract base class for all ExaHyPE 2 solvers.
Fourth-order central Finite Differences with explicit Runge-Kutta time stepping, realised over a bloc...
Combine the solution with the right-hand side estimates of the Runge-Kutta stages.
Store the maximum eigenvalue over all grid cells of a patch.
Project a patch's data onto the overlap held on its surrounding faces, so the halo layers can be reco...
Roll over the face data, and set the ghost grid cells along the domain boundary through exahype2....
Copy patch_overlap_update - the face overlap exahype2.api.rkfd4.actionsets.ProjectPatchOntoFaces has ...
Represents a Peano 4 project.
Holds a sequence of Task instances.
The Python-side model of "what happens during one mesh sweep".
The task graph abstraction allows users to formalise their solver steps over small task graphs which ...
test_dirichlet_accepts_decreasing_stage_time_stamps(tmp_path, monkeypatch)
test_stage_combinations_use_rows_of_butcher_tableau(tmp_path)
test_one_reconstruction_per_stage_and_chain_of_stages(tmp_path)
test_periodic_domain_needs_no_boundary_tasks(tmp_path)
test_fixed_time_step_size_skips_eigenvalue(tmp_path)
test_boundary_values_use_stage_time_stamp(tmp_path)
test_right_hand_side_uses_stage_time_stamp_and_estimate_slot(tmp_path)
test_estimates_are_discarded_last_but_not_written_first(tmp_path)
test_stage_input_is_loaded_once_after_each_store(tmp_path)
Peano's stacks require that each stored datum is loaded by the next sweep which uses it.
test_sommerfeld_replaces_roll_over_and_omits_boundary_tasks(tmp_path)
test_stage_combinations_are_tagged_as_solution_updates(tmp_path)
test_adaptive_time_stepping_requires_max_eigenvalue(tmp_path)
test_periodic_domain_rejects_boundary_condition_term(tmp_path)
_solver(time_step_size=None, rk_order=3, boundary="dirichlet")
test_kernels_are_generated_for_both_dimensions(tmp_path)
test_sommerfeld_rejects_decreasing_stage_time_stamps(tmp_path, monkeypatch)
test_time_step_size_acts_at_the_end_of_the_time_step_and_needs_no_traversal(tmp_path, time_step_size)
_construct_time_step(solver, directory, periodic_BC=(False, False, False))