# Mshmet and mmg3d

**URL:** https://community.freefem.org/t/mshmet-and-mmg3d/1851
**Category:** General Discussion
**Created:** [June 27, 2022, 3:22am UTC](https://community.freefem.org/t/mshmet-and-mmg3d/1851 "2022-06-27T03:22:40Z")
**Posts on this page:** 10
**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: [June 27, 2022, 3:22am UTC](https://community.freefem.org/t/mshmet-and-mmg3d/1851/1 "2022-06-27T03:22:41Z")

</div>

Hello  
Sorry to bother you . In freefem++, mshmet is used to generate metric matrix, and then mmg3d is used to generate three-dimensional meshes of various anisotropy. Can we use our own metric matrix and mmg3d to generate 3D anisotropic meshes without using the metric matrix generated by mshmet?  
Thank you !

---

<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: [June 27, 2022, 4:16am UTC](https://community.freefem.org/t/mshmet-and-mmg3d/1851/2 "2022-06-27T04:16:18Z")

</div>

Yes. using Mmg3d only and put your individual metric array into the parameter `metric=...` of `mmg3d`.

---

<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: [June 27, 2022, 5:04am UTC](https://community.freefem.org/t/mshmet-and-mmg3d/1851/3 "2022-06-27T05:04:29Z")

</div>

Ok,thank you very much.

---

<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: [June 28, 2022, 4:38am UTC](https://community.freefem.org/t/mshmet-and-mmg3d/1851/4 "2022-06-28T04:38:18Z")

</div>

Hello  
I would like to ask you what parameters need to be adjusted to use our own metric matrix and mmg3d to generate three-dimensional anisotropic meshes? I used my own metric matrix and found that there was no change in the grid.  
Thank you!

---

<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: [June 29, 2022, 1:13am UTC](https://community.freefem.org/t/mshmet-and-mmg3d/1851/5 "2022-06-29T01:13:44Z")

</div>

You can adjust `hmin` and `hmax`, `hgrad` is used in controlling the ratio between two adjacent edges, and `hausd` is used in approximation of boundaries (for details, ref. [https://www.mmgtools.org](https://www.mmgtools.org)). Of course, before doing this, you also need to check whether the individual metric array is input correctly.

---

<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: [June 29, 2022, 12:58pm UTC](https://community.freefem.org/t/mshmet-and-mmg3d/1851/6 "2022-06-29T12:58:19Z")

</div>

Ok,thank you for your answer.

---

<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: [July 4, 2022, 7:11am UTC](https://community.freefem.org/t/mshmet-and-mmg3d/1851/7 "2022-07-04T07:11:39Z")

</div>

Hello  
This is the metric array “metric\_n11” I calculated.  
[metric\_n11.zip](https://community.freefem.org/uploads/short-url/uhjVMnZuArmhclhFCILileCUAVn.zip) (48.1 KB)

My parameter settings are as follows:  
fespace Mh(Th,[P1,P1,P1,P1,P1,P1]);  
Mh [n11,n21,n22,n31,n32,n33];  
[n11,n21,n22,n31,n32,n33]=[0,0,0,0,0,0];  
n11 =[m11,m12,m22,m13,m23,m33];  
Th=mmg3d(Th,metric=n11,hmin=1e-5,hmax=0.2,hgrad=10000);  
But the anisotropic mesh is not generated .Is there a problem with the metric array I calculated, or with the parameter setting?  
Thank you very much.

---

<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: [July 4, 2022, 7:50am UTC](https://community.freefem.org/t/mshmet-and-mmg3d/1851/8 "2022-07-04T07:50:36Z")

</div>

> `[n11,n21,n22,n31,n32,n33]=[0,0,0,0,0,0];`  
> `n11[] = [m11[], m12[], m22[], m23[], m33[]];`

Note that it’s incorrect. Correct code is as follows:

```c++
[n11, n21, n22, n31, n32, n33] = [m11, m12, m22, m13, m23, m33];

```

instead.That is

```c++
n11[] = [m11[][0], m12[][0], ..., m33[][0],
         m11[][1], m12[][1], ..., m33[][1],
         ...,
         m11[][Th.nv-1], m12[][Th.nv-1], ..., m33[][Th.nv-1]];

```

if your `m11, m12, m22, m13, m23, m33` are finite element functions.

---

<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: [July 4, 2022, 9:23am UTC](https://community.freefem.org/t/mshmet-and-mmg3d/1851/9 "2022-07-04T09:23:21Z")

</div>

When I use  
[n11, n21, n22, n31, n32, n33] = [m11, m12, m22, m13, m23, m33];  
Th=mmg3d(Th,metric=n11,hmin=1e-5,hmax=0.2,hgrad=10000);  
The mesh is still unchanged, just like the initial mesh.

 ![mesh](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/3/3b90bf91cf23e4c66003148c60e64892192d100f.png)

---

<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: [July 4, 2022, 11:33am UTC](https://community.freefem.org/t/mshmet-and-mmg3d/1851/10 "2022-07-04T11:33:53Z")

</div>

Cutting the L-shape domain and check its interior to see if the grid changes, if the singularity of the solution is inside the domain. Otherwise, checking individual metric or adjusting `hmin` and `hmax`. In addition, your metric input should be `metric=n11[]`.
