def setup_visit(plot_variable_data, db_name): print 'Opening database...' # Get the complete database name including directory path, db file # pattern and extension, followed by the word database # Example: db_filename = './output*.vtk database' visit.OpenDatabase(db_name) # Getting the list of current variables db_meta_data = visit.GetMetaData(db_name) scalar_list = [db_meta_data.GetScalars(i).name for i in range(db_meta_data.GetNumScalars())] vector_list = [db_meta_data.GetVectors(i).name for i in range(db_meta_data.GetNumVectors())] for vec in vector_list: scalar_list.append(vec + '_magnitude') # Check if current variable name exists in the database. If no, then # res becomes 0. Hence, we need to define a scalar expression for the # current variable if plot_variable_data['plot variable'] in scalar_list or \ plot_variable_data['plot variable'] in vector_list: visit.AddPlot(plot_variable_data['plot type'], \ plot_variable_data['plot variable']) else: print 'No existing variable of that name' visit.DefineScalarExpression(plot_variable_data['plot variable'], \ plot_variable_data['plot variable definition']) visit.AddPlot(plot_variable_data['plot type'], \ plot_variable_data['plot variable']) if plot_variable_data['plot type'] == 'Pseudocolor': p = visit.PseudocolorAttributes() p.SetCentering(1) p.colorTableName = 'hot_desaturated' # p.colorTableName = 'rainbow' visit.SetPlotOptions(p)
def setup_workspace(self, file): define_flow_vpe("flow", pjoin(examples_dir, file), "pyocl_ops", 0, 0) visit.AddPlot("Pseudocolor", "flow") visit.DrawPlots() visit.DefineScalarExpression("check", "flow - ((d + p)^2.0 + (d-p)^2.0)") visit.AddPlot("Pseudocolor", "check") visit.DrawPlots()
def setup_visit(plot_variable_data, db_name): print 'Opening database...' # Get the complete database name including directory path, db file # pattern and extension, followed by the word database # Example: db_filename = './output*.vtk database' visit.OpenDatabase(db_name) # Getting the list of current variables db_meta_data = visit.GetMetaData(db_name) scalar_list = [ db_meta_data.GetScalars(i).name for i in range(db_meta_data.GetNumScalars()) ] vector_list = [ db_meta_data.GetVectors(i).name for i in range(db_meta_data.GetNumVectors()) ] for vec in vector_list: scalar_list.append(vec + '_magnitude') # Check if current variable name exists in the database. If no, then # res becomes 0. Hence, we need to define a scalar expression for the # current variable if plot_variable_data['plot variable'] in scalar_list or \ plot_variable_data['plot variable'] in vector_list: visit.AddPlot(plot_variable_data['plot type'], \ plot_variable_data['plot variable']) else: print 'No existing variable of that name' visit.DefineScalarExpression(plot_variable_data['plot variable'], \ plot_variable_data['plot variable definition']) visit.AddPlot(plot_variable_data['plot type'], \ plot_variable_data['plot variable']) # Making mesh transparent and overlaying it on the plot visit.AddPlot('Mesh', 'mesh') p = visit.MeshAttributes() p.SetOpacity(0.25) visit.SetPlotOptions(p)
def define(ename, edef, etype='scalar', echo=False): """ Defines a new expression. If expression with given name already exists the new definition will replace it. """ etype = etype.lower() if not etype in ["scalar", "vector", "curve", "array", "tensor"]: raise VisItException("Unsupported expression type: %s" % etype) delete(ename) if exists(ename): raise VisItException("Cannot redefine database expression: %s" % ename) if etype == "scalar": visit.DefineScalarExpression(ename, edef) elif etype == "vector": visit.DefineVectorExpression(ename, edef) elif etype == "curve": visit.DefineCurveExpression(ename, edef) elif etype == "array": visit.DefineArrayExpression(ename, edef) elif etype == "tensor": visit.DefineTensorExpression(ename, edef) if echo: print "[Expression: %s = '%s']" % (ename, edef)
def createPseudocolor(self, varname, display_name=None, cmap=None, limits=None, linewidth=None, legend=True, alpha=False): """Generic creation of pseudocolor""" if display_name is None: display_name = vrc.renameScalar(varname) if "temperature" in display_name: display_name = display_name.replace("[K]", "[C]") print "defining alias: %s = %s"%(display_name, varname) v.DefineScalarExpression(display_name, "%s - 273.15"%varname) elif display_name != varname: print "defining alias: %s = %s"%(display_name, varname) v.DefineScalarExpression(display_name, varname) v.AddPlot('Pseudocolor', display_name) pa = v.PseudocolorAttributes() # limits if limits is None: limits = vrc.getLimits(varname) if limits is not None: min = limits[0] max = limits[1] if min is not None: pa.minFlag = 1 pa.min = min if max is not None: pa.maxFlag = 1 pa.max = max # opacity if alpha: pa.opacity = 0 pa.opacityType = pa.ColorTable # colormap if cmap is not None: reverse = cmap.endswith("_r") if reverse: cmap = cmap.strip("_r") pa.invertColorTable = 1 pa.colorTableName = cmap # linewidth for 2D if linewidth is None: linewidth = vrc.rcParams['pseudocolor.linewidth'] pa.lineWidth = linewidth # turn off legend for 2D surf if not legend: pa.legendFlag = 0 v.SetPlotOptions(pa) pname = v.GetPlotList().GetPlots(v.GetNumPlots()-1).plotName if legend: plot = Plot(pname, 'Pseudocolor', pa, display_name) else: plot = Plot(pname, 'Pseudocolor', pa) self.plots.append(plot) return plot
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
import visit dirname = "/Users/uec/research/water/data/meshing/data/meshes/06010208/12" db = os.listdir(dirname) dbf = [os.path.join(dirname, d) for d in db] opacity = 0.5 vmin = 100 vmax = 1000 for d in dbf: visit.OpenDatabase(d) visit.AddPlot("Mesh", "mesh") ma = visit.MeshAttributes() ma.legendFlag = 0 ma.opaqueMode = ma.On ma.opacity = opacity visit.SetPlotOptions(ma) visit.DefineScalarExpression("z", "coord(mesh)[2]") visit.AddPlot('Pseudocolor', "z") pa = visit.PseudocolorAttributes() pa.minFlag = 1 pa.min = vmin pa.maxFlag = 1 pa.max = vmax visit.SetPlotOptions(pa)
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
import time import sys sys.path.append("/home/tbent/packages/visit2_7_0/2.7.0/linux-x86_64/lib/site-packages/") import visit visit.Launch('/home/tbent/packages/visit2_7_0/bin/') filename_prefix = 'solution_' filename_prefix = 'init_refinement_' for i in range(12): time.sleep(0.5) visit.DeleteAllPlots() visit.OpenDatabase('./data/test/' + filename_prefix + str(i) + '.0000.pvtu') visit.DefineScalarExpression('logabsoldszx', 'log(abs(old_szx))') # visit.AddPlot('Pseudocolor', 'logabsoldszx') visit.AddPlot('Pseudocolor', 'vel') # visit.AddPlot('Mesh', 'mesh') visit.DrawPlots()
import sys # visit sys.path.append("/home/neo/visit/2.11.0/linux-x86_64/lib/site-packages") import visit as vs vs.Launch() vs.OpenDatabase("visit-data/globe.silo") vs.DefineScalarExpression("myvar", "sin(u) + cos(w)") # Plot the scalar expression variable. vs.AddPlot("Pseudocolor", "myvar") vs.DrawPlots() # Plot a vector expression variable. vs.DefineVectorExpression("myvec", "{u,v,w}") vs.AddPlot("Vector", "myvec") vs.DrawPlots() d = input('Press anything to quit')