Setting subdomains from h5 file

Hello Everyone,

I have (I hope) a rather simple question. I have a 2D-Mesh which is a square with many tiny circles in it. I want to define 2 different Materialparamers for the elements in the circles and the one surrounding them.
For that purpose I created a mesh with gmsh, converted it to *xml and converted it then with the following code to a h5 file:

mesh = Mesh(“NameofMesh.xml”)
subdomains = MeshFunction(“size_t”, mesh, “NameofMesh_physical_region.xml”)
hdf = HDF5File(mesh.mpi_comm(), “file.h5”, “w”)
hdf.write(mesh, “/mesh”)
hdf.write(subdomains, “/subdomains”)

and after that I load it into my Code with:

mesh = Mesh()
hdf = HDF5File(mesh.mpi_comm(), “file.h5”, “r”), “/mesh”, False)
subdomains = MeshFunction(“size_t”, mesh, mesh.topology().dim(),0), “/subdomains”)

My Question now is: how can define the subdomains and then apply the different materialparameters? The tutorials I have found all worked with boundary’s that had fixed values like: 0,5 > x[0] and then used the MeshFunction as markers, like here:
What I want is to set the subdomains and the materialparameters without having to explicitly write were they are. Like:

subdomains(0) = k1
subdomains(1) = k2

Many thanks in advance

See for instance: How to define different materials / importet 3D geometry (gmsh)