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.1.tar.gz (197.5 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.1-py3-none-any.whl (188.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: meshlane-5.4.1.tar.gz
  • Upload date:
  • Size: 197.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for meshlane-5.4.1.tar.gz
Algorithm Hash digest
SHA256 9a8f9aa798371101b973384fcf62b23d6b768bc57bd9bbd75b6b7d0384469c10
MD5 86bedc3856ef170663227b98bb9a640c
BLAKE2b-256 8c99d26702c8bc3bd0917273fc60a25a62095e290a8ec69dfaf8d84743028650

See more details on using hashes here.

Provenance

The following attestation bundles were made for meshlane-5.4.1.tar.gz:

Publisher: release.yml on simvia-tech/meshlane

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: meshlane-5.4.1-py3-none-any.whl
  • Upload date:
  • Size: 188.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for meshlane-5.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f099c047449e4920916a9d66df65077bd9bfc4375511ec48c78e44b502b52feb
MD5 57edc50e048b38ac0b84276e2e01f0a2
BLAKE2b-256 3fa40fcf5ce5020ada7e234d966df8932b6fb9b7f90f9e7b5400cf02694ae728

See more details on using hashes here.

Provenance

The following attestation bundles were made for meshlane-5.4.1-py3-none-any.whl:

Publisher: release.yml on simvia-tech/meshlane

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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