Create a mesh consisting of points only. Note: No points are shared between processes. Args: comm: MPI communicator to create the mesh on. points: Points local to the process in the mesh.
(comm: _MPI.Intracomm, points: npt.NDArray[np.float32 | np.float64])
| 1365 | |
| 1366 | |
| 1367 | def create_point_mesh(comm: _MPI.Intracomm, points: npt.NDArray[np.float32 | np.float64]) -> Mesh: |
| 1368 | """Create a mesh consisting of points only. |
| 1369 | |
| 1370 | Note: |
| 1371 | No points are shared between processes. |
| 1372 | |
| 1373 | Args: |
| 1374 | comm: MPI communicator to create the mesh on. |
| 1375 | points: Points local to the process in the mesh. |
| 1376 | """ |
| 1377 | # Create topology which only has a 0->0 connectivity and dim 0 entities |
| 1378 | cells = np.arange(points.shape[0], dtype=np.int32).reshape(-1, 1) |
| 1379 | num_nodes_local = cells.shape[0] |
| 1380 | imap = _cpp.common.IndexMap(comm, num_nodes_local) |
| 1381 | local_range = imap.local_range[0] |
| 1382 | igi = np.arange(num_nodes_local, dtype=np.int64) + local_range |
| 1383 | topology = _cpp.mesh.Topology( |
| 1384 | cell_type=_cpp.mesh.CellType.point, |
| 1385 | vertex_map=imap, |
| 1386 | cell_map=imap, |
| 1387 | cells=_cpp.graph.AdjacencyList_int32(cells), |
| 1388 | original_index=igi, |
| 1389 | ) |
| 1390 | |
| 1391 | e = basix.ufl.element("Lagrange", "point", 0, shape=(points.shape[1],), dtype=points.dtype) |
| 1392 | c_el = _coordinate_element(e.basix_element) # type: ignore[call-arg] |
| 1393 | geometry = create_geometry(imap, cells, c_el, points, igi) |
| 1394 | |
| 1395 | if points.dtype == np.float64: |
| 1396 | cpp_mesh = _cpp.mesh.Mesh_float64(comm, topology, geometry._cpp_object) |
| 1397 | elif points.dtype == np.float32: |
| 1398 | cpp_mesh = _cpp.mesh.Mesh_float32(comm, topology, geometry._cpp_object) |
| 1399 | else: |
| 1400 | raise RuntimeError(f"Unsupported dtype for mesh {points.dtype}") |
| 1401 | |
| 1402 | return Mesh(cpp_mesh, domain=ufl.Mesh(e)) |