How to reset a metric to cleared state?

Dear forum, in general, the function

MMG2D_mmg2dlib(mesh, met)

is not idempotent: calling it repeatedly gives different results than calling it once. Regardless of whether it makes sens to call it repeatedly, I wondered how not to make use of the metric computed in the first call.
If met->np was zero before the first call, it is !=0 after the first call. So, I wondered how to reset it to a state with met->np == 0. Just setting met->np = 0 works but it is not an API function (and maybe it leads to a memory leak somewhere). On the other hand, freeing the solution with the API function

MMG2D_Free_solutions(mesh, met)

between the calls does not work: it gives the message ##ERROR: WRONG DATA TYPE in the second call.
I feel there should be an API function to clear a solution/metric since I don’t want to touch the internals of mmg because they can change in the future. What API function should I use to reset a metric/solution to the state it was left after a call to

MMG2D_Init_mesh(MMG5_ARG_start, MMG5_ARG_ppMesh, &mesh, MMG5_ARG_ppMet, &met, MG5_ARG_end

?
Thank you.

Hi Mathias,

Most of time, people uses iterative call of MMG2D_mmg2dlib in the context of the mesh adaptation to a solution. In this case they provide a metric computed from the solution between each call of mmg so it works without any issue.

In your case, I totally agree that touching the internal structure of Mmg is not a good idea and that I should provide APIs to reset it. I have tried to patch the error in a such way that after the call to MMG2D_Free_solutions :

  • you can call MMG2D_mmg2dlib without error (the structure is in a state compatible with the state it had after the MMG2D_Init_mesh call);
  • you can use MMG2D_Set_solSize and MMG2D_Set_.*Sol to set a new metric;
  • I hope that the function is still compatible with your PR #70.

For now you can test the correction in the branch feature/cleaned-free-solutions-API. I let you confirm if it works on your test case and I will merge it into the develop branch.

By the way, I will also add the equivalent MMG*_Free_solutions functions in mmgs and mmg3d.

Regards,

Algiane

Thank you for the answer. Yes, that looks as if it’ll do the trick!

Hello Mathias,

Thank you for your feedback. It is merged in the develop now.

Have a nice day

Ok, thank you!
Mathias