Skip to main content

Mesh optimization/smoothing

Project description

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

Project details


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.

optimesh-0.12.4-cp314-none-any.whl (83.0 kB view details)

Uploaded CPython 3.14

optimesh-0.12.4-cp313-none-any.whl (79.7 kB view details)

Uploaded CPython 3.13

optimesh-0.12.4-cp312-none-any.whl (80.0 kB view details)

Uploaded CPython 3.12

optimesh-0.12.4-cp311-none-any.whl (88.3 kB view details)

Uploaded CPython 3.11

optimesh-0.12.4-cp310-none-any.whl (51.9 kB view details)

Uploaded CPython 3.10

File details

Details for the file optimesh-0.12.4-cp314-none-any.whl.

File metadata

  • Download URL: optimesh-0.12.4-cp314-none-any.whl
  • Upload date:
  • Size: 83.0 kB
  • Tags: CPython 3.14
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for optimesh-0.12.4-cp314-none-any.whl
Algorithm Hash digest
SHA256 8318b89b0a77f9f9f38b82de8d4c90b04b4fb82cf3bc68eb65729deee7e3a4a8
MD5 55cc39c773c58d4afde8194f999c688f
BLAKE2b-256 15b55dcaef46b3f9d5839407e4cd7f08389ba2dd19827e681d3eb23a9a8cf76d

See more details on using hashes here.

Provenance

The following attestation bundles were made for optimesh-0.12.4-cp314-none-any.whl:

Publisher: release.yml on meshpro/optimesh-dev

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

File details

Details for the file optimesh-0.12.4-cp313-none-any.whl.

File metadata

  • Download URL: optimesh-0.12.4-cp313-none-any.whl
  • Upload date:
  • Size: 79.7 kB
  • Tags: CPython 3.13
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for optimesh-0.12.4-cp313-none-any.whl
Algorithm Hash digest
SHA256 68dce2c2de2967607921c577f8e1fcede521a62f86e66d43d6c7ddbf02e49521
MD5 f840c92bf9041812ea364c51d7c63c1a
BLAKE2b-256 df04932059e07f92d8f067352f6fef536c9f8649c8348a7b7bfb615993add676

See more details on using hashes here.

Provenance

The following attestation bundles were made for optimesh-0.12.4-cp313-none-any.whl:

Publisher: release.yml on meshpro/optimesh-dev

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

File details

Details for the file optimesh-0.12.4-cp312-none-any.whl.

File metadata

  • Download URL: optimesh-0.12.4-cp312-none-any.whl
  • Upload date:
  • Size: 80.0 kB
  • Tags: CPython 3.12
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for optimesh-0.12.4-cp312-none-any.whl
Algorithm Hash digest
SHA256 7f4d0b8b31f95c83e0b2175eb2e33d8da5ecfa5377e7f0e59472200799e9d830
MD5 789b5e55bb29df4e7ef5cc8d63fc1912
BLAKE2b-256 e24b9fb55b6f18d81e3776cfeba4c8bdae7cf2bb49ec28c093614fa59ee5d6d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for optimesh-0.12.4-cp312-none-any.whl:

Publisher: release.yml on meshpro/optimesh-dev

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

File details

Details for the file optimesh-0.12.4-cp311-none-any.whl.

File metadata

  • Download URL: optimesh-0.12.4-cp311-none-any.whl
  • Upload date:
  • Size: 88.3 kB
  • Tags: CPython 3.11
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for optimesh-0.12.4-cp311-none-any.whl
Algorithm Hash digest
SHA256 0153e01a15737367495a2f967175569b666bf17ac7908778cebb90e093dccc35
MD5 93a3c025711291f80806a0fd4b74fe8d
BLAKE2b-256 01e1d7c94fd2751eb3a78a0debe113407bd190406af0dd457581a13a88555158

See more details on using hashes here.

Provenance

The following attestation bundles were made for optimesh-0.12.4-cp311-none-any.whl:

Publisher: release.yml on meshpro/optimesh-dev

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

File details

Details for the file optimesh-0.12.4-cp310-none-any.whl.

File metadata

  • Download URL: optimesh-0.12.4-cp310-none-any.whl
  • Upload date:
  • Size: 51.9 kB
  • Tags: CPython 3.10
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for optimesh-0.12.4-cp310-none-any.whl
Algorithm Hash digest
SHA256 bead091582a175207c31968f7e4a710123566530528db06cdc481fafcbba3c2b
MD5 427231940c79ebf83df915f6552906fc
BLAKE2b-256 7ea4e54f7689d8fa3fe7cb8a528db7da218300e13e7585619e186ef3a23d8018

See more details on using hashes here.

Provenance

The following attestation bundles were made for optimesh-0.12.4-cp310-none-any.whl:

Publisher: release.yml on meshpro/optimesh-dev

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 Pingdom Monitoring Sentry Error logging StatusPage Status page