Skip to main content

Python frontend for Gmsh

Project description

pygmsh

Gmsh for Python.

CircleCI codecov Code style: black Documentation Status PyPi Version PyPI pyversions DOI GitHub stars PyPi downloads Slack

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

pip install pygmsh

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.

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 Distribution

pygmsh-6.0.3.tar.gz (36.4 kB view details)

Uploaded Source

Built Distribution

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

pygmsh-6.0.3-py2.py3-none-any.whl (35.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pygmsh-6.0.3.tar.gz.

File metadata

  • Download URL: pygmsh-6.0.3.tar.gz
  • Upload date:
  • Size: 36.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.2rc1

File hashes

Hashes for pygmsh-6.0.3.tar.gz
Algorithm Hash digest
SHA256 8a985403bcd31dd87763b4e66db95964860d79e507ad01cb5c81a1209126a8de
MD5 060fe747e78964b6823344569f55ac23
BLAKE2b-256 58fc501bca3c440288de0055991d817dad0c2e5fb3c675e4d4b24b35da894ac2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygmsh-6.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 35.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.2rc1

File hashes

Hashes for pygmsh-6.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 67b821ce71a0ff361070ab55a767a702df031731df133133f5939c6af2ceae3f
MD5 59f8601edd567f72ae22bc08014464a4
BLAKE2b-256 4aa5053f337992f0ae2691e374916cd67ad0169d09ccbcdb5531de3866d1ccd6

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