zslwyuan / gmsh-doc

How to read the source code of gmsh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Introduction

This is the project used to show the mechanism of gmsh. It can be regarded as a guide to read the source code of gmsh.

I tend to use Doxygen to visualize the overall interaction between functions (just like the BFS algorithm) and use GDB to trace the call stack of the functions (just like the DFS algorithm).

The Doxygen documentation is available here (https://zslwyuan.github.io/gmsh-doc/).

Gmsh's data structures

The geometry module is based on a model class (GModel), and abstract entity classes for geometrical points (GVertex), curves (GEdge), surfaces (GFace) and volumes (GRegion). Concrete implementations of these classes are provided for each supported CAD kernel (e.g. gmshVertex for points in Gmsh’s built-in CAD kernel, or OCCVertex for points from OpenCASCADE). All these elementary model entities derive from GEntity. Physical groups are simply stored as integer tags in the entities.

A mesh is composed of elements: mesh points (MPoint), lines (MLine), triangles (MTriangle), quadrangles (MQuadrangle), tetrahedra (MTetrahedron), etc. All the mesh elements are derived from MElement, and are stored in the corresponding model entities: one mesh point per geometrical point, mesh lines in geometrical curves, triangles and quadrangles in surfaces, etc. The elements are defined in terms of their nodes (MVertex). Each model entity stores only its internal nodes: nodes on boundaries or on embedded entities are stored in the associated bounding/embedded entity.

How a geo file is loaded into gmsh

main()
 -> GmshMainBatch()
  -> GmshBatch()
  -> GmshInitialize() which resets all the parameters to defaul values
   -> OpenProject() which will load the input file
    -> GModel::readGEO()
     -> ParseFile()
      -> gmsh_yyparse() which is implemented at Gmsh.tab.cpp:6741 and it will parse the file and add the following internal components for the current model
       -> GModel::current() -> GModel::getGEOInternals() -> GEO_Internals::addVertex()   GEO_Internals::addLine()   GEO_Internals::addSpline()   GEO_Internals::addCompoundSpline()   GEO_Internals::addCompoundBSpline()   GEO_Internals::addCircleArc()   GEO_Internals::addEllipseArc()   GEO_Internals::addEllipseArc()   GEO_Internals::addBSpline()  GEO_Internals::addBezier()   GEO_Internals::addBSpline()   GEO_Internals::addCurveLoop()   GEO_Internals::addPlaneSurface()   GEO_Internals::addSurfaceFilling()   GEO_Internals::addSurfaceFilling()   GEO_Internals::addSurfaceLoop()   GEO_Internals::addVolume()   GEO_Internals::addDiscreteSurface();  
      -> GModel::current() -> GModel::getGEOInternals() -> GEO_Internals::synchronize() this function will synchronize the elements in GEO_Internals with the entities in GModel (from GEO types to gmsh types)
   ->GModel::current()->mesh() this function will mesh the model

How a GModel get meshed in 0D/1D/2D

main()
 -> GmshMainBatch()
  -> GmshBatch()
   -> GModel::mesh()
    -> GenerateMesh()
     -> SetOrder1() this function reset high-order elements to elements with the order of 1
     -> FixPeriodicMesh() don't know its usage temporarily
     -> Mesh0D() which initializes the mesh vertexes for later processing
     -> Mesh1D() which mainly meshes the GEdge
      -> GEdge::mesh() which mainly meshes the GEdges
       -> meshGEdge::operator()()
        -> meshGEdgeProcessing()
         -> Integration() and RecursiveIntegration() which will utilize bi-section approaches to mesh GEdge based on given constraints, such as mesh size (!! "lc" in the code means characteristic length or mesh size ), and the integration can be regarded as side products.
     -> Mesh2D() which mainly meshes the GFace
      -> GFace::mesh() which mainly meshes the GFaces
       -> meshGFace::operator()() which can define the mesh algorithm (default: Frontal-Delaunay)
        -> meshGenerator()
         ->GFaceInitialMesh() which splits a face into delaunay triangles
         ->bowyerWatson() and bowyerWatsonFrontal() which splits a face into delaunay triangles maybe refer to: https://www.bilibili.com/video/BV1QB4y1S7RK/?share_source=copy_web&vd_source=acff9de7d590c26061bcce92dfc8206d

How a GModel get meshed in 3D

main()
 -> GmshMainBatch()
  -> GmshBatch()
   -> GModel::mesh()
    -> GenerateMesh()
     -> Mesh3D() which mainly meshes the GRegion
      -> MeshDelaunayVolume()
       -> insertVerticesInRegion() maybe refer to : https://www.kiv.zcu.cz/site/documents/verejne/vyzkum/publikace/technicke-zpravy/2002/tr-2002-02.pdf

About

How to read the source code of gmsh

License:Other


Languages

Language:C++ 78.1%Language:C 12.2%Language:Fortran 4.1%Language:Python 1.7%Language:CMake 1.0%Language:Julia 0.7%Language:Yacc 0.5%Language:Cuda 0.3%Language:Java 0.3%Language:Objective-C++ 0.3%Language:GLSL 0.2%Language:Shell 0.1%Language:Makefile 0.1%Language:TeX 0.1%Language:Perl 0.1%Language:SWIG 0.1%Language:MATLAB 0.1%Language:Lex 0.0%Language:HTML 0.0%Language:JavaScript 0.0%Language:POV-Ray SDL 0.0%Language:Roff 0.0%Language:Objective-C 0.0%Language:XSLT 0.0%Language:Scilab 0.0%Language:CSS 0.0%Language:Gnuplot 0.0%Language:Jolie 0.0%Language:Batchfile 0.0%