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 Distribution

pytetwild-0.4.1.tar.gz (2.6 MB view details)

Uploaded Source

Built Distributions

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

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

Uploaded CPython 3.12+Windows x86-64

pytetwild-0.4.1-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.1-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (2.8 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.12+macOS 15.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

pytetwild-0.4.1-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.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (2.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.11macOS 15.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

pytetwild-0.4.1-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.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (2.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

pytetwild-0.4.1-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.1.tar.gz.

File metadata

  • Download URL: pytetwild-0.4.1.tar.gz
  • Upload date:
  • Size: 2.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pytetwild-0.4.1.tar.gz
Algorithm Hash digest
SHA256 4572aa422c5e53216f798737540ab9d2af8e41b49cb59b45753eadd74555d16b
MD5 a1134f3d54032c8281892a6944c0afdc
BLAKE2b-256 299d8a71d197902c91225a355321e44ebc5992667eab3e4964933941942a6e27

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.1.tar.gz:

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.1-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: pytetwild-0.4.1-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.1-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f83a35afcef67866a2f51080c31a5f2695af50e26ec165d39a4f5348535d8c67
MD5 e95e1127402e428a92cbdfc55863b809
BLAKE2b-256 94cb8d40fe37a0e819d45258bbcb8e4f2aebad1ac850c20649b5e26e6f103a81

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.1-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.1-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for pytetwild-0.4.1-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 c00d02e149e104ff3ea32f09a9dc4d561866019ba0b3d4d173fd9a4a397012f1
MD5 5d6c50e2610b3d29879fa8b1db9ea989
BLAKE2b-256 8036fe4205caf9c10ff97ceda3cc9822c289aacb96bc6cb60969f74890f4fbcf

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.1-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.1-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for pytetwild-0.4.1-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 9b12ff95fec161dc1b638fe7371220bf2076474d9f4f458327967eecefb12e45
MD5 3008aa86c39c62fb86542fd3afb3a06c
BLAKE2b-256 f9492b51551617adb798b985461de2e8c292b6833ca06cfd8efefa731d0907ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.1-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.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.1-cp312-abi3-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pytetwild-0.4.1-cp312-abi3-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 21046797271727138f49e6581de5081ec261c3870ecceadf0aac9332557bc9ed
MD5 b9ff7dc120a6f7fe05348da4a147e3c2
BLAKE2b-256 6a8195fccd3f9f9428a7f7f4bc70bf79d0bd533bd2d6a96bb38fdd5eba84a147

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.1-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.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pytetwild-0.4.1-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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 957b724e6e270447ba6c06be01966cbf963452078f8e87ac28199b83e90ba656
MD5 4666cb6a265573b33e61f44cac6c4cf2
BLAKE2b-256 2dd4d2ea195d26f17bc3b3a2106ee0e058c5ec821dd62592960c2456310ce84e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.1-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.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for pytetwild-0.4.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 6fb553d5f3516cf65dd074b27e52a2ac43146dfb64a6fed0bd017492121f133e
MD5 56567aaaca931030a4a9c61512f4651b
BLAKE2b-256 691d6b191ecbfb6783fe89ac102f023d3b9fed6ecf5ae580b1e7d148acf40de2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.1-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.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for pytetwild-0.4.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 f3b612003f1d43dbe60a85f454f29040e6d37e801cc082b026aec0fd30e2aac8
MD5 2310a13840a7a3f3a7455b2215c2eebe
BLAKE2b-256 2d0f265ca8d070041a4c6d10140ddb52b2c77c73e06ed8950f9121dbf7cec825

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.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.1-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pytetwild-0.4.1-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 4f1ca8a47475e31033f16a6efcb9ac0095e37a8596925c04c1954f78de23c14b
MD5 cd914fc249c56be2ac7bfcffb6c28b54
BLAKE2b-256 81292d154c2eaa1a6a5bcc1354e629beadc115f5081bee5672d6682dac95a2c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.1-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.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pytetwild-0.4.1-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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1b857bc29d4863761fdaf9726d90666df2327cc77d2724c2d1ca8a9a534f24fe
MD5 4fea967f89e79316a87ffa6ec905456a
BLAKE2b-256 869a31bfea505dc169e389770d129d82e1dd146fbd4caedddde0f18eec3a27d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.1-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.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for pytetwild-0.4.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 9d53c1a650f21d2163441e5d5727cfb42a85fefa9ba6cdcf11103ec374b87eb1
MD5 67656af38c261d3234229997e69d3e89
BLAKE2b-256 6eb7c9327821216ad3be71ca403e4a05da840c4dec72be8f4517990a1b8514a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.1-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.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for pytetwild-0.4.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 91797ce7b93a96027947a4a84d2a4a5a0ad96f3854ef4121511528349c0ab29c
MD5 aa9d38355167e3a5d8a05b88cf5b7af1
BLAKE2b-256 a6820b39dbeedc9fc15202f9b9cdcf127d635ca926dcb1e997a5d5f92116b257

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.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.1-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pytetwild-0.4.1-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 0009083dad4b217a40d0190ded4c9fa8b0d15249fa66471c61157c921f9447fb
MD5 8a3d0d0ec27cd6a52ba97d6eea8044e0
BLAKE2b-256 79a62ce0e14a32d08cbd026ba45285391c122ff08503cd08a01175624d423a7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytetwild-0.4.1-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