def isCleanupDone(self): print("LineoutAsynchTask.doCleanup()") assert(self._state == self.STATE_3_CHECK_CLEANUP) # current state try: visit.SetActiveWindow(2) if visit.GetNumPlots()==0: self._state = self.STATE_DONE # new state finally: visit.SetActiveWindow(1)
def doCleanup(self): print("LineoutAsynchTask.doCleanup()") assert(self._state == self.STATE_2_CLEANUP) # current state try: visit.SetActiveWindow(2) assert visit.GetNumPlots()!=0 visit.ClearWindow() visit.DeleteAllPlots() self._state = self.STATE_3_CHECK_CLEANUP # new state finally: visit.SetActiveWindow(1)
def doLineout(self): print("LineoutAsynchTask.doLineout()") assert(self._state == self.STATE_INITIAL) # current state try: if (2 in visit.GetGlobalAttributes().GetWindows()): visit.SetActiveWindow(2) assert visit.GetNumPlots()==0 print("passed assertion that Window2 doesn't exist yet or has no plots") print(visit.SetActiveWindow(1)) visit.Lineout(self._startPoint, self._endPoint) self._state = self.STATE_1_CHECK_DATA # new state finally: visit.SetActiveWindow(1)
def plane_slice_plotting(window_number, axis_number, label, images, timestamp): """ Copy the Mesh, Pseudocolor, and Contour plots into a new VisIt window and slice through the proper axis. Input: ______ window_number: int The number of the window to open (2,3, or 4). axis_number: int The number of the axis to slice through (0 for X, 1 for Y, 2 for Z). label: str The title of the plane slice. images: boolean Whether or not to save images of the plot windows. timestamp: boolean Whether or not to keep the timestamp on plot window images. Returns: ________ none """ # Open a new window with all three plots. Vi.AddWindow() Vi.CopyPlotsToWindow(1, window_number) # Create the plane slice plot by activating the mesh, pseudocolor, and contour plots. Vi.SetActiveWindow(window_number) Vi.SetActivePlots((0, 1, 2)) # Remove the clip and slice operators from previous plot windows. Vi.RemoveAllOperators() # Add a slice through the proper axis. Vi.AddOperator("Slice", 1) s = Vi.SliceAttributes() s.axisType = axis_number Vi.SetOperatorOptions(s) # Include a label for each plane slice plot. banner = Vi.CreateAnnotationObject("Text2D") banner.position = (0.45, 0.92) banner.text = label banner.height = 0.05 # Include the CNERG logo in the bottom left corner of the plot. image = Vi.CreateAnnotationObject("Image") image.image = os.path.dirname(os.path.abspath(__file__)) + "/cnerg.jpg" image.position = (0.02, 0.02) image.width = 10 image.height = 10 Vi.DrawPlots() if images: if timestamp: attributes = Vi.GetAnnotationAttributes() attributes.userInfoFlag = 0 Vi.SetAnnotationAttributes(attributes) Vi.SaveWindow()
def DrawPlot(iWindow, plotInfo): # choose window visit.SetActiveWindow(iWindow) # open database visit.OpenDatabase(plotInfo.databaseName) # create pseudocolor plot visit.AddPlot("Pseudocolor", plotInfo.variableName) # set pseudocolor attributes SetPseudocolorAttributes(plotInfo.valMin, plotInfo.valMax) # set view2d attributtes SetView2dAttributes(plotInfo.domain, plotInfo.viewport) # set annotation attributes SetAnnotationAttributes(plotInfo.domain, plotInfo.legendInfo) # set legend SetLegend(plotInfo.legendInfo) # set time text SetTimeText(plotInfo.timeTextInfo) # draw plot visit.DrawPlots()
def LoadContourPlot(self): (windowid,filename,var) = self.GetDetails() if windowid is None: return wid = viswinmapper[windowid] visit.SetActiveWindow(wid) visit.DeleteAllPlots() visit.OpenDatabase(filename) visit.AddPlot("Contour",var) visit.DrawPlots()
def register_window(cls, win): if len(cls.registered_windows()) > 0: # visit will always have one valid window # when more than one Window instance is registered # we need to add an addtional window. visit.AddWindow() # get active window id from global atts gatts = visit.GetGlobalAttributes() rid = gatts.windows[gatts.activeWindow] visit.SetActiveWindow(rid) cls.__windows[rid] = win return rid
def TimeSeriesS1(): visit.AddPlot('Curve', 's1') visit.AddPlot('Curve', 's2') visit.DrawPlots() visit.AddWindow() visit.AddPlot('Curve', 'pAverage') visit.DrawPlots() visit.SetActiveWindow(1) AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.axes2D.yAxis.grid = 1 AnnotationAtts.axes2D.xAxis.grid = 1 AnnotationAtts.axes2D.xAxis.title.userTitle = 1 AnnotationAtts.axes2D.xAxis.title.userUnits = 1 AnnotationAtts.axes2D.xAxis.title.title = "Position along the machine s" AnnotationAtts.axes2D.xAxis.title.units = "m" visit.SetAnnotationAttributes(AnnotationAtts) visit.DrawPlots()
def isDataReady(self): print("LineoutAsynchTask.isDataReady()") assert(self._state == self.STATE_1_CHECK_DATA) # current state visit.SetActiveWindow(2) if visit.GetNumPlots()==1: print("Lineout data ready\n") self._lineOutData = visit.GetPlotInformation()['Curve'] print("The data from the lineout from (0,0,0) to (1,1,1) is:\n") print("\n") print(str(self._lineOutData)) print("\n") if isinstance(self._lineOutData, tuple): self._state = self.STATE_2_CLEANUP # new state else: raise Exception("LineoutAsynchTask.isDataReady(): failed to return lineout plot data"); else: pass # don't change state ... still waiting for plot
def draw(self): print "drawing window %d of dimension %d"%(self.i,self.dim) v.SetActiveWindow(self.i) v.SetAnnotationAttributes(self.annot) if self.dim == 2: # add the slice assert self._slice is not None for i,plot in enumerate(self.plots): sliced = False for op in plot.operators: if "slice" == op.oname: sliced = True if not sliced: print "slicing plot %d..."%i v.SetActivePlots(i) v.AddOperator("Slice") sa = self._slice.toAttributes() v.SetOperatorOptions(sa) plot.operators.append(Operator("slice", "Slice", sa)) if self.exaggeration is not None: print "exaggerating..." self._exaggerateVertical() # set the plot options for i, plot in enumerate(self.plots): print "setting plot options for plot %i..."%i v.SetActivePlots(i) v.SetPlotOptions(plot.patts) # set the view print "setting the view..." if self.dim == 2: v.SetView2D(self.view) else: v.SetView3D(self.view) print "drawing..." v.DrawPlots()
def LoadExtremeValueAnalysisPlot(self): (windowid,filename,var) = self.GetDetails() if windowid is None: return wid = viswinmapper[windowid] visit.SetActiveWindow(wid) visit.DeleteAllPlots() visit.OpenDatabase(filename, 0) visit.AddPlot("Pseudocolor", var, 1, 1) #visit.AddOperator("Box", 1) #visit.SetActivePlots(0) #visit.SetActivePlots(0) #BoxAtts = visit.BoxAttributes() #BoxAtts.amount = BoxAtts.Some # Some, All #BoxAtts.minx = 90 #BoxAtts.maxx = 100 #BoxAtts.miny = -10 #BoxAtts.maxy = 10 #BoxAtts.minz = 0 #BoxAtts.maxz = 1 #visit.SetOperatorOptions(BoxAtts, 1) visit.AddOperator("ExtremeValueAnalysis") visit.DrawPlots()
def visit_plot_qcrit_wx_3d(xdmf_dir, wx_range=(-5.0, 5.0), q_value=0.1, config_view=None, out_dir=os.getcwd(), out_prefix='wake3d_', figsize=(1024, 1024), visit_dir=None, visit_arch='linux-x86_64', state=None, states=None, states_range=[0, None, 1]): # Import VisIt package. if visit_dir is None: visit_dir = os.environ.get('VISIT_DIR') if visit_dir is None: raise ValueError('Provide VisIt installation path or ' 'set env variable VISIT_DIR') sys.path.append(os.path.join(visit_dir, visit_arch, 'lib', 'site-packages')) import visit visit.LaunchNowin() # Check version of VisIt. visit_check_version(visit.Version()) # Define some variables to get the q_crit and wx_cc. p_xdmf_path = os.path.join(str(xdmf_dir), 'p.xmf') visit.OpenDatabase(p_xdmf_path, 0) visit.DefineScalarExpression("operators/ConnectedComponents/p Grid", "cell_constant(<p Grid>, 0.)") visit.DefineCurveExpression("operators/DataBinning/1D/p Grid", "cell_constant(<p Grid>, 0)") visit.DefineScalarExpression("operators/DataBinning/2D/p Grid", "cell_constant(<p Grid>, 0)") visit.DefineScalarExpression("operators/DataBinning/3D/p Grid", "cell_constant(<p Grid>, 0)") visit.DefineScalarExpression("operators/Flux/p Grid", "cell_constant(<p Grid>, 0.)") visit.DefineCurveExpression("operators/Lineout/p", "cell_constant(<p>, 0.)") visit.DefineCurveExpression( "operators/Lineout/time_derivative/p Grid_time", "cell_constant(time_derivative/p Grid_time, 0.)") visit.DefineCurveExpression( "operators/Lineout/time_derivative/p Grid_lasttime", "cell_constant(time_derivative/p Grid_lasttime, 0.)") visit.DefineCurveExpression("operators/Lineout/time_derivative/p", "cell_constant(time_derivative/p, 0.)") visit.DefineScalarExpression("operators/ModelFit/model", "point_constant(<p Grid>, 0)") visit.DefineScalarExpression("operators/ModelFit/distance", "point_constant(<p Grid>, 0)") visit.DefineScalarExpression("operators/StatisticalTrends/Sum/p", "cell_constant(<p>, 0.)") visit.DefineScalarExpression("operators/StatisticalTrends/Mean/p", "cell_constant(<p>, 0.)") visit.DefineScalarExpression("operators/StatisticalTrends/Variance/p", "cell_constant(<p>, 0.)") visit.DefineScalarExpression("operators/StatisticalTrends/Std. Dev./p", "cell_constant(<p>, 0.)") visit.DefineScalarExpression("operators/StatisticalTrends/Slope/p", "cell_constant(<p>, 0.)") visit.DefineScalarExpression("operators/StatisticalTrends/Residuals/p", "cell_constant(<p>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Sum/time_derivative/p Grid_time", "cell_constant(<time_derivative/p Grid_time>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Sum/time_derivative/p Grid_lasttime", "cell_constant(<time_derivative/p Grid_lasttime>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Sum/time_derivative/p", "cell_constant(<time_derivative/p>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Mean/time_derivative/p Grid_time", "cell_constant(<time_derivative/p Grid_time>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Mean/time_derivative/p Grid_lasttime", "cell_constant(<time_derivative/p Grid_lasttime>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Mean/time_derivative/p", "cell_constant(<time_derivative/p>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Variance/time_derivative/p Grid_time", "cell_constant(<time_derivative/p Grid_time>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Variance/time_derivative/p Grid_lasttime", "cell_constant(<time_derivative/p Grid_lasttime>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Variance/time_derivative/p", "cell_constant(<time_derivative/p>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Std. Dev./time_derivative/p Grid_time", "cell_constant(<time_derivative/p Grid_time>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Std. Dev./time_derivative/p Grid_lasttime", "cell_constant(<time_derivative/p Grid_lasttime>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Std. Dev./time_derivative/p", "cell_constant(<time_derivative/p>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Slope/time_derivative/p Grid_time", "cell_constant(<time_derivative/p Grid_time>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Slope/time_derivative/p Grid_lasttime", "cell_constant(<time_derivative/p Grid_lasttime>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Slope/time_derivative/p", "cell_constant(<time_derivative/p>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Residuals/time_derivative/p Grid_time", "cell_constant(<time_derivative/p Grid_time>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Residuals/time_derivative/p Grid_lasttime", "cell_constant(<time_derivative/p Grid_lasttime>, 0.)") visit.DefineScalarExpression( "operators/StatisticalTrends/Residuals/time_derivative/p", "cell_constant(<time_derivative/p>, 0.)") visit.DefineVectorExpression("operators/SurfaceNormal/p Grid", "cell_constant(<p Grid>, 0.)") # Define cell-centered velocity vector field. ux_xdmf_path = os.path.join(str(xdmf_dir), 'u.xmf') uy_xdmf_path = os.path.join(str(xdmf_dir), 'v.xmf') uz_xdmf_path = os.path.join(str(xdmf_dir), 'w.xmf') vel_exp = ('{' + 'pos_cmfe(<{}[0]id:u>, <p Grid>, 1.0),'.format(ux_xdmf_path) + 'pos_cmfe(<{}[0]id:v>, <p Grid>, 0.0),'.format(uy_xdmf_path) + 'pos_cmfe(<{}[0]id:w>, <p Grid>, 0.0)'.format(uz_xdmf_path) + '}') visit.DefineVectorExpression('velocity', vel_exp) # Define Q-criterion. qcrit_exp = ('q_criterion(' + 'gradient(velocity[0]),' + 'gradient(velocity[1]),' + 'gradient(velocity[2])' + ')') visit.DefineScalarExpression('q_crit', qcrit_exp) # Define cell-centered streamwise vorticity. wx_xdmf_path = os.path.join(str(xdmf_dir), 'wx.xmf') wx_exp = 'pos_cmfe(<{}[0]id:wx>, <p Grid>, 0.0)'.format(wx_xdmf_path) visit.DefineScalarExpression('wx_cc', wx_exp) # Add a pseudocolor of the cell-centered streamwise vorticity. visit.AddPlot('Pseudocolor', 'wx_cc', 1, 1) PseudocolorAtts = visit.PseudocolorAttributes() PseudocolorAtts.minFlag = 1 PseudocolorAtts.min = wx_range[0] PseudocolorAtts.maxFlag = 1 PseudocolorAtts.max = wx_range[1] PseudocolorAtts.colorTableName = 'viridis' PseudocolorAtts.invertColorTable = 1 PseudocolorAtts.opacityType = PseudocolorAtts.Constant PseudocolorAtts.opacity = 0.8 PseudocolorAtts.legendFlag = 0 visit.SetPlotOptions(PseudocolorAtts) # Add an isosurface of the Q-criterion. visit.AddOperator('Isosurface', 1) IsosurfaceAtts = visit.IsosurfaceAttributes() IsosurfaceAtts.variable = 'q_crit' IsosurfaceAtts.contourMethod = IsosurfaceAtts.Value IsosurfaceAtts.contourValue = (q_value) IsosurfaceAtts.scaling = IsosurfaceAtts.Linear visit.SetOperatorOptions(IsosurfaceAtts, 1) # Remove info about user, time, database, and legend. AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.userInfoFlag = 0 AnnotationAtts.databaseInfoFlag = 0 AnnotationAtts.timeInfoFlag = 0 AnnotationAtts.legendInfoFlag = 0 AnnotationAtts.axes3D.visible = 0 AnnotationAtts.axes3D.triadFlag = 1 AnnotationAtts.axes3D.bboxFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts) # Parse the 3D view configuration file. if config_view is not None: with open(str(config_view), 'r') as infile: config_view = yaml.load(infile, Loader=yaml.FullLoader) config_view = config_view['View3DAtts'] # Set attributes of the view. View3DAtts = visit.View3DAttributes() for key, value in config_view.items(): if type(value) is list: value = tuple(value) setattr(View3DAtts, key, value) visit.SetView3D(View3DAtts) visit.SetActiveWindow(1) visit.Source(os.path.join(visit_dir, visit_arch, 'bin', 'makemovie.py')) visit.ToggleCameraViewMode() # Create output directory if necessary. if not os.path.isdir(str(out_dir)): os.makedirs(str(out_dir)) # Loop over the states to render and save the plots. if state is not None: states = [state] elif states is None: if states_range[1] is None: states_range[1] = visit.TimeSliderGetNStates() else: states_range[1] += 1 states = range(*states_range) for i, state in enumerate(states): print('[state {}] Rendering and saving figure ...'.format(state)) visit.SetTimeSliderState(state) if i == 0: visit.DrawPlots() RenderingAtts = visit.RenderingAttributes() visit.SetRenderingAttributes(RenderingAtts) SaveWindowAtts = visit.SaveWindowAttributes() SaveWindowAtts.outputToCurrentDirectory = 0 SaveWindowAtts.outputDirectory = str(out_dir) SaveWindowAtts.fileName = '{}{:0>4}'.format(out_prefix, state) SaveWindowAtts.family = 0 SaveWindowAtts.format = SaveWindowAtts.PNG SaveWindowAtts.width = figsize[0] SaveWindowAtts.height = figsize[1] SaveWindowAtts.quality = 100 SaveWindowAtts.resConstraint = SaveWindowAtts.NoConstraint visit.SetSaveWindowAttributes(SaveWindowAtts) visit.SaveWindow() os.remove('visitlog.py') visit.CloseComputeEngine() visit.Close() return
def visit_plot_pseudocolor_2d(xdmf_path, name, value_range=(-5.0, 5.0), curve2d_paths=None, config_view=None, out_dir=os.getcwd(), out_prefix='wake2d_', figsize=(1024, 1024), visit_dir=None, visit_arch='linux-x86_64', state=None, states=None, states_range=[0, None, 1]): # Import VisIt package. if visit_dir is None: visit_dir = os.environ.get('VISIT_DIR') if visit_dir is None: raise ValueError('Provide VisIt installation path or ' 'set env variable VISIT_DIR') sys.path.append(os.path.join(visit_dir, visit_arch, 'lib', 'site-packages')) import visit visit.LaunchNowin() # Check version of VisIt. visit_check_version(visit.Version()) # Create database correlation with optional Curve2D files. num_bodies = 0 databases = [str(xdmf_path)] if curve2d_paths is not None: num_bodies = len(curve2d_paths) databases = [str(path) for path in curve2d_paths] databases.append(str(xdmf_path)) visit.CreateDatabaseCorrelation('common', databases[num_bodies:], 0) # Open the file with the coordinates of the immersed boundary. if num_bodies > 0: for i in range(num_bodies): visit.OpenDatabase(databases[i], 0) # Add plot the mesh points. visit.AddPlot('Curve', 'curve', 1, 1) # Set attributes of the curve. CurveAtts = visit.CurveAttributes() CurveAtts.lineWidth = 1 CurveAtts.curveColorSource = CurveAtts.Custom CurveAtts.curveColor = (0, 0, 0, 255) CurveAtts.showLegend = 0 CurveAtts.showLabels = 0 visit.SetPlotOptions(CurveAtts) # Open the XMF file for the spanwise-averaged z-component of the vorticity. visit.OpenDatabase(databases[-1], 0) # Add a pseudocolor plot of the scalar field. visit.AddPlot('Pseudocolor', name, 1, 1) # Set attributes of the pseudocolor. PseudocolorAtts = visit.PseudocolorAttributes() PseudocolorAtts.minFlag = 1 PseudocolorAtts.min = value_range[0] PseudocolorAtts.maxFlag = 1 PseudocolorAtts.max = value_range[1] PseudocolorAtts.colorTableName = 'viridis' visit.SetPlotOptions(PseudocolorAtts) # Parse the 2D view configuration file. if config_view is not None: with open(str(config_view), 'r') as infile: config_view = yaml.load(infile, Loader=yaml.FullLoader) config_view = config_view['View2DAtts'] # Set attributes of the view. View2DAtts = visit.View2DAttributes() for key, value in config_view.items(): if type(value) is list: value = tuple(value) setattr(View2DAtts, key, value) visit.SetView2D(View2DAtts) # Remove time and user info. AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.userInfoFlag = 0 AnnotationAtts.timeInfoFlag = 1 visit.SetAnnotationAttributes(AnnotationAtts) visit.SetActiveWindow(1) visit.Source(os.path.join(visit_dir, visit_arch, 'bin', 'makemovie.py')) visit.ToggleCameraViewMode() # Create output directory if necessary. if not os.path.isdir(str(out_dir)): os.makedirs(str(out_dir)) # Loop over the states to render and save the plots. if state is not None: states = [state] elif states is None: if states_range[1] is None: states_range[1] = visit.TimeSliderGetNStates() else: states_range[1] += 1 states = range(*states_range) for i, state in enumerate(states): print('[state {}] Rendering and saving figure ...'.format(state)) visit.SetTimeSliderState(state) if i == 0: visit.DrawPlots() RenderingAtts = visit.RenderingAttributes() visit.SetRenderingAttributes(RenderingAtts) SaveWindowAtts = visit.SaveWindowAttributes() SaveWindowAtts.outputToCurrentDirectory = 0 SaveWindowAtts.outputDirectory = str(out_dir) SaveWindowAtts.fileName = '{}{:0>4}'.format(out_prefix, state) SaveWindowAtts.family = 0 SaveWindowAtts.format = SaveWindowAtts.PNG SaveWindowAtts.width = figsize[0] SaveWindowAtts.height = figsize[1] SaveWindowAtts.quality = 100 SaveWindowAtts.resConstraint = SaveWindowAtts.NoConstraint visit.SetSaveWindowAttributes(SaveWindowAtts) visit.SaveWindow() os.remove('visitlog.py') visit.Close() return
def visit_plot_contour_3d(xdmf_path, name, value_range=(-5.0, 5.0), p3d_paths=None, config_view=None, out_dir=os.getcwd(), out_prefix='wake3d_', figsize=(1024, 1024), visit_dir=None, visit_arch='linux-x86_64', state=None, states=None, states_range=[0, None, 1]): # Import VisIt package. if visit_dir is None: visit_dir = os.environ.get('VISIT_DIR') if visit_dir is None: raise ValueError('Provide VisIt installation path or ' 'set env variable VISIT_DIR') sys.path.append(os.path.join(visit_dir, visit_arch, 'lib', 'site-packages')) import visit visit.LaunchNowin() # Check version of VisIt. visit_check_version(visit.Version()) # Create database correlation with optional Point3D files. num_bodies = 0 databases = [str(xdmf_path)] if p3d_paths is not None: num_bodies = len(p3d_paths) databases = [str(path) for path in p3d_paths] databases.append(str(xdmf_path)) visit.CreateDatabaseCorrelation('common', databases[num_bodies:], 0) # Open the file with the coordinates of the immersed boundary. if num_bodies > 0: for i in range(num_bodies): visit.OpenDatabase(databases[i], 0, 'Point3D_1.0') # Add plot the mesh points. visit.AddPlot('Mesh', 'points', 1, 1) # Set attributes of the mesh plot. MeshAtts = visit.MeshAttributes() MeshAtts.legendFlag = 0 MeshAtts.meshColor = (255, 204, 0, 1.0 * 255) MeshAtts.meshColorSource = MeshAtts.MeshCustom MeshAtts.pointSize = 0.05 MeshAtts.pointType = MeshAtts.Point MeshAtts.pointSizePixels = 2 MeshAtts.opacity = 1 visit.SetPlotOptions(MeshAtts) # Open the XMF file for the z-component of the vorticity. visit.OpenDatabase(databases[-1], 0) # Add the plot of the contour of the z-component of the vorticity. visit.AddPlot('Contour', name, 1, 1) # Set attributes of the contour. ContourAtts = visit.ContourAttributes() ContourAtts.contourNLevels = 2 ContourAtts.SetMultiColor(0, (0, 51, 102, 0.6 * 255)) ContourAtts.SetMultiColor(1, (255, 0, 0, 0.6 * 255)) ContourAtts.legendFlag = 1 ContourAtts.minFlag = 1 ContourAtts.maxFlag = 1 ContourAtts.min = value_range[0] ContourAtts.max = value_range[1] visit.SetPlotOptions(ContourAtts) # Parse the 3D view configuration file. if config_view is not None: with open(str(config_view), 'r') as infile: config_view = yaml.load(infile, Loader=yaml.FullLoader) config_view = config_view['View3DAtts'] # Set attributes of the view. View3DAtts = visit.View3DAttributes() for key, value in config_view.items(): if type(value) is list: value = tuple(value) setattr(View3DAtts, key, value) visit.SetView3D(View3DAtts) # Remove time and user info. AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.userInfoFlag = 0 AnnotationAtts.timeInfoFlag = 0 AnnotationAtts.axes3D.visible = 0 AnnotationAtts.axes3D.triadFlag = 1 AnnotationAtts.axes3D.bboxFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts) visit.SetActiveWindow(1) visit.Source(os.path.join(visit_dir, visit_arch, 'bin', 'makemovie.py')) visit.ToggleCameraViewMode() # Create output directory if necessary. if not os.path.isdir(str(out_dir)): os.makedirs(str(out_dir)) # Loop over the states to render and save the plots. if state is not None: states = [state] elif states is None: if states_range[1] is None: states_range[1] = visit.TimeSliderGetNStates() else: states_range[1] += 1 states = range(*states_range) for i, state in enumerate(states): print('[state {}] Rendering and saving figure ...'.format(state)) visit.SetTimeSliderState(state) if i == 0: visit.DrawPlots() RenderingAtts = visit.RenderingAttributes() visit.SetRenderingAttributes(RenderingAtts) SaveWindowAtts = visit.SaveWindowAttributes() SaveWindowAtts.outputToCurrentDirectory = 0 SaveWindowAtts.outputDirectory = str(out_dir) SaveWindowAtts.fileName = '{}{:0>4}'.format(out_prefix, state) SaveWindowAtts.family = 0 SaveWindowAtts.format = SaveWindowAtts.PNG SaveWindowAtts.width = figsize[0] SaveWindowAtts.height = figsize[1] SaveWindowAtts.quality = 100 SaveWindowAtts.resConstraint = SaveWindowAtts.NoConstraint visit.SetSaveWindowAttributes(SaveWindowAtts) visit.SaveWindow() os.remove('visitlog.py') visit.Close() return
def WriteScript(f): """Write Python code to replicate the current VisIt state to the specified file object. Example: f = open('script.py', 'wt') WriteScript(f) f.close() """ def object_type(obj): return str(type(obj))[7:-2] def write_state_object_atts(f, atts, name): lines = str(atts).split('\n') for line in lines: if line == '' or line[0] == '#': continue if '#' in line: pos = string.find(line, "=") if '"' in line[pos + 2:]: f.write('%s.%s\n' % (name, line)) else: f.write('%s.%s%s.%s\n' % (name, line[:pos + 2], name, line[pos + 2:])) else: f.write('%s.%s\n' % (name, line)) def write_state_object(f, atts, name): typename = object_type(atts) f.write('%s = %s()\n' % (name, typename)) write_state_object_atts(f, atts, name) def write_state_object_atts_diffs(f, atts, defaultatts, name): lines = str(atts).split('\n') defaultlines = str(defaultatts).split('\n') if len(lines) != len(defaultlines): write_state_object_atts(f, atts, name) return 1 wroteline = 0 for i in range(len(lines)): line = lines[i] if line == '' or line[0] == '#': continue # If the lines are the same then don't output the line. if line == defaultlines[i]: continue if '#' in line: pos = string.find(line, "=") if '"' in line[pos + 2:]: f.write('%s.%s\n' % (name, line)) wroteline = 1 else: f.write('%s.%s%s.%s\n' % (name, line[:pos + 2], name, line[pos + 2:])) wroteline = 1 else: f.write('%s.%s\n' % (name, line)) wroteline = 1 return wroteline def write_state_object_diffs(f, atts, defaultatts, name): typename = object_type(atts) f.write('%s = %s()\n' % (name, typename)) return write_state_object_atts_diffs(f, atts, defaultatts, name) def write_color_tables(f): f.write('# Write color tables\n') # The list of built-in color table names. builtin_cts = ('Accent', 'Blues', 'BrBG', 'BuGn', 'BuPu', 'Dark2', 'GnBu', 'Greens', 'Greys', 'OrRd', 'Oranges', 'PRGn', 'Paired', 'Pastel1', 'Pastel2', 'PiYG', 'PuBu', 'PuBuGn', 'PuOr', 'PuRd', 'Purples', 'RdBu', 'RdGy', 'RdPu', 'RdYlBu', 'RdYlGn', 'Reds', 'Set1', 'Set2', 'Set3', 'Spectral', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd', 'amino_rasmol', 'amino_shapely', 'bluehot', 'caleblack', 'calewhite', 'contoured', 'cpk_jmol', 'cpk_rasmol', 'difference', 'gray', 'hot', 'hot_and_cold', 'hot_desaturated', 'levels', 'orangehot', 'rainbow', 'xray') ctlist = visit.ColorTableNames() for name in ctlist: # Only write the color tables not in builtin_cts. Assume they are unchanged. if not name in builtin_cts: ct = visit.GetColorTable(name) f.write('ct = ColorControlPointList()\n') for i in range(ct.GetNumControlPoints()): pname = "p%d" % i f.write('%s = ColorControlPoint()\n' % pname) f.write('%s.colors = %s\n' % (pname, str(ct.GetControlPoints(i).colors))) f.write('%s.position = %s\n' % (pname, str(ct.GetControlPoints(i).position))) f.write('ct.AddControlPoints(%s)\n' % pname) f.write('AddColorTable("%s", ct)\n' % name) def write_sil(f): silr = visit.SILRestriction() nsets = [0, 0] for setid in range(silr.NumSets()): if silr.UsesData(setid): nsets[1] += 1 else: nsets[0] += 1 f.write('silr = SILRestriction()\n') if nsets[1] == silr.NumSets(): f.write('silr.TurnOnAll()\n') elif nsets[0] < nsets[1]: # More sets were on so we'll turn them all on and then turn off sets # that were off. sets = [] for setid in range(silr.NumSets()): if not silr.UsesData(setid) and len(silr.MapsOut(setid)) == 0: sets.append(setid) if len(sets) == 0: f.write('silr.TurnOffAll()\n') elif len(sets) == 1: f.write('silr.TurnOnAll()\n') f.write('silr.TurnOffSet("%s")\n' % silr.SetName(sets[0])) else: f.write('silr.SuspendCorrectnessChecking()\n') f.write('silr.TurnOnAll()\n') if 0: #For now. silr.SetIndex() is buggy. #if len(sets) < 100: line = 'offSets = (' linelen = len(line) for i in range(len(sets)): s = '"%s", ' % silr.SetName(sets[i]) line = line + s linelen = linelen + len(s) if linelen > 80: line = line + '\n' linelen = 0 line = line + ')\n' f.write('%s' % line) f.write('offSets = (') for i in range(len(sets)): f.write('"%s", ' % silr.SetName(sets[i])) f.write(')\n') f.write('for silSet in offSets:\n') f.write(' silr.TurnOffSet(silr.SetIndex(silSet))\n') else: line = 'offSets = (' linelen = len(line) for i in range(len(sets)): s = '%d, ' % sets[i] line = line + s linelen = linelen + len(s) if linelen > 80: line = line + '\n' linelen = 0 line = line + ')\n' f.write('%s' % line) f.write('for silSet in offSets:\n') f.write(' silr.TurnOffSet(silSet)\n') f.write('silr.EnableCorrectnessChecking()\n') else: # More sets were off so we'll turn them all off and then turn on sets # that were on. sets = [] for setid in range(silr.NumSets()): if silr.UsesData(setid) and len(silr.MapsOut(setid)) == 0: sets.append(setid) if len(sets) == 0: f.write('silr.TurnOffAll()\n') elif len(sets) == 1: f.write('silr.TurnOffAll()\n') f.write('silr.TurnOnSet("%s")\n' % silr.SetName(sets[0])) else: f.write('silr.SuspendCorrectnessChecking()\n') f.write('silr.TurnOffAll()\n') if 0: #For now. silr.SetIndex() is buggy. #if len(sets) < 100: line = 'onSets = (' linelen = len(line) for i in range(len(sets)): s = '"%s", ' % silr.SetName(sets[i]) line = line + s linelen = linelen + len(s) if linelen > 80: line = line + '\n' linelen = 0 line = line + ')\n' f.write('%s' % line) f.write('for silSet in onSets:\n') f.write(' silr.TurnOnSet(silr.SetIndex(silSet))\n') else: line = 'onSets = (' linelen = len(line) for i in range(len(sets)): s = '%d, ' % sets[i] line = line + s linelen = linelen + len(s) if linelen > 80: line = line + '\n' linelen = 0 line = line + ')\n' f.write('%s' % line) f.write('for silSet in onSets:\n') f.write(' silr.TurnOnSet(silSet)\n') f.write('silr.EnableCorrectnessChecking()\n') f.write('SetPlotSILRestriction(silr, 0)\n') def write_sil99(f): silr = visit.SILRestriction() f.write('silr = SILRestriction()\n') if silr.UsesAllData(): f.write('silr.TurnOnAll()\n') else: f.write('silr.SuspendCorrectnessChecking()\n') onSets = [] offSets = [] for cat in silr.Categories(): sets = silr.SetsInCategory(cat) for s in sets: enabled = silr.UsesData(s) if enabled: onSets.append(s) else: offSets.append(s) if len(onSets) > len(offSets): f.write('silr.TurnOnAll()\n') if len(offSets) < 100: # With a small number of sets, mention them by name. f.write('offSets = (') for s in offSets: f.write('"%s", ' % silr.SetName(s)) f.write(')\n') f.write('for setName in offSets:\n') f.write(' silr.TurnOffSet(silr.SetIndex(setName))\n') else: f.write('offSets = (') for s in offSets: f.write('%d, ' % s) f.write(')\n') f.write('for setIndex in offSets:\n') f.write(' silr.TurnOffSet(setIndex)\n') else: f.write('silr.TurnOffAll()\n') if len(onSets) < 100: # With a small number of sets, mention them by name. f.write('onSets = (') for s in onSets: f.write('"%s", ' % silr.SetName(s)) f.write(')\n') f.write('for setName in onSets:\n') f.write(' silr.TurnOnSet(silr.SetIndex(setName))\n') else: f.write('onSets = (') for s in onSets: f.write('%d, ' % s) f.write(')\n') f.write('for setIndex in onSets:\n') f.write(' silr.TurnOnSet(setIndex)\n') f.write('silr.EnableCorrectnessChecking()\n') f.write('SetPlotSILRestriction(silr, 0)\n') def write_plots(f): f.write('# Create plots\n') pL = visit.GetPlotList() activePlots = [] for i in range(visit.GetNumPlots()): plot = pL.GetPlots(i) if plot.activeFlag: activePlots = activePlots + [i] plotName = visit.PlotPlugins()[plot.plotType] visit.SetActivePlots(i) f.write('# Create plot %d\n' % (i + 1)) f.write('OpenDatabase("%s")\n' % plot.databaseName) f.write('AddPlot("%s", "%s", 0, 0)\n' % (plotName, plot.plotVar)) atts = eval("visit." + plotName + "Attributes(1)") defaultatts = eval("visit." + plotName + "Attributes()") if write_state_object_diffs(f, atts, defaultatts, "atts"): f.write('SetPlotOptions(atts)\n') else: f.write('#SetPlotOptions(atts)\n') opIndex = 0 for op in plot.operatorNames: f.write('AddOperator("%s", 0)\n' % op) opAtts = visit.GetOperatorOptions(opIndex) defaultAtts = eval("visit." + object_type(opAtts) + "()") if write_state_object_diffs(f, opAtts, defaultAtts, "opAtts"): f.write('SetOperatorOptions(opAtts)\n') else: f.write('#SetOperatorOptions(opAtts)\n') opIndex += 1 # Set the SIL restriction write_sil(f) f.write('\n') if len(activePlots) > 1: f.write('SetActivePlots(%s)\n\n' % str(activePlots)) visit.SetActivePlots(activePlots) elif len(activePlots) == 1: f.write('SetActivePlots(%d)\n\n' % activePlots[0]) visit.SetActivePlots(activePlots[0]) def set_annotation_objects(f, prefix): f.write('# Set annotation object properties\n') names = visit.GetAnnotationObjectNames() index = 0 plotNames = [] for name in names: obj = visit.GetAnnotationObject(name) objtype = object_type(obj) newname = prefix + "obj%03d" % index index = index + 1 if objtype == 'LineObject': f.write('%s = CreateAnnotationObject("Line2D", "%s")\n' % (newname, name)) elif objtype == 'Text2DObject': f.write('%s = CreateAnnotationObject("Text2D", "%s")\n' % (newname, name)) elif objtype == 'ImageObject': f.write('%s = CreateAnnotationObject("Image", "%s")\n' % (newname, name)) elif objtype == 'TimeSliderObject': f.write('%s = CreateAnnotationObject("TimeSlider", "%s")\n' % (newname, name)) elif objtype == 'LegendAttributesObject': plotNames = plotNames + [name] continue write_state_object_atts(f, obj, newname) f.write('\n') index = 0 for name in plotNames: legend = prefix + "legend%03d" % index f.write( '%s = GetAnnotationObject(GetPlotList().GetPlots(%d).plotName)\n' % (legend, index)) write_state_object_atts(f, visit.GetAnnotationObject(name), legend) index += 1 f.write('\n') def write_window(f, prefix): # Window setup f.write('width, height = %d, %d\n' % visit.GetWindowInformation().windowSize) f.write( 'win = GetGlobalAttributes().windows[GetGlobalAttributes().activeWindow]\n' ) f.write('ResizeWindow(win, width, height)\n') f.write('SetActiveWindow(win) # Synchronize\n') f.write('size = GetWindowInformation().windowSize\n') f.write('if width < size[0] or height < size[1]:\n') f.write( ' ResizeWindow(win, width + (size[0] - width), height + (size[1] - height))\n' ) f.write('DeleteAllPlots()\n') f.write('for name in GetAnnotationObjectNames():\n') f.write(' DeleteAnnotationObject(name)\n') f.write('\n') # Write the plots. write_plots(f) f.write('DrawPlots()\n\n') # Set the view f.write('# Set the view\n') if visit.GetWindowInformation().viewDimension == 1: view = visit.GetViewCurve() elif visit.GetWindowInformation().viewDimension == 2: view = visit.GetView2D() else: view = visit.GetView3D() write_state_object(f, view, "view") if visit.GetWindowInformation().viewDimension == 1: f.write('SetViewCurve(view)\n') elif visit.GetWindowInformation().viewDimension == 2: f.write('SetView2D(view)\n') else: f.write('SetView3D(view)\n') f.write('\n') # Get the annotation attributes f.write('# Set the annotation attributes\n') annot = visit.GetAnnotationAttributes() if write_state_object_diffs(f, annot, visit.AnnotationAttributes(), "annot"): f.write('SetAnnotationAttributes(annot)\n\n') else: f.write('#SetAnnotationAttributes(annot)\n\n') set_annotation_objects(f, prefix) # Define expressions f.write('# Define expressions\n') expr = visit.ExpressionList(1) for i in range(expr.GetNumExpressions()): e = expr.GetExpressions(i) if e.fromDB == 0 and e.fromOperator == 0: if e.type == e.ScalarMeshVar: f.write('DefineScalarExpression("%s", "%s")\n' % (e.name, e.definition)) elif e.type == e.VectorMeshVar: f.write('DefineVectorExpression("%s", "%s")\n' % (e.name, e.definition)) elif e.type == e.TensorMeshVar: f.write('DefineTensorExpression("%s", "%s")\n' % (e.name, e.definition)) elif e.type == e.ArrayMeshVar: f.write('DefineArrayExpression("%s", "%s")\n' % (e.name, e.definition)) elif e.type == e.CurveMeshVar: f.write('DefineCurveExpression("%s", "%s")\n' % (e.name, e.definition)) elif e.type == e.Mesh: f.write('DefineMeshExpression("%s", "%s")\n' % (e.name, e.definition)) # Write the definitions of any non-standard color tables. write_color_tables(f) g = visit.GetGlobalAttributes() index = 0 f.write('SetCloneWindowOnFirstRef(0)\n') for win in g.windows: visit.SetActiveWindow(win) f.write( '###############################################################################\n' ) if index > 0: f.write('AddWindow()\n') write_window(f, "win%d_" % index) index += 1 f.write('SetActiveWindow(GetGlobalAttributes().windows[%d])\n' % g.activeWindow) visit.SetActiveWindow(g.windows[g.activeWindow])
def visit_plot_pseudocolor_2d(xdmf_path, name, value_range=(-5.0, 5.0), curve2d_paths=None, config_view=None, out_dir=os.getcwd(), out_prefix=None, figsize=(1024, 1024), state=None, states=None, states_range=[0, None, 1]): visit_initialize() # Create database correlation with optional Curve2D files. num_bodies = 0 databases = [str(xdmf_path)] if curve2d_paths is not None: num_bodies = len(curve2d_paths) databases = [str(path) for path in curve2d_paths] databases.append(str(xdmf_path)) visit.CreateDatabaseCorrelation('common', databases[num_bodies:], 0) # Open the file with the coordinates of the immersed boundary. if num_bodies > 0: for i in range(num_bodies): visit.OpenDatabase(databases[i], 0) # Add plot the mesh points. visit.AddPlot('Curve', 'curve', 1, 1) # Set attributes of the curve. CurveAtts = visit.CurveAttributes() CurveAtts.lineWidth = 1 CurveAtts.curveColorSource = CurveAtts.Custom CurveAtts.curveColor = (0, 0, 0, 255) CurveAtts.showLegend = 0 CurveAtts.showLabels = 0 visit.SetPlotOptions(CurveAtts) # Open the XMF file for the spanwise-averaged z-component of the vorticity. visit.OpenDatabase(databases[-1], 0) # Add a pseudocolor plot of the scalar field. visit.AddPlot('Pseudocolor', name, 1, 1) # Set attributes of the pseudocolor. PseudocolorAtts = visit.PseudocolorAttributes() PseudocolorAtts.minFlag = 1 PseudocolorAtts.min = value_range[0] PseudocolorAtts.maxFlag = 1 PseudocolorAtts.max = value_range[1] PseudocolorAtts.colorTableName = 'viridis' visit.SetPlotOptions(PseudocolorAtts) # Parse the 2D view configuration file. if config_view is not None: View2DAtts = visit_get_view(config_view, '2D') visit.SetView2D(View2DAtts) # Remove time and user info. AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.userInfoFlag = 0 AnnotationAtts.timeInfoFlag = 1 visit.SetAnnotationAttributes(AnnotationAtts) visit.SetActiveWindow(1) states = visit_get_states(state=state, states=states, states_range=states_range) if out_prefix is None: out_prefix = name + '_' visit_render_save_states(states, out_dir=out_dir, out_prefix=out_prefix, figsize=figsize) visit_finalize() return
def visit_plot_qcrit_wx_3d_direct(xdmf_path, wx_range=(-5.0, 5.0), q_value=0.1, config_view=None, out_dir=os.getcwd(), out_prefix='qcrit_wx_', figsize=(1024, 1024), state=None, states=None, states_range=[0, None, 1]): visit_initialize() visit.OpenDatabase(str(xdmf_path), 0) # Add a pseudocolor of the cell-centered streamwise vorticity. visit.AddPlot('Pseudocolor', 'wx_cc', 1, 1) PseudocolorAtts = visit.PseudocolorAttributes() PseudocolorAtts.minFlag = 1 PseudocolorAtts.min = wx_range[0] PseudocolorAtts.maxFlag = 1 PseudocolorAtts.max = wx_range[1] PseudocolorAtts.colorTableName = 'viridis' PseudocolorAtts.invertColorTable = 0 PseudocolorAtts.opacityType = PseudocolorAtts.Constant PseudocolorAtts.opacity = 0.8 PseudocolorAtts.legendFlag = 0 visit.SetPlotOptions(PseudocolorAtts) # Add an isosurface of the Q-criterion. visit.AddOperator('Isosurface', 1) IsosurfaceAtts = visit.IsosurfaceAttributes() IsosurfaceAtts.variable = 'qcrit' IsosurfaceAtts.contourMethod = IsosurfaceAtts.Value IsosurfaceAtts.contourValue = (q_value) IsosurfaceAtts.scaling = IsosurfaceAtts.Linear visit.SetOperatorOptions(IsosurfaceAtts, 1) # Remove info about user, time, database, and legend. AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.userInfoFlag = 0 AnnotationAtts.databaseInfoFlag = 0 AnnotationAtts.timeInfoFlag = 0 AnnotationAtts.legendInfoFlag = 0 AnnotationAtts.axes3D.visible = 0 AnnotationAtts.axes3D.triadFlag = 1 AnnotationAtts.axes3D.bboxFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts) # Parse the 3D view configuration file. if config_view is not None: View3DAtts = visit_get_view(config_view, '3D') visit.SetView3D(View3DAtts) visit.SetActiveWindow(1) states = visit_get_states(state=state, states=states, states_range=states_range) visit_render_save_states(states, out_dir=out_dir, out_prefix=out_prefix, figsize=figsize) visit_finalize() return
def visit_plot_contour_3d(xdmf_path, name, value_range=(-5.0, 5.0), p3d_paths=None, config_view=None, out_dir=os.getcwd(), out_prefix=None, figsize=(1024, 1024), state=None, states=None, states_range=[0, None, 1]): visit_initialize() # Create database correlation with optional Point3D files. num_bodies = 0 databases = [str(xdmf_path)] if p3d_paths is not None: num_bodies = len(p3d_paths) databases = [str(path) for path in p3d_paths] databases.append(str(xdmf_path)) visit.CreateDatabaseCorrelation('common', databases[num_bodies:], 0) # Open the file with the coordinates of the immersed boundary. if num_bodies > 0: for i in range(num_bodies): visit.OpenDatabase(databases[i], 0, 'Point3D_1.0') # Add plot the mesh points. visit.AddPlot('Mesh', 'points', 1, 1) # Set attributes of the mesh plot. MeshAtts = visit.MeshAttributes() MeshAtts.legendFlag = 0 MeshAtts.meshColor = (255, 204, 0, 1.0 * 255) MeshAtts.meshColorSource = MeshAtts.MeshCustom MeshAtts.pointSize = 0.05 MeshAtts.pointType = MeshAtts.Point MeshAtts.pointSizePixels = 2 MeshAtts.opacity = 1 visit.SetPlotOptions(MeshAtts) # Open the XMF file for the z-component of the vorticity. visit.OpenDatabase(databases[-1], 0) # Add the plot of the contour of the z-component of the vorticity. visit.AddPlot('Contour', name, 1, 1) # Set attributes of the contour. ContourAtts = visit.ContourAttributes() ContourAtts.contourNLevels = 2 ContourAtts.SetMultiColor(0, (0, 51, 102, 0.6 * 255)) ContourAtts.SetMultiColor(1, (255, 0, 0, 0.6 * 255)) ContourAtts.legendFlag = 1 ContourAtts.minFlag = 1 ContourAtts.maxFlag = 1 ContourAtts.min = value_range[0] ContourAtts.max = value_range[1] visit.SetPlotOptions(ContourAtts) # Parse the 3D view configuration file. if config_view is not None: View3DAtts = visit_get_view(config_view, '3D') visit.SetView3D(View3DAtts) # Remove time and user info. AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.userInfoFlag = 0 AnnotationAtts.timeInfoFlag = 0 AnnotationAtts.axes3D.visible = 0 AnnotationAtts.axes3D.triadFlag = 1 AnnotationAtts.axes3D.bboxFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts) visit.SetActiveWindow(1) states = visit_get_states(state=state, states=states, states_range=states_range) if out_prefix is None: out_prefix = name + '_' visit_render_save_states(states, out_dir=out_dir, out_prefix=out_prefix, figsize=figsize) visit_finalize() return
def _setActiveWindow(self, windowIndex): assert isinstance(windowIndex, int) assert windowIndex > 0 and windowIndex < 17 visit.SetActiveWindow(windowIndex)
def MultipleWindows(Files, OperatorSet=None, Windows=False, SliceProject=1): """ Attain multiple windows for different applied operators. Data other than mesh are plotted individually as well. """ if Windows is False: It.Iterator(Files, OperatorSet) if Windows is True: Pa.PathCreator() # Creates necessary folders. Count = 1 # Load the plots without operators. for item in Files: Vi.SetActiveWindow(Count) # Select window to be worked in. Image = Mk.MakeImages([item]) Image.Plot() Image.Save() Vi.ToggleLockViewMode() # Lock the view perspective. Vi.AddWindow() # Add another window for next iteration. Count += 1 try: # Display plots with operators if defined. for item in OperatorSet: Vi.SetActiveWindow(Count) # Select window to be worked in. It.Iterator(Files, [item], SliceProject=0) Vi.DrawPlots() # Draw plots with operator. Wi.WindowSettings() Vi.ToggleLockViewMode() # Lock the view perspective. Vi.AddWindow() # Add another window for next iteration. Count += 1 except Exception: pass # Last window is always empty. Vi.SetActiveWindow(Count) Vi.DeleteWindow() # Delete last window. # Compensate for odd number of windows. if (Count - 1) < 2: Vi.SetWindowLayout(1) elif (Count - 1) == 2: Vi.SetWindowLayout(2) elif 2 < (Count - 1) <= 4: Vi.SetWindowLayout(4) elif 4 < (Count - 1) <= 6: Vi.SetWindowLayout(6) elif 6 < (Count - 1) <= 8: Vi.SetWindowLayout(8) elif (Count - 1) == 9: Vi.SetWindowLayout(9) elif 9 > (Count - 1) <= 16: print "Too many windows to view nicely." else: print "Too many windows for ViSit to Support." # Alternate saving scheme for multiple windows is used. i = 0 while os.path.exists("../Sessions/XML_Original/sampleMulti%s.session" % i): i += 1 Vi.SaveSession("../Sessions/XML_Original/sampleMulti%s.session" % i)
def activate(self): visit.SetActiveWindow(self.window_id)
def setActiveWindow(self, i): assert 0 < i <= len(self.windows) self._active_window = i v.SetActiveWindow(i)
def visit_plot_qcrit_wx_3d(xdmf_dir, wx_range=(-5.0, 5.0), q_value=0.1, config_view=None, out_dir=os.getcwd(), out_prefix='qcrit_wx_', figsize=(1024, 1024), state=None, states=None, states_range=[0, None, 1]): visit_initialize() # Define some variables to get the q_crit and wx_cc. p_xdmf_path = os.path.join(str(xdmf_dir), 'p.xmf') visit.OpenDatabase(p_xdmf_path, 0) # Define cell-centered velocity vector field. ux_xdmf_path = os.path.join(str(xdmf_dir), 'u.xmf') uy_xdmf_path = os.path.join(str(xdmf_dir), 'v.xmf') uz_xdmf_path = os.path.join(str(xdmf_dir), 'w.xmf') vel_expr = ('{' + 'pos_cmfe(<{}[0]id:u>, <p Grid>, 1.0),'.format(ux_xdmf_path) + 'pos_cmfe(<{}[0]id:v>, <p Grid>, 0.0),'.format(uy_xdmf_path) + 'pos_cmfe(<{}[0]id:w>, <p Grid>, 0.0)'.format(uz_xdmf_path) + '}') visit.DefineVectorExpression('velocity', vel_expr) # Define Q-criterion. qcrit_expr = ('q_criterion(' + 'gradient(velocity[0]),' + 'gradient(velocity[1]),' + 'gradient(velocity[2])' + ')') visit.DefineScalarExpression('q_crit', qcrit_expr) # Define cell-centered streamwise vorticity. wx_xdmf_path = os.path.join(str(xdmf_dir), 'wx.xmf') wx_exp = 'pos_cmfe(<{}[0]id:wx>, <p Grid>, 0.0)'.format(wx_xdmf_path) visit.DefineScalarExpression('wx_cc', wx_exp) # Add a pseudocolor of the cell-centered streamwise vorticity. visit.AddPlot('Pseudocolor', 'wx_cc', 1, 1) PseudocolorAtts = visit.PseudocolorAttributes() PseudocolorAtts.minFlag = 1 PseudocolorAtts.min = wx_range[0] PseudocolorAtts.maxFlag = 1 PseudocolorAtts.max = wx_range[1] PseudocolorAtts.colorTableName = 'viridis' PseudocolorAtts.invertColorTable = 0 PseudocolorAtts.opacityType = PseudocolorAtts.Constant PseudocolorAtts.opacity = 0.8 PseudocolorAtts.legendFlag = 0 visit.SetPlotOptions(PseudocolorAtts) # Add an isosurface of the Q-criterion. visit.AddOperator('Isosurface', 1) IsosurfaceAtts = visit.IsosurfaceAttributes() IsosurfaceAtts.variable = 'q_crit' IsosurfaceAtts.contourMethod = IsosurfaceAtts.Value IsosurfaceAtts.contourValue = (q_value) IsosurfaceAtts.scaling = IsosurfaceAtts.Linear visit.SetOperatorOptions(IsosurfaceAtts, 1) # Remove info about user, time, database, and legend. AnnotationAtts = visit.AnnotationAttributes() AnnotationAtts.userInfoFlag = 0 AnnotationAtts.databaseInfoFlag = 0 AnnotationAtts.timeInfoFlag = 0 AnnotationAtts.legendInfoFlag = 0 AnnotationAtts.axes3D.visible = 0 AnnotationAtts.axes3D.triadFlag = 1 AnnotationAtts.axes3D.bboxFlag = 0 visit.SetAnnotationAttributes(AnnotationAtts) # Parse the 3D view configuration file. if config_view is not None: View3DAtts = visit_get_view(config_view, '3D') visit.SetView3D(View3DAtts) visit.SetActiveWindow(1) states = visit_get_states(state=state, states=states, states_range=states_range) visit_render_save_states(states, out_dir=out_dir, out_prefix=out_prefix, figsize=figsize) visit_finalize() return