Skip to main content

I/O for many mesh formats

Project description

meshlane

I/O for mesh files: convert smoothly between many formats.

License: MIT PyPI version Code style: black

meshlane is an actively maintained descendant of meshio by Nico Schlömer. It builds directly on meshio's codebase and history, and extends it with new format support and fixes geared toward FEA/CFD interoperability (code_aster, Ansys, OpenFOAM, Salome/MED). See Relationship to meshio.

There are many mesh formats for representing unstructured meshes. meshlane reads and writes all of the following and converts smoothly between them:

Abaqus (.inp), ANSYS msh (.msh), Ansys/APDL input (.inp, .cdb), AVS-UCD (.avs), CGNS (.cgns), DOLFIN XML (.xml), Exodus (.e, .exo), FLAC3D (.f3grid), H5M (.h5m), Kratos/MDPA (.mdpa), Medit (.mesh, .meshb), MED/Salome (.med), Nastran (bulk data, .bdf, .fem, .nas), Netgen (.vol, .vol.gz), Neuroglancer precomputed format, Gmsh (formats 2.2, 4.0, 4.1, .msh), OBJ (.obj), OFF (.off), OpenFOAM polyMesh (.foam, read only), PERMAS (.post, .post.gz, .dato, .dato.gz), PLY (.ply), STL (.stl), Tecplot .dat, TetGen .node/.ele, SVG (2D output only) (.svg), SU2 (.su2), UGRID (.ugrid), VTK (.vtk), VTU (.vtu), WKT (TIN) (.wkt), XDMF (.xdmf, .xmf).

What meshlane adds over meshio

  • OpenFOAM polyMesh reader: ASCII and binary, arbitrary cell types (tri / quad / polyhedra).
  • Ansys/APDL .inp / .cdb reader & writer for FEA interoperability.
  • MED/Salome improvements:
    • multi-mesh files (several meshes in one .med)
    • polygon cell support, including ragged/Voronoi meshes
    • multi-timestep result fields, with NDT/NOR/PDT preserved
    • round-trip of mesh metadata, field units and component names
    • MED 4.1 bitmask metadata and HDF5 link-creation-order, so files stay readable by Salome / medfile / mdump
    • extended field data types (float32/64, int32/64)
    • robust handling of missing FAS / NOEUD / GRO sections and merged cell blocks
  • Encoding and parsing robustness fixes (Latin-1 metadata, group name parsing).

Installation

meshlane is available on PyPI:

pip install meshlane[all]

([all] pulls in the optional dependencies netCDF4 and h5py, required for the CGNS, H5M, MED and XDMF formats. By default only numpy is needed.)

To install from source instead:

git clone https://github.com/simvia-tech/meshlane.git
cd meshlane
pip install -e .[all]

Usage

Command line:

meshlane convert    input.msh output.vtk   # convert between two formats
meshlane info       input.xdmf             # show some info about the mesh
meshlane compress   input.vtu              # compress the mesh file
meshlane decompress input.vtu              # decompress the mesh file
meshlane binary     input.msh              # convert to binary format
meshlane ascii      input.msh              # convert to ASCII format

In Python, read a mesh:

import meshlane

mesh = meshlane.read(
    filename,                # path, os.PathLike, or a buffer/open file
    # file_format="stl",     # optional; inferred from the extension
)
# mesh.points, mesh.cells, mesh.cells_dict, ...

Write a mesh:

import meshlane

points = [
    [0.0, 0.0], [1.0, 0.0], [0.0, 1.0],
    [1.0, 1.0], [2.0, 0.0], [2.0, 1.0],
]
cells = [
    ("triangle", [[0, 1, 2], [1, 3, 2]]),
    ("quad", [[1, 4, 5, 3]]),
]

mesh = meshlane.Mesh(
    points,
    cells,
    point_data={"T": [0.3, -1.2, 0.5, 0.7, 0.0, -3.0]},
    cell_data={"a": [[0.1, 0.2], [0.4]]},
)
mesh.write("foo.vtk")

# Or, equivalently:
meshlane.write_points_cells("foo.vtk", points, cells)

For both reading and writing you may pass file_format= explicitly (e.g. to force ASCII over binary VTK).

Time series

The XDMF format supports time series sharing one mesh:

with meshlane.xdmf.TimeSeriesWriter(filename) as writer:
    writer.write_points_cells(points, cells)
    for t in [0.0, 0.1, 0.21]:
        writer.write_data(t, point_data={"phi": data})
with meshlane.xdmf.TimeSeriesReader(filename) as reader:
    points, cells = reader.read_points_cells()
    for k in range(reader.num_steps):
        t, point_data, cell_data = reader.read_data(k)

Testing

tox

(Some test meshes are stored with Git LFS; run git lfs pull after cloning.)

Relationship to meshio

meshlane is a fork of meshio. We kept the full git history and authorship so the original work remains properly attributed. We started a separate project, rather than only contributing upstream, to move faster on the FEA/CFD interoperability features we need (code_aster, Ansys, code_saturne, OpenFOAM, Salome, etc.) and to maintain them under active development.

meshio is no longer actively maintained. Simvia is a company willing to commit time and people to keep this project alive and moving forward.

Contributing

Everyone is welcome, individuals and companies alike. If you want to help us keep meshlane maintained, we would be glad to have you on board. We will do our best to triage issues quickly and to give timely, constructive feedback on pull requests.

Huge thanks to Nico Schlömer and all meshio contributors for the foundation this project is built on.

License

meshlane is published under the MIT license, the same as meshio. Copyright is retained by the original meshio authors and the meshlane contributors.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

meshlane-5.4.0.tar.gz (197.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

meshlane-5.4.0-py3-none-any.whl (188.5 kB view details)

Uploaded Python 3

File details

Details for the file meshlane-5.4.0.tar.gz.

File metadata

  • Download URL: meshlane-5.4.0.tar.gz
  • Upload date:
  • Size: 197.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.10

File hashes

Hashes for meshlane-5.4.0.tar.gz
Algorithm Hash digest
SHA256 63dc9f27ab4e1efed92a3d6b8b813f500ef62864e1250cd0cdce01b213488d4a
MD5 15c0ed676d8eb63852c715fff6c3f7b8
BLAKE2b-256 6c5cc3be790c7a76d8bd878a05060c0e88c608f0bda6b55e303716addcddcfe2

See more details on using hashes here.

File details

Details for the file meshlane-5.4.0-py3-none-any.whl.

File metadata

  • Download URL: meshlane-5.4.0-py3-none-any.whl
  • Upload date:
  • Size: 188.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.10

File hashes

Hashes for meshlane-5.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d26e51e6efd98a1d724854040e4dffb49f8016dd0fc3e47ca1cea36160657ac0
MD5 e9c30efed3f2dbb756b8f0588c6815da
BLAKE2b-256 34f8bd59965477997f3924b17a33925b84cc10325a3802fd9aff8df4a36baceb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page