# pygmsh
[](https://circleci.com/gh/nschloe/pygmsh)
[](https://codecov.io/gh/nschloe/pygmsh)
[](https://github.com/ambv/black)
[](https://pygmsh.readthedocs.org/en/latest/?badge=latest)
[](https://pypi.org/project/pygmsh)
[](https://doi.org/10.5281/zenodo.1173105)
[](https://github.com/nschloe/pygmsh)
<p align="center">
<img src="https://nschloe.github.io/pygmsh/logo.svg" width="20%">
</p>
[Gmsh](https://gmsh.info/) is a powerful mesh generation tool with a
scripting language that is notoriously hard to write.
The goal of pygmsh is to combine the power of Gmsh with the versatility of
Python and to provide useful abstractions from the Gmsh scripting language
so you can create complex geometries more easily.
See [here](https://pygmsh.readthedocs.io/en/latest/index.html) for the full
documentation.
#### Built-in

To create the above mesh, simply do
```python,test
import pygmsh
import numpy as np
geom = pygmsh.built_in.Geometry()
# Draw a cross.
poly = geom.add_polygon([
[ 0.0, 0.5, 0.0],
[-0.1, 0.1, 0.0],
[-0.5, 0.0, 0.0],
[-0.1, -0.1, 0.0],
[ 0.0, -0.5, 0.0],
[ 0.1, -0.1, 0.0],
[ 0.5, 0.0, 0.0],
[ 0.1, 0.1, 0.0]
],
lcar=0.05
)
axis = [0, 0, 1]
geom.extrude(
poly,
translation_axis=axis,
rotation_axis=axis,
point_on_axis=[0, 0, 0],
angle=2.0 / 6.0 * np.pi
)
points, cells, point_data, cell_data, field_data = pygmsh.generate_mesh(geom)
```
to retrieve all points and cells of the mesh for the specified geometry.
To store the mesh, you can use [meshio](https://pypi.org/project/meshio);
for example
```python
import meshio
meshio.write_points_cells('test.vtk', points, cells, cell_data=cell_data)
```
The output file can be visualized with various tools, e.g.,
[ParaView](https://www.paraview.org/).
You will find the above mesh in the directory
[`test/`](https://github.com/nschloe/pygmsh/tree/master/test/) along with other
small examples.
#### OpenCASCADE

As of version 3.0, Gmsh supports OpenCASCADE, allowing for a CAD-style geometry
specification.
Example:
```python,test
import pygmsh
geom = pygmsh.opencascade.Geometry(
characteristic_length_min=0.1,
characteristic_length_max=0.1,
)
rectangle = geom.add_rectangle([-1.0, -1.0, 0.0], 2.0, 2.0)
disk1 = geom.add_disk([-1.2, 0.0, 0.0], 0.5)
disk2 = geom.add_disk([+1.2, 0.0, 0.0], 0.5)
union = geom.boolean_union([rectangle, disk1, disk2])
disk3 = geom.add_disk([0.0, -0.9, 0.0], 0.5)
disk4 = geom.add_disk([0.0, +0.9, 0.0], 0.5)
flat = geom.boolean_difference([union], [disk3, disk4])
geom.extrude(flat, [0, 0, 0.3])
points, cells, point_data, cell_data, field_data = pygmsh.generate_mesh(geom)
```
### Installation
pygmsh is [available from the Python Package
Index](https://pypi.org/project/pygmsh/), so simply type
```
pip install -U pygmsh
```
to install or upgrade.
### Usage
Just
```
import pygmsh as pg
```
and make use of all the goodies the module provides. The
[documentation](https://pygmsh.readthedocs.org/) and the examples under
[`test/`](https://github.com/nschloe/pygmsh/tree/master/test/)
might inspire you.
### Testing
To run the pygmsh unit tests, check out this repository and type
```
pytest
```
### Building Documentation
Docs are built using [Sphinx](http://www.sphinx-doc.org/en/stable/).
To build run
```
sphinx-build -b html doc doc/_build
```
### Distribution
To create a new release
1. bump the `__version__` number,
2. publish to PyPi and GitHub:
```
$ make publish
```
### License
pygmsh is published under the [MIT license](https://en.wikipedia.org/wiki/MIT_License).
[](https://circleci.com/gh/nschloe/pygmsh)
[](https://codecov.io/gh/nschloe/pygmsh)
[](https://github.com/ambv/black)
[](https://pygmsh.readthedocs.org/en/latest/?badge=latest)
[](https://pypi.org/project/pygmsh)
[](https://doi.org/10.5281/zenodo.1173105)
[](https://github.com/nschloe/pygmsh)
<p align="center">
<img src="https://nschloe.github.io/pygmsh/logo.svg" width="20%">
</p>
[Gmsh](https://gmsh.info/) is a powerful mesh generation tool with a
scripting language that is notoriously hard to write.
The goal of pygmsh is to combine the power of Gmsh with the versatility of
Python and to provide useful abstractions from the Gmsh scripting language
so you can create complex geometries more easily.
See [here](https://pygmsh.readthedocs.io/en/latest/index.html) for the full
documentation.
#### Built-in

To create the above mesh, simply do
```python,test
import pygmsh
import numpy as np
geom = pygmsh.built_in.Geometry()
# Draw a cross.
poly = geom.add_polygon([
[ 0.0, 0.5, 0.0],
[-0.1, 0.1, 0.0],
[-0.5, 0.0, 0.0],
[-0.1, -0.1, 0.0],
[ 0.0, -0.5, 0.0],
[ 0.1, -0.1, 0.0],
[ 0.5, 0.0, 0.0],
[ 0.1, 0.1, 0.0]
],
lcar=0.05
)
axis = [0, 0, 1]
geom.extrude(
poly,
translation_axis=axis,
rotation_axis=axis,
point_on_axis=[0, 0, 0],
angle=2.0 / 6.0 * np.pi
)
points, cells, point_data, cell_data, field_data = pygmsh.generate_mesh(geom)
```
to retrieve all points and cells of the mesh for the specified geometry.
To store the mesh, you can use [meshio](https://pypi.org/project/meshio);
for example
```python
import meshio
meshio.write_points_cells('test.vtk', points, cells, cell_data=cell_data)
```
The output file can be visualized with various tools, e.g.,
[ParaView](https://www.paraview.org/).
You will find the above mesh in the directory
[`test/`](https://github.com/nschloe/pygmsh/tree/master/test/) along with other
small examples.
#### OpenCASCADE

As of version 3.0, Gmsh supports OpenCASCADE, allowing for a CAD-style geometry
specification.
Example:
```python,test
import pygmsh
geom = pygmsh.opencascade.Geometry(
characteristic_length_min=0.1,
characteristic_length_max=0.1,
)
rectangle = geom.add_rectangle([-1.0, -1.0, 0.0], 2.0, 2.0)
disk1 = geom.add_disk([-1.2, 0.0, 0.0], 0.5)
disk2 = geom.add_disk([+1.2, 0.0, 0.0], 0.5)
union = geom.boolean_union([rectangle, disk1, disk2])
disk3 = geom.add_disk([0.0, -0.9, 0.0], 0.5)
disk4 = geom.add_disk([0.0, +0.9, 0.0], 0.5)
flat = geom.boolean_difference([union], [disk3, disk4])
geom.extrude(flat, [0, 0, 0.3])
points, cells, point_data, cell_data, field_data = pygmsh.generate_mesh(geom)
```
### Installation
pygmsh is [available from the Python Package
Index](https://pypi.org/project/pygmsh/), so simply type
```
pip install -U pygmsh
```
to install or upgrade.
### Usage
Just
```
import pygmsh as pg
```
and make use of all the goodies the module provides. The
[documentation](https://pygmsh.readthedocs.org/) and the examples under
[`test/`](https://github.com/nschloe/pygmsh/tree/master/test/)
might inspire you.
### Testing
To run the pygmsh unit tests, check out this repository and type
```
pytest
```
### Building Documentation
Docs are built using [Sphinx](http://www.sphinx-doc.org/en/stable/).
To build run
```
sphinx-build -b html doc doc/_build
```
### Distribution
To create a new release
1. bump the `__version__` number,
2. publish to PyPi and GitHub:
```
$ make publish
```
### License
pygmsh is published under the [MIT license](https://en.wikipedia.org/wiki/MIT_License).
Metadata
Release files for pygmsh 4.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pygmsh-4.4.0.tar.gz | 32.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pygmsh-4.4.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 70.1 kB
Release files / pygmsh-4.4.0.tar.gz
| Download URL | pygmsh-4.4.0.tar.gz |
|---|---|
| Size | 32.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
46f2fe50f189565b7b468ce6775bcaf01bffaa71fd5247d0f14d15cc1aa0462f
|
|
BLAKE2b-256 checksum How to use checksums |
f45a2f1bb0ce59985e24cee76ef9f75f2cc26c0039a8e93295e3371fad078974
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2+
|
Release files / pygmsh-4.4.0-py2.py3-none-any.whl
| Download URL | pygmsh-4.4.0-py2.py3-none-any.whl |
|---|---|
| Size | 37.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
6ac000685e9154d3ccfba8bd1cd93e617a027c87678eaf3496b87edd37557b9f
|
|
BLAKE2b-256 checksum How to use checksums |
dbf6845ef88c7104154b55794ae0dfd60ca9d10d530e1863a7cbb991d333c8f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2+
|