With all this code, I’m not really sure what you are asking for. Especially since you do not supply any error message. However, with the following modifications to the meshio and loading to dolfin code everything seems to run smoothly. (note that i’ve renamed the input mesh to meshi.read)
import meshio
msh = meshio.read("mesh.msh")
for key in msh.cell_data_dict["gmsh:physical"].keys():
if key == "triangle":
triangle_data = msh.cell_data_dict["gmsh:physical"][key]
elif key == "tetra":
tetra_data = msh.cell_data_dict["gmsh:physical"][key]
for cell in msh.cells:
if cell.type == "tetra":
tetra_cells = cell.data
elif cell.type == "triangle":
triangle_cells = cell.data
tetra_mesh = meshio.Mesh(points=msh.points, cells={"tetra": tetra_cells},
cell_data={"name_to_read":[tetra_data]})
triangle_mesh =meshio.Mesh(points=msh.points,
cells=[("triangle", triangle_cells)],
cell_data={"name_to_read":[triangle_data]})
meshio.write("plate.xdmf", tetra_mesh)
meshio.write("mf.xdmf", triangle_mesh)
from dolfin import *
set_log_level(LogLevel.ERROR)
mesh = Mesh()
with XDMFFile("plate.xdmf") as infile:
infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 2)
with XDMFFile("mf.xdmf") as infile:
infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
mvc2 = MeshValueCollection("size_t", mesh, 3)
with XDMFFile("plate.xdmf") as infile:
infile.read(mvc2, "name_to_read")
cf = cpp.mesh.MeshFunctionSizet(mesh, mvc2)
ds_top = Measure("ds", domain=mesh, subdomain_data=mf, subdomain_id=11)
ds_right = Measure("ds", domain=mesh, subdomain_data=mf, subdomain_id=7)
dx_volume = Measure("dx", domain=mesh, subdomain_data=cf, subdomain_id=12)
As you see here, you can save the cell function data along with the mesh, in a similar fashion to how it was saved for the facets