Skip to main content

Python interface to pytetgen

Project description

https://travis-ci.org/akaszynski/tetgen.svg?branch=master

This python module is a python interface to Hang Si’s tetgen C++ software. This module combines speed of C++ with the portability and ease of installation of Python along integration with the visualization toolkit VTK . See the tetgen GitHub page for more details on the 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 --user

From source at GitHub

git clone https://github.com/akaszynski/tetgen
cd tetgen
pip install . --user

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 vtki
import tetgen
import numpy as np

sphere = vtki.Sphere()
tet = tetgen.TetGen(sphere)
tet.tetrahedralize(order=1, mindihedral=20, minratio=1.5)
grid = tet.grid
grid.plot()
https://github.com/akaszynski/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 = vtki.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/akaszynski/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/akaszynski/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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tetgen-0.2.1.tar.gz (275.7 kB view hashes)

Uploaded Source

Built Distributions

tetgen-0.2.1-cp37-cp37m-win_amd64.whl (284.7 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

tetgen-0.2.1-cp37-cp37m-manylinux1_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.7m

tetgen-0.2.1-cp36-cp36m-win_amd64.whl (284.7 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

tetgen-0.2.1-cp36-cp36m-manylinux1_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.6m

tetgen-0.2.1-cp35-cp35m-win_amd64.whl (282.7 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

tetgen-0.2.1-cp35-cp35m-manylinux1_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.5m

tetgen-0.2.1-cp27-cp27mu-manylinux1_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 2.7mu

tetgen-0.2.1-cp27-cp27m-manylinux1_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 2.7m

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page