8import toolbox.loadbalancing.api.actionsets
11from ..Solver
import Solver
17 C++ expression which yields the exahype2::CheckpointReader of the
22 "::exahype2::CheckpointReader::getInstance("
23 f
'"{index_file_name}", {repr(float(time_stamp))}, {halo_width}, DomainOffset, DomainSize)'
30 Refine the mesh such that it matches the mesh of a checkpoint
32 The action set hands the refinement events of the checkpoint
33 (@ref exahype2::CheckpointReader::getRefinementEvents()) to Peano. As the
34 mesh setup over a regular grid, it pauses the refinement while the load
35 balancing has just split.
40 super().
__init__(descend_invocation_order=1, parallel=
False)
47 ::toolbox::loadbalancing::LoadBalancingService::getInstance().hasLoadBalancing()
49 ::toolbox::loadbalancing::LoadBalancingService::getInstance().getLoadBalancing()->hasSplitRecently()
51 return std::vector< peano4::grid::GridControlEvent >();
53 return {self._reader}.getRefinementEvents();
69 return "RefineFromCheckpoint"
80#include "exahype2/CheckpointReader.h"
81#include "toolbox/loadbalancing/AbstractLoadBalancing.h"
82#include "toolbox/loadbalancing/LoadBalancingService.h"
91 Read each cell's patch with halo from a checkpoint and restore the
94 In touchCellFirstTime(), the action set copies the cell's patch with halo
95 from the checkpoint into solver._patch_with_halo, and the patch without
96 the halo into solver._patch. Every cell selected by the guard has to have
97 a patch in the checkpoint. Otherwise, the mesh does not match the
98 checkpoint, and the action set terminates the code.
100 In unprepareTraversal(), it hands the checkpoint's meta data to the
101 solver (@ref exahype2::Solver::fromCheckpointMetaData()) and frees the
106 def __init__(self, solver, reader, index_file_name, halo_width, guard, includes):
107 super().
__init__(descend_invocation_order=1, parallel=
False)
116 if operation_name != ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
119 patch_with_halo = self.
_solver._patch_with_halo
121 constexpr int Unknowns = {patch.no_of_unknowns};
122 constexpr int DoFsPerAxis = {patch.dim[0]};
123 constexpr int Halo = {self._halo_width};
124 constexpr int EntriesPerAxisHalo = DoFsPerAxis + 2 * Halo;
126 int numberOfEntries = Unknowns;
127 for (int d=0; d<Dimensions; d++) {{
128 numberOfEntries *= EntriesPerAxisHalo;
131 const bool found = {self._reader}.readPatch(
135 fineGridCell{patch_with_halo.name}.value
139 "touchCellFirstTime(...)",
140 "checkpoint {self._index_file_name} holds no patch for cell " << marker.toString()
141 << ". The mesh does not match the checkpoint"
146 dfor(cell, DoFsPerAxis) {{
147 const int cellSerialised = peano4::utils::dLinearised(cell, DoFsPerAxis);
148 const int cellWithHaloSerial = peano4::utils::dLinearised(cell + tarch::la::Vector<Dimensions,int>(Halo), EntriesPerAxisHalo);
149 for (int unknown=0; unknown<Unknowns; unknown++) {{
150 fineGridCell{patch.name}.value[cellSerialised*Unknowns+unknown] = fineGridCell{patch_with_halo.name}.value[cellWithHaloSerial*Unknowns+unknown];
156 if operation_name == ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
165 repositories::{self._solver.get_name_of_global_instance()}.fromCheckpointMetaData( {self._reader}.getMetaData() );
166 ::exahype2::CheckpointReader::release( "{self._index_file_name}" );
173 return "LoadPatchesFromCheckpoint"
185#include "exahype2/CheckpointReader.h"
194 Set up a simulation from a checkpoint
196 Alternative to the setups over a regular grid
197 (@ref exahype2.api.fv.SetupSimulationOverRegularGrid,
198 @ref exahype2.api.rkfd4.SetupSimulationOverRegularGrid): Instead of
199 constructing a mesh and setting the initial condition, the setup reads a
200 checkpoint written by exahype2.api.fv.WriteCheckpoint or
201 exahype2.api.rkfd4.WriteCheckpoint and continues the simulation from
202 there. It is available for both schemes as exahype2.api.fv.LoadCheckpoint
203 and exahype2.api.rkfd4.LoadCheckpoint, as both use the same data layout.
205 The setup consists of three phases:
207 - It reconstructs the checkpoint's mesh. The refinement sweep repeats
208 until the mesh is stationary and the load balancing has stagnated,
209 exactly as for the regular grid. Instead of refining down to a given
210 mesh size, it refines the parents of all cells in the checkpoint
211 (@ref exahype2::CheckpointReader).
212 - Once the mesh is complete, it switches off the load balancing and
213 waits until the last splits have been carried out.
214 - A last sweep loads the data. For every cell, it reads the patch with
215 halo into the temporary solver._patch_with_halo, copies the patch into
216 solver._patch and writes the patch with halo onto the overlaps of the
217 faces (toolbox.blockstructured.api.ProjectPatchWithHaloOntoFaces).
218 The faces hence also hold the ghost data along the domain boundary and
219 the data at coarse-fine transitions as they have been at the time of
220 the checkpoint. In unprepareTraversal(), the sweep restores the
221 solver's time stamps, time step sizes and mesh sizes, plus the
222 attributes the Python API has added, e.g. the time stamps of the next
223 outputs of the plotters. Plotters which have written output at the
224 time of the checkpoint move on to their next output, so the restarted
225 simulation does not write them again
226 (@ref exahype2.api.Solver.Solver._add_checkpoint_meta_data_to_solver()).
228 The setup neither uses the initial condition nor the boundary conditions.
229 The checkpoint has to be written by a solver with the same unknowns,
230 auxiliary variables, patch size and halo, over the same domain. The code
231 reads the checkpoint at runtime, i.e. the files have to exist when the
232 simulation starts, but not when it is generated or built.
234 The time stamps of all solvers have to match, i.e. a project with
235 several solvers has to load checkpoints of all of them, written at the
243 filename: str =
"checkpoint",
244 output_path: str =
".",
245 time_stamp: float =
None,
249 @param solver: exahype2.api.Solver
250 The solver whose data is loaded.
253 File name of the checkpoint as passed to WriteCheckpoint. The setup
254 reads the index file output_path/filename-SolverName.peano-patch-file.
256 @param output_path: str
257 Directory of the checkpoint, relative to the directory the
258 simulation is started from, or absolute.
260 @param time_stamp: float or None
261 Time stamp of the checkpoint to load. If None, the setup loads the
262 latest checkpoint in the index file. Otherwise, it loads the
263 checkpoint whose time stamp is closest to time_stamp.
273 Path of the checkpoint's index file
283 Add the mesh construction and the loading of the data to the setup
288 "Create setup task graph which loads a checkpoint into a block-structured mesh"
294 "_patch_overlap_current_time_step",
297 f
"Solver {self._solver.name} has no attribute {attribute}. "
298 "LoadCheckpoint assumes the numerical scheme has added this field "
299 "to the solver immediately upon construction."
305 Access = peano4.api.taskgraph.Task.DataAccess
306 Entity = peano4.api.taskgraph.Task.GridEntity
323 name=f
"{self._solver.name}_Refine mesh from checkpoint",
326 "not peano4::grid::isGridStationary( peano4::parallel::SpacetreeSet::getInstance().getGridStatistics() )"
327 " or ( ::toolbox::loadbalancing::LoadBalancingService::getInstance().hasLoadBalancing()"
328 " and ( not ::toolbox::loadbalancing::LoadBalancingService::getInstance().getLoadBalancing()->hasStagnated()"
329 " or ::toolbox::loadbalancing::LoadBalancingService::getInstance().getLoadBalancing()->hasSplitRecently() ) )"
333 refine_task.add_action_set(toolbox.loadbalancing.api.actionsets.LoadBalancing())
336 name=f
"{self._solver.name}_Consolidate mesh",
339 "not peano4::grid::isGridStationary( peano4::parallel::SpacetreeSet::getInstance().getGridStatistics() )"
340 " or ( ::toolbox::loadbalancing::LoadBalancingService::getInstance().hasLoadBalancing()"
341 " and ::toolbox::loadbalancing::LoadBalancingService::getInstance().getLoadBalancing()->hasSplitRecently() )"
344 consolidate_load_balancing_task.add_action_set(
345 toolbox.loadbalancing.api.actionsets.ToggleLoadBalancing(
346 enable_load_balancing=
False, plug_into_prepare_traversal=
True
349 consolidate_load_balancing_task.add_action_set(
350 toolbox.loadbalancing.api.actionsets.LoadBalancing()
352 consolidate_load_balancing_task.add_dependency(refine_task)
355 name=f
"{self._solver.name}_Load checkpoint",
357 may_spawn_background_tasks=
False,
359 load_task.add_dependency(consolidate_load_balancing_task)
361 load_task.use_cell(self.
_solver_solver._patch_with_halo, Access.TEMPORARY)
362 load_task.use_face(self.
_solver_solver._patch_overlap_current_time_step, Access.WRITE)
363 load_task.add_action_set(
373 load_task.add_action_set(
374 toolbox.blockstructured.api.ProjectPatchWithHaloOntoFaces(
378 additional_includes=includes,
382 setup_simulation.add_task(refine_task)
383 setup_simulation.add_task(consolidate_load_balancing_task)
384 setup_simulation.add_task(load_task)
387 setup_simulation.visualise(
391 setup_simulation.log_as_text(
How a Solver drives the construction of the mesh it runs on.
Set up a simulation from a checkpoint.
construct_output(self, exahype2_project, peano_project, setup_simulation)
Add the mesh construction and the loading of the data to the setup task graph.
__init__(self, Solver solver, str filename="checkpoint", str output_path=".", float time_stamp=None)
str index_file_name(self)
Path of the checkpoint's index file.
Read each cell's patch with halo from a checkpoint and restore the solver's state.
get_action_set_name(self)
Return unique action set name.
get_constructor_body(self)
Define a tailored constructor body.
get_includes(self)
Return include statements that you need.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
__init__(self, solver, reader, index_file_name, halo_width, guard, includes)
get_body_of_unprepareTraversal(self)
user_should_modify_template(self)
Is the user allowed to modify the output.
get_guard_of_operation(self, operation_name)
Return the guard of an operation.
get_attributes(self)
Return attributes as copied and pasted into the generated class.
get_body_of_prepareTraversal(self)
Refine the mesh such that it matches the mesh of a checkpoint.
__init__(self, reader, includes)
user_should_modify_template(self)
Is the user allowed to modify the output.
get_constructor_body(self)
Define a tailored constructor body.
get_body_of_unprepareTraversal(self)
get_attributes(self)
Return attributes as copied and pasted into the generated class.
get_includes(self)
Return include statements that you need.
get_action_set_name(self)
Return unique action set name.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_body_of_prepareTraversal(self)
get_body_of_createGridControlEventsForNextTraversal(self)
Return the grid control events that this action set wants to trigger.
Singleton logger for the Peano 4 Python API.
Action set (reactions to events)
One task within a peano4.api.taskgraph.Graph.
_create_reader(index_file_name, time_stamp, halo_width)
C++ expression which yields the exahype2::CheckpointReader of the checkpoint.
The task graph abstraction allows users to formalise their solver steps over small task graphs which ...