Gmsh is powerful mesh generation tool and its scripting language is notoriously hard to write.
The goal 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 even more easily.
To create the above mesh, simply do
import pygmsh as pg
import numpy as np
geom = pg.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(
'Surface{%s}' % poly,
translation_axis=axis,
rotation_axis=axis,
point_on_axis=[0, 0, 0],
angle=2.0 / 6.0 * np.pi
)
print(geom.get_code())
and write the output to a file, e.g., screw.geo
. Then use Gmsh to generate
the mesh screw.msh
,
gmsh -3 screw.geo
You will find this case in the directory test/examples/
along with other
small examples.
To convert from Gmsh's mesh format to other, more common formats (VTK, VTU,
Exodus), you can use MeshIO's
meshio-convert
. Converting is as easy as
meshio-convert screw.msh screw.vtu
The output file can be visualized with various tools, e.g., ParaView.
PyGmsh is available from the Python Package Index, so simply type
pip install pygmsh
to install or
pip install pygmsh -U
to upgrade.
Download PyGmsh from PyPi or GitHub and install it with
python setup.py install
PyGmsh depends on
and, obviously, Gmsh.
Just
import pygmsh as pg
and make use of all the goodies the module provides. The
documentation and the examples under
test/examples/
might inspire you.
To run the PyGmsh unit tests, check out this repository and type
nosetests
or
nose2 -s test
To create a new release
-
bump the
__version__
number, -
create a Git tag,
git tag -a v0.3.1 git push --tags
and
-
upload to PyPi:
make upload
PyGmsh is published under the MIT license.