Peano
Loading...
Searching...
No Matches
SetupSimulationWithUserCodedRefinementCriterion.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
4
5from ..AdaptivityCriterion import get_adaptivity_criterion
6from ..blockstructured.create_dynamic_mesh_refinement_action_set import (
7 create_dynamic_mesh_refinement_action_set,
8)
9from ..Solver import Solver
10from .SetupSimulationOverRegularGrid import SetupSimulationOverRegularGrid
11from .actionsets import InitialiseNewCells
12
13
15 """!
16
17 Setup over a regular mesh which is then refined adaptively by the user's
18 adaptivity criterion
19
20 The setup does everything SetupSimulationOverRegularGrid does: It
21 constructs a regular mesh and sets the initial condition. If the solver
22 has an exahype2.api.AdaptivityCriterion PDE term, the setup then
23 adapts this mesh. It inserts one further task after the task tagged with
24 SetupSimulationOverRegularGrid.FinishedInitialRegularMeshSetup, i.e.
25 after the initial condition. The projection onto the faces, which has
26 followed the initial condition so far, follows this new task instead and
27 hence remains the very last task of the setup.
28
29 The new task repeats until the mesh is stationary. It hosts two action
30 sets:
31
32 - The action set which also evaluates the criterion within the time
33 step (@ref exahype2.api.blockstructured.create_dynamic_mesh_refinement_action_set.create_dynamic_mesh_refinement_action_set())
34 turns the criterion's outcome into refine or erase events for
35 ExaHyPE's refinement service. Different to the time step, it also
36 hands the service's events over to Peano.
37 The mesh is never refined below min_volume_size.
38 The setup vetoes all erase commands, i.e. it only ever refines the
39 regular mesh: It has no restriction which would hand the patches of
40 erased cells over to their parent. Erase commands of the criterion
41 hence only take effect once the time stepping runs.
42 - exahype2.api.fv.actionsets.InitialiseNewCells sets the initial
43 condition within each cell which the refinement creates.
44
45 Without an adaptivity criterion, the setup is the same as
46 SetupSimulationOverRegularGrid.
47
48 Peano realises a refinement event one to two mesh sweeps after the
49 criterion has asked for it (@ref exahype2::RefinementControl). The mesh
50 hence might still be stationary in the sweeps right after the criterion
51 has issued an event. The task therefore repeats as long as the mesh
52 changes or the refinement service still holds events.
53
54 """
55
56 def __init__(self, solver: Solver, volume_size: float, min_volume_size: float):
57 """!
58
59 @param volume_size: float
60 Maximum edge length of one Finite Volume. The setup first
61 constructs a regular mesh with this volume size
62 (@ref exahype2.api.fv.SetupSimulationOverRegularGrid). The mesh
63 refinement never erases cells of this regular mesh.
64
65 @param min_volume_size: float
66 Minimum edge length of one Finite Volume. The setup refines a cell
67 only if its volumes are at least of this size, i.e. the resulting
68 volumes are strictly smaller than min_volume_size. The
69 semantics are the same as for volume_size.
70
71 """
72 super().__init__(solver, volume_size)
73 assert min_volume_size <= volume_size, (
74 f"min_volume_size={min_volume_size} has to be smaller than or equal to "
75 f"volume_size={volume_size}"
76 )
77 self.min_volume_size = min_volume_size
78
79
80 RepeatCondition = (
81 "not peano4::grid::isGridStationary( peano4::parallel::SpacetreeSet::getInstance().getGridStatistics() )"
82 " or not ::exahype2::RefinementControlService::getInstance().createGridControlEventsForNextTraversal().empty()"
83 )
84
85 def construct_output(self, exahype2_project, peano_project, setup_simulation):
86 """!
87
88 Construct the setup over the regular mesh and insert the mesh
89 adaptation after it, if the solver has an adaptivity criterion
90
91 """
93 "Create setup task graph for Finite Volume scheme with user-coded refinement criterion"
94 )
95 self._construct_task_graph(exahype2_project, peano_project, setup_simulation)
96
97 if get_adaptivity_criterion(self._solver_solver_solver) is not None:
98 anchors = setup_simulation.find_tasks(
99 SetupSimulationOverRegularGrid.FinishedInitialRegularMeshSetup
100 )
101 assert len(anchors) == 1, (
102 f"Expected exactly one task tagged with "
103 f"{SetupSimulationOverRegularGrid.FinishedInitialRegularMeshSetup}, "
104 f"got {len(anchors)}"
105 )
106 setup_simulation.insert_after(anchors, self._create_adapt_mesh_task())
107
108 self._report_task_graph(setup_simulation)
109
111 """!
112
113 Create the repeating task which adapts the mesh
114
115 """
116 patch_size = self._solver_solver_solver.numerical_scheme.patch_size
117 adapt_mesh_task = peano4.api.taskgraph.Task(
118 name=f"{self._solver.name} Adapt mesh",
119 entity=peano4.api.taskgraph.Task.GridEntity.CELL,
120 task_has_to_repeat=self.RepeatCondition,
121 )
122 adapt_mesh_task.add_action_set(
123 create_dynamic_mesh_refinement_action_set(
125 patch_size,
126 guard=self._solver_solver_solver.grid_selector.createCellGuard(),
127 min_volume_size=self.min_volume_size,
128 max_volume_size=self.volume_size,
129 hand_events_to_peano=True,
130 veto_erase=True,
131 )
132 )
133 adapt_mesh_task.add_action_set(
135 self._solver_solver_solver, guard=self._solver_solver_solver.grid_selector.createCellGuard()
136 )
137 )
138 adapt_mesh_task.use_cell(
139 self._solver_solver_solver._patch, peano4.api.taskgraph.Task.DataAccess.READ_AND_WRITE
140 )
141 return adapt_mesh_task
Setup phase counterpart to RusanovWithExplicitEuler: sets the initial condition for a Finite Volume s...
_construct_task_graph(self, exahype2_project, peano_project, setup_simulation)
Add the tasks of the setup over a regular mesh to setup_simulation.
_solver
On adaptive meshes, restrict the fine data from the hanging faces onto the coarse faces.
_report_task_graph(self, setup_simulation)
Visualise or log the setup task graph, depending on the logger's verbosity.
construct_output(self, exahype2_project, peano_project, setup_simulation)
Construct the setup over the regular mesh and insert the mesh adaptation after it,...
Set the initial condition within cells which the mesh refinement creates.
Singleton logger for the Peano 4 Python API.
Definition Logger.py:37
One task within a peano4.api.taskgraph.Graph.
Definition Task.py:8