# Copy variables between different meshes with PETSc

I would like to use different 2 meshes with PETSc.
Additionally, variables want to be copied from each other.
However, as shown following codes, the direct copy, such as “v=u”, does not work.

Would you please let me know how to do it?

Thank you very much in advance.
Best regards,
Tak

// \$ ff-mpirun -np 4 script.edp -wg -ne
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(4x)+cos(5y);

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

macro defPlot(u)u//
plotMPI(Sh2, v, P2, defPlot, real, cmm = “v”)

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.
Here is the function used in your code, and the resulting screenshots.

``````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")
``````

1 Like

Dear Professor prj,
Thank you very much for your quick response and your great assistance. Your answer have been of great help to me in my work.

Best,
Tak

Dear Professor Prj,

I’m new to freefem. I’m trying to use the function transfer but I always have some errors. I ran this code that you’ve posted in your reply to Tak and it didn’t work. Is it necessary to have any archive in the same folder of the original code?

Best regards,
Jorge Morvan

What is the error, and which FreeFEM version are you using?

Dear professor Prj,

I have a compile error that seems to be associated with “macro_ddm.idp”. This is the message I get and also the line in which the error occurs:

820 @ real timerPartition = mpiWtime The Identifier mpiWtime does not exist

Error line number 820, in file macro: buildOverlapEdgePeriodicRecursive in C:\Program Files (x86)\FreeFem++\idp\macro_ddm.idp, before token mpiWtime

I’m using the version 4.7-1.

Thank you!
Jorge Morvan

You are using the `FreeFem++` binary, you need to use `FreeFem++-mpi`.

1 Like

Ok, I see!

Thank you!
Jorge Morvan