MmgTools / mmg

open source software for bidimensional and tridimensional remeshing

Home Page:http://www.mmgtools.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MMG takes indefinite time or gets stuck in infinite loop when performing implicit domain meshing

cbritopacheco opened this issue · comments

Environment

OS macOS Big Sur
Compiler AppleClang 13.0.0.13000029
mmg 0b6d864
Build Release and Debug

Problem

MMG2D will take indefinite time to perform the implicit domain meshing of the following input (uploaded with .txt extension because GitHub doesn't let me upload them directly):

Faulty.sol.txt
Faulty.sol.mesh.txt
Faulty.mmg2d.txt

with the following command line

mmg2d -ls -rmc 0.00001 -hmax 0.05 Faulty.sol

Screenshot of .sol plot:

Screenshot 2022-02-09 at 5 05 33 PM

Possible source of the problem

Running lldb on the executable and stopping execution when it gets stuck gives the following frame stack:

frame #2: 0x00000001007e5434 LevelSetCantilever`MMG2D_mmg2d6(mesh=0x000000010d107e18, sol=0x000000010d208cd8, met=0x0000000000000000) at mmg2d6.c:1032:9
   1029	  }
   1030
   1031	  /* Snap values of the level set function which are very close to 0 to 0 exactly */
-> 1032	  if ( !MMG2D_snapval(mesh,sol) ) {
   1033	    fprintf(stderr,"\n  ## Wrong input implicit function. Exit program.\n");
   1034	    return 0;
   1035	  }
(lldb) down
frame #1: 0x00000001007e21a4 LevelSetCantilever`MMG2D_snapval(mesh=0x000000010d107e18, sol=0x000000010d208cd8) at mmg2d6.c:357:15
   354
   355 	      /* Catch a snapped point by a triangle where there is a sign change */
   356 	      if ( p0->flag && !(MG_SMSGN(v1,v2)) ) {
-> 357 	        if ( !MMG2D_ismaniball(mesh,sol,k,i) ) {
   358 	          sol->m[ip] = tmp[ip];
   359 	          nc++;
   360 	        }
(lldb) down
frame #0: 0x00000001007e18fa LevelSetCantilever`MMG2D_ismaniball(mesh=0x000000010d107e18, sol=0x000000010d208cd8, start=6822, istart='\x02') at mmg2d6.c:235:13
   232 	  /* First loop: stop if an external boundary, or a change in signs (or a 0) is met
   233 	     recall that MG_SMGSGN(a,b) = 1 provided a*b >0 */
   234 	  do{
-> 235 	    adja = &mesh->adja[3*(k-1)+1];
   236 	    k = adja[i] / 3;
   237 	    i1 = adja[i] % 3;
   238 	    i = MMG5_iprv2[i1];

I will tag @dapogny since he is responsable for this part of the code (I think) :)

Please let me know if you don't succeed in reproducing the bug.

Hi @cbritopacheco,

Thanks for the detailed bug feedback (and sorry for the delay of answer). I am able to reproduce the bug and I will look at it today.

I hope that it will not be too long to correct this ;-).

Best Regards,
Algiane

Hi Algiane,
Thanks for looking into this. Having spoken with @dapogny we have determined it might be unfeaseable to mesh this level set function. You might want to do a big zoom on the points where the boundary changes attribute, where there are some really bad quality elements. The problem is surely numerical.

If you don't arrive to fix this, it would be nice to have some output stating that this an unfeasible implicit domain, maybe fixing a maximum number of iterations in MMG2D_ismaniball ? As you can see the do-while loop is not guaranteed to end.

Thanks again,
Carlos.

Hi,

Thanks for the precisions. PR #125 will solve the infinite loop but as expected, due to the presence of degenerated triangles, the final result is still bad (the discretized level-set has a weird shape along the boundary). I suppose that the optimization process is likely to fail on this final mesh.

I attach a picture of the final mesh as well as a zoom toward the area shown by the arrow.

Capture d’écran 2022-02-21 à 15 51 27

Capture d’écran 2022-02-21 à 15 48 35

Hi Algiane,
Thank you very much for this hotfix. As an additional note, I did circumvent this issue by computing better level set functions which in turn lead to better shapes. However, I still think this fix should improve robustness!