PETSc interpolate a function from global to local mesh

Dear FreeFem users and developers,

I know which is possible to “recollect” te results obtained in parallel on the tocal mesh to the global (starting) one using the mpiAllReduce(u,uS,mpiCommWorld, mpiSUM) command. Is there a function whch is doing the opposite, so dictributing a global variable on the local mesh?

I need this since I am loading from a file, node by node, a variable of my problem and so it is strictly defined on the global mesh. By the way to perform the computations I need to move it in the local one.

Thank you in advance for your help.

Sincerely

Marco

Like this? See this example.

int[int] n2o, rest;
rest = restrict(MhLocal, MhGlobal, n2o); // local/global fespace restriction
uLocal[] = uGlobal[](rest); //restrict global solution to each local mesh

I’m not sure that this is exactly what I need. Just to be clearer what I am doing is something like that:

  • I am meshing my domain starting from a point cloud, knowing the load on that point cloud.
mesh Th = triangulate(fname);
  • I get the load from the point cloud file
fespace Vh(Th,P1);

Vh EE;

{
    ifstream file(fname);
    real xx,yy;
    for(int i = 0; i < EE.n; i++)
        file >> xx >> yy >> EE[][i];
}
  • Now what I would like to do is to produce a local mesh using PETSc (buildDmesh(Th)) and then having a VhPar EEpar which is the exact correspondence of the previously defined EE on the obtained local mesh

I hope now it is clearer!

I don’t think that any of that should cause a problem… Try:

mesh ThG = triangulate(fname);
fespace VhG(ThG,P1);
VhG EE;
{
    ifstream file(fname);
    real xx,yy;
    for(int i = 0; i < EE.n; i++)
        file >> xx >> yy >> EE[][i];
}
mesh ThPar = ThG;
int[int] n2o, rest;
macro ThN2O()n2o// EOM
buildDmesh(ThPar);
fespace VhPar(ThPar,P1);
VhPar EEpar;
rest = restrict(VhPar, VhG, n2o); // local/global fespace restriction
EEpar[] = EE[](rest); //restrict global solution to each local mesh

Unfortunately this option provides me a PETSc error:

Please attach a reproducer script (without any fileread dependencies) if you’d like help debugging.

Even with the extremely simple condition reported below the procedure leads to the PETSc error:

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


string fname = "Tungsten_5deg_FF.txt";

//mesh Th = triangulate(fname);
mesh Th = square(10,10);

plot(Th);

fespace Vh(Th,P1);

Vh EE;

EE = x^2;
/*
{
    ifstream file(fname);
    real xx,yy;
    for(int i = 0; i < EE.n; i++)
        file >> xx >> yy >> EE[][i];
}
*/
mesh ThPar = Th;

int[int] n2o, rest;

macro ThN2O()n2o //EOM

buildDmesh(ThPar);

fespace VhPar(ThPar,P1);

VhPar EEpar;

rest = restrict(VhPar,Vh,n2o);

EEpar[] = EE[](rest);

The commented part is the original one which has been substituted by a simpler mesh and EE.

Thank you very much for your help!

Ah yes, my mistake. Just change the name of the macro ThN2o to ThParN2o.

Oh that’s true! Thank you very much @cmd !

Now I’m ok!

1 Like