Peano
Loading...
Searching...
No Matches
EnumerateCellsAndVertices.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.solversteps.ActionSet import ActionSet
4
5
6import jinja2
7import dastgen2
8import peano4
9
10
11TaskMarkerIdentifier = "TaskMarker"
12UndefinedNumber = -1
13
14
15def construct_marker_name(task_name):
16 return task_name + "MeshNumber"
17
18
20 full_qualified_enumerator_type = "tarch::Enumerator",
21 enumerator_include = """ #include "tarch/Enumerator.h" """
22 ):
23 """!
24
25 Create vertex marker
26
27 This marker can be used for vertices. The numbers are then typically used
28 for some kind of task system or external referencing. Similar systems are
29 also used linear algebra, i.e. where you enumerate mesh entities, but this
30 one is different as a vertex holds information about its adjacent cells'
31 numbers.
32
33 If you want to use the action sets from this file, you have to run create
34 markers for the vertices and the cells, and you have to add them to the
35 mesh:
36
37 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38 cell_marker_for_tasks = peano4.toolbox.api.EnumerateCellsAndVertices.create_cell_marker(current_species_set.name)
39 vertex_marker_for_tasks = peano4.toolbox.api.EnumerateCellsAndVertices.create_vertex_marker(current_species_set.name)
40
41 self._project.datamodel.add_cell(cell_marker_for_tasks)
42 self._project.datamodel.add_vertex(vertex_marker_for_tasks)
43 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
45 Furthermore, you have to add the use_vertex and use_cell instructions to
46 each observer (algorithm step) before you add the action sets to the sets
47 in turn.
48
49 Please note that this marker not only holds an index for the vertex. It
50 also hosts the markers of the adjacent cells.
51
52 """
53 dastgen_marker = peano4.datamodel.DaStGen2(construct_marker_name(task_name))
54 dastgen_marker.data.add_attribute(
56 name="Number",
57 initval=UndefinedNumber,
58 )
59 )
60 dastgen_marker.data.add_attribute(
62 name="AdjacentCellNumber", cardinality="TwoPowerD"
63 )
64 )
65 dastgen_marker.data.add_attribute(
67 name="Enumerator",
68 type=full_qualified_enumerator_type,
69 include=enumerator_include,
70 qualifier=dastgen2.attributes.Attribute.Qualifier.STATIC,
71 )
72 )
73 return dastgen_marker
74
75
76def create_cell_marker(task_name):
77 """!
78
79 Create cell marker for tasking
80
81 This marker can be used for cells.
82
83 @see create_vertex_marker() for some usage information.
84
85 """
86 dastgen_marker = peano4.datamodel.DaStGen2(construct_marker_name(task_name))
87 dastgen_marker.data.add_attribute(
89 name="Number",
90 initval=UndefinedNumber,
91 )
92 )
93 dastgen_marker.data.add_attribute(
95 name="Enumerator",
96 type="tarch::Enumerator",
97 include=""" #include "tarch/Enumerator.h" """,
98 qualifier=dastgen2.attributes.Attribute.Qualifier.STATIC,
99 )
100 )
101 return dastgen_marker
102
103
105 """!
106
107 Gives each mesh entity a unique number
108
109 Also ensure that a vertex knows about the numbers of the adjacent cells.
110 The numbers are unique per rank, but not unique globally. We achieve
111 uniqueness by relying on the tarch::Enumerator.
112
113 """
114
116 self,
117 task_name,
118 ):
119 """!
120
121 Initialise assignment
122
123 @param task_name: String
124 The name of the task (attribute tied to the mesh entity) to be
125 manipulated.
126
127 """
128 super( AssignNumbersToMesh, self ).__init__()
129 self._task_name = task_name
130 pass
131
132 def get_body_of_operation(self, operation_name):
133 """!
134
135 Very simple operation which basically resets all data
136
137 """
138 if (
139 operation_name == ActionSet.OPERATION_CREATE_PERSISTENT_VERTEX
140 or operation_name == ActionSet.OPERATION_CREATE_HANGING_VERTEX
141 ):
142 return """
143 fineGridVertex{}.setNumber(tarch::Enumerator::NoNumber);
144 for (int i=0; i<TwoPowerD; i++) {{
145 fineGridVertex{}.setAdjacentCellNumber(i,tarch::Enumerator::NoNumber);
146 }}
147 """.format(
148 construct_marker_name(self._task_name),
149 construct_marker_name(self._task_name),
150 construct_marker_name(self._task_name),
151 )
152 if (
153 operation_name == ActionSet.OPERATION_DESTROY_PERSISTENT_VERTEX
154 or operation_name == ActionSet.OPERATION_DESTROY_HANGING_VERTEX
155 ):
156 return """
157 fineGridVertex{}.getEnumerator().releaseNumber( fineGridVertex{}.getNumber() );
158 """.format(
159 construct_marker_name(self._task_name),
160 construct_marker_name(self._task_name),
161 )
162 if operation_name == ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME:
163 return """
164 if ( fineGridVertex{}.getNumber()==tarch::Enumerator::NoNumber ) {{
165 fineGridVertex{}.setNumber( fineGridVertex{}.getEnumerator().getNumber() );
166 logDebug( "touchVertexFirstTime(...)", "set number " << fineGridVertex{}.toString() );
167 }}
168 """.format(
169 construct_marker_name(self._task_name),
170 construct_marker_name(self._task_name),
171 construct_marker_name(self._task_name),
172 construct_marker_name(self._task_name),
173 construct_marker_name(self._task_name),
174 )
175 if operation_name == ActionSet.OPERATION_CREATE_CELL:
176 return """
177 fineGridCell{}.setNumber(tarch::Enumerator::NoNumber);
178 """.format(
179 construct_marker_name(self._task_name)
180 )
181 if operation_name == ActionSet.OPERATION_DESTROY_CELL:
182 return """
183 fineGridCell{}.getEnumerator().releaseNumber( fineGridCell{}.getNumber() );
184 """.format(
185 construct_marker_name(self._task_name),
186 construct_marker_name(self._task_name),
187 )
188 if operation_name == ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
189 return """
190 if ( fineGridCell{}.getNumber()==tarch::Enumerator::NoNumber ) {{
191 fineGridCell{}.setNumber( fineGridCell{}.getEnumerator().getNumber() );
192 logDebug( "touchCellFirstTime(...)", "set number " << fineGridCell{}.toString() );
193 }}
194 for (int i=0; i<TwoPowerD; i++) {{
195 fineGridVertices{}(i).setAdjacentCellNumber(
196 TwoPowerD-1-i,
197 fineGridCell{}.getNumber()
198 );
199 }}
200 """.format(
201 construct_marker_name(self._task_name),
202 construct_marker_name(self._task_name),
203 construct_marker_name(self._task_name),
204 construct_marker_name(self._task_name),
205 construct_marker_name(self._task_name),
206 construct_marker_name(self._task_name),
207 )
208 return ""
209
211 return " return std::vector< peano4::grid::GridControlEvent >();\n"
212
214 return __name__.replace(".py", "").replace(".", "_") + "_AssignNumbersToMesh"
215
217 return False
218
219 def get_includes(self):
220 return """
221#include "tarch/Enumerator.h"
222 """
223
224
226 """!
227
228 Clear all the numbers on the mesh
229
230 We set all entries to AdjacentCellNumber.
231
232 """
233 def __init__(self, task_name):
234 self._task_name = task_name
235 pass
236
237 def get_body_of_operation(self, operation_name):
238 """!
239
240 Very simple operation which basically resets all data
241
242 """
243 if operation_name == ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME:
244 return """
245 fineGridVertex{}.setNumber(tarch::Enumerator::NoNumber);
246 for (int i=0; i<TwoPowerD; i++) fineGridVertex{}.setAdjacentCellNumber(i,tarch::Enumerator::NoNumber);
247 logDebug( "touchVertexFirstTime(...)", "reset " << fineGridVertex{}.toString() );
248 """.format(
249 construct_marker_name(self._task_name),
250 construct_marker_name(self._task_name),
251 construct_marker_name(self._task_name),
252 construct_marker_name(self._task_name),
253 )
254 if operation_name == ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
255 return """
256 fineGridCell{}.setNumber(tarch::Enumerator::NoNumber);
257 logDebug( "touchCellFirstTime(...)", "reset " << fineGridCell{}.toString() );
258 """.format(
259 construct_marker_name(self._task_name),
260 construct_marker_name(self._task_name),
261 construct_marker_name(self._task_name),
262 )
263 return ""
264
266 return " return std::vector< peano4::grid::GridControlEvent >();\n"
267
269 return __name__.replace(".py", "").replace(".", "_") + "_ClearNumbersOnMesh"
270
272 return False
273
274 def get_includes(self):
275 return """
276#include "tarch/Enumerator.h"
277"""
Wrapper around user-defined attribute.
Default superclass for any data model in Peano which is stored within the grid.
Definition DaStGen2.py:197
Action set (reactions to events)
Definition ActionSet.py:6
user_should_modify_template(self)
Is the user allowed to modify the output.
get_body_of_operation(self, operation_name)
Very simple operation which basically resets all data.
user_should_modify_template(self)
Is the user allowed to modify the output.
get_body_of_operation(self, operation_name)
Very simple operation which basically resets all data.
create_vertex_marker(task_name, full_qualified_enumerator_type="tarch::Enumerator", enumerator_include=""" #include "tarch/Enumerator.h" """)
Create vertex marker.
create_cell_marker(task_name)
Create cell marker for tasking.