Join the official 2020 Python Developers Survey

Mesh optimization/smoothing

optimesh

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

• is fast,
• preserves submeshes,
• only works for triangular meshes (for now), and
• supports all mesh formats that meshio can handle.

Install with

``````pip install optimesh
``````

Example call:

``````optimesh in.e out.vtk --method lloyd -n 50
``````

Output:

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 viewed with

``````optimesh -h
``````

Laplacian smoothing

classical Laplace linear solve (`--method laplace`)

Classical Laplacian mesh smoothing means moving all (interior) points into the average of their neighbors until an equilibrium has been reached. The method preserves the mesh density (i.e., small simplices are not blown up as part of the smoothing).

Instead of a fixed-point iteration, one can do a few linear solves, interleaved with facet-flipping. This approach converges much faster.

CVT (centroidal Voronoi tesselation)

`--method lloyd`

Centroidal Voronoi tessellation smoothing, realized by Lloyd's algorithm, i.e., points are iteratively moved into the centroid of their Voronoi cell. If the topological neighbors of any node are also the geometrically closest nodes, this is exactly Lloyd's algorithm. That is fulfilled in many practical cases, but the algorithm can break down if it is not.

CPT (centroidal patch tessalation)

fixed-point iteration (`--method cpt-fp`) quasi-Newton (`--method cpt-qn`)

A smooting 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 Laplace smoothing, so optimesh only contains the the uniform-density variant.

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

ODT (optimal Delaunay tesselation)

fixed-point iteration (`--method odt-fp`) nonlinear optimization (`--method odt-no`)

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.

Which method is best?

As usual, it depends. From practical experiments, it seems that `lloyd` smoothing gives very satisfactory results. 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.)

Access from Python

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

```import optimesh

X, cells = optimesh.odt(X, cells, 1.0e-2, 100, verbosity=1)
```

Installation

optimesh is available from the Python Package Index, so simply do

``````pip install -U optimesh
``````

to install or upgrade. Use `sudo -H` to install as root or the `--user` option of `pip` to install in `\$HOME`.

Testing

To run the optimesh unit tests, check out this repository and type

``````pytest
``````

Distribution

To create a new release

1. bump the `__version__` number,

2. publish to PyPi and tag on GitHub:

``````\$ make publish
``````

optimesh is published under the MIT license.