How to read a physical object from a xdmf file

You are using pygmsh, which doesn’t give you an option to choose the integer associated with a physical group. If you open line_mesh.xdmf in Paraview you see that the inner circle is marked with the integer 2.
Thus you can integrate over that part of the boundary as shown below:

import numpy as np
from fenics import *


input_directory = "."

# create mesh with new method
mesh = Mesh()
with XDMFFile(input_directory + "/triangle_mesh.xdmf") as infile:
    infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 1)
with XDMFFile(input_directory + "/line_mesh.xdmf") as infile:
    infile.read(mvc, "name_to_read")


mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
ds_inner = Measure("ds", domain=mesh, subdomain_data=mf, subdomain_id=2)

inner_circumference = assemble(1*ds_inner)

print(inner_circumference/(2*np.pi))

print((assemble(1*ds(domain=mesh))-inner_circumference)/(2*np.pi))

returning the inner and outer radius as expected

0.2490685406113397
0.9997493049308164
1 Like