Here you go:
from dolfin import *
mesh = UnitCubeMesh(10,10,10)
mesh.init()
class top_half(SubDomain):
def inside(self, x, on_boundary):
return (x[0]<=0.25)
domains = MeshFunction("size_t", mesh, mesh.topology().dim())
domains.set_all(0)
top_half().mark(domains,1)
V = FunctionSpace(mesh, "DG", 0)
v = Function(V)
v.vector()[:] = domains.array()
XDMFFile("bdfunc.xdmf").write(v)
W = FunctionSpace(mesh, "CG", 1)
u_n = interpolate(v, W)
print(u_n.vector().get_local())
XDMFFile("u_n.xdmf").write(u_n)
So as you can see, domains is a function per cell, Im moving it into a DG0 function, and then projecting it to the CG1 space.