Create a box mesh. Args: comm: MPI communicator. points: Coordinates of the 'lower-left' and 'upper-right' corners of the box. n: List of cells in each direction cell_type: The cell type. dtype: Float type for the mesh geometry(``numpy.float32
(
comm: _MPI.Comm,
points: list[npt.ArrayLike],
n: Sequence[int],
cell_type=CellType.tetrahedron,
dtype: npt.DTypeLike = default_real_type,
ghost_mode=GhostMode.shared_facet,
partitioner=None,
)
| 1156 | |
| 1157 | |
| 1158 | def create_box( |
| 1159 | comm: _MPI.Comm, |
| 1160 | points: list[npt.ArrayLike], |
| 1161 | n: Sequence[int], |
| 1162 | cell_type=CellType.tetrahedron, |
| 1163 | dtype: npt.DTypeLike = default_real_type, |
| 1164 | ghost_mode=GhostMode.shared_facet, |
| 1165 | partitioner=None, |
| 1166 | ) -> Mesh: |
| 1167 | """Create a box mesh. |
| 1168 | |
| 1169 | Args: |
| 1170 | comm: MPI communicator. |
| 1171 | points: Coordinates of the 'lower-left' and 'upper-right' |
| 1172 | corners of the box. |
| 1173 | n: List of cells in each direction |
| 1174 | cell_type: The cell type. |
| 1175 | dtype: Float type for the mesh geometry(``numpy.float32`` |
| 1176 | or ``numpy.float64``). |
| 1177 | ghost_mode: The ghost mode used in the mesh partitioning. |
| 1178 | partitioner: Function that computes the parallel distribution of |
| 1179 | cells across MPI ranks. |
| 1180 | |
| 1181 | Returns: |
| 1182 | A mesh of a box domain. |
| 1183 | """ |
| 1184 | if partitioner is None and comm.size > 1: |
| 1185 | partitioner = _cpp.mesh.create_cell_partitioner(ghost_mode, 2) |
| 1186 | domain = ufl.Mesh( |
| 1187 | basix.ufl.element( |
| 1188 | "Lagrange", |
| 1189 | cell_type.name, |
| 1190 | 1, |
| 1191 | lagrange_variant=basix.LagrangeVariant.unset, |
| 1192 | shape=(3,), |
| 1193 | dtype=dtype, |
| 1194 | ) |
| 1195 | ) # type: ignore |
| 1196 | if np.issubdtype(dtype, np.float32): |
| 1197 | msh = _cpp.mesh.create_box_float32(comm, points, n, cell_type, partitioner) |
| 1198 | elif np.issubdtype(dtype, np.float64): |
| 1199 | msh = _cpp.mesh.create_box_float64(comm, points, n, cell_type, partitioner) |
| 1200 | else: |
| 1201 | raise RuntimeError(f"Unsupported mesh geometry float type: {dtype}") |
| 1202 | |
| 1203 | return Mesh(msh, domain) |
| 1204 | |
| 1205 | |
| 1206 | def create_unit_cube( |