Transition from MeshFunction in Fenicsx

The MeshFunction has been replaced by MeshTags, for various reasons, discussed here:MeshValueCollection in dolfinx - #2 by dokken

What you would like to do is easily achieved with the following (v0.6.0 syntax)

import dolfinx
from mpi4py import MPI
import numpy as np

mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)

cell_map = mesh.topology.index_map(mesh.topology.dim)
num_cells_on_process = cell_map.size_local + cell_map.num_ghosts
cells = np.arange(num_cells_on_process, dtype=np.int32)
my_mask = dolfinx.mesh.meshtags(mesh, mesh.topology.dim, cells, np.full_like(cells, 2))
print(my_mask.values)
2 Likes