meshRW is a Python module that proposes basic readers and writers for msh (gmsh) and vtk (Paraview).
Project description
meshRW
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
gmshmesh files (version: 2.2) - to write mesh files including time series fields to any version of
gmshmesh 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
mshformat (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 value2in 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
getElementsproperty
-
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
mshformat (based on Legacy format, version 2.2 only with classmshand all meshes format provided bygmshusing classmsh2):- for classical legacy file (not use the gmsh's libAPI) could be accessed by choosing
XXXX = mshandzzzz=msh(msh.mshWriter(...)) - for any kind of legacy file (not use the gmsh's libAPI) could be accessed by choosing
XXXX = msh2andzzzz=msh(msh2.mshWriter(...))
- for classical legacy file (not use the gmsh's libAPI) could be accessed by choosing
NB for .msh files:
-
filenamemust contain.mshextension -
optscould be (formsh2only){'version': VV}(VVcould be equal to2, 2.2, 4, 4.1that corresponds togmshmesh 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 = Trueto the writer). -
for
vtkformat (only non-binary legacy)- for classical legacy file (not use the VTK library) could be accessed by choosing
XXXX = vtkandzzzz=vtk(vtk.vtkWriter(...)) - for any kind of legacy file (not use the gmsh's libAPI) could be accessed by choosing
XXXX = vtk2andzzzz=vtk(vtk2.vtkWriter(...))
- for classical legacy file (not use the VTK library) could be accessed by choosing
NB for .vtk|.vtu|.pvd files:
filenamemust contain.vtk,.vtu(recommanded) extensionoptscould be (forvtk2only){'binary': True/False, 'ascii': True/False}(these options force data format in.vtufiles)- 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.pvdfile 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file meshrw-1.5.2.tar.gz.
File metadata
- Download URL: meshrw-1.5.2.tar.gz
- Upload date:
- Size: 8.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
153ca51b793b9d8099c4c45db63bea657a9cd32a2fd80fb0186ed23ae900d6b7
|
|
| MD5 |
cfdcbc2a9bd3bcb03c9ce1877863a19f
|
|
| BLAKE2b-256 |
18229a8aa0c286911fbeb7d05fdc1716fd92edd535afdca7425cd0d6b4e085a6
|
Provenance
The following attestation bundles were made for meshrw-1.5.2.tar.gz:
Publisher:
CI-publish.yml on luclaurent/meshRW
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
meshrw-1.5.2.tar.gz -
Subject digest:
153ca51b793b9d8099c4c45db63bea657a9cd32a2fd80fb0186ed23ae900d6b7 - Sigstore transparency entry: 597213011
- Sigstore integration time:
-
Permalink:
luclaurent/meshRW@edab5345044696df7d4fbf2f72450d19320fd069 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/luclaurent
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
CI-publish.yml@edab5345044696df7d4fbf2f72450d19320fd069 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file meshrw-1.5.2-py3-none-any.whl.
File metadata
- Download URL: meshrw-1.5.2-py3-none-any.whl
- Upload date:
- Size: 8.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db768812bdf2394eededf0279e36e10c2bd90032cf45d7c17ca821a772b91796
|
|
| MD5 |
053c4197053bcc3aba1103f24c0f218f
|
|
| BLAKE2b-256 |
53078240641b3f09b0ca7911e8ffb371fb577adb52296f03b71be529bd643e8b
|
Provenance
The following attestation bundles were made for meshrw-1.5.2-py3-none-any.whl:
Publisher:
CI-publish.yml on luclaurent/meshRW
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
meshrw-1.5.2-py3-none-any.whl -
Subject digest:
db768812bdf2394eededf0279e36e10c2bd90032cf45d7c17ca821a772b91796 - Sigstore transparency entry: 597213012
- Sigstore integration time:
-
Permalink:
luclaurent/meshRW@edab5345044696df7d4fbf2f72450d19320fd069 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/luclaurent
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
CI-publish.yml@edab5345044696df7d4fbf2f72450d19320fd069 -
Trigger Event:
workflow_run
-
Statement type: