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)
| 8 | from .remove_duplicated_vertices import remove_duplicated_vertices_raw |
| 9 | |
| 10 | def 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 | |
| 51 | def generate_2D_box_mesh(box_min, box_max, num_samples, keep_symmetry, |
| 52 | subdiv_order, using_simplex): |