Skip to content
A Python interface to the C++ TetGen library to generate tetrahedral meshes of any 3D polyhedral domains
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Add docs menu links May 24, 2019
examples Change cow animation May 24, 2019
tests fixed switches string bug May 21, 2019
tetgen
.appveyor.yml appveyor build fix May 21, 2019
.gitignore Add documentation for tetgen with example gallery May 21, 2019
.travis.yml
LICENSE added mac build to travis May 21, 2019
MANIFEST.in added scripts and changed name Jun 20, 2018
README.rst
github_deploy_key_pyvista_tetgen.enc Deploy docs to GitHub Pages May 22, 2019
pytest.ini updating for vtki==0.16.1 Jan 31, 2019
requirements.txt Use master branch of PyVista May 22, 2019
setup.py Resolve links to PyVista org account May 22, 2019

README.rst

tetgen

https://travis-ci.org/pyvista/tetgen.svg?branch=master https://img.shields.io/pypi/v/tetgen.svg?logo=python&logoColor=white

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.

The last update to the original C++ software was on 19 January 2011, but the software remains relevant today. 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

sphere = pv.Sphere()
tet = tetgen.TetGen(sphere)
tet.tetrahedralize(order=1, mindihedral=20, minratio=1.5)
grid = tet.grid
grid.plot()
https://github.com/pyvista/tetgen/raw/master/docs/images/sphere.png

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
cell_ind = mask.nonzero()[0]
subgrid = grid.extract_cells(cell_ind)

# advanced plotting
plotter = pv.Plotter()
plotter.set_background('w')
plotter.add_mesh(subgrid, 'lightgrey', lighting=True)
plotter.add_mesh(sphere, 'r', 'wireframe')
plotter.add_legend([[' Input Mesh ', 'r'],
                    [' Tesselated Mesh ', 'black']])
plotter.plot()

https://github.com/pyvista/tetgen/raw/master/docs/images/sphere_subgrid.png

Cell quality scalars can be obtained and plotted with:

cell_qual = subgrid.quality

# plot quality
subgrid.plot(scalars=cell_qual, stitle='quality', cmap='bwr', flip_scalars=True)

https://github.com/pyvista/tetgen/raw/master/docs/images/sphere_qual.png

Acknowledgments

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

You can’t perform that action at this time.