Usage examples

Some library examples are provided in the mmg repository, under the libexamples directory. (see the projects source tree section of the wiki for the description of the libexamples directory).

  • Basic examples with automatic parsing of .mesh files are provided in the libexamples/mmg<X>/adaptation_example0/example0_a folder (<X> = <2d|3d|s> depending on the library that you want to use). Inputs/outputs are done using the API functions that read/write .mesh/.sol files.

  • Basic examples with manual mesh setters and getters are provided in the libexamples/mmg<X>/adaptation_example0/example0_b folder. Inputs/outputs are done using setters and getters to transfer a mesh and a size map already stored in arrays (in the solver structures for example) to mmg entities by entities.

  • Examples of Fortran calls can be found in the libexamples/mmg<X>/adaptation_example0_fortran/example0_<a|b> folders. These examples are similar to the previous ones. Usually, a Fortran subroutine similar to the C API is provided with an additional argument to store the return value of the C function. Note that if the C API takes a string as argument, the Fortran one will use another additional input argument for string length.

  • An example of library call from a C++ code is provided in libexamples/mmg/adaptation_example0_cpp.

  • libexamples/mmg3d/adaptation_example2 shows how to customize some of the parameters of Mmg;

  • libexamples/mmg3d/IsosurfDiscretization_example0 provides examples of isovalue discretisation;

  • libexamples/mmg3d/LagrangianMotion_example0 shows examples of lagrangian motion.

  • Even if we try to preserve the API compatibility between mmg versions, we can have small modifications. In this case, you can use predefined macro (MMG_VERSION, MMG_VERSION_LE…) to detect the API version of Mmg in your code. An example is provided in the mmg/libexamples/mmg2d/adaptation_example0/example0_b/ directory (and its fortran version);

Since mmg3d library and API have been developped first, you will find more examples in the libexamples/mmg3d folder than in the other ones. Note that the APIs of the 3 codes works in the same way except that:

  • use suitable prefixes: MMG3D_ for mmg3d, MMG2D_ for mmg2d or MMGS_ for mmgs.

  • in 2D, the MMG2D_Set_vertex function takes 2D coordinates while the MMGS_Set_vertex and MMG3D_Set_vertex functions take 3D coordinates.