Package: optimesh
Triangular mesh optimization.Several mesh smoothing/optimization methods with one simple interface. optimeshis fast,preserves submeshes,only works for triangular meshes, flat and on a surface, (for now; upvotethis
issueif you're interested in
tetrahedral mesh smoothing), andsupports all mesh formats thatmeshiocan
handle.InstallationInstall optimeshfrom PyPIwithpip install optimeshHow to get a licenseLicenses for personal and academic use can be purchasedhere.
You'll receive a confirmation email with a license key.
Install the key withslim install <your-license-key>on your machine and you're good to go.For commercial use, please contactsupport@mondaytech.com.Using optimeshExample call:optimesh in.e out.vtkOutput: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 atoptimesh -hShowcaseThe 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)uniform-density relaxedLloyd'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)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 byChen 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)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 byChen 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 PythonYou can also use optimesh in a Python program. Tryimportoptimesh# [...] create points, cells [...]points,cells=optimesh.optimize_points_cells(points,cells,"CVT (block-diagonal)",1.0e-5,100)# or create a meshplex Meshimportmeshplexmesh=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, dopoints=optimesh.get_new_points(mesh,"CVT (block-diagonal)")Surface mesh smoothingoptimesh 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:importmeshzooimportoptimeshpoints,cells=meshzoo.tetra_sphere(20)classSphere:deff(self,x):return1.0-(x[0]**2+x[1]**2+x[2]**2)defgrad(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 usingmeshzoo,and then optimizes. Some results:CPTODTCVT (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-qnfgive 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 meshGmsh mesh after optimeshdmshmeshLet us compare the properties of the Poisson problem (Δu = fwith Dirichlet boundary
conditions) when solved on different meshes of the unit circle. The first mesh is the
on generated byGmsh, the second the same mesh but optimized with
optimesh, the third a very high-qualitydmshmesh.We consider meshings of the circle with an increasing number of points:average cell qualitycondition number of the Poisson matrixnumber of CG steps for Poisson problemQuite 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 inhalf.Access from PythonAll optimesh functions can also be accessed from Python directly, for example:importoptimeshX,cells=optimesh.odt.fixed_point(X,cells,1.0e-2,100,verbose=False)Relevant publicationsQiang Du, Vance Faber, and Max Gunzburger,Centroidal Voronoi Tessellations: Applications and Algorithms,
SIAM Rev., 41(4), 1999, 637–676.Yang Liu et al.,On centroidal Voronoi tessellation—Energy smoothness and fast computation,
ACM Transactions on Graphics, Volume 28, Issue 4, August 2009.Long Chen, Michael Holst,Efficient mesh optimization schemes based on Optimal Delaunay Triangulations,
Comput. Methods Appl. Mech. Engrg. 200 (2011) 967–984.