Skip to main content

pypi MPL

pytetwild is a Python library for mesh tetrahedralization. It is a Python wrapper around the efficient C++ library for tetrahedral meshing provided by fTetWild.

Installation

We have pre-built wheels for Python 3.10 - Python 3.14 for Windows, Linux, and macOS.

The recommended way to install pytetwild is via PyPI:

pip install pytetwild[all]

This installs pyvista by default, which you can use to tetrahedralize sufrace meshes from PyVista. Alternatively you can just install with pip install pytetwild for a lighter install.

You can also clone the repository and install it from source, but since there’s C++ involved, the build is a bit more complicated. See CONTRIBUTING.md for more details.

Usage

To tetrahedralize a surface mesh from PyVista, you’ll need to first install pyvista as it’s not a dependency and then run:

import pyvista as pv
import pytetwild

# Load or create a PyVista PolyData surface mesh
# Here, we'll create a simple sphere mesh as an example
surface_mesh = pv.Icosphere(nsub=2)

# Convert the surface mesh to a tetrahedral mesh. For this example let's
# use a coarse mesh
tetrahedral_mesh = pytetwild.tetrahedralize_pv(surface_mesh, edge_length_fac=1)

# Visualize the tetrahedral mesh in an "exploded" view
tetrahedral_mesh.explode(0.5).plot(
    show_edges=True, zoom=1.6, ssao=True, anti_aliasing="ssaa"
)
https://github.com/pyvista/pytetwild/raw/main/exploded-sphere.png

You can also work with raw arrays. Here’s a simple cube that we turn into tetrahedra.

import numpy as np
import pytetwild

# Define vertices of the cube
vertices = np.array([
    [0, 0, 0],  # Vertex 0
    [1, 0, 0],  # Vertex 1
    [1, 1, 0],  # Vertex 2
    [0, 1, 0],  # Vertex 3
    [0, 0, 1],  # Vertex 4
    [1, 0, 1],  # Vertex 5
    [1, 1, 1],  # Vertex 6
    [0, 1, 1]   # Vertex 7
])

# Define faces using vertex indices
# Each face is a rectangle (also accepts triangles)
faces = np.array([
    [0, 1, 2, 3],  # Front face
    [1, 5, 6, 2],  # Right face
    [5, 4, 7, 6],  # Back face
    [4, 0, 3, 7],  # Left face
    [4, 5, 1, 0],  # Bottom face
    [3, 2, 6, 7]   # Top face
])
v_out, tetra = pytetwild.tetrahedralize(vertices, faces, optimize=False)

Usage - Sizing Field

To vary cell size across the mesh rather than using one edge length everywhere, pass a background tetrahedral mesh carrying the target edge length at each of its points. This is fTetWild’s --bg-mesh.

import numpy as np
import pyvista as pv
import pytetwild

# Background mesh covering the input, refined on one side
background = pv.ImageData(
    dimensions=(5, 5, 5), spacing=(0.3, 0.3, 0.3), origin=(-0.6, -0.6, -0.6)
).to_tetrahedra()
background.point_data["target"] = np.where(
    background.points[:, 0] < 0, 0.04, 0.2
)

mesh = pytetwild.tetrahedralize_pv(
    pv.Sphere(), sizing_field=background, sizing_field_scalars="target"
)

The value at any point is interpolated over the background tetrahedron containing it, and anywhere the background mesh does not cover falls back to the global ideal edge length. Note this is unrelated to disable_filtering, which keeps the internal background mesh fTetWild builds for itself.

Usage - Options

We’ve surfaced a several parameters to each of our interfaces tetrahedralize and tetrahedralize_pv:

Parameters
----------
edge_length_fac : float, default: 0.05
    Tetrahedral edge length as a function of bounding box diagonal. The
    default ideal edge length is ``bb/20`` (bounding box divided by
    20). Ignored when ``edge_length_abs`` is input.
edge_length_abs : float, optional
    Absolute ideal edge length. When input ``edge_length_fac`` is ignored.
optimize : bool, default: True
    Improve the minimum scaled Jacobean for each cell. This leads to higher
    cell quality at the expense of computation time. Optimization level is
    dependent on ``stop_energy`` and ``num_opt_iter``.
simplify : bool, default: True
    Simplfiy the input mesh surface before tetrahedralization.
epsilon : float, default 1e-3
    Envelop size, specifying the maximum distance of the output surface
    from the input surface, relative to the bounding box size.
stop_energy : float, default: 10.0
    The mesh optimization stops when the conformal AMIPS energy reaches
    ``stop_energy``.
coarsen : bool, default: False
    Coarsen the output as much as possible, while maintaining the mesh
    quality.
num_threads : int, default: 0
    Set number of threads used. 0 (default) uses all available cores.
num_opt_iter : int, default: 80
    Maximum number of optimization iterations if ``optimize=True``.
loglevel : int, default: 6
    Set log level (0 = most verbose, 6 = minimal output).
quiet : bool, default: False
    Disable all output. Overrides ``loglevel``.
sizing_field : pv.UnstructuredGrid, optional
    ``tetrahedralize_pv`` only. All-tetrahedral mesh supplying a
    spatially varying target edge length. Requires ``optimize=True``.
sizing_field_scalars : str, optional
    ``tetrahedralize_pv`` only. Name of the point array on
    ``sizing_field`` holding the target edge length. Defaults to its
    active point scalars.
bg_vertices, bg_tets, bg_values : np.ndarray, optional
    ``tetrahedralize`` only. The same sizing field as raw arrays:
    points ``(n, 3)``, tetrahedra ``(m, 4)``, and the target edge
    length at each point ``(n,)``.

License and Acknowledgments

This project relies on fTetWild and credit goes to the original authors for their efficient C++ library for tetrahedral meshing. That work is licensed under the Mozilla Public License v2.0.

The work in this repository is also licensed under the Mozilla Public License v2.0.

Support

If you are having issues, please feel free to raise an Issue.

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pytetwild-0.4.0-cp312-abi3-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.12+Windows x86-64

pytetwild-0.4.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ x86-64

pytetwild-0.4.0-cp312-abi3-macosx_15_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.12+macOS 15.0+ ARM64

pytetwild-0.4.0-cp311-cp311-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.11Windows x86-64

pytetwild-0.4.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pytetwild-0.4.0-cp311-cp311-macosx_15_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

pytetwild-0.4.0-cp310-cp310-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.10Windows x86-64

pytetwild-0.4.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pytetwild-0.4.0-cp310-cp310-macosx_15_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

Details for the file pytetwild-0.4.0-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: pytetwild-0.4.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pytetwild-0.4.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 30f9179ef88d819acedb988069e7bb3979bbc70f1358a3087939434fd921087d
MD5 5762a9d8820ae10ac2c437512855acc9
BLAKE2b-256 c95fb4f5b149aa23e6c57b81861307162acdc7cab979bf810a4d09efa72df8b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.0-cp312-abi3-win_amd64.whl:

Publisher: build-and-deploy.yml on pyvista/pytetwild

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytetwild-0.4.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for pytetwild-0.4.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 3176785fb23cfaea300ce303da82ca144f9e9008f6a5742de8f41b89cf0c5c41
MD5 8136f9e9854180601ca09041689374a7
BLAKE2b-256 5cef68b088dc326f20b07db86f73b4a6e42e053c6e8fdbc6ab6f7c2c13b48cc8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl:

Publisher: build-and-deploy.yml on pyvista/pytetwild

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytetwild-0.4.0-cp312-abi3-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pytetwild-0.4.0-cp312-abi3-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 539dbb4fc54240db43323773645938f465beea83c77a72da5a87a18069b49e78
MD5 42544419bb1fe27856eabe0c84facddd
BLAKE2b-256 f972f891ebc03ad7bc5861d44970fba5ced631dc3d4af3dfbdd16af478f6296a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.0-cp312-abi3-macosx_15_0_arm64.whl:

Publisher: build-and-deploy.yml on pyvista/pytetwild

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytetwild-0.4.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pytetwild-0.4.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pytetwild-0.4.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 18241d34145d8e76b4c97ba7f382c41fb92a8e7ae4db9e25d7a0d7f5ed2107ed
MD5 8a5c0bd14d56a5a7ae9719a81608a1e2
BLAKE2b-256 1b4639deaf822ea96cd91726bd30c92a3af7cd7230473d1ea440f10ec0c0eb21

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.0-cp311-cp311-win_amd64.whl:

Publisher: build-and-deploy.yml on pyvista/pytetwild

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytetwild-0.4.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for pytetwild-0.4.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 f444ca469dd648fc0cd2a9eb7d8060de1d7c4fe61d98117e7e48ff30341e7445
MD5 a67beeb1c4f673edb560d2ade1aa4de0
BLAKE2b-256 4744d0dbe37318cfa833f325c792c94035140274ae6728ff5f229de12dbf7391

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl:

Publisher: build-and-deploy.yml on pyvista/pytetwild

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytetwild-0.4.0-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pytetwild-0.4.0-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 2a006cfedfe343bfb9408e2ff731e49b46fc65954be30a6a9288791c8184eba1
MD5 5cbe04851a498a74da95be6c78a6b382
BLAKE2b-256 3e939360f618333ec763274fa494b44ba301be7be607ce42eabec67c812aa498

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.0-cp311-cp311-macosx_15_0_arm64.whl:

Publisher: build-and-deploy.yml on pyvista/pytetwild

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytetwild-0.4.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pytetwild-0.4.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pytetwild-0.4.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 10a66f46cd20287a54698d65d5ce019454380ee9874cb5b5e0271d6d210af483
MD5 89fb74c08fa3a4366f5d46963c4266ef
BLAKE2b-256 1df638455473cf541781e5fb8788ba0e1f5eb4df341bf542a175c3ad9b056324

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.0-cp310-cp310-win_amd64.whl:

Publisher: build-and-deploy.yml on pyvista/pytetwild

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytetwild-0.4.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for pytetwild-0.4.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 ee023fdf8b8500cef0573825c8e1bf9d61bff0156effc3cd25bd30b4527242ad
MD5 30e99f9ab73252a468ec73031aebc095
BLAKE2b-256 5613fd0c602e719a5a3ee03da003f7ba4a634838dec03127902b5502bb3ecf20

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl:

Publisher: build-and-deploy.yml on pyvista/pytetwild

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytetwild-0.4.0-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pytetwild-0.4.0-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 1d1a93424538ab703c2a3febbee2c1b122c4c885f236a760f4b9a5847bfe535f
MD5 a06b66c0cb228b238ed73e89b32eab45
BLAKE2b-256 a7550e48a68b0b2d8c69faa559167d26b448a41ad4da36e7270cb1b849de95c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.0-cp310-cp310-macosx_15_0_arm64.whl:

Publisher: build-and-deploy.yml on pyvista/pytetwild

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page