Skip to content

Commit

Permalink
always expect available meshio and pyvista
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippMetsch committed Aug 17, 2020
1 parent 15dd3a4 commit baaf813
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 32 deletions.
4 changes: 1 addition & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@ include LICENSE
include examples/*.py
include docs/conf.py
include docs/Makefile
recursive-include docs/*.rst
include docs/images

recursive-include docs *.rst

4 changes: 0 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ software packages are required:
3. `pyvista <https://www.pyvista.org/>`_ for the visualization of meshes
4. `pythonocc <https://github.com/tpaviot/pythonocc-core/>`_ for the visualization of the model geometry

If the visualization functionality is not required and meshes exported in the
Gmsh-internal ``.msh`` format are sufficient, a working installation of Gmsh and
its Python-API is enough.


Getting Started
***************
Expand Down
22 changes: 6 additions & 16 deletions gmshModel/Model/GenericModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,19 @@

# additional program libraries
import gmsh # Gmsh Python-API
try: # meshio for mesh file conversions
import meshio # meshio is available
MESHIO_AVAILABLE=True # -> set availability of meshio
except ImportError: # meshio is not available
MESHIO_AVAILABLE=False # -> set availability of meshio
logger.warning("Library \"meshio\" not found. In order to export meshes in formats other than \".msh\", the meshio library is needed.")
import meshio # meshio for mesh file format conversions

# self-defined class definitions and modules
from ..Geometry import GeometricObjects as geomObj # classes for implemented geometric objects
from ..Geometry import GeometricObjects as geomObj # classes for implemented geometric objects
from ..Visualization.GeometryVisualization import GeometryVisualization, PYTHONOCC_AVAILABLE # class for geometry visualization
from ..Visualization.MeshVisualization import MeshVisualization, PYVISTA_AVAILABLE # class for mesh visualization
from ..Visualization.MeshVisualization import MeshVisualization # class for mesh visualization


#############################
# Set configuration options #
#############################
SUPPORTED_GEOMETRY_FORMATS=[".brep", ".stp", ".step"] # set supported geometry formats
SUPPORTED_MESH_FORMATS=list(meshio.extension_to_filetype.keys()) if MESHIO_AVAILABLE else [".msh"] # set supported mesh file formats
SUPPORTED_MESH_FORMATS=list(meshio.extension_to_filetype.keys()) # set supported mesh file formats


#############################
Expand Down Expand Up @@ -291,7 +286,7 @@ def saveMesh(self,file=None):
os.makedirs(fileDir,exist_ok=True) # ensure that the file directory exists
if fileExt == ".msh": # file extension is "".msh"
gmsh.write(fileDir+"/"+fileName+fileExt) # -> save mesh using built-in gmsh.write method
elif MESHIO_AVAILABLE: # file extension is different from ".msh" and meshio is available
else: # file extension is different from ".msh"
if fileExt in SUPPORTED_MESH_FORMATS: # -> check if file extension is supported by meshio
with tf.TemporaryDirectory() as tmpDir: # ->-> create temporary directory
tmpFile=tmpDir+"/"+self.modelName+".msh" # ->-> create temporary file
Expand All @@ -302,8 +297,6 @@ def saveMesh(self,file=None):
self._convertMesh(tmpFile,fileDir+"/"+fileName+fileExt) # ->-> convert mesh to required file format
else: # raise error if mesh file format is not supported by meshio
raise ValueError("Unknown mesh file extension {}. The output mesh format must be supported by the meshio library.".format(fileExt))
else:
raise ValueError("Unsupported mesh file format {} for unavailabe meshio package. Install the meshio library to export meshes to other formats than \".msh\".".format(fileExt))


#####################################################
Expand Down Expand Up @@ -360,10 +353,7 @@ def visualizeGeometry(self):
############################################################
def visualizeMesh(self):
"""Method to visualize the generated mesh using pyvista and vtk"""
if PYVISTA_AVAILABLE: # optional pyvista package is available
MeshVisualization(self) # -> visualize the mesh
else: # optional pyvista package is unavailable
logger.warning("Mesh visualization is unavailable due to missing packages.") # -> do nothing but printing a warning
MeshVisualization(self) # -> visualize the mesh


####################################################################
Expand Down
9 changes: 2 additions & 7 deletions gmshModel/Visualization/MeshVisualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@
logger=logging.getLogger(__name__) # -> set logger

# additional program libraries
try: # try import of pyvista library
import pyvista as pv # -> load pyVista visualization module
import vtk # -> load vtk since pyvista depends on it, i.e. it must be available
PYVISTA_AVAILABLE=True # -> set availability flag to True
except ImportError: # handle unavailable pyvista module
PYVISTA_AVAILABLE=False # -> set availability flag to False
logger.warning("The mesh visualization class depends on the pyvista package. It seems like you have not installed it. The mesh visualization is therefore unavailable.")
import pyvista as pv # -> load pyVista visualization module
import vtk # -> load vtk since pyvista depends on it, i.e. it must be available


##################################
Expand Down
2 changes: 1 addition & 1 deletion gmshModel/_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Version information for GmshModel"""
# versioning scheme: major, minor, patch
versionInfo= 1, 0, 7
versionInfo= 1, 0, 8

__version__= ".".join(map(str, versionInfo))
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@
author="Philipp Metsch",
author_email="philipp.metsch@tu-dresden.de",
url='https://github.com/NEFM-TUDresden/GmshModel',
project_urls={
"Code": "https://github.com/NEFM-TUDresden/GmshModel",
"Issues": "https://github.com/NEFM-TUDresden/GmshModel/issues",
"Documentation": "https://gmshmodel.readthedocs.io/en/latest/",
},
description="A mesh modeling interface to the Gmsh-Python-API",
long_description=readmeInfo,
long_description_content_type="text/x-rst",
license="MIT",
classifiers=["Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
Expand Down

0 comments on commit baaf813

Please sign in to comment.