Python frontend for Gmsh
Project description
pygmsh
======
|CircleCI| |codecov| |Documentation Status| |PyPi Version| |GitHub
stars|
.. raw:: html
<p align="center">
.. raw:: html
</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.
Built-in
^^^^^^^^
.. figure:: https://nschloe.github.io/pygmsh/screw.png
:alt:
To create the above mesh, simply do
.. code:: python
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.python.org/pypi/meshio>`__; for example
.. code:: python
import meshio
meshio.write('test.vtu', 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
^^^^^^^^^^^
.. figure:: https://nschloe.github.io/pygmsh/puzzle.png
:alt:
As of version 3.0, Gmsh supports OpenCASCADE, allowing for a CAD-style
geometry specification.
Example:
.. code:: python
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.python.org/pypi/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>`__.
.. |CircleCI| image:: https://img.shields.io/circleci/project/github/nschloe/pygmsh/master.svg
:target: https://circleci.com/gh/nschloe/pygmsh
.. |codecov| image:: https://codecov.io/gh/nschloe/pygmsh/branch/master/graph/badge.svg
:target: https://codecov.io/gh/nschloe/pygmsh
.. |Documentation Status| image:: https://readthedocs.org/projects/pygmsh/badge/?version=latest
:target: https://pygmsh.readthedocs.org/en/latest/?badge=latest
.. |PyPi Version| image:: https://img.shields.io/pypi/v/pygmsh.svg
:target: https://pypi.python.org/pypi/pygmsh
.. |GitHub stars| image:: https://img.shields.io/github/stars/nschloe/pygmsh.svg?style=social&label=Stars&maxAge=2592000
:target: https://github.com/nschloe/pygmsh
======
|CircleCI| |codecov| |Documentation Status| |PyPi Version| |GitHub
stars|
.. raw:: html
<p align="center">
.. raw:: html
</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.
Built-in
^^^^^^^^
.. figure:: https://nschloe.github.io/pygmsh/screw.png
:alt:
To create the above mesh, simply do
.. code:: python
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.python.org/pypi/meshio>`__; for example
.. code:: python
import meshio
meshio.write('test.vtu', 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
^^^^^^^^^^^
.. figure:: https://nschloe.github.io/pygmsh/puzzle.png
:alt:
As of version 3.0, Gmsh supports OpenCASCADE, allowing for a CAD-style
geometry specification.
Example:
.. code:: python
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.python.org/pypi/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>`__.
.. |CircleCI| image:: https://img.shields.io/circleci/project/github/nschloe/pygmsh/master.svg
:target: https://circleci.com/gh/nschloe/pygmsh
.. |codecov| image:: https://codecov.io/gh/nschloe/pygmsh/branch/master/graph/badge.svg
:target: https://codecov.io/gh/nschloe/pygmsh
.. |Documentation Status| image:: https://readthedocs.org/projects/pygmsh/badge/?version=latest
:target: https://pygmsh.readthedocs.org/en/latest/?badge=latest
.. |PyPi Version| image:: https://img.shields.io/pypi/v/pygmsh.svg
:target: https://pypi.python.org/pypi/pygmsh
.. |GitHub stars| image:: https://img.shields.io/github/stars/nschloe/pygmsh.svg?style=social&label=Stars&maxAge=2592000
:target: https://github.com/nschloe/pygmsh
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
pygmsh-4.0.5-py2.py3-none-any.whl
(30.3 kB
view hashes)
Close
Hashes for pygmsh-4.0.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5a09ca986e8a16f46725c7f75db7dac09aed9f74b37ec59363e37d0eb5f928a |
|
MD5 | acf9fc5609de2aee0243cd88b601c8b6 |
|
BLAKE2b-256 | c71d9e5f1fcd0df00bface0debb0bdb4de1caae4bc53f3bf7dc6db1c387e2ef7 |