Getting coordinates of facets in dolfinx

Consider the following to get the coordinates for all entities of your mesh (can be restricted by changing np.arange(num_facets_owned_by_proc, dtype=np.int32) to the facets of interest)

import dolfinx

from mpi4py import MPI
import numpy as np
mesh = dolfinx.UnitSquareMesh(MPI.COMM_WORLD, 2, 2)
fdim = mesh.topology.dim - 1
mesh.topology.create_connectivity(fdim, 0)

num_facets_owned_by_proc = mesh.topology.index_map(fdim).size_local
geometry_entitites = dolfinx.cpp.mesh.entities_to_geometry(mesh, fdim, np.arange(num_facets_owned_by_proc, dtype=np.int32), False)
points = mesh.geometry.x
for e, entity in enumerate(geometry_entitites):
    print(e, points[entity])
3 Likes