# How to revise mesh using mshmet and mmg in 2d?

**URL:** https://community.freefem.org/t/how-to-revise-mesh-using-mshmet-and-mmg-in-2d/1237
**Category:** General Discussion
**Created:** [September 30, 2021, 2:13pm UTC](https://community.freefem.org/t/how-to-revise-mesh-using-mshmet-and-mmg-in-2d/1237 "2021-09-30T14:13:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![hezl09](https://avatars.discourse-cdn.com/v4/letter/h/f07891/32.png) [@hezl09](https://community.freefem.org/u/hezl09)
#### Post date: [September 30, 2021, 2:13pm UTC](https://community.freefem.org/t/how-to-revise-mesh-using-mshmet-and-mmg-in-2d/1237/1 "2021-09-30T14:13:44Z")

</div>

Hi everyone,

I have a question regarding the use of mshmet and mmg in FreeFEM++. I’m trying to revise my mesh so that its density gradually increases with the increase of x. Thus, I introduce a P1 variable `G1 = x^2. + 0.01` and pass it into function mshmet, trying to get a vector (named `met1`) containing density that will increase with the increase of x. With this vector, I can call mmg and revise my old mesh to get the new one. Thus, I wrote the following code, where I call `mmg2d_O3` as an external command

```auto
load "mshmet"
load "medit"
mesh Th1 = square(10,10);
fespace Vh1(Th1,P1);
Vh1 G1,u1sol;
G1 = x^2. + 0.01;
real[int] met1 = mshmet(Th1,G1);
u1sol[] = met1;
savemesh(Th1,"Mesh1.mesh");
savesol("Mesh1.sol",Th1,u1sol);
exec("mmg2d_O3 Mesh1 -met Mesh1.sol");
mesh Th2 = readmesh("Mesh1.o.mesh");
plot(Th1,cmm="mesh before mmg");
plot(Th2,cmm="mesh after mmg");

```

However, the mesh after calling mmg does not show any variation pattern with respect to x (figures below). I checked the reason, finding that the vector `met1` has a pretty uniform distribution, not showing any varied distribution with respect to x.

I wonder what’s is the wrong with my calling of mshmet at line 7? Thank you!

**Initial Mesh**

 ![Initial Mesh](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/14d179600cdd8d60900b2d3b97fb751279a18e83.png)

**After revision**

 ![After revision](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/b4fd2895ac744195dd30a5b52a4768463b032542.png)

---

<div class="post-metadata">

### Author: ![LucasPa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/lucaspa/32/347_2.png) [@LucasPa](https://community.freefem.org/u/LucasPa)
#### Post date: [November 15, 2021, 3:18pm UTC](https://community.freefem.org/t/how-to-revise-mesh-using-mshmet-and-mmg-in-2d/1237/2 "2021-11-15T15:18:28Z")

</div>

Hi,

I found a tutorial at [http://annabellecollin.perso.math.cnrs.fr/TPS/TP\_0.pdf](http://annabellecollin.perso.math.cnrs.fr/TPS/TP_0.pdf) (it’s in French sorry). You can download the file at [http://annabellecollin.perso.math.cnrs.fr/TPS/Code\_TP0.zip](http://annabellecollin.perso.math.cnrs.fr/TPS/Code_TP0.zip). In particular, you will see in adaptLPoisson.edp how that the metric exported as a .sol file is not directly the output of `mshmet` but is rescaled.

Best,

Lucas
