Peano
Loading...
Searching...
No Matches
test_hanging_faces.py
Go to the documentation of this file.
1"""Hanging faces on adaptive meshes: the toolbox action sets
2(toolbox.blockstructured.api.InterpolateHangingFaces,
3toolbox.blockstructured.api.RestrictHangingFaces) and how the Finite
4Volume scheme uses them."""
5
6import peano4.api
10import exahype2.api
12
14Interpolate = toolbox.blockstructured.api.InterpolateHangingFaces
15Restrict = toolbox.blockstructured.api.RestrictHangingFaces
16
17
19 return peano4.api.datamodel.Patch((2, 9, 9), 4, "QFace")
20
21
23 action_set = Interpolate(_face_patch())
24 body = action_set.get_body_of_operation(ActionSet.OPERATION_CREATE_HANGING_FACE)
25 assert "interpolateHaloLayer_AoS_linear_with_constant_extrapolation(" in body
26 assert "coarseGridFacesQFace(marker.getSelectedFaceNumber()).value" in body
27 assert "fineGridFaceQFace.value" in body
28 for operation in [
29 ActionSet.OPERATION_DESTROY_HANGING_FACE,
30 ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME,
31 ActionSet.OPERATION_CREATE_CELL,
32 ]:
33 assert action_set.get_body_of_operation(operation) == ""
34
35
37 action_set = Interpolate(_face_patch(), Interpolate.Scheme.PiecewiseConstant)
38 body = action_set.get_body_of_operation(ActionSet.OPERATION_CREATE_HANGING_FACE)
39 assert "interpolateHaloLayer_AoS_piecewise_constant(" in body
40
41
43 action_set = Restrict(_face_patch(), clear_guard="myClearGuard")
44 body = action_set.get_body_of_operation(ActionSet.OPERATION_DESTROY_HANGING_FACE)
45 assert "restrictInnerHalfOfHaloLayer_AoS_averaging(" in body
46 assert "coarseGridFacesQFace(marker.getSelectedFaceNumber()).value" in body
47 clear = action_set.get_body_of_operation(ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME)
48 assert "clearHaloLayerAoS(" in clear
49 assert (
50 action_set.get_guard_of_operation(ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME)
51 == "myClearGuard"
52 )
53
54
56 action_set = Restrict(_face_patch(), Restrict.Scheme.Inject)
57 body = action_set.get_body_of_operation(ActionSet.OPERATION_DESTROY_HANGING_FACE)
58 assert "restrictInnerHalfOfHaloLayer_AoS_inject(" in body
59 assert (
60 action_set.get_body_of_operation(ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME)
61 == ""
62 )
63
64
65def _graphs(tmp_path, **scheme_arguments):
66 solver = exahype2.api.Solver("Probe", 4)
67 solver.add_pde_term(exahype2.api.Flux(implementation=""))
68 solver.add_pde_term(exahype2.api.MaxEigenvalue(implementation=""))
69 solver.add_pde_term(exahype2.api.InitPointWisely(implementation=""))
70 solver.numerical_scheme = exahype2.api.fv.RusanovWithExplicitEuler(
71 solver, 9, **scheme_arguments
72 )
73 solver.grid_construction = exahype2.api.fv.SetupSimulationOverRegularGrid(
74 solver, volume_size=0.1
75 )
76 exahype2_project = exahype2.api.Project(
77 ["probe"], "probe", "probe", directory=str(tmp_path)
78 )
79 exahype2_project.set_global_simulation_parameters(
80 dimensions=2,
81 offset=[0.0, 0.0],
82 size=[1.0, 1.0],
83 min_end_time=1.0,
84 periodic_BC=[True, True, True],
85 )
86 peano_project = peano4.api.Project(["probe"], "probe", str(tmp_path))
87 graphs = [peano4.api.taskgraph.Graph() for _ in range(4)]
88 solver.generate_solver_realisation(exahype2_project, peano_project, *graphs)
89 return solver, [{task.name: task for task in graph.tasks} for graph in graphs[:2]]
90
91
92def _action_sets_of_type(task, action_set_type):
93 return [a for a in task.action_sets if isinstance(a, action_set_type)]
94
95
97 tmp_path,
98):
99 solver, (setup, time_step) = _graphs(tmp_path)
100 (interpolation,) = _action_sets_of_type(
101 time_step["Probe_Reconstruct"], Interpolate
102 )
103 # Interpolation is no task of its own: it acts before the reconstruction
104 assert "Probe_Interpolate hanging faces" not in time_step
105 actions = time_step["Probe_Reconstruct"].action_sets
106 assert actions.index(interpolation) < min(
107 i for i, a in enumerate(actions) if type(a).__name__ == "ReconstructPatchWithHalo"
108 )
109 assert interpolation.scheme == Interpolate.Scheme.Linear
110 assert interpolation.d["FACE_NAME"] == solver._patch_overlap_current_time_step.name
111 assert "Probe_Restrict on hanging faces" not in time_step
112 (restriction,) = _action_sets_of_type(
113 time_step["Probe_Project on faces"], Restrict
114 )
115 assert restriction.scheme == Restrict.Scheme.Averaging
116 assert restriction.d["FACE_NAME"] == solver._patch_overlap_update.name
117 (setup_restriction,) = _action_sets_of_type(
118 setup["Probe Project on faces"], Restrict
119 )
120 assert setup_restriction.d["FACE_NAME"] == solver._patch_overlap_update.name
121
122
124 _, (setup, time_step) = _graphs(
125 tmp_path,
126 interpolation=Interpolate.Scheme.PiecewiseConstant,
127 restriction=Restrict.Scheme.Inject,
128 )
129 (interpolation,) = _action_sets_of_type(
130 time_step["Probe_Reconstruct"], Interpolate
131 )
132 assert interpolation.scheme == Interpolate.Scheme.PiecewiseConstant
133 for task in [
134 time_step["Probe_Project on faces"],
135 setup["Probe Project on faces"],
136 ]:
137 (restriction,) = _action_sets_of_type(task, Restrict)
138 assert restriction.scheme == Restrict.Scheme.Inject
139
140
142 # The roll over copies the update, which lives within one traversal only
143 # (src/exahype2/api/fv/adrs/0003-roll-over-is-part-of-the-projection.md).
144 # The restriction precedes the roll over, as the roll over has to copy the
145 # restricted data
146 _, (_, time_step) = _graphs(tmp_path)
147 projection = time_step["Probe_Project on faces"]
148 assert "Probe_Restrict on hanging faces" not in time_step
149 assert "Probe_Roll over faces" not in time_step
150 assert [type(a).__name__ for a in projection.action_sets] == [
151 "ProjectPatchOntoFaces",
152 "RestrictHangingFaces",
153 "RollOverUpdatedFace",
154 ]
The conservative flux F(Q) of a hyperbolic PDE.
Definition Flux.py:8
Point-wise initial condition: given the physical position of a single degree of freedom,...
The maximum absolute eigenvalue of the flux Jacobian in a given direction, i.e.
ExaHyPE 2 project.
Definition Project.py:15
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-...
Setup phase counterpart to RusanovWithExplicitEuler: sets the initial condition for a Finite Volume s...
Represents a Peano 4 project.
Definition Project.py:26
Patch implementation of a degree of freedom.
Definition Patch.py:7
Action set (reactions to events).
Definition ActionSet.py:6
Holds a sequence of Task instances.
Definition Graph.py:9
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
test_interpolation_defaults_to_linear_in_create_hanging_face()
test_reconstruction_interpolates_before_it_reconstructs_and_restricts_projection(tmp_path)
_action_sets_of_type(task, action_set_type)
test_averaging_restricts_in_destroy_hanging_face_and_clears_faces()
test_projection_hosts_the_restriction_and_the_roll_over(tmp_path)
_graphs(tmp_path, **scheme_arguments)
test_schemes_are_configurable(tmp_path)