Localized meshing on a moving boundary

Greeting!

I have a problem with localized meshing on a moving boundary.

I want to use mmg2d to only refine the mesh near level set function (basically, it’s an area defined by a distance function of the 0 level set surface). Is there any way to realize the localized meshing refinement? It is preferred if the solution can be utilized on a moving boundary because my level set function needs to be updated during optimization.

Thank you very much.

Hi and welcome Zhou,

If I understand, you want to remesh only in a small area around your level-set?

If yes and if you are using Mmg in library mode, you can use required triangles to ensure that Mmg doesn’t modify the far field. A simple way is:

  • to choose a level-set ls value sufficiently large enough to be considered as the far-field;
  • to travel the triangles of your mesh and to mark the triangle as required if all its vertices have a level-set value greater than ls (using the MMG2D_Set_requiredTriangle API function);

You just have to ensure that the chosen threshold for the far-field allow to have multiple layers of triangles that Mmg can remesh (otherwise the remeshing sted will be overconstraint).

I hope that it will help,

Algiane

Dear Algiane,

Thank you for your suggestion and prompt reply.

I tried your concept by using implicated meshing and the geometry was divided into the near region and far region with region ID 3 and 2 respectively.

It is a great idea to use the MMG2D_Set_requiredTriangle API function that you mentioned, but I did not figure out the way of implementing the API function for each triangle in the far region yet. Now I am using Freefem++ as the solver; it will be appreciated if you have some tutorial or user guidance about the implementation.

By the way, is there any API function that can be directly used for a specified region(region 3 in my case) instead of a bunch of triangles?

Thank you very much.

Sincerely,
iso meshing

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

Dear Algiane,

Thank you for your detailed explanation and kind suggestion.

I was hoping to get smooth boundaries around a certain distance from 0 level-set isosurfaces. Inspired by your idea, I might use the distance function instead of the level-set function when traveling the triangles. Additionaly, I have a question about the command MMG2D_Set_requiredTriangle. Because this command may change the total number of nodes on the refined area, can this command guarantee compatibility especially on the boundaries of the far region and near region?

By the way, because I am only focusing on 2D problem at the current stage, I will also try to use the trunc function as you mentioned.

Thank you for your answer and your contribution to such an awesome platform.

Regards,
Jiaxin

Dear Zhou,

Yes, if you set some triangles as “freezed” using the MMG2D_Set_requiredTriangles, Mmg will ensure the mesh compatibility between freezed and non-freezed area (so you have still a conformal mesh of your far and near regions).

In opposite, I think that the trunc function of ff++ splits your mesh in two different parts so you have to freeze the mesh boundaries to ensure the compatibility between the adapted mesh and the other one. But maybe I am wrong, I am not a freefem expert ;-).

Regards,
Algiane

Dear Algiane,

Thank you very much for your answer.

Your suggestion helped a lot. Thank you for your time.

Have a nice day. :smile:

Regards,
Zhou