Dear Zhou,
My idea was slightly different in fact (because the level-set mode of Mmg modify the entire mesh, if you call it, your far region will be remeshed).
In pseudo-C code I was thinking to something like that (I suppose that the near region is between level-set -0.5 and 0.5):
MMG2D_loadMesh(mesh,filename);
MMG2D_loadSol(mesh,levelset,filename);
/* Get number of vertices and triangles of the mesh */
int nVert,NTria;
MMG2D_Get_meshSize(mesh,&nVert,&nTria,NULL);
/* Store the level-set in a local array 's' */
double s[nVert];
MMG2D_Get_scalarSols(levelset,s);
/* Travel the triangles: if one vertex has a level-set value greater than 0.5 or lower than -0.5, mark the triangle as required (far region) */
for ( k=1; k<=nTria; ++k ) {
int v0,v1,v2;
MMG2D_Get_triangle(mesh,&v0,&v1,&v2,NULL,NULL);
if ( (fabs(s[v0]) > 0.5) || (fabs(s[v1]) > 0.5) || (fabs(s[v2]) > 0.5) ) {
MMG2D_Set_requiredTriangle(mesh,k);
}
}
What is not really convenient in this program is that we have to store locally the level-set because Mmg doesn’t provide a getter by id for the solution (I keep note that it would be useful).
For now we don’t have API to mark a specific region. If you are interested to contribute to Mmg and to write it, I will be happy to help you ;-).
You can also create a github ticket (I can’t promise that it will be done in a short time though).
Mmg in freefem++
Regarding freefem++, I think that it uses only the 3D and surfacic version of Mmg (because freefem has its own 2D remesher).
For now, in 3D, you can specify only boundary elements (triangles) as required. An example on how to set all the triangles of reference 2 as required is given in FreeFem-sources/laplace-adapt-3d-PETSc.edp at master · FreeFem/FreeFem-sources · GitHub
To get back to your 2D test case, I think that you can use the trunc
function of freefem++ to split your mesh into 2 submeshes. Then you can remesh one of the submesh (without modifying the boundaries) and merge again the 2 submeshes.
Something like that:
Th3 = trunc(Th,region==3);
Th2 = trunc(Th,region==2);
/* If you want to remesh only Th2 */
Thadp = adaptmesh(Th2,...);
/* Merge meshes and store result in Th2 */
Th2 = Thadp + Th3;
Regards,
Algiane