Skip to main content

Python frontend for Gmsh

Project description

Build Status Code Health Coverage Status Documentation Status PyPi Version PyPi Downloads

Gmsh is powerful mesh generation tool and its scripting language is notoriously hard to write.

The goal 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 even 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(
    'Surface{%s}' % poly,
    translation_axis=axis,
    rotation_axis=axis,
    point_on_axis=[0, 0, 0],
    angle=2.0 / 6.0 * np.pi
    )

print(geom.get_code())

and write the output to a file, e.g., screw.geo. Then use Gmsh to generate the mesh screw.msh,

gmsh -3 screw.geo

You will find this case in the directory test/examples/ along with other small examples.

To convert from Gmsh’s mesh format to other, more common formats (VTK, VTU, Exodus), you can use MeshIO’s meshio-convert. Converting is as easy as

meshio-convert screw.msh screw.vtu

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

Installation

Python Package Index

PyGmsh is available from the Python Package Index, so simply type

pip install pygmsh

to install or

pip install pygmsh -U

to upgrade.

Manual installation

Download PyGmsh from PyPi or GitHub and install it with

python setup.py install

Requirements

PyGmsh depends on

and, obviously, Gmsh.

Usage

Just

import pygmsh as pg

and make use of all the goodies the module provides. The documentation and the examples under test/examples/ might inspire you.

Testing

To run the PyGmsh unit tests, check out this repository and type

nosetests

or

nose2 -s test

Distribution

To create a new release

  1. bump the __version__ number,

  2. create a Git tag,

    git tag -a v0.3.1
    git push --tags

    and

  3. upload to PyPi:

    make upload

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-2.1.0.tar.gz (8.1 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for pygmsh-2.1.0.tar.gz
Algorithm Hash digest
SHA256 988735135a71e1fcd48b57093f4f3c5092b2d672cb01c036e50925f7d282f371
MD5 e111de396b196f7fd3274b638007b9d2
BLAKE2b-256 4fc2ca47f8db5af895c84f43950e5a3349cb9a435219a14785d3aab358bf7d10

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