How to define spatially varying materials

Hi, Prof Dokken. Sorry to bother you.
I have test the code you provided 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))
v = dolfinx.fem.Function(V)
x = V.tabulate_dof_coordinates()

for i in range(x.shape[0]):
    midpoint = x[i,:]
    if midpoint[0]> 0.5 and midpoint[1]>0.25:
        v.vector.setValueLocal(i, 2)
    else:
        v.vector.setValueLocal(i, 1)

The code use the midpoint to define the function space. I’m not sure whether the list of x(V.tabulate_dof_coordinate) in DG mesh space is arranged by the element index. Or is there any API of dolfinx to get the list of element index so that the corresponding list of material parameters can be generated and attached to the each fem element?

Thanks a lot!