CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-meshio

I/O for many mesh formats

Pending
Overview
Eval results
Files

formats.mddocs/

Format-Specific Modules

Specialized readers and writers for individual mesh formats, providing format-specific functionality and advanced features for over 30 different mesh file formats.

Capabilities

Standard Format Modules

Most format modules follow a consistent pattern, providing read and write functions for their respective file formats.

Scientific Computing Formats

High-performance formats commonly used in finite element analysis and computational fluid dynamics.

# VTK Legacy Format
import meshio.vtk
def vtk.read(filename):
    """Read VTK legacy format files (.vtk)."""
def vtk.write(filename, mesh, binary=True):
    """Write VTK legacy format with binary option."""

# VTU (VTK XML) Format  
import meshio.vtu
def vtu.read(filename):
    """Read VTU XML format files (.vtu)."""
def vtu.write(filename, mesh, binary=True, compression=None):
    """Write VTU format with compression options (zlib, lzma)."""

# Exodus Format
import meshio.exodus
def exodus.read(filename):
    """Read Exodus II format files (.e, .exo)."""
def exodus.write(filename, mesh):
    """Write Exodus II format files."""

# CGNS Format
import meshio.cgns
def cgns.read(filename):
    """Read CGNS format files (.cgns)."""
def cgns.write(filename, mesh):
    """Write CGNS format files."""

CAD and Graphics Formats

Formats commonly used in computer-aided design and 3D graphics applications.

# STL Format
import meshio.stl
def stl.read(filename):
    """Read STL format files (.stl) - both ASCII and binary."""
def stl.write(filename, mesh, binary=True):
    """Write STL format with binary/ASCII option."""

# PLY Format
import meshio.ply
def ply.read(filename):
    """Read PLY format files (.ply) - Stanford Triangle Format."""
def ply.write(filename, mesh, binary=True, encoding="ascii"):
    """Write PLY format with encoding options."""

# Wavefront OBJ Format
import meshio.obj
def obj.read(filename):
    """Read Wavefront OBJ format files (.obj)."""
def obj.write(filename, mesh):
    """Write Wavefront OBJ format files."""

# OFF Format
import meshio.off
def off.read(filename):
    """Read Object File Format files (.off)."""
def off.write(filename, mesh):
    """Write Object File Format files."""

Engineering Analysis Formats

Formats used by commercial finite element analysis software.

# NASTRAN Format
import meshio.nastran
def nastran.read(filename):
    """Read NASTRAN format files (.nas, .bdf)."""
def nastran.write(filename, mesh):
    """Write NASTRAN format files."""

# ABAQUS Format
import meshio.abaqus
def abaqus.read(filename):
    """Read ABAQUS format files (.inp)."""
def abaqus.write(filename, mesh):
    """Write ABAQUS format files."""

# ANSYS Format
import meshio.ansys
def ansys.read(filename):
    """Read ANSYS format files (.ans)."""
def ansys.write(filename, mesh):
    """Write ANSYS format files."""

# PERMAS Format
import meshio.permas
def permas.read(filename):
    """Read PERMAS format files (.post, .dat)."""
def permas.write(filename, mesh):
    """Write PERMAS format files."""

Specialized Scientific Formats

Formats for specific domains and applications.

# MED Format (Salome)
import meshio.med
def med.read(filename):
    """Read MED format files (.med) - Salome platform."""
def med.write(filename, mesh):
    """Write MED format files."""

# AVS-UCD Format  
import meshio.avsucd
def avsucd.read(filename):
    """Read AVS-UCD format files (.avs)."""
def avsucd.write(filename, mesh):
    """Write AVS-UCD format files."""

# TetGen Format
import meshio.tetgen
def tetgen.read(filename):
    """Read TetGen format files (.node, .ele, .face)."""
def tetgen.write(filename, mesh):
    """Write TetGen format files."""

# Netgen Format
import meshio.netgen
def netgen.read(filename):
    """Read Netgen format files (.vol)."""
def netgen.write(filename, mesh):
    """Write Netgen format files."""

# FLAC3D Format
import meshio.flac3d
def flac3d.read(filename):
    """Read FLAC3D format files (.f3grid)."""
def flac3d.write(filename, mesh):
    """Write FLAC3D format files."""

# SU2 Format
import meshio.su2
def su2.read(filename):
    """Read SU2 format files (.su2)."""
def su2.write(filename, mesh):
    """Write SU2 format files."""

Other Specialized Formats

Additional formats for various applications and software packages.

# Tecplot Format
import meshio.tecplot
def tecplot.read(filename):
    """Read Tecplot format files (.dat)."""
def tecplot.write(filename, mesh):
    """Write Tecplot format files."""

# UGRID Format
import meshio.ugrid
def ugrid.read(filename):
    """Read UGRID format files (.ugrid)."""
def ugrid.write(filename, mesh):
    """Write UGRID format files."""

# Medit Format
import meshio.medit
def medit.read(filename):
    """Read Medit format files (.mesh)."""
def medit.write(filename, mesh):
    """Write Medit format files."""

# H5M Format (MOAB)
import meshio.h5m
def h5m.read(filename):
    """Read H5M format files (.h5m) - MOAB mesh format."""
def h5m.write(filename, mesh):
    """Write H5M format files."""

# MDPA Format (Kratos)
import meshio.mdpa
def mdpa.read(filename):
    """Read MDPA format files (.mdpa) - Kratos MultiPhysics."""
def mdpa.write(filename, mesh):
    """Write MDPA format files."""

# HMF Format
import meshio.hmf
def hmf.read(filename):
    """Read HMF format files (.hmascii)."""
def hmf.write(filename, mesh):
    """Write HMF format files."""

# Neuroglancer Format
import meshio.neuroglancer
def neuroglancer.read(filename):
    """Read Neuroglancer format files (.ng)."""
def neuroglancer.write(filename, mesh):
    """Write Neuroglancer format files."""

# DOLFIN XML Format
import meshio.dolfin
def dolfin.read(filename):
    """Read DOLFIN XML format files (.xml) - FEniCS."""
def dolfin.write(filename, mesh):
    """Write DOLFIN XML format files."""

# WKT Format
import meshio.wkt
def wkt.read(filename):
    """Read Well-Known Text format files (.wkt)."""
def wkt.write(filename, mesh):
    """Write Well-Known Text format files."""

Special Format Modules

Format modules with enhanced functionality beyond basic read/write operations.

GMSH Format

Enhanced GMSH support with cell type conversion utilities.

import meshio.gmsh

def gmsh.read(filename):
    """
    Read GMSH format files (.msh) with support for all GMSH versions.
    
    Supports:
    - GMSH format versions 2.2, 4.0, 4.1
    - Physical names and entity information
    - Periodic boundary conditions
    - Node and element data
    """

def gmsh.write(filename, mesh, fmt_version="4.1", binary=True):
    """
    Write GMSH format files with version control.
    
    Parameters:
    - fmt_version: str - GMSH format version ("2.2", "4.0", "4.1") 
    - binary: bool - Write in binary format for better performance
    """

def gmsh.gmsh_to_meshio_type(gmsh_type):
    """
    Convert GMSH cell type ID to meshio cell type string.
    
    Parameters:
    - gmsh_type: int - GMSH element type ID
    
    Returns:
    - str - Corresponding meshio cell type name
    
    Examples:
    >>> meshio.gmsh.gmsh_to_meshio_type(2)  # "triangle"
    >>> meshio.gmsh.gmsh_to_meshio_type(4)  # "tetra"
    """

def gmsh.meshio_to_gmsh_type(meshio_type):
    """
    Convert meshio cell type string to GMSH cell type ID.
    
    Parameters:
    - meshio_type: str - meshio cell type name
    
    Returns:
    - int - Corresponding GMSH element type ID
    
    Examples:
    >>> meshio.gmsh.meshio_to_gmsh_type("triangle")  # 2
    >>> meshio.gmsh.meshio_to_gmsh_type("tetra")     # 4
    """

XDMF Format

Advanced XDMF support with time series functionality for temporal data.

import meshio.xdmf

def xdmf.read(filename):
    """
    Read XDMF format files (.xdmf, .xmf) with HDF5 data support.
    
    Supports:
    - XDMF version 3.0 specification
    - Heavy data stored in HDF5 format
    - Structured and unstructured grids
    """

def xdmf.write(filename, mesh, data_format="HDF", compression="gzip"):
    """
    Write XDMF format files with HDF5 backend.
    
    Parameters:
    - data_format: str - Data storage format ("HDF", "Binary", "XML")
    - compression: str - Compression algorithm ("gzip", "lzf", "szip")
    """

class xdmf.TimeSeriesReader:
    """
    Read time series data from XDMF files.
    
    Handles temporal datasets where mesh geometry may change over time
    or data is associated with different time steps.
    """
    
    def __init__(self, filename):
        """
        Initialize time series reader.
        
        Parameters:
        - filename: str - Path to XDMF file containing time series data
        """
    
    @property
    def num_steps(self):
        """
        Get number of time steps in the series.
        
        Returns:
        - int - Number of time steps
        """
    
    def read_times(self):
        """
        Get all available time steps.
        
        Returns:
        - List[float] - List of time values
        """
    
    def read_points_cells(self):
        """
        Read mesh geometry (points and cells) from time series.
        
        Returns:
        - Tuple[np.ndarray, List[CellBlock]] - Points array and cell blocks
        """
    
    def read_data(self, time_step):
        """
        Read mesh data for specific time step.
        
        Parameters:
        - time_step: int - Time step index
        
        Returns:
        - Tuple[Mesh, float] - Mesh object and time value
        """

class xdmf.TimeSeriesWriter:
    """
    Write time series data to XDMF files.
    
    Allows writing temporal datasets with multiple time steps.
    """
    
    def __init__(self, filename):
        """
        Initialize time series writer.
        
        Parameters:
        - filename: str - Output XDMF file path
        """
    
    def write_points_cells(self, points, cells):
        """
        Write mesh geometry (points and cells) to time series file.
        
        Parameters:
        - points: np.ndarray - Point coordinates
        - cells: List[CellBlock] - Cell connectivity data
        """
    
    def write_data(self, time, point_data=None, cell_data=None):
        """
        Write data for specific time step.
        
        Parameters:
        - time: float - Time value for this step
        - point_data: Dict[str, np.ndarray] | None - Point-based data
        - cell_data: Dict[str, List[np.ndarray]] | None - Cell-based data
        """
    
    def close(self):
        """Close the time series file and write final metadata."""

SVG Format

Write-only format for creating 2D visualizations.

import meshio.svg

def svg.write(filename, mesh, line_width=1.0, point_size=2.0):
    """
    Write 2D mesh visualization to SVG format (write-only).
    
    Parameters:
    - line_width: float - Width of mesh edges in SVG units
    - point_size: float - Size of mesh vertices in SVG units
    
    Note: Only supports 2D meshes. 3D meshes are projected to 2D.
    Primarily used for visualization and documentation purposes.
    """

Usage Examples

Basic Format Usage

import meshio

# Standard format usage - automatic detection
mesh = meshio.read("input.msh")        # GMSH format
mesh = meshio.read("model.vtk")        # VTK format
mesh = meshio.read("geometry.stl")     # STL format

# Write to different formats
meshio.write("output.vtu", mesh)       # VTU format
meshio.write("surface.ply", mesh)      # PLY format
meshio.write("cad_model.obj", mesh)    # OBJ format

# Format-specific options
meshio.write("model.stl", mesh, binary=True)
meshio.write("result.vtu", mesh, compression="zlib")

Direct Format Module Usage

# Use format modules directly
import meshio.gmsh as gmsh_io
import meshio.vtk as vtk_io

# Read with format-specific functions
mesh = gmsh_io.read("complex.msh")
legacy_mesh = vtk_io.read("legacy.vtk")

# Write with format-specific options
gmsh_io.write("output.msh", mesh, fmt_version="4.1", binary=True)
vtk_io.write("result.vtk", mesh, binary=False)  # ASCII VTK

GMSH Type Conversion

import meshio.gmsh

# Convert between GMSH and meshio cell types
gmsh_triangle_id = meshio.gmsh.meshio_to_gmsh_type("triangle")  # Returns 2
meshio_type = meshio.gmsh.gmsh_to_meshio_type(4)               # Returns "tetra"

# Useful when working directly with GMSH API
cell_type_mapping = {
    "triangle": meshio.gmsh.meshio_to_gmsh_type("triangle"),
    "quad": meshio.gmsh.meshio_to_gmsh_type("quad"), 
    "tetra": meshio.gmsh.meshio_to_gmsh_type("tetra")
}

XDMF Time Series Operations

import meshio.xdmf

# Reading time series data
reader = meshio.xdmf.TimeSeriesReader("simulation.xdmf")
times = reader.read_times()
print(f"Available time steps: {times}")

for i, t in enumerate(times):
    mesh, time_val = reader.read_data(i)
    print(f"Time {time_val}: {len(mesh.points)} points")
    # Process mesh data for this time step

# Writing time series data
writer = meshio.xdmf.TimeSeriesWriter("output_series.xdmf")

# Assume we have simulation data at multiple time steps
time_steps = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5]
for i, t in enumerate(time_steps):
    # Generate or load data for this time step
    point_data = {"temperature": temperature_field[i]}
    cell_data = {"pressure": [pressure_field[i]]}
    
    writer.write_data(t, point_data=point_data, cell_data=cell_data)

writer.close()

Engineering Format Examples

# NASTRAN format with material properties
import meshio.nastran
mesh = meshio.nastran.read("model.bdf") 
meshio.nastran.write("analysis.nas", mesh)

# ABAQUS format for finite element analysis
import meshio.abaqus
fem_mesh = meshio.abaqus.read("part.inp")
meshio.abaqus.write("modified.inp", fem_mesh)

# Exodus format for large-scale simulations
import meshio.exodus
simulation_mesh = meshio.exodus.read("results.e")
meshio.exodus.write("processed.exo", simulation_mesh)

CAD Format Conversions

# Convert CAD formats
cad_mesh = meshio.stl.read("part.stl")      # Read STL
meshio.obj.write("part.obj", cad_mesh)      # Convert to OBJ
meshio.ply.write("part.ply", cad_mesh)      # Convert to PLY

# STL with specific options
meshio.stl.write("binary_part.stl", cad_mesh, binary=True)
meshio.stl.write("ascii_part.stl", cad_mesh, binary=False)

# PLY with encoding options
meshio.ply.write("model.ply", cad_mesh, encoding="binary_little_endian")

Visualization Output

# Create 2D visualization
import numpy as np

# Create 2D triangle mesh
points = np.array([[0, 0], [1, 0], [0.5, 1]])
cells = [("triangle", [[0, 1, 2]])]
mesh_2d = meshio.Mesh(points, cells)

# Write as SVG for documentation
meshio.svg.write("mesh_diagram.svg", mesh_2d, line_width=2.0, point_size=3.0)

Format-Specific Features

# GMSH with physical names
mesh = meshio.gmsh.read("model.msh")
print("Physical entities:", mesh.field_data)

# VTU with compression
meshio.vtu.write("compressed.vtu", mesh, compression="lzma")

# TetGen multi-file format
tetgen_mesh = meshio.tetgen.read("mesh.1")  # Reads .node, .ele, .face files

Format Capabilities Matrix

FormatReadWriteBinaryCompressionTime SeriesSpecial Features
VTK--Legacy format
VTU-XML-based
GMSH--Type conversion
STL--Surface meshes
PLY--Point clouds
XDMFHDF5 backend
Exodus-Large datasets
NASTRAN---FEA format
ABAQUS---FEA format
SVG----2D visualization
OBJ---Graphics format
TetGen---Multi-file

Performance Considerations

Binary vs ASCII

# Binary formats are faster for large meshes
meshio.write("large.vtu", big_mesh, binary=True)     # Faster
meshio.write("large.vtu", big_mesh, binary=False)    # Slower, human-readable

# STL binary is much more compact
meshio.stl.write("model.stl", mesh, binary=True)     # Recommended
meshio.stl.write("model.stl", mesh, binary=False)    # For debugging

Compression Options

# Use compression for storage efficiency
meshio.write("data.vtu", mesh, compression="zlib")   # Good compression/speed balance
meshio.write("data.vtu", mesh, compression="lzma")   # Better compression, slower
meshio.write("data.vtu", mesh, compression=None)     # No compression, fastest I/O

Format Selection Guidelines

  • VTK/VTU: General-purpose, good ParaView support
  • GMSH: Mesh generation, preprocessor compatibility
  • STL: CAD interchange, 3D printing
  • PLY: Point clouds, computer graphics
  • XDMF: Large datasets, time series, parallel I/O
  • Exodus: Large-scale simulations, Sandia tools
  • NASTRAN/ABAQUS: Commercial FEA software
  • HDF5-based formats: Very large datasets, parallel access

Install with Tessl CLI

npx tessl i tessl/pypi-meshio

docs

cli.md

core-io.md

format-registration.md

formats.md

index.md

mesh-data.md

tile.json