# Usage of mmg3d does not work like in doc

**URL:** https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752
**Category:** General Discussion
**Created:** [January 19, 2021, 11:19am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752 "2021-01-19T11:19:08Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![BeniaminBogosel](https://avatars.discourse-cdn.com/v4/letter/b/3ec8ea/32.png) [@BeniaminBogosel](https://community.freefem.org/u/BeniaminBogosel)
#### Post date: [January 19, 2021, 11:19am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/1 "2021-01-19T11:19:08Z")

</div>

Hello,  
I tried to use mmg3d to adapt some 3d mesh. However, it seems that the examples in the documentation pdf are not up to date. I use version 4.7 of FreeFEM.

I tried to use the command

Th3 = mmg3d(Th,options=opt);  
with opt being an int[int] of size 6 as shown in the documentation.

However FreeFem gives an error that there is no option “options”. I see “opt” as an option, but it does not work. Can you please give an example of usage of mmg3d inside FreeFEM? Thank you.

Best regards,  
Beniamin

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [January 19, 2021, 11:26am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/2 "2021-01-19T11:26:00Z")

</div>

You can do the following:

```auto
$ git clone -b develop https://github.com/FreeFem/FreeFem-sources
$ cd FreeFem-sources
$ git grep "load \"mmg\""
examples/3d/Laplace-Adapt-aniso-3d.edp:load "mmg"
examples/3d/Sphere-Isocahedron.edp:load "mmg"
examples/3dSurf/Pinocchio.edp:load "mmg"
examples/hpddm/laplace-adapt-3d-PETSc.edp:load "mmg"
examples/hpddm/transfer.edp:load "mmg"

```

You can look at any of these examples to see how to use Mmg.

---

<div class="post-metadata">

### Author: ![BeniaminBogosel](https://avatars.discourse-cdn.com/v4/letter/b/3ec8ea/32.png) [@BeniaminBogosel](https://community.freefem.org/u/BeniaminBogosel)
#### Post date: [January 19, 2021, 11:54am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/3 "2021-01-19T11:54:58Z")

</div>

Thank you for the answer. I was able to adapt one of the examples to what I am doing.

---

<div class="post-metadata">

### Author: ![mrbenson](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mrbenson](https://community.freefem.org/u/mrbenson)
#### Post date: [April 30, 2021, 10:03pm UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/4 "2021-04-30T22:03:23Z")

</div>

Hello,

In the souce code it appears that :

> basicAC\_F0::name\_and\_type mmg3d\_Op::name\_param = {  
> {“metric”, &typeid(KN\< double \> \*)}, // 0  
> {“displacement”, &typeid(E\_Array)}, // 1  
> {“displVect”, &typeid(KN\_\< double \>)}, // 2  
> {“opt”, &typeid(string \*)}, // 3  
> {“Mb”, &typeid(long)} // 4  
> };

- Memory usage is controled with “Mb”
- Options are defined using “opt” string

Does anybody know the options in the string ?

Best regards.

---

<div class="post-metadata">

### Author: ![zhaog6](https://avatars.discourse-cdn.com/v4/letter/z/4af34b/32.png) [@zhaog6](https://community.freefem.org/u/zhaog6)
#### Post date: [May 1, 2021, 10:06am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/5 "2021-05-01T10:06:20Z")

</div>

> Hello,
> 
> In the souce code it appears that :
> 
> basicAC\_F0::name\_and\_type mmg3d\_Op::name\_param = {  
> {“metric”, &typeid(KN\< double \> \*)}, // 0  
> {“displacement”, &typeid(E\_Array)}, // 1  
> {“displVect”, &typeid(KN\_\< double \>)}, // 2  
> {“opt”, &typeid(string \*)}, // 3  
> {“Mb”, &typeid(long)} // 4  
> };
> 
> - Memory usage is controled with “Mb”
> - Options are defined using “opt” string
> 
> Does anybody know the options in the string ?

As Prof. Pierre suggested, you should use the new “mmg” module (~v5.5.2) instead of the old “mmg3d-v4.0” module (~v4.0). These parameters you mentioned exist in mmg3d-v4.0 (which is an old version Mmg in 3d). If you just want to understand what these old parameters mean, you can refer to P168 in FreeFEM tutorial [https://doc.freefem.org/pdf/FreeFEM-documentation.pdf](https://doc.freefem.org/pdf/FreeFEM-documentation.pdf).

---

<div class="post-metadata">

### Author: ![mrbenson](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mrbenson](https://community.freefem.org/u/mrbenson)
#### Post date: [May 1, 2021, 10:22am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/6 "2021-05-01T10:22:29Z")

</div>

Hi,  
I use the latest version of freefem (4.9), it includes mmg3d 4.0. Do you know where to find dll file of mmg 5.5.2 (cause the mmg website only offer exe) ?

---

<div class="post-metadata">

### Author: ![zhaog6](https://avatars.discourse-cdn.com/v4/letter/z/4af34b/32.png) [@zhaog6](https://community.freefem.org/u/zhaog6)
#### Post date: [May 1, 2021, 10:27am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/7 "2021-05-01T10:27:17Z")

</div>

> I use the latest version of freefem (4.9), it includes mmg3d 4.0. Do you know where to find dll file of mmg 5.5.2 (cause the mmg website only offer exe) ?

In FreeFem-sources/plugin/seq/mmg.cpp

---

<div class="post-metadata">

### Author: ![mrbenson](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mrbenson](https://community.freefem.org/u/mrbenson)
#### Post date: [May 1, 2021, 10:31am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/8 "2021-05-01T10:31:29Z")

</div>

That’s the source code… not sure to understand.

---

<div class="post-metadata">

### Author: ![zhaog6](https://avatars.discourse-cdn.com/v4/letter/z/4af34b/32.png) [@zhaog6](https://community.freefem.org/u/zhaog6)
#### Post date: [May 1, 2021, 10:39am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/9 "2021-05-01T10:39:40Z")

</div>

mmg.so is the dll file, which is generated by mmg.cpp. If you want to refer to all parameters added, you also can see mmg.cpp.

---

<div class="post-metadata">

### Author: ![mrbenson](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mrbenson](https://community.freefem.org/u/mrbenson)
#### Post date: [May 1, 2021, 10:46am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/10 "2021-05-01T10:46:18Z")

</div>

Sorry, i made a confusion, i believed that mmg.dll was for 2d and mmg3d for 3d… now it’s fine, mmg.dll contains both 2d and 3d !  
Thanks.

---

<div class="post-metadata">

### Author: ![zhaog6](https://avatars.discourse-cdn.com/v4/letter/z/4af34b/32.png) [@zhaog6](https://community.freefem.org/u/zhaog6)
#### Post date: [May 1, 2021, 10:47am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/11 "2021-05-01T10:47:51Z")

</div>

Yes, the new version Mmg include `mmgs` and `mmg3d`

---

<div class="post-metadata">

### Author: ![mrbenson](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mrbenson](https://community.freefem.org/u/mrbenson)
#### Post date: [May 1, 2021, 11:00am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/12 "2021-05-01T11:00:32Z")

</div>

I try to use mmg3d for mesh adaption using mshmet first (to get the metric from a scalar solution) but i’m not really sure.  
Did you ever used mmg for 3d mesh refinement ?

---

<div class="post-metadata">

### Author: ![zhaog6](https://avatars.discourse-cdn.com/v4/letter/z/4af34b/32.png) [@zhaog6](https://community.freefem.org/u/zhaog6)
#### Post date: [May 1, 2021, 11:07am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/13 "2021-05-01T11:07:52Z")

</div>

> I try to use mmg3d for mesh adaption using mshmet first (to get the metric from a scalar solution) but i’m not really sure.

Right, using “Mshmet + Mmg” if you use the default metric instead of the metric constructed by yourself.

> Did you ever used mmg for 3d mesh refinement ?

Yes, I used them to do mesh adaptation

---

<div class="post-metadata">

### Author: ![mrbenson](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mrbenson](https://community.freefem.org/u/mrbenson)
#### Post date: [May 1, 2021, 11:28am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/14 "2021-05-01T11:28:37Z")

</div>

I have an error during mmg 3d for a classic laplacian equation on an anisotropic mesh

> h = mshmet(Th, u, normalization=true); // u is the initial solution  
> Th = mmg3d(Th, metric=h, mem=1000,hmin=1e-3, hmax=1e-1);

> – PHASE 2 : ISOTROPIC MESHING  
> Assertion failed: MG\_GET(pxt1-\>ori,voyq ), file C:/builds/workspace/deployEXE/3rdparty/ff-petsc/petsc-3.15.0/fr/externalpackages/git.mmg/src/mmg3d/colver\_3d.c, line 1131  
> Unexpected error: \*\*\* potential lack of memory.

How to use mm3g for anisotropic meshes ?

---

<div class="post-metadata">

### Author: ![zhaog6](https://avatars.discourse-cdn.com/v4/letter/z/4af34b/32.png) [@zhaog6](https://community.freefem.org/u/zhaog6)
#### Post date: [May 1, 2021, 11:36am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/15 "2021-05-01T11:36:10Z")

</div>

> How to use mm3g for anisotropic meshes ?

As Prof. Pierre (prj) suggested before, you can refer to the following examples to study how to use it.

examples/3d/Laplace-Adapt-aniso-3d.edp:load “mmg”  
examples/3d/Sphere-Isocahedron.edp:load “mmg”  
examples/3dSurf/Pinocchio.edp:load “mmg”  
examples/hpddm/laplace-adapt-3d-PETSc.edp:load “mmg”  
examples/hpddm/transfer.edp:load “mmg”

---

<div class="post-metadata">

### Author: ![mrbenson](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mrbenson](https://community.freefem.org/u/mrbenson)
#### Post date: [May 1, 2021, 12:38pm UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/16 "2021-05-01T12:38:26Z")

</div>

Yes that very good examples, i do the same.  
When i activate aniso in mshmet, the metric is very strange, but with aniso=0 the metric looks better.  
I want a final anisotropic mesh, so i guess i must set aniso=true ? (as you see, my initial mesh is highly anisotropic, it contains thin layers)

Moreover mmg3d doesn’t work whatever aniso.

Here my very basic script with a .sol file

Can you have a look ? Thank you for your help.

[adapt.zip](https://community.freefem.org/uploads/short-url/nyQXodvBIAQBU5COezj8xYwoGIj.zip) (192.9 KB)

---

<div class="post-metadata">

### Author: ![mrbenson](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mrbenson](https://community.freefem.org/u/mrbenson)
#### Post date: [May 1, 2021, 2:53pm UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/17 "2021-05-01T14:53:21Z")

</div>

Here the modified edp script with a finer mesh. The script crash when performing mmg3d.

[adapt3d.zip](https://community.freefem.org/uploads/short-url/k91U1zkjNqUbRFom1qvkQcccou0.zip) (184.2 KB)

---

<div class="post-metadata">

### Author: ![zhaog6](https://avatars.discourse-cdn.com/v4/letter/z/4af34b/32.png) [@zhaog6](https://community.freefem.org/u/zhaog6)
#### Post date: [May 2, 2021, 10:01am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/18 "2021-05-02T10:01:45Z")

</div>

> Yes that very good examples, i do the same.  
> When i activate aniso in mshmet, the metric is very strange, but with aniso=0 the metric looks better.  
> I want a final anisotropic mesh, so i guess i must set aniso=true ? (as you see, my initial mesh is highly anisotropic, it contains thin layers)
> 
> Moreover mmg3d doesn’t work whatever aniso.
> 
> Here my very basic script with a .sol file
> 
> Can you have a look ? Thank you for your help.

I captured two errors:

1. `hmet` in your temp.edp is in P1, but it should be in [P1, P1, P1, P1, P1, P1]
2. I’m not sure that loading your `temp.mesh` is right (there seems to be a problem in your `temp.mesh` or loading ‘temp.mesh’). For the `temp.mesh` and its loading, I don’t know.

---

<div class="post-metadata">

### Author: ![mrbenson](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mrbenson](https://community.freefem.org/u/mrbenson)
#### Post date: [May 2, 2021, 1:11pm UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/19 "2021-05-02T13:11:49Z")

</div>

Hello,

Thanks yo for your answer.

This two blocks are different ?

> fespace Mh(Th,[P1, P1, P1, P1, P1, P1]);  
> Mh [m11,m21,m22,m31,m32,m33];  
> real[int] met = mshmet(Th, u, hmin=1e-3,hmax=0.2, err=errm, aniso=1);  
> m11 = met;

> fespace Mh(Th,P1);  
> Mh m11;  
> real[int] met = mshmet(Th, u, hmin=1e-3,hmax=0.2, err=errm, aniso=1);  
> m11 = met;

the scalar field m11 looks very strange for a metric…

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/7bf7e9c7dcd19a3f0641ff079ddcff26feca7d0b.png)

Concerning the mesh :  
readmesh3 with the medit file temp.mesh indicates one warning

> — Warning manifold obj nb:432 adj 446 of dim =2

The mesh comes from a brep file that i mesh with gmsh and export it as medit file. You can find file the brep file [here](https://we.tl/t-SW7H01zdPz).  
I tried to use gmsh mesh file (gmshload3, no warning when loading), mmg3d doesn’t crash but it’s still running (more than 15min, then i stopped) with some worrying warnings…

> Warning: MMG5\_elementWeight: at least 1 negative or null density.  
> Warning: MMG5\_movbdyregpt\_ani: unable to compute optimal position for at least 1 point.

Sorry for disturbing you.

Best regards.

---

<div class="post-metadata">

### Author: ![zhaog6](https://avatars.discourse-cdn.com/v4/letter/z/4af34b/32.png) [@zhaog6](https://community.freefem.org/u/zhaog6)
#### Post date: [May 6, 2021, 11:27am UTC](https://community.freefem.org/t/usage-of-mmg3d-does-not-work-like-in-doc/752/20 "2021-05-06T11:27:27Z")

</div>

> This two blocks are different ?

The second code block is wrong, and please note that `met` obtained by Mshmet describe the metric at each vertice in the mesh (It’s a flatten vector). Checking if `m11[].n` equals `met.n` before doing `m11[] = met;`, you can also find the wrong from this point.

> [@mrbenson](#):
>
> Concerning the mesh :  
> readmesh3 with the medit file temp.mesh indicates one warning
> 
> > — Warning manifold obj nb:432 adj 446 of dim =2
> 
> The mesh comes from a brep file that i mesh with gmsh and export it as medit file. You can find file the brep file [here](https://we.tl/t-SW7H01zdPz).  
> I tried to use gmsh mesh file (gmshload3, no warning when loading), mmg3d doesn’t crash but it’s still running (more than 15min, then i stopped) with some worrying warnings…
> 
> > Warning: MMG5\_elementWeight: at least 1 negative or null density.  
> > Warning: MMG5\_movbdyregpt\_ani: unable to compute optimal position for at least 1 point.

Sorry, I don’t know about loading and exporting of Gmsh grids and the gmshload3 module
