Peano
Loading...
Searching...
No Matches
ApplyPointWiselyToPatch.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.ActionSet import ActionSet
4
5
7 """!
8
9 Apply a C++ snippet to each entry of a cell's patch
10
11 The action set hooks into touchCellFirstTime() and runs over all
12 NxNxN entries (volumes or grid points) of the patch. For each entry, it
13 runs implementation, i.e. a C++ snippet which may use
14
15 - Q: a pointer (double*) to the patch.no_of_unknowns doubles of the
16 entry, which the snippet may read and write;
17 - x: the position (tarch::la::Vector<Dimensions,double>) of the entry,
18 i.e. the centre of the volume if we interpret the patch as N^d
19 volumes which tessellate the cell.
20
21 A typical use case is the postprocessing of a solution, e.g. the
22 enforcement of algebraic constraints or the clipping of unphysical
23 values.
24
25 As the action set plugs into touchCellFirstTime(), it runs after all
26 action sets of tasks it depends on which plug into touchCellFirstTime()
27 as well, and before all action sets plugging into touchCellLastTime()
28 such as toolbox.blockstructured.api.ProjectPatchOntoFaces, if the task
29 graph compiler fuses the tasks into one mesh traversal.
30
31 """
32
34 self,
35 patch,
36 implementation: str,
37 guard: str = "true",
38 additional_includes: str = "",
39 ):
40 """!
41
42 @param patch: peano4.api.datamodel.Patch
43 The cell's patch. It has to be a cube, i.e. have the same number of
44 entries along each axis.
45
46 @param implementation: str
47 C++ snippet that is applied to each entry, @see class
48 documentation for the variables it may use.
49
50 @param guard: str
51 C++ boolean expression. The action set only processes cells for
52 which the guard holds.
53
54 @param additional_includes: str
55 Includes that the snippet needs.
56
57 """
58 super(ApplyPointWiselyToPatch, self).__init__(
59 descend_invocation_order=1, parallel=False
60 )
61 assert patch.dim[0] == patch.dim[1], "Can only handle square patches"
62 self._patch = patch
63 self._implementation = implementation
64 self._guard = guard
65 self.additional_includes = additional_includes
66
67 @property
68 def guard(self):
69 return self._guard
70
71 @guard.setter
72 def guard(self, value):
73 self._guard = value
74
76 return ""
77
79 return ""
80
82 return " return std::vector< peano4::grid::GridControlEvent >();\n"
83
85 return __name__.replace(".py", "").replace(".", "_")
86
88 return False
89
90 def get_body_of_operation(self, operation_name):
91 if operation_name != ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
92 return "\n"
93 entries_per_axis = self._patch.dim[0]
94 unknowns = self._patch.no_of_unknowns
95 return f"""
96 const tarch::la::Vector<Dimensions, double> entryH = marker.h() / {entries_per_axis}.0;
97 dfor(entry, {entries_per_axis}) {{
98 tarch::la::Vector<Dimensions, double> x;
99 for (int d = 0; d < Dimensions; d++) {{
100 x(d) = marker.x()(d) - 0.5 * marker.h()(d) + (entry(d) + 0.5) * entryH(d);
101 }}
102 double* __restrict__ Q = fineGridCell{self._patch.name}.value + peano4::utils::dLinearised(entry, {entries_per_axis}) * {unknowns};
103 {{
104 {self._implementation}
105 }}
106 }}
107"""
108
109 def get_guard_of_operation(self, operation_name):
110 if operation_name == ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
111 return self._guard
112 return "true"
113
114 def get_attributes(self):
115 return ""
116
117 def get_includes(self):
118 return (
119 """
120#include "peano4/utils/Loop.h"
121"""
123 )
Apply a C++ snippet to each entry of a cell's patch.
get_guard_of_operation(self, operation_name)
Return the guard of an operation.
get_constructor_body(self)
Define a tailored constructor body.
user_should_modify_template(self)
Is the user allowed to modify the output.
get_body_of_createGridControlEventsForNextTraversal(self)
Return the grid control events that this action set wants to trigger.
get_includes(self)
Return include statements that you need.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_attributes(self)
Return attributes as copied and pasted into the generated class.
__init__(self, patch, str implementation, str guard="true", str additional_includes="")
Action set (reactions to events)
Definition ActionSet.py:6