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

Function generate_box_mesh

python/pymesh/meshutils/generate_box_mesh.py:10–49  ·  view source on GitHub ↗

Generate axis-aligned box mesh. Each box is made of a number of cells (a square in 2D and cube in 3D), and each cell is made of triangles (2D) or tetrahedra (3D). Args: box_min (``numpy.ndarray``): min corner of the box. box_max (``numpy.ndarray``): max corner of the b

(box_min, box_max,
        num_samples=1, keep_symmetry=False, subdiv_order=0, using_simplex=True)

Source from the content-addressed store, hash-verified

8from .remove_duplicated_vertices import remove_duplicated_vertices_raw
9
10def generate_box_mesh(box_min, box_max,
11 num_samples=1, keep_symmetry=False, subdiv_order=0, using_simplex=True):
12 """ Generate axis-aligned box mesh.
13
14 Each box is made of a number of cells (a square in 2D and cube in 3D), and
15 each cell is made of triangles (2D) or tetrahedra (3D).
16
17 Args:
18 box_min (``numpy.ndarray``): min corner of the box.
19 box_max (``numpy.ndarray``): max corner of the box.
20 num_samples (``int``): (optional) Number of segments on each edge of the
21 box. Default is 1.
22 keep_symmetry (``bool``): (optional) If true, ensure mesh connectivity
23 respect all reflective symmetries of the box. Default is true.
24 subdiv_order (``int``): (optional) The subdivision order. Default is 0.
25 using_simplex (``bool``): If true, build box using simplex elements
26 (i.e. triangle or tets), otherwise, use quad or hex element.
27
28 Returns:
29 A box :py:class:`Mesh`. The following attributes are defined.
30
31 * ``cell_index``: An :py:class:`numpy.ndarray` of size :math:`N_e`
32 that maps each element to the index of the cell it belongs to.
33 :math:`N_e` is the number of elements.
34 """
35 if not isinstance(box_min, np.ndarray):
36 box_min = np.array(box_min)
37 if not isinstance(box_max, np.ndarray):
38 box_max = np.array(box_max)
39 dim = len(box_min)
40 if dim == 2:
41 mesh, cell_index = generate_2D_box_mesh(box_min, box_max, num_samples,
42 keep_symmetry, subdiv_order, using_simplex)
43 elif dim == 3:
44 mesh, cell_index = generate_3D_box_mesh(box_min, box_max, num_samples,
45 keep_symmetry, subdiv_order, using_simplex)
46
47 mesh.add_attribute("cell_index")
48 mesh.set_attribute("cell_index", cell_index)
49 return mesh
50
51def generate_2D_box_mesh(box_min, box_max, num_samples, keep_symmetry,
52 subdiv_order, using_simplex):

Callers 15

slice_meshFunction · 0.90
test_3DMethod · 0.90
test_2DMethod · 0.90
test_samplesMethod · 0.90
test_subdivMethod · 0.90
test_no_degeneracyMethod · 0.90
test_vertex_to_vertexMethod · 0.90
test_face_to_vertexMethod · 0.90
test_vertex_to_faceMethod · 0.90
test_2_meshesMethod · 0.90
test_3_meshesMethod · 0.90

Calls 4

generate_2D_box_meshFunction · 0.85
generate_3D_box_meshFunction · 0.85
add_attributeMethod · 0.45
set_attributeMethod · 0.45

Tested by 15

test_3DMethod · 0.72
test_2DMethod · 0.72
test_samplesMethod · 0.72
test_subdivMethod · 0.72
test_no_degeneracyMethod · 0.72
test_vertex_to_vertexMethod · 0.72
test_face_to_vertexMethod · 0.72
test_vertex_to_faceMethod · 0.72
test_2_meshesMethod · 0.72
test_3_meshesMethod · 0.72
test_single_hexMethod · 0.72