Using the Medit file format (.mesh/.sol) or the API functions
Matrix flattening into a vector
Be d the mesh dimension and the metric that we want to impose at the 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 using the following convention:
Be very careful, Medit uses a column storage of the upper triangular matrix while Mmg uses a line storage of the same matrix. Thus, the vector stored in the Medit solution file is different from the vector to provide to the Mmg API functions:
Be M an anisotropic metric of size 1 en every direction (so the metric is isotropic but stored in an anisotropic way):
In the .sol file at Medit file format, we will store V = (1,0,1,0,0,1) while you must provide to the Mmg APIs V = (1,0,0,1,0,1).
Anisotropic metric prescription at mesh nodes
Be the flattened metric that we want to prescribe at the mesh node and nbvals the number of mesh nodes.
There is two ways to provide your metrics: using a solution file at the medit format (for command line interface) or using the API function (for library users).
Using an input file at medit format (.sol extension)
The medit solution file describes the metric precision, dimension, size and type (in the following example, the user must fill the fields in italic and comments must be removed):
MeshVersionFormatted nprec # nprec=1: simple precision, nprec=2: double precision Dimension d # metric dimension: must match with the mesh dimension SolAtVertices # For now, Mmg works only with metrics defined at mesh vertices nbvals # number of metrics: must match with the number of nodes in the mesh file 1 3 # number of solutions per node (always 1 for Mmg) and type of each solution (1:scalar, 2:vector, 3:tensor). Note that vectors can not be used to prescribe a size map. # metric at first node # metric at second node ... # metric at last node End
Using the API functions
We suppose here that we want to adapt a three-dimensional volumic mesh, thus we call the Mmg3d library.
We call mmgMesh the mesh structure at the Mmg format and mmgSol the metric structure at the Mmg format.
In a first step, we must give the solution size and type:
if ( MMG3D_Set_solSize(mmgMesh,mmgSol,MMG5_Vertex,nbvals,MMG5_Tensor) != 1 ) exit(EXIT_FAILURE);
MMG5_Vertex is keyword to say that the metrics are provided at mesh nodes (mandatory for now) and MMG5_Tensor a keyword to specify that we want to impose a tensorial metric at nodes (note that we don’t need to specify the metric dimension because this information is redundant with the mesh dimension).
In a last step, we can provide the metric at each node:
for ( i=1; i<=nbvals; ++i ) if ( MMG3D_Set_tensorSol(mmgSol, ,i) != 1 ) exit(EXIT_FAILURE);
Using the Gmsh file format (.msh)
Be d the mesh dimension, the metric that we want to impose at the mesh node and nbvals the number of mesh nodes.
you can prescribe your sizemap using the NodeData field of the gmsh file format. For a complete description of this field, you can refers to the gmsh documentation.
For now, the number of string data must be exactly 1. This string is used as name for your size map. The number of real tags must be exactly 1 too (its value is ignored by Mmg). And the number of interger tags must be 3:
- the time step (ignored by Mmg);
- the type of data (1 for scalar data, 3 for vectorial ones and 9 for tensorial ones). Note that vectors can not be used to prescribe a size map;
- the number of data (it must be the same number than the number of mesh nodes).
In the following example, the user must fill the fields in italic 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 nbvals # number of mesh vertices # index of the first node, x-coordinate, y-coordinate, z-coordinate # index of the second node, x-coordinate, y-coordinate, z-coordinate ... # index of the last node, x-coordinate, y-coordinate, z-coordinate $EndNodes $Elements nbelts # number of mesh elements # 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 ... # index of the last element ... $EndElements $NodeData # For now, Mmg works only 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 # 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 # metric at first node # metric at second node ... # metric at last node $EndNodeData