| name | meshio-formats |
| description | Convert between mesh file formats using meshio library. Use for translating meshes between VTK, Gmsh, XDMF, Exodus, and other FEM formats. Supports reading/writing 40+ mesh formats. |
meshio Formats
Universal mesh format converter for scientific computing.
Installation
pip install meshio
Reading Meshes
import meshio
# Auto-detect format
mesh = meshio.read("model.vtk")
mesh = meshio.read("model.msh")
mesh = meshio.read("model.xdmf")
# Explicit format
mesh = meshio.read("model.dat", file_format="tecplot")
Writing Meshes
import meshio
# Convert formats
mesh = meshio.read("input.msh")
mesh.write("output.vtk")
# Specify format explicitly
mesh.write("output.dat", file_format="abaqus")
Mesh Data Access
import meshio
mesh = meshio.read("model.vtk")
# Points (vertices)
points = mesh.points # numpy array (n, 3)
# Cells (elements)
for cell_block in mesh.cells:
print(f"Type: {cell_block.type}, Count: {len(cell_block.data)}")
# Point data (fields at vertices)
for name, data in mesh.point_data.items():
print(f"Field: {name}, Shape: {data.shape}")
# Cell data (fields at elements)
for name, data in mesh.cell_data.items():
print(f"Field: {name}")
Creating Meshes
import meshio
import numpy as np
# Define mesh
points = np.array([
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[1.0, 1.0, 0.0],
[0.0, 1.0, 0.0],
])
cells = [
("triangle", np.array([[0, 1, 2], [0, 2, 3]]))
]
# Create mesh object
mesh = meshio.Mesh(points, cells)
# Add point data
mesh.point_data["temperature"] = np.array([100, 200, 150, 120])
# Add cell data
mesh.cell_data["material"] = [np.array([1, 2])]
mesh.write("output.vtk")
Supported Formats
- VTK:
.vtk,.vtu,.pvtu - Gmsh:
.msh - XDMF:
.xdmf - Exodus:
.e,.exo - Abaqus:
.inp - ANSYS:
.ans - CGNS:
.cgns - DOLFIN:
.xml - STL:
.stl - PLY:
.ply - OBJ:
.obj
Command Line
# Convert file
meshio convert input.msh output.vtk
# Show mesh info
meshio info model.vtk
# Compress/decompress
meshio compress mesh.vtu
meshio decompress mesh.vtu