Debian Codegraph @

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

raw
1 # Copyright(C) 1999-2020 National Technology & Engineering Solutions
2 # of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 # NTESS, the U.S. Government retains certain rights in this software.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
8 #
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 #
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 #
17 # * Neither the name of NTESS nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 from phactori import *
34 from paraview.simple import *
35
36 #phactori_combine_to_single_python_file_subpiece_begin_1
37 class PhactoriPartitionedToMultiBlockOperation(PhactoriOperationSpecifics):
38 """manages PartitionedToMultiBlock filter"""
39 def __init__(self):
40 PhactoriOperationSpecifics.__init__(self)
41 self.InputFilter = None
42 self.OutVtkMultiBlockDataSet = None
43 self.OutputPVTrivialProducer = None
44
45 def ParseParametersFromJson(self, inJson):
46 dummy = 0
47
48 def GetNodeType(self, inNode):
49 if inNode == None:
50 myDebugPrint3AndException("PhactoriVtkDataExportOperation::GetNodeType\n"
51 "fix to handle None inNode\n")
52 icsdClassname = inNode.GetClassName()
53 if icsdClassname == "vtkMultiBlockDataSet":
54 nodeType = 0
55 elif icsdClassname == "vtkExodusIIMultiBlockDataSet":
56 nodeType = 1
57 elif icsdClassname == "vtkMultiPieceDataSet":
58 nodeType = 2
59 elif icsdClassname == "vtkPartitionedDataSet":
60 nodeType = 3
61 elif icsdClassname == "vtkStructuredGrid":
62 nodeType = 4
63 elif icsdClassname == "vtkUntructuredGrid":
64 nodeType = 5
65 else:
66 nodeType = 6
67 return nodeType
68
69 def AddItemToMultiblockOrMultiPiece(self, nonLeafType, inCurrentAlteredNode, oneChild, childName):
70 if nonLeafType == 2:
71 newChildIndex = inCurrentAlteredNode.GetNumberOfPieces()
72 inCurrentAlteredNode.SetPiece(newChildIndex, oneChild)
73 elif nonLeafType == 3:
74 #newChildIndex = inCurrentAlteredNode.GetNumberOfPartitions()
75 #inCurrentAlteredNode.SetPartition(newChildIndex, oneChild)
76 myDebugPrint3AndException(
77 "PhactoriVtkDataExportOperation::ParseParametersFromJson\n"
78 "unexpected nonLeafType (vtkPartitionedDataSet) at this place\n")
79 else:
80 newChildIndex = inCurrentAlteredNode.GetNumberOfBlocks()
81 inCurrentAlteredNode.SetBlock(newChildIndex, oneChild)
82 if childName != None:
83 newAlteredNodeMetaData = inCurrentAlteredNode.GetMetaData(newChildIndex)
84 newAlteredNodeMetaData.Set(vtk.vtkCompositeDataSet.NAME(), childName)
85
86 def UpdateAlteredVtkMultiBlockDataSetRecurse1(self, inCurrentAlteredNode, inCurrentSourceNode):
87 #at this point, both inputs are not leafs, and inCurrentSource is not
88 #VtkPartitionedDataSet
89 if PhactoriDbg(100):
90 myDebugPrint3("PhactoriVtkDataExportOperation." \
91 "UpdateAlteredVtkMultiBlockDataSetRecurse1 entered\n"
92 "inCurrentAlteredNode type: " + str(inCurrentAlteredNode.GetClassName()) + "\n"
93 "inCurrentSourceNode type: " + str(inCurrentSourceNode.GetClassName()) + "\n", 100)
94
95 nonLeafType = self.GetNodeType(inCurrentSourceNode)
96 if PhactoriDbg(100):
97 myDebugPrint3("inCurrentAlteredNode nonLeafType " + str(nonLeafType) + "\n")
98
99 if nonLeafType > 3:
100 myDebugPrint3AndException(
101 "PhactoriVtkDataExportOperation::UpdateAlteredVtkMultiBlockDataSetRecurse1\n"
102 "this is a leaf node or unexpected class here.\n"
103 "GetClassName(): " + str(inCurrentSourceNode.GetClassName()) + "\n")
104
105 if nonLeafType == 2:
106 numChildren = inCurrentSourceNode.GetNumberOfPieces()
107 elif nonLeafType == 3:
108 numChildren = inCurrentSourceNode.GetNumberOfPartitions()
109 else:
110 numChildren = inCurrentSourceNode.GetNumberOfBlocks()
111
112 if PhactoriDbg(100):
113 myDebugPrint3("nonLeafType: " + str(nonLeafType) + " numChildren: " + str(numChildren) + "\n")
114
115 if PhactoriDbg(100):
116 myDebugPrint3("begin quick children check\n")
117 for childIndex in range(0, numChildren):
118 if nonLeafType == 2:
119 oneChild = inCurrentSourceNode.GetPiece(childIndex)
120 elif nonLeafType == 3:
121 oneChild = inCurrentSourceNode.GetPartition(childIndex)
122 else:
123 oneChild = inCurrentSourceNode.GetBlock(childIndex)
124 if oneChild != None:
125 myDebugPrint3("childIndex " + str(childIndex) + " is " + str(oneChild.GetClassName()) + "\n")
126 else:
127 myDebugPrint3("childIndex " + str(childIndex) + " is None\n")
128 myDebugPrint3("end quick children check\n")
129
130 for childIndex in range(0, numChildren):
131 if PhactoriDbg(100):
132 myDebugPrint3("doing childIndex: " + str(childIndex) + "\n")
133
134 if nonLeafType == 2:
135 oneChild = inCurrentSourceNode.GetPiece(childIndex)
136 elif nonLeafType == 3:
137 oneChild = inCurrentSourceNode.GetPartition(childIndex)
138 else:
139 oneChild = inCurrentSourceNode.GetBlock(childIndex)
140
141 childMetaData = inCurrentSourceNode.GetMetaData(childIndex)
142 if childMetaData != None:
143 childName = childMetaData.Get(vtk.vtkCompositeDataSet.NAME())
144 else:
145 childName = None
146
147 if oneChild == None:
148 #for now, just add a None block to match
149 self.AddItemToMultiblockOrMultiPiece(nonLeafType, inCurrentAlteredNode, oneChild, childName)
150 if PhactoriDbg(100):
151 myDebugPrint3("done childIndex: " + str(childIndex) + " (oneChild was None)\n")
152 continue
153
154 childNodeType = self.GetNodeType(oneChild)
155
156 if PhactoriDbg(100):
157 myDebugPrint3("childIndex " + str(childIndex) + " childNodeType " + str(childNodeType) + " childName " + str(childName) + "\n")
158 if (childNodeType == 4) or (childNodeType == 5):
159 self.AddItemToMultiblockOrMultiPiece(nonLeafType, inCurrentAlteredNode, oneChild, childName)
160 elif (childNodeType == 0) or (childNodeType == 1):
161 #newAlteredNode = vtk.VtkMultiBlockDataSet()
162 #newAlteredNode = oneChild.NewInstance()
163 #we are just using self.OutVtkMultiBlockDataSet here to get
164 #access to the desired type of NewInstance regardless if
165 #childNodeType is 0 or 1
166 newAlteredNode = self.OutVtkMultiBlockDataSet.NewInstance()
167 newChildIndex = inCurrentAlteredNode.GetNumberOfBlocks()
168 self.AddItemToMultiblockOrMultiPiece(nonLeafType, inCurrentAlteredNode, newAlteredNode, childName)
169 self.UpdateAlteredVtkMultiBlockDataSetRecurse1(newAlteredNode, oneChild)
170 elif childNodeType == 2:
171 #newAlteredNode = vtk.VtkMultiPieceDataSet()
172 newAlteredNode = oneChild.NewInstance()
173 newChildIndex = inCurrentAlteredNode.GetNumberOfPieces()
174 self.AddItemToMultiblockOrMultiPiece(nonLeafType, inCurrentAlteredNode, newAlteredNode, childName)
175 self.UpdateAlteredVtkMultiBlockDataSetRecurse1(newAlteredNode, oneChild)
176 elif childNodeType == 3:
177 #for now we're making assumption all the partitions under here are leaf grids
178 numSubChildren = oneChild.GetNumberOfPartitions()
179 if PhactoriDbg(100):
180 myDebugPrint3("numSubChildren: " + str(numSubChildren) + "\n")
181 for subChildIndex in range(0, numSubChildren):
182 if PhactoriDbg(100):
183 myDebugPrint3("doing subChildIndex: " + str(subChildIndex) + "\n")
184 oneSubChild = oneChild.GetPartition(subChildIndex)
185
186 if oneSubChild == None:
187 self.AddItemToMultiblockOrMultiPiece(nonLeafType, inCurrentAlteredNode, oneSubChild, childName)
188 if PhactoriDbg(100):
189 myDebugPrint3("done subChildIndex: " + str(subChildIndex) + " (which was a None subchild)\n")
190 continue
191
192 subChildNodeType = self.GetNodeType(oneSubChild)
193 if PhactoriDbg(100):
194 myDebugPrint3("subChildIndex " + str(subChildIndex) + " subChildNodeType " + str(subChildNodeType) + "\n")
195 if (subChildNodeType == 4) or (subChildNodeType == 5):
196 if (nonLeafType == 0) or (nonLeafType == 1) or (nonLeafType == 2):
197 self.AddItemToMultiblockOrMultiPiece(nonLeafType, inCurrentAlteredNode, oneSubChild, childName)
198 else:
199 myDebugPrint3AndException(
200 "PhactoriVtkDataExportOperation::ParseParametersFromJson\n"
201 "unexpected nonLeafType at this place: " + str(nonLeafType) + "\n")
202 else:
203 myDebugPrint3AndException(
204 "PhactoriVtkDataExportOperation::ParseParametersFromJson\n"
205 "unexpected subChildNodeType at this place: " + str(subChildNodeType) + "\n")
206 if PhactoriDbg(100):
207 myDebugPrint3("done subChildIndex: " + str(subChildIndex) + "\n")
208 else:
209 myDebugPrint3AndException(
210 "PhactoriVtkDataExportOperation::ParseParametersFromJson\n"
211 "unexpected childNodeType\n")
212 if PhactoriDbg(100):
213 myDebugPrint3("done childIndex: " + str(childIndex) + "\n")
214
215 if PhactoriDbg(100):
216 myDebugPrint3("PhactoriVtkDataExportOperation.ExportOperationData returning\n")
217
218
219 def MakeOrUpdateVtkMultiBlockDataSetWithtoutVtkPartitionedDataSets(self, inVtkMultiBlockDataSet):
220 if self.OutVtkMultiBlockDataSet == None:
221 self.OutVtkMultiBlockDataSet = inVtkMultiBlockDataSet.NewInstance()
222 else:
223 self.OutVtkMultiBlockDataSet.SetNumberOfBlocks(0)
224 self.UpdateAlteredVtkMultiBlockDataSetRecurse1(self.OutVtkMultiBlockDataSet, inVtkMultiBlockDataSet)
225
226 def DoUpdateDueToChangeInData(self, inIncomingPvFilter,
227 outOutgoingPvFilter):
228 #default behavior is to do nothing on new data
229 if PhactoriDbg():
230 myDebugPrint3("PhactoriPartitionedToMultiBlockOperation.DoUpdateDueToChangeInData entered\n")
231 if self.InputFilter != None:
232 if PhactoriDbg():
233 myDebugPrint3("self.InputFilter != None; updating\n")
234 UpdatePipelineWithCurrentTimeArgument(self.InputFilter)
235 theVtkMultiBlockDataSetObject = self.InputFilter.GetClientSideObject().GetOutputDataObject(0)
236 self.MakeOrUpdateVtkMultiBlockDataSetWithtoutVtkPartitionedDataSets(theVtkMultiBlockDataSetObject)
237 UpdatePipelineWithCurrentTimeArgument(self.OutputPVTrivialProducer)
238 if PhactoriDbg():
239 myDebugPrint3("PhactoriPartitionedToMultiBlockOperation.DoUpdateDueToChangeInData returning\n")
240 return True
241
242 def CreateParaViewFilter(self, inInputFilter):
243 """create the PartitionedToMultiBlock filter for ParaView"""
244 if PhactoriDbg(100):
245 myDebugPrint3("PhactoriPartitionedToMultiBlockOperation.CreateParaViewFilter "
246 "entered\n", 100)
247
248 savedActiveSource = GetActiveSource()
249
250 UpdatePipelineWithCurrentTimeArgument(inInputFilter)
251
252 self.InputFilter = inInputFilter
253 theVtkMultiBlockDataSetObject = self.InputFilter.GetClientSideObject().GetOutputDataObject(0)
254
255 self.MakeOrUpdateVtkMultiBlockDataSetWithtoutVtkPartitionedDataSets(theVtkMultiBlockDataSetObject)
256
257 #make trivial producer with this block
258 newParaViewFilter = PVTrivialProducer()
259 newParaViewFilter.GetClientSideObject().SetOutput(self.OutVtkMultiBlockDataSet)
260
261 self.OutputPVTrivialProducer = newParaViewFilter
262
263 if PhactoriDbg(100):
264 myDebugPrint3("PhactoriPartitionedToMultiBlockOperation.CreateParaViewFilter "
265 "returning\n", 100)
266
267 return newParaViewFilter
268
269 #phactori_combine_to_single_python_file_subpiece_end_1