How to define spatially varying materials

By the way, I have tried the second method about MeshFunction mentioned in Dolfinx discontinous expression

import dolfinx.io
import dolfinx
from mpi4py import MPI

mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 5, 5)
V = dolfinx.fem.FunctionSpace(mesh, ("DG", 0))
v2 = dolfinx.Function(V)
mf = dolfinx.MeshFunction("size_t", mesh, mesh.topology.dim, 0)
mf.mark(lambda x: numpy.logical_and(x[0] < 0.5, x[1]>0.2), 2)
for i in range(x.shape[0]):
    if mf.values[i] == 2:
        v2.vector.setValueLocal(i, 2)
    else:
        v2.vector.setValueLocal(i, 1)

But it came to an Error about the API of MeshFunction in the dolfinx library.

AttributeError: module 'dolfinx' has no attribute 'MeshFunction'

Could you please tell me where it did go wrong? Thanks!