Skip to main content

Python frontend for Gmsh

Project description

Build Status Code Health 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 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(
    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 = pg.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/examples/ along with other small examples.

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/examples/ <https://github.com/nschloe/pygmsh/tree/master/test/examples>`__ 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 Distribution

pygmsh-3.0.8.tar.gz (12.0 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: pygmsh-3.0.8.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pygmsh-3.0.8.tar.gz
Algorithm Hash digest
SHA256 96dc86afc492258d8adaf4955c92f2374ca69ee310e1f32273ded9bc14bea07a
MD5 169cfc5d812590eed081b1020260eab4
BLAKE2b-256 38e8daf3598c1f51de482b3e3c6e36f1a9f634f6fbbc614316ae7f4b7c3cdad2

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