MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / hex_to_tet

Function hex_to_tet

python/pymesh/meshutils/hex_to_tet.py:9–54  ·  view source on GitHub ↗

Convert hex mesh into tet mesh. Args: mesh (:class:`Mesh`): Input hex mesh. keep_symmetry (`boolean`): (optional) Whether to split hex symmetrically into tets. Default is False. subdiv_order (`int`): (optional) Number of times to subdiv the hex

(mesh, keep_symmetry=False, subdiv_order=0)

Source from the content-addressed store, hash-verified

7from .generate_box_mesh import subdivide_hex
8
9def hex_to_tet(mesh, keep_symmetry=False, subdiv_order=0):
10 """
11 Convert hex mesh into tet mesh.
12
13 Args:
14 mesh (:class:`Mesh`): Input hex mesh.
15 keep_symmetry (`boolean`): (optional) Whether to split hex symmetrically
16 into tets. Default is False.
17 subdiv_order (`int`): (optional) Number of times to subdiv the hex
18 before splitting. Default is 0.
19
20 Returns:
21 The resulting tet mesh.
22 """
23 assert(mesh.num_voxels > 0)
24 num_vertices = 0
25 vertices = []
26 tets = []
27 hex_indices = []
28 for hex_index, corners in enumerate(mesh.voxels):
29 corners = mesh.vertices[corners]
30 subcell_corners = subdivide_hex(corners, subdiv_order)
31 for corners in subcell_corners:
32 if keep_symmetry:
33 cell_vertices, cell_elems =\
34 split_hex_into_tets_symmetrically(corners)
35 else:
36 cell_vertices, cell_elems =\
37 split_hex_into_tets(corners)
38 vertices.append(cell_vertices)
39 tets.append(cell_elems + num_vertices)
40 num_vertices += len(cell_vertices)
41 hex_indices.append(np.ones(len(cell_elems)) * hex_index)
42
43 vertices = np.vstack(vertices)
44 tets = np.vstack(tets)
45 hex_indices = np.vstack(hex_indices).ravel(order="C")
46
47 vertices, tets, __ = remove_duplicated_vertices_raw(vertices, tets)
48 vertices, tets, __ = remove_isolated_vertices_raw(vertices, tets)
49
50 faces = np.array([], dtype=int)
51 mesh = form_mesh(vertices, faces, tets)
52 mesh.add_attribute("cell_index")
53 mesh.set_attribute("cell_index", hex_indices)
54 return mesh

Callers 2

test_single_hexMethod · 0.90
test_multiple_hexMethod · 0.90

Calls 9

enumerateFunction · 0.85
subdivide_hexFunction · 0.85
split_hex_into_tetsFunction · 0.85
form_meshFunction · 0.85
add_attributeMethod · 0.45
set_attributeMethod · 0.45

Tested by 2

test_single_hexMethod · 0.72
test_multiple_hexMethod · 0.72