From KratosWiki
Revision as of 16:06, 8 February 2017 by Vmataix (Talk | contribs)
Jump to: navigation, search


What is MMG?

Mmg is an open source software for simplicial remeshing. MMG main page[1], and you can download the code in GitHub[2]

  • It provides 3 applications and 4 libraries:
    • The mmg2d application and the libmmg2d library: adaptation and optimization of a two-dimensional triangulation and generation of a triangulation from a set of points or from given boundary edges
    • The mmgs application and the libmmgs library: adaptation and optimization of a surface triangulation and isovalue discretization
    • The mmg3d application and the libmmg3d library: adaptation and optimization of a tetrahedral mesh and implicit domain meshing
    • The libmmg library gathering the libmmg2d, libmmgs and libmmg3d libraries
  • It uses a LGPL[3] license and it has been integrated in Kratos via the mmg_utility.h in the MeshingApplication.

Important: For use it you need to download first (look in the installation section)

  • It is used like a process, using the in the MeshingApplication.
  • There are basically two different types of re-meshing strategies (both of them compatibles with an anisotropic re-meshing):
    • Level-Set: This re-meshing technique is based in the gradient of the DISTANCE function, and can be used to re-mesh when you are getting closer to the reference geometry.
    • Hessian: This re-meshing technique is based in the computation of the Hessian of any variable, in the case of more than one variable or a variable by components is considered them the intersection of the corresponding tensors is computed.

Screenshot 20170208 161730.jpeg

How can I install this library?

The installation of the library is fortunately quite straightforward thanks to the marvels of the configure scripts. The easiest way is the following one, because requires the minimal effort; of course if you have expertise you can find an alternative way to install the library:

  • Go to MeshingApplication/custom_external_libraries/
    • Here you can see the mmg folder, but it is empty. You have the README.txt, where the installation is explained, and the build folder, where the script can be found.
    • Rename the folder to anything else and execute (make sure you have installed git first):
   git clone
  • Then copy the content of the build folder from the old mmg folder to the new mmg folder. Go to the build folder and execute:
  • Once the compilation is done go to the main Kratos folder and go to your cmake_build folder. Here you modify the adding the following lines (modify the kartos_dir for your current Kratos installation directory):
   -DINCLUDE_MMG=ON                                                                  \
   -DMMG_LIBRARY="kratos_dir/applications/MeshingApplication/custom_external_libraries/mmg/lib/libmmg.a"     \
   -DMMG2D_LIBRARY="kratos_dir/applications/MeshingApplication/custom_external_libraries/mmg/lib/libmmg2d.a" \
   -DMMG3D_LIBRARY="kratos_dir/applications/MeshingApplication/custom_external_libraries/mmg/lib/libmmg3d.a" \
   -DMMGS_LIBRARY="kratos_dir/applications/MeshingApplication/custom_external_libraries/mmg/lib/libmmgs.a"   \
  • After that recompile Kratos using again:

Once it is compiled

Go to the folder tests in the MeshingApplication and run:


You should get an OK, if you don't get an OK there is something wrong:

  • Check that your compilation is the correct one
    • Follow again all the steps
    • Check that the it is correctly compiled
  • If you get an Unexpected error:
    • This problem is because your machine is not compatible with the library, unfortunately this means that you need to wait until the problem is solved

How can I used this library?

As said before, the re-meshing is based in a process structure, in this case the '' files must be modified (you can take as reference one present in the next section). The parameters that define this process are the following ones:

       ## Settings string in json format
       default_parameters = KratosMultiphysics.Parameters("""
           "output_file_name"                 : "out",
           "model_part_name"                  : "MainModelPart",
           "strategy"                         : "LevelSet",
           "level_set_strategy_parameters"              :{
               "scalar_variable"                  : "DISTANCE",
               "gradient_variable"                : "DISTANCE_GRADIENT"
           "hessian_strategy_parameters"              :{
               "metric_variable"                  : ["DISTANCE"],
               "interpolation_error"              : 0.04,
               "mesh_dependent_constant"          : 0.0
           "enforce_current"                  : true,
           "initial_step"                     : 1,
           "step_frequency"                   : 0,
           "automatic_remesh"                 : true,
           "automatic_remesh_parameters"      :{
               "automatic_remesh_type"            : "Ratio",
               "min_size_ratio"                   : 1.0,
               "max_size_ratio"                   : 3.0,
               "refer_type"                       : "Mean",
               "min_size_current_percentage"      : 50.0,
               "max_size_current_percentage"      : 98.0
           "initial_remeshing"                : true,
           "fix_contour_model_parts"          : [],
           "minimal_size"                     : 0.1,
           "maximal_size"                     : 10.0,
           "anisotropy_remeshing"             : true,
               "hmin_over_hmax_anisotropic_ratio" : 0.01,
               "boundary_layer_max_distance"      : 1.0,
               "boundary_layer_min_size_ratio"    : 2.0,
               "interpolation"                    : "Linear"
           "save_external_files"              : false,
           "max_number_of_searchs"            : 1000,
           "echo_level"                       : 3

The meaning of each of the parameters is the following one:

  • output_file_name: This is the name of *.sol and *.mesh generated in the case you chose to activate save_external_files.
  • model_part_name: This is important, it should correspond with the name of your actual main model part.
  • strategy: The type of strategy to chose, or LevelSet or Hessian.
  • If you chose the LevelSet strategy:
    • scalar_variable:
    • gradient_variable:
  • If you chose the Hessian strategy:
    • metric_variable:
    • interpolation_error:
    • mesh_dependent_constant:
  • enforce_current:
  • initial_step:
  • step_frequency:
  • automatic_remesh:
    • automatic_remesh_type:
    • min_size_ratio:
    • max_size_ratio:
    • refer_type:
    • min_size_current_percentage:
    • max_size_current_percentage:
  • initial_remeshing:
  • fix_contour_model_parts:
  • minimal_size:
  • maximal_size:
  • anisotropy_remeshing:
    • hmin_over_hmax_anisotropic_ratio:
    • boundary_layer_max_distance:
    • boundary_layer_min_size_ratio:
    • interpolation: The interpolation algorithm used in the anisotropic area. By default is linear, which means that is increasing until the value to the reference is zero.
  • save_external_files: This activates the saving of the resulting meshes (in *.mesh and *.sol files)
  • max_number_of_searchs: This is the max. number of search that can be done in the value interpolation process (when values are interpolated from the old mesh to the new mesh)
  • echo_level: This sets the echo_level, 0 for no output at all, 3 for standard output, 4 for awesome output.

Can you show us a little example?

Of course, in the File:Sphere remeshed.gid.tar.gz you can find an example that you can run in your machine. This problem consists in a continuous re-meshing using the Hessian of the velocity as reference.

The resulting output should look something similar to the following[4].

The problems presented in the tests can be used as reference too.

Personal tools