Level set discretization with existing refs


Hi all,

First I would like to thank you for sharing this very useful and powerful remeshing software.
Now here is my problem:
As input, I have a 2D or 3D volume mesh with different subdomains, that I tag with what you call “refs”.
If I use mmgd2dlib or mmg3dlib, these refs are preserved correctly, and I can recover them when I do Get_triangle or Get_tetrahedron.
But when I do mmg3dls (mmg2dls does not seem to be implemented, am I right?), the refs seem to be ignored. New refs are generated for the new interface, which seems to be 2 inside and 3 outside.
How can I preserve old interfaces while adding a new one with mmg3dls?
If not possible easily, is there a workaround that I could use, for instance by fixing all boundaries between existing refs, and then updating the refs manually? If so, will the new ref always be 2?

Thank you



Thank you for using the Mmg platform.

You are right, the level-set discretization is not yet available for mmg2d. It will be a part of the next release (5.3.0). Until the next release, you can use mmgs to discretize your level-set (since the release 5.2.0). You just need to define your 2D mesh as a 3D surface mesh.

When discretizing an implicit function, mmg3d remove the old references to create two new domains whose interface are the level-set value that you want to discretize. The new references are always 2 inside the domain and 3 outside.

I think that there is no way for now to preserve the initial domain references with mmg3d. The problem is that we are not able, for now, to preserve triangles at the interface of two domains of same reference.

Note that it is possible to keep your initial references with mmgs using the -keep-ref option:

mmgs_O3 -ls -keep-ref initmesh.mesh

In this case, the new mesh contains the old domains and the edges discretized from the level-set. This new edges are created with the reference 0.

Best Regards,



Hello Algiane,

Thank you for your help.

If I understand well, for the 2D version, I could use mmgs with ls option, which is for discretization of polylines on 3D surfaces. By adding the keepRef option, I would be able to keep old references, and update these references myself based on edge tags.

For a more general 2D/3D manner, could I instead use the noswap, nomove (and nosurf?) options?
My idea is that then the mapping between old mesh and new mesh would be conservative, and I would be able to map old tags and “intersect” them with mmg’s 2 and 3.
I would then use mmg2dlib/mmg3dlib to adapt this mesh with new tags.
Would that work?

Best regards


Dear Mods,

I think that your idea must work:

  • The nomove, noswap and noinsert options have only effects on the mesh improvement step (not on the level-set discretization step), thus, using the nomove, noswap and noinsert options, you will obtain your initial mesh with a thin layer of new elements around the discretization of the level-set function.

  • You can map your initial tags over the new mesh but you must be able to find which tag to apply at the new elements.

  • Moreover, you will need to apply a new tag at the elements between your old domains interface and the new one (because Mmg can’t preserve the surfaces at the interface of 2 domains of same reference).

  • You can then use Mmg to improve your mesh quality. (You may obtain a poor mesh quality if the 2 interfaces are too close to each other).

  • Last, you can apply the suitable tags to the elements marked with the new tag and recover your initial domains.

Best Regards,




I have implemented this method and it works.
Thank you for your help.

Best regards,



Then I close this topic.

Have a nice Day.