3D structured mesh conversion with meshio

Hello,

When I try to convert my 3D structured mesh from .msh to .xdmf format, only some physical surfaces are kept (groups 101 to 103 when we should have groups from 101 to 107). For the conversion, I used the following code from the FEniCS tutorial, and added a line to print the different physical surfaces of the mesh:

import meshio
import numpy as np

# Read in mesh
msh = meshio.read("3Dmesh/3Dblock.msh")

# Helper function to extract the cells and physical data
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)
    points = mesh.points[:,:2] if prune_z else mesh.points
    out_mesh = meshio.Mesh(points=points, cells={cell_type: cells}, cell_data={"name_to_read":[cell_data]})
    return out_mesh

print(np.unique(msh.cell_data_dict['gmsh:physical']['quad']))
print(np.unique(msh.cell_data_dict['gmsh:physical']['hexahedron']))

# Convert mesh to XDMF
quad_mesh = create_mesh(msh, "quad", prune_z=False)
meshio.write("3Dmesh/3Dblock_facet_mesh.xdmf", quad_mesh)

hexahedron_mesh = create_mesh(msh, "hexahedron", prune_z=False)
meshio.write("3Dmesh/3Dblock_mesh.xdmf", hexahedron_mesh)

Output:

[1]
[101 102 103]

In the header of the .msh file, the number of physical surfaces is indicated correctly:

image

Do you have any idea where the problem could come from? Could this be due to the fact that the mesh is structured?

Thanks a lot for your help!

Without the msh file, there is very little chance that anyone can help you with this. Please upload it here or at https://gist.github.com and upload the link in a reply.

1 Like

Thank you for your reply, here is the full code for the .msh file:

Inspecting your mesh in GMSH, it seems like some of your 2D surfaces has been tagged as physical volumes, when they should be physical surfaces


There seems to be something wrong with your mesh in general, as this mesh gets into partitioning issues with scotch if you use:

import dolfinx
from mpi4py import MPI
mesh, ct, ft = dolfinx.io.gmshio.read_from_msh("mesh.msh", MPI.COMM_WORLD)

yields

RuntimeError: Consistency error in SCOTCH graph
1 Like

Hello,
Thank you very much for your reply. It was indeed a problem with the mesh as I assigned some elements of the mesh to several groups.