Anisotropic refinement example


Dear List,

first of all let me tell that i highly praise the MMG initiative. I am really looking forward trying out your code!
To introduce myself, i am one of the main developer of the Kratos Multiphysics code, a finite element code which can deal with immersed CFD.

my starting situation is the following:

i have a good quality tetrahedral initial mesh, obtained by an octtree-like approch. The mesh is conforming. I also have a levelset distance function defined on each node of the mesh, which describes an inner surface, cutting the mesh at arbitrary positions. I DO NOT want to mesh such inner surface, my CFD solver can deal nicely with it.

my wish is to define an anisotropic metric tensor on the basis of the distance function and of its gradients (which are both known to me, either on the nodes or on the initial mesh). To start i would like to try it out by using the command line interface.

do you have any example of how i can achieve this? i saw that your “.sol” file would allow passing a matrix on every node. would that be the way to pass my target metric tensor?
Can u point me to an example?
any hint would be cool.

If possible i will send one of my students, or maybe come myself to your “first MMG user event” so to have a more direct contact



Dear Riccardo,

I’m glad that you are interested in the Mmg project.

To pass an anisotropic metric to Mmg using a .sol, you need to write the lower triangular matrix at each node.

Be M=. I suppose that you want to apply this metric over the 4 node of a tridimensional mesh. You must provide the following solution file (note that comments must be removed):

MeshVersionFormatted 2 # Double precision
Dimension 3

4 # The mesh contains 4 vertices (must match with the information in the mesh file)
1 3 # We give 1 solution per vertex and this solution is of type 3 (it is a tensor).
751 249 751 -352 352 502 # Lower triangular matrix at first vertex
751 249 751 -352 352 502 # Lower triangular matrix at second vertex
751 249 751 -352 352 502 # Lower triangular matrix at third vertex
751 249 751 -352 352 502 # Lower triangular matrix at fourth vertex

You will find attached a cube mesh with the previous constant anisotropic metric applied on each node.
cube.mesh (272.4 KB)
cube.sol (44.3 KB)

I hope this will help you.

Last, we will be very happy to meet you or one of your student during the Mmg day.

Best regards,



Dear Algiane,

thank you very much, this is exactly what i needed. If i may suggest, the thing missing in your documentation is
how to flatten the symmetric matrix to a vector

as i understand from your answer you do it as (assuming i,j start in 0)
00 01 11 02 12 22

i also understand that if v0, v1, v2 are the main axis of the ellipsoid, and h0,h1,h2 are the sizes you whish to achieve, then the matrix you describe would correspond to

1/h0^2 * v0\otimes v0 + 1/h1^2 * v1\otimes v1 + 1/h2^2 * v2\otimes v2

one last question:

what is the “logic” (reference) of a vertex/triangle/tetrahedra??

i mean the value in the last column…



Dear Riccardo,

Thank you for your suggestion, we will add informations about anisotropic metric storage as soon as possible.

You are totally right about the matrix flattening and the sizes and directions prescribed by the matrix.

The reference of a triangle/tetrahedra is an integer that allows to define and/or preserve different domains inside a volume or a surface (for now, the reference of the vertices is not used and not preserved during the remeshing process).

Moreover, the triangle references allow the specification of local parameters (minimal/maximal edge size and hausdorff distance) over different boundaries.