3from .AbstractRungeKuttaDGActionSet
import AbstractRungeKuttaDGActionSet
11 The action set to realise AMR
13 AMR is a multistep process in ExaHyPE. Most of the relevant documentation
14 on it is documented in the class exahype2::RefinementControl.
16 There are different phases in ExaHyPE: grid generation (either with
17 refinement or without), initialisation, plotting and time stepping. It
18 depends on your solver in which time stepping to use AMR, but the there
19 are some things to take into account that are in common for all schemes:
21 - The grid creation does not use any actual solver data, so we should not
22 evalutae the adaptivity criterion here.
23 - InitGrid has volumetric data and might want to evaluate the criterion.
24 This is implicitly done by the t=0 check below.
25 - The plotting does not alter the solution. It thus makes no sense to
26 evaluate the criterion here.
28 Please consult EnclaveTasking.create_action_sets for details regarding
29 the handling of AMR within the enclave tasking concept.
35 logTraceInWith2Arguments( "touchCellFirstTime(...)", marker.willBeRefined(), marker.hasBeenRefined() );
37 ::exahype2::RefinementCommand refinementCriterion = ::exahype2::getDefaultRefinementCommand();
39 {% if GRID_CONSTRUCTION %}
41 not marker.willBeRefined()
43 tarch::la::greater( tarch::la::max( marker.h() ), repositories::{{SOLVER_INSTANCE}}.MaxAdmissibleCellH)
45 refinementCriterion = ::exahype2::RefinementCommand::Refine;
48 not marker.willBeRefined()
50 tarch::la::greaterEquals( tarch::la::max( marker.h() ), repositories::{{SOLVER_INSTANCE}}.MinAdmissibleCellH )
52 not fineGridCell{{CELL_LABEL_NAME}}.getAMDCriterionEvaluatedThroughoutGridConstruction()
54 refinementCriterion = repositories::{{SOLVER_INSTANCE}}.refinementCriterion(
60 fineGridCell{{CELL_LABEL_NAME}}.setAMDCriterionEvaluatedThroughoutGridConstruction(true);
63 refinementCriterion = ::exahype2::RefinementCommand::Keep;
69 not marker.willBeRefined()
71 tarch::la::greater( tarch::la::max( marker.h() ), repositories::{{SOLVER_INSTANCE}}.MaxAdmissibleCellH)
73 refinementCriterion = ::exahype2::RefinementCommand::Refine;
78 fineGridCell{{CELL_LABEL_NAME}}.getHasUpdated()
80 refinementCriterion = repositories::{{SOLVER_INSTANCE}}.refinementCriterion(
81 fineGridCell{{UNKNOWN_IDENTIFIER}}.value,
84 repositories::{{SOLVER_INSTANCE}}.getMinTimeStamp()
88 refinementCriterion==::exahype2::RefinementCommand::Refine
90 tarch::la::smaller( tarch::la::max( marker.h() ), repositories::{{SOLVER_INSTANCE}}.MinAdmissibleCellH )
92 logDebug( "touchCellFirstTime(...)", "drop refine instructions, as mesh would be too small" );
93 refinementCriterion = ::exahype2::RefinementCommand::Keep;
95 else if (refinementCriterion==::exahype2::RefinementCommand::Erase and 3.0* tarch::la::max( marker.h() ) > repositories::{{SOLVER_INSTANCE}}.MaxAdmissibleCellH ) {
96 refinementCriterion = ::exahype2::RefinementCommand::Keep;
100 refinementCriterion = ::exahype2::RefinementCommand::Keep;
104 _localRefinementControl.addCommand( marker.x(), marker.h(), refinementCriterion, {{EVENT_LIFETIME}} );
105 logTraceOutWith1Argument( "touchCellFirstTime(...)", toString(refinementCriterion) );
112 build_up_new_refinement_instructions,
113 implement_previous_refinement_instructions,
114 called_by_grid_construction,
121 _implement_previous_refinement_instructions: Boolean
122 This name might be misleading. Consult exahype2::RefinementControl for
123 a description of the control flow. This flag controls if instructions
124 are picked up from the RefinementControl database.
129 guard: C++ expression which evaluates to true or false
130 A per cell decision whether we should study a cell or not.
132 build_up_new_refinement_instructions: Boolean
133 See remarks on multistep realisation of AMR in C++ class
134 exahype2::RefinementControl.
136 implement_previous_refinement_instructions: Boolean
137 See remarks on multistep realisation of AMR in C++ class
138 exahype2::RefinementControl.
144 super(AdaptivityCriterion,self).
__init__(solver)
155 return ::exahype2::RefinementControlService::getInstance().getGridControlEvents();
159 return std::vector< peano4::grid::GridControlEvent >();
167 _localRefinementControl.clear();
172 ::exahype2::RefinementControlService::getInstance().merge( _localRefinementControl );
178 d[
"CELL_LABEL_NAME" ] = self.
_solver._cell_label.name
179 d[
"UNKNOWNS" ] = str(self.
_solver._current_time_step.no_of_unknowns)
183 d[
"CELL_ACCESSOR" ] =
"fineGridCell" + self.
_solver._current_time_step.name
184 d[
"PREDICATE" ] =
"not marker.willBeRefined() and not marker.hasBeenRefined() and " + self.
guard
188 self.
_solver._init_dictionary_with_default_parameters(d)
189 self.
_solver.add_entries_to_text_replacement_dictionary(d)
190 result = jinja2.Template( self.
TemplateAMR ).render(**d)
200 @event_lifetime.setter
204 By default, a refinement/coarsening event is only alive for one grid sweep.
205 After that one, the set of refine/coarsen commands is reset and we start
206 again. If you work with local time stepping, subcycling, multiphysics codes,
207 you might want to keep an event for more steps. In this case, you have to
216 ::exahype2::RefinementControl _localRefinementControl;
221 return __name__.replace(
".py",
"").replace(
".",
"_")
225 return super( AdaptivityCriterion, self ).
get_includes() +
"""
226#include "exahype2/RefinementControlService.h"
The action set to realise AMR.
get_attributes(self)
Return attributes as copied and pasted into the generated class.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
_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...
__init__(self, solver, guard, build_up_new_refinement_instructions, implement_previous_refinement_instructions, called_by_grid_construction, event_lifetime=2)
:: Attributes
get_includes(self)
Return include statements that you need.
_implement_previous_refinement_instructions
_build_up_new_refinement_instructions
get_body_of_getGridControlEvents(self)