Skip to main content

Python frontend for Gmsh

Project description

Build Status codecov Documentation Status PyPi Version GitHub stars

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.

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
    )

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; for example

import meshio
meshio.write('test.vtu', points, cells, cell_data=cell_data)

The output file can be visualized with various tools, e.g., ParaView.

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:

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, 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 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

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.

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

If you're not sure about the file name format, learn more about wheel file names.

pygmsh-4.0.0-py2.py3-none-any.whl (45.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pygmsh-4.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pygmsh-4.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8fd6b5a87c8457e6807a39d8272ed4a477abc169b19271fc6bec9169b525a4e4
MD5 bacc9beb57210f221225a419e0b301b3
BLAKE2b-256 9d6d911c98f1ed8760129e818fa14d1707e3b0d22b3c0deb43a77d8018f1c43b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page