Mesh optimization/smoothing

## Project description

Triangular mesh optimization.

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.

Install with

```
pip install optimesh
```

Example call:

```
optimesh in.e out.vtk
```

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 documented at

```
optimesh -h
```

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 tesselation)

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

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 tesselation)

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

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 tesselation)

density-preserving fixed-point iteration (`--method odt-dp-fp` ) |
uniform-density fixed-point iteration (`--method odt-uniform-fp` ) |
uniform-density BFGS (`--method odt-uniform-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.

### 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.cpt.fixed_point_uniform( # points, cells = optimesh.odt.fixed_point_uniform( points, cells = optimesh.cvt.quasi_newton_uniform_full( points, cells, 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:

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.)

### Access from Python

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

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

### Installation

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

```
pip install optimesh
```

to install.

### Relevant publications

### Testing

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

```
pytest
```

### License

optimesh is published under the MIT license.

## Project details

## Release history Release notifications | RSS feed

## Download files

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

Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|

Filename, size optimesh-0.6.1-py3-none-any.whl (22.7 kB) | File type Wheel | Python version py3 | Upload date | Hashes View |

Filename, size optimesh-0.6.1.tar.gz (24.2 kB) | File type Source | Python version None | Upload date | Hashes View |