980 self, exahype2_project, peano_project, time_step, add_global_tasks=True
984 Add the data to the Peano 4 project, generate the kernels and add
985 the tasks of one Runge-Kutta step to time_step
987 @param add_global_tasks: bool
988 If False, the scheme adds neither the task that switches the load
989 balancing off nor the last task that evaluates the adaptivity
990 criterion and switches the load balancing on again,
991 @see exahype2.api.Solver.Solver.NumericalScheme.construct_output().
993 Per stage k, the time step holds the following tasks (see the class
994 documentation for the data flow). Every task holds exactly one
995 action set, with the exception of the reconstruction of the
996 unknowns, which also holds the interpolation onto the hanging faces,
997 and the reconstruction of several sets of auxiliary variables. This is deliberate: the task graph compiler
998 runs the action sets of independent tasks in parallel only if each
999 task holds one action set (@ref peano4.api.taskgraph.compiler.FuseSteps).
1000 Where the scheme needs several action sets in a row, it hence creates
1001 a chain of tasks. If several solvers share a task graph, their chains
1004 - {SolverName}_Disable load balancing: switches the load balancing
1005 off throughout the time step. Added last by
1006 wrap_task_graph_in_load_balancing_and_amr_tasks(), which makes all
1007 tasks without predecessor wait for it.
1008 - {SolverName}_Apply Dirichlet BCs stage k: sets the ghost grid
1009 cells along the domain boundary for Dirichlet boundary conditions.
1010 The task does not exist if all axes are periodic, or for Sommerfeld
1011 boundary conditions, which advance the ghost grid cells within the
1012 roll over of the projection onto the faces.
1013 - {SolverName}_Reconstruct stage k: interpolates the coarse face
1014 data onto the hanging faces and reconstructs the stage's input with
1015 its halo. Interpolation is no task of its own.
1016 - {SolverName}_Reconstruct auxiliary variables stage k: reconstructs
1017 the halos of the auxiliary variables. Exists only if the solver has
1018 auxiliary variables. Sets which are stationary throughout the time
1019 step (exahype2.api.AuxiliaryVariables.Mode.STATIONARY_THROUGHOUT_TIME_STEPS_ON_FACES)
1020 have this task in the first stage only: The right-hand-side tasks
1021 hold their halo as persistent cell data until the last stage
1023 - {SolverName}_Evaluate Runge-Kutta right hand side stage k. Where
1024 the right-hand side has further terms
1025 (_right_hand_side_action_sets()), each term adds a task behind it,
1026 e.g. {SolverName}_Add lopsided advection stage k.
1027 - {SolverName}_Prepare stage k+1, or {SolverName}_Complete time step
1028 after the last stage: computes the linear combination of the
1029 estimates. Prepare stage k+1 is tagged with
1030 exahype2.api.Solver.IntermediateSolutionUpdateTag, Complete time
1031 step with exahype2.api.Solver.SolutionUpdateTaskTag, i.e.
1032 postprocessing such as the enforcement of constraints can be
1033 inserted directly after them (see @ref
1034 page_exahype2_solver_manipulate_solver_steps).
1035 - {SolverName}_Compute max eigenvalue: determines the maximum
1036 eigenvalue of the new solution. Exists after the last stage for
1037 adaptive time stepping only.
1038 - {SolverName}_Project stage k+1 onto faces, or {SolverName}_Project
1039 solution onto faces after the last stage: projects the outcome of
1040 the linear combination onto the faces and restricts the hanging
1041 faces onto the coarse faces.
1042 - {SolverName}_Roll over stage k+1 faces, or {SolverName}_Roll over
1043 solution faces. The projection (with the restriction) and the roll over
1044 share the update patch, which is temporary, i.e. they rely on the
1045 task graph compiler to fuse them into one mesh traversal. Only
1046 the roll over writes the face data of the current time step, but
1047 the projection declares it, and the roll over declares it as
1048 temporary. If the roll over declared it, the projection would not conflict with the reconstruction, which reads
1049 the faces. The compiler would then fuse them into the traversal of
1050 the previous stage, and only the roll over would start a new
1051 traversal. The update patch does not survive such a split, and the
1052 roll over reads uninitialised data (observed as NaNs in the next
1053 stage's input). The fused traversal merges the qualifiers back into
1054 the one of the projection.
1056 After the last stage, {SolverName}_Compute time step size determines
1057 the time step size of the next time step and advances the solver's
1058 time stamp. {SolverName}_Dynamic mesh refinement and load balancing finally evaluates the
1059 adaptivity criterion if the solver has one
1060 (@ref exahype2.api.blockstructured.create_dynamic_mesh_refinement_action_set.create_dynamic_mesh_refinement_action_set()),
1061 switches the load balancing on again and informs it that the time
1066 "Create time stepping task graph for fourth-order Finite Differences "
1067 f
"with Runge-Kutta of order {self.rk_order} over block-structured meshes"
1071 exahype2_project.periodic_BC
1074 f
"Solver {self._solver.name}: the advection velocity has "
1075 f
"{len(self.advection_velocity)} entries, but the domain has "
1076 f
"{len(exahype2_project.periodic_BC)} dimensions"
1081 isinstance(term, MaxEigenvalue)
for term
in self.
_solver.pde_terms
1083 f
"Solver {self._solver.name} uses adaptive time step sizes, but has no "
1084 "MaxEigenvalue PDE term. Add one via "
1085 "solver.add_pde_term(exahype2.api.MaxEigenvalue(...)), or pass a "
1086 "time_step_size to CentralDifferencesWithRungeKutta."
1089 relative_time_step_sizes = self.
butcher_tableau.relative_time_step_sizes()
1091 get_boundary_conditions(self.
_solver, exahype2_project),
1092 SommerfeldBoundaryConditions,
1095 for earlier, later
in zip(
1096 relative_time_step_sizes, relative_time_step_sizes[1:]
1100 f
"Solver {self._solver.name} uses Sommerfeld boundary conditions, but "
1101 f
"the time stamps c={relative_time_step_sizes} of the stages of its "
1102 f
"Runge-Kutta scheme of order {self.rk_order} decrease. The roll over "
1103 "advances the ghost grid cells from one stage to the next, so it "
1104 "requires non-decreasing time stamps "
1105 "(@ref exahype2::blockstructured::applySommerfeldBoundaryConditions())."
1121 cell_guard = self.
_solver.grid_selector.createCellGuard()
1122 face_guard = self.
_solver.grid_selector.createFaceGuard()
1124 self.
_solver._get_default_includes() + self.
_solver.user_solver_includes
1128 Access = peano4.api.taskgraph.Task.DataAccess
1129 Entity = peano4.api.taskgraph.Task.GridEntity
1131 previous_stage_task =
None
1133 is_last_stage = stage == self.
rk_order - 1
1144 face_read = get_access_to_persistent_face_data(
1145 self.
_solver, exahype2_project, Access.READ_AND_DISCARD
1150 name=f
"{name}_Reconstruct stage {stage}", entity=Entity.CELL
1152 time_step.add_task(reconstruction_task)
1153 if previous_stage_task
is not None:
1154 reconstruction_task.add_dependency(previous_stage_task)
1159 reconstruction_task.use_cell(
1161 Access.READ_AND_WRITE
if stage == 0
else Access.READ_AND_DISCARD,
1163 reconstruction_task.use_cell(self.
_solver._patch_with_halo, Access.WRITE)
1166 reconstruction_task.use_face(
1167 self.
_solver._patch_overlap_current_time_step, face_read
1174 reconstruction_task.add_action_set(
1175 toolbox.blockstructured.api.InterpolateHangingFaces(
1176 self.
_solver._patch_overlap_current_time_step,
1178 additional_includes=includes,
1181 reconstruction_task.add_action_set(
1182 toolbox.blockstructured.api.ReconstructPatchWithHalo(
1184 patch_overlap=self.
_solver._patch_overlap_current_time_step,
1185 reconstructed_patch=self.
_solver._patch_with_halo,
1187 add_assertions_to_halo_exchange=
False,
1188 additional_includes=includes,
1195 boundary_task = ApplyDirichletBoundaryConditions.add_task_to_time_step(
1199 reconstruction_task,
1200 name_suffix=f
" stage {stage}",
1201 relative_time_step_size=self.
butcher_tableau.relative_time_step_sizes()[
1205 if boundary_task
is not None and previous_stage_task
is not None:
1206 boundary_task.add_dependency(previous_stage_task)
1213 reconstruction_tasks = [reconstruction_task] + (
1214 add_reconstruction_tasks_of_auxiliary_variables(
1218 [previous_stage_task]
if previous_stage_task
is not None else [],
1219 name_suffix=f
" stage {stage}",
1222 for auxiliary
in self.
_solver.auxiliary_variables
1223 if stage == 0
or not auxiliary.halo_is_held_through_stages
1231 right_hand_side_tasks = []
1232 for index, action_set
in enumerate(
1236 "Evaluate Runge-Kutta right hand side"
1238 else getattr(action_set,
"TASK_NAME",
None)
1242 name=f
"{name}_{task_name} stage {stage}", entity=Entity.CELL
1244 task.add_action_set(action_set)
1246 [right_hand_side_tasks[-1]]
1247 if right_hand_side_tasks
1248 else reconstruction_tasks
1250 task.add_dependency(dependency)
1251 time_step.add_task(task)
1252 right_hand_side_tasks.append(task)
1253 for position, task
in enumerate(right_hand_side_tasks):
1254 length = len(right_hand_side_tasks)
1256 self.
_solver._patch_with_halo,
1265 task.use_cell(self.
_solver._rhs_estimates, Access.READ_AND_WRITE)
1266 use_halos_of_auxiliary_variables(
1273 Access.READ_AND_DISCARD
1275 else Access.READ_AND_WRITE
1281 right_hand_side_task = right_hand_side_tasks[-1]
1293 name=f
"{name}_Complete time step", entity=Entity.CELL
1297 weights = weight_matrix[stage + 1]
1298 output = self.
_solver._stage_input
1300 name=f
"{name}_Prepare stage {stage + 1}", entity=Entity.CELL
1302 suffix = f
"stage {stage + 1}"
1303 time_step.add_task(combination_task)
1304 combination_task.add_dependency(right_hand_side_task)
1305 combination_task.use_cell(self.
_solver._patch, Access.READ_AND_WRITE)
1307 combination_task.use_cell(
1309 Access.READ_AND_DISCARD
if is_last_stage
else Access.READ_AND_WRITE,
1311 if not is_last_stage:
1312 combination_task.use_cell(self.
_solver._stage_input, Access.WRITE)
1313 combination_task.add_action_set(
1314 ComputeLinearCombination(
1315 self.
_solver, weights, output, guard=cell_guard
1318 combination_task.tags.add(
1319 Solver.SolutionUpdateTaskTag
1321 else Solver.IntermediateSolutionUpdateTag
1331 eigenvalue_task =
None
1334 name=f
"{name}_Compute max eigenvalue", entity=Entity.CELL
1336 eigenvalue_task.use_cell(output, Access.READ_AND_WRITE)
1337 eigenvalue_task.use_cell(self.
_solver._max_eigenvalue, Access.WRITE)
1338 for auxiliary
in self.
_solver.auxiliary_variables:
1339 eigenvalue_task.use_cell(auxiliary.patch, Access.READ_AND_WRITE)
1340 eigenvalue_task.add_action_set(
1341 ComputeMaxEigenvalue(self.
_solver, guard=cell_guard)
1343 eigenvalue_task.add_dependency(combination_task)
1344 time_step.add_task(eigenvalue_task)
1346 name=f
"{name}_Reduce max eigenvalue", entity=Entity.CELL
1348 reduction_task.use_cell(
1349 self.
_solver._max_eigenvalue, Access.READ_AND_DISCARD
1351 reduction_task.add_action_set(
1352 ReduceMaxEigenvalue(self.
_solver, guard=cell_guard)
1354 reduction_task.add_dependency(eigenvalue_task)
1355 time_step.add_task(reduction_task)
1358 name=f
"{name}_Project {suffix} onto faces"
1359 if not is_last_stage
1360 else f
"{name}_Project solution onto faces",
1363 projection_task.add_dependency(combination_task)
1364 projection_task.use_cell(output, Access.READ_AND_WRITE)
1365 projection_task.use_face(
1366 self.
_solver._patch_overlap_update, Access.TEMPORARY
1369 projection_task.use_face(
1370 self.
_solver._patch_overlap_current_time_step,
1371 get_access_to_persistent_face_data(
1372 self.
_solver, exahype2_project, Access.WRITE
1375 projection_task.add_action_set(
1376 ProjectPatchOntoFaces(
1378 self.
_solver._patch_overlap_update,
1390 time_step.add_task(projection_task)
1391 if eigenvalue_task
is not None:
1392 eigenvalue_task.add_dependency(projection_task)
1397 next_relative_time_step_size = (
1398 1.0
if is_last_stage
else relative_time_step_sizes[stage + 1]
1401 name=f
"{name}_Roll over {suffix} faces", entity=Entity.CELL
1403 roll_over_task.use_face(
1404 self.
_solver._patch_overlap_update, Access.TEMPORARY
1406 roll_over_task.use_face(
1407 self.
_solver._patch_overlap_current_time_step, Access.TEMPORARY
1409 roll_over_task.add_action_set(
1410 RollOverUpdatedFaceWithSommerfeldBoundaryConditions.create_roll_over(
1416 f
"{next_relative_time_step_size - relative_time_step_sizes[stage]!r}"
1417 f
" * repositories::{self._solver.get_name_of_global_instance()}.getMinTimeStepSize()"
1421 roll_over_task.add_dependency(projection_task)
1422 time_step.add_task(roll_over_task)
1423 previous_stage_task = roll_over_task
1428 name=f
"{name}_Compute time step size",
1429 entity=Entity.GLOBAL_END_OF_STEP,
1430 may_spawn_background_tasks=
False,
1436 time_step_size_task.add_dependency(previous_stage_task)
1438 time_step_size_task.add_dependency(reduction_task)
1439 time_step_size_task.add_action_set(
1440 ComputeTimeStepSize(
1451 time_step.add_task(time_step_size_task)
1456 if add_global_tasks:
1460 time_step.visualise(
1461 title=
"Time stepping task graph for {}".format(name)
1464 time_step.log_as_text(
1465 title=
"Time stepping task graph for {}".format(name)