Peano
Loading...
Searching...
No Matches
RestrictHangingFaces.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 enum
4
5import jinja2
6
7from peano4.api.solversteps.ActionSet import ActionSet
8
9
11 """!
12
13 Restrict the overlap data of hanging faces onto the coarser mesh
14
15 A hanging face is a face of a fine cell which sits on the face of a
16 coarser, unrefined cell (toolbox.blockstructured.api.InterpolateHangingFaces).
17 The action set plugs into destroyHangingFace(): It takes the half of the
18 hanging face which belongs to the fine cell and restricts it onto the
19 corresponding half of the coarse face
20 (::toolbox::blockstructured::restrictInnerHalfOfHaloLayer_AoS_...).
21 Peano destroys a hanging face after touchCellLastTime() of its fine
22 cell, i.e. after the fine cell has projected its data onto its faces.
23 Peano touches the coarse face for the last time after all of these
24 hanging faces have been destroyed. Afterwards, the coarse face holds the
25 data of the coarse cell on one side and the restricted fine data on the
26 other side.
27
28 The face overlap has to be a 2MxNxN patch: M is the overlap, N the
29 number of volumes per patch axis.
30
31
32 ## Averaging and clearing
33
34 Averaging accumulates the fine grid values within the coarse face.
35 The action set therefore clears the face data in touchFaceFirstTime()
36 for each face which passes the clear guard. This clears both halves of
37 the face. Use the action set only in a mesh sweep where all face data
38 which are cleared are written again afterwards, e.g. by a projection
39 onto the faces. Injection overwrites the coarse values and hence does
40 not clear anything.
41
42 """
43
44 class Scheme(enum.Enum):
45 """!
46
47 Restriction schemes
48
49 The value of each entry is the suffix of the C++ routine
50 ::toolbox::blockstructured::restrictInnerHalfOfHaloLayer_AoS_<suffix>().
51
52 - Averaging sets each coarse volume to the average of the fine
53 volumes along the face which it covers.
54 - Inject copies the value of the fine volume in the centre of each
55 coarse volume.
56
57 """
58
59 Averaging = "averaging"
60 Inject = "inject"
61
62 TemplateTouchFaceFirstTime = jinja2.Template(
63 """
64 logTraceInWith1Argument( "touchFaceFirstTime(...)---RestrictHangingFaces", marker.toString() );
65 ::toolbox::blockstructured::clearHaloLayerAoS(
66 marker,
67 {{DOFS_PER_AXIS}},
68 {{OVERLAP}},
69 {{UNKNOWNS}},
70 fineGridFace{{FACE_NAME}}.value
71 );
72 logTraceOut( "touchFaceFirstTime(...)---RestrictHangingFaces" );
73"""
74 )
75
76 TemplateDestroyHangingFace = jinja2.Template(
77 """
78 logTraceInWith1Argument( "destroyHangingFace(...)---RestrictHangingFaces", marker.toString() );
79 ::toolbox::blockstructured::restrictInnerHalfOfHaloLayer_AoS_{{SCHEME}}(
80 marker,
81 {{DOFS_PER_AXIS}},
82 {{OVERLAP}},
83 {{UNKNOWNS}},
84 fineGridFace{{FACE_NAME}}.value,
85 coarseGridFaces{{FACE_NAME}}(marker.getSelectedFaceNumber()).value
86 );
87 logTraceOut( "destroyHangingFace(...)---RestrictHangingFaces" );
88"""
89 )
90
92 self,
93 patch_overlap,
94 scheme: "RestrictHangingFaces.Scheme" = None,
95 guard: str = "true",
96 clear_guard: str = "true",
97 additional_includes: str = "",
98 ):
99 """!
100
101 @param patch_overlap: peano4.api.datamodel.Patch
102 The face data which the action set restricts. The data of the
103 hanging face are read, the data of the coarse face are written.
104
105 @param scheme: RestrictHangingFaces.Scheme
106 Restriction scheme. Defaults to Scheme.Averaging. Injection
107 supports an overlap of one only.
108
109 @param guard: str
110 C++ boolean expression over the hanging face's
111 peano4::datamanagement::FaceMarker marker.
112
113 @param clear_guard: str
114 C++ boolean expression over a persistent face's
115 peano4::datamanagement::FaceMarker marker. Only used for averaging:
116 The action set clears the face's data in touchFaceFirstTime() if
117 the expression holds.
118
119 @param additional_includes: str
120 Further include statements, e.g. required by the guards.
121
122 """
123 super().__init__(descend_invocation_order=1, parallel=False)
124 assert patch_overlap.dim[0] % 2 == 0, (
125 "Patch associated to face has to have even number of volumes along "
126 "the normal. Otherwise, it is not a symmetric overlap."
127 )
128 self.scheme = (
129 RestrictHangingFaces.Scheme.Averaging if scheme is None else scheme
130 )
131 assert isinstance(self.scheme, RestrictHangingFaces.Scheme), self.scheme
132 assert (
133 self.scheme != RestrictHangingFaces.Scheme.Inject
134 or patch_overlap.dim[0] == 2
135 ), (
136 "Injection supports an overlap of one only, but the face data "
137 f"{patch_overlap.name} have an overlap of {patch_overlap.dim[0] // 2}. "
138 "Use averaging instead."
139 )
140 self.d = {
141 "UNKNOWNS": patch_overlap.no_of_unknowns,
142 "DOFS_PER_AXIS": patch_overlap.dim[1],
143 "OVERLAP": patch_overlap.dim[0] // 2,
144 "FACE_NAME": patch_overlap.name,
145 "SCHEME": self.scheme.value,
146 }
147 self.guard = guard
148 self.clear_guard = clear_guard
149 self.additional_includes = additional_includes
150
151 @property
152 def clears_faces(self) -> bool:
153 """! Does the scheme accumulate, i.e. does it have to clear the faces first?"""
154 return self.scheme == RestrictHangingFaces.Scheme.Averaging
155
157 return ""
158
160 return ""
161
163 return " return std::vector< peano4::grid::GridControlEvent >();\n"
164
166 return "\n"
167
169 return "\n"
170
171 def get_body_of_operation(self, operation_name):
172 if operation_name == ActionSet.OPERATION_DESTROY_HANGING_FACE:
173 return self.TemplateDestroyHangingFace.render(**self.d)
174 if (
175 operation_name == ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME
176 and self.clears_faces
177 ):
178 return self.TemplateTouchFaceFirstTime.render(**self.d)
179 return ""
180
181 def get_guard_of_operation(self, operation_name):
182 if operation_name == ActionSet.OPERATION_DESTROY_HANGING_FACE:
183 return self.guard
184 if operation_name == ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME:
185 return self.clear_guard
186 return "true"
187
189 return __name__.replace(".py", "").replace(".", "_")
190
192 return False
193
194 def get_attributes(self):
195 return ""
196
197 def get_includes(self):
198 return (
199 """
200#include "toolbox/blockstructured/Restriction.h"
201"""
203 )
Restrict the overlap data of hanging faces onto the coarser mesh.
get_action_set_name(self)
Return unique action set name.
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_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_includes(self)
Return include statements that you need.
bool clears_faces(self)
Does the scheme accumulate, i.e.
get_guard_of_operation(self, operation_name)
Return the guard of an operation.
__init__(self, patch_overlap, "RestrictHangingFaces.Scheme" scheme=None, str guard="true", str clear_guard="true", str additional_includes="")
get_attributes(self)
Return attributes as copied and pasted into the generated class.
get_body_of_createGridControlEventsForNextTraversal(self)
Return the grid control events that this action set wants to trigger.
Action set (reactions to events)
Definition ActionSet.py:6