Problem while specifiying an anisotropic metric through the API

Hello mmg community,

I use mmg in a C++ software. So far, I had no problem using it for isotropic metric. I have began to implement the support of anisotropic metric, and I have an issue in the function called MMG5_cavity_ani.

At some point, I end up with an Arithmetic Exception here crit += sqrt(dd/ray);.

Inded, dd is negative.

I have tried to cheat a little bit and ensure dd to be positive by computing ux, uy and uz like that

ux = fabs(ppt->c[0] - c[0]);
uy = fabs(ppt->c[1] - c[1]);
uz =fabs( ppt->c[2] - c[2]);
dd = mj[0]*ux*ux + mj[3]*uy*uy + mj[5]*uz*uz  + 2.0*(mj[1]*ux*uy + mj[2]*ux*uz + mj[4]*uy*uz);

But then, it was ray that was negative. So I cheat again by doing ray=fabs(ray); and now I have a correct results.

I have really hard trouble to debug. If I use mmg through command line, everything is going fine. I have checked multiple times if the metric was well specified usingthis page and it was.

I have tried with a “fake” anisotropic metric (with only 1 in the diagonal) and I still have an issue.

Do you have any tips on how to debug ? are ux, uz and uy supposed to be negative ?

Thanks !

Hello Antoine,

Please correct me if I am wrong:

  • you have an error using anisotropic metrics that appears only using the API and not the command line?
  • it also happens when providing the identity matrix as metric?

If I have understood your issue, I think that there is a problem with the order you provide the metric terms (note that the error may be in my documentation as we use a different convention in our API than in the Medit file format). If you confirm that you get this kind of issue, I will check my doc.

Othewise, it may be due to a lack of robustness in the implementation of the anisotropy and it will help me a lot if you can send me your input mesh and metric files.

Regards,

Algiane

Hello,

Yes you are right ! It works with the medit metric prescription but not with the API !

Hello Antoine,

I am not able to reproduce this bug and as you will see, I have lot of questions: so maybe it will be faster to try to debug this together in visio (I am really surprised by the fact that the API and command line tools behave differently and that it is not detected during the analysis)?

In any case, I can give you some tips:

  • you can check your API call:

    • Set your mesh and metric using the API;
    • Save your mesh and metric at Medit file format using the MMG3D_saveMesh and MMG3D_saveSol functions (normally, you must be able to run Mmg on this data);
    • Use Medit to vizualize your mesh and click on the mesh points to check that Medit is able to compute the metric eigenvalues and vectors (it prints it inside your terminal);
  • you can also try to run in analysis mode and see if your metric or your mesh have been modified by the analysis step of Mmg :

MMG3D_Set_iparameter(mmgMesh,mmgSol,MMG3D_IPARAM_noinsert, 1)
MMG3D_Set_iparameter(mmgMesh,mmgSol,MMG3D_IPARAM_noswap, 1)
MMG3D_Set_iparameter(mmgMesh,mmgSol,MMG3D_IPARAM_nomove, 1)

Now, some of my questions:

  • through command line, which input file format are you using?
  • what are the values of mj during the computation of dd? I guess that this values aren’t the same with API than through command line?
  • in this position of the code, “ip” is the index of the point on which we work:
    • is it a surface point? a special one? (corner, point along a sharp angle…)
    • is it an interior one?

Thank you by advance,

Algiane

Hello !

Sorry for the late answer !

Yes I managed to use mmg as a standalone and it’s work great. I am 100% sure I am doing something wrong using the API… I will try to dig into it…

I have a side question. when I use the anisotropic with the opnbdy option, I have refined cells around internal surfaces, is there a reason for such behavior ?

(In the image, it’s a horizontal slice of the mesh. The internal surface belongs where the cells are refined whereas I have not specified any special mesh size in this region.)

Hi Antoine,

The internal surfaces are remeshed with respect to the hausdorff distance (as the external surfaces): is it possible that your internal surface is not plane (in this case, Mmg will refine it to improve its approximation)?

Regards,

Algiane

Hello Algiane,

Thanks for the answer.

Yes the surface is not plane ! Is it possible to tune this refining parameter ?

Regards,

Antoine

Hi Antoine,

You can release the hausdorff parameter (a global parameter that leads to refine curve areas an to unrefine plane ones). By default it is setted to 0.01, you can try 0.2 for example:

  • using the command laine arguments: -hausd 0.2
  • using the API functions:
   if ( MMG3D_Set_dparameter(mmgMesh,mmgSol,MMG3D_DPARAM_hausd, 0.2) != 1 )
      exit(EXIT_FAILURE);

It is also possible to modify locally the hausdorff by associating a specific hausdorff to a triangle reference (but it slow down Mmg) : https://www.mmgtools.org/local-parameters-for-boundaries

Regards,

Algiane