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.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.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.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 if ( {GUARD} ) {{
95 logTraceIn( "touchCellLastTime(...)---ProjectPatchOntoFaces" );
96"""
97
98
99 __Template_TouchCellLastTime_Core = """
100 // @todo Might want to use routine from Projection.h in toolbox.
101 for(int d=0; d<Dimensions; d++) {{
102 /**
103 * d-loop over all dimensions except d. The vector k's entry d is set
104 * to 0. We start with the left/bottom face, i.e. the one closer to the
105 * coordinate system's origin.
106 */
107 dfore(k,{DOFS_PER_AXIS},d,0) {{
108 for (int i=0; i<{OVERLAP}; i++) {{
109 tarch::la::Vector<Dimensions,int> patchCell = k;
110 tarch::la::Vector<Dimensions,int> overlapCell = k;
111 patchCell(d) = i;
112 overlapCell(d) = i+{OVERLAP};
113
114 int patchCellSerialised = peano4::utils::dLinearised(patchCell,{DOFS_PER_AXIS});
115 int overlapCellSerialised = toolbox::blockstructured::serialiseVoxelIndexInOverlap(overlapCell,{DOFS_PER_AXIS},{OVERLAP},d);
116 for (int j=0; j<{UNKNOWNS}; j++) {{
117 assertion7(
118 {ASSERTION_PREFIX}
119 or
120 {CELL_ACCESSOR}.value[patchCellSerialised*{UNKNOWNS}+j]=={CELL_ACCESSOR}.value[patchCellSerialised*{UNKNOWNS}+j], j,i,k,d, patchCell, overlapCell,
121 marker.toString()
122 );
123 {FACES_ACCESSOR}(d).value[overlapCellSerialised*{UNKNOWNS}+j] =
124 {CELL_ACCESSOR}.value[patchCellSerialised*{UNKNOWNS}+j];
125 }}
126
127 patchCell(d) = i+{DOFS_PER_AXIS}-{OVERLAP};
128 overlapCell(d) = i;
129
130 patchCellSerialised = peano4::utils::dLinearised(patchCell,{DOFS_PER_AXIS});
131 overlapCellSerialised = toolbox::blockstructured::serialiseVoxelIndexInOverlap(overlapCell,{DOFS_PER_AXIS},{OVERLAP},d);
132 for (int j=0; j<{UNKNOWNS}; j++) {{
133 assertion7(
134 {ASSERTION_PREFIX}
135 or
136 {CELL_ACCESSOR}.value[patchCellSerialised*{UNKNOWNS}+j]=={CELL_ACCESSOR}.value[patchCellSerialised*{UNKNOWNS}+j], j,i,k,d, patchCell, overlapCell,
137 marker.toString()
138 );
139 {FACES_ACCESSOR}(d+Dimensions).value[overlapCellSerialised*{UNKNOWNS}+j] =
140 {CELL_ACCESSOR}.value[patchCellSerialised*{UNKNOWNS}+j];
141 }}
142 }}
143 }}
144 }}
145"""
146
147
148 __Template_TouchCellLastTime_Epilogue = """
149 logTraceOut( "touchCellLastTime(...)---ProjectPatchOntoFaces" );
150 }}
151 else {{
152 logTraceInWith1Argument( "touchCellLastTime(...)---ProjectPatchOntoFaces [skip]", marker.toString() );
153 logTraceOut( "touchCellLastTime(...)---ProjectPatchOntoFaces [skip]" );
154 }}
155"""
156
157
158 def get_body_of_operation(self,operation_name):
159 result = "\n"
160 if operation_name==ActionSet.OPERATION_TOUCH_CELL_LAST_TIME:
161 result = self.__Template_TouchCellLastTime_Preamble.format(**self.d)
162 result += self.__Template_TouchCellLastTime_Core.format(**self.d)
163 result += self.__Template_TouchCellLastTime_Epilogue.format(**self.d)
164 pass
165 return result
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
Action set (reactions to events)
Definition ActionSet.py:6
This class assumes that you have NxNxN patch within your block.
get_attributes(self)
Return attributes as copied and pasted into the generated class.
__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.