# Transfer scalar field to deformed mesh with movemesh2d

**URL:** https://community.freefem.org/t/transfer-scalar-field-to-deformed-mesh-with-movemesh2d/4010
**Category:** General Discussion
**Created:** [July 22, 2025, 6:11pm UTC](https://community.freefem.org/t/transfer-scalar-field-to-deformed-mesh-with-movemesh2d/4010 "2025-07-22T18:11:40Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)
#### Post date: [July 24, 2025, 9:35am UTC](https://community.freefem.org/t/transfer-scalar-field-to-deformed-mesh-with-movemesh2d/4010/4 "2025-07-24T09:35:26Z")

</div>

Dear Angel Daniel,  
Indeed the following lines make it work for P2 or any finite element space:

```auto
int[int] renum(Ch.ndof);
for (int k=0;k<Th2.nt;++k){
 for (int j=0;j<Ch.ndofK;++j){
  renum(Ch3(k,j))=Ch(k,j);
 }
}
temp3d[]=Temp[](renum);

```

full code:

```auto
load "msh3"
real r=1.;
real R=2.;
real x0 = pi/2.;
real x1 = 3.*pi/2.;
real y0 = pi;
real y1 = 2.*pi;
int n = 5;
int m = 5;
mesh Th2 = square(n, m, [x0+(x1-x0)*x, y0+(y1-y0)*y]);
fespace Ch(Th2,P2);
Ch Temp;
//calculations of Temp follow
Temp=x;
plot(Th2, Temp, nbiso=30, fill=true, value=true, cmm="A",wait=1);//plot 2D ok
func f1 = r*sin(x);
func f2 = (R-r*cos(x))*cos(y);
func f3 = (R-r*cos(x))*sin(y);
meshS Th3 = movemesh23(Th2, transfo=[f1,f2,f3]);
fespace Ch3(Th3,P2);

int[int] renum(Ch.ndof);
for (int k=0;k<Th2.nt;++k){
 for (int j=0;j<Ch.ndofK;++j){
  renum(Ch3(k,j))=Ch(k,j);
 }
}

Ch3 temp3d;
temp3d[]=Temp[](renum);
plot(Th3, temp3d, nbiso=30, fill=true, value=true, cmm="A",wait=1);//plot ok

```

---

_[View the full topic](https://community.freefem.org/t/transfer-scalar-field-to-deformed-mesh-with-movemesh2d/4010)._
