Debian Codegraph @

packages/seacas/libraries/ioss/src/visualization/catalyst/phactori/PhactoriDriver_modular.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 try: paraview.simple
34 except: from paraview.simple import *
35
36 from paraview import coprocessing
37
38 # ----------------------- Pipeline definition -----------------------
39
40 from phactori import *
41
42 #do sierra/catalyst logging (from process id 0 only)
43 #note: logging should be disabled for testing, but enabled for production
44 if SmartGetLocalProcessId() == 0:
45 import os
46 import datetime
47
48 loggingIsEnabled = True
49 if "SNL_CATALYST_SIERRA_USAGE_LOG_FLAG" in os.environ:
50 #print "SNL_CATALYST_SIERRA_USAGE_LOG_FLAG environment variable: " + \
51 #os.environ["SNL_CATALYST_SIERRA_USAGE_LOG_FLAG"]
52 if os.environ["SNL_CATALYST_SIERRA_USAGE_LOG_FLAG"] == "disable":
53 loggingIsEnabled = False
54
55 if loggingIsEnabled:
56 #print "I am process 0 doing logging!"
57 if "HOSTNAME" in os.environ:
58 os.environ["LOG_PLATFORM"] = os.environ["HOSTNAME"]
59 else:
60 os.environ["LOG_PLATFORM"] = "HOSTNAMEnotset"
61 os.environ["LOG_PRODUCT"] = "sierra-catalyst"
62 os.environ["CATALYST_VERSION"] = "p4.1.0-s4.31.6-p"
63 nowdate = datetime.datetime.now()
64 #os.environ["DATE"] = str(nowdate.month) + "/" + str(nowdate.day) + "/" + str(nowdate.year)
65 #currently, DATE environment variable is overwritten in logParserScr script
66 #print "date is : " + os.environ["DATE"]
67 import subprocess
68 try:
69 subprocess.call("/projects/viz/catalyst/utilities/logParserScr")
70 except:
71 print("usage logging warning: logParserScr call failed\n")
72
73 #print "platform: " + os.environ["LOG_PLATFORM"]
74 #print "product: " + os.environ["LOG_PRODUCT"]
75 #print "version: " + os.environ["CATALYST_VERSION"]
76 #print "date: ->" + os.environ["DATE"] + "<-"
77 #print "I am process 0 done logging!"
78 #else:
79 #print "I am process 0, logging disabled in environment variable"
80
81 #def UseViewMapB(inViewMapB):
82 # PhactoriScript.UseViewMapB_ps(inViewMapB)
83
84 #def UseDataSetupMapB(inDataSetupMapB):
85 # PhactoriScript.UseDataSetupMapB_ps(inDataSetupMapB)
86
87 global gMyInitialUpdateFrequencies
88 gMyInitialUpdateFrequencies = {}
89
90 def CreateCoProcessor():
91 def _CreatePipeline(coprocessor, datadescription):
92 class Pipeline:
93 dummyItem = "blah"
94 #global cp_views, cp_writers
95
96 #print "CreatePipeline startup"
97 #print "cp_views len is " + str(len(cp_views))
98
99 #rigid_body_impact_6_ff_e = coprocessor.CreateProducer( datadescription, "input" )
100
101 #SetUpCoProcessor(coprocessor)
102 #SetCpViewsAndCpWriters(cp_views, cp_writers)
103
104 #QQQQQ->we want to do this and CreateProducer once for each output results block,
105 #reuse same coprocesor instance (?), then have LocalWriteImages3 only do the images for a given output results bloxk:q
106
107 #PhactoriScript.CreatePipeline(datadescription)
108
109 return Pipeline()
110
111 class CoProcessor(coprocessing.CoProcessor):
112 def CreatePipeline(self, datadescription):
113 self.Pipeline = _CreatePipeline(self, datadescription)
114
115 def LocalWriteImages3(self, datadescription, rescale_lookuptable=False):
116 WriteImagesForCurrentPipeAndViewsState(datadescription)
117
118 def LocalExportOperationsData3(self, datadescription, rescale_lookuptable=False):
119 ExportOperationsDataForCurrentPipeAndViewsState(datadescription)
120
121 def SetInitialUpdateFrequences(self, datadescription):
122 global gMyInitialUpdateFrequencies
123 freqsChanged = False
124 numInputGrids = datadescription.GetNumberOfInputDescriptions()
125 for ii in range(0,numInputGrids):
126 oneGridName = datadescription.GetInputDescriptionName(ii)
127 if PhactoriDbg():
128 myDebugPrint3("SetInitialUpdateFrequences " + str(ii) + " " + str(oneGridName) + "\n")
129 if oneGridName not in gMyInitialUpdateFrequencies:
130 gMyInitialUpdateFrequencies[oneGridName] = [1]
131 freqsChanged = True
132 if PhactoriDbg():
133 if freqsChanged:
134 myDebugPrint3("gMyInitialUpdateFrequencies changed:\n")
135 else:
136 myDebugPrint3("gMyInitialUpdateFrequencies not changed:\n")
137 myDebugPrint3(str(gMyInitialUpdateFrequencies) + "\n")
138 if freqsChanged:
139 self.SetUpdateFrequencies(gMyInitialUpdateFrequencies)
140
141 coprocessor = CoProcessor()
142 #freqs = {'input': [1]}
143 #coprocessor.SetUpdateFrequencies(freqs)
144 return coprocessor
145
146
147 #--------------------------------------------------------------
148 # Global variables that will hold the pipeline for each timestep
149 # Creating the CoProcessor object, doesn't actually create the ParaView pipeline.
150 # It will be automatically setup when coprocessor.UpdateProducers() is called the
151 # first time.
152 #coprocessor = CreateCoProcessor()
153 coprocessor = None
154
155 #--------------------------------------------------------------
156 # Enable Live-Visualizaton with ParaView
157 #coprocessor.EnableLiveVisualization(False)
158
159 global gDoNewScatterPlotsC
160 gDoNewScatterPlotsC = True
161 #gDoNewScatterPlotsC = False
162
163 def PerFrameUpdate(datadescription):
164 PerRendersetInitialization(datadescription)
165 UpdateAllOperationsWhichMayChangeWithData()
166 UpdateAllImagesetViewsWhichMayChangeWithData()
167
168 #we are now updating color range stuff right before WriteImage
169 #UpdateDataRangesForColorValues()
170
171 myDebugPrint3('PerFrameUpdate entered\n')
172 #GetAndReduceViewControl()
173 global tearListPersistent
174 global deathListPersistent
175
176 global gDoNewScatterPlotsC
177 if gDoNewScatterPlotsC:
178 myDebugPrint3('doing UpdateAllScatterPlots (C)\n')
179 UpdateAllScatterPlots()
180 myDebugPrint3('doing UpdateAllPlotsOverTime\n')
181 UpdateAllPlotsOverTime()
182 myDebugPrint3('did plot updates\n')
183
184 #currentFrameTearList = CollectCells1('TEAR_DOUBLE', 0.01, 1)
185 #tearListPersistent = mergeCurrentIntoPersistent(tearListPersistent,
186 # currentFrameTearList)
187 #currentFrameDeathList = CollectCells1('STATUS', 0.8, -1)
188 #deathListPersistent = mergeCurrentIntoPersistent(deathListPersistent,
189 # currentFrameDeathList)
190 #compareTearDeath(tearListPersistent, deathListPersistent)
191
192 myDebugPrint3('PerFrameUpdate exiting\n')
193
194
195 #begin tear/death persistence; not used now but may be useful later
196 global tearListPersistent
197 tearListPersistent = []
198 global deathListPersistent
199 deathListPersistent = []
200
201 def mergeCipCompare(item1, item2):
202 if item1[1] > item2[1]:
203 return 1
204 if item1[1] < item2[1]:
205 return -1
206 if item1[2] > item2[2]:
207 return 1
208 if item1[2] < item2[2]:
209 return -1
210 return 0
211
212 def mergeCurrentIntoPersistent(pList, cList):
213 myDebugPrint2('mergeCurrentIntoPersistent entered\n')
214 pListLen = len(pList)
215 cListLen = len(cList)
216 myDebugPrint2(' pList has ' + str(pListLen) + ' elements, cList has ' + str(cListLen) + ' elements\n')
217 pIndex = 0
218 cIndex = 0
219 mergeList = []
220 while (pIndex < pListLen) or (cIndex < cListLen):
221 if(pIndex >= pListLen):
222 mergeList.append(cList[cIndex])
223 #myDebugPrint2(' pIndex ' + str(pIndex) + ' cIndex ' + str(cIndex) + '\n')
224 #myDebugPrint2(' (p ended) [cIndex] ' + str(cList[cIndex]) + '\n')
225 cIndex += 1
226 continue
227 if(cIndex >= cListLen):
228 mergeList.append(pList[pIndex])
229 #myDebugPrint2(' pIndex ' + str(pIndex) + ' cIndex ' + str(cIndex) + '\n')
230 #myDebugPrint2(' (c ended) [pIndex] ' + str(cList[pIndex]) + '\n')
231 pIndex += 1
232 continue
233 compareResult = mergeCipCompare(cList[cIndex], pList[pIndex])
234 #myDebugPrint2(' pIndex ' + str(pIndex) + ' cIndex ' + str(cIndex) + '\n')
235 #myDebugPrint2(' [pIndex] ' + str(pList[pIndex]) + ' [cIndex] ' + str(cList[cIndex]) + '\n')
236 if compareResult == 1:
237 #myDebugPrint2(' item from pList is less\n')
238 mergeList.append(pList[pIndex])
239 pIndex += 1
240 if compareResult == -1:
241 #myDebugPrint2(' item from cList is less\n')
242 mergeList.append(cList[cIndex])
243 cIndex += 1
244 if compareResult == 0:
245 #myDebugPrint2(' items from cList and pList are same element\n')
246 mergeList.append(pList[pIndex])
247 pIndex += 1
248 cIndex += 1
249 myDebugPrint2(' merged list has ' + str(len(mergeList)) + ' elements\n')
250 myDebugPrint2('mergeCurrentIntoPersistent returning\n')
251 return mergeList
252
253 def compareTearDeath(tList, dList):
254 myDebugPrint2('compareTearDeath entered\n')
255 myDebugPrint2('compareTearDeath returning\n')
256 #end tear/death persistence; not used now but may be useful later
257
258
259 # ---------------------- Data Selection method ----------------------
260
261 global gFirstTimeInDoCoProcessing
262 gFirstTimeInDoCoProcessing = True
263 global gSkipCountdown
264 #gSkipCountdown = 3
265 gSkipCountdown = 0
266
267 global gCatchAllExceptionsAndPassUpFlag
268 gCatchAllExceptionsAndPassUpFlag = True
269 #gCatchAllExceptionsAndPassUpFlag = False
270
271 def RequestDataDescription(datadescription):
272 myDebugPrint3("PhactoriDriver.RequestDataDescription entered: " + str(gDoCoProcessingCount)+ "\n");
273 if PhactoriDbg():
274 numInputGrids = datadescription.GetNumberOfInputDescriptions()
275 for ii in range(0,numInputGrids):
276 oneGridName = datadescription.GetInputDescriptionName(ii)
277 myDebugPrint3("RequestDataDescription " + str(ii) + " " + str(oneGridName) + "\n")
278
279 TestUserDataForBypassScript(datadescription)
280
281 if GetBypassUserDataFlag() == False:
282 fd = datadescription.GetUserData()
283
284 if fd == None:
285 myDebugPrint2("no user data, returning {}\n")
286 returnViewMapC = {}
287 return returnViewMapC
288
289 global gCatchAllExceptionsAndPassUpFlag
290 if gCatchAllExceptionsAndPassUpFlag:
291 try:
292 return RequestDataDescriptionSub(datadescription)
293 except:
294 import traceback
295 tb = traceback.format_exc()
296 IssueErrorOrWarningThroughSierraIO(datadescription, tb, True)
297 else:
298 return RequestDataDescriptionSub(datadescription)
299
300 def RequestDataDescriptionSub(datadescription):
301 myDebugPrint("PhactoriDriver.RequestDataDescriptionSub entered\n");
302 "Callback to populate the request for current timestep"
303
304 TestUserDataForBypassScript(datadescription)
305
306 if GetBypassUserDataFlag() == False:
307 fd = datadescription.GetUserData()
308
309 if fd == None:
310 myDebugPrint2("no user data, returning {}\n")
311 returnViewMapC = {}
312 return returnViewMapC
313
314 global coprocessor
315
316 global gFirstTimeInDoCoProcessing
317 global gSkipCountdown
318
319 if gFirstTimeInDoCoProcessing == True:
320 myDebugPrint2("RequestDataDescription doing gFirstTimeInDoCoProcessing\n")
321 myDebugPrint2(" skip countdown is " + str(gSkipCountdown) + "\n")
322 if gSkipCountdown > 0:
323 gSkipCountdown = gSkipCountdown - 1
324 return 0
325 coprocessor = CreateCoProcessor()
326 coprocessor.SetInitialUpdateFrequences(datadescription)
327 coprocessor.EnableLiveVisualization(False)
328 gFirstTimeInDoCoProcessing = False
329 else:
330 coprocessor.SetInitialUpdateFrequences(datadescription)
331
332 #import pdb
333 #pdb.set_trace()
334
335 InitializePerPipeRoot(datadescription, coprocessor)
336
337 if datadescription.GetForceOutput() == True:
338 # We are just going to request all fields and meshes from the simulation
339 # code/adaptor.
340 for i in range(datadescription.GetNumberOfInputDescriptions()):
341 datadescription.GetInputDescription(i).AllFieldsOn()
342 datadescription.GetInputDescription(i).GenerateMeshOn()
343 return 1
344
345 # setup requests for all inputs based on the requirements of the
346 # pipeline.
347 coprocessor.LoadRequestedData(datadescription)
348 return 1
349
350
351
352
353 # ------------------------ Processing method ------------------------
354
355 global tripleBufferCount
356 tripleBufferCount = 0
357
358 global gDoCoProcessingCount
359 gDoCoProcessingCount = 0
360
361 def DoCoProcessing(datadescription):
362 myDebugPrint3("PhactoriDriver.DoCoProcessing entered: " + str(gDoCoProcessingCount)+ "\n");
363 if PhactoriDbg():
364 numInputGrids = datadescription.GetNumberOfInputDescriptions()
365 for ii in range(0,numInputGrids):
366 oneGridName = datadescription.GetInputDescriptionName(ii)
367 myDebugPrint3("DoCoProcessing " + str(ii) + " " + str(oneGridName) + "\n")
368
369
370 fd = datadescription.GetUserData()
371
372 if GetBypassUserDataFlag() == False:
373 if fd == None:
374 myDebugPrint2("no user data, returning {}\n")
375 returnViewMapC = {}
376 return returnViewMapC
377
378 global gCatchAllExceptionsAndPassUpFlag
379 if gCatchAllExceptionsAndPassUpFlag:
380 try:
381 DoCoProcessingSub(datadescription)
382 except:
383 import traceback
384 tb = traceback.format_exc()
385 IssueErrorOrWarningThroughSierraIO(datadescription, tb, True)
386 else:
387 DoCoProcessingSub(datadescription)
388
389 def DoCoProcessingSub(datadescription):
390 "Callback to do co-processing for current timestep"
391
392 global gDoCoProcessingCount
393 myDebugPrint3("PhactoriDriver.DoCoProcessingSub entered: " + str(gDoCoProcessingCount)+ "\n");
394
395 gDoCoProcessingCount += 1
396
397
398 fd = datadescription.GetUserData()
399
400 if GetBypassUserDataFlag() == False:
401 if fd == None:
402 myDebugPrint2("no user data, returning {}\n")
403 returnViewMapC = {}
404 return returnViewMapC
405
406 global coprocessor
407 global gFirstTimeInDoCoProcessing
408 global gSkipCountdown
409
410 if gFirstTimeInDoCoProcessing == True:
411 myDebugPrint2("DoCoProcessing doing gFirstTimeInDoCoProcessing\n")
412 myDebugPrint2(" skip countdown is " + str(gSkipCountdown) + "\n")
413 if gSkipCountdown > 0:
414 return
415 coprocessor = CreateCoProcessor()
416 coprocessor.SetInitialUpdateFrequences(datadescription)
417 coprocessor.EnableLiveVisualization(False)
418 gFirstTimeInDoCoProcessing = False
419 else:
420 coprocessor.SetInitialUpdateFrequences(datadescription)
421
422 #import pdb
423 #pdb.set_trace()
424
425 InitializePerPipeRoot(datadescription, coprocessor)
426
427 "Callback to do co-processing for current timestep"
428 timestep = datadescription.GetTimeStep()
429
430 myDebugPrint("timestep is: " + str(timestep) + "\n");
431
432 SmartGetLocalProcessId()
433
434 # Load the Pipeline if not created yet
435 #if not pipeline:
436 # myDebugPrint("PhactoriDriver.DoCoProcessing creating pipeline\n");
437 # pipeline = CreatePipeline(datadescription)
438 #else:
439 # myDebugPrint("PhactoriDriver.DoCoProcessing updating pipeline\n");
440 # # update to the new input and time
441 # UpdateProducers(datadescription)
442 # PerFrameUpdate(datadescription)
443
444
445 # Update the coprocessor by providing it the newly generated simulation data.
446 # If the pipeline hasn't been setup yet, this will setup the pipeline.
447 coprocessor.UpdateProducers(datadescription)
448
449 PerFrameUpdate(datadescription)
450
451 # check for simulation-data-based i/o filtering--skip image creation
452 # and writing if criteria has been set up to determine whether to
453 # create images, such as 'maximum of variable X above 80.0'
454 result = WriteOutImagesTest(datadescription, coprocessor)
455 if result == False:
456 #don't write images
457 return
458
459 # Write output data, if appropriate.
460 #coprocessor.WriteData(datadescription);
461
462 # Write output data
463 #WriteAllData(datadescription, cp_writers, timestep);
464
465 # Write image capture (Last arg: rescale lookup table)
466 #myDebugPrint("PhactoriDriver.DoCoProcessing writing images\n");
467 #LocalWriteAllImages(datadescription, cp_views, timestep, False)
468 #WriteAllImages(datadescription, cp_views, timestep, False)
469
470 # Live Visualization
471 #if (len(cp_views) == 0) and live_visu_active:
472 # DoLiveInsitu(timestep, pv_host, pv_port)
473
474 # Write output data, if appropriate.
475 coprocessor.WriteData(datadescription)
476
477 coprocessor.LocalExportOperationsData3(datadescription)
478
479 # Write image capture (Last arg: rescale lookup table), if appropriate.
480 coprocessor.LocalWriteImages3(datadescription,
481 rescale_lookuptable=False)
482
483 #test and allow for looping when doing user vis interaction while
484 #pausing simulation
485 continueWriteAndInteractionCheckLoop = True
486 while continueWriteAndInteractionCheckLoop:
487 interactionTestResult = \
488 DoUserInteractionWithSimulationPausedIfEnabled()
489 if interactionTestResult == 0:
490 #looping interaction is not or is no longer on; allow simulation to
491 #continue
492 continueWriteAndInteractionCheckLoop = False
493 elif interactionTestResult == 1:
494 #looping interaction is on, but there were no changes to the vis
495 #(i.e. no trigger was given to update vis). Therefore do not write
496 #images, but continue looping and waiting for vis change trigger
497 continueWriteAndInteractionCheckLoop = True
498 elif interactionTestResult == 2:
499 #there was a vis change triggered; update the images for the new
500 #vis, write out the images, and continue looping
501 continueWriteAndInteractionCheckLoop = True
502 imagesNeedWriting = True
503 if imagesNeedWriting:
504 UpdateAllImagesetViewsWhichMayChangeWithData()
505 coprocessor.LocalExportOperationsData3(datadescription)
506 coprocessor.LocalWriteImages3(datadescription,
507 rescale_lookuptable=False)
508
509 #coprocessor.WriteImages(datadescription, rescale_lookuptable=True)
510
511 # Live Visualization, if enabled.
512 coprocessor.DoLiveVisualization(datadescription, "localhost", 22222)
513