From 2f35838806cb5e04fa9c635003e172793013856a Mon Sep 17 00:00:00 2001 From: "clemens.fricke" Date: Fri, 22 Sep 2023 12:38:28 +0200 Subject: [PATCH] Exp: Add 3D tetra mesh, Feat: Add vertex import for msh import --- examples/show_gmsh.py | 9 +++++++-- gustaf/io/meshio.py | 11 ++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/examples/show_gmsh.py b/examples/show_gmsh.py index 38d3e5e63..dde821603 100644 --- a/examples/show_gmsh.py +++ b/examples/show_gmsh.py @@ -13,10 +13,12 @@ if __name__ == "__main__": mesh_file_tri = pathlib.Path("faces/tri/2DChannelTria.msh") mesh_file_quad = pathlib.Path("faces/quad/2DChannelQuad.msh") + mesh_file_tetra = pathlib.Path("volumes/tet/3DBrickTet.msh") base_samples_path = pathlib.Path(__file__).parent / "samples" load_sample_file.load_sample_file(str(mesh_file_tri)) load_sample_file.load_sample_file(str(mesh_file_quad)) + load_sample_file.load_sample_file(str(mesh_file_tetra)) # load the .msh file directly with the correct io module (meshio) loaded_mesh_tri = io.meshio.load(base_samples_path / mesh_file_tri) @@ -30,6 +32,9 @@ # load the .msh file with the default load function which needs to find out # it self which module is the correct one. - loaded_mesh_default = io.load(base_samples_path / mesh_file_tri) + loaded_mesh_default = io.load(base_samples_path / mesh_file_tetra) - gustaf.show(loaded_mesh_default) + gustaf.show( + *[[msh.__class__.__name__, msh] for msh in loaded_mesh_default], + title="3D mesh with tetrahedrons", + ) diff --git a/gustaf/io/meshio.py b/gustaf/io/meshio.py index 7027adf4f..7254a9e11 100644 --- a/gustaf/io/meshio.py +++ b/gustaf/io/meshio.py @@ -25,6 +25,7 @@ "quad": Faces, "triangle": Faces, "line": Edges, + "vertex": Vertices, } @@ -44,7 +45,7 @@ def load(fname): Returns -------- - MESH_TYPES + MESH_TYPES | List[MESH_TYPES] """ # fname sanity check fname = pathlib.Path(fname) @@ -72,8 +73,12 @@ def load(fname): f"`{element_type}`-elements are not supported in gustaf" ) continue - - meshes.append(_meshio2gus[element_type](vertices, elements=elements)) + if element_type.startswith("vertex"): + meshes.append(Vertices(vertices[elements.ravel()])) + else: + meshes.append( + _meshio2gus[element_type](vertices, elements=elements) + ) return meshes[0] if len(meshes) == 1 else meshes