This page describes how to use the tools dedicated to mesh adaptation using the Mmg remeshing library (http://www.mmgtools.org/).

**Currently the solvers are compatible with version 5.2.6 (https://github.com/MmgTools/mmg/releases)
**

Using the remeshing solver require to install Mmg and provide the direction to the header files and library using the CMake arguments “MMG_INCLUDE_DIR” and “MMG_LIBRARY”:

cmake -DMMG_INCLUDE_DIR=/path/to/MmgInstallDir/include \ -DMMG_LIBRARY=/path/to/MmgInstallDir/lib/libmmg.a

Make sure that Mmg has been compiled using the `-fPIC`

flag in order to be able to be linked to Elmer. You can achieve that for instance by providing a cache-file to the cmake building process of Mmg

SET(CMAKE_C_FLAGS "-fPIC" CACHE STRING "") SET(CMAKE_CXX_FLAGS "-fPIC" CACHE STRING "") SET(CMAKE_Fortran_FLAGS "-fPIC" CACHE STRING "")

Examples can be found under the test directories “MMG2D_Aniso1”, “MMG2D_Aniso2” and “MMG2D_Iso”.
These tests have the label *elmerice-fast* and can be executed alone using

ctest -L mmg

The metric * M* , used to define the element size, derives from a geometric error estimate based on an upper bound for the interpolation error of a continuous field to piecewise linear elements (Frey and Alauzet, 2005).

For a variable *v*, * M* depends on the eigenvalues and eigenvector matrix

with and

where

- is a geometric constant equal to 2/9 in 2D
- (resp. ) is a prescribed minimal (resp. maximal) edge size
- is the prescribed maximum error

Computing second derivatives in linear elements in not straightforward. Following Buscaglia and Dari (1997), this is done in two steps:

- First, we compute the nodal gradient using the Compute2DNodalGradient Solver
- Second, we compute the hessian matrix
by solving the diffusive equation , where is a diffusivity proportionnal to the local element size. The metric**H**is then computed from Eq. (1). This is done using the MMG2D_MetricAniso Solver.**M**

Sometimes it can be desirable to use several variables to compute the metric, if we want, for example, to capture with the same mesh different physical phenomena represented by different variables.

The intersection of two metrics * M_1* and

with the matrix where the columns are the normalised eigenvectors , of and .

Nodal values of are computed using the MMG2D_MetricIntersect Solver.

The mesh adaptation step is performed using the Mmg 2D library.

The MMG2DSolver Solver pass the mesh topology and required (isotropic or anisotropc) metric to the library then create the new mesh structure from the adapted mesh returned by the library.

During a transient simulation the progression of a physical phenomena, *e.g.* the location of the grounding line, in the computational domain is usually not known in advance.

If the mesh has been adapted using informations available at time *t*, the mesh may not be optimal anymore at time *t+n.dt*. Keeping a mesh sufficiently refined in areas where the physical phenomena progress requires to adapt the mesh frequently, introducing additionnal interpolation errors when solutions are transfered to the adapted meshes.

The metric intersection formula given above allows to compute a metric map that contain informations at different time-steps. Iteratively solving the transient problem allows to adapt and refine the mesh in all regions where the phenomena progress.

The algorithm described in Alauzet *et al.* (J. Comp. Phys., 2007) has been implemented using a bash script that allows to iterate .sif files for the physical transient simulation and the mesh adaptation. Details are given here

- An example for isotropic mesh adaptation can be found under
- [ELMER_TRUNK]/elmerice/Tests/MMG2D_Iso

- Examples for anisotropic mesh adaptation where the mesh size is adapted using 1 or 2 variables (i.e. combining metric informations) can be found under :
- [ELMER_TRUNK]/elmerice/Tests/MMG2D_Aniso1
- [ELMER_TRUNK]/elmerice/Tests/MMG2D_Aniso2

- An example for transient mesh adaptation can be found under
- [ELMER_TRUNK]/elmerice/Tests/MMG2D_Transient