Python interface to tetgen

Project description

This Python module is an interface to Hang Si’s TetGen C++ software. This module combines speed of C++ with the portability and ease of installation of Python along with integration to PyVista for 3D visualization and analysis. See the TetGen GitHub page for more details on the original creator.

This python module uses the C++ source from TetGen (version 1.5.1, released on August 18, 2018) hosted at ufz/TetGen.

Brief description from Weierstrass Institute Software:

TetGen is a program to generate tetrahedral meshes of any 3D polyhedral domains. TetGen generates exact constrained Delaunay tetrahedralization, boundary conforming Delaunay meshes, and Voronoi partitions.

TetGen provides various features to generate good quality and adaptive tetrahedral meshes suitable for numerical methods, such as finite element or finite volume methods. For more information of TetGen, please take a look at a list of features.

Installation

From PyPI

```pip install tetgen
```

From source at GitHub

```git clone https://github.com/pyvista/tetgen
cd tetgen
pip install .
```

Basic Example

The features of the C++ TetGen software implemented in this module are primarily focused on the tetrahedralization a manifold triangular surface. This basic example demonstrates how to tetrahedralize a manifold surface and plot part of the mesh.

```import pyvista as pv
import tetgen
import numpy as np
pv.set_plot_theme('document')

sphere = pv.Sphere()
tet = tetgen.TetGen(sphere)
tet.tetrahedralize(order=1, mindihedral=20, minratio=1.5)
grid = tet.grid
grid.plot(show_edges=True)
```

Tetrahedralized Sphere

Extract a portion of the sphere’s tetrahedral mesh below the xy plane and plot the mesh quality.

```# get cell centroids
cells = grid.cells.reshape(-1, 5)[:, 1:]
cell_center = grid.points[cells].mean(1)

# extract cells below the 0 xy plane
mask = cell_center[:, 2] < 0
subgrid = grid.extract_cells(cell_ind)

plotter = pv.Plotter()
[' Tesselated Mesh ', 'black']])
plotter.show()
```

Cell quality scalars can be obtained and plotted using pyansys:

```import pyansys
cell_qual = subgrid.quality

# plot quality
subgrid.plot(scalars=cell_qual, stitle='Quality', cmap='bwr', clim=[0,1],
flip_scalars=True, show_edges=True,)
```

Acknowledgments

Software was originally created by Hang Si based on work published in TetGen, a Delaunay-Based Quality Tetrahedral Mesh Generator.

Project details

Files for tetgen, version 0.5.0
Filename, size File type Python version Upload date Hashes
Filename, size tetgen-0.5.0-cp35-cp35m-manylinux1_x86_64.whl (1.8 MB) File type Wheel Python version cp35 Upload date Hashes
Filename, size tetgen-0.5.0-cp35-cp35m-win_amd64.whl (291.2 kB) File type Wheel Python version cp35 Upload date Hashes
Filename, size tetgen-0.5.0-cp36-cp36m-macosx_10_9_x86_64.whl (425.8 kB) File type Wheel Python version cp36 Upload date Hashes
Filename, size tetgen-0.5.0-cp36-cp36m-manylinux1_x86_64.whl (1.8 MB) File type Wheel Python version cp36 Upload date Hashes
Filename, size tetgen-0.5.0-cp36-cp36m-win_amd64.whl (293.0 kB) File type Wheel Python version cp36 Upload date Hashes
Filename, size tetgen-0.5.0-cp37-cp37m-macosx_10_9_x86_64.whl (422.7 kB) File type Wheel Python version cp37 Upload date Hashes
Filename, size tetgen-0.5.0-cp37-cp37m-manylinux1_x86_64.whl (1.8 MB) File type Wheel Python version cp37 Upload date Hashes
Filename, size tetgen-0.5.0-cp37-cp37m-win_amd64.whl (293.1 kB) File type Wheel Python version cp37 Upload date Hashes
Filename, size tetgen-0.5.0-cp38-cp38-manylinux1_x86_64.whl (1.8 MB) File type Wheel Python version cp38 Upload date Hashes
Filename, size tetgen-0.5.0-cp38-cp38-win_amd64.whl (294.5 kB) File type Wheel Python version cp38 Upload date Hashes