Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio

Your msh file does not contain any physical markers (i.e Physical Line/Volume/Surface), thus you cannot read in cell_data.

I would suggest using the following code for reading meshes (from Accessing and marking imported boundaries - #8 by dokken). Note that here I have defined a physical surface and physical curve.

import meshio

msh ="cylinder.msh")

def create_mesh(mesh, cell_type, prune_z=False):
    cells = mesh.get_cells_type(cell_type)
    cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
    out_mesh = meshio.Mesh(points=mesh.points, cells={
                           cell_type: cells}, cell_data={"name_to_read": [cell_data]})
    if prune_z:
    return out_mesh

tetra_mesh = create_mesh(msh, "tetra")
triangle_mesh = create_mesh(msh, "triangle")
meshio.write("mesh.xdmf", tetra_mesh)

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