Skip to main content

optimesh

Triangular mesh optimization.

PyPi Version PyPI pyversions DOI GitHub stars PyPi downloads

Discord

Several mesh smoothing/optimization methods with one simple interface. optimesh

  • is fast,
  • preserves submeshes,
  • only works for triangular meshes, flat and on a surface, (for now; upvote this issue if you're interested in tetrahedral mesh smoothing), and
  • supports all mesh formats that meshio can handle.

Installation

Install optimesh from PyPI with

pip install optimesh

How to get a license

Licenses for personal and academic use can be purchased here. You'll receive a confirmation email with a license key. Install the key with

slim install <your-license-key>

on your machine and you're good to go.

For commercial use, please contact support@mondaytech.com.

Using optimesh

Example call:

optimesh in.e out.vtk

Output: terminal-screenshot

The left hand-side graph shows the distribution of angles (the grid line is at the optimal 60 degrees). The right hand-side graph shows the distribution of simplex quality, where quality is twice the ratio of circumcircle and incircle radius.

All command-line options are documented at

optimesh -h

Showcase

disk-step0

The following examples show the various algorithms at work, all starting from the same randomly generated disk mesh above. The cell coloring indicates quality; dark green is bad, yellow is good.

CVT (centroidal Voronoi tessellation)

cvt-uniform-lloyd2 cvt-uniform-qnb cvt-uniform-qnf
uniform-density relaxed Lloyd's algorithm (--method lloyd --omega 2.0) uniform-density quasi-Newton iteration (block-diagonal Hessian, --method cvt-block-diagonal) uniform-density quasi-Newton iteration (default method, full Hessian, --method cvt-full)

Centroidal Voronoi tessellation smoothing (Du et al.) is one of the oldest and most reliable approaches. optimesh provides classical Lloyd smoothing as well as several variants that result in better meshes.

CPT (centroidal patch tessellation)

cpt-cp cpt-uniform-fp cpt-uniform-qn
density-preserving linear solve (Laplacian smoothing, --method cpt-linear-solve) uniform-density fixed-point iteration (--method cpt-fixed-point) uniform-density quasi-Newton (--method cpt-quasi-newton)

A smoothing method suggested by Chen and Holst, mimicking CVT but much more easily implemented. The density-preserving variant leads to the exact same equation system as Laplacian smoothing, so CPT smoothing can be thought of as a generalization.

The uniform-density variants are implemented classically as a fixed-point iteration and as a quasi-Newton method. The latter typically converges faster.

ODT (optimal Delaunay tessellation)

odt-dp-fp odt-uniform-fp odt-uniform-bfgs
density-preserving fixed-point iteration (--method odt-dp-fp) uniform-density fixed-point iteration (--method odt-fixed-point) uniform-density BFGS (--method odt-bfgs)

Optimal Delaunay Triangulation (ODT) as suggested by Chen and Holst. Typically superior to CPT, but also more expensive to compute.

Implemented once classically as a fixed-point iteration, once as a nonlinear optimization method. The latter typically leads to better results.

Using optimesh from Python

You can also use optimesh in a Python program. Try

import optimesh

# [...] create points, cells [...]

points, cells = optimesh.optimize_points_cells(
    points, cells, "CVT (block-diagonal)", 1.0e-5, 100
)

# or create a meshplex Mesh
import meshplex

mesh = meshplex.MeshTri(points, cells)
optimesh.optimize(mesh, "CVT (block-diagonal)", 1.0e-5, 100)
# mesh.points, mesh.cells, ...

If you only want to do one optimization step, do

points = optimesh.get_new_points(mesh, "CVT (block-diagonal)")

Surface mesh smoothing

optimesh also supports optimization of triangular meshes on surfaces which are defined implicitly by a level set function (e.g., spheres). You'll need to specify the function and its gradient, so you'll have to do it in Python:

import meshzoo
import optimesh

points, cells = meshzoo.tetra_sphere(20)


class Sphere:
    def f(self, x):
        return 1.0 - (x[0] ** 2 + x[1] ** 2 + x[2] ** 2)

    def grad(self, x):
        return -2 * x


# You can use all methods in optimesh:
points, cells = optimesh.optimize_points_cells(
    points,
    cells,
    "CVT (full)",
    1.0e-2,
    100,
    verbose=False,
    implicit_surface=Sphere(),
    # step_filename_format="out{:03d}.vtk"
)

This code first generates a mediocre mesh on a sphere using meshzoo,

and then optimizes. Some results:

odt-dp-fp odt-uniform-fp odt-uniform-bfgs
CPT ODT CVT (full Hessian)

Which method is best?

From practical experiments, it seems that the CVT smoothing variants, e.g.,

optimesh in.vtk out.vtk -m cvt-uniform-qnf

give very satisfactory results. (This is also the default method, so you don't need to specify it explicitly.) Here is a comparison of all uniform-density methods applied to the random circle mesh seen above:

(Mesh quality is twice the ratio of incircle and circumcircle radius, with the maximum being 1.)

Why optimize?

Gmsh mesh Gmsh mesh after optimesh dmsh mesh

Let us compare the properties of the Poisson problem (Δu = f with Dirichlet boundary conditions) when solved on different meshes of the unit circle. The first mesh is the on generated by Gmsh, the second the same mesh but optimized with optimesh, the third a very high-quality dmsh mesh.

We consider meshings of the circle with an increasing number of points:

gmsh-quality gmsh-cond gmsh-cg
average cell quality condition number of the Poisson matrix number of CG steps for Poisson problem

Quite clearly, the dmsh generator produces the highest-quality meshes (left). The condition number of the corresponding Poisson matrices is lowest for the high quality meshes (middle); one would hence suspect faster convergence with Krylov methods. Indeed, most CG iterations are necessary on the Gmsh mesh (right). After optimesh, one saves between 10 and 20 percent of iterations/computing time. The dmsh mesh cuts the number of iterations in half.

Access from Python

All optimesh functions can also be accessed from Python directly, for example:

import optimesh

X, cells = optimesh.odt.fixed_point(X, cells, 1.0e-2, 100, verbose=False)

Relevant publications

Metadata

Release files for optimesh 0.12.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for optimesh 0.12.7
File Actions
optimesh-0.12.7-cp315-none-any.whl CPython 3.15 none any Details for optimesh-0.12.7-cp315-none-any.whl
optimesh-0.12.7-cp314-none-any.whl CPython 3.14 none any Details for optimesh-0.12.7-cp314-none-any.whl
optimesh-0.12.7-cp313-none-any.whl CPython 3.13 none any Details for optimesh-0.12.7-cp313-none-any.whl
optimesh-0.12.7-cp312-none-any.whl CPython 3.12 none any Details for optimesh-0.12.7-cp312-none-any.whl
optimesh-0.12.7-cp311-none-any.whl CPython 3.11 none any Details for optimesh-0.12.7-cp311-none-any.whl
optimesh-0.12.7-cp310-none-any.whl CPython 3.10 none any Details for optimesh-0.12.7-cp310-none-any.whl

Total release size: 563.3 kB

Release files / optimesh-0.12.7-cp315-none-any.whl

Download URL optimesh-0.12.7-cp315-none-any.whl
Size 104.2 kB
Tags CPython 3.15
SHA-256 checksum
How to use checksums
fc79481a4d4ec53cf64f19500a2968f70267a124e2688e4aeeb99424e150d737
BLAKE2b-256 checksum
How to use checksums
fda0da62391c76a08e1969277075d08af9871796bb2613bd3cd4f90f08bb9b9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / optimesh-0.12.7-cp314-none-any.whl

Download URL optimesh-0.12.7-cp314-none-any.whl
Size 103.3 kB
Tags CPython 3.14
SHA-256 checksum
How to use checksums
2290d82bb7630d5f148a64e2e4aa0bf62717eacb3d30c20e4184554f15365a96
BLAKE2b-256 checksum
How to use checksums
b76f9d052371086b0bfcb74a0d8d867b615252cac77279baa8767bd88ad5990b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / optimesh-0.12.7-cp313-none-any.whl

Download URL optimesh-0.12.7-cp313-none-any.whl
Size 94.4 kB
Tags CPython 3.13
SHA-256 checksum
How to use checksums
9cc76a7e62e7ba095ce7a6086ddd63d5297cf089673805430a34e7ab1efa7bc7
BLAKE2b-256 checksum
How to use checksums
718bc6698527b9e9d15a685ae539493da776543f47d872a4e75fece7a5e10580
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / optimesh-0.12.7-cp312-none-any.whl

Download URL optimesh-0.12.7-cp312-none-any.whl
Size 94.0 kB
Tags CPython 3.12
SHA-256 checksum
How to use checksums
0943e85aec16b57e88a960d7015018df0c208e80ffd49b855a38cb8ae94bff45
BLAKE2b-256 checksum
How to use checksums
7d3f97aac88b8fe0801af10ef00013d649f7ef5c0ae93b949b377b71f4962a4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / optimesh-0.12.7-cp311-none-any.whl

Download URL optimesh-0.12.7-cp311-none-any.whl
Size 103.2 kB
Tags CPython 3.11
SHA-256 checksum
How to use checksums
63080cda2b141e6d9e328c040e587746d1a4668f4271fcef5f27a09343aed684
BLAKE2b-256 checksum
How to use checksums
5862298e4e4f457491a59abc96b1321228fc6d8de20d1f51724818ae63bb3643
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / optimesh-0.12.7-cp310-none-any.whl

Download URL optimesh-0.12.7-cp310-none-any.whl
Size 64.1 kB
Tags CPython 3.10
SHA-256 checksum
How to use checksums
fc1082d329d07547243de534397017e69dc6241a1aa26d54c00c1529adf1060a
BLAKE2b-256 checksum
How to use checksums
1a4442a5791ff9ec760338b89720d4b10e73bdb34c71b18a4618cb5d726983d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Security for optimesh 0.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for optimesh-0.12.7-cp315-none-any.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page