I cannot reproduce any errors with:
import meshio
import numpy as np
def create_mesh(mesh: meshio.Mesh, cell_type: str, data_name: str = "name_to_read",
prune_z: bool = False):
cells = mesh.get_cells_type(cell_type)
cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
points = mesh.points[:, :2] if prune_z else mesh.points
out_mesh = meshio.Mesh(points=points, cells={cell_type: cells}, cell_data={
data_name: [cell_data]})
return out_mesh
# import and convert msh file to xdmf
msh = meshio.read('mesh.msh')
print(msh)
facet_mesh = create_mesh(msh, "triangle")
meshio.write("test_facet.xdmf", facet_mesh)
triangle_mesh = create_mesh(msh, "tetra")
meshio.write("test_mesh.xdmf", triangle_mesh)
which prints
<meshio mesh object>
Number of points: 199
Number of cells:
triangle: 16
triangle: 16
tetra: 512
Cell sets: gmsh:bounding_entities
Point data: gmsh:dim_tags
Cell data: gmsh:physical, gmsh:geometrical
Please look at all the other posts regarding gmsh/meshio
as they contain a lot of tips and tricks.