Esempio n. 1
0
def visualize_with_paraview(obj, mode="element", transformation=None):
    """
    View a grid or grid function with Paraview.

    Parameters
    ----------
    obj : bempp.api.Grid or bempp.api.GridFunction
        Grid or grid function to visualize.
    mode : string
        One of 'element' or 'node'
        (default 'vertices')
    transformation : callable
        A function object that is applied to the data before
        writing it out

    Notes
    -----
    This function writes the data into a temp file and
    visualizes it.

    """
    import tempfile
    import subprocess
    from bempp.api import export, TMP_PATH, GridFunction
    from bempp.api.grid.grid import Grid
    from bempp.api.utils import which
    import os

    if os.name == "nt":
        pview = which("paraview.exe")
    else:
        pview = which("paraview")

    if pview is None:
        raise EnvironmentError(
            "Could not find Paraview." +
            "Interactive plotting with Paraview not available.")

    outfile = tempfile.NamedTemporaryFile(suffix=".vtu",
                                          dir=TMP_PATH,
                                          delete=False)
    if isinstance(obj, Grid):
        export(outfile.name, grid=obj)
    elif isinstance(obj, GridFunction):
        export(
            outfile.name,
            grid_function=obj,
            transformation=transformation,
            data_type=mode,
        )
    outfile.close()

    subprocess.Popen([pview, outfile.name])
Esempio n. 2
0
def _gmsh_path():
    """Find Gmsh."""
    from bempp.api.utils import which

    if _os.name == "nt":
        gmp = which("gmsh.exe")
    else:
        gmp = which("gmsh")
    if gmp is None:
        print("Could not find Gmsh." +
              "Interactive plotting and shapes module not available.")
    return gmp