Peano
Loading...
Searching...
No Matches
ConstructRegularGrid.py
Go to the documentation of this file.
1# This file is part of the Peano project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from peano4.api.solversteps import ActionSet
4
5
7 """!
8
9 Refine the mesh - solver-agnostic - down to a regular grid of a given
10 resolution.
11
12 Unlike the dynamic mesh refinement action sets that evaluate a solver's
13 adaptivity criterion (@ref exahype2.api.AdaptivityCriterion, see
14 @ref exahype2.api.blockstructured.DynamicMeshRefinement), this action set
15 does not evaluate any solver data (there is none yet while the grid is
16 still being built): it only ever looks at a cell's size and decides to
17 refine or keep based on cell_size alone. That is what makes it
18 "generic" - solver-independent - and hence a candidate to sit in
19 peano4.api.actionsets rather than one of the discretisation- or
20 extension-specific actionsets packages (e.g. exahype2.api.fv.actionsets).
21
22 The resulting C++ file will be really simplistic, basically consisting of
23 only a few lines of code in the touchVertexFirstTime operation, the beginTraversal()
24 event and the routine that returns the grid control events.
25
26 """
27
29 self,
30 cell_size: float,
31 descend_invocation_order=0,
32 parallel=True,
33 guard: str = "true",
34 includes: str = "",
35 ):
36 """!
37
38 @param cell_size: float
39 Upper bound on the edge length of the cells of the regular grid.
40 Peano refines every cell whose edge length is greater than or equal
41 to cell_size, i.e. the resulting cells are strictly smaller than
42 cell_size. Peano always refines the root cell at least once.
43
44 @param guard: str
45 C++ boolean expression. The action set only returns its
46 refinement instruction for the next traversal if the expression
47 holds. Otherwise, it does not ask for any refinement, i.e. the
48 mesh construction pauses. The expression is evaluated in
49 createGridControlEventsForNextTraversal(). By default, the action
50 set always refines.
51
52 @param includes: str
53 Include statements required by guard.
54
55 """
56 super().__init__(descend_invocation_order, parallel)
57 self.cell_size = cell_size
58 self.guard = guard
59 self.includes = includes
60
62 return False
63
65 return f"""
66if ( not ({self.guard}) ) {{
67 return std::vector< peano4::grid::GridControlEvent >();
68}}
69
70const std::vector< peano4::grid::GridControlEvent > result = {{
71 peano4::grid::GridControlEvent(
72 peano4::grid::GridControlEvent::RefinementControl::Refine,
73 tarch::la::Vector<Dimensions,double>( -0.5 * std::numeric_limits<double>::max() ),
74 tarch::la::Vector<Dimensions,double>( std::numeric_limits<double>::max() ),
75 tarch::la::Vector<Dimensions,double>( {self.cell_size} )
76 )
77}};
78return result;
79"""
80
81 def get_includes(self):
82 return """
83#include <limits>
84""" + self.includes
85
87 return __name__.replace(".py", "").replace(".", "_")
Refine the mesh - solver-agnostic - down to a regular grid of a given resolution.
__init__(self, float cell_size, descend_invocation_order=0, parallel=True, str guard="true", str includes="")
get_body_of_createGridControlEventsForNextTraversal(self)
Return the grid control events that this action set wants to trigger.
user_should_modify_template(self)
Is the user allowed to modify the output.
get_includes(self)
Return include statements that you need.
Action set (reactions to events)
Definition ActionSet.py:6
The Python-side model of "what happens during one mesh sweep".
Definition __init__.py:1