meshRW 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,132 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ pip-wheel-metadata/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py,cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ target/
76
+
77
+ # Jupyter Notebook
78
+ .ipynb_checkpoints
79
+
80
+ # IPython
81
+ profile_default/
82
+ ipython_config.py
83
+
84
+ # pyenv
85
+ .python-version
86
+
87
+ # pipenv
88
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
90
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
91
+ # install all needed dependencies.
92
+ #Pipfile.lock
93
+
94
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95
+ __pypackages__/
96
+
97
+ # Celery stuff
98
+ celerybeat-schedule
99
+ celerybeat.pid
100
+
101
+ # SageMath parsed files
102
+ *.sage.py
103
+
104
+ # Environments
105
+ .env
106
+ .venv
107
+ env/
108
+ venv/
109
+ ENV/
110
+ env.bak/
111
+ venv.bak/
112
+
113
+ # Spyder project settings
114
+ .spyderproject
115
+ .spyproject
116
+
117
+ # Rope project settings
118
+ .ropeproject
119
+
120
+ # mkdocs documentation
121
+ /site
122
+
123
+ # mypy
124
+ .mypy_cache/
125
+ .dmypy.json
126
+ dmypy.json
127
+
128
+ # Pyre type checker
129
+ .pyre/
130
+
131
+ meshRW/tests/unused_test_data
132
+ meshRW/tests/artifacts/
meshrw-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 luclaurent
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
meshrw-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,184 @@
1
+ Metadata-Version: 2.4
2
+ Name: meshRW
3
+ Version: 1.0.0
4
+ Summary: meshRW is a Python module that proposes basic readers and writers for msh (gmsh) and vtk (Paraview).
5
+ Project-URL: Homepage, https://github.com/luclaurent/meshRW
6
+ Project-URL: Repository, https://github.com/luclaurent/meshRW
7
+ Project-URL: Issues, https://github.com/luclaurent/meshRW/issues
8
+ Author-email: "L. Laurent" <luc.laurent@lecnam.net>
9
+ License: MIT License
10
+
11
+ Copyright (c) 2021 luclaurent
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
30
+ License-File: LICENSE
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Operating System :: OS Independent
33
+ Classifier: Programming Language :: Python :: 3
34
+ Requires-Python: >=3.8
35
+ Requires-Dist: gmsh
36
+ Requires-Dist: loguru
37
+ Requires-Dist: lxml
38
+ Requires-Dist: numpy
39
+ Requires-Dist: pytest
40
+ Requires-Dist: pytest-cov
41
+ Requires-Dist: vtk==9.4.0
42
+ Description-Content-Type: text/markdown
43
+
44
+ # meshRW
45
+
46
+ ![GitHub](https://img.shields.io/github/license/luclaurent/meshRW?style=flat-square) [![pypi release](https://img.shields.io/pypi/v/meshrw.svg)](https://pypi.org/project/meshrw/) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.14514790.svg)](https://doi.org/10.5281/zenodo.14514790) ![CI-pytest](https://github.com/luclaurent/meshRW/actions/workflows/CI-pytest.yml/badge.svg) ![code coverage](https://raw.githubusercontent.com/luclaurent/meshRW/refs/heads/coverage-badge/coverage.svg)
47
+
48
+ <!-- ![GitHub release (latest by date)](https://img.shields.io/github/v/release/luclaurent/meshRW?style=flat-square) ![GitHub all releases](https://img.shields.io/github/downloads/luclaurent/meshRW/total?style=flat-square) -->
49
+
50
+ `meshRW` is a Python module that proposes basic readers and writers for `msh` ([gmsh](http://gmsh.info)) and `vtk/vtu/pvd` ([Paraview](https://www.paraview.org/)). It proposes:
51
+
52
+ * to read basic legacy `gmsh` mesh files (version: 2.2)
53
+ * 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](https://www.paraview.org/).
54
+
55
+
56
+ ## Installation
57
+
58
+ Installation via `pip install meshRW`
59
+
60
+ ## Usage
61
+
62
+ ### Examples of usage
63
+
64
+ Examples of usage could be found in tests files: [`test_msh.py`](meshRW/tests/test_msh.py) and [`test_vtk.py`](meshRW/tests/test_vtk.py).
65
+
66
+ ### Read mesh files
67
+
68
+ `meshRW` can read `msh` files only. Notice that no field can be read.
69
+
70
+ * For `msh` format ([only Legacy version 2](http://gmsh.info/doc/texinfo/gmsh.html#MSH-file-format-version-2-_0028Legacy_0029)):
71
+
72
+ * Read the file
73
+
74
+ from meshRW import msh
75
+ dataMesh = msh.mshReader(filename=<name of the file>, dim=<2 or 3>)
76
+
77
+ 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).
78
+
79
+ * Get coordinates of the nodes
80
+
81
+ nodes = dataMesh.getNodes()
82
+
83
+ * Get the list of tags number
84
+
85
+ tags = dataMesh.getTags()
86
+
87
+ * Get the list of types of elements
88
+
89
+ tags = dataMesh.getTypes()
90
+
91
+ * Get the list of elements
92
+
93
+ elements = dataMesh.getElements(type=<types of elements>, tag=<tags>, dictFormat=<True or False>)
94
+
95
+ The `getElements` property
96
+
97
+
98
+ ### Write mesh files
99
+
100
+ `meshRW` can write `msh` and `vtk` files. Basic static and **time dependent** nodal and elemental fields can be written aswell.
101
+
102
+ The common syntax for writers is the following
103
+
104
+ from meshRW import XXXX
105
+
106
+ XXXX.zzzzWriter(
107
+ filename = <name of the file>,
108
+ nodes = <array of nodes coordinates>,
109
+ title = <title of the file> (optional),
110
+ elements = [
111
+ {
112
+ 'connectivity': <name of the file>,
113
+ 'type': <type (string) of elements (TRI3, TET4...)>,
114
+ 'physgrp': <list/array of physical groups>,
115
+ },...
116
+ ],
117
+ fields = [
118
+ {
119
+ 'data': <array of data>,
120
+ 'type': <type of data ('nodal' or 'elemental')>,
121
+ 'dim': <ndimension of data's array>,
122
+ 'name': <name of the field>,
123
+ },
124
+ {
125
+ 'data': <array of data>,
126
+ 'type': <name of the file>,
127
+ 'dim': <dimension of data's array>,
128
+ 'name': <name of the field>,
129
+ 'nbsteps': <number of steps (transient field for instance)>,
130
+ 'steps': <list of steps (time steps for instance)>
131
+ },...
132
+ ],
133
+ opts = {...} (dictionary of specific options)
134
+ )
135
+
136
+ * For `msh` format (based on [Legacy format, version 2.2](http://gmsh.info/doc/texinfo/gmsh.html#MSH-file-format-version-2-_0028Legacy_0029) only with class `msh` and all meshes format provided by `gmsh` using class `msh2`):
137
+
138
+ * for classical legacy file (not use the gmsh's libAPI) could be accessed by choosing `XXXX = msh` and `zzzz=msh` (`msh.mshWriter(...)`)
139
+ * for any kind of legacy file (not use the gmsh's libAPI) could be accessed by choosing `XXXX = msh2` and `zzzz=msh` (`msh2.mshWriter(...)`)
140
+
141
+ **NB:**
142
+ * `filename` must contain `.msh` extension
143
+ * `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`)
144
+ * 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).
145
+
146
+ * for `vtk` format ([only non-binary legacy](https://kitware.github.io/vtk-examples/site/VTKFileFormats/))
147
+
148
+ * for classical legacy file (not use the VTK library) could be accessed by choosing `XXXX = vtk` and `zzzz=vtk` (`vtk.vtkWriter(...)`)
149
+ * for any kind of legacy file (not use the gmsh's libAPI) could be accessed by choosing `XXXX = vtk2` and `zzzz=vtk` (`vtk2.vtkWriter(...)`)
150
+
151
+ **NB:**
152
+ * `filename` must contain `.vtk`, `.vtu` (recommanded) extension
153
+ * `opts` could be (for `vtk2` only) `{'binary': True/False, 'ascii': True/False}` (these options force data format in `.vtu` files)
154
+ * 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](https://www.paraview.org/Wiki/ParaView/Data_formats#PVD_File_Format) `.pvd` file is also generated to declare all the steps and associated mesh files with the time step values.
155
+
156
+
157
+
158
+ <!-- ## Examples
159
+ ### Example: load and display a mesh file from msh
160
+
161
+ ### Example: add a static nodal field to an existing mesh
162
+
163
+ ### Example: add a time-dependent nodal field to an exisiting mesh -->
164
+
165
+ ## References
166
+
167
+ Developments are based on [GMSH API documentation](https://gmsh.info/doc/texinfo/gmsh.html#Gmsh-API), [GMSH tutorials](https://gitlab.onelab.info/gmsh/gmsh/-/tree/master/tutorials/python?ref_type=heads), [VTK documentation](https://vtk.org/doc/nightly/html/index.html), [Kitware blog posts](https://www.kitware.com/blog/), [VTK discourse](https://discourse.vtk.org/).
168
+
169
+
170
+ ## Other similar tools
171
+
172
+ * [`meshio`](https://github.com/nschloe/meshio)
173
+
174
+ ## LICENSE
175
+
176
+
177
+
178
+ Copyright 2024 luc.laurent@lecnam.net
179
+
180
+ 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:
181
+
182
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
183
+
184
+ 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.
meshrw-1.0.0/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # meshRW
2
+
3
+ ![GitHub](https://img.shields.io/github/license/luclaurent/meshRW?style=flat-square) [![pypi release](https://img.shields.io/pypi/v/meshrw.svg)](https://pypi.org/project/meshrw/) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.14514790.svg)](https://doi.org/10.5281/zenodo.14514790) ![CI-pytest](https://github.com/luclaurent/meshRW/actions/workflows/CI-pytest.yml/badge.svg) ![code coverage](https://raw.githubusercontent.com/luclaurent/meshRW/refs/heads/coverage-badge/coverage.svg)
4
+
5
+ <!-- ![GitHub release (latest by date)](https://img.shields.io/github/v/release/luclaurent/meshRW?style=flat-square) ![GitHub all releases](https://img.shields.io/github/downloads/luclaurent/meshRW/total?style=flat-square) -->
6
+
7
+ `meshRW` is a Python module that proposes basic readers and writers for `msh` ([gmsh](http://gmsh.info)) and `vtk/vtu/pvd` ([Paraview](https://www.paraview.org/)). It proposes:
8
+
9
+ * to read basic legacy `gmsh` mesh files (version: 2.2)
10
+ * 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](https://www.paraview.org/).
11
+
12
+
13
+ ## Installation
14
+
15
+ Installation via `pip install meshRW`
16
+
17
+ ## Usage
18
+
19
+ ### Examples of usage
20
+
21
+ Examples of usage could be found in tests files: [`test_msh.py`](meshRW/tests/test_msh.py) and [`test_vtk.py`](meshRW/tests/test_vtk.py).
22
+
23
+ ### Read mesh files
24
+
25
+ `meshRW` can read `msh` files only. Notice that no field can be read.
26
+
27
+ * For `msh` format ([only Legacy version 2](http://gmsh.info/doc/texinfo/gmsh.html#MSH-file-format-version-2-_0028Legacy_0029)):
28
+
29
+ * Read the file
30
+
31
+ from meshRW import msh
32
+ dataMesh = msh.mshReader(filename=<name of the file>, dim=<2 or 3>)
33
+
34
+ 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).
35
+
36
+ * Get coordinates of the nodes
37
+
38
+ nodes = dataMesh.getNodes()
39
+
40
+ * Get the list of tags number
41
+
42
+ tags = dataMesh.getTags()
43
+
44
+ * Get the list of types of elements
45
+
46
+ tags = dataMesh.getTypes()
47
+
48
+ * Get the list of elements
49
+
50
+ elements = dataMesh.getElements(type=<types of elements>, tag=<tags>, dictFormat=<True or False>)
51
+
52
+ The `getElements` property
53
+
54
+
55
+ ### Write mesh files
56
+
57
+ `meshRW` can write `msh` and `vtk` files. Basic static and **time dependent** nodal and elemental fields can be written aswell.
58
+
59
+ The common syntax for writers is the following
60
+
61
+ from meshRW import XXXX
62
+
63
+ XXXX.zzzzWriter(
64
+ filename = <name of the file>,
65
+ nodes = <array of nodes coordinates>,
66
+ title = <title of the file> (optional),
67
+ elements = [
68
+ {
69
+ 'connectivity': <name of the file>,
70
+ 'type': <type (string) of elements (TRI3, TET4...)>,
71
+ 'physgrp': <list/array of physical groups>,
72
+ },...
73
+ ],
74
+ fields = [
75
+ {
76
+ 'data': <array of data>,
77
+ 'type': <type of data ('nodal' or 'elemental')>,
78
+ 'dim': <ndimension of data's array>,
79
+ 'name': <name of the field>,
80
+ },
81
+ {
82
+ 'data': <array of data>,
83
+ 'type': <name of the file>,
84
+ 'dim': <dimension of data's array>,
85
+ 'name': <name of the field>,
86
+ 'nbsteps': <number of steps (transient field for instance)>,
87
+ 'steps': <list of steps (time steps for instance)>
88
+ },...
89
+ ],
90
+ opts = {...} (dictionary of specific options)
91
+ )
92
+
93
+ * For `msh` format (based on [Legacy format, version 2.2](http://gmsh.info/doc/texinfo/gmsh.html#MSH-file-format-version-2-_0028Legacy_0029) only with class `msh` and all meshes format provided by `gmsh` using class `msh2`):
94
+
95
+ * for classical legacy file (not use the gmsh's libAPI) could be accessed by choosing `XXXX = msh` and `zzzz=msh` (`msh.mshWriter(...)`)
96
+ * for any kind of legacy file (not use the gmsh's libAPI) could be accessed by choosing `XXXX = msh2` and `zzzz=msh` (`msh2.mshWriter(...)`)
97
+
98
+ **NB:**
99
+ * `filename` must contain `.msh` extension
100
+ * `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`)
101
+ * 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).
102
+
103
+ * for `vtk` format ([only non-binary legacy](https://kitware.github.io/vtk-examples/site/VTKFileFormats/))
104
+
105
+ * for classical legacy file (not use the VTK library) could be accessed by choosing `XXXX = vtk` and `zzzz=vtk` (`vtk.vtkWriter(...)`)
106
+ * for any kind of legacy file (not use the gmsh's libAPI) could be accessed by choosing `XXXX = vtk2` and `zzzz=vtk` (`vtk2.vtkWriter(...)`)
107
+
108
+ **NB:**
109
+ * `filename` must contain `.vtk`, `.vtu` (recommanded) extension
110
+ * `opts` could be (for `vtk2` only) `{'binary': True/False, 'ascii': True/False}` (these options force data format in `.vtu` files)
111
+ * 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](https://www.paraview.org/Wiki/ParaView/Data_formats#PVD_File_Format) `.pvd` file is also generated to declare all the steps and associated mesh files with the time step values.
112
+
113
+
114
+
115
+ <!-- ## Examples
116
+ ### Example: load and display a mesh file from msh
117
+
118
+ ### Example: add a static nodal field to an existing mesh
119
+
120
+ ### Example: add a time-dependent nodal field to an exisiting mesh -->
121
+
122
+ ## References
123
+
124
+ Developments are based on [GMSH API documentation](https://gmsh.info/doc/texinfo/gmsh.html#Gmsh-API), [GMSH tutorials](https://gitlab.onelab.info/gmsh/gmsh/-/tree/master/tutorials/python?ref_type=heads), [VTK documentation](https://vtk.org/doc/nightly/html/index.html), [Kitware blog posts](https://www.kitware.com/blog/), [VTK discourse](https://discourse.vtk.org/).
125
+
126
+
127
+ ## Other similar tools
128
+
129
+ * [`meshio`](https://github.com/nschloe/meshio)
130
+
131
+ ## LICENSE
132
+
133
+
134
+
135
+ Copyright 2024 luc.laurent@lecnam.net
136
+
137
+ 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:
138
+
139
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
140
+
141
+ 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.
@@ -0,0 +1 @@
1
+ __version__ = '1.0.0'
@@ -0,0 +1,22 @@
1
+ """
2
+ This file contains the default
3
+ declaration of the keywords
4
+ used to declare/manipulate a mesh in Python
5
+ ----
6
+ Luc Laurent - luc.laurent@lecnam.net -- 2021
7
+ """
8
+
9
+ DFLT_MESH = 'connectivity'
10
+ DFLT_TYPE_ELEM = 'type'
11
+ DFLT_PHYS_GRP = 'physgrp'
12
+ DFLT_FIELD_DATA = 'data'
13
+ DFLT_FIELD_TYPE = 'type'
14
+ DFLT_FIELD_TYPE_NODAL = 'nodal'
15
+ DFLT_FIELD_TYPE_ELEMENT = 'elemental'
16
+ DFLT_FIELD_TYPE_NODAL_SCALAR = 'nodal_scalar'
17
+ DFLT_FIELD_TYPE_ELEMENT_SCALAR = 'elemental_scalar'
18
+ DFLT_FIELD_DIM = 'dim'
19
+ DFLT_FIELD_NAME = 'name'
20
+ DFLT_FIELD_STEPS = 'steps'
21
+ DFLT_FIELD_NBSTEPS = 'nbsteps'
22
+ DFLT_FIELD_NUMENTITIES = 'numentities'
@@ -0,0 +1,172 @@
1
+ """ "
2
+ This file includes the definition
3
+ and tools to manipulate MSH format
4
+ Documentation available here:
5
+ https://gmsh.info/doc/texinfo/gmsh.html#MSH-file-format
6
+ ----
7
+ Luc Laurent - luc.laurent@lecnam.net -- 2021
8
+
9
+ """
10
+
11
+ from loguru import logger as Logger
12
+
13
+
14
+ def loadElementDict():
15
+ """
16
+ dictionary from element (string) to msh element number
17
+ """
18
+ elementDict = {
19
+ # 2-nodes line
20
+ 'LIN2': {'code': 1, 'nodes': 2, 'dim': 1},
21
+ # 3-nodes second order line
22
+ 'LIN3': {'code': 8, 'nodes': 3, 'dim': 1},
23
+ # 4-nodes third order line
24
+ 'LIN4': None,
25
+ # 3-nodes triangle
26
+ 'TRI3': {'code': 2, 'nodes': 3, 'dim': 2},
27
+ # 6-nodes second order triangle (3 vertices, 3 on edges)
28
+ 'TRI6': {'code': 9, 'nodes': 6, 'dim': 2},
29
+ # 9-nodes cubic order triangle (3 vertices, 3 on edges and 3 inside)
30
+ 'TRI9': None,
31
+ # 10-nodes higher order triangle (3 vertices, 6 on edges and 1 inside)
32
+ 'TRI10': None,
33
+ # 12-nodes higher order triangle (3 vertices and 9 on edges)
34
+ 'TRI12': None,
35
+ # 15-nodes higher order triangle (3 vertices, 9 on edges and 3 inside)
36
+ 'TRI15': None,
37
+ # 4-nodes quadrangle
38
+ 'QUA4': {'code': 3, 'nodes': 4, 'dim': 2},
39
+ # 8-nodes second order quadrangle (4 vertices and 4 on edges)
40
+ 'QUA8': {'code': 16, 'nodes': 8, 'dim': 2},
41
+ # 9-nodes higher order quadrangle (4 vertices, 4 on edges and 1 inside)
42
+ 'QUA9': {'code': 10, 'nodes': 9, 'dim': 2},
43
+ # 4-nodes tetrahedron
44
+ 'TET4': {'code': 4, 'nodes': 4, 'dim': 3},
45
+ # 10-nodes second order tetrahedron (4 vertices and 6 on edges)
46
+ 'TET10': {'code': 11, 'nodes': 10, 'dim': 3},
47
+ # 8-nodes hexahedron
48
+ 'HEX8': {'code': 5, 'nodes': 8, 'dim': 3},
49
+ # 20-nodes second order hexahedron (8 vertices and 12 on edges)
50
+ 'HEX20': {'code': 17, 'nodes': 20, 'dim': 3},
51
+ # 27-nodes higher order hexahedron
52
+ # (8 vertices, 12 on edges, 6 on faces and 1 inside)
53
+ 'HEX27': {'code': 12, 'nodes': 27, 'dim': 3},
54
+ # 6-nodes prism
55
+ 'PRI6': {'code': 6, 'nodes': 6, 'dim': 3},
56
+ # 15-nodes second order prism (6 vertices and 9 on edges)
57
+ 'PRI15': {'code': 18, 'nodes': 15, 'dim': 3},
58
+ # 18-nodes higher order prism (6 vertices, 9 on edges and 3 on faces)
59
+ 'PRI18': {'code': 13, 'nodes': 18, 'dim': 3},
60
+ # 5-node pyramid
61
+ 'PYR5': {'code': 7, 'nodes': 5, 'dim': 3},
62
+ # 13-nodes second order pyramid (5 edges and 8 on edges)
63
+ 'PYR13': {'code': 19, 'nodes': 13, 'dim': 3},
64
+ # 14-nodes higher order pyramid (5 edges, 8 on edges and 1 inside)
65
+ 'PYR14': {'code': 14, 'nodes': 14, 'dim': 3},
66
+ # 1-node point
67
+ 'NOD1': {'code': 15, 'nodes': 1, 'dim': 0},
68
+ }
69
+ return elementDict
70
+
71
+
72
+ def getMSHElemType(txtEltype):
73
+ """
74
+ Get the element type defined as in gmsh (refer to gmsh documentation for numbering) from text declaration
75
+ syntax:
76
+ getMshElemType(txtEltype)
77
+
78
+ input:
79
+ txtEltype: element declared using string (if number is used the function will return it)
80
+ output:
81
+ element type defined as gmsh number
82
+ """
83
+ elementDict = loadElementDict()
84
+
85
+ # depending on the type of txtEltype
86
+ # - if int: return txtEltype
87
+ # - else get the number from the dictionary
88
+ if isinstance(txtEltype, int):
89
+ elementNum = txtEltype
90
+ else:
91
+ elementNum = elementDict[txtEltype.upper()].get('code', None)
92
+ # show error if the type is not available
93
+ if not elementNum:
94
+ Logger.error(f'Element type {txtEltype} not implemented')
95
+ return elementNum
96
+
97
+
98
+ def getElemTypeFromMSH(elementNum):
99
+ """
100
+ Get the element type from id (integer) defined in gmsh (refer to gmsh documentation for numbering)
101
+ syntax:
102
+ getElemTypeFromMSH(elementNum)
103
+
104
+ input:
105
+ elementNum: integer used in gmsh to declare element
106
+ output:
107
+ global name of the element
108
+ """
109
+ # load the dictionary
110
+ elementDict = loadElementDict()
111
+ globalName = None
112
+ # get the name of the element using the integer iD along the dictionary
113
+ for k, v in elementDict.items():
114
+ if v:
115
+ if v.get('code', None) == elementNum:
116
+ globalName = k
117
+ break
118
+ # if the name of the element if not available show error
119
+ if globalName is None:
120
+ Logger.error(f'Element type not found with id {elementNum}')
121
+ return globalName
122
+
123
+
124
+ def getNumberNodes(txtElemtype):
125
+ """
126
+ Get the number of nodes for a specific element type type (declare as string)
127
+ syntax:
128
+ getNumberNodes(txtElemtype)
129
+
130
+ input:
131
+ txtElemtype: element declared using string (if number is used the function wil return it)
132
+ output:
133
+ number of nodes for txtEltype
134
+ """
135
+ # load the dictionary
136
+ elementDict = loadElementDict()
137
+ nbNodes = 0
138
+ # check if the type of element exists
139
+ if txtElemtype in elementDict.keys():
140
+ # get the number of nodes for the type of element
141
+ if elementDict[txtElemtype]:
142
+ nbNodes = elementDict[txtElemtype].get('nodes', None)
143
+ else:
144
+ # show error message if the type of element does not exist
145
+ Logger.error(f'Element type {txtElemtype} not defined')
146
+ return nbNodes
147
+
148
+
149
+ def getNumberNodesFromNum(elementNum):
150
+ """
151
+ Get the number of nodfs for a specific element type type (declare as string)
152
+ syntax:
153
+ getNumberNodesFromNum(elementNum)
154
+
155
+ input:
156
+ elementNum: integer used in gmsh to declare element
157
+ output:
158
+ number of nodes for txtEltype
159
+ """
160
+ return getNumberNodes(getElemTypeFromMSH(elementNum))
161
+
162
+
163
+ # DEFAULT VALUES
164
+ ALLOWED_EXTENSIONS = ['.msh', '.msh.bz2', '.msh.gz']
165
+
166
+ # Keywords MSH
167
+ DFLT_FILE_OPEN_CLOSE = {'open': '$MeshFormat', 'close': '$EndMeshFormat'}
168
+ DFLT_FILE_VERSION = '2.2 0 8'
169
+ DFLT_NODES_OPEN_CLOSE = {'open': '$Nodes', 'close': '$EndNodes'}
170
+ DFLT_ELEMS_OPEN_CLOSE = {'open': '$Elements', 'close': '$EndElements'}
171
+ DFLT_FIELDS_NODES_OPEN_CLOSE = {'open': '$NodeData', 'close': '$EndNodeData'}
172
+ DFLT_FIELDS_ELEMS_OPEN_CLOSE = {'open': '$ElementData', 'close': '$EndElementData'}