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 lower triangular part of M to Mmg. We flatten this lower triangular matrix to a vector using the following convention:
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) # 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);