Debian Codegraph @

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

raw
1 # Copyright(C) 1999-2022 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 PhactoriVariableMinMaxAvgSumCntSave:
38 def __init__(self):
39 self.mStatsTestCounter = -1
40 self.mMin = 0.0
41 self.mMax = 0.0
42 self.mSum = 0.0
43 self.mCount = 0
44 self.mIdsTestCounter = -1
45 self.mLocalFoundMinId = False
46 self.mLocalMinIdCount = -1
47 self.mMinId = -1;
48 self.mLocalFoundMaxId = False
49 self.mLocalMaxIdCount = -1
50 self.mMaxId = -1;
51
52 class PhactoriVariableInfo:
53 def __init__(self):
54 self.mVariableIntendedForUseFlag = False
55 self.mVariableName = ""
56 self.mVariableComponent = None
57 self.mVariableType = None
58 self.mVariableTypeNeedsDetection = False
59 self.mVariableTypeWasDetected = False
60 self.mVariableTypeWasCopied = False
61 self.mVariableIsVectorMagnitude = False
62 self.mVariableIsVectorComponent = False
63 self.mVectorBaseName = None
64 self.mStats = PhactoriVariableMinMaxAvgSumCntSave()
65 #as of 2022Aug09 we want this to default to False
66 self.mAddSeparatorToVectorVariableName = False
67
68 def SelfToStr(self):
69 retStr = "PhactoriVariableInfo:\n" +\
70 "\n mVariableName: " + str(self.mVariableName) +\
71 "\n mVariableComponent: " + str(self.mVariableComponent) +\
72 "\n mVariableType: " + str(self.mVariableType) +\
73 "\n mVariableTypeNeedsDetection: " + str(self.mVariableTypeNeedsDetection) +\
74 "\n mVariableTypeWasDetected: " + str(self.mVariableTypeWasDetected) +\
75 "\n mVariableTypeWasCopied: " + str(self.mVariableTypeWasCopied) +\
76 "\n mVariableIsVectorMagnitude: " + \
77 str(self.mVariableIsVectorMagnitude) +\
78 "\n mVariableIsVectorComponent: " + \
79 str(self.mVariableIsVectorComponent) +\
80 "\n mVectorBaseName: " + str(self.mVectorBaseName) +\
81 "\n mVariableIntendedForUseFlag: " + str(self.mVariableIntendedForUseFlag) +\
82 "\n"
83 return retStr
84
85 def CheckAndParseScalarVariable1(self, inJson, inBaseString):
86 testKey = inBaseString + 'scalar'
87 if testKey in inJson:
88 self.mVariableName = inJson[testKey]
89 self.mVariableComponent = None
90 return True
91 else:
92 return False
93
94 def CheckAndParseVectorComponentNumber1(self, inJson, inBaseString):
95 testKey = inBaseString + 'vector component number'
96 if testKey in inJson:
97 self.mVariableIsVectorComponent = True
98 varCompNumPair = inJson[testKey]
99 self.mVariableName = varCompNumPair[0]
100 self.mVariableComponent = int(varCompNumPair[1])
101 return True
102 else:
103 return False
104
105 def CheckAndParseVectorComponentSuffix(self, inJson, inBaseString):
106 testKey = inBaseString + 'vector component'
107 if testKey in inJson:
108 self.mVariableIsVectorComponent = True
109 varName = inJson[testKey]
110 resultPair = breakSpecialVarNameIntoBaseAndComponent(varName,
111 self.mAddSeparatorToVectorVariableName)
112 self.mVariableName = resultPair[0]
113 self.mVariableComponent = resultPair[1]
114 self.mVectorBaseName = resultPair[2]
115 return True
116 else:
117 return False
118
119 def CheckAndParseVectorMagnitude(self, inJson, inBaseString):
120 testKey = inBaseString + 'vector magnitude'
121 if testKey in inJson:
122 self.mVariableIsVectorMagnitude = True
123 if self.mAddSeparatorToVectorVariableName:
124 self.mVariableName = inJson[testKey] + GetSeparatorString()
125 else:
126 self.mVariableName = inJson[testKey]
127 self.mVectorBaseName = inJson[testKey]
128 return True
129 else:
130 return False
131
132 def CheckAndParseTensorComponent(self, inJson, inBaseString):
133 testKey = inBaseString + 'tensor component'
134 if testKey in inJson:
135 self.mVariableName = inJson[testKey]
136 return True
137 else:
138 return False
139
140 def CheckAndParseVectorVariable1(self, inJson, inBaseString):
141 variableFoundFlag = False
142 variableFoundFlag = self.CheckAndParseVectorComponentNumber1(inJson, inBaseString)
143 if not variableFoundFlag:
144 variableFoundFlag = self.CheckAndParseVectorComponentSuffix(inJson, inBaseString)
145 if not variableFoundFlag:
146 variableFoundFlag = self.CheckAndParseVectorMagnitude(inJson, inBaseString)
147 if not variableFoundFlag:
148 variableFoundFlag = self.CheckAndParseTensorComponent(inJson, inBaseString)
149 if not variableFoundFlag:
150 variableFoundFlag = False
151 self.mVariableName = ''
152 self.mComponent = None
153 return variableFoundFlag
154
155 def ParseVariableNameAndVectorOrTensorComponent(self, inJson, inBaseString):
156 "take a base string such as 'y axis variable ' or 'variable ', use it\n to construct keys to define a scalar variable, vector component, vector\n magnitude, or tensor component, and see if the json has those keys.\n If the json has a key, use it to grab the variable name and setup.\n Also look to see if the type of the variable is specifically defined\n (node or element) or needs to be detected\n "
157 variableFoundFlag = False
158 self.mVariableIsVectorComponent = False
159 self.mVariableIsVectorMagnitude = False
160
161 if 'add separator to vector variable name' in inJson:
162 self.mAddSeparatorToVectorVariableName = \
163 inJson['add separator to vector variable name']
164
165 variableFoundFlag = self.CheckAndParseScalarVariable1(inJson, inBaseString)
166 if not variableFoundFlag:
167 variableFoundFlag = self.CheckAndParseVectorVariable1(inJson, inBaseString)
168 if variableFoundFlag:
169 #it is now apparent variable is intended to be used, not ignored
170 self.mVariableIntendedForUseFlag = True
171 if 'variable type' in inJson:
172 variableType = inJson['variable type']
173 self.mVariableType = variableType
174 if variableType != 'element' \
175 and variableType != 'node' \
176 and variableType != 'global' \
177 and variableType != 'detect':
178 errStr = 'error! inJson has variable type is neither node nor '\
179 'element nor detect nor global in ParseVariableNameAndVectorOrTensorComponent\n'
180 if PhactoriDbg():
181 myDebugPrint3(errStr)
182 raise Exception(errStr)
183 if variableType == 'detect':
184 self.mVariableType = 'element'
185 self.mVariableTypeNeedsDetection = True
186 self.mVariableTypeWasDetected = False
187 elif variableType == 'element':
188 self.mVariableType = 'element'
189 self.mVariableTypeNeedsDetection = False
190 self.mVariableTypeWasDetected = True
191 elif variableType == 'node':
192 self.mVariableType = 'node'
193 self.mVariableTypeNeedsDetection = False
194 self.mVariableTypeWasDetected = True
195 elif variableType == 'global':
196 self.mVariableType = 'global'
197 self.mVariableTypeNeedsDetection = False
198 self.mVariableTypeWasDetected = True
199 else:
200 self.mVariableType = 'element'
201 self.mVariableTypeNeedsDetection = True
202 self.mVariableTypeWasDetected = False
203 else:
204 self.mVariableType = None
205
206 if PhactoriDbg():
207 str1 = "ParseVariableNameAndVectorOrTensorComponent:\n"
208 str2 = "inBaseString:\n" + str(inBaseString) + "\n"
209 str3 = "inJson:\n" + str(inJson) + "\n"
210 str4 = "instance state after parsing:\n" + self.SelfToStr()
211 myDebugPrint3(str1 + str2 + str3 + str4)
212 return variableFoundFlag
213
214 def CopyVariableTypeFrom(self, inSourceVariableInfo):
215 self.mVariableType = inSourceVariableInfo.mVariableType
216 self.mVariableTypeNeedsDetection = False
217 self.mVariableTypeWasDetected = True
218 self.mVariableTypeWasCopied = True
219
220 def DetectVariableType(self, inInputCsData, inInputIsProxy = False,
221 inAllowGlobalVariableDetection = False):
222
223 if self.mVariableTypeNeedsDetection == False:
224 return True
225
226 #testing hack--force to cell
227 #self.mVariableTypeNeedsDetection = False
228 #self.mVariableTypeWasDetected = True
229 #self.mVariableType = 'element'
230 #return
231
232 if PhactoriDbg():
233 myDebugPrint3('PhactoriVariableInfo::DetectVariableType entered\n')
234
235 if inInputIsProxy:
236 pointData = inInputCsData.PointData
237 else:
238 pointData = inInputCsData.GetPointData()
239 if pointData != None:
240 testPointArray = pointData.GetArray(self.mVariableName)
241 if testPointArray != None:
242 if PhactoriDbg():
243 myDebugPrint3(' type node detected!\n')
244 self.mVariableType = 'node'
245 self.mVariableTypeNeedsDetection = False
246 self.mVariableTypeWasDetected = True
247 return True
248
249 if inInputIsProxy:
250 cellData = inInputCsData.CellData
251 else:
252 cellData = inInputCsData.GetCellData()
253 if cellData != None:
254 testCellArray = cellData.GetArray(self.mVariableName)
255 if testCellArray != None:
256 if PhactoriDbg():
257 myDebugPrint3(' type element detected!\n')
258 self.mVariableType = 'element'
259 self.mVariableTypeNeedsDetection = False
260 self.mVariableTypeWasDetected = True
261 return True
262
263 if inAllowGlobalVariableDetection:
264 if inInputIsProxy:
265 fieldData = inInputCsData.FieldData
266 else:
267 fieldData = inInputCsData.GetFieldData()
268 if fieldData != None:
269 testFieldArray = fieldData.GetArray(self.mVariableName)
270 if testFieldArray != None:
271 if PhactoriDbg():
272 myDebugPrint3(' type global detected!\n')
273 self.mVariableType = 'global'
274 self.mVariableTypeNeedsDetection = False
275 self.mVariableTypeWasDetected = True
276 return True
277
278 if PhactoriDbg():
279 myDebugPrint3(' type not detected!\n')
280 #default to 'element' type knowing assumption may be wrong,
281 #leave mVariableTypeNeedsDetection set to True so we know the variable
282 #type has not yet been successfully detected
283 self.mVariableType = 'element'
284 #self.mVariableType = 'node'
285 return False
286
287 def GetXYPlotAxisTitle(self):
288 """for this variable info, construct the name to put on the axis of an XY
289 plot, e.g. with magnitude or component information"""
290
291 if self.mVariableName[-1] == '_':
292 axisTitle = str(self.mVariableName[0:-1])
293 else:
294 axisTitle = self.mVariableName
295
296 if self.mVariableIsVectorComponent:
297 if self.mVariableComponent == 0:
298 axisTitle += ' X component'
299 elif self.mVariableComponent == 1:
300 axisTitle += ' Y component'
301 elif self.mVariableComponent == 2:
302 axisTitle += ' Z component'
303 else:
304 if PhactoriDbg():
305 myDebugPrint3(" variable component is not 0, 1, or 2, using 0 (X)\n")
306 localVariableName = self.mVariableName + '_X'
307 elif self.mVariableIsVectorMagnitude:
308 axisTitle += " Magnitude"
309
310 return axisTitle
311
312 #phactori_combine_to_single_python_file_subpiece_end_1