Debian Codegraph @

packages/seacas/libraries/ioss/src/visualization/catalyst/phactori/Operation/PhactoriParallelGeometryUtilities.py

raw
1
2 from phactori import *
3 from paraview.simple import *
4
5 #utilities for doing various data grid/geometric operations in parallel
6 #in particular:
7 #GetListOfGridPointsNearestListOfPointsV5
8 # takes a list of geometric points, and goes through all processors and all
9 # blocks and finds the data grid point which is nearest to each point in the list
10 #GetListOfCellTestPointsNearestListOfPointsV5
11 # takes a list of geometric points, and goes through all processors and all
12 # blocks and all cells in each block and for each geometric point finds the
13 # cell bounding box center which is nearest to each point in the list
14
15 #phactori_combine_to_single_python_file_subpiece_begin_1
16
17 def GetGridPointsClosestToPointsInBlockV5(recursionObject, inInputCsData, inParameters):
18 if PhactoriDbg(100):
19 myDebugPrint3("GetGridPointsClosestToPointsInBlockV5 entered\n")
20 numCells = inInputCsData.GetNumberOfCells()
21 numPoints = inInputCsData.GetNumberOfPoints()
22 if (numCells == 0) or (numPoints == 0):
23 #no cells here
24 if PhactoriDbg(100):
25 myDebugPrint3("GetGridPointsClosestToPointsInBlockV5 returning (no cells or no points)\n")
26 return
27
28 if PhactoriDbg(100):
29 myDebugPrint3(str(inParameters.testPointList) + "\n")
30 myDebugPrint3(str(inParameters.distSqrdList) + "\n")
31
32 pointsArray = inInputCsData.GetPoints()
33 gridPtXyz = [0.0, 0.0, 0.0]
34 for gridPtNdx in range(0,numPoints):
35 pointsArray.GetPoint(gridPtNdx, gridPtXyz)
36 for ptndx, oneTestPt in enumerate(inParameters.testPointList):
37 testDist = vecDistanceSquared(oneTestPt, gridPtXyz)
38 if testDist < inParameters.distSqrdList[ptndx]:
39 inParameters.closestList[ptndx] = list(gridPtXyz)
40 inParameters.distSqrdList[ptndx] = testDist
41
42 if PhactoriDbg(100):
43 myDebugPrint3(str(inParameters.testPointList) + "\n")
44 myDebugPrint3(str(inParameters.distSqrdList) + "\n")
45
46 if PhactoriDbg(100):
47 myDebugPrint3("after this block:\n")
48 for ii, oneGridPoint in enumerate(inParameters.closestList):
49 myDebugPrint3(str(ii) + ": " + \
50 str(inParameters.distSqrdList[ii]) + "\n" + \
51 str(inParameters.testPointList[ii]) + "\n" + str(oneGridPoint))
52 myDebugPrint3("\n")
53
54 if PhactoriDbg(100):
55 myDebugPrint3("GetGridPointsClosestToPointsInBlockV5 returning\n")
56
57 def GetCellsClosestToPointsInBlockV5(recursionObject, inInputCsData, inParameters):
58 if PhactoriDbg(100):
59 myDebugPrint3("GetCellsClosestToPointsInBlock entered\n")
60 numCells = inInputCsData.GetNumberOfCells()
61 numPoints = inInputCsData.GetNumberOfPoints()
62 if (numCells == 0) or (numPoints == 0):
63 #no cells here
64 if PhactoriDbg(100):
65 myDebugPrint3("GetCellsClosestToPointsInBlock returning (no cells or no points)\n")
66 return
67
68 if PhactoriDbg(100):
69 myDebugPrint3(str(inParameters.testPointList) + "\n")
70 myDebugPrint3(str(inParameters.distSqrdList) + "\n")
71
72 for cellIndex in range(0,numCells):
73 oneCell = inInputCsData.GetCell(cellIndex)
74 cellTestPoint = GetCellTestPoint(oneCell)
75 for ptndx, oneTestPt in enumerate(inParameters.testPointList):
76 testDist = vecDistanceSquared(oneTestPt, cellTestPoint)
77 if testDist < inParameters.distSqrdList[ptndx]:
78 inParameters.closestList[ptndx] = cellTestPoint
79 inParameters.distSqrdList[ptndx] = testDist
80
81 if PhactoriDbg(100):
82 myDebugPrint3(str(inParameters.testPointList) + "\n")
83 myDebugPrint3(str(inParameters.distSqrdList) + "\n")
84
85 if PhactoriDbg(100):
86 myDebugPrint3("after this block:\n")
87 for ii, oneCellPoint in enumerate(inParameters.closestList):
88 myDebugPrint3(str(ii) + ": " + \
89 str(inParameters.distSqrdList[ii]) + "\n" + \
90 str(inParameters.testPointList[ii]) + "\n" + str(oneCellPoint))
91 myDebugPrint3("\n")
92
93 if PhactoriDbg(100):
94 myDebugPrint3("GetCellsClosestToPointsInBlock returning\n")
95
96 class GetCellsClosestToPointsInBlockRecursionParamsV5:
97 def __init__(self):
98 self.testPointList = []
99 self.distSqrdList = []
100 self.closestList = []
101
102 def InitializeWithPointList(self, inTestPointList):
103 self.testPointList = inTestPointList
104 numTestPoints = len(inTestPointList)
105 for ii in range(0, numTestPoints):
106 self.distSqrdList.append(sys.float_info.max)
107 self.closestList.append(None)
108
109 def GetCellsClosestToPointsOnThisProcessFromParaViewFilterV5(inInputFilter, inTestPointList):
110 if PhactoriDbg(100):
111 myDebugPrint3("GetCellsClosestToPointsOnThisProcessFromParaViewFilter entered\n")
112 recursionObj = PhactoriParaviewMultiBlockRecursionControl()
113 recursionObj.mParameters = GetCellsClosestToPointsInBlockRecursionParamsV5()
114 recursionObj.mParameters.InitializeWithPointList(inTestPointList)
115 recursionObj.mOperationToDoPerBlock = GetCellsClosestToPointsInBlockV5
116 PhactoriRecusivelyDoMethodPerBlockFromParaViewFilter(recursionObj, inInputFilter)
117 if PhactoriDbg(100):
118 myDebugPrint3("GetCellsClosestToPointsOnThisProcessFromParaViewFilter returning\n")
119 return recursionObj.mParameters.closestList, recursionObj.mParameters.distSqrdList
120
121 def GetGridPointsClosestToPointsOnThisProcessFromParaViewFilterV5(inInputFilter, inTestPointList):
122 if PhactoriDbg(100):
123 myDebugPrint3("GetGridPointsClosestToPointsOnThisProcessFromParaViewFilterV5 entered\n")
124 recursionObj = PhactoriParaviewMultiBlockRecursionControl()
125 recursionObj.mParameters = GetCellsClosestToPointsInBlockRecursionParamsV5()
126 recursionObj.mParameters.InitializeWithPointList(inTestPointList)
127 recursionObj.mOperationToDoPerBlock = GetGridPointsClosestToPointsInBlockV5
128 PhactoriRecusivelyDoMethodPerBlockFromParaViewFilter(recursionObj, inInputFilter)
129 if PhactoriDbg(100):
130 myDebugPrint3("GetGridPointsClosestToPointsOnThisProcessFromParaViewFilterV5 returning\n")
131 return recursionObj.mParameters.closestList, recursionObj.mParameters.distSqrdList
132
133 def GetPidWithLeastValueListV5(inLocalDistSqrdList):
134 myPid = int(SmartGetLocalProcessId())
135 globalDistSqrdList = UseReduceOnFloatList(inLocalDistSqrdList, 1)
136 localPidList = []
137 numItems = len(inLocalDistSqrdList)
138 for ndx in range(0,numItems):
139 if globalDistSqrdList[ndx] == inLocalDistSqrdList[ndx]:
140 localPidList.append(myPid)
141 else:
142 localPidList.append(-1)
143
144 pidWithDataList = UseReduceOnIntegerList(localPidList, 0)
145 return pidWithDataList, globalDistSqrdList
146
147
148 def UseMpiToGetGlobalCellPointsClosestV5(inInputFilter, inLocalCellPointList, inLocalDistSqrdList):
149 if PhactoriDbg(100):
150 myDebugPrint3("PhactoriSegmentCellSampler3.UseMpiToGetGlobalCellPointsClosest entered\n", 100)
151
152 if PhactoriDbg(100):
153 myDebugPrint3("inLocalCellPointList:\n" + str(inLocalCellPointList) + "\ninLocalDistSqrdList:\n" + str(inLocalDistSqrdList) + "\n")
154 pidWithDataList, globalDistSqrdList = GetPidWithLeastValueListV5(inLocalDistSqrdList)
155 if PhactoriDbg(100):
156 myDebugPrint3("pidWithDataList:\n" + str(pidWithDataList) + "\nglobalDistSqrdList:\n" + str(globalDistSqrdList) + "\n")
157
158 #convert cell point list to array of doubles and ints, use mpi reduce to share
159 #the values, then convert back to cell point list
160 serializeFloatArray = []
161 serializeIntArray = []
162
163 #convert cell point list to array of doubles
164 cellPointFloatArray = []
165 myPid = SmartGetLocalProcessId()
166 for ii, oneCellPoint in enumerate(inLocalCellPointList):
167 if pidWithDataList[ii] == myPid:
168 cellPointFloatArray.append(oneCellPoint[0])
169 cellPointFloatArray.append(oneCellPoint[1])
170 cellPointFloatArray.append(oneCellPoint[2])
171 else:
172 cellPointFloatArray.append(0.0)
173 cellPointFloatArray.append(0.0)
174 cellPointFloatArray.append(0.0)
175
176 #use mpi reduce to spread array correctly
177 globalCellPointFloatArray = UseReduceOnFloatList(cellPointFloatArray, 2)
178
179 #now create return global cell point list from arrays
180 numCells = len(inLocalCellPointList)
181 returnGlobalCellPointList = []
182 for ii in range(0,numCells):
183 myndx = ii*3
184 oneCellPoint = [globalCellPointFloatArray[myndx],
185 globalCellPointFloatArray[myndx+1],
186 globalCellPointFloatArray[myndx+2]]
187 returnGlobalCellPointList.append(oneCellPoint)
188
189 if PhactoriDbg(100):
190 myDebugPrint3("returnGlobalCellPointList:\n" + str(returnGlobalCellPointList) + "\n")
191 if PhactoriDbg(100):
192 myDebugPrint3("PhactoriSegmentCellSampler3.UseMpiToGetGlobalCellPointsClosest returning\n", 100)
193 return returnGlobalCellPointList, globalDistSqrdList
194
195 def GetListOfCellTestPointsNearestListOfPointsV5(inInputFilter, pointList):
196 """for each point in the list, find the cell test point (e.g. center of
197 cell bounding box) which is nearest the test point. Use MPI to work
198 in parallel"""
199
200 thisProcessNearestCellPointList, thisProcDistSqrdList = \
201 GetCellsClosestToPointsOnThisProcessFromParaViewFilterV5(inInputFilter, pointList)
202
203 nearestCellList, distanceList = UseMpiToGetGlobalCellPointsClosestV5(
204 inInputFilter, thisProcessNearestCellPointList, thisProcDistSqrdList)
205
206 return nearestCellList
207
208 def GetListOfGridPointsNearestListOfPointsV5(inInputFilter, pointList):
209 """for each point in the list, find the point in the data grid
210 which is nearest the test point. Use MPI to work
211 in parallel"""
212
213 thisProcessNearestGridPointList, thisProcDistSqrdList = \
214 GetGridPointsClosestToPointsOnThisProcessFromParaViewFilterV5(inInputFilter, pointList)
215
216 nearestCellList, distanceList = UseMpiToGetGlobalCellPointsClosestV5(
217 inInputFilter, thisProcessNearestGridPointList, thisProcDistSqrdList)
218
219 return nearestCellList
220
221
222
223 #phactori_combine_to_single_python_file_subpiece_end_1