Skip to main content

meshRW is a Python module that proposes basic readers and writers for msh (gmsh) and vtk (Paraview).

Project description

meshRW

GitHub pypi release DOI CI-pytest code coverage

meshRW is a Python module that proposes basic readers and writers for msh (gmsh) and vtk/vtu/pvd (Paraview). It proposes:

  • to read basic legacy gmsh mesh files (version: 2.2)
  • to write mesh files including time series fields to any version of gmsh mesh files and legacy (.vtk) and XML (.vtu, with .pvd) VTK mesh file compatible with Paraview.

Installation

Installation via pip install meshRW

Usage

Examples of usage

Examples of usage could be found in tests files: test_msh.py and test_vtk.py.

Read mesh files

meshRW can read msh files only. Notice that no field can be read.

  • For msh format (only Legacy version 2):

    • Read the file

        from meshRW import msh
        dataMesh = msh.mshReader(filename=<name of the file>, dim=<2 or 3>)
      

      Argument dim (which is optional) could be switched to the value 2 in order to force to extract nodes coordinates in 2D (z-axis coordinate will be removed).

    • Get coordinates of the nodes

         nodes = dataMesh.getNodes()
      
    • Get the list of tags number

         tags = dataMesh.getTags() 
      
    • Get the list of types of elements

         tags = dataMesh.getTypes() 
      
    • Get the list of elements

         elements = dataMesh.getElements(type=<types of elements>, tag=<tags>, dictFormat=<True or False>)
      

      The getElements property

Write mesh files

meshRW can write msh and vtk files. Basic static and time dependent nodal and elemental fields can be written aswell.

The common syntax for writers is the following

    from meshRW import XXXX

        XXXX.zzzzWriter(
            filename = <name of the file>,
            nodes = <array of nodes coordinates>,
            title = <title of the file> (optional),
            elements = [
                {
                    'connectivity': <name of the file>,
                    'type': <type (string) of elements (TRI3, TET4...)>,
                    'physgrp': <list/array of physical groups>,
                },...
            ],
            fields = [
                {
                    'data': <array of data>,
                    'type': <type of data ('nodal' or 'elemental')>,
                    'dim': <ndimension of data's array>,
                    'name': <name of the field>,
                },            
                {
                    'data': <array of data>,
                    'type': <name of the file>,
                    'dim': <dimension of data's array>,
                    'name': <name of the field>,
                    'nbsteps': <number of steps (transient field for instance)>,
                    'steps': <list of steps (time steps for instance)>
                    },...
            ],  
            opts = {...} (dictionary of specific options)
        )
  • For msh format (based on Legacy format, version 2.2 only with class msh and all meshes format provided by gmsh using class msh2):

    • for classical legacy file (not use the gmsh's libAPI) could be accessed by choosing XXXX = msh and zzzz=msh (msh.mshWriter(...))
    • for any kind of legacy file (not use the gmsh's libAPI) could be accessed by choosing XXXX = msh2 and zzzz=msh (msh2.mshWriter(...))

NB:

  • filename must contain .msh extension

  • opts could be (for msh2 only) {'version': VV} (VV could be equal to 2, 2.2, 4, 4.1 that corresponds to gmsh mesh files version - MshFileVersion)

  • in the case of time series data, all the fields are given by default in the output file (to obtain one field per file, pass option append = True to the writer).

  • for vtk format (only non-binary legacy)

    • for classical legacy file (not use the VTK library) could be accessed by choosing XXXX = vtk and zzzz=vtk (vtk.vtkWriter(...))
    • for any kind of legacy file (not use the gmsh's libAPI) could be accessed by choosing XXXX = vtk2 and zzzz=vtk (vtk2.vtkWriter(...))

NB:

  • filename must contain .vtk, .vtu (recommanded) extension
  • opts could be (for vtk2 only) {'binary': True/False, 'ascii': True/False} (these options force data format in .vtu files)
  • in the case of time series fields, the fields are written separated series files with the following format : basename.NNN.vtu (NNN correspond the number of the step starting at 0). In this case, a Paraview .pvd file is also generated to declare all the steps and associated mesh files with the time step values.

References

Developments are based on GMSH API documentation, GMSH tutorials, VTK documentation, Kitware blog posts, VTK discourse.

Other similar tools

LICENSE

Copyright 2024 luc.laurent@lecnam.net

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

meshrw-1.2.0rc0.tar.gz (8.2 MB view details)

Uploaded Source

Built Distribution

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

meshrw-1.2.0rc0-py3-none-any.whl (8.3 MB view details)

Uploaded Python 3

File details

Details for the file meshrw-1.2.0rc0.tar.gz.

File metadata

  • Download URL: meshrw-1.2.0rc0.tar.gz
  • Upload date:
  • Size: 8.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for meshrw-1.2.0rc0.tar.gz
Algorithm Hash digest
SHA256 eb35f25a59256d66f3cb4b0f67e9217751ebe6fa01fc0cc30ab1a10c59d44923
MD5 c9a4668a9c4e56964c86411c9d963642
BLAKE2b-256 304d997aabcc16024e731d2c61c2580040e5fc62abaa7009b8a2c4fcd4f99fa2

See more details on using hashes here.

Provenance

The following attestation bundles were made for meshrw-1.2.0rc0.tar.gz:

Publisher: CI-publish.yml on luclaurent/meshRW

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

File details

Details for the file meshrw-1.2.0rc0-py3-none-any.whl.

File metadata

  • Download URL: meshrw-1.2.0rc0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for meshrw-1.2.0rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 47d7920f38aa5e7a28c98d7cea4e4d0be0c2e3fdf21954bbb59ee2ab40bac6bf
MD5 3ec19f277aa918dfcb8ef3a518a641dc
BLAKE2b-256 1494142c713a3e0ad7855c621a1c829c6467a65f5ecabca9f449c0711f1bc496

See more details on using hashes here.

Provenance

The following attestation bundles were made for meshrw-1.2.0rc0-py3-none-any.whl:

Publisher: CI-publish.yml on luclaurent/meshRW

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