Debian Codegraph @

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

raw
1 # Copyright(C) 1999-2020, 2024 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 from Operation.PhactoriMpiUtilities import *
36 try:
37 from .PhactoriParaviewMultiBlockRecursion import *
38 except:
39 from Operation.PhactoriParaviewMultiBlockRecursion import *
40
41 #phactori_combine_to_single_python_file_subpiece_begin_1
42 class PhactoriThresholdOperation(PhactoriOperationSpecifics):
43 """Threshold operation, phactori interface adapter to the catalyst filter
44
45 PhactoriThresholdOperation is the phactori manager for working with the
46 paraview/catalyst Threshold() operation and its paramters, providing
47 access and pipeline/input/output managment via the json, lexx/yacc, or soon
48 yaml interface. The user may specify a named input to the filter, with the
49 unnamed default being the incoming data mesh.
50
51 For detailed information on the Threshold filter from ParaView, see the
52 ParaView Documentation. The basic operation of the Threshold filter is to
53 extract all cells and points for which cell or point mesh variable (e.g.
54 pressure, temperature, vonmises, displacement) is inside a specified range.
55
56 To add a PhactoriThresholdOperation to the incoming script, you add
57 a sub-block to the "operation blocks" section of the data with the "type"
58 key given a value of "threshold". You also specify one of a range of values
59 to keep, a value below which to keep values above, or a value above which to
60 keep points/nodes. One complete but simple example
61 script:
62
63 ::
64
65 {
66 "camera blocks":{"mycam1":{"type":"camera", "look direction":[1.0, 2.0, 3.0]}},
67 "representation blocks":{"rep_tmprtr":{"color by scalar":"temperature"}},
68 "imageset blocks":{
69 "temperature_on_slice_1":{
70 "operation":"mytempthrsh1",
71 "camera":"mycam1",
72 "representation":"rep_tmprtr",
73 "image basedirectory":"CatalystOutput",
74 "image basename":"threshold1_temperature."
75 }
76 },
77 "operation blocks":{
78 "mytempthrsh1":{
79 "type":"threshold",
80 "variable scalar":"temperature",
81 "keep between":[10.0, 100.0]
82 }
83 }
84 }
85
86 Rather than "keep between" with a min/max range you can also have "keep above" with a single value or "keep below" with a single value, e.g.
87
88 ::
89
90 "keep above": 100.0
91 or
92 "keep below": 10.0
93
94 """
95
96 def __init__(self):
97 PhactoriOperationSpecifics.__init__(self)
98 #self.mVariableName = None
99 #self.mElementOrNode = ""
100 self.mVariableInfo = PhactoriVariableInfo()
101 self.mRange = [0.0, 1.0]
102
103 #flag allows system to be set up to bypass this operation, especially
104 #for testing camera settings against geometry without thresholds,
105 #iso surfaces messing the tests up
106 self.mBypassFlag = False
107
108 def DoUpdateDueToChangeInData(self, inIncomingPvFilter,
109 outOutgoingPvFilter):
110 """the PhactoriThresholdOperation may need to update if the variable type
111 was not detectable in a previous callback, but is now detectable"""
112 if PhactoriDbg():
113 myDebugPrint3("PhactoriThresholdOperation::"
114 "DoUpdateDueToChangeInData override executing\n")
115
116 #BarrierLock("PhactoriThresholdOperation sync 700")
117
118 if self.mVariableInfo.mVariableTypeNeedsDetection == True:
119 UpdatePipelineWithCurrentTimeArgument(inIncomingPvFilter)
120 self.HandleVariableNeedingDetection(inIncomingPvFilter,
121 outOutgoingPvFilter)
122 if self.mVariableInfo.mVariableTypeNeedsDetection == False:
123 UpdatePipelineWithCurrentTimeArgument(outOutgoingPvFilter)
124
125
126 def ParseParametersFromJson(self, inJson):
127
128 self.mBypassFlag = getParameterFromBlock(inJson, 'bypass flag',
129 self.mBypassFlag)
130 if self.mBypassFlag == True:
131 #this operation is bypassed: don't do other parsing
132 return
133
134 foundVariableFlag = self.mVariableInfo.\
135 ParseVariableNameAndVectorOrTensorComponent(inJson, 'variable ')
136
137 if foundVariableFlag == False:
138 errStr = """error! inJson has no variable info in
139 PhactoriThresholdOperation.ParseParametersFromJson\n"""
140 if PhactoriDbg():
141 myDebugPrint3(errStr)
142 raise Exception(errStr)
143
144 #self.mVariableName = inJson['variable']
145
146 #if 'variable type' in inJson:
147 # self.mElementOrNode = inJson['variable type']
148 # if self.mElementOrNode != 'element' and self.mElementOrNode != 'node':
149 # errStr = "error! inJson 'variable type' is neither node nor\nelement PhactoriThresholdOperation.ParseParametersFromJson\n"
150 # myDebugPrint3(errStr)
151 # raise Exception(errStr)
152 #else:
153 # errStr = "error! inJson has no 'variable type' key in\nPhactoriThresholdOperation.ParseParametersFromJson\n"
154 # myDebugPrint3(errStr)
155 # raise Exception(errStr)
156
157 if 'keep between' in inJson:
158 self.mRange = inJson['keep between']
159 elif 'keep below' in inJson:
160 rangeMin = -sys.float_info.max
161 rangeMax = inJson['keep below']
162 self.mRange = [rangeMin, rangeMax]
163 elif 'keep above' in inJson:
164 rangeMin = inJson['keep above']
165 rangeMax = sys.float_info.max
166 self.mRange = [rangeMin, rangeMax]
167 else:
168 if PhactoriDbg():
169 myDebugPrint3(" no keep between/above/below, using keep above 0.0\n")
170 rangeMin = 0.0
171 rangeMax = sys.float_info.max
172 self.mRange = [rangeMin, rangeMax]
173
174 def HandleVariableNeedingDetection(self, inIncomingPvFilter,
175 outOutgoingPvFilter):
176
177 detectResult = self.mVariableInfo.DetectVariableType(
178 inIncomingPvFilter, True)
179
180 if self.mVariableInfo.mVariableType == 'element':
181 scalarType = 'CELLS'
182 elif self.mVariableInfo.mVariableType == 'node':
183 scalarType = 'POINTS'
184 else:
185 errStr = """error! in PhactoriThresholdOperation.CreateParaViewFilter
186 variable type is not element or node or detect but:
187 """ + \
188 str(self.mVariableInfo.mVariableType) + \
189 """\n"""
190 if PhactoriDbg():
191 myDebugPrint3(errStr)
192 raise Exception(errStr)
193
194 #hack to deal with how paraview/catalyst expects naming of threshold
195 #variables which are vector components or magnitudes
196
197 localVariableName = GetThresholdContourHackVariableNameString(self.mVariableInfo)
198
199 if PhactoriDbg():
200 myDebugPrint3(' name for variable in threshold: ' + localVariableName + '\n')
201 outOutgoingPvFilter.Scalars = [scalarType, localVariableName]
202
203 def CreateParaViewFilter(self, inInputFilter):
204 """create the threshold filter for ParaView"""
205 if PhactoriDbg(100):
206 myDebugPrint3('PhactoriThresholdOperation.CreateParaViewFilter entered\n', 100)
207 #info in block class should already be parsed and checked
208
209 #if the operation bypass flag is set to true, we want this
210 #operation to do nothing and just pass the input to the output
211 if self.mBypassFlag == True:
212 if PhactoriDbg():
213 myDebugPrint3("PhactoriThresholdOperation::CreateParaViewFilter\n" +
214 "mBypassFlag was true, so paraview output filter is input filter")
215 return inInputFilter
216
217 savedActiveSource = GetActiveSource()
218
219 UpdatePipelineWithCurrentTimeArgument(inInputFilter)
220
221 #BarrierLock("PhactoriThresholdOperation sync 100")
222 if PhactoriDbg():
223 numCellArrays = inInputFilter.CellData.GetNumberOfArrays()
224 myDebugPrint3("before threshold cell numCellArrays: " + str(numCellArrays) + "\n")
225 for ii in range(0, numCellArrays):
226 myDebugPrint3(inInputFilter.CellData.GetArray(ii).Name + "\n")
227
228 newParaViewFilter = Threshold(inInputFilter)
229 global gParaViewCatalystVersionFlag
230 if gParaViewCatalystVersionFlag < 51000:
231 newParaViewFilter.ThresholdRange = self.mRange
232 else:
233 newParaViewFilter.LowerThreshold = self.mRange[0]
234 newParaViewFilter.UpperThreshold = self.mRange[1]
235 newParaViewFilter.ThresholdMethod = vtk.vtkThreshold.THRESHOLD_BETWEEN
236
237 self.HandleVariableNeedingDetection(inInputFilter, newParaViewFilter)
238
239 SetActiveSource(newParaViewFilter)
240 SetActiveSource(savedActiveSource)
241 #AddFilterToFilterMap(ioOperationBlock.mName, newParaViewFilter)
242
243 if PhactoriDbg(100):
244 RecursivelyPrintPointAndCellArrayInformation(inInputFilter)
245
246 #inputSource = GetActiveSource()
247 UpdatePipelineWithCurrentTimeArgument(newParaViewFilter)
248 if PhactoriDbg():
249 numCellArrays = newParaViewFilter.CellData.GetNumberOfArrays()
250 myDebugPrint3("after threshold cell numCellArrays: " + str(numCellArrays) + "\n")
251 for ii in range(0, numCellArrays):
252 myDebugPrint3(newParaViewFilter.CellData.GetArray(ii).Name + "\n")
253
254 if PhactoriDbg(100):
255 myDebugPrint3('PhactoriThresholdOperation.CreateParaViewFilter returning\n', 100)
256
257 return newParaViewFilter
258
259 #phactori_combine_to_single_python_file_subpiece_end_1