File tree Expand file tree Collapse file tree 1 file changed +28
-3
lines changed
Expand file tree Collapse file tree 1 file changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -184,6 +184,29 @@ class GmshFileType(Enum):
184184 GMSH = auto ()
185185
186186
187+ class MshFileExtensionType (Enum ):
188+ """Gmsh file extensions"""
189+
190+ GEO = ".geo"
191+ GEO_UNROLLED = ".geo_unrolled"
192+ MSH = ".msh"
193+ XDMF = ".xdmf"
194+ H5 = ".h5"
195+ ini = ".ini"
196+
197+ @classmethod
198+ def _missing_ (cls , value ):
199+ """
200+ Called when value does not match any enum member.
201+
202+ Raises
203+ ------
204+ ValueError
205+ Unsupported mesh file extension
206+ """
207+ raise ValueError (f"Unsupported mesh file extension: '{ value } '" )
208+
209+
187210class Mesh :
188211 """
189212 A class for supporting the creation of meshes and writing out those meshes to files.
@@ -220,16 +243,18 @@ def _check_meshfile(meshfile: str | list) -> list[str]:
220243 TypeError
221244 Meshfile must be a string or list of strings
222245 """
223- # TODO @ivanmaione: should be implemented also a check on the file extension.
224- # Only a limited type of file extensions is allowed by gmsh.
225- # 3656
226246 if isinstance (meshfile , str ):
227247 meshfile = [meshfile ]
228248 elif isinstance (meshfile , list ):
229249 if len (meshfile ) < 1 :
230250 raise ValueError ("meshfile is an empty list" )
231251 else :
232252 raise TypeError ("meshfile must be a string or a list of strings" )
253+
254+ for filename in meshfile :
255+ ext = Path (filename ).suffix .lower ()
256+ MshFileExtensionType (ext ) # raises error if invalid
257+
233258 return meshfile
234259
235260 @property
You can’t perform that action at this time.
0 commit comments