# Mmg3d generates anisotropic meshes

**URL:** <https://community.freefem.org/t/mmg3d-generates-anisotropic-meshes/1932>\
**Category:** General Discussion\
**Created:** [August 7, 2022, 6:43am UTC](https://community.freefem.org/t/mmg3d-generates-anisotropic-meshes/1932 "2022-08-07T06:43:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![wanglongfei](https://avatars.discourse-cdn.com/v4/letter/w/ea666f/32.png) [@wanglongfei](https://community.freefem.org/u/wanglongfei)\
**Post date:** [August 7, 2022, 6:43am UTC](https://community.freefem.org/t/mmg3d-generates-anisotropic-meshes/1932/1 "2022-08-07T06:43:20Z")

</div>

Hello  
I’m sorry to bother you again. I generated 3D anisotropic meshes with my own metrics and mmg3d. I found that the tetrahedron segmentation speed is too fast. How does mmg3d control the number of tetrahedrons? I tried to add the parameter mem = 100, and found that mmg3d did not work after adding mem.  
Thank you very much.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [August 10, 2022, 12:08pm UTC](https://community.freefem.org/t/mmg3d-generates-anisotropic-meshes/1932/2 "2022-08-10T12:08:33Z")

</div>

Without your mesh, it is hard to give an answer.  
I have to try to se if it is a bug!

---

<div class="post-metadata">

**Author:** ![wanglongfei](https://avatars.discourse-cdn.com/v4/letter/w/ea666f/32.png) [@wanglongfei](https://community.freefem.org/u/wanglongfei)\
**Post date:** [August 10, 2022, 2:52pm UTC](https://community.freefem.org/t/mmg3d-generates-anisotropic-meshes/1932/3 "2022-08-10T14:52:43Z")

</div>

load “msh3”  
load “tetgen”  
load “mshmet”  
load “medit”  
load “mmg”  
load “aniso”

real epsilon=1e-6;  
func b1=1;  
func b2=2;  
func b3=3;

func ue=-y^2_exp(b1_(x-1)/epsilon)-x_exp(b2_(y-1)/epsilon)-z_exp(b3_(z-1)/epsilon)+exp((b1\*(x-1)+b2\*(y-1)+b3\*(z-1))/epsilon)+x_y^2_z^3;  
func uex=y^2_z^3 - exp((b2_(y - 1))/epsilon) + (b1_exp((b1_(x - 1) + b2\*(y - 1) + b3\*(z - 1))/epsilon))/epsilon - (b1_y^2_exp((b1\*(x - 1))/epsilon))/epsilon;  
func uey=2_x_y_z^3 - 2_y_exp((b1_(x - 1))/epsilon) + (b2_exp((b1_(x - 1) + b2\*(y - 1) + b3\*(z - 1))/epsilon))/epsilon - (b2_x_exp((b2\*(y - 1))/epsilon))/epsilon;  
func uez=(b3_exp((b1_(x - 1) + b2\*(y - 1) + b3\*(z - 1))/epsilon))/epsilon - exp((b3\*(z - 1))/epsilon) + 3_x_y^2_z^2 - (b3_z_exp((b3_(z - 1))/epsilon))/epsilon;  
func f=epsilon\*(2_exp((b1_(x - 1))/epsilon) - 2_x_z^3 - 6_x_y^2_z + (2_b3_exp((b3_(z - 1))/epsilon))/epsilon - (b1^2_exp((b1_(x - 1)

- b2\*(y - 1) + b3\*(z - 1))/epsilon))/epsilon^2 - (b2^2_exp((b1_(x - 1) + b2\*(y - 1) + b3\*(z - 1))/epsilon))/epsilon^2 - (b3^2_exp((b1_(x - 1)
- b2\*(y - 1) + b3\*(z - 1))/epsilon))/epsilon^2 + (b2^2_x_exp((b2\*(y - 1))/epsilon))/epsilon^2 + (b3^2_z_exp((b3\*(z - 1))/epsilon))/epsilon^2
- (b1^2_y^2_exp((b1\*(x - 1))/epsilon))/epsilon^2) - b1\*(exp((b2\*(y - 1))/epsilon) - y^2_z^3 - (b1_exp((b1\*(x - 1) + b2\*(y - 1) + b3\*(z - 1))/epsilon))/epsilon
- (b1_y^2_exp((b1\*(x - 1))/epsilon))/epsilon) - b3\*(exp((b3\*(z - 1))/epsilon) - (b3_exp((b1_(x - 1) + b2\*(y - 1) + b3\*(z - 1))/epsilon))/epsilon - 3_x_y^2\*z^2
- (b3_z_exp((b3\*(z - 1))/epsilon))/epsilon) - b2\*(2_y_exp((b1\*(x - 1))/epsilon) - 2_x_y_z^3 - (b2_exp((b1\*(x - 1) + b2\*(y - 1) + b3\*(z - 1))/epsilon))/epsilon
- (b2_x_exp((b2\*(y - 1))/epsilon))/epsilon);

int nn = 10;  
int[int] lc=[1,2,2,1,1,2];

mesh3 Th=cube(nn,nn,nn,label=lc);  
fespace Vh(Th,P1);  
fespace Mh(Th,[P1,P1,P1,P1,P1,P1]);  
Vh u,v;  
Mh [n11,n21,n22,n31,n32,n33];

problem Lap3d (u, v)  
= int3d(Th)(  
epsilon\*(dx(u)_dx(v)+dy(u)dy(v)+dz(u)dz(v))  
)  
+int3d(Th)(  
(b1dx(u)+b2dy(u)+b3_dz(u))\*v  
)  
- int3d(Th)(  
f \* v  
)  
+ on(0, 1, u=ue)  
;

real lerr=0.05;  
int a=9;  
for(int ii=0; ii\<a; ii++)  
{  
[n11,n21,n22,n31,n32,n33]=[0,0,0,0,0,0];  
real cc=(u.max-u.min);  
real[int] met=mshmet(Th,u,hmin=1e-8,hmax=0.2,err=lerr,aniso=1);  
n11=met;  
Th=mmg3d(Th,metric=n11,mem=100,hgrad=1000000);  
lerr=lerr/1.5;  
mesh3 Th4=trunc (Th,(x\<0.5|y\<0.5|z\<0.5),label=1);  
if(ii\>a-2) medit(“U-adap-aniso-”+ii,Th4,u,wait=1);  
}

This is the program. When I add men = 100, mmg3d will not work. Thank you.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [August 10, 2022, 4:15pm UTC](https://community.freefem.org/t/mmg3d-generates-anisotropic-meshes/1932/4 "2022-08-10T16:15:47Z")

</div>

Please some character disappear please send the file not a paste of the file.

---

<div class="post-metadata">

**Author:** ![wanglongfei](https://avatars.discourse-cdn.com/v4/letter/w/ea666f/32.png) [@wanglongfei](https://community.freefem.org/u/wanglongfei)\
**Post date:** [August 10, 2022, 4:44pm UTC](https://community.freefem.org/t/mmg3d-generates-anisotropic-meshes/1932/5 "2022-08-10T16:44:50Z")

</div>

[test.edp](https://community.freefem.org/uploads/short-url/72K4Tt3e15WBixoq1UYE6VW5gHd.edp) (2.5 KB)

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [August 11, 2022, 8:29am UTC](https://community.freefem.org/t/mmg3d-generates-anisotropic-meshes/1932/6 "2022-08-11T08:29:16Z")

</div>

First You code is wrong,

u is never set, I tty to correct but I do not understand you code  
remark, I get no error on my Mac and the mesh never change

I change mem to 500 and I don adaptation with ue no u.

my change:  
[test.edp](https://community.freefem.org/uploads/short-url/2J6Hf4zDmHdVY3goS2XMrxcAGxM.edp) (2.6 KB)

---

<div class="post-metadata">

**Author:** ![wanglongfei](https://avatars.discourse-cdn.com/v4/letter/w/ea666f/32.png) [@wanglongfei](https://community.freefem.org/u/wanglongfei)\
**Post date:** [August 11, 2022, 9:20am UTC](https://community.freefem.org/t/mmg3d-generates-anisotropic-meshes/1932/7 "2022-08-11T09:20:23Z")

</div>

Thank you very much for your answer. I want to use the approximate solution to generate the metrics of anisotropy, and then generate the meshes of anisotropy based on the metrics. I run the program you modified, MEM = 500, the grid changes little, and the anisotropic is lost. Since the mesh does not change after adding MEM, how should we set parameters to control the number of tetrahedrons? This is the program after removing mem.There is also a problem about the second derivative of the approximate solution in this program.  
[test.edp](https://community.freefem.org/uploads/short-url/jXT7IYzYxytJmNuNTvC0O93biZJ.edp) (2.6 KB)

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [August 12, 2022, 11:41am UTC](https://community.freefem.org/t/mmg3d-generates-anisotropic-meshes/1932/8 "2022-08-12T11:41:09Z")

</div>

To control the number of element change the level of err in mshmet.

---

<div class="post-metadata">

**Author:** ![wanglongfei](https://avatars.discourse-cdn.com/v4/letter/w/ea666f/32.png) [@wanglongfei](https://community.freefem.org/u/wanglongfei)\
**Post date:** [August 13, 2022, 5:59am UTC](https://community.freefem.org/t/mmg3d-generates-anisotropic-meshes/1932/9 "2022-08-13T05:59:28Z")

</div>

Thank you very much for your answer. But how can I control the number of tetrahedrons if I generate metrics by other methods instead of mshmet?
