# Movemesh with level set defined geometry

**URL:** https://community.freefem.org/t/movemesh-with-level-set-defined-geometry/2693
**Category:** General Discussion
**Created:** [September 10, 2023, 10:40am UTC](https://community.freefem.org/t/movemesh-with-level-set-defined-geometry/2693 "2023-09-10T10:40:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![gurkanceren](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/gurkanceren/32/1893_2.png) [@gurkanceren](https://community.freefem.org/u/gurkanceren)
#### Post date: [September 10, 2023, 10:40am UTC](https://community.freefem.org/t/movemesh-with-level-set-defined-geometry/2693/1 "2023-09-10T10:40:36Z")

</div>

Hello everyone,

I have compiled the developer version of FreeFem to have my hands on mmg2d function and created the attached mesh where the flower like geometry is defined by a level set function as:  
A = x^2 + y^2;  
ls = sqrt(A) - 0.27 - 0.27 \* 2_cos(3_atan2(x, y));

 ![Screenshot from 2023-09-10 13-07-20](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/b/b9757890694df4c5c4ae4d4f7be683442c6074f1.png)

Now what I want is to rotate the flower counterclockwise and see the deformed mesh after this rotation. When I use movemesh function, the square mesh is rotated rather than the flower gometry, hence no deformation occurs, as seen in attached figure.

 ![Screenshot from 2023-09-10 13-19-40](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/e/e286abbcaabc2ba1528320fd5ea8b1babb59a1f9.png)

Can anyone know how to rotate the level set defined flower geometry and create a deformed mesh while keeping the square mesh stable?

Here is the code I use:

> load “mmg”  
> real x0 = -1.0;  
> real x1 = 1.0;  
> real y0 = -1.0;  
> real y1 = 1.0;  
> int n = 100;  
> real m = 100;  
> mesh Th = square(n, m, [x0+(x1-x0)_x, y0+(y1-y0)y]);  
> fespace Vh(Th, P1);  
> Vh A = x^2 + y^2;  
> Vh ls = sqrt(A) - 0.27 - 0.27 \* 2cos(3_atan2(x, y));  
> Th = mmg2d(Th, iso = 1, ls = 0.0, metric = ls[], hmax = 0.1);  
> func phi1=x \* cos(10) + y \* sin(10);  
> func phi2=-x \* sin(10) + y \* cos(10);  
> Th = movemesh(Th, [phi1, phi2]);  
> Th = trunc(Th, region == 2);  
> plot(Th);

Thank you

---

<div class="post-metadata">

### Author: ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)
#### Post date: [September 10, 2023, 2:01pm UTC](https://community.freefem.org/t/movemesh-with-level-set-defined-geometry/2693/2 "2023-09-10T14:01:19Z")

</div>

What is wrong with just adding theta to the atan2 term and re-creating the mesh?  
Do you want to do in effect an infintesimal rotation and be able to  
have old and new points correspnd to each other?  
Edit : Probably you need a function that moves points near the surface in the  
direction of the surface motion while leaving the outer boundary elements in place.  
If you have fluid flow solution that may help 🙂  
Can you solve some differential equation and use that solution to deform the mesh?

---

<div class="post-metadata">

### Author: ![gurkanceren](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/gurkanceren/32/1893_2.png) [@gurkanceren](https://community.freefem.org/u/gurkanceren)
#### Post date: [September 10, 2023, 2:49pm UTC](https://community.freefem.org/t/movemesh-with-level-set-defined-geometry/2693/3 "2023-09-10T14:49:14Z")

</div>

@marchywka If I just add theta to atan2 term I will get a new mesh (not deformed, nicely adapted to the flower) over the moved flower geometry not a deformed mesh.

---

<div class="post-metadata">

### Author: ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)
#### Post date: [September 10, 2023, 4:31pm UTC](https://community.freefem.org/t/movemesh-with-level-set-defined-geometry/2693/4 "2023-09-10T16:31:51Z")

</div>

to use movemesh you need a function that moves the points on the surface  
the desired amount while leaving the outer rectangle in place. Can you describe  
that with a differential equation and boundary conditions?
