Peano
Loading...
Searching...
No Matches
test_fv_eigenvalue_tasks.py
Go to the documentation of this file.
1"""Unit tests for the separate eigenvalue tasks of the Finite Volume schemes:
2update cell -> compute max eigenvalue -> reduce max eigenvalue -> time step size
3(@ref exahype2.api.fv.actionsets.ComputeMaxEigenvalue)."""
4
5import types
6
7import pytest
8
9import peano4.api
11import exahype2.api
12from peano4.api.taskgraph import Task
13from peano4.api.taskgraph.compiler import FuseSteps
14
15SCHEMES = {
18}
19
20
21def _time_step(scheme, tmp_path):
22 solver = exahype2.api.Solver("Probe", 2)
23 solver.add_pde_term(exahype2.api.Flux(implementation="F[0] = Q[0]; F[1] = Q[1];"))
24 solver.add_pde_term(exahype2.api.MaxEigenvalue(implementation="*lambdaMax = 1.0;"))
25 solver.numerical_scheme = SCHEMES[scheme](solver, 9)
26 exahype2_project = types.SimpleNamespace(periodic_BC=[True, True, True], _dimensions=3)
27 peano_project = peano4.api.Project(["probe"], "probe", str(tmp_path))
29 solver.numerical_scheme.construct_output(exahype2_project, peano_project, graph)
30 return solver, {task.name: task for task in graph.tasks}, graph
31
32
33@pytest.mark.parametrize("scheme", SCHEMES)
35 scheme, tmp_path
36):
37 _, tasks, _ = _time_step(scheme, tmp_path)
38 compute = tasks["Probe_Compute max eigenvalue"]
39 reduce = tasks["Probe_Reduce max eigenvalue"]
40 cfl = tasks["Probe_Compute global CFL condition"]
41 assert compute.entity == Task.GridEntity.CELL
42 assert reduce.entity == Task.GridEntity.CELL
43 assert cfl.entity == Task.GridEntity.GLOBAL_END_OF_STEP
44 assert reduce.dependencies == [compute]
45 assert reduce in cfl.dependencies
46 assert tasks[f"Probe_{exahype2.api.Solver.NumericalScheme.DYNAMIC_MESH_REFINEMENT_TASK_NAME}"].dependencies.count(reduce) == 1
47
48
50 # Sommerfeld roll overs read the time step size, which the CFL task replaces
51 _, tasks, _ = _time_step("explicit", tmp_path)
52 cfl = tasks["Probe_Compute global CFL condition"]
53 assert "Probe_Roll over faces" not in tasks
54 assert tasks["Probe_Project on faces"] in cfl.dependencies
55 _, tasks, _ = _time_step("optimistic", tmp_path)
56 cfl = tasks["Probe_Compute global CFL condition"]
57 assert tasks["Probe_Project on faces"] in cfl.dependencies
58
59
61 tmp_path,
62):
63 _, tasks, _ = _time_step("explicit", tmp_path)
64 assert tasks["Probe_Compute max eigenvalue"].dependencies == [
65 tasks["Probe_Update cell"]
66 ]
67 assert tasks["Probe_Project on faces"].dependencies == [tasks["Probe_Update cell"]]
68
69
71 tmp_path,
72):
73 _, tasks, _ = _time_step("optimistic", tmp_path)
74 assert set(tasks["Probe_Compute max eigenvalue"].dependencies) == {
75 tasks["Probe_Update cell"],
76 tasks["Probe_Insert patch interior"],
77 }
78 spawn = tasks["Probe_Spawn patch interior update"]
79 assert tasks["Probe_Compute max eigenvalue"] not in spawn.dependencies
80 assert spawn in tasks["Probe_Compute global CFL condition"].dependencies
81
82
83@pytest.mark.parametrize("scheme", SCHEMES)
85 _, tasks, _ = _time_step(scheme, tmp_path)
86 for name, task in tasks.items():
87 if "Update cell" in name or "Insert patch interior" in name:
88 continue
89 for action_set in task.action_sets:
90 body = action_set.get_body_of_operation(
91 peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
92 )
93 if type(action_set).__name__ == "ComputeMaxEigenvalue":
94 assert "max_eigenvalue_kernel" not in body
95 assert "setMaxEigenvalue( 0" in body
96 for name in ["Probe_Update cell", "Probe_Update cell shell"]:
97 if name not in tasks:
98 continue
99 for action_set in tasks[name].action_sets:
100 body = action_set.get_body_of_operation(
101 peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
102 )
103 assert "setMaxEigenvalue" not in body
104
105
106@pytest.mark.parametrize("scheme", SCHEMES)
108 _, tasks, graph = _time_step(scheme, tmp_path)
109 steps = FuseSteps.translate(graph, "S", None, None)
110 names = [
111 [type(action_set).__name__ for action_set in step.action_sets] for step in steps
112 ]
113 holders = [
114 step_names
115 for step_names in names
116 if "UpdateCell" in step_names and "ComputeMaxEigenvalue" in step_names
117 ]
118 assert len(holders) == 1, names
119 # The projection writes the face data which the reconstruction reads at the
120 # beginning of a traversal, i.e. it follows in the next one, together with
121 # the reduction. The time step size acts in the last traversal
122 assert "ProjectPatchOntoFaces" not in holders[0]
123 assert "ReduceMaxEigenvalue" not in holders[0]
124 # The reconstruction interpolates the hanging faces itself, i.e. no
125 # traversal is spent on the interpolation
126 assert len(names) == 2, names
127 assert "ProjectPatchOntoFaces" in names[-1]
128 assert "ReduceMaxEigenvalue" in names[-1]
129 assert "ComputeGlobalCFLCondition" in names[-1]
130
131
133 """!
134 The eigenvalue task must call the eigenvalue kernel (not the time step
135 kernel).
136 """
137 solver, _, _ = _time_step("explicit", tmp_path)
138 call = solver.numerical_scheme.max_eigenvalue_kernel_call
139 assert "maxEigenvalueOverPatch" in call
140 assert "timeStepWithRusanov" not in call
The conservative flux F(Q) of a hyperbolic PDE.
Definition Flux.py:8
The maximum absolute eigenvalue of the flux Jacobian in a given direction, i.e.
Abstract base class for all ExaHyPE 2 solvers.
Definition Solver.py:17
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,...
Represents a Peano 4 project.
Definition Project.py:26
Holds a sequence of Task instances.
Definition Graph.py:9
Compilers are simple functions.
Definition __init__.py:1
The task graph abstraction allows users to formalise their solver steps over small task graphs which ...
Definition __init__.py:1
test_update_eigenvalue_and_reduction_fold_into_one_traversal(scheme, tmp_path)
test_eigenvalue_task_calls_the_eigenvalue_kernel(tmp_path)
The eigenvalue task must call the eigenvalue kernel (not the time step kernel).
test_update_does_not_store_an_eigenvalue(scheme, tmp_path)
test_time_step_size_is_computed_after_the_roll_over(tmp_path)
test_optimistic_eigenvalue_follows_both_branches_and_runs_beside_the_spawn(tmp_path)
test_explicit_eigenvalue_follows_the_update_and_runs_beside_the_projection(tmp_path)
test_eigenvalue_is_computed_stored_and_reduced_before_the_time_step_size(scheme, tmp_path)