Create a function from cell data

This depends on what your expression is supposed to do. If it is used to define a material parameter, you can have a look at: Defining subdomains for different materials — FEniCSx tutorial
where input cell data from xdmf is converted to a DG 0 function:


Q = dolfinx.FunctionSpace(mesh, ("DG", 0))
kappa = dolfinx.Function(Q)
with kappa.vector.localForm() as loc:
    bottom_cells = ct.indices[ct.values==bottom_marker]
    loc.setValues(bottom_cells, np.full(len(bottom_cells), 1))
    top_cells = ct.indices[ct.values==top_marker]
    loc.setValues(top_cells, np.full(len(top_cells), 0.1))