3from .AbstractADERDGActionSet
import AbstractADERDGActionSet
6import peano4.solversteps
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 evaluate 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.
33 logTraceInWith2Arguments("touchCellFirstTime(...)", marker.willBeRefined(), marker.hasBeenRefined());
35 ::exahype2::RefinementCommand refinementCriterion = ::exahype2::getDefaultRefinementCommand();
37 {% if GRID_CONSTRUCTION %}
39 not marker.willBeRefined()
41 tarch::la::greater(tarch::la::max(marker.h()), repositories::{{SOLVER_INSTANCE}}.MaxAdmissibleCellH)
43 refinementCriterion = ::exahype2::RefinementCommand::Refine;
45 not marker.willBeRefined()
47 tarch::la::greaterEquals(tarch::la::max(marker.h()), repositories::{{SOLVER_INSTANCE}}.MinAdmissibleCellH)
49 not fineGridCell{{CELL_LABEL_NAME}}.getAMDCriterionEvaluatedThroughoutGridConstruction()
51 refinementCriterion = repositories::{{SOLVER_INSTANCE}}.refinementCriterion(
55 repositories::{{SOLVER_INSTANCE}}.getMinTimeStamp()
57 fineGridCell{{CELL_LABEL_NAME}}.setAMDCriterionEvaluatedThroughoutGridConstruction(true);
59 refinementCriterion = ::exahype2::RefinementCommand::Keep;
65 not marker.willBeRefined()
67 tarch::la::greater(tarch::la::max(marker.h()), repositories::{{SOLVER_INSTANCE}}.MaxAdmissibleCellH)
69 refinementCriterion = ::exahype2::RefinementCommand::Refine;
73 fineGridCell{{CELL_LABEL_NAME}}.getHasUpdated()
75 refinementCriterion = repositories::{{SOLVER_INSTANCE}}.refinementCriterion(
76 fineGridCell{{UNKNOWN_IDENTIFIER}}.value,
79 repositories::{{SOLVER_INSTANCE}}.getMinTimeStamp()
83 refinementCriterion == ::exahype2::RefinementCommand::Refine
85 tarch::la::smallerEquals(tarch::la::max(marker.h()), 3.0 * repositories::{{SOLVER_INSTANCE}}.MinAdmissibleCellH)
87 logDebug("touchCellFirstTime(...)", "drop refine instructions, as mesh would be too small");
88 refinementCriterion = ::exahype2::RefinementCommand::Keep;
90 refinementCriterion == ::exahype2::RefinementCommand::Erase
92 3.0 * tarch::la::max(marker.h()) > repositories::{{SOLVER_INSTANCE}}.MaxAdmissibleCellH
94 refinementCriterion = ::exahype2::RefinementCommand::Keep;
97 refinementCriterion = ::exahype2::RefinementCommand::Keep;
101 _localRefinementControl.addCommand(marker.x(), marker.h(), refinementCriterion, {{EVENT_LIFETIME}});
102 logTraceOutWith1Argument("touchCellFirstTime(...)", toString(refinementCriterion));
109 build_up_new_refinement_instructions,
110 implement_previous_refinement_instructions,
111 called_by_grid_construction,
117 _implement_previous_refinement_instructions: Boolean
118 This name might be misleading. Consult exahype2::RefinementControl for
119 a description of the control flow. This flag controls if instructions
120 are picked up from the RefinementControl database.
125 guard: C++ expression which evaluates to true or false
126 A per cell decision whether we should study a cell or not.
128 build_up_new_refinement_instructions: Boolean
129 See remarks on multistep realisation of AMR in C++ class
130 exahype2::RefinementControl.
132 implement_previous_refinement_instructions: Boolean
133 See remarks on multistep realisation of AMR in C++ class
134 exahype2::RefinementControl.
139 super(AdaptivityCriterion, self).
__init__(solver)
142 build_up_new_refinement_instructions
145 implement_previous_refinement_instructions
153 return ::exahype2::RefinementControlService::getInstance().getGridControlEvents();
157 return std::vector<peano4::grid::GridControlEvent>();
164 and operation_name == peano4.solversteps.ActionSet.OPERATION_BEGIN_TRAVERSAL
167 _localRefinementControl.clear();
172 and operation_name == peano4.solversteps.ActionSet.OPERATION_END_TRAVERSAL
175 ::exahype2::RefinementControlService::getInstance().merge(_localRefinementControl);
181 == peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_LAST_TIME
185 d[
"CELL_LABEL_NAME"] = self.
_solver._cell_label.name
186 d[
"UNKNOWNS"] = str(self.
_solver._current_time_step.no_of_unknowns)
190 d[
"CELL_ACCESSOR"] =
"fineGridCell" + self.
_solver._current_time_step.name
192 "not marker.willBeRefined() and not marker.hasBeenRefined() and "
198 self.
_solver._init_dictionary_with_default_parameters(d)
199 self.
_solver.add_entries_to_text_replacement_dictionary(d)
206 By default, a refinement/coarsening event is only alive for one grid sweep.
207 After that one, the set of refine/coarsen commands is reset and we start
208 again. If you work with local time stepping, subcycling, multiphysics codes,
209 you might want to keep an event for more steps. In this case, you have to
216 ::exahype2::RefinementControl _localRefinementControl;
220 return __name__.replace(
".py",
"").replace(
".",
"_")
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_includes(self)
Return include statements that you need.
get_body_of_getGridControlEvents(self)
_called_by_grid_construction
_build_up_new_refinement_instructions
_implement_previous_refinement_instructions
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...
set_event_lifetime(self, value)
By default, a refinement/coarsening event is only alive for one grid sweep.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
__init__(self, solver, guard, build_up_new_refinement_instructions, implement_previous_refinement_instructions, called_by_grid_construction, event_lifetime=2)
:: Attributes