{"id":19361078,"url":"https://github.com/flosewn/tmesh","last_synced_at":"2025-10-07T03:42:18.013Z","repository":{"id":132110178,"uuid":"263730325","full_name":"FloSewn/tmesh","owner":"FloSewn","description":"Triangular mesh generator in C","archived":false,"fork":false,"pushed_at":"2021-12-16T06:23:40.000Z","size":6589,"stargazers_count":17,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-23T06:48:29.215Z","etag":null,"topics":["advancing-front","cfd-mesh","fem-mesh","mesh-generation","triangle-mesh","triangulation"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FloSewn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2020-05-13T19:58:00.000Z","updated_at":"2025-03-31T10:24:26.000Z","dependencies_parsed_at":"2023-08-16T13:50:37.847Z","dependency_job_id":null,"html_url":"https://github.com/FloSewn/tmesh","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/FloSewn/tmesh","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FloSewn%2Ftmesh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FloSewn%2Ftmesh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FloSewn%2Ftmesh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FloSewn%2Ftmesh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FloSewn","download_url":"https://codeload.github.com/FloSewn/tmesh/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FloSewn%2Ftmesh/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278717433,"owners_count":26033539,"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","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["advancing-front","cfd-mesh","fem-mesh","mesh-generation","triangle-mesh","triangulation"],"created_at":"2024-11-10T07:20:32.270Z","updated_at":"2025-10-07T03:42:17.985Z","avatar_url":"https://github.com/FloSewn.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TMesh\n-----------------------------\n\u003cimg src=\"doc/images/tMesh.png\" alt=\"tMesh-Grid\" width=\"500\"/\u003e\n\n\n**TMesh** is a small program to create two-dimensional triangular grids, which can \nbe used for Finite Element Methods or Computational Fluid Dynamics applications.\nThe triangles are generated with an advancing-front method, for which the user must only provide edge segments that define the boundaries of the domain. Furthermore it is possible to refine \ntriangles locally with a user-defined size function.\n\n## Installation\n**TMesh** is just base on the static library **libtmesh.a**, generated in the *lib*-directory of this repository. \nIt is automatically created upon compilation with cmake.\nFor installation, just create a build directory and run\n```sh\ncmake ..\nmake install\n```\n\n## Usage of TMesh\n**TMesh** takes a parameter-file as input for the mesh generation. Sample files are given in *share/files/*.\nBasically, one only needs to define a few global parameters and the mesh boundaries in terms\nof boundary nodes and edges. \nThere is the possibility to assign markers to the boundaries and to each boundary-edge.\nThe only purpose of these markers is to identify these boundaries/edges later when the meshing is generated.\nHere is a simple example to create a mesh using **TMesh**:\nIt is even possible to provide simple size function expressions through the input file.\n```sh\n#-----------------------------------------------------------\n#                          TMESH\n#-----------------------------------------------------------\nGlobal element size: 0.5\nNumber of quadtree elements: 50\nMesh bounding box: -10.0, -10.0, 20.0, 20.0\nSize function: 0.5-0.43*exp(-0.03*((1.-x)*(2.-x)+(9.-y)*(9.-y)))\n\n\n#-----------------------------------------------------------\n#                          NODES\n#-----------------------------------------------------------\nDefine nodes:\n1.0, 1.0\n10.0, 0.0\n10.0, 10.0\n0.0,  10.0\n2.0,  2.0\n2.0,  4.0\n4.0,  4.0\n4.0,  2.0\n6.0,  5.0\n7.0,  7.0\n9.0,  4.0\nEnd nodes\n\n#-----------------------------------------------------------\n#                          BOUNDARIES\n#-----------------------------------------------------------\n# For every boundary an integer is assigned as marker.\n# Boundary edges are defined by:\n#\n#     iStart, iEnd, edgeMarker, edgeRefinement\n#\n# \u003e iStart and iEnd corresponds to the indices of the\n#   nodes define above\n# \u003e edgeMarker is an integer that is assigned to the\n#   respective edge\n# \u003e edgeRefinement is a double used to control the local\n#   refinement near share edges (\u003e0)\n#\n# \u003e Exterior boundaries must be defined counter-clockwise\n# \u003e Interior boundaries must be defined clockwise\n#\n#-----------------------------------------------------------\nDefine exterior boundary: 1\n0, 1, 0, 1.4\n1, 2, 0, 1.4\n2, 3, 0, 1.4\n3, 0, 0, 1.4\nEnd exterior boundary\n\nDefine interior boundary: 1\n4, 5, 1, 1.6\n5, 6, 1, 1.6\n6, 7, 1, 1.6\n7, 4, 1, 1.6\nEnd interior boundary\n\nDefine interior boundary: 2\n8, 9, 2, 1.5\n9, 10, 2, 1.5\n10, 8, 2, 1.5\nEnd interior boundary\n```\n\nThe mesh is created with \n```sh\n./bin/TMesh example.para\n```\nHere is the generated mesh:\n\u003cimg src=\"doc/images/TMeshExample.png\" alt=\"Example-Grid\" width=\"500\"/\u003e\n\n## Create a plot of your mesh\nThe python script `share/python/plot_mesh.py` can create simple mesh plots from TMesh's output.\nSimply write TMesh's output to a text file \n\n```sh\n./bin/TMesh example.para \u003e your_mesh.txt\n```\n\nand then run the Python script with\n\n```sh\npython share/python/plot_mesh.py your_mesh.txt your_meshplot.png\n```\n\n## Usage of C-Functions\nA detailed description on how to define a mesh is given in the examples under \n*src/tmesh/test*.\n\nEvery mesh is defined by an exterior boundary and several more interior boundaries.\nThese boundaries consist of edge segments, which connect two nodes.\nBesides this, it is also necessary to provide a size-function `size_fun` to the mesh, which\ndefines the local element size in the domain.\nFirst, create a new mesh object:\n```sh\ntmMesh *mesh = tmMesh_create(xy_min, xy_max, N, size_fun);\n```\nHere, `xy_min` and `xy_max` define the bounding box of the entire domain, `N` is the number of elements that are stored in the underlying quadtree structure until a quad is refined.\nNext, define some vertices for the exterior boundary:\n```sh\ntmNode *n0 = tmNode_create(mesh, xy0);\ntmNode *n1 = tmNode_create(mesh, xy1);\ntmNode *n2 = tmNode_create(mesh, xy2);\n```\n`xy0`, `xy1`, `xy2` define the node coordinates, e.g. `tmDouble xy0[2] = { -1.0, -1.0 };`.\nNow create the exterior boundary and add the edge segments to it.\n**IMPORTANT**: Exteriror boundary edge segments must be defined in a **counter-clockwise** manner, such that all edge normals point to the inside of the domain.\n```sh\ntmBdry *bdry_ext = tmMesh_addBdry(mesh, FALSE, 0);\ntmEdge *e0 = tmBdry_edgeCreate(bdry_ext, n0, n1, 0, 1.0);\ntmEdge *e1 = tmBdry_edgeCreate(bdry_ext, n1, n2, 0, 1.0);\ntmEdge *e2 = tmBdry_edgeCreate(bdry_ext, n2, n0, 0, 1.0);\n```\nInterior boundaries are defined in a similar manner, but the segments must be defined in  **clockwise** direction. \n```sh\ntmNode *n3 = tmNode_create(mesh, xy3);\ntmNode *n4 = tmNode_create(mesh, xy4);\ntmNode *n5 = tmNode_create(mesh, xy5);\n\ntmBdry *bdry_int = tmMesh_addBdry(mesh, TRUE, 1);\ntmEdge *e3 = tmBdry_edgeCreate(bdry_int, n3, n4, 1, 1.0);\ntmEdge *e4 = tmBdry_edgeCreate(bdry_int, n4, n5, 1, 1.0);\ntmEdge *e5 = tmBdry_edgeCreate(bdry_int, n5, n3, 1, 1.0);\n```\nFinally, the advancing-front meshing is performed using\n```sh\ntmMesh_ADFMeshing(mesh);\n```\nThe final mesh can be printed to the command line with\n```sh\ntmMesh_printMesh(mesh);\n```\nand the output of this function can be rendered with a small Python script **plot_mesh.py**,\nwhich is located in the directory *share/python*.\n\n\u003cimg src=\"doc/images/exampleMesh.png\" alt=\"Example-Grid\" width=\"500\"/\u003e\n\n### Custom Element Sizing\nThe local element size can either be defined through a size function defined by the user or  \nby the boundary edges. Elements near sharp angles are automatically refined.\n\n\u003cimg src=\"doc/images/bdrySizeFun.png\" alt=\"SizeFunction\" width=\"500\"/\u003e\n\n## Benchmarks\n\u003cimg src=\"doc/images/qtree.png\" alt=\"tMesh-Grid\" width=\"500\"/\u003e\n\n**TMesh** uses an adaptive quadtree structure to store vertices, edges and triangles in an accessible way. This allows to find any existing object in the meshing process with an average complexity of N log.\nThe quadtree is refined and coarsened automatically as objects are inserted or removed from the structure. \n\nFor profiling of a test-binary:\n* Compile with `-pg` (default in debugging mode)\n* Run the test binary \n* Profile with: `gprof test gmon.out \u003e prof_output`\n\n ### Qtree search benchmark\n Here's a short benchmark of the underlying quadtree structure. Its the output from the test-function `test_tmQtree_performance()` for various numbers of vertices.\n| Nodes        | Qtree        | Brute Force  |\n| :----------: | :----------: | :----------: |\n|        10000 |        0.0 s |        0.6 s |\n|        20000 |        0.1 s |        2.6 s |\n|        30000 |        0.3 s |        8.2 s |\n|        50000 |        0.8 s |       38.4 s |\n|       100000 |        3.5 s |      371.7 s |\n\n\n### Triangular mesh generation benchmark\nThis plot shows the performance of **TMesh** for the generation of to simple meshes, \ndefined in the test function `test_tmFront_simpleMesh2()` and `test_tmBdry_sizeFun()`.\n\n\u003cimg src=\"doc/images/performance.png\" alt=\"tMesh-Grid\" width=\"500\"/\u003e\n\n## Todos\n* Python-Interface \n* Delaunay-refinement for generated grids\n* Better output format of generated meshes, e.g. HDF5 or netCDF.\n\n## Used Libraries \n* [The Better String Library](http://bstring.sourceforge.net)\n* [TinyExpr](https://github.com/codeplea/tinyexpr)\n* Some snippets from Zed Shaw's [Learn C the hard way](https://github.com/zedshaw/learn-c-the-hard-way-lectures)\n\n## Sources\n* o'Rourke, Joseph. Computational geometry in C. Cambridge university press, 1998.\n* [Shewchuk, Jonathan R. Lecture Notes on Delaunay Mesh Generation, February 5, 2012](https://people.eecs.berkeley.edu/~jrs/meshpapers/delnotes.pdf)\n* [Jonathan R. Shewchuk's free course material on Mesh Generation and Geometry Processing in Graphics, Engineering, and Modeling ](https://people.eecs.berkeley.edu/~jrs/mesh/)\n* Lo, Daniel SH. Finite element mesh generation. CRC Press, 2014\n* Blazek, Jiri. Computational fluid dynamics: principles and applications. Butterworth-Heinemann, 2015\n* Zed A. Shaw, Learn C the Hard Way (this is where the testing structure and the list functions are coming from)\n\n## License \nThe project is licensed under the MIT License - see the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflosewn%2Ftmesh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflosewn%2Ftmesh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflosewn%2Ftmesh/lists"}