Skip to main content

pygmsh

CircleCI codecov Codacy grade Documentation Status PyPi Version DOI 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.

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
    )

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

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.

Metadata

Release files for pygmsh 4.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pygmsh 4.1.4
File Size Uploaded Provenance Actions
pygmsh-4.1.4.tar.gz 26.0 kB Without provenance Details for pygmsh-4.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pygmsh 4.1.4
File Interpreter ABI Platform Actions
pygmsh-4.1.4-py2.py3-none-any.whl Python 2, Python 3 none any Details for pygmsh-4.1.4-py2.py3-none-any.whl

Total release size: 57.5 kB

Release files / pygmsh-4.1.4.tar.gz

Download URL pygmsh-4.1.4.tar.gz
Size 26.0 kB
Tags Source
SHA-256 checksum
How to use checksums
44d33b6188166b8d949dbbb2560e851aa9353cd1a08e5fec14ca8c30a1a7afac
BLAKE2b-256 checksum
How to use checksums
b2e415fe5e255055413a04ed403c1636f2bad4d6af016a66531267251184dcb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pygmsh-4.1.4-py2.py3-none-any.whl

Download URL pygmsh-4.1.4-py2.py3-none-any.whl
Size 31.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
26327c5977230f65dab9a56455cae97e7778b86e0347c780d49850021133318d
BLAKE2b-256 checksum
How to use checksums
4327c448a732e03b21585cf8e84f438f8cebb023b5997ff5073500c16b4e3ad2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pygmsh 4.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

4.1.4 This release

2 release files No provenance

0.1.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page