Peano
Loading...
Searching...
No Matches
DynamicAMR.py
Go to the documentation of this file.
1# This file is part of the Peano project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from peano4.solversteps.ActionSet import ActionSet
4
5
6import jinja2
7
8
10 """
11 This class assumes that you have an 2MxNxN patch on your faces.
12
13 patch: peano4.datamodel.Patch
14
15 patch_overlap_interpolation: peano4.datamodel.Patch
16 Consult remark above about how the dimensions of this overlap
17 patch have to match. This overlap is used for the
18 interpolation. It can be the same as for the restriction.
19
20 patch_overlap_restriction: peano4.datamodel.Patch
21
22 """
23
24
25 def __init__(self,
26 patch,
27 patch_overlap_interpolation,
28 patch_overlap_restriction,
29 interpolation_scheme,
30 restriction_scheme,
31 clear_guard="true",
32 restrict_guard="true",
33 interpolate_guard="true",
34 additional_includes=""
35 ):
36 """
37
38 restrict_guard: String
39 Predicate as C++ expression. It determines which faces are cleared.
40
41 interpolation_scheme: String
42 This is a string that is used to assemble the interpolation scheme that
43 is actually used. At the moment, I mainly offer three variants here:
44 - piecewise_constant.
45 - linear.
46 - linear_precomputed_operators<3>. The 3 has to be replaced by the
47 number of unknowns that you use per coordinate axis.
48
49 """
50 super(DynamicAMR,self).__init__(descend_invocation_order=1,parallel=False)
51 self.d = {}
52 if patch_overlap_interpolation.dim[0] % 2 != 0:
53 raise Exception( "Error: Patch associated to face has to have even number of cells. Otherwise, it is not a symmetric overlap." )
54 if patch_overlap_interpolation.dim != patch_overlap_restriction.dim:
55 raise Exception( "Error: Patches associated to face have to have same dimensions for restriction and interpolation." )
56
57 self.d[ "UNKNOWNS" ] = str(patch_overlap_interpolation.no_of_unknowns)
58 self.d[ "DOFS_PER_AXIS" ] = str(patch_overlap_interpolation.dim[1])
59 self.d[ "OVERLAP" ] = str(int(patch_overlap_interpolation.dim[0]/2))
60 self.d[ "FINE_GRID_CELL" ] = "fineGridCell" + patch.name
61 self.d[ "COARSE_GRID_CELL" ] = "coarseGridCell" + patch.name
62 self.d[ "FINE_GRID_FACE_ACCESSOR_INTERPOLATION" ] = "fineGridFace" + patch_overlap_interpolation.name
63 self.d[ "COARSE_GRID_FACE_ACCESSOR_INTERPOLATION" ] = "coarseGridFaces" + patch_overlap_interpolation.name
64 self.d[ "FINE_GRID_FACE_ACCESSOR_RESTRICTION" ] = "fineGridFace" + patch_overlap_restriction.name
65 self.d[ "COARSE_GRID_FACE_ACCESSOR_RESTRICTION" ] = "coarseGridFaces" + patch_overlap_restriction.name
66 self.d[ "INTERPOLATION_SCHEME" ] = interpolation_scheme
67 self.d[ "RESTRICTION_SCHEME" ] = restriction_scheme
68 self.d[ "CLEAR_GUARD" ] = clear_guard
69 self.d[ "RESTRICT_GUARD" ] = restrict_guard
70 self.d[ "INTERPOLATE_GUARD" ] = interpolate_guard
71
72 self.additional_includes = additional_includes
73
74
76 return ""
77
78
80 return ""
81
82
84 return " return std::vector< peano4::grid::GridControlEvent >();\n"
85
86
88 return __name__.replace(".py", "").replace(".", "_")
89
90
92 return False
93
94
95 _Template_TouchFaceFirstTime = """
96 if ( {{CLEAR_GUARD}} ) {
97 logTraceInWith2Arguments( "touchFaceFirstTime(...)", marker.toString(), "clear halo layer {{FINE_GRID_FACE_ACCESSOR_RESTRICTION}}" );
98
99 ::toolbox::blockstructured::clearHaloLayerAoS(
100 marker,
101 {{DOFS_PER_AXIS}},
102 {{OVERLAP}},
103 {{UNKNOWNS}},
104 {{FINE_GRID_FACE_ACCESSOR_RESTRICTION}}.value
105 );
106
107 logTraceOut( "touchFaceFirstTime(...)" );
108 }
109"""
110
111
112 _Template_TouchCellFirstTime = """
113 if ( marker.hasBeenRefined() and not marker.willBeRefined() ) {
114 logTraceInWith2Arguments( "touchCellFirstTime(...)", marker.toString(), "clear cell {{FINE_GRID_CELL}}" );
115
116 ::toolbox::blockstructured::clearCell(
117 marker,
118 {{DOFS_PER_AXIS}},
119 {{UNKNOWNS}},
120 {{FINE_GRID_CELL}}.value
121 );
122
123 logTraceOut( "touchCellFirstTime(...)" );
124 }
125"""
126
127
128 _Template_CreateHangingFace = """
129 if ( {{INTERPOLATE_GUARD}} ) {
130 logTraceInWith1Argument( "createHangingFace(...)", marker.toString() );
131
132 ::toolbox::blockstructured::interpolateHaloLayer_AoS_{{INTERPOLATION_SCHEME}}(
133 marker,
134 {{DOFS_PER_AXIS}},
135 {{OVERLAP}},
136 {{UNKNOWNS}},
137 {{COARSE_GRID_FACE_ACCESSOR_INTERPOLATION}}(marker.getSelectedFaceNumber()).value,
138 {{FINE_GRID_FACE_ACCESSOR_INTERPOLATION}}.value
139 );
140
141 logTraceOut( "createHangingFace(...)" );
142 }
143 else {
144 logDebug( "createHangingFace(...)", "skip interpolation for " << marker.toString() << " as interpolation guard did not yield true" );
145 }
146"""
147
148
149 _Template_DestroyHangingFace = """
150 if ( {{RESTRICT_GUARD}} ) {
151 logTraceInWith4Arguments( "destroyHangingFace(...)", "{{FINE_GRID_FACE_ACCESSOR_RESTRICTION}}", "{{COARSE_GRID_FACE_ACCESSOR_RESTRICTION}}", marker.getSelectedFaceNumber(), marker.toString() );
152
153 ::toolbox::blockstructured::restrictInnerHalfOfHaloLayer_AoS_{{RESTRICTION_SCHEME}}(
154 marker,
155 {{DOFS_PER_AXIS}},
156 {{OVERLAP}},
157 {{UNKNOWNS}},
158 {{FINE_GRID_FACE_ACCESSOR_RESTRICTION}}.value,
159 {{COARSE_GRID_FACE_ACCESSOR_RESTRICTION}}(marker.getSelectedFaceNumber()).value
160 );
161
162 logTraceOut( "destroyHangingFace(...)" );
163 }
164"""
165
166
167 """
168
169 """
170 _Template_CreatePersistentFace = """
171 logTraceInWith1Argument( "createPersistentFace(...)", marker.toString() );
172
173 ::toolbox::blockstructured::interpolateHaloLayer_AoS_{{INTERPOLATION_SCHEME}}(
174 marker,
175 {{DOFS_PER_AXIS}},
176 {{OVERLAP}},
177 {{UNKNOWNS}},
178 {{COARSE_GRID_CELL}}.value,
179 {{COARSE_GRID_FACE_ACCESSOR_INTERPOLATION}}(marker.getSelectedFaceNumber()).value,
180 {{FINE_GRID_FACE_ACCESSOR_INTERPOLATION}}.value
181 );
182
183 logTraceOutWith1Argument( "createPersistentFace(...)", marker.toString() );
184"""
185
186
187 _Template_DestroyPersistentFace = """
188 if ( not marker.isInteriorFaceWithinPatch() ) {
189 logTraceIn( "destroyPersistentFace(...)" );
190
191 ::toolbox::blockstructured::restrictHaloLayer_AoS_{{RESTRICTION_SCHEME}}(
192 marker,
193 {{DOFS_PER_AXIS}},
194 {{OVERLAP}},
195 {{UNKNOWNS}},
196 {{FINE_GRID_FACE_ACCESSOR_RESTRICTION}}.value,
197 {{COARSE_GRID_FACE_ACCESSOR_RESTRICTION}}(marker.getSelectedFaceNumber()).value
198 );
199
200 logTraceOut( "destroyPersistentFace(...)" );
201 }
202"""
203
204
205 _Template_CreateCell = """
206 logTraceIn( "createCell(...)" );
207
208 ::toolbox::blockstructured::interpolateCell_AoS_{{INTERPOLATION_SCHEME}}(
209 marker,
210 {{DOFS_PER_AXIS}},
211 {{UNKNOWNS}},
212 {{COARSE_GRID_CELL}}.value,
213 {{FINE_GRID_CELL}}.value
214 );
215
216 logTraceOut( "createCell(...)" );
217"""
218
219
220 _Template_DestroyCell = """
221 logTraceInWith1Argument( "destroyCell(...)", marker.toString() );
222
223 ::toolbox::blockstructured::restrictCell_AoS_{{RESTRICTION_SCHEME}}(
224 marker,
225 {{DOFS_PER_AXIS}},
226 {{UNKNOWNS}},
227 {{FINE_GRID_CELL}}.value,
228 {{COARSE_GRID_CELL}}.value
229 );
230
231 logTraceOut( "destroyCell(...)" );
232"""
233
234
235 def get_body_of_operation(self,operation_name):
236 result = "\n"
237 if operation_name==ActionSet.OPERATION_CREATE_HANGING_FACE:
238 result = jinja2.Template(self._Template_CreateHangingFace).render(**self.d)
239 pass
240 if operation_name==ActionSet.OPERATION_CREATE_PERSISTENT_FACE:
241 result = jinja2.Template(self._Template_CreatePersistentFace).render(**self.d)
242 pass
243 if operation_name==ActionSet.OPERATION_DESTROY_HANGING_FACE:
244 result = jinja2.Template(self._Template_DestroyHangingFace).render(**self.d)
245 pass
246 if operation_name==ActionSet.OPERATION_DESTROY_PERSISTENT_FACE:
247 result = jinja2.Template(self._Template_DestroyPersistentFace).render(**self.d)
248 pass
249 if operation_name==ActionSet.OPERATION_CREATE_CELL:
250 result = jinja2.Template(self._Template_CreateCell).render(**self.d)
251 pass
252 if operation_name==ActionSet.OPERATION_DESTROY_CELL:
253 result = jinja2.Template(self._Template_DestroyCell).render(**self.d)
254 pass
255 if operation_name==ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME:
256 result = jinja2.Template(self._Template_TouchFaceFirstTime).render(**self.d)
257 pass
258 if operation_name==ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
259 result = jinja2.Template(self._Template_TouchCellFirstTime).render(**self.d)
260 pass
261 return result
262
263
264 def get_attributes(self):
265 return ""
266
267
268 def get_includes(self):
269 return """
270#include "peano4/utils/Loop.h"
271#include "toolbox/blockstructured/Enumeration.h"
272#include "toolbox/blockstructured/Interpolation.h"
273#include "toolbox/blockstructured/Restriction.h"
274""" + self.additional_includes
275
276
278 return self.d[ "CLEAR_GUARD" ]
279
280
282 return self.d[ "RESTRICT_GUARD" ]
283
284
286 return self.d[ "INTERPOLATE_GUARD" ]
287
288
289 def switch_interpolation_scheme(self,interpolation_scheme):
290 self.d[ "INTERPOLATION_SCHEME" ] = interpolation_scheme
291
292
293 def switch_restriction_scheme(self,restriction_scheme):
294 self.d[ "RESTRICTION_SCHEME" ] = restriction_scheme
295
Action set (reactions to events)
Definition ActionSet.py:6
This class assumes that you have an 2MxNxN patch on your faces.
Definition DynamicAMR.py:9
get_includes(self)
Return include statements that you need.
get_attributes(self)
Return attributes as copied and pasted into the generated class.
get_action_set_name(self)
Return unique action set name.
Definition DynamicAMR.py:87
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
switch_interpolation_scheme(self, interpolation_scheme)
user_should_modify_template(self)
Is the user allowed to modify the output.
Definition DynamicAMR.py:91
__init__(self, patch, patch_overlap_interpolation, patch_overlap_restriction, interpolation_scheme, restriction_scheme, clear_guard="true", restrict_guard="true", interpolate_guard="true", additional_includes="")
restrict_guard: String Predicate as C++ expression.
Definition DynamicAMR.py:35
get_constructor_body(self)
Define a tailored constructor body.
Definition DynamicAMR.py:75