Transition from MeshFunction in Fenicsx

With Fenics I used the functionnality below to initialize material properties before assigning them for multi-materials:

my_mask = mesh.MeshFunction('size_t', mesh, 3, mesh.domains())
my_mask.set_all(2)

but MeshFunction seems to have disappeared from Fenicsx lately and after going through the documentation at https://jsdokken.com/dolfinx-tutorial/chapter3/subdomains.html I still can’t figure out how to do the same in Fenicsx.
Any hint in the right direction would be greatly appreciated!

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

Yes, it’s exactly that, thank you!