Anisotropic metric prescription

Using Medit file format or API functions

Matrix flattening into a vector

Let \(d\) be the mesh dimension and \(M = (m_{ij})_{1 \leq i,j \leq d} \) the metric that we want to impose at the \(l^{\text{th}}\) mesh node.

M is a metric tensor so it is a symmetric matrix and we can choose to only provide the upper triangular part of M to mmg. We flatten this upper triangular matrix to a vector \(V = (v_i)_{1 \leq i \leq d(d+1)/2}\) using the following convention:

2D

\[V = \begin{array}{} (m_{11} & m_{12} & m_{22}) \end{array}\]

3D

Warning

Be very careful, Medit uses a column storage of the upper triangular matrix while Mmg uses a line storage of the same matrix.

The vector stored in the Medit solution file is different from the vector to provide to mmg API functions:

\[ \begin{align}\begin{aligned}V_{\text{sol file}} = \begin{array}{} (m_{11} & m_{12} & m_{22} & m_{13} & m_{23} & m_{33}) \end{array}\\V_{\text{API}} = \begin{array}{} (m_{11} & m_{12} & m_{13} & m_{22} & m_{23} & m_{33}) \end{array}\end{aligned}\end{align} \]

Example 1

Let \(M\) be an anisotropic metric of size 1 in every direction. This metric is isotropic but is stored in an anisotropic way:

\[\begin{split}M = \begin{pmatrix}{} 1 & 0 & 0\\ 0 & 1 & 0\\ 0 & 0 & 1\\ \end{pmatrix}\end{split}\]

In the .sol file at Medit file format, metric is stored as \(V = (1,0,\textcolor{red}{1,0},0,1)\). In the API, it must be provided as \(V = (1,0,\textcolor{red}{0,1},0,1)\).

Example 2

The prescribed size is the inverse of the square root of the metric eigenvalues. For instance, to impose an anisotropic size of 0.25 along the x-direction, of 10 along the y-direction and 0.5 along the z-direction, the following metric must be provided:

\[\begin{split}M = \begin{pmatrix}{} \frac{1}{25^2} & 0 & 0 \\ 0 & \frac{1}{10^2} & 0 \\ 0 & 0 & \frac{1}{0.5^2}\\ \end{pmatrix} = \begin{pmatrix}{} 16 & 0 & 0\\ 0 & 0.001 & 0\\ 0 & 0 & 4\\ \end{pmatrix}\end{split}\]

Anisotropic metric prescription at mesh nodes

Let \(V_l = (v_{l,i})_{1 \leq i \leq d(d+1)/2} \) be the prescribed flattened metric at the \(l^{\text{th}}\) mesh node and \(\text{nbvals}\) the number of mesh nodes.

There are two ways to provide the metric: using a input file or using the API.

Using an input file at Medit format (.sol extension)

The Medit solution file describes the metric precision, dimension, size and type. Below is an template of such a file.

 1MeshVersionFormatted nprec # nprec=1: simple precision, nprec=2: double precision
 2
 3Dimension d                # metric dimension: must match with the mesh dimension
 4
 5SolAtVertices              # mmg only works with metrics defined at mesh vertices
 6m                          # number of metrics: must match number of nodes
 71 3                        # number of solutions per node and type of each solution
 8
 9v11 v12 ... v1n            # metric at first node
10v21 v22 ... v2n            # metric at second node
11...
12vm1 vm2 ... vmn            # metric at last node
13
14End

The number of solution per node (defined line 7) is always equal to one in mmg. The type of a solution is specified by one of the following values: (1:scalar, 2:vector, 3:tensor). Note that vectors can not be used to prescribe size maps. For this example to work, specific values must be filled in by the user and comments must be removed.

Using API functions

In this example, this objective is to illustrate how to call the mmg3d library to adapt a three-dimensional volumic mesh. mmgMesh denotes the mesh structure and mmgSol denotes the metric structure.

The first step consists in giving the solution size and type:

if ( MMG3D_Set_solSize(mmgMesh,mmgSol,MMG5_Vertex,nbvals,MMG5_Tensor) != 1 )
exit(EXIT_FAILURE);

MMG5_Vertex is keyword specifying that metrics are provided at mesh nodes (which is mandatory). MMG5_Tensor is a keyword that allows to specify that prescribed metric data are tensorial. Note that it is not necessary to specify metric dimension since this information is redundant with mesh dimension.

Then, metric data at each node may be provided:

for ( i=1; i<=nbvals; ++i ) {
    if ( MMG3D_Set_tensorSol(mmgSol,Latex formula,i) != 1 ) exit(EXIT_FAILURE);
}

Using gmsh file format

Let \(d\) be the mesh dimension, \(M = (m_{l_{ij}})_{1 \leq i,j \leq d}\) the metric prescribed at the \(l^{\text{th}}\) mesh node and \(m\) the number of nodes.

In a .msh file, a sizemap may be prescribed using the NodeData field. Please refer to the gmsh documentation for a complete description of this field.

The number of string data must be exactly equal to 1. The corresponding string is used as the name of the size map. The number of real tags must be exactly 1 as well (its value is ignored by mmg). The number of integer tags must be equal to 3:

  • time step (ignored by mmg)

  • type of data (1: scalar data, 3: vectorial data,9: tensorial data). Note that vectors can not be used to prescribe a size map.

  • number of data (equal to the number of mesh nodes).

In the following example, the user must fill in fields and comments must be removed:

$MeshFormat
version-number file-type data-size # version-number (2.2), file-type (0: ASCII), data-size (8: double precision)
$EndMeshFormat

$Nodes
m # number of mesh vertices
id1 x1 y1 z1 # index of the first node, x-coordinate, y-coordinate, z-coordinate
id2 x2 y2 z2 # index of the second node, x-coordinate, y-coordinate, z-coordinate
…
idm xm ym zm # index of the last node, x-coordinate, y-coordinate, z-coordinate
$EndNodes

$Elements
n # number of mesh elements
id1 type1 ntags1 taglist1 nodelist1 # index of the first element, its type (2:tria, 4:tetra, 15:node),
# number of tags (>=2 for Mmg compatibility, the first is used as element reference and must be positive or null, the second is ignored), element connectivity
…
idn typen ntagsn taglistn nodelistn # index of the last element …
$EndElements

$NodeData # mmg only works with metrics defined at mesh vertices
number-of-string-tag # must be 1 for mmg
string # name of the metric field
number-of-real-tags # must be 1 for mmg
real # ignored value
number-of-integer-tags # must be 3 for mmg
val1 # ignored value
metric-type # type of metric ( 1:scalar, 3:vector, 9:tensor)
nbvals # number of metrics: must match with the number of nodes in the $Nodes field
m111 m112 m113 m121 m122 m123 m131 m132 m133 # metric at first node
m211 m212 m213 m221 m222 m223 m231 m232 m233 # metric at second node
…
mm11 mm12 mm13 mm21 mm22 mm23 mm31 mm32 mm33 # metric at last node
$EndNodeData