Peano
Loading...
Searching...
No Matches
create_dynamic_mesh_refinement_action_set.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
3from ..AdaptivityCriterion import get_adaptivity_criterion
4from ..GradientRefinement import GradientRefinement
5from ..RefineErasePointwisely import RefineErasePointwisely
6from .DynamicMeshRefinement import DynamicMeshRefinement
7from .DynamicMeshRefinementWithGradients import DynamicMeshRefinementWithGradients
8
9
10def create_dynamic_mesh_refinement_action_set(
11 solver,
12 patch_size: int,
13 guard: str,
14 min_volume_size: float = None,
15 max_volume_size: float = None,
16 hand_events_to_peano: bool = False,
17 veto_erase: bool = False,
18):
19 """!
20
21 Create the action set which evaluates the solver's adaptivity criterion
22
23 The numerical schemes and the setup do not evaluate any criterion if the
24 solver has none, i.e. they then add no action set at all. Otherwise, the
25 criterion's type determines the action set:
26
27 - exahype2.api.RefineErasePointwisely yields an
28 exahype2.api.blockstructured.DynamicMeshRefinement;
29 - exahype2.api.GradientRefinement yields an
30 exahype2.api.blockstructured.DynamicMeshRefinementWithGradients.
31
32 @param solver: exahype2.api.Solver
33 The solver whose criterion is evaluated. It may have at most one
34 adaptivity criterion (@ref exahype2.api.AdaptivityCriterion).
35
36 @param patch_size: int
37 Number of volumes per axis within one patch.
38
39 @param guard: str
40 C++ boolean expression, evaluated per cell, guarding whether the
41 criterion is evaluated for that cell.
42
43 @param min_volume_size: float
44 See exahype2.api.blockstructured.DynamicMeshRefinement.
45
46 @param max_volume_size: float
47 See exahype2.api.blockstructured.DynamicMeshRefinement.
48
49 @param hand_events_to_peano: bool
50 See exahype2.api.blockstructured.DynamicMeshRefinement.
51
52 @param veto_erase: bool
53 See exahype2.api.blockstructured.DynamicMeshRefinement.
54
55 @return The action set, or None if the solver has no adaptivity
56 criterion.
57
58 """
59 criterion = get_adaptivity_criterion(solver)
60 if criterion is None:
61 return None
62 if isinstance(criterion, RefineErasePointwisely):
63 action_set_type = DynamicMeshRefinement
64 elif isinstance(criterion, GradientRefinement):
65 action_set_type = DynamicMeshRefinementWithGradients
66 else:
67 raise TypeError(
68 f"No action set evaluates adaptivity criteria of type {type(criterion).__name__}"
69 )
70 return action_set_type(
71 solver,
72 patch_size,
73 guard=guard,
74 min_volume_size=min_volume_size,
75 max_volume_size=max_volume_size,
76 hand_events_to_peano=hand_events_to_peano,
77 veto_erase=veto_erase,
78 )