LGerard
February 12, 2026, 4:09pm
1
Hello,
I have some questions regarding mesh reading in the scripts.
What is the difference between reading a mesh directly from Gmsh versus reading the mesh from an XDMF file?
# Extract mesh data
mesh, ct, ft = io.gmshio.read_from_msh("data_gmsh/domain.msh", MPI.COMM_WORLD)
Related to the first question, is it necessary to convert from Gmsh to XDMF if the mesh has many elements?
import meshio
from mpi4py import MPI
import numpy as np
proc = MPI.COMM_WORLD.rank
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.astype(np.int32)]})
return out_mesh
if proc == 0:
# Read in mesh
msh = meshio.read("name_mesh.msh")
# Create and save one file for the mesh, and one file for the facets
line_mesh = create_mesh(msh, "line", prune_z=True)
meshio.write("data/mesh.xdmf", line_mesh)
triangle_mesh = create_mesh(msh, "triangle", prune_z=True)
meshio.write("data/ft_mesh.xdmf", line_mesh)
MPI.COMM_WORLD.barrier()
How does it affect the tags in the code?
dokken
February 12, 2026, 4:18pm
2
msh files are plain-text files, which means that they have to be read on a single process and then data has to be distributed to the number of processes you run on.
If you use XDMF with HDF5 encoding data is stored in .h5 files, where data can be read in contiguous chunks on each process, speeding up the time it takes to read and distribute the data.
It shouldn’t affect the tags at all.
LGerard
February 12, 2026, 4:39pm
3
Thank you for the response. So, would the code execution be faster using the XDMF format even if it is not run in parallel with MPI? Do both mesh reading approaches support MPI execution?
How can I make sure that the conversion uses HDF5 with this code?
LGerard:
import meshio
from mpi4py import MPI
import numpy as np
proc = MPI.COMM_WORLD.rank
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.astype(np.int32)]})
return out_mesh
if proc == 0:
# Read in mesh
msh = meshio.read("name_mesh.msh")
# Create and save one file for the mesh, and one file for the facets
line_mesh = create_mesh(msh, "line", prune_z=True)
meshio.write("data/mesh.xdmf", line_mesh)
triangle_mesh = create_mesh(msh, "triangle", prune_z=True)
meshio.write("data/ft_mesh.xdmf", line_mesh)
MPI.COMM_WORLD.barrier()