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”)
hdf.read(mesh, “/mesh”, False)
subdomains = MeshFunction(“size_t”, mesh, mesh.topology().dim(),0)
hdf.read(subdomains, “/subdomains”)
hdf.close()

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:
https://fenicsproject.org/pub/tutorial/sphinx1/._ftut1005.html.
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
Martin

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