Metadata-Version: 2.4
Name: mtex2gmsh
Version: 1.0.0
Summary: Generate conforming 2D/3D meshes from EBSD data processed with the Python port of MTEX (mtex) and Gmsh
Author: Dorian Depriester
License-Expression: MIT
Project-URL: Homepage, https://github.com/DorianDepriester/pyMTEX2Gmsh
Project-URL: Documentation, https://pymtex2gmsh.readthedocs.io/
Project-URL: Repository, https://github.com/DorianDepriester/pyMTEX2Gmsh
Project-URL: Issues, https://github.com/DorianDepriester/pyMTEX2Gmsh/issues
Project-URL: Changelog, https://github.com/DorianDepriester/pyMTEX2Gmsh/releases
Keywords: EBSD,MTEX,gmsh,mesh,polycrystal,FEA
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: scipy
Requires-Dist: mtex>=1.0
Requires-Dist: gmsh>=4.11
Requires-Dist: matplotlib
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Provides-Extra: doc
Requires-Dist: sphinx>=7; extra == "doc"
Requires-Dist: myst-parser>=3; extra == "doc"
Requires-Dist: sphinx-gallery>=0.16; extra == "doc"
Requires-Dist: sphinx-rtd-theme>=2; extra == "doc"
Requires-Dist: sphinx-rtd-dark-mode>=1.3; extra == "doc"
Dynamic: license-file

# MTEX2Gmsh for Python

[![tests](https://github.com/DorianDepriester/pyMTEX2Gmsh/actions/workflows/tests.yml/badge.svg)](https://github.com/DorianDepriester/pyMTEX2Gmsh/actions/workflows/tests.yml)
[![Documentation Status](https://readthedocs.org/projects/pymtex2gmsh/badge/?version=latest)](https://pymtex2gmsh.readthedocs.io/)

Generate a conforming mesh from EBSD data processed with Python and MTEX.

**MTEX2Gmsh** (Python package `mtex2gmsh`, this repository `pyMTEX2Gmsh`) is a 100% Python port of the Matlab toolbox
[MTEX2Gmsh](https://github.com/DorianDepriester/MTEX2Gmsh) (Depriester & Kubler,
JOSS 2020, [doi:10.21105/joss.02094](https://doi.org/10.21105/joss.02094)). It
converts grains reconstructed with the [Python port of
MTEX](https://pypi.org/project/mtex/) (`pip install mtex`) into a Gmsh-readable
geometry, then meshes it with [Gmsh](https://gmsh.info) through its official
Python SDK (`pip install gmsh`) — no Matlab, no external binary required.

It is intended to perform Finite Element Analysis (FEA) at grain scale on
polycrystals imaged by EBSD.

📖 **Documentation (with executed examples): <https://pymtex2gmsh.readthedocs.io/>**

## Install

```bash
pip install mtex2gmsh   # everything included: mtex, numpy, scipy, Gmsh SDK, matplotlib
```

Requirements: Python >= 3.12 (required by `mtex` 1.0). On headless machines, also
install the GL libraries used by the Gmsh SDK (`sudo apt-get install libgl1 libglu1-mesa`).

## Quickstart

```python
import mtex
from mtex2gmsh import GmshGeo, plot_mesh

ebsd = mtex.mtexdata('small')              # example dataset shipped with MTEX
grains = mtex.calcGrains(ebsd[ebsd.isIndexed])

G = GmshGeo(grains)                        # Gmsh-readable description of the grains
print(G.size())                            # number of grains and ROI size

G.mesh('small.msh')                        # 3D mesh of linear wedge elements (default)
G.mesh('small_tri.msh', element_type='Tri', element_size=100)   # 2D triangular mesh
plot_mesh('small_tri.msh', output_file='small_tri.png')   # visualize the mesh, export a PNG
G.savegeo('geometry.geo')                  # dump only the Gmsh geometry
G.export_grain_props('grains.csv')         # grain ids, phases, Euler orientations

G.plot()   # plot the B-spline geometry (matplotlib)
```

A complete runnable script is provided in [`examples/example.py`](examples/example.py);
the full documentation (installation, all meshing options, API reference, executed
examples) lives in [`docs/`](docs/) and is built with Sphinx on
[ReadTheDocs](https://pymtex2gmsh.readthedocs.io/).

## Citation

If you use this toolbox, please cite the original paper (Depriester & Kubler,
JOSS 2020, [doi:10.21105/joss.02094](https://doi.org/10.21105/joss.02094)) — see
[CITATION.cff](CITATION.cff), which GitHub picks up for its “Cite this repository” button.

## License

MIT (see [LICENSE](LICENSE)).
