Mesh generation in 2D

Once the input mesh has been read by the appropriate function (depending on mesh file format), if no triangles have been found (i.e. mesh->nt = 0), mesh generation mode is triggered first, using function:

int MMG2D_mmg2d2(MMG5_pMesh mesh,MMG5_pSol sol);

In this case, the input mesh file contains at least a set of points, and possibly a set of edges connecting some or all of these points. The objective of this function is to insert all these points in the mesh first, regardless of the provided edges. Secondly, it checks whether the edges are present in the produced mesh and enforces them if necessary.

Point insertion

The first step consists in creating the four points of the bounding box, which hold the following coordinates:

\[\begin{split}\begin{align} &P_1 (-0.5;-0.5),\\ &P_2 (-0.5;\frac{1}{\Delta}(M_1 - m_1) + 0.5),\\ &P_3 (\frac{1}{\Delta}(M_0 - m_0) + 0.5);-0.5),\\ &P_4 (\frac{1}{\Delta}(M_0 - m_0) + 0.5);\frac{1}{\Delta}(M_1 - m_1) + 0.5).\\ \end{align}\end{split}\]

where:

  • \(M_i\) is the largest \(i^{th}\) coordinate in the input mesh (corresponds to mesh->info.max[0:1] in the source code).

  • \(m_i\) is the smallest \(i^{th}\) coordinate in the input mesh (corresponds to mesh->info.min[0:1] in the source code).

  • \(\Delta = \max\limits_i{(M_i - m_i)}\) (corresponds to mesh->info.delta in the source code).

Two triangles are then created with these four points. By construction, all input points belong to this bounding box. Point insertion routine is then performed by calling the function:

int MMG2D_insertpointdelone(MMG5_pMesh mesh,MMG5_pSol sol);

This function performs a loop over all input points and attempts to insert them using the Delaunay method. For every input point, this iterative procedure consists in listing all the triangles in the mesh whose circumscribed circle contains the point and delete them, to replace them with new triangles that possess the current point as a vertex.

For a given input point \(k\), the procedure goes as follows:

  • Identify one triangle that contains the point, using function:

    static inline MMG5_int MMG2D_findTria_exhaust(MMG5_pMesh mesh,MMG5_int k);
    

    and storing it in list[0].

  • Create the cavity of point \(k\):

    int MMG2D_cavity(MMG5_pMesh mesh,MMG5_pSol sol,MMG5_int k,MMG5_int *list);
    

    This step consists in travelling the whole mesh by adjacency, starting from list[0]. All the triangles of the mesh such that their circumscribed circle contains point \(k\) are added to list[].

  • Effectively insert the point calling function:

    int MMG2D_delone(MMG5_pMesh mesh,MMG5_pSol sol,MMG5_int k,MMG5_int *list,int ilist);
    

    This function counts the number of external faces of the cavity (ilist), which corresponds to the number of triangles that will be deleted, which is also equal to the number of triangles that will be created. For every triangle in list, a new triangle containing the corresponding external face of the cavity and point \(k\) is created. Then, adjacencies are updated and old triangles (elements of list) are deleted.

Once the whole list of input points has been processed, if some points were not able to be inserted, insertion is attempted by calling function:

int MMG2D_splitbar(MMG5_pMesh mesh,MMG5_int k,MMG5_int ip);

To do so, a loop over remaining points is performed. Similarly to the previous step, for a point \(k\):

  • Identify a triangle that contains the point with MMG2D_findTria_exhaust.

  • Call function MMG2D_splitbar to split the triangle in three new triangles.

  • Update adjacency.

Boundary enforcement

Once all points are inserted, user-provided edges are enforced by calling function:

int MMG2D_bdryenforcement(MMG5_pMesh mesh,MMG5_pSol sol);

This function is comprised of two steps:

  1. Loop over all user-provided edges and check whether or not they are present in the mesh.

  2. If some edges are missing, enforce them. To do so, it is necessary to identify all the triangles that are intersected by this edge. Once the list of intersected triangles is complete, the function performs a series of swap until the edge exists in the mesh.

Post-generation treatment

To conclude the mesh generation section, several operations are performed on the produced mesh. First, mesh validity is checked by calling:

int MMG5_mmg2dChkmsh(MMG5_pMesh mesh, int severe,MMG5_int base);

Then, if edges have been provided by the user, the following function is called:

int MMG2D_markSD(MMG5_pMesh mesh);

This function assigns material references to triangles according to the connected components delimited by the edges. It then deletes all triangles from the bounding box.

Howver, if there are no edges in the mesh, the only action that is performed is the removal of triangles from the bounding box:

  1. Triangles that posses one point of the bounding box as a vertex are tagged by calling function:

    int MMG2D_settagtriangles(MMG5_pMesh mesh,MMG5_pSol sol);
    
  2. Such bounding box triangles are removed by calling:

    int MMG2D_removeBBtriangles(MMG5_pMesh mesh);