# Copy variables between different meshes with PETSc

**URL:** <https://community.freefem.org/t/copy-variables-between-different-meshes-with-petsc/390>\
**Category:** General Discussion\
**Created:** [May 5, 2020, 9:03am UTC](https://community.freefem.org/t/copy-variables-between-different-meshes-with-petsc/390 "2020-05-05T09:03:42Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [May 5, 2020, 3:34pm UTC](https://community.freefem.org/t/copy-variables-between-different-meshes-with-petsc/390/2 "2020-05-05T15:34:03Z")

</div>

Dear Tak,  
You can use the newly implemented routine `transfer` to help you go between one distributed solution to another. If you want the `transfer` PETSc `Mat`, you can use the `transferMat` function, see this new example [PtAP-2d-PETSc.edp](https://github.com/FreeFem/FreeFem-sources/blob/develop/examples/hpddm/PtAP-2d-PETSc.edp).  
Here is the function used in your code, and the resulting screenshots.

```auto
load "PETSc"
macro dimension()2// EOM
include "macro_ddm.idp"

meshN Sh1=square(30,30,[x,y]);
meshN Sh2=square(50,50,[x,y]);

buildDmesh(Sh1)
buildDmesh(Sh2)

fespace Ph1(Sh1, P2);
Ph1 u=sin(4*x)+cos(5*y);

fespace Ph2(Sh2, P2);
Ph2 v;
// v=u;

macro defPlot(u)u//
transfer(Sh1, P2, u, Sh2, P2, v);
plotMPI(Sh1, u, P2, defPlot, real, cmm = "u")
plotMPI(Sh2, v, P2, defPlot, real, cmm = "v")

```

 ![Screenshot 2020-05-05 at 5.32.58 PM](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/bb5d0a6c8427473dc5c962d344aac906c3a7da49.png) ![Screenshot 2020-05-05 at 5.33.07 PM](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/261797680ef643ef734ce318cd94aa6e962f0b34.png)

---

_[View the full topic](https://community.freefem.org/t/copy-variables-between-different-meshes-with-petsc/390)._
