Copy variables between different meshes with PETSc

Dear Sir or Madam,

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
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(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