Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions bluemira/mesh/meshing.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,29 @@ class GmshFileType(Enum):
GMSH = auto()


class MshFileExtensionType(Enum):
"""Gmsh file extensions"""

GEO = ".geo"
GEO_UNROLLED = ".geo_unrolled"
MSH = ".msh"
XDMF = ".xdmf"
H5 = ".h5"
ini = ".ini"

@classmethod
def _missing_(cls, value):
"""
Called when value does not match any enum member.

Raises
------
ValueError
Unsupported mesh file extension
"""
raise ValueError(f"Unsupported mesh file extension: '{value}'")


class Mesh:
"""
A class for supporting the creation of meshes and writing out those meshes to files.
Expand Down Expand Up @@ -220,16 +243,18 @@ def _check_meshfile(meshfile: str | list) -> list[str]:
TypeError
Meshfile must be a string or list of strings
"""
# TODO @ivanmaione: should be implemented also a check on the file extension.
# Only a limited type of file extensions is allowed by gmsh.
# 3656
if isinstance(meshfile, str):
meshfile = [meshfile]
elif isinstance(meshfile, list):
if len(meshfile) < 1:
raise ValueError("meshfile is an empty list")
else:
raise TypeError("meshfile must be a string or a list of strings")

for filename in meshfile:
ext = Path(filename).suffix.lower()
MshFileExtensionType(ext) # raises error if invalid

return meshfile

@property
Expand Down
Loading