4from .AbstractRKFDActionSet
import AbstractRKFDActionSet
12 The action set to realise AMR
14 AMR is a multistep process in ExaHyPE. Most of the relevant documentation
15 on it is documented in the class exahype2::RefinementControl.
17 There are different phases in ExaHyPE: grid generation (either with
18 refinement or without), initialisation, plotting and time stepping. It
19 depends on your solver in which time stepping to use AMR, but the there
20 are some things to take into account that are in common for all schemes:
22 - The grid creation does not use any actual solver data, so we should not
23 evalutae the adaptivity criterion here.
24 - InitGrid has volumetric data and might want to evaluate the criterion.
25 This is implicitly done by the t=0 check below.
26 - The plotting does not alter the solution. It thus makes no sense to
27 evaluate the criterion here.
29 Please consult EnclaveTasking.create_action_sets for details regarding
30 the handling of AMR within the enclave tasking concept.
36 logTraceInWith2Arguments( "touchCellFirstTime(...)", marker.willBeRefined(), marker.hasBeenRefined() );
38 ::exahype2::RefinementCommand refinementCriterion = ::exahype2::getDefaultRefinementCommand();
40 {% if GRID_CONSTRUCTION %}
42 not marker.willBeRefined()
44 tarch::la::greater( tarch::la::max( marker.h() ), repositories::{{SOLVER_INSTANCE}}.MaxAdmissiblePatchH)
46 refinementCriterion = ::exahype2::RefinementCommand::Refine;
49 not marker.willBeRefined()
51 tarch::la::greaterEquals( tarch::la::max( marker.h() ), repositories::{{SOLVER_INSTANCE}}.MinAdmissiblePatchH )
53 not fineGridCell{{CELL_LABEL_NAME}}.getAMDCriterionEvaluatedThroughoutGridConstruction()
55 dfor( volume, {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}} ) {
56 refinementCriterion = refinementCriterion and repositories::{{SOLVER_INSTANCE}}.refinementCriterion(
58 ::exahype2::fd::getGridCellCentre( marker.x(), marker.h(), {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}}, volume),
59 ::exahype2::fd::getGridCellSize( marker.h(), {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}} ),
63 fineGridCell{{CELL_LABEL_NAME}}.setAMDCriterionEvaluatedThroughoutGridConstruction(true);
66 refinementCriterion = ::exahype2::RefinementCommand::Keep;
72 not marker.willBeRefined()
74 tarch::la::greater( tarch::la::max( marker.h() ), repositories::{{SOLVER_INSTANCE}}.MaxAdmissiblePatchH)
76 refinementCriterion = ::exahype2::RefinementCommand::Refine;
81 fineGridCell{{CELL_LABEL_NAME}}.getHasUpdated()
84 dfor( volume, {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}} ) {
85 refinementCriterion = refinementCriterion and repositories::{{SOLVER_INSTANCE}}.refinementCriterion(
86 fineGridCell{{UNKNOWN_IDENTIFIER}}.value + index,
87 ::exahype2::fd::getGridCellCentre( marker.x(), marker.h(), {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}}, volume),
88 ::exahype2::fd::getGridCellSize( marker.h(), {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}} ),
89 repositories::{{SOLVER_INSTANCE}}.getMinTimeStamp()
91 index += {{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}};
95 refinementCriterion==::exahype2::RefinementCommand::Refine
97 tarch::la::smallerEquals( tarch::la::max( marker.h() ), repositories::{{SOLVER_INSTANCE}}.MinAdmissiblePatchH )
99 logDebug( "touchCellFirstTime(...)", "drop refine instructions, as mesh would be too small" );
100 refinementCriterion = ::exahype2::RefinementCommand::Keep;
102 else if (refinementCriterion==::exahype2::RefinementCommand::Erase and 3.0* tarch::la::max( marker.h() ) > repositories::{{SOLVER_INSTANCE}}.MaxAdmissiblePatchH ) {
103 refinementCriterion = ::exahype2::RefinementCommand::Keep;
107 refinementCriterion = ::exahype2::RefinementCommand::Keep;
111 _localRefinementControl.addCommand( marker.x(), marker.h(), refinementCriterion, {{EVENT_LIFETIME}} );
112 logTraceOutWith1Argument( "touchCellFirstTime(...)", toString(refinementCriterion) );
119 build_up_new_refinement_instructions,
120 implement_previous_refinement_instructions,
121 called_by_grid_construction,
128 _implement_previous_refinement_instructions: Boolean
129 This name might be misleading. Consult exahype2::RefinementControl for
130 a description of the control flow. This flag controls if instructions
131 are picked up from the RefinementControl database.
136 guard: C++ expression which evaluates to true or false
137 A per cell decision whether we should study a cell or not.
139 build_up_new_refinement_instructions: Boolean
140 See remarks on multistep realisation of AMR in C++ class
141 exahype2::RefinementControl.
143 implement_previous_refinement_instructions: Boolean
144 See remarks on multistep realisation of AMR in C++ class
145 exahype2::RefinementControl.
151 AbstractRKFDActionSet.__init__(self,solver)
162 return ::exahype2::RefinementControlService::getInstance().getGridControlEvents();
166 return std::vector< peano4::grid::GridControlEvent >();
174 _localRefinementControl.clear();
179 ::exahype2::RefinementControlService::getInstance().merge( _localRefinementControl );
185 raise Exception(
"Error: Can only handle square patches." )
187 d[
"CELL_LABEL_NAME" ] = self.
_solver._cell_label.name
188 d[
"UNKNOWNS" ] = str(self.
_solver._patch.no_of_unknowns)
189 d[
"DOFS_PER_AXIS" ] = str(self.
_solver._patch.dim[0])
190 d[
"NUMBER_OF_DOUBLE_VALUES_IN_ORIGINAL_PATCH_2D" ] = str(self.
_solver._patch.no_of_unknowns * self.
_solver._patch.dim[0] * self.
_solver._patch.dim[0])
191 d[
"NUMBER_OF_DOUBLE_VALUES_IN_ORIGINAL_PATCH_3D" ] = str(self.
_solver._patch.no_of_unknowns * self.
_solver._patch.dim[0] * self.
_solver._patch.dim[0] * self.
_solver._patch.dim[0])
192 d[
"CELL_ACCESSOR" ] =
"fineGridCell" + self.
_solver._patch.name
193 d[
"PREDICATE" ] =
"not marker.willBeRefined() and not marker.hasBeenRefined() and " + self.
guard
197 self.
_solver._init_dictionary_with_default_parameters(d)
198 self.
_solver.add_entries_to_text_replacement_dictionary(d)
199 result = jinja2.Template( self.
TemplateAMR ).render(**d)
209 @event_lifetime.setter
213 By default, a refinement/coarsening event is only alive for one grid sweep.
214 After that one, the set of refine/coarsen commands is reset and we start
215 again. If you work with local time stepping, subcycling, multiphysics codes,
216 you might want to keep an event for more steps. In this case, you have to
225 ::exahype2::RefinementControl _localRefinementControl;
230 return __name__.replace(
".py",
"").replace(
".",
"_")
234 return super( AdaptivityCriterion, self ).
get_includes() +
"""
235#include "exahype2/RefinementControlService.h"
The action set to realise AMR.
__init__(self, solver, guard, build_up_new_refinement_instructions, implement_previous_refinement_instructions, called_by_grid_construction, event_lifetime=2)
:: Attributes
_called_by_grid_construction
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...
_implement_previous_refinement_instructions
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_attributes(self)
Return attributes as copied and pasted into the generated class.
_build_up_new_refinement_instructions
get_includes(self)
Return include statements that you need.
get_body_of_getGridControlEvents(self)