# Exchange of estimated temperature between two mesh

**URL:** <https://community.freefem.org/t/exchange-of-estimated-temperature-between-two-mesh/702>\
**Category:** General Discussion\
**Created:** [December 23, 2020, 8:14am UTC](https://community.freefem.org/t/exchange-of-estimated-temperature-between-two-mesh/702 "2020-12-23T08:14:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://community.freefem.org/u/Mik)\
**Post date:** [December 23, 2020, 8:14am UTC](https://community.freefem.org/t/exchange-of-estimated-temperature-between-two-mesh/702/1 "2020-12-23T08:14:07Z")

</div>

Hello All,

My question is regarding the transfer of data from one mesh to another.  
In my first iteration, I am estimating the temperature in a smaller domain (Domain 1) and then I add a section (Domain 2) to the smaller domain and get a mesh (Domain 3= Domain 1+ Domain 2).

For my estimation of T in Domain 3, I would like to impose the T from domain 1 (from 1st iteration) as the initial condition for the domain 1 section of Domain 3.

One way of doing it by going through each x,y,z which can be computationally expensive as I have a bigger mesh.

I wonder is there any other way of doing it?

Thanks,

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [December 23, 2020, 8:20am UTC](https://community.freefem.org/t/exchange-of-estimated-temperature-between-two-mesh/702/2 "2020-12-23T08:20:22Z")

</div>

Is your domain 1 a truncation of domain 3, i.e., `mesh Th1 = trunc(Th3, some condition);`? Otherwise, there is no other way than to use the interpolation. It shouldn’t be that costly and of course you don’t have to go through each _x_, _y_, and _z_ yourself.

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://community.freefem.org/u/Mik)\
**Post date:** [December 23, 2020, 8:33am UTC](https://community.freefem.org/t/exchange-of-estimated-temperature-between-two-mesh/702/3 "2020-12-23T08:33:23Z")

</div>

Thank you for the reply;  
Yes, I am truncating from a bigger mesh. I am attaching a test version here. Th is my global mesh and Th1 my domain 1 then Th2 my domain 3.

load “iovtk”;

load “msh3”

mesh3 Th(“3sections.mesh”);  
Th = readmesh3(“3sections.mesh”);

int LayerMax=1;  
int totalSteps=5;

real cellx=(0.05715-(-0.01905))/9;  
real celly=(0.0189484)/29;

real x0=-0.01905;  
real y2=0.0189484-4_celly;  
real xMax=x0+4_cellx;  
func part1=(y\>y2)\*(x\<xMax);  
func part2=(y\<=y2);

mesh3 Th1 = trunc(Th, part1 || part2 ,flabel=1,fregion=5);

real y2New=0.0189484-4_celly;  
real xMaxNew=x0+8_cellx;  
func part1New=(y\>y2)\*(x\<xMax);  
func part2New=(y\<=y2);  
mesh3 Th2 = trunc(Th, part1New || part2New ,flabel=1,fregion=5); ////// trunc the mesh depending on the region of interest by the function at 2nd position of the bracket,  
//flabel for changing the surface tag and fregion for changing the volume tag

macro normal [N.x, N.y, N.z]//   
macro fluxVECTOR(L) [0, L,0]//

real Tamb=300;  
real dt=0.08;  
real rho=4430;  
real Cp=500;  
real cond=10;  
real h=10;

for (int i = 0; i \< 1; i++)

```
{

```

fespace Vh(Th1,P1);  
Vh Told=Tamb, T=Tamb, TT;

/////////////////////////// Varf Function ////////////////////////

varf vA(T, TT)  
= int3d(Th1)  
(  
rho_Cp_T_TT/dt  
+ cond_(dx(T)\*dx(TT) + dy(T)\*dy(TT) + dz(T)\*dz(TT))  
)

- int2d(Th1, 1)(h_T_TT)  
;

varf vB(T, TT) = int3d(Th1)(rho_Cp_T_TT/dt) ;  
varf vRHS(T,TT) = int2d(Th1, 1)(h_Tamb_TT) + int2d(Th1,1)( (fluxVECTOR(1.2e8_0.45_exp((-2_((x-(xMax-2_cellx))^2+(z-(1.5e-3))^2))/(2_cellx)^2) ) _(1-part2)) ’_ normal\*TT ) ;

real[int] rhs0 = vRHS(0, Vh);  
matrix A = vA(Vh, Vh, solver=GMRES); ////// Stiffness Matrix  
matrix B = vB(Vh, Vh); ////// Mass Matrix

real[int] b = B\*T[];  
b += rhs0;

```
T[] = A^-1*b;

```

int[int] Order = [1];  
savevtk(“Varf.vtu”, Th1,T, dataname=“Temp”, order=Order);

```
}
```

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://community.freefem.org/u/Mik)\
**Post date:** [December 23, 2020, 8:35am UTC](https://community.freefem.org/t/exchange-of-estimated-temperature-between-two-mesh/702/4 "2020-12-23T08:35:55Z")

</div>

Currently its reading only Th1, but I would like that in my next iteration I read Th2 and initial condition of part under Th1 from the previous iteration and rest of the section as T ambient.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [December 23, 2020, 8:50am UTC](https://community.freefem.org/t/exchange-of-estimated-temperature-between-two-mesh/702/5 "2020-12-23T08:50:09Z")

</div>

Since you use `trunc`, you can use the `new2old` + `restrict` keywords to do very cheap interpolations between both meshes. I’d suggest you go through this [movie](https://youtu.be/-Aw2O46V2bo?t=1590) which explains how.

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://community.freefem.org/u/Mik)\
**Post date:** [December 23, 2020, 10:10am UTC](https://community.freefem.org/t/exchange-of-estimated-temperature-between-two-mesh/702/6 "2020-12-23T10:10:07Z")

</div>

Thank you so much for your help. It is working perfectly .  
Have a great day ahead.
