{"id":22059738,"url":"https://github.com/precise-simulation/distmesh-julia","last_synced_at":"2025-05-12T19:55:30.758Z","repository":{"id":201688144,"uuid":"490179001","full_name":"precise-simulation/distmesh-julia","owner":"precise-simulation","description":"DistMesh-Julia - Simple Mesh Generation in Julia","archived":false,"fork":false,"pushed_at":"2022-05-09T07:35:18.000Z","size":37,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-01T02:53:01.113Z","etag":null,"topics":["julia","matlab","mesh","mesh-generation","mesh-generator","octave","simulation"],"latest_commit_sha":null,"homepage":"https://www.featool.com/grid/2018/03/06/Matlab-Mesh-Generation-Comparison.html","language":"Julia","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/precise-simulation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-05-09T07:30:18.000Z","updated_at":"2025-03-08T13:56:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"c33fc25f-c66b-44ad-aa2b-ad823b1e7ec7","html_url":"https://github.com/precise-simulation/distmesh-julia","commit_stats":null,"previous_names":["precise-simulation/distmesh-julia"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/precise-simulation%2Fdistmesh-julia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/precise-simulation%2Fdistmesh-julia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/precise-simulation%2Fdistmesh-julia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/precise-simulation%2Fdistmesh-julia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/precise-simulation","download_url":"https://codeload.github.com/precise-simulation/distmesh-julia/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253813535,"owners_count":21968504,"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":["julia","matlab","mesh","mesh-generation","mesh-generator","octave","simulation"],"created_at":"2024-11-30T17:32:09.181Z","updated_at":"2025-05-12T19:55:30.738Z","avatar_url":"https://github.com/precise-simulation.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"DistMesh-Julia - Simple Mesh Generation in Julia\n================================================\n\nAbout DistMesh-Julia\n--------------------\n\nDistMesh is a simple Julia code for automatic generation of\nunstructured 2D triangular and 3D tetrahedral volume meshes using\n(level set) distance functions for describing geometries and domains.\n\nThis repository is a Julia port of the consolidated\n[2D/3D DistMesh implementation for MATLAB and Octave](https://github.com/precise-simulation/distmesh).\n\n\u003ctable align=\"center\"\u003e\n\u003ctr\u003e\n\u003ctd width=\"30%\"\u003e\u003cimg src=\"https://www.featool.com/images/featool-multiphysics-easy-to-use-gui.jpg\" style=\"width:100%\"\u003e\u003c/td\u003e\n\u003ctd width=\"30%\"\u003e\u003cimg src=\"https://www.featool.com/doc/grid_main_50.png\" style=\"width: 100%;\"\u003e\u003c/td\u003e\n\u003ctd width=\"30%\"\u003e\u003cimg src=\"http://persson.berkeley.edu/distmesh/ex06zoom.png\" style=\"width: 100%;\"\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n\nDescription\n-----------\n\nThe original DistMesh MATLAB algorithm was invented by Per-Olof\nPersson and Gilbert Strang in the Department of Mathematics at\nMIT. More detailed descriptions of the DistMesh algorithm and the\noriginal MATLAB mesh generation code can be found in the SIAM Review\npaper and other references linked below.\n\nThe simplicity of the DistMesh algorithm is due to using signed\ndistance functions (level sets) to specify and describe domains,\ngeometries, and regions to mesh. Distance functions specify the\nshortest distance from any point in space to the boundary of the\ndomain, where the sign of the function is positive outside the region,\nnegative inside, and zero on the boundary. This definition is used to\nidentify if a point is located in or outside of the\ngeometry. Moreover, the gradient of the distance function points in\nthe direction of the boundary, allowing points outside to be\nefficiently moved back to the domain.\n\nA simple example is the unit circle in two dimensions, which has the\ndistance function _d(r) = r-1_, where _r = sqrt(x^2+y^2)_ is the\ndistance from the origin. For more complicated geometries the distance\nfunction can be computed by interpolation between values on a grid,\nwhich is a common representation for level set methods.\n\nFor the mesh generation procedure, DistMesh uses the Delaunay\ntriangulation routine in the VornoiDelaunay Julia module and tries to\noptimize the node locations by a force-based smoothing procedure. The\ntopology is regularly updated by Delaunay. The boundary points are\nonly allowed to move tangentially to the boundary by projections using\nthe distance function. This iterative procedure typically results in\nvery uniform and well-shaped high quality meshes.\n\n\nUsage\n-----\n\nTo use the this mesh generation code, simply download the stand alone\n[distmesh](https://github.com/precise-simulation/distmesh-julia/blob/master/DistMesh.jl)\nsource code and run it in Julia (tested under Julia v6.2). The\nfunction syntax is as follows\n\n    (P, T, STAT) = DISTMESH( FD, FH, H0, BBOX, P_FIX, E_FIX, IT_MAX, FID)\n\nwhere **FD** is a function handle to the geometry description that\nshould take evaluation coordinates and points as input. For example\n\u003ccode\u003efd = p -\u003e sqrt.(sum(p.^2,2)) - 1\u003c/code\u003e specifies the distance\nfunction for a unit circle (both function handles, string function\nnames, and anonymous functions are supported). Similar to _FD_, **FH**\na function describing the desired relative mesh size distribution. For\nexample \u003ccode\u003efh = p -\u003e ones(size(p,1),1)\u003c/code\u003e specifies a uniform\ndistribution where _FH_ evaluates to _1_ at all points. **H0** is a\nnumeric scalar specifying the initial edge lengths, and **BBOX** is a\n2 by 2 in 2D (or 2 by 3 in 3D) bounding box of the domain (enclosing\nthe zero contour/level set of _FD_). **P_FIX** optionally specifies a\nnumber of points that should always be present (fixed) in the\nresulting mesh. **E_FIX** can be sets of edge vertex indices to\nconstrain, or alternatively a cell array with function handle to call.\n**IT_MAX** sets the maximum number of grid generation iterations\nallowed (default _1000_).  Finally, **FID** specifies a file\nidentifies for output (default _1_ = terminal output).\n\nThe DistMesh-Julia function returns the grid point vertices in **P**,\ntriangulated simplices in **T**, as well as an optional statistics\nstruct **STAT** including timings and convergence information.\n\n    Input:\n\n       FD:        Distance function d(x,y,(z))\n       FH:        Scaled edge length function h(x,y,(z))\n       H0:        Initial edge length\n       BBOX:      Bounding box [xmin ymin (zmin); xmax,ymax,(zmax)]\n       P_FIX:     Fixed node positions [N_P_FIX x 2/3]\n       E_FIX:     Constrained edges [N_E_FIX x 2]\n       IT_MAX:    Maximum number of iterations\n       FID:       Output file id number (default 1 = terminal)\n\n    Output:\n\n       P:         Grid vertex/node coordinates [N_P x 2/3]\n       T:         Triangle indices [N_T x 3]\n       STAT:      Mesh generation statistics (struct)\n\n\n\nExamples\n--------\n\nTo automatically run the collection of basic mesh generation examples\ndescribed below, type\n[distmesh_demo](https://github.com/precise-simulation/distmesh-julia/blob/master/distmesh_demo.jl)\ninto the Julia command prompt from the directory where the _distmesh_\nfiles can be found.\n\n- Example 1: (Uniform mesh on unit circle)\n\n        fd = p -\u003e sqrt.(sum(p.^2,2)) - 1\n        fh = p -\u003e ones(size(p,1))\n        (p, t) = distmesh( fd, fh, 0.1, [-1 -1;1 1] )\n        plotgrid( p, t )\n\n- Example 2: (Uniform mesh on ellipse)\n\n        fd = p -\u003e p[:,1].^2/2^2 + p[:,2].^2/1^2 - 1\n        fh = p -\u003e ones(size(p,1))\n        (p, t) = distmesh( fd, fh, 0.2, [-2 -1;2 1], [], [], 200 )\n        plotgrid( p, t )\n\n- Example 3: (Uniform mesh on unit square)\n\n        fd = p -\u003e -minimum([minimum([minimum([p[:,2] 1-p[:,2]],2) p[:,1]],2) 1-p[:,1]],2)\n        fh = p -\u003e ones(size(p,1))\n        (p, t) = distmesh( fd, fh, 0.2, [-1 -1;1 1], [-1 -1;-1 1;1 -1;1 1] )\n        plotgrid( p, t )\n\n- Example 4: (Uniform mesh on complex polygon)\n\n        pv = [-0.4 -0.5;0.4 -0.2;0.4 -0.7;1.5 -0.4;0.9 0.1;\n              1.6 0.8;0.5 0.5;0.2 1;0.1 0.4;-0.7 0.7;-0.4 -0.5]\n        fd = p -\u003e dpolygon( p, pv )\n        fh = p -\u003e ones(size(p,1))\n        (p, t) = distmesh( fd, fh, 0.1, [-1 -1;2 1], pv )\n        plotgrid( p, t )\n\n- Example 5: (Rectangle with circular hole, refined at circle boundary)\n\n        fd = p -\u003e maximum( [dpolygon(p,[-1 -1;1 -1;1 1;-1 1;-1 -1]) -(sqrt.(sum(p.^2,2))-0.5)], 2 )\n        fh = p -\u003e 0.05 + 0.3*(sqrt.(sum(p.^2,2))-0.5)\n        plotgrid( p, t )\n\n- Example 6: (Square, with size function point and line sources)\n\n        dcircle = (p,xc,yc,r) -\u003e sqrt.((p[:,1]-xc).^2+(p[:,2]-yc).^2)-r\n        fd = p -\u003e -minimum([minimum([minimum([p[:,2] 1-p[:,2]],2) p[:,1]],2) 1-p[:,1]],2)\n        fh = p -\u003e minimum([minimum(hcat(0.01+0.3*abs.(dcircle(p,0,0,0)),\n                      0.025+0.3*abs.(dpolygon(p,[0.3 0.7;0.7 0.5;0.3 0.7]))),2) 0.15*ones(size(p,1),1)],2)\n        (p, t) = distmesh( fd, fh, 0.01, [0 0;1 1], [0 0;1 0;0 1;1 1] )\n        plotgrid( p, t )\n\n- Example 7: (NACA0012 airfoil)\n\n        hlead = 0.01; htrail = 0.04; hmax = 2; circx = 2; circr = 4\n        a = 0.12/0.2*[0.2969 -0.126 -0.3516 0.2843 -0.1036]\n        dcircle = (p,xc,yc,r) -\u003e sqrt.((p[:,1]-xc).^2+(p[:,2]-yc).^2)-r\n        fd = p -\u003e maximum(hcat( dcircle(p,circx,0,circr),\n                   -((abs.(p[:,2])-polyval([a[5:-1:2];0],p[:,1])).^2-a[1]^2*p[:,1]) ), 2 )\n        fh = p -\u003e minimum([minimum([hlead+0.3*dcircle(p,0,0,0) htrail+0.3*dcircle(p,1,0,0)],2) hmax*ones(size(p,1),1)],2)\n\n        fixx = 1 - htrail*cumsum(1.3.^(0:4)')\n        fixy = a[1]*sqrt.(fixx) + polyval([a[5:-1:2];0],fixx)\n        pfix = [[circx+[-1 1 0 0]*circr; 0 0 circr*[-1 1]]'; 0 0; 1 0; fixx' fixy'; fixx' -fixy']\n        bbox = [circx-circr -circr; circx+circr circr]\n        h0   = minimum([hlead htrail hmax])\n\n        (p, t) = distmesh( fd, fh, h0, bbox, pfix )\n        plotgrid( p, t )\n\n- Example 8: (Uniform mesh on unit sphere)\n\n        fd = p -\u003e sqrt.(sum(p.^2,2)) - 1\n        fh = p -\u003e ones(size(p,1),1)\n        (p,t) = distmesh( fd, fh, 0.2, [-1 -1 -1;1 1 1] )\n        plotgrid( p, t )\n\n- Example 9: (Uniform mesh on unit cube)\n\n        fd = p -\u003e -minimum([minimum([minimum([minimum([minimum([p[:,3] 1-p[:,3]],2) p[:,2]],2) 1-p[:,2]],2) p[:,1]],2) 1-p[:,1]],2)\n        fh = p -\u003e ones(size(p,1),1)\n        pfix = [-1 -1 -1;-1 1 -1;1 -1 -1;1 1 -1; -1 -1 1;-1 1 1;1 -1 1;1 1 1]\n        (p,t) = distmesh( fd, fh, 0.2, [-1 -1 -1;1 1 1], pfix )\n        plotgrid( p, t )\n\n- Example 10: (Uniform mesh on cylinder)\n\n        fd = p -\u003e -minimum([minimum([p[:,3] 4-p[:,3]],2) 1-sqrt.(sum(p[:,1:2].^2,2))],2)\n        fh = p -\u003e ones(size(p,1),1)\n        pfix = [-1 -1 -1;-1 1 -1;1 -1 -1;1 1 -1; -1 -1 1;-1 1 1;1 -1 1;1 1 1]\n        (p,t) = distmesh( fd, fh, 0.5, [-1 -1 0;1 1 4] )\n        plotgrid( p, t )\n\n\nDependencies\n------------\n\n- VornoiDelaunay.jl\n- Plots.jl\n\n\nIssues\n------\n\n- 3D is technically supported by DistMesh-Julia, but Julia is missing\n  a _3D Delaunay_ triangulation functionality.\n\n- Proper module bundling not implemented.\n\n\n\nReferences\n----------\n\n[1] [P.-O. Persson, G. Strang, A Simple Mesh Generator in MATLAB. SIAM Review, Volume 46 (2), pp. 329-345, June 2004.](http://persson.berkeley.edu/distmesh/persson04mesh.pdf)\n\n[2] [P.-O. Persson, Mesh Generation for Implicit Geometries. Ph.D. thesis, Department of Mathematics, MIT, Dec 2004.](http://persson.berkeley.edu/thesis/persson-thesis-color.pdf)\n\n[3] [P.-O. Persson's DistMesh website](http://persson.berkeley.edu/distmesh/)\n\n\nAlternative Implementations\n---------------------------\n\n[4] [Consolidated 2D/3D DistMesh for MATLAB and Octave](https://github.com/precise-simulation/distmesh)\n\n[5] [libDistMesh - A Simple Mesh Generator in C++](https://github.com/pgebhardt/libdistmesh)\n\n[6] [PyDistMesh - A Simple Mesh Generator in Python](https://github.com/bfroehle/pydistmesh)\n\n[7] [Mesh generator - Java implementation of DistMesh](https://github.com/plichjan/jDistMesh)\n\n[8] [DistMesh - Wolfram Language Implementation](https://github.com/WolframResearch/DistMesh)\n\n[9] [J. Burkardt's DistMesh repository](http://people.sc.fsu.edu/~jburkardt/m_src/distmesh/distmesh.html)\n\n[10] [KOKO Mesh Generator](http://fc.isima.fr/~jkoko/codes.html)\n\n\nLicense\n-------\n\nThe DistMesh-Julia code is copyrighted by J.S. Hysing and Precise\nSimulation Limited and licensed under the GNU GPL License; see the\nLicense and Copyright notice for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprecise-simulation%2Fdistmesh-julia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprecise-simulation%2Fdistmesh-julia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprecise-simulation%2Fdistmesh-julia/lists"}