Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertex submesh support #3455

Merged
merged 8 commits into from
Oct 7, 2024
Merged

Vertex submesh support #3455

merged 8 commits into from
Oct 7, 2024

Conversation

jorgensd
Copy link
Member

@jorgensd jorgensd commented Oct 5, 2024

Allows for submeshes made of vertices.

Coupled with: FEniCS/basix#851

Would also allow for creating of point-cloud meshes with a simple Python or C++ code of 20 lines, as shown in #2593

# Create a mesh consisting of points only
# Author: Jørgen S. Dokken
# SPDX-License-Identifier: MIT

from mpi4py import MPI
import basix.ufl

import dolfinx
import numpy as np
import numpy.typing as npt
import ufl



def create_point_mesh(comm: MPI.Intracomm, points:npt.NDArray[np.float32]|npt.NDArray[np.float64])->dolfinx.mesh.Mesh:
    """
    Create a mesh consisting of points only.

    Note:
        No nodes are shared between processes.
    
    Args:
        comm: MPI communicator to create the mesh on.
        points: Points local to the process in the mesh.
    """
    # Create mesh topology
    cells = np.arange(points.shape[0], dtype=np.int32).reshape(-1, 1)
    topology = dolfinx.cpp.mesh.Topology(MPI.COMM_WORLD, dolfinx.mesh.CellType.point)
    num_nodes_local = cells.shape[0]
    imap = dolfinx.common.IndexMap(MPI.COMM_WORLD, num_nodes_local)
    local_range = imap.local_range[0]
    igi = np.arange(num_nodes_local, dtype=np.int64)+local_range
    topology.set_index_map(0, imap)
    topology.set_connectivity(dolfinx.graph.adjacencylist(cells), 0, 0)

    # Create mesh geometry
    e = basix.ufl.element("Lagrange", "point", 0, shape=(points.shape[1],))
    c_el = dolfinx.fem.coordinate_element(e.basix_element)
    geometry = dolfinx.mesh.create_geometry(imap, cells, c_el._cpp_object, points,  igi)

    # Create DOLFINx mesh
    if points.dtype == np.float64:
        cpp_mesh = dolfinx.cpp.mesh.Mesh_float64(comm, topology, geometry._cpp_object)
    elif points.dtype == np.float32:
        cpp_mesh = dolfinx.cpp.mesh.Mesh_float32(comm, topology, geometry._cpp_object)
    else:
        raise RuntimeError(f"Unsupported dtype for mesh {points.dtype}")
    # Wrap as Python object
    return dolfinx.mesh.Mesh(cpp_mesh, domain = ufl.Mesh(e))

@jorgensd jorgensd added the enhancement New feature or request label Oct 5, 2024
.github/workflows/ccpp.yml Outdated Show resolved Hide resolved
.github/workflows/ccpp.yml Outdated Show resolved Hide resolved
.github/workflows/ccpp.yml Outdated Show resolved Hide resolved
.github/workflows/ccpp.yml Outdated Show resolved Hide resolved
.github/workflows/macos.yml Outdated Show resolved Hide resolved
.github/workflows/oneapi.yml Outdated Show resolved Hide resolved
.github/workflows/redhat.yml Outdated Show resolved Hide resolved
@jorgensd jorgensd added this pull request to the merge queue Oct 7, 2024
Merged via the queue into main with commit 99e29fb Oct 7, 2024
27 checks passed
@jorgensd jorgensd deleted the dokken/vertex-submesh branch October 7, 2024 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants