Peano
Loading...
Searching...
No Matches
Observer.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
3import os
4import re
5import jinja2
6
7
8from .Helper import write_file
9
10from .Overwrite import Overwrite
11
12from .Jinja2TemplatedHeaderFile import Jinja2TemplatedHeaderFile
13
14from ..Logger import Logger
15
16
17class Observer(object):
18 """!
19
20 C++ observer of one mesh traversal
21
22 ## Task groups
23
24 The observer invokes its action sets one by one: Per event, such as
25 touchVertexFirstTime() or createCell(), it runs through the action sets
26 and invokes the event on each of them. The action sets can be split
27 into task groups, i.e. consecutive action sets which may run in parallel
28 (@ref peano4.api.solversteps.SynchroniseActionSets.get_task_groups()).
29 Within enterCell() and leaveCell(), the observer embeds the code which
30 invokes the events of a group's action sets into one task per action
31 set, spawns these tasks and waits for them
32 (tarch::multicore::spawnAndWait()) before it continues with the next
33 group. This holds for all events, i.e. the create, touch and destroy
34 events of vertices, faces and cells. The tasks capture everything by
35 reference, which is safe, as the observer waits for them. A group with
36 one action set yields exactly the same code as an observer without task
37 groups.
38
39 """
40
41 default_overwrite = True
42
44 self,
45 classname,
46 namespace,
47 subdirectory,
48 included_actions,
49 vertices,
50 faces,
51 cells,
52 task_groups=None,
53 ):
54 """!
55
56 @param included_actions: [str]
57 Full qualified names of the action sets in invocation order.
58
59 @param task_groups: [[int]] or None
60 Groups of indices into included_actions. The groups are invoked
61 one after the other, the action sets within a group in parallel.
62 Concatenated, the groups have to yield 0, 1, 2, ..., i.e. every
63 action set exactly once and in invocation order. If None, every
64 action set forms a group of its own.
65
66 """
67 self.classname = classname
68 self.namespace = namespace
69 self.subdirectory = subdirectory
70
71 self.included_actions = included_actions
72 if task_groups is None:
73 task_groups = [[index] for index in range(len(included_actions))]
74 if [index for group in task_groups for index in group] != list(range(len(included_actions))):
75 raise Exception(
76 f"Task groups {task_groups} of observer {classname} do not enumerate its {len(included_actions)} action sets in order"
77 )
78 self.task_groups = task_groups
79 self.vertices = vertices
80 self.faces = faces
81 self.cells = cells
82
83 self.d = {}
84 self.d["OPEN_NAMESPACE"] = ""
85 self.d["CLOSE_NAMESPACE"] = ""
86 self.d["FULL_QUALIFIED_CLASSNAME"] = ""
87 for i in namespace:
88 self.d["OPEN_NAMESPACE"] += "namespace " + i + "{\n"
89 self.d["CLOSE_NAMESPACE"] += "}\n"
90 self.d["FULL_QUALIFIED_CLASSNAME"] += i + "::"
91 self.d["CLASSNAME"] = classname
92 self.d["FULL_QUALIFIED_CLASSNAME"] += classname
93 self.d["INCLUDE_GUARD"] = (
94 "_" + self.d["FULL_QUALIFIED_CLASSNAME"].replace("::", "_").upper() + "_H_"
95 )
96 self.d["INCLUDES"] = ""
97 self.d["ATTRIBUTES"] = ""
98
99 for action in self.included_actions:
100 self.d["INCLUDES"] += '#include "'
101 self.d["INCLUDES"] += action.replace("::", "/")
102 self.d["INCLUDES"] += '.h"\n'
103 self.d["ATTRIBUTES"] += " "
104 self.d["ATTRIBUTES"] += action
105 self.d["ATTRIBUTES"] += " _actionSet"
106 self.d["ATTRIBUTES"] += str(self.included_actions.index(action))
107 self.d["ATTRIBUTES"] += "; \n"
108
109 subdirectories = set()
110
111 self.d["MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS"] = ""
112 self.d["MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS"] = ""
113 self.d["MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS_PICK_ENTRY"] = ""
114 self.d["MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS_PICK_ENTRY"] = ""
115 for cell in cells:
116 if cells.index(cell) != 0:
117 self.d["MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS"] += ","
118 self.d["MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS"] += ","
119 self.d["MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS_PICK_ENTRY"] += ","
120 self.d["MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS_PICK_ENTRY"] += ","
121 self.d["MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS"] += (
122 cell.subnamespace +
123 "repositories::DataRepository::_"
124 + cell.get_logical_type_name()
125 + "Stack.getForPop( " +
126 cell.subnamespace +
127 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->top(0)"
128 )
129 self.d["MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS"] += (
130 cell.subnamespace +
131 "repositories::DataRepository::_"
132 + cell.get_logical_type_name()
133 + "Stack.getForPop( " +
134 cell.subnamespace +
135 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->top(1)"
136 )
137 self.d["MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS_PICK_ENTRY"] += (
138 cell.subnamespace +
139 "repositories::DataRepository::_"
140 + cell.get_logical_type_name()
141 + "Stack.getForPop( " +
142 cell.subnamespace +
143 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->top(0)"
144 )
145 self.d["MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS_PICK_ENTRY"] += (
146 cell.subnamespace +
147 "repositories::DataRepository::_"
148 + cell.get_logical_type_name()
149 + "Stack.getForPop( " +
150 cell.subnamespace +
151 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->top(1)"
152 )
153 if cell.subdirectory:
154 subdirectories.add(cell.subdirectory)
155
156 self.d["MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS_CELL_EVENT"] = self.d[
157 "MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS"
158 ]
159 self.d["MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS_CELL_EVENT"] = self.d[
160 "MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS"
161 ]
162
163 self.d["MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS"] = ""
164 self.d["MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS"] = ""
165 self.d["MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_PICK_ENTRY"] = ""
166 self.d["MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_PICK_ENTRY"] = ""
167 for face in faces:
168 if faces.index(face) != 0:
169 self.d["MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS"] += ","
170 self.d["MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS"] += ","
171 self.d["MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_PICK_ENTRY"] += ","
172 self.d[
173 "MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_PICK_ENTRY"
174 ] += ","
175 self.d["MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS"] += (
176 "peano4::datamanagement::FaceEnumerator<"
177 + face.get_full_qualified_type()
178 + ">( &" +
179 face.subnamespace +
180 "repositories::DataRepository::_"
181 + face.get_logical_type_name()
182 + "Stack.getForPop( " +
183 face.subnamespace +
184 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->top(TwoTimesD-1) )"
185 )
186 self.d["MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS"] += (
187 "peano4::datamanagement::FaceEnumerator<"
188 + face.get_full_qualified_type()
189 + ">( &" +
190 face.subnamespace +
191 "repositories::DataRepository::_"
192 + face.get_logical_type_name()
193 + "Stack.getForPop( " +
194 face.subnamespace +
195 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->top(TwoTimesD*2-1) )"
196 )
197 self.d["MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_PICK_ENTRY"] += (
198 "peano4::datamanagement::FaceEnumerator<"
199 + face.get_full_qualified_type()
200 + ">( &" +
201 face.subnamespace +
202 "repositories::DataRepository::_"
203 + face.get_logical_type_name()
204 + "Stack.getForPop( " +
205 face.subnamespace +
206 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->top(TwoTimesD-1) )(pick)"
207 )
208 self.d["MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_PICK_ENTRY"] += (
209 "peano4::datamanagement::FaceEnumerator<"
210 + face.get_full_qualified_type()
211 + ">( &" +
212 face.subnamespace +
213 "repositories::DataRepository::_"
214 + face.get_logical_type_name()
215 + "Stack.getForPop( " +
216 face.subnamespace +
217 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->top(TwoTimesD*2-1) )(pick)"
218 )
219 if face.subdirectory:
220 subdirectories.add(face.subdirectory)
221
222 self.d["MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS"] = ""
223 self.d["MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS"] = ""
224 self.d["MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY"] = ""
225 self.d["MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY"] = ""
226 for vertex in vertices:
227 if vertices.index(vertex) != 0:
228 self.d["MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS"] += ","
229 self.d["MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS"] += ","
230 self.d[
231 "MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY"
232 ] += ","
233 self.d[
234 "MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY"
235 ] += ","
236 self.d["MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS"] += (
237 "peano4::datamanagement::VertexEnumerator<"
238 + vertex.get_full_qualified_type()
239 + ">( &" +
240 vertex.subnamespace +
241 "repositories::DataRepository::_"
242 + vertex.get_logical_type_name()
243 + "Stack.getForPop( " +
244 vertex.subnamespace +
245 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->top(TwoPowerD-1) )"
246 )
247 self.d["MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS"] += (
248 "peano4::datamanagement::VertexEnumerator<"
249 + vertex.get_full_qualified_type()
250 + ">( &" +
251 vertex.subnamespace +
252 "repositories::DataRepository::_"
253 + vertex.get_logical_type_name()
254 + "Stack.getForPop( " +
255 vertex.subnamespace +
256 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->top(TwoPowerD*2-1) )"
257 )
258 self.d["MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY"] += (
259 "peano4::datamanagement::VertexEnumerator<"
260 + vertex.get_full_qualified_type()
261 + ">( &" +
262 vertex.subnamespace +
263 "repositories::DataRepository::_"
264 + vertex.get_logical_type_name()
265 + "Stack.getForPop( " +
266 vertex.subnamespace +
267 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->top(TwoPowerD-1) )(pick)"
268 )
269 self.d["MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY"] += (
270 "peano4::datamanagement::VertexEnumerator<"
271 + vertex.get_full_qualified_type()
272 + ">( &" +
273 vertex.subnamespace +
274 "repositories::DataRepository::_"
275 + vertex.get_logical_type_name()
276 + "Stack.getForPop( " +
277 vertex.subnamespace +
278 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->top(TwoPowerD*2-1) )(pick)"
279 )
280 if vertex.subdirectory:
281 subdirectories.add(vertex.subdirectory)
282
283 self.d["DATAREPOSITORY_INCLUDES"] = ""
284 if subdirectories:
285 for subdir in subdirectories:
286 self.d["INCLUDES"] = "#include \"../" + subdir + "repositories/DataRepository.h\"\n" + self.d["INCLUDES"]
287 self.d["DATAREPOSITORY_INCLUDES"] += "#include \"../../" + subdir + "repositories/DataRepository.h\"\n"
288 else:
289 self.d["DATAREPOSITORY_INCLUDES"] = "#include \"../repositories/DataRepository.h\"\n"
290
291 def __generate_header(self, overwrite, directory):
292 headerfile_template = (
293 os.path.realpath(__file__)
294 .replace(".pyc", ".template.h")
295 .replace(".py", ".template.h")
296 )
297 md = self.mkSubDict(["ATTRIBUTES", "INCLUDES"])
299 headerfile_template,
300 self.classname,
301 self.namespace,
302 self.subdirectory,
303 md,
305 announce=False,
306 )
307 header.generate(overwrite, directory)
308 del header
309
310 TemplateConstructor = """
311
312{{FULL_QUALIFIED_CLASSNAME}}::{{CLASSNAME}}(int spacetreeId):
313 _spacetreeId( spacetreeId ) {{MAPPING_INITIALISATION_LIST}}
314{}
315
316
317 """
318
319 def __generate_constructor(self, output_file):
320 #
321 # Constructor
322 #
323 self.d["MAPPING_INITIALISATION_LIST"] = ""
324 for actions in self.included_actions:
325 self.d["MAPPING_INITIALISATION_LIST"] += ", _actionSet"
326 self.d["MAPPING_INITIALISATION_LIST"] += str(
327 self.included_actions.index(actions)
328 )
329 self.d["MAPPING_INITIALISATION_LIST"] += "(spacetreeId)"
330 output_file.write(jinja2.Template(self.TemplateConstructorTemplateConstructor).render(**self.d))
331
332 TemplateClone = """
333
334peano4::grid::TraversalObserver* {{FULL_QUALIFIED_CLASSNAME}}::clone(int spacetreeId) {
335 return new {{CLASSNAME}}(spacetreeId);
336}
337
338 """
339
340 TemplateBeginTraversal = """
341
342void {{FULL_QUALIFIED_CLASSNAME}}::beginTraversal( const tarch::la::Vector<Dimensions,double>& x, const tarch::la::Vector<Dimensions,double>& h ) {
343 logTraceInWith2Arguments( "beginTraversal(...)", x, h );
344 //
345 // Invoke beginTraversal() on the actions
346 //
347{{MAPPING_BEGIN_TRAVERSAL_CALLS}}
348
349 //
350 // Fill call stacks with dummies which represent level 0 such that we can
351 // call standard action routines on level 1 with parents. Without these
352 // statements, a top(1) call would raise an assertion.
353 //
354{{INITIAL_PUSH_TO_OUTPUT_STREAMS}}
355 logTraceOutWith2Arguments( "beginTraversal(...)", x, h );
356}
357
358 """
359
360 def __generate_beginTraversal(self, output_file):
361 self.d["MAPPING_BEGIN_TRAVERSAL_CALLS"] = ""
362 for action in self.included_actions:
363 self.d["MAPPING_BEGIN_TRAVERSAL_CALLS"] += " _actionSet"
364 self.d["MAPPING_BEGIN_TRAVERSAL_CALLS"] += str(
365 self.included_actions.index(action)
366 )
367 self.d["MAPPING_BEGIN_TRAVERSAL_CALLS"] += ".beginTraversal();\n"
368
369 self.d["INITIAL_PUSH_TO_OUTPUT_STREAMS"] = ""
370 for cell in self.cells:
371 self.d["INITIAL_PUSH_TO_OUTPUT_STREAMS"] += (
372 " " +
373 cell.subnamespace +
374 "repositories::DataRepository::_"
375 + cell.get_logical_type_name()
376 + "Stack.getForPush( " +
377 cell.subnamespace +
378 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->push( "
379 + cell.get_full_qualified_type()
380 + "() );\n"
381 )
382 pass
383
384 for face in self.faces:
385 self.d[
386 "INITIAL_PUSH_TO_OUTPUT_STREAMS"
387 ] += " for (int i=0; i<TwoTimesD; i++) {\n"
388 self.d["INITIAL_PUSH_TO_OUTPUT_STREAMS"] += (
389 " " +
390 face.subnamespace +
391 "repositories::DataRepository::_"
392 + face.get_logical_type_name()
393 + "Stack.getForPush( " +
394 face.subnamespace +
395 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->push( "
396 + face.get_full_qualified_type()
397 + "() );\n"
398 )
399 self.d["INITIAL_PUSH_TO_OUTPUT_STREAMS"] += " }\n"
400 pass
401
402 for vertex in self.vertices:
403 self.d[
404 "INITIAL_PUSH_TO_OUTPUT_STREAMS"
405 ] += " for (int i=0; i<TwoPowerD; i++) {\n"
406 self.d["INITIAL_PUSH_TO_OUTPUT_STREAMS"] += (
407 " " +
408 vertex.subnamespace +
409 "repositories::DataRepository::_"
410 + vertex.get_logical_type_name()
411 + "Stack.getForPush( " +
412 vertex.subnamespace +
413 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->push( "
414 + vertex.get_full_qualified_type()
415 + "() );\n"
416 )
417 self.d["INITIAL_PUSH_TO_OUTPUT_STREAMS"] += " }\n"
418 pass
419
420 output_file.write(jinja2.Template(self.TemplateBeginTraversalTemplateBeginTraversal).render(**self.d))
421
422 TemplateEndTraversal = """
423
424void {{FULL_QUALIFIED_CLASSNAME}}::endTraversal( const tarch::la::Vector<Dimensions,double>& x, const tarch::la::Vector<Dimensions,double>& h ) {
425 logTraceInWith2Arguments( "endTraversal(...)", x, h );
426 {{MAPPING_END_TRAVERSAL_CALLS}}
427 {{FINAL_POP_FROM_INPUT_STREAMS}}
428 logTraceOutWith2Arguments( "endTraversal(...)", x, h );
429}
430
431 """
432
433 def __generate_endTraversal(self, output_file):
434 self.d["MAPPING_END_TRAVERSAL_CALLS"] = ""
435 for action in self.included_actions:
436 self.d["MAPPING_END_TRAVERSAL_CALLS"] += " _actionSet"
437 self.d["MAPPING_END_TRAVERSAL_CALLS"] += str(
438 self.included_actions.index(action)
439 )
440 self.d["MAPPING_END_TRAVERSAL_CALLS"] += ".endTraversal();\n"
441
442 self.d["FINAL_POP_FROM_INPUT_STREAMS"] = ""
443 for cell in self.cells:
444 self.d["FINAL_POP_FROM_INPUT_STREAMS"] += (
445 " " +
446 cell.subnamespace +
447 "repositories::DataRepository::_"
448 + cell.get_logical_type_name()
449 + "Stack.getForPop( " +
450 cell.subnamespace +
451 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->pop();\n"
452 )
453 pass
454
455 for face in self.faces:
456 self.d[
457 "FINAL_POP_FROM_INPUT_STREAMS"
458 ] += " for (int i=0; i<TwoTimesD; i++) {\n"
459 self.d["FINAL_POP_FROM_INPUT_STREAMS"] += (
460 " " +
461 face.subnamespace +
462 "repositories::DataRepository::_"
463 + face.get_logical_type_name()
464 + "Stack.getForPop( " +
465 face.subnamespace +
466 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->pop();\n"
467 )
468 self.d["FINAL_POP_FROM_INPUT_STREAMS"] += " }\n"
469 pass
470
471 for vertex in self.vertices:
472 self.d[
473 "FINAL_POP_FROM_INPUT_STREAMS"
474 ] += " for (int i=0; i<TwoPowerD; i++) {\n"
475 self.d["FINAL_POP_FROM_INPUT_STREAMS"] += (
476 " " +
477 vertex.subnamespace +
478 "repositories::DataRepository::_"
479 + vertex.get_logical_type_name()
480 + "Stack.getForPop( " +
481 vertex.subnamespace +
482 "repositories::DataRepository::DataKey(_spacetreeId,peano4::grid::PeanoCurve::CallStack))->pop();\n"
483 )
484 self.d["FINAL_POP_FROM_INPUT_STREAMS"] += " }\n"
485 pass
486
487 output_file.write(jinja2.Template(self.TemplateEndTraversalTemplateEndTraversal).render(**self.d))
488
489 TemplatePrepareTraversal = """
490
491void {{FULL_QUALIFIED_CLASSNAME}}::prepareTraversal() {
492 logTraceIn( "prepareTraversal(...)" );
493 {{MAPPING_PREPARE_TRAVERSAL_CALLS}}
494 logTraceOut( "prepareTraversal(...)" );
495}
496
497 """
498
499 def __generate_prepareTraversal(self, output_file):
500 self.d["MAPPING_PREPARE_TRAVERSAL_CALLS"] = ""
501 for action in self.included_actions:
502 self.d["MAPPING_PREPARE_TRAVERSAL_CALLS"] += " "
503 self.d["MAPPING_PREPARE_TRAVERSAL_CALLS"] += action
504 self.d["MAPPING_PREPARE_TRAVERSAL_CALLS"] += "::prepareTraversal();\n"
505 output_file.write(
506 jinja2.Template(self.TemplatePrepareTraversalTemplatePrepareTraversal).render(**self.d)
507 )
508
509 TemplateUnprepareTraversal = """
510
511void {{FULL_QUALIFIED_CLASSNAME}}::unprepareTraversal() {
512 logTraceIn( "unprepareTraversal(...)" );
513 {{MAPPING_UNPREPARE_TRAVERSAL_CALLS}}
514 logTraceOut( "unprepareTraversal(...)" );
515}
516
517 """
518
519 def __generate_unprepareTraversal(self, output_file):
520 self.d["MAPPING_UNPREPARE_TRAVERSAL_CALLS"] = ""
521 for action in self.included_actions:
522 self.d["MAPPING_UNPREPARE_TRAVERSAL_CALLS"] += " "
523 self.d["MAPPING_UNPREPARE_TRAVERSAL_CALLS"] += action
524 self.d["MAPPING_UNPREPARE_TRAVERSAL_CALLS"] += "::unprepareTraversal();\n"
525 output_file.write(
526 jinja2.Template(self.TemplateUnprepareTraversalTemplateUnprepareTraversal).render(**self.d)
527 )
528
530 self, output_file, template, reverse_order=False, manual_dict=None
531 ):
532 """
533
534 Takes the specified template file, iterates over actions and pastes
535 the template into the output file once per action. Per action, the dictionary's
536 entries are updated. Otherwise, the dictionary remains unchanged.
537
538 @todo It is not clear what manual_dict really means, and I think it is never none. Documentation might have to be updated, too.
539
540 output_file:
541 Handle on output file
542
543 """
544 local_actions = [x for x in self.included_actions]
545 if reverse_order:
546 local_actions.reverse()
547
548 for action in local_actions:
549 if manual_dict is None:
550 self.d["ACTIVE_ACTION_SET"] = "_actionSet" + str(
551 self.included_actions.index(action)
552 )
553 self.d["ACTIVE_ACTION_SET_FULL_QUALIFIED_NAME"] = action
554 if output_file is not None:
555 output_file.write(jinja2.Template(template).render(**self.d))
556 else:
557 return jinja2.Template(template).render(**self.d)
558 else:
559 manual_dict["ACTIVE_ACTION_SET"] = "_actionSet" + str(
560 self.included_actions.index(action)
561 )
562 manual_dict["ACTIVE_ACTION_SET_FULL_QUALIFIED_NAME"] = action
563 if output_file is not None:
564 output_file.write(jinja2.Template(template).render(**manual_dict))
565 else:
566 return jinja2.Template(template).render(**manual_dict)
567
568 def __render_template_for_action(self, template, action_index, manual_dict):
569 """!
570
571 Render template for the action set with the given index, i.e. the
572 C++ code with which the observer invokes this action set's events
573
574 """
575 dictionary = self.d if manual_dict is None else manual_dict
576 dictionary["ACTIVE_ACTION_SET"] = "_actionSet" + str(action_index)
577 dictionary["ACTIVE_ACTION_SET_FULL_QUALIFIED_NAME"] = self.included_actions[action_index]
578 return jinja2.Template(template).render(**dictionary)
579
581 self, output_file, template, reverse_order=False, manual_dict=None
582 ):
583 """!
584
585 Counterpart of __format_template_per_action() which takes the task
586 groups into account
587
588 The groups are handled one after the other. A group with one action
589 set yields exactly the code of __format_template_per_action(). For a
590 group with several action sets, the code of each action set is
591 embedded into a lambda which captures everything by reference. Each
592 lambda is spawned as a task, and the code waits for all of them
593 before it continues. See the class documentation.
594
595 @param reverse_order: bool
596 Invoke the groups, and the action sets within each group, in
597 reversed order, as we do for all events of leaveCell().
598
599 """
600 groups = [list(group) for group in self.task_groups]
601 if reverse_order:
602 groups = [list(reversed(group)) for group in reversed(groups)]
603
604 for group in groups:
605 if len(group) == 1:
606 output_file.write(self.__render_template_for_action(template, group[0], manual_dict))
607 continue
608
609 code = "\n {\n"
610 code += " // Action sets " + ", ".join(str(index) for index in group) + " run in parallel\n"
611 code += " std::vector< tarch::multicore::Task* > parallelActionSets;\n"
612 for index in group:
613 code += f" std::function<void()> invokeActionSet{index} = [&]() -> void {{\n"
614 code += self.__render_template_for_action(template, index, manual_dict)
615 code += "\n };\n"
616 code += " parallelActionSets.push_back( new tarch::multicore::TaskWithoutCopyOfFunctor(\n"
617 code += " tarch::multicore::Task::DontFuse,\n"
618 code += " tarch::multicore::Task::DefaultPriority,\n"
619 code += f" invokeActionSet{index}\n"
620 code += " ));\n"
621 code += " tarch::multicore::spawnAndWait( parallelActionSets );\n"
622 code += " }\n"
623 output_file.write(code)
624
625 TemplateGetGridControlEvents_Prologue = """
626
627std::vector< peano4::grid::GridControlEvent > {{FULL_QUALIFIED_CLASSNAME}}::createGridControlEventsForNextTraversal() const {
628 std::vector< peano4::grid::GridControlEvent > result;
629"""
630
631 TemplateGetGridControlEvents_MappingCall = """
632 {
633 const std::vector< peano4::grid::GridControlEvent > actionResult = {{ACTIVE_ACTION_SET}}.createGridControlEventsForNextTraversal();
634 result.insert(result.begin(),actionResult.begin(),actionResult.end());
635 }
636"""
637
638 TemplateGetGridControlEvents_Epilogue = """
639 return result;
640}
641
642
643"""
644
646 output_file.write(
648 **{"FULL_QUALIFIED_CLASSNAME": self.d["FULL_QUALIFIED_CLASSNAME"]}
649 )
650 )
653 )
654 output_file.write(
656 )
657
658 def __generate_clone(self, output_file):
659 output_file.write(jinja2.Template(self.TemplateCloneTemplateClone).render(**self.d))
660
661 TemplateEnterCell_Prologue = """
662void {{FULL_QUALIFIED_CLASSNAME}}::enterCell( const peano4::grid::GridTraversalEvent& event ) {
663 logTraceInWith2Arguments( "enterCell(...)", _spacetreeId, event.toString() );
664
665 [[maybe_unused]] const peano4::datamanagement::CellMarker cellMarker( event );
666 [[maybe_unused]] const peano4::datamanagement::FaceMarker faceMarker( event );
667 [[maybe_unused]] const peano4::datamanagement::VertexMarker vertexMarker(event);
668"""
669
670 TemplateLoadCell_VertexLoad = r"""
671 // Load vertex {{logical_type_name}}
672 std::function<void ()> loadVertex{{logical_type_name}} =
673 [&]()->void {
674 ::peano4::datamanagement::loadVertexData<{{full_qualified_type}}>(
675 {{subnamespace}}repositories::DataRepository::_{{logical_type_name}}Stack,
676 _spacetreeId,
677 event,
678 vertexMarker,
679 "{{name}}",
680 [&](const peano4::datamanagement::VertexMarker& marker) -> ::peano4::grid::LoadStoreComputeFlag {
681 return {{full_qualified_type}}::loadStoreComputeFlag(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
682 }
683 );
684 };
685
686 tasks.push_back( new tarch::multicore::TaskWithoutCopyOfFunctor(
687 tarch::multicore::Task::DontFuse,
688 tarch::multicore::Task::DefaultPriority,
689 loadVertex{{logical_type_name}}
690 ));
691"""
692
693 TemplateEnterCell_VertexMappingCall = r"""
694 // Handle vertex {{logical_type_name}}
695 {
696 peano4::datamanagement::VertexMarker marker = vertexMarker;
697
698 for (int i=0; i<TwoPowerD; i++) {
699 int inVertexStack = event.getVertexDataFrom(i);
700 int pick = event.getVertexDataTo(i); // the vertex position
701
702 marker.select(pick);
703
704 logDebug( "enterCell(...)", inVertexStack << "->" << pick << " (is-local=" << marker.isLocal() << ")" );
705
706 if (
707 inVertexStack==peano4::grid::TraversalObserver::CreateOrDestroyPersistentGridEntity
708 and
709 marker.isLocal()
710 ) {
711 // Take care about the coarse grid accesses: Faces and cells are not yet loaded.
712 // Therefore we don't use the usual shift of 2*2d or 2*2**d (don't use LaTeX here
713 // as this is within a Python document and the Python interpreter doesn't fancy
714 // escape chars here, even though these escape chars are actually within a TeX
715 // formula) but only half of it.
716 {{ACTIVE_ACTION_SET}}.createPersistentVertex(
717 marker
718 ,{{MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY}}
719 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
720 );
721 {{ACTIVE_ACTION_SET}}.touchVertexFirstTime(
722 marker
723 ,{{MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY}}
724 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
725 );
726 }
727 else if (
728 inVertexStack==peano4::grid::TraversalObserver::CreateOrDestroyHangingGridEntity
729 and
730 marker.isLocal()
731 ) {
732 {{ACTIVE_ACTION_SET}}.createHangingVertex(
733 marker
734 ,{{MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY}}
735 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
736 );
737 }
738 else if (
739 peano4::grid::PeanoCurve::isInOutStack(inVertexStack)
740 and
741 marker.isLocal()
742 ) {
743 {{ACTIVE_ACTION_SET}}.touchVertexFirstTime(
744 marker
745 ,{{MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY}}
746 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
747 );
748 }
749 }
750 }
751"""
752
753 TemplateLoadCell_FaceLoad = r"""
754 // Load face {{logical_type_name}}
755 std::function<void ()> loadFace{{logical_type_name}} =
756 [&]()->void {
757 ::peano4::datamanagement::loadFaceData<{{full_qualified_type}}>(
758 {{subnamespace}}repositories::DataRepository::_{{logical_type_name}}Stack,
759 _spacetreeId,
760 event,
761 faceMarker,
762 "{{name}}",
763 [&](const peano4::datamanagement::FaceMarker& marker) -> ::peano4::grid::LoadStoreComputeFlag {
764 return {{full_qualified_type}}::loadStoreComputeFlag(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
765 }
766 );
767 };
768
769 tasks.push_back( new tarch::multicore::TaskWithoutCopyOfFunctor(
770 tarch::multicore::Task::DontFuse,
771 tarch::multicore::Task::DefaultPriority,
772 loadFace{{logical_type_name}}
773 ));
774"""
775
776 TemplateEnterCell_FaceMappingCall = r"""
777 // Handle face {{logical_type_name}}
778 {
779 peano4::datamanagement::FaceMarker marker = faceMarker;
780
781 for (int i=0; i<TwoTimesD; i++) {
782 int inFaceStack = event.getFaceDataFrom(i);
783 int pick = event.getFaceDataTo(i);
784
785 marker.select(pick);
786
787 assertion4(
788 marker.isLocal() or not event.getIsCellLocal(),
789 marker.toString(),
790 event.toString(),
791 i,
792 _spacetreeId
793 );
794
795 if (
796 inFaceStack==peano4::grid::TraversalObserver::CreateOrDestroyPersistentGridEntity
797 and
798 marker.isLocal()
799 ) {
800 {{ACTIVE_ACTION_SET}}.createPersistentFace(
801 marker
802 {{_COMMA_MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS}}
803 ,{{MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_PICK_ENTRY}}
804 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
805 );
806 {{ACTIVE_ACTION_SET}}.touchFaceFirstTime(
807 marker
808 {{_COMMA_MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS}}
809 ,{{MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_PICK_ENTRY}}
810 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
811 );
812 }
813 else if (
814 inFaceStack==peano4::grid::TraversalObserver::CreateOrDestroyHangingGridEntity
815 and
816 marker.isLocal()
817 ) {
818 {{ACTIVE_ACTION_SET}}.createHangingFace(
819 marker
820 {{_COMMA_MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS}}
821 ,{{MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_PICK_ENTRY}}
822 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
823 );
824 }
825 else if (
826 peano4::grid::PeanoCurve::isInOutStack(inFaceStack)
827 and
828 marker.isLocal()
829 ) {
830 {{ACTIVE_ACTION_SET}}.touchFaceFirstTime(
831 marker
832 {{_COMMA_MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS}}
833 ,{{MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_PICK_ENTRY}}
834 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
835 );
836 }
837 }
838 }
839"""
840
841 TemplateLoadCell_CellLoad = r"""
842 // Load cell {{logical_type_name}}
843 std::function<void ()> loadCell{{logical_type_name}} =
844 [&]()->void {
845 ::peano4::datamanagement::loadCellData<{{full_qualified_type}}>(
846 {{subnamespace}}repositories::DataRepository::_{{logical_type_name}}Stack,
847 _spacetreeId,
848 event,
849 cellMarker,
850 "{{name}}",
851 [&](const peano4::datamanagement::CellMarker& marker) -> ::peano4::grid::LoadStoreComputeFlag {
852 return {{full_qualified_type}}::loadStoreComputeFlag(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
853 }
854 );
855 };
856
857 tasks.push_back( new tarch::multicore::TaskWithoutCopyOfFunctor(
858 tarch::multicore::Task::DontFuse,
859 tarch::multicore::Task::DefaultPriority,
860 loadCell{{logical_type_name}}
861 ));
862"""
863
864 TemplateEnterCell_CellMappingCall = r"""
865 // Invoke creational events on cell {{logical_type_name}}
866 {
867 peano4::datamanagement::CellMarker marker = cellMarker;
868
869 if (
870 event.getCellData()==peano4::grid::TraversalObserver::CreateOrDestroyPersistentGridEntity
871 and
872 marker.isLocal()
873 ) {
874 {{ACTIVE_ACTION_SET}}.createCell(
875 marker,
876 {{MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_COMMA_}}
877 {{MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_COMMA_}}
878 {{MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS_PICK_ENTRY}}
879 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS}}
880 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS}}
881 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
882 );
883 }
884 }
885"""
886
887 TemplateEnterCell_MappingCall = r"""
888 {
889 peano4::datamanagement::CellMarker marker( event );
890 if (
891 marker.isLocal()
892 ) {
893 {{ACTIVE_ACTION_SET}}.touchCellFirstTime(
894 marker
895 {{_COMMA_MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS_CELL_EVENT}}
896 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS_CELL_EVENT}}
897 );
898 }
899 }
900"""
901
902 TemplateEnterCell_Epilogue = """
903 logTraceOut( "enterCell(...)" );
904}
905
906
907"""
908
909 def generateDictEntry(self, key):
910 """
911 Some logic to produce new dictionary entries from existing ones.
912 This deals mainly with having to avoid C++ code with consequtive commata
913 as some dict entries can be an empty string.
914 """
915
916 fields = key.split(",")
917 nonempty = [self.d[f] for f in fields if not f == "" and not self.d[f] == ""]
918 if len(nonempty) > 0:
919 s = ",".join(nonempty)
920 if key.startswith(",") and not s.startswith(","):
921 s = "," + s
922 if key.endswith(",") and not s.endswith(","):
923 s += ","
924 else:
925 s = ""
926
927 return s
928
929 def mkSubDict(self, keys):
930 """
931
932 Create the particular subdictionary that's used for an expression.
933
934 """
935 temp = {}
936 for k in keys:
937 if not k in self.d:
938 temp[k] = self.generateDictEntry(k)
939 else:
940 temp[k] = self.d[k]
941 result = {}
942 for k in temp:
943 result[k.replace(",", "_COMMA_").strip()] = temp[k]
944 return result
945
946 def __generate_loadCell(self, output_file):
947 output_file.write(
948 jinja2.Template(self.TemplateLoadCell_PrologueTemplateLoadCell_Prologue).render(**self.d)
949 )
950
951 for vertex in self.vertices:
952 temp = {
953 "name": vertex.name,
954 "enumeration_type": vertex.get_enumeration_type(),
955 "logical_type_name": vertex.get_logical_type_name(),
956 "full_qualified_type": vertex.get_full_qualified_type(),
957 "ADDITIONAL_LOAD_STORE_ARGUMENTS": vertex.additional_load_and_store_arguments,
958 "subnamespace": vertex.subnamespace,
959 }
960 self.d["name"] = vertex.name
961 output_file.write(
963 )
964
965 for face in self.faces:
966 temp = {
967 "name": face.name,
968 "enumeration_type": face.get_enumeration_type(),
969 "logical_type_name": face.get_logical_type_name(),
970 "full_qualified_type": face.get_full_qualified_type(),
971 "ADDITIONAL_LOAD_STORE_ARGUMENTS": face.additional_load_and_store_arguments,
972 "subnamespace": face.subnamespace,
973 }
974 self.d["name"] = face.name
975 output_file.write(
976 jinja2.Template(self.TemplateLoadCell_FaceLoadTemplateLoadCell_FaceLoad).render(**temp)
977 )
978
979 for cell in self.cells:
980 temp = {
981 "name": cell.name,
982 "logical_type_name": cell.get_logical_type_name(),
983 "full_qualified_type": cell.get_full_qualified_type(),
984 "ADDITIONAL_LOAD_STORE_ARGUMENTS": cell.additional_load_and_store_arguments,
985 "subnamespace": cell.subnamespace,
986 }
987 self.d["name"] = cell.name
988 output_file.write(
989 jinja2.Template(self.TemplateLoadCell_CellLoadTemplateLoadCell_CellLoad).render(**temp)
990 )
991
992 output_file.write(jinja2.Template(self.TemplateLoadCell_EpilogueTemplateLoadCell_Epilogue).render({}))
993
994 def __generate_enterCell(self, output_file):
995 """
996 Generates enter cell
997 """
998 output_file.write(
999 jinja2.Template(self.TemplateEnterCell_PrologueTemplateEnterCell_Prologue).render(**self.d)
1000 )
1001
1002 if len(self.vertices) > 0:
1003 md = self.mkSubDict(
1004 [
1005 "name",
1006 "MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY",
1007 ",MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS,MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS,MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS",
1008 ]
1009 )
1011 output_file,
1013 False,
1014 manual_dict=md,
1015 )
1016
1017 if len(self.faces) > 0:
1018 md = self.mkSubDict(
1019 [
1020 "name",
1021 "MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS",
1022 "MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_PICK_ENTRY",
1023 "MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS",
1024 "MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS",
1025 "MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS",
1026 ",MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS,MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS,MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS",
1027 ",MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS",
1028 ]
1029 )
1031 output_file,
1033 False,
1034 manual_dict=md,
1035 )
1036
1037 if len(self.cells) > 0:
1038 md = self.mkSubDict(
1039 [
1040 "name",
1041 "MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS,",
1042 "MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS,",
1043 "MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS_PICK_ENTRY",
1044 ",MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS",
1045 ",MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS",
1046 ",MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS",
1047 ]
1048 )
1050 output_file,
1052 False,
1053 manual_dict=md,
1054 )
1055
1056 md = self.mkSubDict(
1057 [
1058 ",MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS,MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS,MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS_CELL_EVENT",
1059 ",MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS,MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS,MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS_CELL_EVENT",
1060 ]
1061 )
1062
1064 output_file, self.TemplateEnterCell_MappingCallTemplateEnterCell_MappingCall, False, manual_dict=md
1065 )
1066 output_file.write(jinja2.Template(self.TemplateEnterCell_EpilogueTemplateEnterCell_Epilogue).render({}))
1067
1068 TemplateLoadCell_Prologue = """
1069void {{FULL_QUALIFIED_CLASSNAME}}::loadCell( const peano4::grid::GridTraversalEvent& event ) {
1070 logTraceInWith2Arguments( "loadCell(...)", _spacetreeId, event.toString() );
1071
1072 [[maybe_unused]] const peano4::datamanagement::CellMarker cellMarker( event );
1073 [[maybe_unused]] const peano4::datamanagement::FaceMarker faceMarker( event );
1074 [[maybe_unused]] const peano4::datamanagement::VertexMarker vertexMarker(event);
1075
1076 std::vector< tarch::multicore::Task* > tasks;
1077"""
1078
1079 TemplateStoreCell_Prologue = """
1080void {{FULL_QUALIFIED_CLASSNAME}}::storeCell( const peano4::grid::GridTraversalEvent& event ) {
1081 logTraceInWith2Arguments( "storeCell(...)", _spacetreeId, event.toString() );
1082
1083 [[maybe_unused]] const peano4::datamanagement::CellMarker cellMarker( event );
1084 [[maybe_unused]] const peano4::datamanagement::FaceMarker faceMarker( event );
1085 [[maybe_unused]] const peano4::datamanagement::VertexMarker vertexMarker(event);
1086
1087 std::vector< tarch::multicore::Task* > tasks;
1088"""
1089
1090 TemplateLeaveCell_Prologue = """
1091void {{FULL_QUALIFIED_CLASSNAME}}::leaveCell( const peano4::grid::GridTraversalEvent& event ) {
1092 logTraceInWith2Arguments( "leaveCell(...)", _spacetreeId, event.toString() );
1093
1094 [[maybe_unused]] const peano4::datamanagement::CellMarker cellMarker( event );
1095 [[maybe_unused]] const peano4::datamanagement::FaceMarker faceMarker( event );
1096 [[maybe_unused]] const peano4::datamanagement::VertexMarker vertexMarker(event);
1097"""
1098
1099 TemplateLeaveCell_MappingCall = """
1100 {
1101 peano4::datamanagement::CellMarker marker = cellMarker;
1102
1103 if (
1104 marker.isLocal()
1105 ) {
1106 {{ACTIVE_ACTION_SET}}.touchCellLastTime(
1107 marker
1108 {{_COMMA_MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS_CELL_EVENT}}
1109 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS_CELL_EVENT}}
1110 );
1111 }
1112 }
1113"""
1114
1115 TemplateLeaveCell_CellStore_MappingCall = """
1116 {
1117 peano4::datamanagement::CellMarker marker = cellMarker;
1118
1119 if (
1120 event.getCellData()==peano4::grid::TraversalObserver::CreateOrDestroyPersistentGridEntity
1121 and
1122 marker.isLocal()
1123 ) {
1124 {{ACTIVE_ACTION_SET}}.destroyCell(
1125 marker
1126 {{_COMMA_MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS}}
1127 ,{{MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS_PICK_ENTRY}}
1128 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
1129 );
1130 }
1131 }
1132"""
1133
1134 TemplateStoreCell_CellStore = """
1135 // Store cell {{logical_type_name}}
1136 std::function<void ()> storeCell{{logical_type_name}} =
1137 [&]()->void {
1138 ::peano4::datamanagement::storeCellData<{{full_qualified_type}}>(
1139 {{subnamespace}}repositories::DataRepository::_{{logical_type_name}}Stack,
1140 _spacetreeId,
1141 event,
1142 cellMarker,
1143 "{{name}}",
1144 [&](const peano4::datamanagement::CellMarker& marker) -> ::peano4::grid::LoadStoreComputeFlag {
1145 return {{full_qualified_type}}::loadStoreComputeFlag(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
1146 }
1147 );
1148 };
1149
1150 tasks.push_back( new tarch::multicore::TaskWithoutCopyOfFunctor(
1151 tarch::multicore::Task::DontFuse,
1152 tarch::multicore::Task::DefaultPriority,
1153 storeCell{{logical_type_name}}
1154 ));
1155"""
1156
1157 TemplateLeaveCell_FaceStore_MappingCall = """
1158 // Handle face {{logical_type_name}}
1159 {
1160 peano4::datamanagement::FaceMarker marker = faceMarker;
1161
1162 for (int i=0; i<TwoTimesD; i++) {
1163 int outFaceStack = event.getFaceDataTo(i);
1164 int pick = event.getFaceDataFrom(i);
1165
1166 marker.select(pick);
1167
1168 if (
1169 outFaceStack==peano4::grid::TraversalObserver::CreateOrDestroyPersistentGridEntity
1170 and
1171 marker.isLocal()
1172 ) {
1173 {{ACTIVE_ACTION_SET}}.touchFaceLastTime(
1174 marker
1175 {{_COMMA_MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS}}
1176 ,{{MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_PICK_ENTRY}}
1177 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
1178 );
1179 {{ACTIVE_ACTION_SET}}.destroyPersistentFace(
1180 marker
1181 {{_COMMA_MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS}}
1182 ,{{MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_PICK_ENTRY}}
1183 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
1184 );
1185 }
1186 else if (
1187 outFaceStack==peano4::grid::TraversalObserver::CreateOrDestroyHangingGridEntity
1188 and
1189 marker.isLocal()
1190 ) {
1191 {{ACTIVE_ACTION_SET}}.destroyHangingFace(
1192 marker
1193 {{_COMMA_MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS}}
1194 ,{{MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_PICK_ENTRY}}
1195 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
1196 );
1197 }
1198 else if (
1199 peano4::grid::PeanoCurve::isInOutStack(outFaceStack)
1200 and
1201 marker.isLocal()
1202 ) {
1203 {{ACTIVE_ACTION_SET}}.touchFaceLastTime(
1204 marker
1205 {{_COMMA_MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS}}
1206 ,{{MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_PICK_ENTRY}}
1207 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
1208 );
1209 }
1210 }
1211 }
1212"""
1213
1214 TemplateStoreCell_FaceStore = """
1215 // Store face {{logical_type_name}}
1216 std::function<void ()> storeFace{{logical_type_name}} =
1217 [&]()->void {
1218 ::peano4::datamanagement::storeFaceData<{{full_qualified_type}}>(
1219 {{subnamespace}}repositories::DataRepository::_{{logical_type_name}}Stack,
1220 _spacetreeId,
1221 event,
1222 faceMarker,
1223 "{{name}}",
1224 [&](const peano4::datamanagement::FaceMarker& marker) -> ::peano4::grid::LoadStoreComputeFlag {
1225 return {{full_qualified_type}}::loadStoreComputeFlag(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
1226 }
1227 );
1228 };
1229
1230 tasks.push_back( new tarch::multicore::TaskWithoutCopyOfFunctor(
1231 tarch::multicore::Task::DontFuse,
1232 tarch::multicore::Task::DefaultPriority,
1233 storeFace{{logical_type_name}}
1234 ));
1235"""
1236
1237 TemplateLeaveCell_VertexStore_MappingCall = """
1238 // Handle vertex {{logical_type_name}}
1239 {
1240 peano4::datamanagement::VertexMarker marker = vertexMarker;
1241
1242 for (int i=0; i<TwoPowerD; i++) {
1243 int outVertexStack = event.getVertexDataTo(i);
1244 int pick = event.getVertexDataFrom(i);
1245
1246 marker.select(pick);
1247
1248 if (
1249 outVertexStack==peano4::grid::TraversalObserver::CreateOrDestroyPersistentGridEntity
1250 and
1251 marker.isLocal()
1252 ) {
1253 {{ACTIVE_ACTION_SET}}.touchVertexLastTime(
1254 marker
1255 ,{{MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY}}
1256 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
1257 );
1258 {{ACTIVE_ACTION_SET}}.destroyPersistentVertex(
1259 marker
1260 ,{{MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY}}
1261 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
1262 );
1263 }
1264 else if (
1265 outVertexStack==peano4::grid::TraversalObserver::CreateOrDestroyHangingGridEntity
1266 and
1267 marker.isLocal()
1268 ) {
1269 {{ACTIVE_ACTION_SET}}.destroyHangingVertex(
1270 marker
1271 ,{{MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY}}
1272 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
1273 );
1274 }
1275 else if (
1276 peano4::grid::PeanoCurve::isInOutStack(outVertexStack)
1277 and
1278 marker.isLocal()
1279 ) {
1280 {{ACTIVE_ACTION_SET}}.touchVertexLastTime(
1281 marker
1282 ,{{MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY}}
1283 {{_COMMA_MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS_COMMA_MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS}}
1284 );
1285 }
1286 }
1287 }
1288"""
1289
1290 TemplateStoreCell_VertexStore = """
1291 // Store vertex {{logical_type_name}}
1292 std::function<void ()> storeVertex{{logical_type_name}} =
1293 [&]()->void {
1294 ::peano4::datamanagement::storeVertexData<{{full_qualified_type}}>(
1295 {{subnamespace}}repositories::DataRepository::_{{logical_type_name}}Stack,
1296 _spacetreeId,
1297 event,
1298 vertexMarker,
1299 "{{name}}",
1300 [&](const peano4::datamanagement::VertexMarker& marker) -> ::peano4::grid::LoadStoreComputeFlag {
1301 return {{full_qualified_type}}::loadStoreComputeFlag(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
1302 }
1303 );
1304 };
1305
1306 tasks.push_back( new tarch::multicore::TaskWithoutCopyOfFunctor(
1307 tarch::multicore::Task::DontFuse,
1308 tarch::multicore::Task::DefaultPriority,
1309 storeVertex{{logical_type_name}}
1310 ));
1311"""
1312
1313 TemplateLeaveCell_Epilogue = """
1314 logTraceOutWith1Argument( "leaveCell(...)", _spacetreeId );
1315}
1316
1317
1318"""
1319
1320 TemplateLoadCell_Epilogue = """
1321 tarch::multicore::spawnAndWait(tasks);
1322 logTraceOutWith1Argument( "loadCell(...)", _spacetreeId );
1323}
1324
1325
1326"""
1327
1328 TemplateStoreCell_Epilogue = """
1329 tarch::multicore::spawnAndWait( tasks );
1330 logTraceOutWith1Argument( "storeCell(...)", _spacetreeId );
1331}
1332
1333
1334"""
1335
1336 def __generate_leaveCell(self, output_file):
1337 """
1338 Generates enter cell
1339 """
1340 output_file.write(
1342 **self.mkSubDict(["FULL_QUALIFIED_CLASSNAME"])
1343 )
1344 )
1345
1346 md = self.mkSubDict(
1347 [
1348 ",MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS,MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS,MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS_CELL_EVENT",
1349 ",MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS,MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS,MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS_CELL_EVENT",
1350 ]
1351 )
1354 )
1355
1356 if len(self.cells) > 0:
1357 md = self.mkSubDict(
1358 [
1359 ",MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS,MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS",
1360 "MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS_PICK_ENTRY",
1361 ",MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS,MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS,MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS",
1362 ]
1363 )
1365 output_file,
1367 True,
1368 manual_dict=md,
1369 )
1370
1371 if len(self.faces) > 0:
1372 md = self.mkSubDict(
1373 [
1374 "name",
1375 ",MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS",
1376 "MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_PICK_ENTRY",
1377 ",MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS,MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS,MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS",
1378 ",MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS",
1379 "MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS_PICK_ENTRY",
1380 ",MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS,MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS,MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS",
1381 ]
1382 )
1384 output_file,
1386 True,
1387 manual_dict=md,
1388 )
1389
1390 if len(self.vertices) > 0:
1391 md = self.mkSubDict(
1392 [
1393 "name",
1394 "MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY",
1395 ",MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS,MAPPING_SIGNATURE_FINE_GRID_FACES_ARGUMENTS,MAPPING_SIGNATURE_FINE_GRID_CELL_ARGUMENTS",
1396 ",MAPPING_SIGNATURE_COARSE_GRID_VERTICES_ARGUMENTS,MAPPING_SIGNATURE_COARSE_GRID_FACES_ARGUMENTS,MAPPING_SIGNATURE_COARSE_GRID_CELL_ARGUMENTS",
1397 "MAPPING_SIGNATURE_FINE_GRID_VERTICES_ARGUMENTS_PICK_ENTRY",
1398 ]
1399 )
1401 output_file,
1403 True,
1404 manual_dict=md,
1405 )
1406
1407 output_file.write(jinja2.Template(self.TemplateLeaveCell_EpilogueTemplateLeaveCell_Epilogue).render({}))
1408
1409 def __generate_storeCell(self, output_file):
1410 output_file.write(
1411 jinja2.Template(self.TemplateStoreCell_PrologueTemplateStoreCell_Prologue).render(**self.d)
1412 )
1413
1414 cells_inverted = [x for x in self.cells]
1415 faces_inverted = [x for x in self.faces]
1416 vertices_inverted = [x for x in self.vertices]
1417
1418 cells_inverted.reverse()
1419 faces_inverted.reverse()
1420 vertices_inverted.reverse()
1421
1422 for cell in cells_inverted:
1423 temp = {
1424 "name": cell.name,
1425 "logical_type_name": cell.get_logical_type_name(),
1426 "full_qualified_type": cell.get_full_qualified_type(),
1427 "ADDITIONAL_LOAD_STORE_ARGUMENTS": cell.additional_load_and_store_arguments,
1428 "subnamespace": cell.subnamespace,
1429 }
1430 self.d["name"] = cell.name
1431 output_file.write(
1433 )
1434
1435 for face in faces_inverted:
1436 temp = {
1437 "name": face.name,
1438 "enumeration_type": face.get_enumeration_type(),
1439 "logical_type_name": face.get_logical_type_name(),
1440 "full_qualified_type": face.get_full_qualified_type(),
1441 "ADDITIONAL_LOAD_STORE_ARGUMENTS": face.additional_load_and_store_arguments,
1442 "subnamespace": face.subnamespace,
1443 }
1444 self.d["name"] = face.name
1445 output_file.write(
1447 )
1448
1449 for vertex in vertices_inverted:
1450 temp = {
1451 "name": vertex.name,
1452 "enumeration_type": vertex.get_enumeration_type(),
1453 "logical_type_name": vertex.get_logical_type_name(),
1454 "full_qualified_type": vertex.get_full_qualified_type(),
1455 "ADDITIONAL_LOAD_STORE_ARGUMENTS": vertex.additional_load_and_store_arguments,
1456 "subnamespace": vertex.subnamespace,
1457 }
1458 self.d["name"] = vertex.name
1459 output_file.write(
1461 )
1462
1463 output_file.write(jinja2.Template(self.TemplateStoreCell_EpilogueTemplateStoreCell_Epilogue).render({}))
1464
1465 TemplateExchangeRoutines_exchangeAllVerticalDataExchangeStacks_Prologue = """
1466void {{FULL_QUALIFIED_CLASSNAME}}::exchangeAllVerticalDataExchangeStacks( int masterId ) {
1467 logTraceInWith2Arguments( "exchangeAllVerticalDataExchangeStacks(...)", masterId, _spacetreeId );
1468"""
1469
1470 TemplateExchangeRoutines_exchangeAllVerticalDataExchangeStacks_Exchange = """
1471 peano4::parallel::SpacetreeSet::exchangeAllVerticalDataExchangeStacks(
1472 {{DATASET}},
1473 _spacetreeId,
1474 masterId
1475 );
1476"""
1477
1478 TemplateExchangeRoutines_exchangeAllVerticalDataExchangeStacks_Epilogue = """
1479 logTraceOut( "exchangeAllVerticalDataExchangeStacks(...)" );
1480}
1481
1482
1483"""
1484
1485 TemplateExchangeRoutines_exchangeAllHorizontalDataExchangeStacks_Prologue = """
1486void {{FULL_QUALIFIED_CLASSNAME}}::exchangeAllHorizontalDataExchangeStacks( bool symmetricDataCardinality ) {
1487 logTraceInWith2Arguments( "exchangeAllHorizontalDataExchangeStacks(...)", symmetricDataCardinality, _spacetreeId );
1488"""
1489
1490 TemplateExchangeRoutines_exchangeAllHorizontalDataExchangeStacks_Exchange = """
1491 peano4::parallel::SpacetreeSet::exchangeAllHorizontalDataExchangeStacks(
1492 {{DATASET}},
1493 _spacetreeId,
1494 symmetricDataCardinality
1495 );
1496"""
1497
1498 TemplateExchangeRoutines_exchangeAllHorizontalDataExchangeStacks_Epilogue = """
1499 logTraceOut( "exchangeAllHorizontalDataExchangeStacks(...)" );
1500}
1501
1502
1503"""
1504
1505 TemplateExchangeRoutines_exchangeAllPeriodicBoundaryDataStacks_Prologue = """
1506void {{FULL_QUALIFIED_CLASSNAME}}::exchangeAllPeriodicBoundaryDataStacks() {
1507 logTraceInWith1Argument( "exchangeAllPeriodicBoundaryDataStacks()", _spacetreeId );
1508"""
1509
1510 TemplateExchangeRoutines_exchangeAllPeriodicBoundaryDataStacks_Exchange = """
1511 peano4::parallel::SpacetreeSet::exchangeAllPeriodicBoundaryDataStacks(
1512 {{DATASET}},
1513 _spacetreeId
1514 );
1515"""
1516
1517 TemplateExchangeRoutines_exchangeAllPeriodicBoundaryDataStacks_Epilogue = """
1518 logTraceOut( "exchangeAllPeriodicBoundaryDataStacks()" );
1519}
1520
1521
1522"""
1523
1524 TemplateExchangeRoutines_streamDataFromSplittingTreeToNewTree_Prologue = """
1525void {{FULL_QUALIFIED_CLASSNAME}}::streamDataFromSplittingTreeToNewTree(int newWorker) {
1526 logTraceInWith2Arguments( "streamDataFromSplittingTreeToNewTree(int)", _spacetreeId, newWorker );
1527"""
1528
1529 TemplateExchangeRoutines_streamDataFromSplittingTreeToNewTree_Exchange = """
1530 peano4::parallel::SpacetreeSet::streamDataFromSplittingTreeToNewTree(
1531 {{DATASET}},
1532 _spacetreeId,
1533 newWorker
1534 );
1535"""
1536
1537 TemplateExchangeRoutines_streamDataFromSplittingTreeToNewTree_Epilogue = """
1538 logTraceOut( "streamDataFromSplittingTreeToNewTree(int)");
1539}
1540
1541
1542"""
1543
1544 TemplateExchangeRoutines_streamDataFromJoiningTreeToMasterTree_Prologue = """
1545void {{FULL_QUALIFIED_CLASSNAME}}::streamDataFromJoiningTreeToMasterTree(int master) {
1546 logTraceInWith2Arguments( "streamDataFromJoiningTreeToMasterTree(int)", _spacetreeId, master );
1547"""
1548
1549 TemplateExchangeRoutines_streamDataFromJoiningTreeToMasterTree_Exchange = """
1550 peano4::parallel::SpacetreeSet::streamDataFromJoiningTreeToMasterTree(
1551 {{DATASET}},
1552 _spacetreeId,
1553 master
1554 );
1555"""
1556
1557 TemplateExchangeRoutines_streamDataFromJoiningTreeToMasterTree_Epilogue = """
1558 logTraceOut( "streamDataFromJoiningTreeToMasterTree(int)");
1559}
1560
1561
1562"""
1563
1564 TemplateExchangeRoutines_finishAllOutstandingSendsAndReceives_Prologue = """
1565void {{FULL_QUALIFIED_CLASSNAME}}::finishAllOutstandingSendsAndReceives() {
1566 logTraceInWith1Argument( "finishAllOutstandingSendsAndReceives()", _spacetreeId );
1567"""
1568
1569 TemplateExchangeRoutines_finishAllOutstandingSendsAndReceives_Exchange = """
1570 peano4::parallel::SpacetreeSet::finishAllOutstandingSendsAndReceives(
1571 {{DATASET}},
1572 _spacetreeId
1573 );
1574"""
1575
1576 TemplateExchangeRoutines_finishAllOutstandingSendsAndReceives_Epilogue = """
1577 logTraceOut( "finishAllOutstandingSendsAndReceives()");
1578}
1579
1580
1581"""
1582
1583 TemplateSendVertex_Prologue = """
1584void {{FULL_QUALIFIED_CLASSNAME}}::sendVertex(int position, int toStack, ::peano4::grid::TraversalObserver::SendReceiveContext context, const peano4::grid::GridTraversalEvent& event) {
1585 logTraceInWith4Arguments( "sendVertex(int,int,int)", position, toStack, event.toString(), _spacetreeId );
1586
1587 [[maybe_unused]] const peano4::datamanagement::VertexMarker vertexMarker(event);
1588"""
1589
1590 TemplateSendVertex_SendCall = """
1591 ::peano4::datamanagement::sendVertexData<{{full_qualified_type}}>(
1592 {{subnamespace}}repositories::DataRepository::_{{logical_type_name}}Stack,
1593 _spacetreeId,
1594 position,
1595 toStack,
1596 context,
1597 vertexMarker,
1598 [&](const peano4::datamanagement::VertexMarker& marker) -> ::peano4::grid::LoadStoreComputeFlag {
1599 return {{full_qualified_type}}::loadStoreComputeFlag(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
1600 },
1601 [&](const {{full_qualified_type}}& data, const peano4::datamanagement::VertexMarker& marker) -> bool {
1602 return data.send(marker);
1603 }
1604 );
1605"""
1606
1607 TemplateSendVertex_Epilogue = """
1608 logTraceOut( "sendVertex(int,int,int)");
1609}
1610
1611
1612"""
1613
1614 TemplateSendFace_Prologue = """
1615void {{FULL_QUALIFIED_CLASSNAME}}::sendFace(int position, int toStack, ::peano4::grid::TraversalObserver::SendReceiveContext context, const peano4::grid::GridTraversalEvent& event) {
1616 logTraceInWith4Arguments( "sendFace(int,int,int)", position, toStack, event.toString(), _spacetreeId );
1617
1618 [[maybe_unused]] const peano4::datamanagement::FaceMarker faceMarker( event );
1619"""
1620
1621 TemplateSendFace_SendCall = """
1622 ::peano4::datamanagement::sendFaceData<{{full_qualified_type}}>(
1623 {{subnamespace}}repositories::DataRepository::_{{logical_type_name}}Stack,
1624 _spacetreeId,
1625 position,
1626 toStack,
1627 context,
1628 faceMarker,
1629 [&](const peano4::datamanagement::FaceMarker& marker) -> ::peano4::grid::LoadStoreComputeFlag {
1630 return {{full_qualified_type}}::loadStoreComputeFlag(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
1631 },
1632 [&](const {{full_qualified_type}}& data, const peano4::datamanagement::FaceMarker& marker) -> bool {
1633 return data.send(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
1634 }
1635 );
1636"""
1637
1638 TemplateSendFace_Epilogue = """
1639 logTraceOut( "sendFace(int,int,int)");
1640}
1641
1642
1643"""
1644
1645 TemplateSendCell_Prologue = """
1646void {{FULL_QUALIFIED_CLASSNAME}}::sendCell(int toStack, ::peano4::grid::TraversalObserver::SendReceiveContext context, const peano4::grid::GridTraversalEvent& event) {
1647 logTraceInWith3Arguments( "sendCell(int,int,int)", toStack, event.toString(), _spacetreeId );
1648
1649 [[maybe_unused]] const peano4::datamanagement::CellMarker cellMarker( event );
1650"""
1651
1652 TemplateSendCell_SendCall = """
1653 ::peano4::datamanagement::sendCellData<{{full_qualified_type}}>(
1654 {{subnamespace}}repositories::DataRepository::_{{logical_type_name}}Stack,
1655 _spacetreeId,
1656 toStack,
1657 context,
1658 cellMarker,
1659 [&](const peano4::datamanagement::CellMarker& marker) -> ::peano4::grid::LoadStoreComputeFlag {
1660 return {{full_qualified_type}}::loadStoreComputeFlag(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
1661 },
1662 [&](const {{full_qualified_type}}& data, const peano4::datamanagement::CellMarker& marker) -> bool {
1663 return data.send(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
1664 }
1665 );
1666"""
1667
1668 TemplateSendCell_Epilogue = """
1669 logTraceOut( "sendCell(int,int,int)");
1670}
1671
1672
1673"""
1674
1675 TemplateReceiveAndMergeCell_Prologue = """
1676void {{FULL_QUALIFIED_CLASSNAME}}::receiveAndMergeCell(int fromStack, peano4::grid::TraversalObserver::SendReceiveContext context, const peano4::grid::GridTraversalEvent& event ) {
1677 logTraceInWith3Arguments( "receiveAndMergeCell(...)", fromStack, event.toString(), _spacetreeId );
1678
1679 [[maybe_unused]] const peano4::datamanagement::CellMarker cellMarker( event );
1680"""
1681
1682 TemplateReceiveAndMergeCell_Epilogue = """
1683 logTraceOut( "receiveAndMergeCell(...)");
1684}
1685
1686
1687"""
1688
1689 TemplateReceiveAndMergeVertex_Prologue = """
1690void {{FULL_QUALIFIED_CLASSNAME}}::receiveAndMergeVertex(int position, int fromStack, peano4::grid::TraversalObserver::SendReceiveContext context, const peano4::grid::GridTraversalEvent& event) {
1691 logTraceInWith4Arguments( "receiveAndMergeVertex(...)", position, fromStack, event.toString(), _spacetreeId );
1692
1693 [[maybe_unused]] const peano4::datamanagement::VertexMarker vertexMarker(event);
1694"""
1695
1696 TemplateReceiveAndMergeVertex_Epilogue = """
1697 logTraceOut( "receiveAndMergeVertex(...)");
1698}
1699
1700
1701"""
1702
1703 TemplateReceiveAndMergeFace_Epilogue = """
1704 logTraceOut( "receiveAndMergeFace(...)");
1705}
1706
1707
1708"""
1709
1710 TemplateReceiveAndMergeFace_Prologue = """
1711void {{FULL_QUALIFIED_CLASSNAME}}::receiveAndMergeFace(int position, int fromStack, peano4::grid::TraversalObserver::SendReceiveContext context, const peano4::grid::GridTraversalEvent& event) {
1712 logTraceInWith4Arguments( "receiveAndMergeFace(...)", position, fromStack, event.toString(), _spacetreeId );
1713
1714 [[maybe_unused]] const peano4::datamanagement::FaceMarker faceMarker( event );
1715"""
1716
1717 TemplateReceiveAndMergeVertex_ReceiveAndMergeCalls = """
1718 ::peano4::datamanagement::receiveAndMergeVertexData<{{full_qualified_type}}>(
1719 {{subnamespace}}repositories::DataRepository::_{{logical_type_name}}Stack,
1720 _spacetreeId,
1721 position,
1722 fromStack,
1723 context,
1724 event,
1725 vertexMarker,
1726 [&](const peano4::datamanagement::VertexMarker& marker) -> ::peano4::grid::LoadStoreComputeFlag {
1727 return {{full_qualified_type}}::loadStoreComputeFlag(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
1728 },
1729 [&]({{full_qualified_type}}& data, const peano4::datamanagement::VertexMarker& marker) -> bool {
1730 return data.receiveAndMerge(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
1731 }
1732 );
1733"""
1734
1735 TemplateReceiveAndMergeFace_ReceiveAndMergeCalls = """
1736 ::peano4::datamanagement::receiveAndMergeFaceData<{{full_qualified_type}}>(
1737 {{subnamespace}}repositories::DataRepository::_{{logical_type_name}}Stack,
1738 _spacetreeId,
1739 position,
1740 fromStack,
1741 context,
1742 event,
1743 faceMarker,
1744 [&](const peano4::datamanagement::FaceMarker& marker) -> ::peano4::grid::LoadStoreComputeFlag {
1745 return {{full_qualified_type}}::loadStoreComputeFlag(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
1746 },
1747 [&]({{full_qualified_type}}& data, const peano4::datamanagement::FaceMarker& marker) -> bool {
1748 return data.receiveAndMerge(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
1749 }
1750 );
1751"""
1752
1753 TemplateReceiveAndMergeCell_ReceiveAndMergeCalls = """
1754 ::peano4::datamanagement::receiveAndMergeCellData<{{full_qualified_type}}>(
1755 {{subnamespace}}repositories::DataRepository::_{{logical_type_name}}Stack,
1756 _spacetreeId,
1757 fromStack,
1758 context,
1759 event,
1760 cellMarker,
1761 [&](const peano4::datamanagement::CellMarker& marker) -> ::peano4::grid::LoadStoreComputeFlag {
1762 return {{full_qualified_type}}::loadStoreComputeFlag(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
1763 },
1764 [&]({{full_qualified_type}}& data, const peano4::datamanagement::CellMarker& marker) -> bool {
1765 return data.receiveAndMerge(marker{% for arg in ADDITIONAL_LOAD_STORE_ARGUMENTS %}, {{arg[0]}}{% endfor %});
1766 }
1767 );
1768"""
1769
1770 TemplateExchangeRoutines_deleteAllStacks_Prologue = """
1771void {{FULL_QUALIFIED_CLASSNAME}}::deleteAllStacks() {
1772 logTraceInWith1Argument( "deleteAllStacks()", _spacetreeId );
1773"""
1774
1775 TemplateExchangeRoutines_deleteAllStacks_Exchange = """
1776 peano4::parallel::SpacetreeSet::deleteAllStacks(
1777 {{DATASET}},
1778 _spacetreeId
1779 );
1780"""
1781
1782 TemplateExchangeRoutines_deleteAllStacks_Epilogue = """
1783 logTraceOut( "deleteAllStacks()");
1784}
1785
1786
1787"""
1788
1789 def __generate_exchange_routines(self, output_file):
1790 s = ""
1791
1792 generic_dict_for_prologue_and_epilogue = {
1793 "FULL_QUALIFIED_CLASSNAME": self.d["FULL_QUALIFIED_CLASSNAME"]
1794 }
1795
1796 s += jinja2.Template(
1798 ).render(**generic_dict_for_prologue_and_epilogue)
1799 for cell in self.cells:
1800 s += jinja2.Template(
1802 ).render(
1803 **{
1804 "DATASET": cell.subnamespace + "repositories::DataRepository::_"
1805 + cell.get_logical_type_name()
1806 + "Stack"
1807 }
1808 )
1809 for face in self.faces:
1810 s += jinja2.Template(
1812 ).render(
1813 **{
1814 "DATASET": face.subnamespace + "repositories::DataRepository::_"
1815 + face.get_logical_type_name()
1816 + "Stack"
1817 }
1818 )
1819 for vertex in self.vertices:
1820 s += jinja2.Template(
1822 ).render(
1823 **{
1824 "DATASET": vertex.subnamespace + "repositories::DataRepository::_"
1825 + vertex.get_logical_type_name()
1826 + "Stack"
1827 }
1828 )
1829 s += jinja2.Template(
1831 ).render({})
1832
1833 s += jinja2.Template(
1835 ).render(**generic_dict_for_prologue_and_epilogue)
1836 for cell in self.cells:
1837 s += jinja2.Template(
1839 ).render(
1840 **{
1841 "DATASET": cell.subnamespace + "repositories::DataRepository::_"
1842 + cell.get_logical_type_name()
1843 + "Stack"
1844 }
1845 )
1846 for face in self.faces:
1847 s += jinja2.Template(
1849 ).render(
1850 **{
1851 "DATASET": face.subnamespace + "repositories::DataRepository::_"
1852 + face.get_logical_type_name()
1853 + "Stack"
1854 }
1855 )
1856 for vertex in self.vertices:
1857 s += jinja2.Template(
1859 ).render(
1860 **{
1861 "DATASET": vertex.subnamespace + "repositories::DataRepository::_"
1862 + vertex.get_logical_type_name()
1863 + "Stack"
1864 }
1865 )
1866 s += jinja2.Template(
1868 ).render({})
1869
1870 s += jinja2.Template(
1872 ).render(**generic_dict_for_prologue_and_epilogue)
1873 for cell in self.cells:
1874 s += jinja2.Template(
1876 ).render(
1877 **{
1878 "DATASET": cell.subnamespace + "repositories::DataRepository::_"
1879 + cell.get_logical_type_name()
1880 + "Stack"
1881 }
1882 )
1883 for face in self.faces:
1884 s += jinja2.Template(
1886 ).render(
1887 **{
1888 "DATASET": face.subnamespace + "repositories::DataRepository::_"
1889 + face.get_logical_type_name()
1890 + "Stack"
1891 }
1892 )
1893 for vertex in self.vertices:
1894 s += jinja2.Template(
1896 ).render(
1897 **{
1898 "DATASET": vertex.subnamespace + "repositories::DataRepository::_"
1899 + vertex.get_logical_type_name()
1900 + "Stack"
1901 }
1902 )
1903 s += jinja2.Template(
1905 ).render({})
1906
1907 s += jinja2.Template(
1909 ).render(**generic_dict_for_prologue_and_epilogue)
1910 for cell in self.cells:
1911 s += jinja2.Template(
1913 ).render(
1914 **{
1915 "DATASET": cell.subnamespace + "repositories::DataRepository::_"
1916 + cell.get_logical_type_name()
1917 + "Stack"
1918 }
1919 )
1920 for face in self.faces:
1921 s += jinja2.Template(
1923 ).render(
1924 **{
1925 "DATASET": face.subnamespace + "repositories::DataRepository::_"
1926 + face.get_logical_type_name()
1927 + "Stack"
1928 }
1929 )
1930 for vertex in self.vertices:
1931 s += jinja2.Template(
1933 ).render(
1934 **{
1935 "DATASET": vertex.subnamespace + "repositories::DataRepository::_"
1936 + vertex.get_logical_type_name()
1937 + "Stack"
1938 }
1939 )
1940 s += jinja2.Template(
1942 ).render({})
1943
1944 s += jinja2.Template(
1946 ).render(**generic_dict_for_prologue_and_epilogue)
1947 for cell in self.cells:
1948 s += jinja2.Template(
1950 ).render(
1951 **{
1952 "DATASET": cell.subnamespace + "repositories::DataRepository::_"
1953 + cell.get_logical_type_name()
1954 + "Stack"
1955 }
1956 )
1957 for face in self.faces:
1958 s += jinja2.Template(
1960 ).render(
1961 **{
1962 "DATASET": face.subnamespace + "repositories::DataRepository::_"
1963 + face.get_logical_type_name()
1964 + "Stack"
1965 }
1966 )
1967 for vertex in self.vertices:
1968 s += jinja2.Template(
1970 ).render(
1971 **{
1972 "DATASET": vertex.subnamespace + "repositories::DataRepository::_"
1973 + vertex.get_logical_type_name()
1974 + "Stack"
1975 }
1976 )
1977 s += jinja2.Template(
1979 ).render({})
1980
1981 s += jinja2.Template(
1983 ).render(**generic_dict_for_prologue_and_epilogue)
1984 for cell in self.cells:
1985 s += jinja2.Template(
1987 ).render(
1988 **{
1989 "DATASET": cell.subnamespace + "repositories::DataRepository::_"
1990 + cell.get_logical_type_name()
1991 + "Stack"
1992 }
1993 )
1994 for face in self.faces:
1995 s += jinja2.Template(
1997 ).render(
1998 **{
1999 "DATASET": face.subnamespace + "repositories::DataRepository::_"
2000 + face.get_logical_type_name()
2001 + "Stack"
2002 }
2003 )
2004 for vertex in self.vertices:
2005 s += jinja2.Template(
2007 ).render(
2008 **{
2009 "DATASET": vertex.subnamespace + "repositories::DataRepository::_"
2010 + vertex.get_logical_type_name()
2011 + "Stack"
2012 }
2013 )
2014 s += jinja2.Template(
2016 ).render({})
2017
2018 s += jinja2.Template(self.TemplateSendVertex_Prologue).render(
2019 **generic_dict_for_prologue_and_epilogue
2020 )
2021 for vertex in self.vertices:
2022 temp = {
2023 "name": vertex.name,
2024 "enumeration_type": vertex.get_enumeration_type(),
2025 "logical_type_name": vertex.get_logical_type_name(),
2026 "full_qualified_type": vertex.get_full_qualified_type(),
2027 "FULL_QUALIFIED_CLASSNAME": self.d["FULL_QUALIFIED_CLASSNAME"],
2028 "ADDITIONAL_LOAD_STORE_ARGUMENTS": vertex.additional_load_and_store_arguments,
2029 "subnamespace": vertex.subnamespace,
2030 }
2031 s += jinja2.Template(self.TemplateSendVertex_SendCall).render(**temp)
2032 s += jinja2.Template(self.TemplateSendVertex_Epilogue).render(
2033 **generic_dict_for_prologue_and_epilogue
2034 )
2035
2036 s += jinja2.Template(self.TemplateSendFace_Prologue).render(
2037 **generic_dict_for_prologue_and_epilogue
2038 )
2039 for face in self.faces:
2040 temp = {
2041 "name": face.name,
2042 "enumeration_type": face.get_enumeration_type(),
2043 "logical_type_name": face.get_logical_type_name(),
2044 "full_qualified_type": face.get_full_qualified_type(),
2045 "FULL_QUALIFIED_CLASSNAME": self.d["FULL_QUALIFIED_CLASSNAME"],
2046 "ADDITIONAL_LOAD_STORE_ARGUMENTS": face.additional_load_and_store_arguments,
2047 "subnamespace": face.subnamespace,
2048 }
2049 s += jinja2.Template(self.TemplateSendFace_SendCall).render(**temp)
2050 s += jinja2.Template(self.TemplateSendFace_Epilogue).render(
2051 **generic_dict_for_prologue_and_epilogue
2052 )
2053
2054 s += jinja2.Template(self.TemplateSendCell_Prologue).render(
2055 **generic_dict_for_prologue_and_epilogue
2056 )
2057 for cell in self.cells:
2058 temp = {
2059 "name": cell.name,
2060 "logical_type_name": cell.get_logical_type_name(),
2061 "full_qualified_type": cell.get_full_qualified_type(),
2062 "FULL_QUALIFIED_CLASSNAME": self.d["FULL_QUALIFIED_CLASSNAME"],
2063 "ADDITIONAL_LOAD_STORE_ARGUMENTS": cell.additional_load_and_store_arguments,
2064 "subnamespace": cell.subnamespace,
2065 }
2066 s += jinja2.Template(self.TemplateSendCell_SendCall).render(**temp)
2067 s += jinja2.Template(self.TemplateSendCell_Epilogue).render(
2068 **generic_dict_for_prologue_and_epilogue
2069 )
2070
2071 s += jinja2.Template(self.TemplateReceiveAndMergeCell_Prologue).render(
2072 **generic_dict_for_prologue_and_epilogue
2073 )
2074 for cell in self.cells:
2075 temp = {
2076 "name": cell.name,
2077 "logical_type_name": cell.get_logical_type_name(),
2078 "full_qualified_type": cell.get_full_qualified_type(),
2079 "FULL_QUALIFIED_CLASSNAME": self.d["FULL_QUALIFIED_CLASSNAME"],
2080 "ADDITIONAL_LOAD_STORE_ARGUMENTS": cell.additional_load_and_store_arguments,
2081 "subnamespace": cell.subnamespace,
2082 }
2083 s += jinja2.Template(
2085 ).render(**temp)
2086 s += jinja2.Template(self.TemplateReceiveAndMergeCell_Epilogue).render(
2087 **generic_dict_for_prologue_and_epilogue
2088 )
2089
2090 s += jinja2.Template(self.TemplateReceiveAndMergeFace_Prologue).render(
2091 **generic_dict_for_prologue_and_epilogue
2092 )
2093 for face in self.faces:
2094 temp = {
2095 "name": face.name,
2096 "enumeration_type": face.get_enumeration_type(),
2097 "logical_type_name": face.get_logical_type_name(),
2098 "full_qualified_type": face.get_full_qualified_type(),
2099 "FULL_QUALIFIED_CLASSNAME": self.d["FULL_QUALIFIED_CLASSNAME"],
2100 "ADDITIONAL_LOAD_STORE_ARGUMENTS": face.additional_load_and_store_arguments,
2101 "subnamespace": face.subnamespace,
2102 }
2103 s += jinja2.Template(
2105 ).render(**temp)
2106 s += jinja2.Template(self.TemplateReceiveAndMergeFace_Epilogue).render(
2107 **generic_dict_for_prologue_and_epilogue
2108 )
2109
2110 s += jinja2.Template(self.TemplateReceiveAndMergeVertex_Prologue).render(
2111 **generic_dict_for_prologue_and_epilogue
2112 )
2113 for vertex in self.vertices:
2114 temp = {
2115 "name": vertex.name,
2116 "enumeration_type": vertex.get_enumeration_type(),
2117 "logical_type_name": vertex.get_logical_type_name(),
2118 "full_qualified_type": vertex.get_full_qualified_type(),
2119 "FULL_QUALIFIED_CLASSNAME": self.d["FULL_QUALIFIED_CLASSNAME"],
2120 "ADDITIONAL_LOAD_STORE_ARGUMENTS": vertex.additional_load_and_store_arguments,
2121 "subnamespace": vertex.subnamespace,
2122 }
2123 s += jinja2.Template(
2125 ).render(**temp)
2126 s += jinja2.Template(self.TemplateReceiveAndMergeVertex_Epilogue).render(
2127 **generic_dict_for_prologue_and_epilogue
2128 )
2129
2130 s += jinja2.Template(
2132 ).render(**generic_dict_for_prologue_and_epilogue)
2133 for cell in self.cells:
2134 s += jinja2.Template(
2136 ).render(
2137 **{
2138 "DATASET": cell.subnamespace + "repositories::DataRepository::_"
2139 + cell.get_logical_type_name()
2140 + "Stack"
2141 }
2142 )
2143 for face in self.faces:
2144 s += jinja2.Template(
2146 ).render(
2147 **{
2148 "DATASET": face.subnamespace + "repositories::DataRepository::_"
2149 + face.get_logical_type_name()
2150 + "Stack"
2151 }
2152 )
2153 for vertex in self.vertices:
2154 s += jinja2.Template(
2156 ).render(
2157 **{
2158 "DATASET": vertex.subnamespace + "repositories::DataRepository::_"
2159 + vertex.get_logical_type_name()
2160 + "Stack"
2161 }
2162 )
2163 s += jinja2.Template(
2165 ).render(**generic_dict_for_prologue_and_epilogue)
2166
2167 output_file.write(s)
2168
2169 TemplateImplementationFilePrologue = """
2170#include "{{CLASSNAME}}.h"
2171{{DATAREPOSITORY_INCLUDES}}
2172
2173#include "peano4/grid/PeanoCurve.h"
2174
2175#include "peano4/datamanagement/VertexEnumerator.h"
2176#include "peano4/datamanagement/VertexMarker.h"
2177#include "peano4/datamanagement/FaceEnumerator.h"
2178#include "peano4/datamanagement/FaceMarker.h"
2179#include "peano4/datamanagement/CellMarker.h"
2180#include "peano4/datamanagement/VertexDataMovement.h"
2181#include "peano4/datamanagement/FaceDataMovement.h"
2182#include "peano4/datamanagement/CellDataMovement.h"
2183
2184#include "peano4/parallel/SpacetreeSet.h"
2185
2186
2187tarch::logging::Log {{FULL_QUALIFIED_CLASSNAME}}::_log( "{{FULL_QUALIFIED_CLASSNAME}}" );
2188
2189"""
2190
2191 def __generate_implementation(self, overwrite, full_qualified_filename):
2192 if write_file(overwrite, self.default_overwritedefault_overwrite, full_qualified_filename):
2193 output_file = open(full_qualified_filename, "w")
2194 output_file.write(
2196 **self.d
2197 )
2198 )
2199
2200 self.__generate_constructor(output_file)
2201 self.__generate_clone(output_file)
2203 self.__generate_beginTraversal(output_file)
2204 self.__generate_endTraversal(output_file)
2205 self.__generate_prepareTraversal(output_file)
2206 self.__generate_unprepareTraversal(output_file)
2207 self.__generate_loadCell(output_file)
2208 self.__generate_enterCell(output_file)
2209 self.__generate_leaveCell(output_file)
2210 self.__generate_storeCell(output_file)
2211 self.__generate_exchange_routines(output_file)
2212
2213 #
2214 # @todo Sollte man mit Jinja 2 nicht mehr brauchen
2215 #
2217 return self.subdirectory + "/" + self.classname + ".cpp"
2218
2219 def generate(self, overwrite, directory):
2220 if not os.path.exists(directory + "/" + self.subdirectory):
2221 os.mkdir(directory + "/" + self.subdirectory)
2222
2223 header_filename = directory + "/" + self.subdirectory + "/" + self.classname + ".h"
2224 cpp_filename = directory + "/" + self.get_cpp_file_name()
2225
2226 header_written = write_file(overwrite, self.default_overwritedefault_overwrite, header_filename)
2227 cpp_written = write_file(overwrite, self.default_overwritedefault_overwrite, cpp_filename)
2228
2229 if header_written and cpp_written:
2230 Logger().log("write " + header_filename + " and " + cpp_filename)
2231 elif header_written:
2232 Logger().log("write " + header_filename)
2233 elif cpp_written:
2234 Logger().log("write " + cpp_filename)
2235
2236 self.__generate_header(overwrite, directory)
2237 self.__generate_implementation(overwrite, cpp_filename)
Singleton logger for the Peano 4 Python API.
Definition Logger.py:37
C++ observer of one mesh traversal.
Definition Observer.py:17
__generate_loadCell(self, output_file)
Definition Observer.py:946
mkSubDict(self, keys)
Create the particular subdictionary that's used for an expression.
Definition Observer.py:929
__generate_constructor(self, output_file)
Definition Observer.py:319
str TemplateExchangeRoutines_exchangeAllHorizontalDataExchangeStacks_Prologue
Definition Observer.py:1485
__generate_prepareTraversal(self, output_file)
Definition Observer.py:499
str TemplateExchangeRoutines_exchangeAllVerticalDataExchangeStacks_Prologue
Definition Observer.py:1465
generateDictEntry(self, key)
Some logic to produce new dictionary entries from existing ones.
Definition Observer.py:909
str TemplateExchangeRoutines_exchangeAllVerticalDataExchangeStacks_Exchange
Definition Observer.py:1470
str TemplateExchangeRoutines_streamDataFromJoiningTreeToMasterTree_Exchange
Definition Observer.py:1549
str TemplateExchangeRoutines_streamDataFromJoiningTreeToMasterTree_Prologue
Definition Observer.py:1544
str TemplateExchangeRoutines_streamDataFromSplittingTreeToNewTree_Prologue
Definition Observer.py:1524
str TemplateExchangeRoutines_finishAllOutstandingSendsAndReceives_Prologue
Definition Observer.py:1564
__generate_enterCell(self, output_file)
Generates enter cell.
Definition Observer.py:994
str TemplateExchangeRoutines_exchangeAllPeriodicBoundaryDataStacks_Prologue
Definition Observer.py:1505
__render_template_for_action(self, template, action_index, manual_dict)
Render template for the action set with the given index, i.e.
Definition Observer.py:568
str TemplateExchangeRoutines_streamDataFromSplittingTreeToNewTree_Exchange
Definition Observer.py:1529
str TemplateExchangeRoutines_finishAllOutstandingSendsAndReceives_Epilogue
Definition Observer.py:1576
str TemplateExchangeRoutines_streamDataFromSplittingTreeToNewTree_Epilogue
Definition Observer.py:1537
__generate_leaveCell(self, output_file)
Generates enter cell.
Definition Observer.py:1336
str TemplateExchangeRoutines_exchangeAllPeriodicBoundaryDataStacks_Exchange
Definition Observer.py:1510
str TemplateExchangeRoutines_exchangeAllHorizontalDataExchangeStacks_Epilogue
Definition Observer.py:1498
__init__(self, classname, namespace, subdirectory, included_actions, vertices, faces, cells, task_groups=None)
Definition Observer.py:53
__format_template_per_action(self, output_file, template, reverse_order=False, manual_dict=None)
Takes the specified template file, iterates over actions and pastes the template into the output file...
Definition Observer.py:531
__generate_beginTraversal(self, output_file)
Definition Observer.py:360
__generate_createGridControlEventsForNextTraversal(self, output_file)
Definition Observer.py:645
__generate_endTraversal(self, output_file)
Definition Observer.py:433
__generate_implementation(self, overwrite, full_qualified_filename)
Definition Observer.py:2191
str TemplateExchangeRoutines_exchangeAllVerticalDataExchangeStacks_Epilogue
Definition Observer.py:1478
__format_template_per_task_group(self, output_file, template, reverse_order=False, manual_dict=None)
Counterpart of __format_template_per_action() which takes the task groups into account.
Definition Observer.py:582
__generate_header(self, overwrite, directory)
Definition Observer.py:291
str TemplateExchangeRoutines_exchangeAllPeriodicBoundaryDataStacks_Epilogue
Definition Observer.py:1517
__generate_unprepareTraversal(self, output_file)
Definition Observer.py:519
str TemplateExchangeRoutines_streamDataFromJoiningTreeToMasterTree_Epilogue
Definition Observer.py:1557
generate(self, overwrite, directory)
Definition Observer.py:2219
__generate_exchange_routines(self, output_file)
Definition Observer.py:1789
__generate_storeCell(self, output_file)
Definition Observer.py:1409
__generate_clone(self, output_file)
Definition Observer.py:658
str TemplateExchangeRoutines_finishAllOutstandingSendsAndReceives_Exchange
Definition Observer.py:1569
str TemplateExchangeRoutines_exchangeAllHorizontalDataExchangeStacks_Exchange
Definition Observer.py:1490