Discrepancy between API and command line on the same mesh: API ignores hmax setting

Hello Forum,
new here but I think I might be coming back a few times.
When I run the command line version of mmg (linux debug build from github master branch
mmg2d_Os -hmax 0.1 -v 10 sweet.msh
on a simple square input with four vertices, I get the following output https://pastebin.com/ue95vb8V which is fine.
However, when I run the same mesh through the API, setting hmax to 0.1 using

MMG2D_Set_dparameter(mesh, met, MMG2D_DPARAM_hmax, 0.1)

, I get the debug output
It ignores the hmax option and only generates one additional vertex. So, I wanted to track down on what point the two outpus diverge. The first point of divergence is when it says “8 corners, 0 singular points and 0 non manifold points detected” which appeared in the command line output but not in the API output, and then there are more divergences. How does that information help me to find out what is wrong with my API usage? Or do you recommend another way of debugging to find out why it ignores hmax? What is the recommended mechanism to make sure the API usage and the command line usage are the same? Even if the reason is some setting in mesh->info, why does the API ignore the hmax?
Thanks for help, Mathias

Hello and welcome Mathias,

I can’t reproduce this issue so I have few questions:

  • The use of old (resp. new) libmmg2d.h header file with a new (resp. old) library may create weird beahaviour. Is it possible to try to remove all your installations of Mmg as well as your build directory and to reinstall entirely Mmg?
  • What is the size of the bounding box of your input vertices? [0;1]x[0;1]?
  • Are you using other options of Mmg?
  • If you are used to debugers, is it possible to print the value of mesh->info.hmax (and maybe mesh->info.imprim) at the beggining of the MMG2D_analys function?

For your other questions, I think that your API usage is good (the only thing to check is that you don’t set the hmax value more than one time) but we may have a bug inside Mmg.
It is difficult to ensure that the API behave exactly as the runtime (as difficult as to ensure that a code is free of bugs ;-)). In Mmg I try to call the API inside the runtime if possible (for example, the command line parser of Mmg2d call the API to set the hmax value).

Thank you by advance for your help,



Hello Algiane,
after some debugging, I found the cause of the issue.
In the API, I required some edges using the function:


on some edges that were longer than hmax, and that seemed to cause the API to give up entirely on keeping the edges short. When I set the required edges shorter than hmax, it works fine.
It would be great if there was a warning when that happens and there are required edges longer than hmax!
To answer your questions nevertheless:

  • I don’t understand which versions you refer to as “old” and “new” … I use only one version of mmg, namely the master branch (with the bug fixes that were necessary to make it work and that I submitted, applied to the master branch instead of the develop branch; I’m pretty sure these bug fixes are not responsible for the issue). I compile it into a shared object, and an execubale, and to use the API I include the header files using

#include <mmg/mmg2d/libmmg2d.h>

so the header files should be the same for both executable and API.

  • Yes, the bounding box is the unit square.
  • I’m only setting option

MMG2D_Set_iparameter(mesh, met, MMG2D_IPARAM_nomove, 0);

  • Yes, familiar with debugger :slight_smile: thery are correct at the beginning of MMG2D_analys, mesh->info.hmax is 0.1 as I had set it, and imprim is 10.
    Cheers, Mathias

Hi Mathias,

Ok, so with your help I understand what happens. To avoid elements of bad qualities along required entities:

  • Mmg imposes the size at points belonging to a required edge (it computes this size as the mean of the lengths of the required edges passing through the point);
  • Then, it propagates this size through the mesh.

In some cases, where few points only aren’t on required entities, it leads to override entirely the other size parameters (as the hmax one or the size map).

I will add a warning if the mesh contains required edges (for verbosity >= 5).
I will also add the possibility to disable this behaviour for advanced users.


PS: I asked about “new” and “old” versions because errors in the cmake’s rules may lead to couple, for example, non-updated headers with an updated library after an update of the project.