Triangular mesh optimization.
[](https://pypi.org/project/optimesh/) [](https://pypi.org/project/optimesh/) [](https://doi.org/10.5281/zenodo.4728056) [](https://github.com/nschloe/optimesh) [](https://pypistats.org/packages/optimesh) [](https://discord.gg/PBCCvwHqpv) 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](https://github.com/nschloe/optimesh/issues/17) if you're interested in tetrahedral mesh smoothing), and - supports all mesh formats that [meshio](https://github.com/nschloe/meshio) can handle. ### Installation Install optimesh [from PyPI](https://pypi.org/project/optimesh/) with ``` pip install optimesh ``` ### How to get a license Licenses for personal and academic use can be purchased [here](https://buy.stripe.com/5kA3eV8t8af83iE9AE). You'll receive a confirmation email with a license key. Install the key with ``` slim install
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:
|
|
|
| :----------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------: |
| Gmsh mesh | Gmsh mesh after optimesh | [dmsh](//github.com/nschloe/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](http://gmsh.info/), the second the same mesh but optimized with
optimesh, the third a very high-quality [dmsh](https://github.com/nschloe/dmsh) mesh.
We consider meshings of the circle with an increasing number of points:
|  |  |  |
| :-----------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------: |
| 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:
```python
import optimesh
X, cells = optimesh.odt.fixed_point(X, cells, 1.0e-2, 100, verbose=False)
```
### Relevant publications
- [Qiang Du, Vance Faber, and Max Gunzburger, _Centroidal Voronoi Tessellations: Applications and Algorithms_,
SIAM Rev., 41(4), 1999, 637–676.](https://doi.org/10.1137/S0036144599352836)
- [Yang Liu et al., _On centroidal Voronoi tessellation—Energy smoothness and fast computation_,
ACM Transactions on Graphics, Volume 28, Issue 4, August 2009.](https://dl.acm.org/doi/10.1145/1559755.1559758)
- [Long Chen, Michael Holst, _Efficient mesh optimization schemes based on Optimal Delaunay Triangulations_,
Comput. Methods Appl. Mech. Engrg. 200 (2011) 967–984.](https://doi.org/10.1016/j.cma.2010.11.007)