Skip to content

pyvista/scikit-gmsh

Scikit for Gmsh to generate 3D finite element mesh.

All Contributors Contributing Documentation Status GitHub Repo stars License: GPL v3

The scikit-gmsh package provides a simple interface to the gmsh library. The library has following main objectives:

  1. Provide an intuitive, object-oriented API for mesh creation like scipy.spatial.Delaunay class.
  2. Integrate seamlessly with other libraries in the Scientific Python ecosystem.

Contributions are very welcome . This project is released with a Contributor Code of Conduct. By participating in this project, We want you to know that you agree to follow its terms.

Enjoying scikit-gmsh? Show your support with a GitHub star — it’s a simple click that means the world to us and helps others discover it, too! ⭐️

Installation

pypi

pip install scikit-gmsh

Usage

import skgmsh as sg

Now, let's define geometry.

shell = [(0, 0, 0), (0, 10, 0), (10, 10, 0), (10, 0, 0), (0, 0, 0)]
holes = [[(2, 2, 0), (2, 4, 0), (4, 4, 0), (4, 2, 0), (2, 2, 0)]]

We can then generate a 2D mesh.

alg = sg.Delaunay2D(shell=shell, holes=holes)
mesh = alg.mesh

To visualize the model, we can use PyVista.

mesh.plot(show_edges=True, cpos="xy")

If you want to set the cell size, you can do so.

alg.cell_size = 0.5
alg.mesh.plot(show_edges=True, cpos="xy")

We can also generate a 3D mesh.

source = pv.Cube()
delaunay_3d = sg.Delaunay3D(edge_source=source, target_sizes=0.2)
plotter = pv.Plotter()
_ = plotter.add_mesh(
    delaunay_3d.mesh,
    show_edges=True,
    line_width=1,
    color="aliceblue",
    lighting=False,
    edge_color="gray",
)
_ = plotter.add_mesh(edge_source.extract_all_edges(), line_width=4, color="gray")
_ = plotter.add_box_axes()
plotter.show()

We can clip a mesh by a plane by specifying the origin and normal. See clip_with_surface_example for more examples using this filter.

clipped = delaunay_3d.mesh.clip(
    origin=(0.0, 0.0, 0.0), normal=(0.0, 0.0, 1.0), crinkle=True
)

License

License: GPL v3

This software is published under the GPLv3 license.

Star History

Star History Chart