Gmsh for Python.
Gmsh 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 for the full documentation.
Built-in
To create the above mesh, simply do
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
)
mesh = pygmsh.generate_mesh(geom)
# mesh.points, mesh.cells, ...
to retrieve all points and cells of the mesh for the specified geometry. To store the mesh, you can use meshio; for example
import meshio
meshio.write("test.vtk", mesh)
The output file can be visualized with various tools, e.g., ParaView.
You will find the above mesh in the directory
test/ along with other small
examples.
OpenCASCADE
As of version 3.0, Gmsh supports OpenCASCADE, allowing for a CAD-style geometry specification.
Example:
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])
mesh = pygmsh.generate_mesh(geom)
Installation
pygmsh is available from the Python Package Index, so simply type
pip3 install pygmsh --user
to install. Also make sure to have gmsh installed.
Usage
Just
import pygmsh as pg
and make use of all the goodies the module provides. The
documentation and the examples under
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.
To build run
sphinx-build -b html doc doc/_build
License
pygmsh is published under the MIT license.
Metadata
Release files for pygmsh 6.0.2
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-6.0.2.tar.gz | 33.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pygmsh-6.0.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 68.3 kB
Release files / pygmsh-6.0.2.tar.gz
| Download URL | pygmsh-6.0.2.tar.gz |
|---|---|
| Size | 33.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9ecd79b59de34aafbf75d2643b96ef22bdb6d9a49415223ba403a1022bbfa223
|
|
BLAKE2b-256 checksum How to use checksums |
7536f249b39d6c29fbde1325f78a23c63e15000ad1e076cbd2a3aece52aa036b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4
|
Release files / pygmsh-6.0.2-py2.py3-none-any.whl
| Download URL | pygmsh-6.0.2-py2.py3-none-any.whl |
|---|---|
| Size | 34.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
2ec6b81d82e8b2c64da6293f9c2703510ac673a9360b855eee0a158cd1efe1e8
|
|
BLAKE2b-256 checksum How to use checksums |
5da83e9c5a9e40b3dcdfb251c866e2c7a5a0b34aac62578acaa399c572fa9be5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4
|