Peano
Loading...
Searching...
No Matches
AdaptMeshAndBalanceLoad.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3import peano4.api
5import toolbox.loadbalancing.api.actionsets
6
7from ..Solver import Solver
8from .BoundaryConditions import get_access_to_persistent_face_data
9from .ConsumeRefinementRequests import ConsumeRefinementRequests
10
11
13 """!
14
15 Default mesh adaptation of the block-structured schemes
16
17 Abstract base class of exahype2.api.fv.AdaptMeshAndBalanceLoad and
18 exahype2.api.rkfd4.AdaptMeshAndBalanceLoad, which the Finite Volume and
19 the finite difference schemes use unless the user assigns another mesh
20 adaptation to solver.mesh_adaptation. The subclasses only add the
21 scheme-specific action sets (_add_projection_action_sets() and
22 _add_further_adaptation_action_sets()).
23 The generated main runs the phase right after a time step if this time
24 step has asked for a refinement or erase, or if the load balancing has
25 split (@ref exahype2::isMeshAdaptationRequired()). The phase consists of
26 two tasks:
27
28 1. Adapt mesh and balance load repeats until the mesh is stationary, the
29 refinement service holds no requests anymore, and the load balancing
30 has not split recently. It hosts the following action sets:
31 - Scheme-specific action sets, such as the one which drops the
32 optimistic patch interior updates of the Finite Volumes
33 (_add_further_adaptation_action_sets()).
34 - exahype2.api.blockstructured.ConsumeRefinementRequests hands the
35 requests of the last time step over to Peano. It does not issue any
36 new request. If the mesh changes, it resets the solver's time step
37 size to zero, so the next time step derives a new admissible time
38 step size.
39 - toolbox.blockstructured.api.InterpolateAndRestrictCells
40 interpolates the patches of new cells from their parent and
41 restricts the patches of erased cells into their parent.
42 - toolbox.loadbalancing.api.actionsets.LoadBalancing informs the load
43 balancing after each mesh sweep. The last task of the time step has
44 switched it on.
45 2. Project on faces projects the patches onto the faces, as the new
46 mesh has new faces. It is the same projection as at the end of a time
47 step, including the restriction of the hanging faces if the scheme
48 supports adaptive meshes (_add_projection_action_sets()). Sommerfeld
49 boundary conditions advance the ghost volumes by a time step size of
50 zero, i.e. they keep them. Ghost volumes of faces along the boundary
51 which the refinement has created are hence not set properly.
52
53 """
54
55
56 RepeatCondition = (
57 "not peano4::grid::isGridStationary( peano4::parallel::SpacetreeSet::getInstance().getGridStatistics() )"
58 " or not ::exahype2::RefinementControlService::getInstance().createGridControlEventsForNextTraversal().empty()"
59 " or ( ::toolbox::loadbalancing::LoadBalancingService::getInstance().hasLoadBalancing()"
60 " and ::toolbox::loadbalancing::LoadBalancingService::getInstance().getLoadBalancing()->hasSplitRecently() )"
61 )
62
64 self,
65 solver: Solver,
66 interpolation: "toolbox.blockstructured.api.InterpolateAndRestrictCells.Interpolation" = toolbox.blockstructured.api.InterpolateAndRestrictCells.Interpolation.Linear,
67 restriction: "toolbox.blockstructured.api.InterpolateAndRestrictCells.Restriction" = toolbox.blockstructured.api.InterpolateAndRestrictCells.Restriction.Averaging,
68 ):
69 """!
70
71 @param solver: exahype2.api.Solver
72 Solver with a block-structured scheme, i.e. with solver._patch,
73 solver._patch_overlap_update and
74 solver._patch_overlap_current_time_step.
75
76 @param interpolation: toolbox.blockstructured.api.InterpolateAndRestrictCells.Interpolation
77 How the patch of a new cell is initialised from its parent. The
78 default is d-linear interpolation.
79
80 @param restriction: toolbox.blockstructured.api.InterpolateAndRestrictCells.Restriction
81 How the patches of erased cells are handed over to their parent.
82 The default is averaging.
83
84 """
85 super().__init__(solver)
86 self.interpolation = interpolation
87 self.restriction = restriction
88
89 def construct_output(self, exahype2_project, peano_project, mesh_adaptation):
90 """!
91
92 Add the two tasks of the mesh adaptation to mesh_adaptation
93
94 """
96 f"Create mesh adaptation and load balancing task graph for {self._solver.name}"
97 )
98 Access = peano4.api.taskgraph.Task.DataAccess
99 includes = (
100 self._solver_solver._get_default_includes() + self._solver_solver.user_solver_includes
101 )
102
103 adapt_task = peano4.api.taskgraph.Task(
104 name=f"{self._solver.name}_Adapt mesh and balance load",
105 entity=peano4.api.taskgraph.Task.GridEntity.CELL,
106 task_has_to_repeat=self.RepeatCondition,
107 may_spawn_background_tasks=False,
108 )
109 adapt_task.use_cell(self._solver_solver._patch, Access.READ_AND_WRITE)
111 adapt_task.add_action_set(ConsumeRefinementRequests(self._solver_solver))
112 adapt_task.add_action_set(
113 toolbox.blockstructured.api.InterpolateAndRestrictCells(
114 self._solver_solver._patch,
115 interpolation=self.interpolation,
116 restriction=self.restriction,
117 additional_includes=includes,
118 )
119 )
120 adapt_task.add_action_set(toolbox.loadbalancing.api.actionsets.LoadBalancing())
121
122 project_on_faces_task = peano4.api.taskgraph.Task(
123 name=f"{self._solver.name}_Project on faces",
124 entity=peano4.api.taskgraph.Task.GridEntity.CELL,
125 )
126 project_on_faces_task.add_dependency(adapt_task)
127 project_on_faces_task.use_cell(self._solver_solver._patch, Access.READ_AND_WRITE)
128 project_on_faces_task.use_face(
129 self._solver_solver._patch_overlap_update, Access.TEMPORARY
130 )
131 project_on_faces_task.use_face(
132 self._solver_solver._patch_overlap_current_time_step,
133 get_access_to_persistent_face_data(
134 self._solver_solver, exahype2_project, Access.WRITE
135 ),
136 )
137 self._add_projection_action_sets(project_on_faces_task, exahype2_project)
138
139 mesh_adaptation.add_task(adapt_task)
140 mesh_adaptation.add_task(project_on_faces_task)
141
142 if peano4.api.Logger().is_visualisation:
143 mesh_adaptation.visualise(
144 title=f"Mesh adaptation task graph for {self._solver.name}"
145 )
146 if peano4.api.Logger().is_text:
147 mesh_adaptation.log_as_text(
148 title=f"Mesh adaptation task graph for {self._solver.name}"
149 )
150
152 """!
153
154 Add scheme-specific action sets to the task which adapts the mesh
155
156 They are added before the generic ones. The default adds nothing.
157
158 """
159 pass
160
161 def _add_projection_action_sets(self, project_on_faces_task, exahype2_project):
162 """!
163
164 Add the scheme-specific action sets which project the patches onto
165 the faces and roll the face data over
166
167 Has to be implemented by the subclasses. The task already declares
168 the use of solver._patch, solver._patch_overlap_update and
169 solver._patch_overlap_current_time_step.
170
171 """
172 raise NotImplementedError(
173 f"{type(self).__name__} has to implement _add_projection_action_sets()"
174 )
How a Solver adapts its mesh and rebalances its load between two time steps.
Definition Solver.py:306
construct_output(self, exahype2_project, peano_project, mesh_adaptation)
Add the two tasks of the mesh adaptation to mesh_adaptation.
_add_projection_action_sets(self, project_on_faces_task, exahype2_project)
Add the scheme-specific action sets which project the patches onto the faces and roll the face data o...
_add_further_adaptation_action_sets(self, adapt_task)
Add scheme-specific action sets to the task which adapts the mesh.
tuple RepeatCondition
Repeat condition of the task which adapts the mesh and balances the load.
__init__(self, Solver solver, "toolbox.blockstructured.api.InterpolateAndRestrictCells.Interpolation" interpolation=toolbox.blockstructured.api.InterpolateAndRestrictCells.Interpolation.Linear, "toolbox.blockstructured.api.InterpolateAndRestrictCells.Restriction" restriction=toolbox.blockstructured.api.InterpolateAndRestrictCells.Restriction.Averaging)
Hand the refine and erase requests of the last time step over to Peano, and restart the time stepping...
Singleton logger for the Peano 4 Python API.
Definition Logger.py:37
One task within a peano4.api.taskgraph.Graph.
Definition Task.py:8