//ff-mpirun  -np  4 diffusion-3d-minimal-ddm.edp -wg -raspart -ffddm_schwarz_method ras -ffddm_schwarz_coarse_correction BNN -ffddm_geneo_nu 10 -global 20

// If you have openmpi you may need to add the option --oversubscribe to allow more processes than the number of cores available on your computer

// Abstract :  "Lap: RAS + GENEO :" << endl; //second level method with a GenEO coarse space

// for the make check:
// NBPROC 4
// PARAM -raspart -ffddm_schwarz_method ras -ffddm_schwarz_coarse_correction BNN -ffddm_geneo_nu 10 -global 20

macro dimension 3// EOM            // 2D or 3D


include "ffddm.idp"

macro def(i)i// EOM                         // scalar field definition
macro init(i)i// EOM                        // scalar field initialization
macro grad(u)[dx(u), dy(u), dz(u)]// EOM    // three-dimensional gradient
func Pk = P1;                               // finite element space

int[int] LL = [2,2, 1,2, 2,2];
mesh3 ThGlobal = cube(getARGV("-global", 10), getARGV("-global", 10), getARGV("-global", 10),
    [x, y, z], label = LL);      // global mesh

macro Varf(varfName, meshName, PhName)
    varf varfName(u,v) = int3d(meshName)(grad(u)' * grad(v)) + int3d(meshName)(v) + on(1, u = 1.0); // EOM
       
// Domain decomposition
ffddmbuildDmesh( Lap , ThGlobal , mpiCommWorld )
ffddmbuildDfespace( Lap , Lap , real , def , init , P1 )
ffddmsetupOperator(Lap ,Lap , Varf)

// Domain decomposition solve
real[int] rhs(LapVhi.ndof);//rhs(1) works as well 
ffddmbuildrhs(Lap , Varf , rhs )
LapVhi def(u) ;

// Two-level Schwarz solve
ffddmsetupPrecond(Lap,Varf)
ffddmgeneosetup(Lap,Varf)

real[int] x0(LapVhi.ndof);
x0 = 0;
u[] = LapfGMRES(x0, rhs, 1.e-6, 200, "right");
Lapwritesummary//process 0 prints convergence history
ffddmplot(Lap,u, "Lap Global solution with fGMRES");
