Peano
Loading...
Searching...
No Matches
test_load_checkpoint.py
Go to the documentation of this file.
1"""Unit tests for the setup from a checkpoint
2(@ref exahype2.api.blockstructured.LoadCheckpoint.LoadCheckpoint)."""
3
4import types
5
6import peano4.api
8import exahype2.api
10import pytest
11
12
13def _solver(scheme):
14 solver = exahype2.api.Solver("Probe", 4, 0)
15 solver.add_pde_term(exahype2.api.Flux(implementation=""))
16 solver.add_pde_term(exahype2.api.MaxEigenvalue(implementation=""))
17 if scheme == "fv":
18 solver.numerical_scheme = exahype2.api.fv.RusanovWithExplicitEuler(solver, 9)
19 package = exahype2.api.fv
20 else:
22 solver, patch_size=9, rk_order=2
23 )
24 package = exahype2.api.rkfd4
25 return solver, package
26
27
28def _setup_graph(solver, tmp_path):
29 peano_project = peano4.api.Project(["probe"], "probe", directory=str(tmp_path))
30 exahype2_project = types.SimpleNamespace(periodic_BC=[True, True, True])
32 solver.grid_construction.construct_output(exahype2_project, peano_project, graph)
33 return graph
34
35
38
39
40@pytest.mark.parametrize("scheme,halo", [("fv", 1), ("fd4", 2)])
42 solver, package = _solver(scheme)
43 solver.grid_construction = package.LoadCheckpoint(
44 solver, output_path="restart", time_stamp=0.5
45 )
46 graph = _setup_graph(solver, tmp_path)
47 assert [task.name for task in graph.tasks] == [
48 "Probe_Refine mesh from checkpoint",
49 "Probe_Consolidate mesh",
50 "Probe_Load checkpoint",
51 ]
52 refine, _, load = graph.tasks
53 assert refine.has_to_repeat is not None
54 events = refine.action_sets[0].get_body_of_createGridControlEventsForNextTraversal()
55 assert (
56 f'::exahype2::CheckpointReader::getInstance("restart/checkpoint-Probe.peano-patch-file", 0.5, {halo}, DomainOffset, DomainSize)'
57 in events
58 )
59
60 load_patches, project = load.action_sets
61 assert isinstance(
62 project, toolbox.blockstructured.api.ProjectPatchWithHaloOntoFaces
63 )
64 assert "fineGridCellProbeQWithHalo" in load_patches.get_body_of_operation(
65 "touchCellFirstTime"
66 )
67 assert "fromCheckpointMetaData" in load_patches.get_body_of_unprepareTraversal()
68 assert load.cell_data_access[solver._patch_with_halo] == (
69 peano4.api.taskgraph.Task.DataAccess.TEMPORARY
70 )
71
72
74 solver, package = _solver("fv")
75 solver.grid_construction = package.LoadCheckpoint(solver)
76 graph = _setup_graph(solver, tmp_path)
77 events = (
78 graph.tasks[0]
79 .action_sets[0]
80 .get_body_of_createGridControlEventsForNextTraversal()
81 )
82 assert '"./checkpoint-Probe.peano-patch-file", -1.0,' in events
83
84
86 solver, package = _solver("fv")
87 solver.add_plotter(package.PlotAsVTKFile(solver))
88 solver.add_plotter(package.WriteCheckpoint(solver))
89 solver.grid_construction = package.LoadCheckpoint(solver)
90 _setup_graph(solver, tmp_path)
91 peano_project = peano4.api.Project(["probe"], "probe", directory=str(tmp_path))
92 exahype2_project = types.SimpleNamespace(periodic_BC=[True, True, True])
93 for plotter in solver.plotters:
94 plotter.construct_output(
95 exahype2_project, peano_project, peano4.api.taskgraph.Graph()
96 )
97 (definition,) = [
98 generator("probe::AbstractProbe")
99 for declaration, generator in solver._abstract_solver_methods
100 if declaration.startswith("void fromCheckpointMetaData")
101 ]
102 assert definition.index("_nextPlotAsVTKFileTimeStamp =") < definition.index(
103 "finishPlotAsVTKFile();"
104 )
105 assert "finishWriteCheckpoint();" in definition
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-...
Fourth-order central Finite Differences with explicit Runge-Kutta time stepping, realised over a bloc...
Represents a Peano 4 project.
Definition Project.py:23
Holds a sequence of Task instances.
Definition Graph.py:9
Fourth-order Finite Differences with explicit Runge-Kutta time stepping over block-structured meshes.
Definition __init__.py:1
The task graph abstraction allows users to formalise their solver steps over small task graphs which ...
Definition __init__.py:1
_setup_graph(solver, tmp_path)
test_setup_refines_consolidates_and_loads(tmp_path, scheme, halo)
test_latest_checkpoint_by_default(tmp_path)