Skip to content

Commit

Permalink
Exp: Add 3D tetra mesh, Feat: Add vertex import for msh import
Browse files Browse the repository at this point in the history
  • Loading branch information
clemens-fricke committed Sep 22, 2023
1 parent 741bbce commit 2f35838
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 7 additions & 2 deletions examples/show_gmsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
)
11 changes: 8 additions & 3 deletions gustaf/io/meshio.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"quad": Faces,
"triangle": Faces,
"line": Edges,
"vertex": Vertices,
}


Expand All @@ -44,7 +45,7 @@ def load(fname):
Returns
--------
MESH_TYPES
MESH_TYPES | List[MESH_TYPES]
"""
# fname sanity check
fname = pathlib.Path(fname)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 2f35838

Please sign in to comment.