Replies: 1 comment
-
This is deepseek's solution to this problem, seems to work. import meshio
import numpy as np
# Load the volume mesh
volume_mesh = meshio.read("volume_mesh.vtk") # Replace with your file
# Extract tetrahedron cells
tetra_cells = volume_mesh.get_cells_type("tetra")
# Get the faces of all tetrahedrons
# Each tetrahedron has 4 triangular faces
faces = np.vstack([
tetra_cells[:, [0, 1, 2]], # Face 1
tetra_cells[:, [0, 1, 3]], # Face 2
tetra_cells[:, [0, 2, 3]], # Face 3
tetra_cells[:, [1, 2, 3]], # Face 4
])
# Sort each face to ensure consistent ordering
faces = np.sort(faces, axis=1)
# Find unique faces (boundary faces)
# A face is on the surface if it appears only once
unique_faces, face_counts = np.unique(faces, axis=0, return_counts=True)
surface_faces = unique_faces[face_counts == 1]
# Create the surface mesh
surface_mesh = meshio.Mesh(
points=volume_mesh.points, # Use the same points as the volume mesh
cells=[("triangle", surface_faces)] # Use the boundary faces
)
# Save the surface mesh
meshio.write("surface_mesh.stl", surface_mesh) # Save as STL or another surface format |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I have some FE mesh consisting tet4 elements. Their
cells_dict
only havetetra
key and no 'triangle' key. Then can I extract its surface or boundary usingmeshio
?Beta Was this translation helpful? Give feedback.
All reactions