Mesh adaptation

This section describes the adaptation routine in mmg2d. In all modes (mesh generation, mesh adaptation, isosurface discretization and lagrangian movement), mesh adaptation is performed by the function:

int MMG2D_mmg2d1n(MMG5_pMesh mesh,MMG5_pSol met);

Step 1: Creation of a geometric mesh

The first step of mesh adaptation is performed by the following function:

int MMG2D_anatri(MMG5_pMesh mesh,MMG5_pSol met,int8_t typchk);

In this first call to this function, typchk is set to 1. This variable indicates which kind of criterion is considered when computing edge lengths. With typchk = 1, length criteria are based on the actual length of the edges, whereas typchk = 2 means that edge lengths are computed with respect to the metric prescription.

Function MMG2D_anatri is an iterative procedure where operations are applied as long as:

  • the maximal number of iterations has not been reached

  • at least one modification has been performed on the mesh during the last iteration.

An iteration consists of three sub-steps, each dedicated to one type of mesh modification:

  1. Edge splits, performed by MMG2D_anaelt(MMG5_pMesh ,MMG5_pSol ,int typchk) , where edges that are too long are split by adding a new point along them.

  2. Edge collapses, performed by MMG2D_colelt(MMG5_pMesh mesh,MMG5_pSol met,int typchk), where edges that are too short are deleted.

  3. Edge swaps, performed by MMG2D_swpmsh(MMG5_pMesh ,MMG5_pSol ,int typchk), which does not alter vertex positions, but modifies adjacency relations.

Edge split

This step is performed by calling function:

MMG5_int MMG2D_anaelt(MMG5_pMesh mesh,MMG5_p Sol met,int typchk)

This functions procedes as follows:

  • Step 1: Travel the mesh, compute edge lengths, and tags edges that should be split.

  • Step 2: Make flags consistent over the whole mesh. If an edge is tagged in a given triangle, all other triangles that share this edge should have it tagged as well.

  • Step 3: Simulate splits and cancel those leading to an invalid configuration.

  • Step 4: Perform the actual splits.

Once edge splitting has been done for this iteration, adjacency needs to be updated. This is then done by calling:

int MMG2D_hashTria(MMG5_pMesh mesh);

Edge collapse

The edge collapse step is performed by calling:

MMG5_int MMG2D_colelt(MMG5_pMesh mesh,MMG5_pSol met,int typchk);

Note that both edge splitting and edge collapsing may be skipped by using the -noinsert command line option.

Edge swap

The last substep is done by calling function:

MMG5_int MMG2D_swpmsh(MMG5_pMesh mesh,MMG5_pSol met,int typchk)

This step may be skipped by using the -noswap command line option.

Step 2: Creation of a computational mesh

The second step of mesh adaptation consists in calling the same function MMG2D_anatri as in the previous step, with typchk = 2. This implies that a metric must be prescribed. To do so, several functions are used to define and compute metric data.

Firstly, a size map needs to be computed. By default, an isotropic size map is computed. This is done by calling the function:

int MMG2D_defsiz_iso(MMG5_pMesh ,MMG5_pSol );

In the case where anisotropic mode is activated (by specifying an anisotropic input metric or by activating the mode via the API), the following function is called instead:

int MMG2D_defsiz_ani(MMG5_pMesh ,MMG5_pSol );

If the gradation option has been activated (using the command line tool -hgrad), gradation will be enforced through the size map by calling either:

int MMG5_gradsiz_iso(MMG5_pMesh ,MMG5_pSol );

or:

int MMG2D_gradsiz_ani(MMG5_pMesh ,MMG5_pSol );

Then, gradation over required points is dealt with by using the two functions:

int MMG5_gradsizreq_iso(MMG5_pMesh ,MMG5_pSol );

and:

int MMG5_gradsizreq_ani(MMG5_pMesh ,MMG5_pSol );

Finally, the same adaptation routine as in step 1 may be performed by calling:

int MMG2D_anatri(MMG5_pMesh mesh,MMG5_pSol met,int8_t typchk);

with typchk = 2.

Step 3: Fine mesh improvements

The final step of mesh adaptation is done by calling the following function:

int MMG2D_adptri(MMG5_pMesh mesh,MMG5_pSol met);