Remesh only one subdomain

Dear MMG community,

I have a test.msh file (attached to this post) containing a mesh with two subdomains (tagged 10 and 20) and I would like to remesh only the subdomain with label 10. As far as I understand, it is possible to do so using the MMG3D_Set_requiredTetrahedron function. But, first, I am not even capable of getting the reference label of each tetraheron from the loaded mesh.

This is what I have tried in my testmmg.c file (attached to this post) to print the label of each tetrahedron:

ier = MMG3D_Get_meshSize(mmgMesh,&np,&ne,NULL,&nt,NULL,&na);
printf("Nb of Tetra : %d\n", ne);
for (int i=0; i<ne; i++)
    MMG5_pTetra pt;
    pt = &mmgMesh->tetra[i];
    if (pt->ref>0)

But it prints very big integers, not the tags I have set with GMSH.

Any help would be appreciate.


testmmg.c (5.7 KB)

test.msh (223.2 KB)


The element numbering goes from 1 to the number of tetra (included) in Mmg. Otherwise your program should work (it prints elements of ref 10 and 20 on my laptop).
If your problem persist, you can try to check:

  • that you are using the last release of Mmg;
  • what are saying memory tools such as AdressSanitizer or Valgrind.

Hope that it will help,


Hello Algiane,

Thank you for your help ! It seems the problem was due to my mistake in the element numbering (sorry about that… :confused: ) since the following code works perfectly.


int k;
for ( k=1; k<=ne; ++k ) {
    /* Get the ref of the k^th tetra */
    int ref,dummy;
    if ( MMG3D_Get_tetrahedron(mmgMesh,&dummy,&dummy,&dummy,&dummy,
                        &ref,NULL) != 1 ) {
    /* if this ref is 20, mark the triangle as required */
    if ( ref == 20 ) {
        if ( MMG3D_Set_requiredTetrahedron(mmgMesh,k) != 1 ) {

Thank you for this feedback!