{"id":13714938,"url":"https://github.com/meshpro/dmsh","last_synced_at":"2026-01-25T16:05:18.118Z","repository":{"id":32771481,"uuid":"141055235","full_name":"meshpro/dmsh","owner":"meshpro","description":":spider_web: Simple mesh generator inspired by distmesh.","archived":false,"fork":false,"pushed_at":"2023-03-13T11:05:12.000Z","size":1879,"stargazers_count":218,"open_issues_count":5,"forks_count":27,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-17T06:53:15.361Z","etag":null,"topics":["finite-elements","mathematics","mesh","mesh-generation","python","python3"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","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,"publiccode":null,"codemeta":null}},"created_at":"2018-07-15T20:08:22.000Z","updated_at":"2025-04-14T10:21:59.000Z","dependencies_parsed_at":"2024-06-21T13:09:40.858Z","dependency_job_id":"ea1336d8-f27d-4dc2-ba64-2933f8db666d","html_url":"https://github.com/meshpro/dmsh","commit_stats":{"total_commits":1,"total_committers":1,"mean_commits":1.0,"dds":0.0,"last_synced_commit":"c1b0eadadac9213c328243cf72e1d2956d783908"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meshpro%2Fdmsh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meshpro%2Fdmsh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meshpro%2Fdmsh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meshpro%2Fdmsh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meshpro","download_url":"https://codeload.github.com/meshpro/dmsh/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252806414,"owners_count":21807199,"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":["finite-elements","mathematics","mesh","mesh-generation","python","python3"],"created_at":"2024-08-03T00:00:52.186Z","updated_at":"2026-01-25T16:05:18.068Z","avatar_url":"https://github.com/meshpro.png","language":null,"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/nschloe/dmsh\"\u003e\u003cimg alt=\"dmsh\" src=\"https://raw.githubusercontent.com/meshpro/dmsh/main/logo/logo-with-text.svg\" width=\"50%\"\u003e\u003c/a\u003e\n  \u003cp align=\"center\"\u003eThe worst mesh generator you'll ever use.\u003c/p\u003e\n\u003c/p\u003e\n\n[![PyPi Version](https://img.shields.io/pypi/v/dmsh.svg?style=flat-square)](https://pypi.org/project/dmsh/)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/dmsh.svg?style=flat-square)](https://pypi.org/project/dmsh/)\n[![GitHub stars](https://img.shields.io/github/stars/nschloe/dmsh.svg?style=flat-square\u0026logo=github\u0026label=Stars\u0026logoColor=white)](https://github.com/nschloe/dmsh)\n[![PyPi downloads](https://img.shields.io/pypi/dm/dmsh.svg?style=flat-square)](https://pypistats.org/packages/dmsh)\n\n[![Discord](https://img.shields.io/static/v1?logo=discord\u0026label=chat\u0026message=on%20discord\u0026color=7289da\u0026style=flat-square)](https://discord.gg/PBCCvwHqpv)\n\nInspired by [distmesh](http://persson.berkeley.edu/distmesh/), dmsh can be slow,\nrequires a lot of memory, and isn't terribly robust either.\n\nOn the plus side,\n\n- it's got a user-friendly interface,\n- is pure Python (and hence easily installable on any system), and\n- it produces pretty high-quality meshes.\n\nCombined with [optimesh](https://github.com/nschloe/optimesh), dmsh produces the\nhighest-quality 2D meshes in the west.\n\n### Examples\n\n#### Primitives\n\n| \u003cimg alt=\"circle\" src=\"https://raw.githubusercontent.com/meshpro/dmsh/main/plots/circle.svg\" width=\"100%\"\u003e | \u003cimg alt=\"circle\" src=\"https://raw.githubusercontent.com/meshpro/dmsh/main/plots/rectangle.svg\" width=\"100%\"\u003e | \u003cimg alt=\"circle\" src=\"https://raw.githubusercontent.com/meshpro/dmsh/main/plots/polygon.svg\" width=\"100%\"\u003e |\n| :--------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------: |\n\n```python\nimport dmsh\nimport meshio\nimport optimesh\n\ngeo = dmsh.Circle([0.0, 0.0], 1.0)\nX, cells = dmsh.generate(geo, 0.1)\n\n# optionally optimize the mesh\nX, cells = optimesh.optimize_points_cells(X, cells, \"CVT (full)\", 1.0e-10, 100)\n\n# visualize the mesh\ndmsh.show(X, cells, geo)\n\n# and write it to a file\nmeshio.Mesh(X, {\"triangle\": cells}).write(\"circle.vtk\")\n```\n\n```python\nimport dmsh\n\ngeo = dmsh.Rectangle(-1.0, +2.0, -1.0, +1.0)\nX, cells = dmsh.generate(geo, 0.1)\n```\n\n```python\nimport dmsh\n\ngeo = dmsh.Polygon(\n    [\n        [0.0, 0.0],\n        [1.1, 0.0],\n        [1.2, 0.5],\n        [0.7, 0.6],\n        [2.0, 1.0],\n        [1.0, 2.0],\n        [0.5, 1.5],\n    ]\n)\nX, cells = dmsh.generate(geo, 0.1)\n```\n\n#### Combinations\n\n##### Difference\n\n| \u003cimg src=\"https://raw.githubusercontent.com/meshpro/dmsh/main/plots/moon.svg\" width=\"100%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/meshpro/dmsh/main/plots/pacman.svg\" width=\"100%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/meshpro/dmsh/main/plots/rectangle-hole-refinement.svg\" width=\"100%\"\u003e |\n| :-----------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------: |\n\n```python\nimport dmsh\n\ngeo = dmsh.Circle([-0.5, 0.0], 1.0) - dmsh.Circle([+0.5, 0.0], 1.0)\nX, cells = dmsh.generate(geo, 0.1)\n```\n\n```python\nimport dmsh\n\ngeo = dmsh.Circle([0.0, 0.0], 1.0) - dmsh.Polygon([[0.0, 0.0], [1.5, 0.4], [1.5, -0.4]])\nX, cells = dmsh.generate(geo, 0.1, tol=1.0e-10)\n```\n\nThe following example uses a nonconstant edge length; it depends on the distance to the\ncircle `c`.\n\n```python\nimport dmsh\nimport numpy as np\n\nr = dmsh.Rectangle(-1.0, +1.0, -1.0, +1.0)\nc = dmsh.Circle([0.0, 0.0], 0.3)\ngeo = r - c\n\nX, cells = dmsh.generate(geo, lambda pts: np.abs(c.dist(pts)) / 5 + 0.05, tol=1.0e-10)\n```\n\n##### Union\n\n| \u003cimg src=\"https://raw.githubusercontent.com/meshpro/dmsh/main/plots/union-circles.svg\" width=\"100%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/meshpro/dmsh/main/plots/union-rectangles.svg\" width=\"100%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/meshpro/dmsh/main/plots/union-three-circles.svg\" width=\"100%\"\u003e |\n| :--------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------: |\n\n```python\nimport dmsh\n\ngeo = dmsh.Circle([-0.5, 0.0], 1.0) + dmsh.Circle([+0.5, 0.0], 1.0)\nX, cells = dmsh.generate(geo, 0.15)\n```\n\n```python\nimport dmsh\n\ngeo = dmsh.Rectangle(-1.0, +0.5, -1.0, +0.5) + dmsh.Rectangle(-0.5, +1.0, -0.5, +1.0)\nX, cells = dmsh.generate(geo, 0.15)\n```\n\n```python\nimport dmsh\nimport numpy as np\n\nangles = np.pi * np.array([3.0 / 6.0, 7.0 / 6.0, 11.0 / 6.0])\ngeo = dmsh.Union(\n    [\n        dmsh.Circle([np.cos(angles[0]), np.sin(angles[0])], 1.0),\n        dmsh.Circle([np.cos(angles[1]), np.sin(angles[1])], 1.0),\n        dmsh.Circle([np.cos(angles[2]), np.sin(angles[2])], 1.0),\n    ]\n)\nX, cells = dmsh.generate(geo, 0.15)\n```\n\n#### Intersection\n\n| \u003cimg src=\"https://raw.githubusercontent.com/meshpro/dmsh/main/plots/intersection-circles.svg\" width=\"100%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/meshpro/dmsh/main/plots/intersection-three-circles.svg\" width=\"100%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/meshpro/dmsh/main/plots/intersection-circle-halfspace.svg\" width=\"100%\"\u003e |\n| :---------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------: |\n\n```python\nimport dmsh\n\ngeo = dmsh.Circle([0.0, -0.5], 1.0) \u0026 dmsh.Circle([0.0, +0.5], 1.0)\nX, cells = dmsh.generate(geo, 0.1, tol=1.0e-10)\n```\n\n```python\nimport dmsh\nimport numpy as np\n\nangles = np.pi * np.array([3.0 / 6.0, 7.0 / 6.0, 11.0 / 6.0])\ngeo = dmsh.Intersection(\n    [\n        dmsh.Circle([np.cos(angles[0]), np.sin(angles[0])], 1.5),\n        dmsh.Circle([np.cos(angles[1]), np.sin(angles[1])], 1.5),\n        dmsh.Circle([np.cos(angles[2]), np.sin(angles[2])], 1.5),\n    ]\n)\nX, cells = dmsh.generate(geo, 0.1, tol=1.0e-10)\n```\n\nThe following uses the `HalfSpace` primtive for cutting off a circle.\n\n```python\nimport dmsh\n\ngeo = dmsh.HalfSpace([1.0, 1.0]) \u0026 dmsh.Circle([0.0, 0.0], 1.0)\nX, cells = dmsh.generate(geo, 0.1)\n```\n\n### Rotation, translation, scaling\n\n| \u003cimg src=\"https://raw.githubusercontent.com/meshpro/dmsh/main/plots/rotation.svg\" width=\"100%\"\u003e | \u003cimg src=\"https://raw.githubusercontent.com/meshpro/dmsh/main/plots/scaling.svg\" width=\"100%\"\u003e |\n| :---------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------: |\n\n```python\nimport dmsh\nimport numpy as np\n\ngeo = dmsh.Rotation(dmsh.Rectangle(-1.0, +2.0, -1.0, +1.0), 0.1 * np.pi)\nX, cells = dmsh.generate(geo, 0.1, tol=1.0e-10)\n```\n\n```python\nimport dmsh\n\ngeo = dmsh.Rectangle(-1.0, +2.0, -1.0, +1.0) + [1.0, 1.0]\nX, cells = dmsh.generate(geo, 0.1)\n```\n\n```python\nimport dmsh\n\ngeo = dmsh.Rectangle(-1.0, +2.0, -1.0, +1.0) * 2.0\nX, cells = dmsh.generate(geo, 0.1, tol=1.0e-5)\n```\n\n### Local refinement\n\n\u003cimg alt=\"local-refinement\" src=\"https://raw.githubusercontent.com/meshpro/dmsh/main/plots/local-refinement.svg\" width=\"30%\"\u003e\n\nAll objects can be used to refine the mesh according to the distance to the object;\ne.g. a `Path`:\n\n```python\nimport dmsh\n\ngeo = dmsh.Rectangle(0.0, 1.0, 0.0, 1.0)\n\np1 = dmsh.Path([[0.4, 0.6], [0.6, 0.4]])\n\n\ndef target_edge_length(x):\n    return 0.03 + 0.1 * p1.dist(x)\n\n\nX, cells = dmsh.generate(geo, target_edge_length, tol=1.0e-10)\n```\n\n### Custom shapes\n\nIt is also possible to define your own geometry. Simply create a class derived from\n`dmsh.Geometry` that contains a `dist` method and a method to project points onto the\nboundary.\n\n```python\nimport dmsh\nimport numpy as np\n\n\nclass MyDisk(dmsh.Geometry):\n    def __init__(self):\n        self.r = 1.0\n        self.x0 = [0.0, 0.0]\n        bounding_box = [-1.0, 1.0, -1.0, 1.0]\n        feature_points = np.array([[], []]).T\n        super().__init__(bounding_box, feature_points)\n\n    def dist(self, x):\n        assert x.shape[0] == 2\n        y = (x.T - self.x0).T\n        return np.sqrt(np.einsum(\"i...,i...-\u003e...\", y, y)) - self.r\n\n    def boundary_step(self, x):\n        # project onto the circle\n        y = (x.T - self.x0).T\n        r = np.sqrt(np.einsum(\"ij,ij-\u003ej\", y, y))\n        return ((y / r * self.r).T + self.x0).T\n\n\ngeo = MyDisk()\nX, cells = dmsh.generate(geo, 0.1)\n```\n\n### Debugging\n\n| ![level-set-poly](https://raw.githubusercontent.com/meshpro/dmsh/main/plots/levelset-polygon.png) | ![level-set-rect-hole](https://raw.githubusercontent.com/meshpro/dmsh/main/plots/levelset-rect-hole.png) |\n| :-----------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------: |\n\ndmsh is rather fragile, but sometimes the break-downs are due to an incorrectly defined\ngeometry. Use\n\n```\ngeo.show()\n```\n\nto inspect the level set function of your domain. (It must be negative inside the\ndomain and positive outside. The 0-level set forms the domain boundary.)\n\n### Installation\n\ndmsh is [available from the Python Package\nIndex](https://pypi.org/project/dmsh/), so simply type\n\n```\npip install dmsh\n```\n\nto install.\n\n### Testing\n\nTo run the dmsh unit tests, check out this repository and type\n\n```\ntox\n```\n","funding_links":[],"categories":["Meshing"],"sub_categories":["Triangular and tetrahedral meshing"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeshpro%2Fdmsh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeshpro%2Fdmsh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeshpro%2Fdmsh/lists"}