Peano
Loading...
Searching...
No Matches
ProjectPatchOntoFaces.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
6
8 """!
9
10 This class assumes that you have NxNxN patch within your block. It also
11 assumes that you have an 2MxNxN patch on your faces. M<N. The code interprets
12 these face-associated data as overlap with the patch, hooks into
13 touchCellLastTime, and projects the cell's patch data onto the overlap
14 (simple copy).
15
16 And then runs over your grid and maps the patch data on the respective entries of the
17 face patch which is an auxiliary data structure.
18
19
20 # Attributes
21
22 patch: peano4.api.datamodel.Patch
23 This is the input data structure, i.e. the patch from which we extract
24 the boundary data.
25
26 patch_overlap: peano4.api.datamodel.Patch.
27 Consult remark above about how the dimensions of this overlap patch have
28 to match.
29
30 """
31
32
33 def __init__(self,patch,patch_overlap,guard,additional_includes, add_assertions = True):
34 super(ProjectPatchOntoFaces,self).__init__(descend_invocation_order=1,parallel=False)
35 self.d = {}
36 if patch_overlap.dim[0] % 2 != 0:
37 print( "Error: Patch associated to face has to have even number of cells. Otherwise, it is not a symmetric overlap." )
38 assert( patch_overlap.dim[0] % 2 == 0 )
39 if patch.dim[0] != patch.dim[1]:
40 print( "Error: Can only handle square patches." )
41 assert( patch.dim[0] == patch.dim[1] )
42 if patch_overlap.dim[1] != patch.dim[0]:
43 print( "Error: Patch of overlap and patch of cell have to match" )
44 assert( patch_overlap.dim[1] == patch.dim[0] )
45
46 assert isinstance(patch.no_of_unknowns,int)
47 assert isinstance(patch.dim[0],int)
48 assert isinstance(patch_overlap.dim[0],int)
49
50 self.d[ "UNKNOWNS" ] = str(patch.no_of_unknowns)
51 self.d[ "DOFS_PER_AXIS" ] = str(patch.dim[0])
52 self.d[ "OVERLAP" ] = str(int(patch_overlap.dim[0]/2))
53 self.d[ "FACES_ACCESSOR" ] = "fineGridFaces" + patch_overlap.name
54 self.d[ "CELL_ACCESSOR" ] = "fineGridCell" + patch.name
55 self.d[ "GUARD" ] = guard
56 if add_assertions:
57 self.d[ "ASSERTION_PREFIX" ] = "false"
58 else:
59 self.d[ "ASSERTION_PREFIX" ] = "true"
60
61
62 self.additional_includes = additional_includes
63
64
65 @property
66 def guard(self):
67 return self.d[ "GUARD" ]
68
69 @guard.setter
70 def guard(self,value):
71 self.d[ "GUARD" ] = value
72
74 return ""
75
76
78 return ""
79
80
82 return " return std::vector< peano4::grid::GridControlEvent >();\n"
83
84
86 return __name__.replace(".py", "").replace(".", "_")
87
88
90 return False
91
92
93 __Template_TouchCellLastTime_Preamble = """
94 logTraceIn( "touchCellLastTime(...)---ProjectPatchOntoFaces" );
95"""
96
97
98 __Template_TouchCellLastTime_Core = """
99 // @todo Might want to use routine from Projection.h in toolbox.
100 for(int d=0; d<Dimensions; d++) {{
101 /**
102 * d-loop over all dimensions except d. The vector k's entry d is set
103 * to 0. We start with the left/bottom face, i.e. the one closer to the
104 * coordinate system's origin.
105 */
106 dfore(k,{DOFS_PER_AXIS},d,0) {{
107 for (int i=0; i<{OVERLAP}; i++) {{
108 tarch::la::Vector<Dimensions,int> patchCell = k;
109 tarch::la::Vector<Dimensions,int> overlapCell = k;
110 patchCell(d) = i;
111 overlapCell(d) = i+{OVERLAP};
112
113 int patchCellSerialised = peano4::utils::dLinearised(patchCell,{DOFS_PER_AXIS});
114 int overlapCellSerialised = toolbox::blockstructured::serialiseVoxelIndexInOverlap(overlapCell,{DOFS_PER_AXIS},{OVERLAP},d);
115 for (int j=0; j<{UNKNOWNS}; j++) {{
116 assertion7(
117 {ASSERTION_PREFIX}
118 or
119 {CELL_ACCESSOR}.value[patchCellSerialised*{UNKNOWNS}+j]=={CELL_ACCESSOR}.value[patchCellSerialised*{UNKNOWNS}+j], j,i,k,d, patchCell, overlapCell,
120 marker.toString()
121 );
122 {FACES_ACCESSOR}(d).value[overlapCellSerialised*{UNKNOWNS}+j] =
123 {CELL_ACCESSOR}.value[patchCellSerialised*{UNKNOWNS}+j];
124 }}
125
126 patchCell(d) = i+{DOFS_PER_AXIS}-{OVERLAP};
127 overlapCell(d) = i;
128
129 patchCellSerialised = peano4::utils::dLinearised(patchCell,{DOFS_PER_AXIS});
130 overlapCellSerialised = toolbox::blockstructured::serialiseVoxelIndexInOverlap(overlapCell,{DOFS_PER_AXIS},{OVERLAP},d);
131 for (int j=0; j<{UNKNOWNS}; j++) {{
132 assertion7(
133 {ASSERTION_PREFIX}
134 or
135 {CELL_ACCESSOR}.value[patchCellSerialised*{UNKNOWNS}+j]=={CELL_ACCESSOR}.value[patchCellSerialised*{UNKNOWNS}+j], j,i,k,d, patchCell, overlapCell,
136 marker.toString()
137 );
138 {FACES_ACCESSOR}(d+Dimensions).value[overlapCellSerialised*{UNKNOWNS}+j] =
139 {CELL_ACCESSOR}.value[patchCellSerialised*{UNKNOWNS}+j];
140 }}
141 }}
142 }}
143 }}
144"""
145
146
147 __Template_TouchCellLastTime_Epilogue = """
148 logTraceOut( "touchCellLastTime(...)---ProjectPatchOntoFaces" );
149"""
150
151
152 def get_body_of_operation(self,operation_name):
153 result = "\n"
154 if operation_name==ActionSet.OPERATION_TOUCH_CELL_LAST_TIME:
155 result = self.__Template_TouchCellLastTime_Preamble.format(**self.d)
156 result += self.__Template_TouchCellLastTime_Core.format(**self.d)
157 result += self.__Template_TouchCellLastTime_Epilogue.format(**self.d)
158 pass
159 return result
160
161
162 def get_guard_of_operation(self,operation_name):
163 if operation_name==ActionSet.OPERATION_TOUCH_CELL_LAST_TIME:
164 return self.d[ "GUARD" ]
165 return "true"
166
167
168 def get_attributes(self):
169 return ""
170
171
172 def get_includes(self):
173 return """
174#include "peano4/utils/Loop.h"
175#include "toolbox/blockstructured/Enumeration.h"
176""" + self.additional_includes
#define assert(...)
Definition LinuxAMD.h:28
This class assumes that you have NxNxN patch within your block.
get_attributes(self)
Return attributes as copied and pasted into the generated class.
get_includes(self)
Return include statements that you need.
get_body_of_createGridControlEventsForNextTraversal(self)
Return the grid control events that this action set wants to trigger.
user_should_modify_template(self)
Is the user allowed to modify the output.
get_action_set_name(self)
Return unique action set name.
get_constructor_body(self)
Define a tailored constructor body.
__init__(self, patch, patch_overlap, guard, additional_includes, add_assertions=True)
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_guard_of_operation(self, operation_name)
Return the guard of an operation.
Action set (reactions to events)
Definition ActionSet.py:6