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

Function generate_3D_box_mesh

python/pymesh/meshutils/generate_box_mesh.py:171–224  ·  view source on GitHub ↗
(bbox_min, bbox_max, num_samples, keep_symmetry=False,
        subdiv_order=0, using_simplex=True)

Source from the content-addressed store, hash-verified

169 return tets
170
171def generate_3D_box_mesh(bbox_min, bbox_max, num_samples, keep_symmetry=False,
172 subdiv_order=0, using_simplex=True):
173 if isinstance(num_samples, int):
174 num_samples = [num_samples, num_samples, num_samples]
175 step_size = np.divide((bbox_max - bbox_min), num_samples)
176
177 num_vertices = 0
178 vertices = []
179 tets = []
180 hex_indices = []
181 hex_index = 0
182 for i in range(num_samples[0]):
183 for j in range(num_samples[1]):
184 for k in range(num_samples[2]):
185 p = np.multiply([i,j,k], step_size) + bbox_min
186 corners = [
187 [p[0] , p[1] , p[2] ],
188 [p[0]+step_size[0], p[1] , p[2] ],
189 [p[0]+step_size[0], p[1]+step_size[1], p[2] ],
190 [p[0] , p[1]+step_size[1], p[2] ],
191 [p[0] , p[1] , p[2]+step_size[2]],
192 [p[0]+step_size[0], p[1] , p[2]+step_size[2]],
193 [p[0]+step_size[0], p[1]+step_size[1], p[2]+step_size[2]],
194 [p[0] , p[1]+step_size[1], p[2]+step_size[2]],
195 ]
196 subcell_corners = subdivide_hex(corners, subdiv_order)
197 for corners in subcell_corners:
198 if using_simplex:
199 if keep_symmetry:
200 cell_vertices, cell_elems =\
201 split_hex_into_tets_symmetrically(corners)
202 else:
203 cell_vertices, cell_elems =\
204 split_hex_into_tets(corners)
205 else:
206 cell_vertices = corners
207 cell_elems = np.array([[0, 1, 2, 3, 4, 5, 6, 7]])
208 vertices.append(cell_vertices)
209 tets.append(cell_elems + num_vertices)
210 num_vertices += len(cell_vertices)
211 hex_indices.append(np.ones(len(cell_elems)) * hex_index)
212
213 hex_index +=1
214
215 vertices = np.vstack(vertices)
216 tets = np.vstack(tets)
217 hex_indices = np.vstack(hex_indices).ravel(order="C")
218
219 vertices, tets, __ = remove_duplicated_vertices_raw(vertices, tets)
220 vertices, tets, __ = remove_isolated_vertices_raw(vertices, tets)
221
222 faces = np.array([], dtype=int)
223 mesh = form_mesh(vertices, faces, tets)
224 return mesh, hex_indices
225
226def subdivide_hex(corners, order):
227 """ Subdivide hex into 8**order sub-cells.

Callers 1

generate_box_meshFunction · 0.85

Calls 6

subdivide_hexFunction · 0.85
split_hex_into_tetsFunction · 0.85
form_meshFunction · 0.85

Tested by

no test coverage detected