Converting gmsh to xdmf

Hi Everyone,

I have a quick question about converting a gmsh mesh to xdmf. I’m using the following .geo file

SetFactory(“OpenCASCADE”);
//+
Cylinder(1) = {0.0, 0, 0.0, 0, 0, 1, .5};
//+
Cylinder(2) = {0.0, 0, 0.0, 0, 0, 1, .25};
//+
BooleanDifference{ Volume{1}; Delete; }{ Volume{2}; Delete; }
//+
Physical Surface(“TOP”) = {6};
//+
Physical Surface(“BOTTOM”) = {7};
//+
Physical Surface(“INNER”) = {4};
//+
Physical Surface(“OUTER”) = {5};
//+
Physical Volume(“VOL”) = {1};

and based on some of the code from a different thread, the following code to convert the mesh to xdmf.

import meshio

msh = meshio.read("TC_mesh.msh")
for cell in msh.cells:
    if cell.type == "triangle":
        triangle_cells = cell.data
    elif  cell.type == "tetra":
        tetra_cells = cell.data

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]
tetra_mesh = meshio.Mesh(points=msh.points, cells={"tetra": tetra_cells})
triangle_mesh =meshio.Mesh(points=msh.points,
                           cells=[("triangle", triangle_cells)],
                           cell_data={"name_to_read":[triangle_data]})
meshio.write("mesh.xdmf", tetra_mesh)

meshio.write("mf.xdmf", triangle_mesh)

I’m under the impression the mf.xdmf file should be outputting the entire surface of the mesh. However, when I examine it in paraview I’m only getting one slice.

Can someone explain if I’m misunderstanding something or if there is a bug here?

Thank You

Further down in that thread, I explain how to deal with the cell blocks generated by meshio, see Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio .
Also, you could just use Converter from GMSH to XDMF (with physical groups)

That is very helpful! Thank You