Skip to content

Tools for the mmg libraries users

Algiane Froehly edited this page May 20, 2022 · 11 revisions

I/ Link with the mmg libraries

By default, the make install command installs the libraries into the /usr/local/lib directory. The header files are located into the /usr/local/include directory.

1) Link with the mmg libraries using CMake

You can use:

If the package fails, you can help it by:

  • setting the MMG_DIR environment variable to your mmg directory path:
export MMG_DIR=<your_mmg_directory_path>
  • or setting the MMG_DIR CMake variable to your mmg directory path:
SET(MMG_DIR <your_mmg_directory_path>)

FindMMG.cmake package

The FindMMG.cmake package defines the MMG_INCLUDE_DIRS and the MMG_LIBRARIES variables.
To link a program named YOUR_TARGET with the mmg library using CMake, just add the following lines in your CMakeLists.txt:

FIND_PACKAGE(MMG)
INCLUDE_DIRECTORIES(${MMG_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES( ${YOUR_TARGET} ${MMG_LIBRARIES})

Don't forget to include the mmg library headers to your program:

#include "mmg/libmmg.h"

FindMMG.cmake package

The FindMMG.cmake package, being replace by 2D, S or 3D, defines the MMG_INCLUDE_DIRS and the MMG_LIBRARIES variables.
To link a program named YOUR_TARGET with the mmg library using CMake, just add the following lines in your CMakeLists.txt:

INCLUDE(FindMMG<X>.cmake)
INCLUDE_DIRECTORIES(${MMG<X>_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES( ${YOUR_TARGET} ${MMG<X>_LIBRARIES})

Don't forget to include the mmg library headers to your program:

#include "mmg/mmg<X>/libmmg<X>.h"

2) Link with the mmg libraries in command line

We supposed in the following that:

  • you want to compile a program with only one file, the main.c file;
  • the mmg libraries are installed in the <LIB_PATH> directory and the header files in the <INCLUDE_PATH> one (default configuration);
  • the scotch library is installed in the <SCOTCH_PATH> directory.

Here we use the example of the mmg3d library.
You must compile specifying:

  • the mmg3d include directory with the -I option;
  • the mmg3d library location with the -L option;
  • the mmg3d library name with the -l option.
 gcc main.c -I<INCLUDE_PATH> -L<LIB_PATH> -L<SCOTCH_PATH> -lmmg3d -lscotch -lscotcherr -lm

Note that mmg uses the math library thus, it may be needed to link with it (-lm option). If you have build mmg without scotch, just remove the variables related to it:

 gcc main.c -I<INCLUDE_PATH> -L<LIB_PATH> -lmmg3d -lm

It may be needed to add the path toward the libraries directory to your LD_LIBRARY_PATH environment variable:

export LD_LIBRARY_PATH=<LIB_PATH>:$LD_LIBRARY_PATH

Don't forget to include the mmg3d library headers to your program:

#include "mmg/mmg3d/libmmg3d.h"

Fortran users

Note that depending on the extension of your fortran's files (and on your compiler), you may need to enable the preprocessing step to link with the Mmg libraries.

For example, gfortran enables automatically the preprocessing for .F90 files but not for .f90 ones. Thus, to compile the main.f90 file that use the Mmg API functions, you must add the -cpp option to gfortran:

gfortran -cpp main.f90 -lmmg3d -lscotch -lscotcherr -lm

Linking with dynamic library under Mac OS X

To avoid trouble with the rpath under Mac OS X just add -Wl,-rpath,<LIB_PATH> to your compilation command line:

 gcc main.c -I/usr/local/include/ -L/usr/local/lib -lmmg3d -lm -Wl,-rpath,<LIB_PATH>

Please refers to your compiler documentation for further informations.

II/ Usage examples

You can find examples of the use of the mmg libraries in the libexamples subfolder (see the projects source tree section of the wiki for the description of the libexamples directory).

As the 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:

  • you will have to use the suitable prefix : 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 takes 3D coordinates.
  • ...

A short summary of the place to find the informations you need:

  • libexamples/mmg3d/adaptation_example0 shows how to call the Mmg3d library with using default parameters;
    • libexamples/mmg3d/adaptation_example0/example0_a simply call the mesh adaptation library. Inputs/outputs are done using the API functions that read/write .mesh/.sol files;
    • libexamples/mmg3d/adaptation_example0/example0_b call the adaptation library but 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.
  • libexamples/mmg3d/adaptation_example0_fortran matches the previous examples but for fortran users;
  • libexamples/mmg3d/adaptation_example2 shows how to customize some of the parameters of Mmg;
  • libexamples/mmg3d/IsosurfDiscretization_example0 call the library of isovalue discretisation;
  • libexamples/mmg3d/LagrangianMotion_example0 call the library that perform lagrangian motion.