-
Notifications
You must be signed in to change notification settings - Fork 48
Open
Description
Dear bempp team,
We are developping software for charge particle optics simulation (efly) using bempp-cl. However, when we set up the gui for our softwar in windows system(Win10), the GMSH.exe cannot be launched due to the batch file (gmsh.bat) used to launch GMSH.exe in bempp for windows system. But, shell is not enabled by default. Therefore, part of the function visualize_with_gmsh(obj, mode=None, transformation=None) in viewer.py (bempp\api\external\viewer.py) should be modified to enable the shell as follows:
## important change for running of windows GUI
import shutil
import os
gmsh_path = shutil.which("gmsh")
env = os.environ.copy()
if gmsh_path.lower().endswith(".bat"):
subprocess.Popen(f'"{gmsh_path}" "{outfile.name}"', shell=True, env=env)
else:
subprocess.Popen([gmsh_path, outfile.name], env=env)
#subprocess.Popen(["gmsh", outfile.name])
#subprocess.Popen([GMSH_PATH, outfile.name])
========================================================
Modified @function:
def visualize_with_gmsh(obj, mode=None, transformation=None):
"""
View a grid or grid function with Gmsh.
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, GMSH_PATH, TMP_PATH, GridFunction
from bempp.api.grid.grid import Grid
if GMSH_PATH is None:
print("Gmsh not available for visualization.")
return None
outfile = tempfile.NamedTemporaryFile(suffix=".msh", 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()
## important change for running of windows GUI
import shutil
import os
gmsh_path = shutil.which("gmsh")
env = os.environ.copy()
if gmsh_path.lower().endswith(".bat"):
subprocess.Popen(f'"{gmsh_path}" "{outfile.name}"', shell=True, env=env)
else:
subprocess.Popen([gmsh_path, outfile.name], env=env)
#subprocess.Popen(["gmsh", outfile.name])
#subprocess.Popen([GMSH_PATH, outfile.name])
Metadata
Metadata
Assignees
Labels
No labels