1"""Unit tests for sets of auxiliary variables (@ref exahype2.api.AuxiliaryVariables)."""
16 solver.add_pde_term(
exahype2.api.Flux(implementation=
"F[0] = 1.0;", stateless=
True))
34 "Distortion", {
"jacobian": 4,
"shift": 1}
36 assert distortion.size == 5
37 assert distortion.variable_positions == {
"jacobian": 0,
"shift": 4}
38 assert distortion.argument_name ==
"distortion"
39 assert distortion.delta_argument_name ==
"deltaDistortion"
40 assert "static constexpr int shift = 4;" in distortion.variables_declaration()
43@pytest.mark.parametrize("name", ["bathymetry", "1B", "B a"])
45 with pytest.raises(ValueError):
52 solver.add_auxiliary_variables(bathymetry)
53 solver.add_auxiliary_variables(distortion)
54 assert solver.auxiliary_variables == [bathymetry, distortion]
55 assert solver.number_of_auxiliary_variables == 6
57 assert solver.auxiliary_variable_offset(bathymetry) == 3
58 assert solver.auxiliary_variable_offset(distortion) == 4
64 solver.add_auxiliary_variables(bathymetry)
65 with pytest.raises(ValueError):
66 solver.add_auxiliary_variables(bathymetry)
67 with pytest.raises(ValueError):
68 solver.add_auxiliary_variables(
76 first.add_auxiliary_variables(bathymetry)
77 second.add_auxiliary_variables(bathymetry)
78 assert bathymetry.owner
is first
83 flux = solver.get_pde_term(
"flux",
True)
84 assert solver.signature_of(flux) == flux.SIGNATURE
90 solver.add_auxiliary_variables(auxiliary)
91 flux = solver.signature_of(solver.get_pde_term(
"flux",
True))
92 assert flux.startswith(
93 "const double* __restrict__ Q, const double* __restrict__ bathymetry, "
94 "const double* __restrict__ distortion, const tarch::la::Vector<Dimensions, double>& x"
96 ncp = solver.signature_of(solver.get_pde_term(
"nonconservativeProduct",
True))
98 "const double* __restrict__ Q, const double* __restrict__ bathymetry, "
99 "const double* __restrict__ distortion, "
100 "const double* __restrict__ deltaQ, const double* __restrict__ deltaBathymetry, "
101 "const double* __restrict__ deltaDistortion, " in ncp
108 owner.add_auxiliary_variables(bathymetry)
109 other.add_auxiliary_variables(bathymetry)
111 "double* __restrict__ Q, double* __restrict__ bathymetry"
112 in owner.signature_of(owner.get_pde_term(
"initPointWisely"))
115 "double* __restrict__ Q, const double* __restrict__ bathymetry"
116 in other.signature_of(other.get_pde_term(
"initPointWisely"))
123 solver.add_auxiliary_variables(auxiliary)
125 solver.get_pde_term(
"flux",
True).generator_for(solver).generate_declaration()
128 assert declaration.count(
"static GPUCallableMethod void flux(") == 2
130 solver.get_pde_term(
"flux",
True)
131 .generator_for(solver)
132 .generate_out_of_class_definitions(
"probe::AbstractProbe")
134 assert "flux(Q, Q + 3, Q + 4, x, normal, F, Offloadable::Yes);" in definition
136 solver.get_pde_term(
"nonconservativeProduct",
True)
137 .generator_for(solver)
138 .generate_out_of_class_definitions(
"probe::AbstractProbe")
140 assert "deltaQ, deltaQ + 3, deltaQ + 4" in ncp
146 solver.add_auxiliary_variables(auxiliary)
149 assert forwarding_arguments(
150 solver.get_pde_term(
"maxEigenvalue").SIGNATURE, solver
162 exahype2_project = types.SimpleNamespace(periodic_BC=[
True] * 3, _dimensions=3)
166 for solver
in solvers:
170 solver.grid_construction.construct_output(
171 exahype2_project, peano_project, setup
173 solver.numerical_scheme.construct_output(
174 exahype2_project, peano_project, time_step
176 return peano_project, setup, time_step
188 first.add_auxiliary_variables(bathymetry)
189 second.add_auxiliary_variables(bathymetry)
190 peano_project, setup, time_step =
_graphs([first, second], tmp_path)
191 cells = [cell.name
for cell
in peano_project.datamodel.cell_data]
192 assert cells.count(
"BathymetryAuxiliaryVariables") == 1
194 assert first._patch.no_of_unknowns == 3
196 assert "BathymetryAuxiliaryVariablesWithHaloOfFirst" in cells
197 assert "BathymetryAuxiliaryVariablesWithHaloOfSecond" in cells
199 tasks = {task.name: task
for task
in setup.tasks}
201 tasks[
"First Initial condition"]
202 in tasks[
"Second Initial condition"].dependencies
209 first.add_auxiliary_variables(bathymetry)
210 second.add_auxiliary_variables(bathymetry)
211 with pytest.raises(ValueError, match=
"before"):
212 _graphs([second, first], tmp_path)
218 solver.add_auxiliary_variables(auxiliary)
219 peano_project, setup, time_step =
_graphs([solver], tmp_path)
220 cells = [cell.name
for cell
in peano_project.datamodel.cell_data]
221 assert "BathymetryAuxiliaryVariables" in cells
222 assert "DistortionAuxiliaryVariables" in cells
227 solver.add_auxiliary_variables(
_two_sets()[0])
231 with pytest.raises(NotImplementedError):
232 solver.numerical_scheme.construct_output(
233 types.SimpleNamespace(periodic_BC=[
True] * 3, _dimensions=3),
242 solver.add_auxiliary_variables(auxiliary)
244 solver._auxiliary_variable_halos = {
245 "Bathymetry": types.SimpleNamespace(name=
"BathymetryHalo"),
246 "Distortion": types.SimpleNamespace(name=
"DistortionHalo"),
248 solver.compute_kernel_call =
"kernel();"
251 ).get_body_of_operation(
252 peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
255 assert "int inputStride = 9 *" in body
256 assert body.index(
"std::vector<double> kernelIn") < body.index(
"CopyCellDataGPU")
257 assert "fineGridCellBathymetryHalo.value[volume*1 + k]" in body
258 assert "fineGridCellDistortionHalo.value[volume*5 + k]" in body
259 assert body.index(
"copyBackAndDestroy") < body.rindex(
"kernelOut[volume*9 + k]")
264 solver.add_auxiliary_variables(
_two_sets()[0])
266 solver, patch_size=6, rk_order=2, time_step_size=0.1
268 exahype2_project = types.SimpleNamespace(periodic_BC=[
True] * 3, _dimensions=3)
271 solver.numerical_scheme.construct_output(exahype2_project, peano_project, time_step)
272 tasks = {task.name: task
for task
in time_step.tasks}
275 reconstruction = tasks[
"Probe_Reconstruct stage 0"]
276 auxiliary = tasks[
"Probe_Reconstruct auxiliary variables Bathymetry stage 0"]
278 assert [type(a).__name__
for a
in reconstruction.action_sets] == [
279 "InterpolateHangingFaces",
280 "ReconstructPatchWithHalo",
282 assert [type(a).__name__
for a
in auxiliary.action_sets] == [
283 "InterpolateHangingFaces",
284 "ReconstructPatchWithHalo",
286 assert reconstruction
not in auxiliary.dependencies
287 assert auxiliary
not in tasks[
"Probe_Reconstruct stage 0"].dependencies
288 update = tasks[
"Probe_Evaluate Runge-Kutta right hand side stage 0"]
289 body = update.action_sets[0].get_body_of_operation(
290 peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
292 assert "std::vector<double> kernelIn" in body
295 "Probe_rightHandSideWithFD4<\n 6,\n 2,\n 3,\n 1\n>"
296 in solver.compute_kernel_call
302 assert auxiliary.mode == exahype2.api.AuxiliaryVariables.Mode.STATIONARY_ON_FACES
303 assert auxiliary.data_name ==
"BathymetryAuxiliaryVariables"
310 mode=exahype2.api.AuxiliaryVariables.Mode.CHANGING_ON_FACES,
311 data_name=
"DerivativeVariables",
313 auxiliary.create_data_structures(9, 3, unittest.mock.MagicMock())
314 assert auxiliary.patch.name ==
"DerivativeVariables"
316 auxiliary.patch_overlap_current_time_step.name
317 ==
"DerivativeVariablesCurrentTimeStep"
319 assert auxiliary.patch_overlap_update.name ==
"DerivativeVariablesUpdate"
325 solver.add_auxiliary_variables(auxiliary)
327 solver, patch_size=6, rk_order=rk_order, time_step_size=0.1
329 exahype2_project = types.SimpleNamespace(periodic_BC=[
True] * 3, _dimensions=3)
332 solver.numerical_scheme.construct_output(exahype2_project, peano_project, time_step)
333 return solver, auxiliary, {task.name: task
for task
in time_step.tasks}
337 name = exahype2.api.AuxiliaryVariables.RECONSTRUCTION_TASK_NAME.format(
340 return f
"Probe_{name} stage {stage}"
344 Mode = exahype2.api.AuxiliaryVariables.Mode
345 solver, auxiliary, tasks =
_fd4_time_step(tmp_path, Mode.CHANGING_ON_FACES)
346 Access = peano4.api.taskgraph.Task.DataAccess
347 halo = solver._auxiliary_variable_halos[auxiliary.name]
348 for stage
in range(3):
350 rhs = tasks[f
"Probe_Evaluate Runge-Kutta right hand side stage {stage}"]
351 assert rhs.cell_data_access[halo] == Access.READ_AND_DISCARD
357 Mode = exahype2.api.AuxiliaryVariables.Mode
359 tmp_path, Mode.STATIONARY_THROUGHOUT_TIME_STEPS_ON_FACES
361 Access = peano4.api.taskgraph.Task.DataAccess
362 halo = solver._auxiliary_variable_halos[auxiliary.name]
371 for stage, expected
in [
372 (0, Access.READ_AND_WRITE),
373 (1, Access.READ_AND_WRITE),
374 (2, Access.READ_AND_DISCARD),
376 rhs = tasks[f
"Probe_Evaluate Runge-Kutta right hand side stage {stage}"]
377 assert rhs.cell_data_access[halo] == expected
379 for stage
in range(3):
380 assert f
"Probe_Reconstruct stage {stage}" in tasks
384 Mode = exahype2.api.AuxiliaryVariables.Mode
386 tmp_path, Mode.STATIONARY_THROUGHOUT_TIME_STEPS_ON_FACES, rk_order=1
388 Access = peano4.api.taskgraph.Task.DataAccess
389 halo = solver._auxiliary_variable_halos[auxiliary.name]
390 rhs = tasks[
"Probe_Evaluate Runge-Kutta right hand side stage 0"]
391 assert rhs.cell_data_access[halo] == Access.READ_AND_DISCARD
A set of auxiliary variables of a solver.
The conservative flux F(Q) of a hyperbolic PDE.
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.
The non-conservative product B(Q) applied to a jump deltaQ in a given direction, i....
Abstract base class for all ExaHyPE 2 solvers.
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,...
Setup phase counterpart to RusanovWithExplicitEuler: sets the initial condition for a Finite Volume s...
Update a Finite Volume patch (solver._patch) from its halo-augmented reconstruction (solver....
Fourth-order central Finite Differences with explicit Runge-Kutta time stepping, realised over a bloc...
Represents a Peano 4 project.
Holds a sequence of Task instances.
The task graph abstraction allows users to formalise their solver steps over small task graphs which ...
test_shared_set_is_held_by_one_cell_data_object(tmp_path)
test_only_the_owner_writes_the_set_in_the_initial_condition()
test_solver_has_arbitrary_number_of_sets_with_offsets_in_kernel_buffer()
test_first_solver_owns_set()
test_fd4_reconstructs_the_halos_of_auxiliary_variables(tmp_path)
test_distinct_sets_get_distinct_cell_data(tmp_path)
_fd4_time_step(tmp_path, mode, rk_order=3)
test_signatures_are_unchanged_without_auxiliary_variables()
_graphs(solvers, tmp_path)
_reconstruction_name(auxiliary, stage)
test_mode_defaults_to_stationary_on_faces()
test_pointers_follow_each_q_and_delta_q()
test_stateful_kernel_call_slices_the_kernel_buffer()
test_data_name_feeds_into_the_generated_data()
test_invalid_names_are_rejected(name)
test_gpu_update_assembles_buffers_before_copying_to_the_device()
test_fd4_with_one_stage_discards_the_held_halo_right_away(tmp_path)
test_fd4_reconstructs_changing_halos_in_every_stage(tmp_path)
test_abstract_solver_declares_structs_and_kernel_adapters(tmp_path)
test_fd4_reconstructs_halos_that_are_stationary_through_the_time_step_once(tmp_path)
test_optimistic_scheme_rejects_auxiliary_variables(tmp_path)
test_same_set_cannot_be_attached_twice()
test_set_knows_its_variables()
test_sharing_solver_has_to_be_added_after_owner(tmp_path)