{"id":13408072,"url":"https://github.com/meshpro/optimesh","last_synced_at":"2026-01-25T16:05:25.005Z","repository":{"id":41897105,"uuid":"131445806","full_name":"meshpro/optimesh","owner":"meshpro","description":":spider_web: Mesh optimization, mesh smoothing.","archived":false,"fork":false,"pushed_at":"2024-01-21T13:15:39.000Z","size":67470,"stargazers_count":563,"open_issues_count":2,"forks_count":54,"subscribers_count":18,"default_branch":"main","last_synced_at":"2024-05-28T19:17:47.442Z","etag":null,"topics":["engineering","fem","mathematics","mesh","mesh-generation","meshing","physics","pypi","python"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/meshpro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-04-28T21:37:12.000Z","updated_at":"2024-05-28T13:30:09.000Z","dependencies_parsed_at":"2024-02-04T20:27:51.054Z","dependency_job_id":"0d02fed2-5276-4520-beb3-f121fe8ac26d","html_url":"https://github.com/meshpro/optimesh","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"d18726ab7d660af7ee40a821152e8f088b044a3c"},"previous_names":["nschloe/optimesh"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meshpro%2Foptimesh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meshpro%2Foptimesh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meshpro%2Foptimesh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meshpro%2Foptimesh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meshpro","download_url":"https://codeload.github.com/meshpro/optimesh/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243578474,"owners_count":20313835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["engineering","fem","mathematics","mesh","mesh-generation","meshing","physics","pypi","python"],"created_at":"2024-07-30T20:00:50.584Z","updated_at":"2026-01-25T16:05:24.978Z","avatar_url":"https://github.com/meshpro.png","language":null,"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/nschloe/optimesh\"\u003e\u003cimg alt=\"optimesh\" src=\"https://raw.githubusercontent.com/meshpro/optimesh/assets/optimesh-logo.svg\" width=\"60%\"\u003e\u003c/a\u003e\n  \u003cp align=\"center\"\u003eTriangular mesh optimization.\u003c/p\u003e\n\u003c/p\u003e\n\n[![PyPi Version](https://img.shields.io/pypi/v/optimesh.svg?style=flat-square)](https://pypi.org/project/optimesh/)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/optimesh.svg?style=flat-square)](https://pypi.org/project/optimesh/)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4728056.svg?style=flat-square)](https://doi.org/10.5281/zenodo.4728056)\n[![GitHub stars](https://img.shields.io/github/stars/nschloe/optimesh.svg?style=flat-square\u0026logo=github\u0026label=Stars\u0026logoColor=white)](https://github.com/nschloe/optimesh)\n[![PyPi downloads](https://img.shields.io/pypi/dm/optimesh.svg?style=flat-square)](https://pypistats.org/packages/optimesh)\n\n[![Discord](https://img.shields.io/static/v1?logo=discord\u0026logoColor=white\u0026label=chat\u0026message=on%20discord\u0026color=7289da\u0026style=flat-square)](https://discord.gg/PBCCvwHqpv)\n\nSeveral mesh smoothing/optimization methods with one simple interface. optimesh\n\n- is fast,\n- preserves submeshes,\n- only works for triangular meshes, flat and on a surface, (for now; upvote [this\n  issue](https://github.com/nschloe/optimesh/issues/17) if you're interested in\n  tetrahedral mesh smoothing), and\n- supports all mesh formats that [meshio](https://github.com/nschloe/meshio) can\n  handle.\n\n### Installation\n\nInstall optimesh [from PyPI](https://pypi.org/project/optimesh/) with\n\n```\npip install optimesh\n```\n\n### How to get a license\n\nLicenses for personal and academic use can be purchased\n[here](https://buy.stripe.com/5kA3eV8t8af83iE9AE).\nYou'll receive a confirmation email with a license key.\nInstall the key with\n\n```\nslim install \u003cyour-license-key\u003e\n```\n\non your machine and you're good to go.\n\nFor commercial use, please contact support@mondaytech.com.\n\n### Using optimesh\n\nExample call:\n\n```\noptimesh in.e out.vtk\n```\n\nOutput:\n![terminal-screenshot](https://raw.githubusercontent.com/meshpro/optimesh/assets/term-screenshot.png)\n\nThe left hand-side graph shows the distribution of angles (the grid line is at the\noptimal 60 degrees). The right hand-side graph shows the distribution of simplex\nquality, where quality is twice the ratio of circumcircle and incircle radius.\n\nAll command-line options are documented at\n\n```\noptimesh -h\n```\n\n### Showcase\n\n![disk-step0](https://raw.githubusercontent.com/meshpro/optimesh/assets/disk-step0.png)\n\nThe following examples show the various algorithms at work, all starting from the same\nrandomly generated disk mesh above. The cell coloring indicates quality; dark green is\nbad, yellow is good.\n\n#### CVT (centroidal Voronoi tessellation)\n\n|                 ![cvt-uniform-lloyd2](https://raw.githubusercontent.com/meshpro/optimesh/assets/lloyd2.webp)                  | ![cvt-uniform-qnb](https://raw.githubusercontent.com/meshpro/optimesh/assets/cvt-uniform-qnb.webp) | ![cvt-uniform-qnf](https://raw.githubusercontent.com/meshpro/optimesh/assets/cvt-uniform-qnf.webp) |\n| :---------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------: |\n| uniform-density relaxed [Lloyd's algorithm](https://en.wikipedia.org/wiki/Lloyd%27s_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`)     |\n\nCentroidal Voronoi tessellation smoothing ([Du et al.](#relevant-publications)) is one\nof the oldest and most reliable approaches. optimesh provides classical Lloyd smoothing\nas well as several variants that result in better meshes.\n\n#### CPT (centroidal patch tessellation)\n\n|                             ![cpt-cp](https://raw.githubusercontent.com/meshpro/optimesh/assets/cpt-dp.png)                             | ![cpt-uniform-fp](https://raw.githubusercontent.com/meshpro/optimesh/assets/cpt-uniform-fp.webp) | ![cpt-uniform-qn](https://raw.githubusercontent.com/meshpro/optimesh/assets/cpt-uniform-qn.webp) |\n| :-------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------: |\n| density-preserving linear solve ([Laplacian smoothing](https://en.wikipedia.org/wiki/Laplacian_smoothing), `--method cpt-linear-solve`) |                uniform-density fixed-point iteration (`--method cpt-fixed-point`)                |                    uniform-density quasi-Newton (`--method cpt-quasi-newton`)                    |\n\nA smoothing method suggested by [Chen and Holst](#relevant-publications), mimicking CVT\nbut much more easily implemented. The density-preserving variant leads to the exact same\nequation system as Laplacian smoothing, so CPT smoothing can be thought of as a\ngeneralization.\n\nThe uniform-density variants are implemented classically as a fixed-point iteration and\nas a quasi-Newton method. The latter typically converges faster.\n\n#### ODT (optimal Delaunay tessellation)\n\n| ![odt-dp-fp](https://raw.githubusercontent.com/meshpro/optimesh/assets/odt-dp-fp.webp) | ![odt-uniform-fp](https://raw.githubusercontent.com/meshpro/optimesh/assets/odt-uniform-fp.webp) | ![odt-uniform-bfgs](https://raw.githubusercontent.com/meshpro/optimesh/assets/odt-uniform-bfgs.webp) |\n| :------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: |\n|            density-preserving fixed-point iteration (`--method odt-dp-fp`)             |                uniform-density fixed-point iteration (`--method odt-fixed-point`)                |                              uniform-density BFGS (`--method odt-bfgs`)                              |\n\nOptimal Delaunay Triangulation (ODT) as suggested by [Chen and\nHolst](#relevant-publications). Typically superior to CPT, but also more expensive to\ncompute.\n\nImplemented once classically as a fixed-point iteration, once as a nonlinear\noptimization method. The latter typically leads to better results.\n\n### Using optimesh from Python\n\nYou can also use optimesh in a Python program. Try\n\n\u003c!--pytest.mark.skip--\u003e\n\n```python\nimport optimesh\n\n# [...] create points, cells [...]\n\npoints, cells = optimesh.optimize_points_cells(\n    points, cells, \"CVT (block-diagonal)\", 1.0e-5, 100\n)\n\n# or create a meshplex Mesh\nimport meshplex\n\nmesh = meshplex.MeshTri(points, cells)\noptimesh.optimize(mesh, \"CVT (block-diagonal)\", 1.0e-5, 100)\n# mesh.points, mesh.cells, ...\n```\n\nIf you only want to do one optimization step, do\n\n\u003c!--pytest.mark.skip--\u003e\n\n```python\npoints = optimesh.get_new_points(mesh, \"CVT (block-diagonal)\")\n```\n\n### Surface mesh smoothing\n\noptimesh also supports optimization of triangular meshes on surfaces which are defined\nimplicitly by a level set function (e.g., spheres). You'll need to specify the function\nand its gradient, so you'll have to do it in Python:\n\n```python\nimport meshzoo\nimport optimesh\n\npoints, cells = meshzoo.tetra_sphere(20)\n\n\nclass Sphere:\n    def f(self, x):\n        return 1.0 - (x[0] ** 2 + x[1] ** 2 + x[2] ** 2)\n\n    def grad(self, x):\n        return -2 * x\n\n\n# You can use all methods in optimesh:\npoints, cells = optimesh.optimize_points_cells(\n    points,\n    cells,\n    \"CVT (full)\",\n    1.0e-2,\n    100,\n    verbose=False,\n    implicit_surface=Sphere(),\n    # step_filename_format=\"out{:03d}.vtk\"\n)\n```\n\nThis code first generates a mediocre mesh on a sphere using\n[meshzoo](https://github.com/nschloe/meshzoo/),\n\n\u003cimg src=\"https://raw.githubusercontent.com/meshpro/optimesh/assets/tetra-sphere.png\" width=\"20%\"\u003e\n\nand then optimizes. Some results:\n\n| ![odt-dp-fp](https://raw.githubusercontent.com/meshpro/optimesh/assets/sphere-cpt.webp) | ![odt-uniform-fp](https://raw.githubusercontent.com/meshpro/optimesh/assets/sphere-odt.webp) | ![odt-uniform-bfgs](https://raw.githubusercontent.com/meshpro/optimesh/assets/sphere-cvt.webp) |\n| :-------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------: |\n|                                           CPT                                           |                                             ODT                                              |                                       CVT (full Hessian)                                       |\n\n### Which method is best?\n\nFrom practical experiments, it seems that the CVT smoothing variants, e.g.,\n\n```\noptimesh in.vtk out.vtk -m cvt-uniform-qnf\n```\n\ngive very satisfactory results. (This is also the default method, so you don't need to\nspecify it explicitly.) Here is a comparison of all uniform-density methods applied to\nthe random circle mesh seen above:\n\n\u003cimg src=\"https://raw.githubusercontent.com/meshpro/optimesh/assets/comparison.svg\" width=\"90%\"\u003e\n\n(Mesh quality is twice the ratio of incircle and circumcircle radius, with the maximum\nbeing 1.)\n\n### Why optimize?\n\n| \u003cimg src=\"https://raw.githubusercontent.com/meshpro/optimesh/assets/gmsh.png\" width=\"80%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/meshpro/optimesh/assets/gmsh-optimesh.png\" width=\"80%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/meshpro/optimesh/assets/dmsh.png\" width=\"80%\"\u003e |\n| :----------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------: |\n|                                         Gmsh mesh                                          |                                      Gmsh mesh after optimesh                                       |                           [dmsh](//github.com/nschloe/dmsh) mesh                           |\n\nLet us compare the properties of the Poisson problem (_Δu = f_ with Dirichlet boundary\nconditions) when solved on different meshes of the unit circle. The first mesh is the\non generated by [Gmsh](http://gmsh.info/), the second the same mesh but optimized with\noptimesh, the third a very high-quality [dmsh](https://github.com/nschloe/dmsh) mesh.\n\nWe consider meshings of the circle with an increasing number of points:\n\n| ![gmsh-quality](https://raw.githubusercontent.com/meshpro/optimesh/assets/gmsh-quality.svg) | ![gmsh-cond](https://raw.githubusercontent.com/meshpro/optimesh/assets/gmsh-cond.svg) | ![gmsh-cg](https://raw.githubusercontent.com/meshpro/optimesh/assets/gmsh-cg.svg) |\n| :-----------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------: |\n|                                    average cell quality                                     |                        condition number of the Poisson matrix                         |                      number of CG steps for Poisson problem                       |\n\nQuite clearly, the dmsh generator produces the highest-quality meshes (left).\nThe condition number of the corresponding Poisson matrices is lowest for the high\nquality meshes (middle); one would hence suspect faster convergence with Krylov methods.\nIndeed, most CG iterations are necessary on the Gmsh mesh (right). After optimesh, one saves\nbetween 10 and 20 percent of iterations/computing time. The dmsh mesh cuts the number of\niterations in _half_.\n\n### Access from Python\n\nAll optimesh functions can also be accessed from Python directly, for example:\n\n\u003c!--pytest.mark.skip--\u003e\n\n```python\nimport optimesh\n\nX, cells = optimesh.odt.fixed_point(X, cells, 1.0e-2, 100, verbose=False)\n```\n\n### Relevant publications\n\n- [Qiang Du, Vance Faber, and Max Gunzburger, _Centroidal Voronoi Tessellations: Applications and Algorithms_,\n  SIAM Rev., 41(4), 1999, 637–676.](https://doi.org/10.1137/S0036144599352836)\n\n- [Yang Liu et al., _On centroidal Voronoi tessellation—Energy smoothness and fast computation_,\n  ACM Transactions on Graphics, Volume 28, Issue 4, August 2009.](https://dl.acm.org/doi/10.1145/1559755.1559758)\n\n- [Long Chen, Michael Holst, _Efficient mesh optimization schemes based on Optimal Delaunay Triangulations_,\n  Comput. Methods Appl. Mech. Engrg. 200 (2011) 967–984.](https://doi.org/10.1016/j.cma.2010.11.007)\n","funding_links":[],"categories":["Meshing"],"sub_categories":["Books","Mesh tools"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeshpro%2Foptimesh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeshpro%2Foptimesh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeshpro%2Foptimesh/lists"}