Consider this:
from dolfin import *
# Sub domain
class Omega1(SubDomain):
def inside(self, x, on_boundary):
return x[0] > 0.5
# Square mesh
mesh = UnitSquareMesh(20, 20, "crossed")
# Create a cell function and mark subdomains
cf1 = CellFunction("size_t", mesh, 0)
Omega1 = Omega1()
Omega1.mark(cf1, 1)
# write/export cellfunction
hdf = HDF5File(mesh.mpi_comm(), "file.h5", "w")
hdf.write(cf1, "/cf1")
hdf.close()
# read/import cell function
hdf = HDF5File(mesh.mpi_comm(), "file.h5", "r")
cf2 = CellFunction("size_t", mesh)
hdf.read(cf2, "/cf1")
hdf.close()