Beispiel #1
0
def query(qname, args=None, rmode="value", echo=False, msg_lvl=2, **kwargs):
    """
    Executes a query and returns result based on 'rmode'.
     rmode={'value','string',object'}
     Raises an exception if an error occurs.
    """
    if echo:
        print("[Query: %s(%s)]" % (qname, str(args)))
    prev_lvl = visit.SuppressMessages(msg_lvl)
    if args is None:
        qres = visit.Query(qname, **kwargs)
    else:
        # call w/ args + kwargs
        cargs = [qname]
        cargs.extend(args)
        qres = visit.Query(*cargs, **kwargs)
    if qres == 0:
        visit.SuppressMessages(prev_lvl)
        raise VisItException("Execution of query: '%s' failed." % qname)
    if rmode == "value":
        res = visit.GetQueryOutputValue()
    elif rmode == "string" or rmode == "text" or rmode == "txt":
        res = visit.GetQueryOutputString()
    elif rmode == "object":
        res = visit.GetQueryOutputObject()
    else:
        visit.SuppressMessages(prev_lvl)
        raise VisItException("Unsupported query result mode: %s" % rmode)
    visit.SuppressMessages(prev_lvl)
    return res
Beispiel #2
0
 def test_03_pyocl_compile(self):
     self.setup_workspace("flow_vpe_pyocl_compile_example_1.py")
     # the total sum of all scalar vals of 'check' should equal zero.
     res = 1e8
     if visit.Query("Variable Sum"):
         res = visit.GetQueryOutputValue()
     self.assertTrue(res < 1.0e-8)
 def test_python(self):
     visit.OpenDatabase(db)
     visit.AddPlot("Pseudocolor", "d")
     visit.DrawPlots()
     exprs.clear()
     exprs.define_python("test_vpe", file=vpe_file, args=["d"])
     visit.Query("Max")
     r1 = visit.GetQueryOutputValue()
     visit.ChangeActivePlotsVar("test_vpe")
     visit.Query("Max")
     r2 = visit.GetQueryOutputValue()
     visit.ChangeActivePlotsVar("d")
     self.assertTrue(r1 * r1 - r2 < 1e-2)
     exprs.clear()
     visit.DeleteAllPlots()
     visit.CloseDatabase(db)
Beispiel #4
0
def python_query(source=None,file=None,vars=None,args=[],rmode="value",echo = False, msg_lvl = 2):
    """
    Executes a Python Query and returns result based on 'rmode'.
     rmode={'value','string',object'}
     Rasies an exception if an error occurs.
    """
    if echo:
        print "[PythonQuery]"
    prev_lvl = visit.SuppressMessages(msg_lvl)
    kwargs = {}
    if not source is None:
        kwargs["source"] = source
    if not file is None:
        kwargs["file"] = file
    if not vars is None:
        kwargs["vars"] = vars
    if len(args) > 0:
        kwargs["args"] = args
    qres = visit.PythonQuery(**kwargs)
    if qres == 0:
        visit.SuppressMessages(prev_lvl)
        raise VisItException("Execution of PythonQuery failed.")
    if rmode == "value":
        res =  visit.GetQueryOutputValue()
    elif rmode == "string":
        res = visit.GetQueryOutputString()
    elif rmode == "object":
        res =  visit.GetQueryOutputObject()
    else:
        visit.SuppressMessages(prev_lvl)
        raise VisItException("Unsupported Python Query result mode: %s" % rmode)
    visit.SuppressMessages(prev_lvl)
    return res
            PseudocolorAtts.max = 0.05
            visit.SetPlotOptions(PseudocolorAtts)
            SliceAtts = visit.SliceAttributes()
            SliceAtts.originType = SliceAtts.Point
            SliceAtts.normal = (-1, 0, 0)
            SliceAtts.axisType = SliceAtts.XAxis  # XAxis, YAxis, ZAxis, Arbitrary, ThetaPhi
            SliceAtts.upAxis = (0, 1, 0)
            SliceAtts.project2d = 1

            for Z in Zs:
                SliceAtts.originPoint = (Z, 0, 0)
                visit.SetOperatorOptions(SliceAtts, 1)
                visit.DrawPlots()

                visit.Query("Average Value")
                sol_hold[i] = visit.GetQueryOutputValue()

                i += 1

            visit.DeleteAllPlots()

            np.savetxt(
                output_folder + sim + '_' + case + '_' + timestep + '_solHold',
                np.asarray([Zs, sol_hold]).T)

            # Second plot

            visit.AddPlot("Curve", "operators/Lineout/vol_frac_average")

            LineoutAtts = visit.LineoutAttributes()
            LineoutAtts.samplingOn = 1
Beispiel #6
0
def visitTime(round=None):
    v.Query("Time")
    return getTime(years=v.GetQueryOutputValue(), round=round)
def visit_render_save_states(states,
                             config_view=None,
                             out_dir=os.getcwd(),
                             prefix=None,
                             figsize=(1024, 1024)):
    """Render and save states into PNG files.

    Parameters
    ----------
    states : list-alike
        List of states to render and save.
    config_view : str, optional
        Path of the YAML file with the configuration of the view;
        default is None (use default VisIt view).
    out_dir : str, optional
        Output directory; created is non-existent;
        default is the present working directory (".").
    prefix : str, optional
        Filename prefix; default is "None" (no prefix).
    figsize : tuple
        Figure width and height (in pixels); default is (1024, 1024).

    """
    visit.Source(VISIT_MAKEMOVIE)
    visit.ToggleCameraViewMode()

    # Create output directory if necessary.
    if not os.path.isdir(out_dir):
        os.makedirs(out_dir)

    # Define common attributes to save the window.
    SaveWindowAtts = visit.SaveWindowAttributes()
    SaveWindowAtts.outputToCurrentDirectory = 0
    SaveWindowAtts.outputDirectory = out_dir
    SaveWindowAtts.family = 0
    SaveWindowAtts.format = SaveWindowAtts.PNG
    SaveWindowAtts.width, SaveWindowAtts.height = figsize
    SaveWindowAtts.quality = 100
    SaveWindowAtts.resConstraint = SaveWindowAtts.NoConstraint

    # Define common rendering attributes.
    RenderingAtts = visit.RenderingAttributes()

    # Parse YAML file with the 3D view configuration.
    if config_view is not None:
        View3DAtts = visit_get_view(config_view, 3)

    # Loop over the states to render and save the plots.
    for i, state in enumerate(states):
        print('[state {}] Rendering and saving figure ...'.format(state))
        visit.SetTimeSliderState(state)

        if i == 0:
            visit.DrawPlots()
            visit.SetView3D(View3DAtts)

        # Get time-step index (stored as time value in XDMF file).
        visit.Query('Time')
        timestep = int(visit.GetQueryOutputValue())

        # Set rendering attributes.
        visit.SetRenderingAttributes(RenderingAtts)

        # Set state-specific attributes to save the window.
        SaveWindowAtts.fileName = '{}{:0>7}'.format(prefix, timestep)
        visit.SetSaveWindowAttributes(SaveWindowAtts)

        visit.SaveWindow()