Actual source code: example2.edp
 1 /*******************************************************
 2  *  This file is part of the FreeFEM tutorial made by  *
 3  *      Pierre Jolivet <pierre@joliv.et>               *
 4  *                                                     *
 5  *  See https://joliv.et/FreeFem-tutorial for more     *
 6  *                                                     *
 7  *   Description: simple two-way domain decomposition  *
 8  *                in parallel                          *
 9  *******************************************************/
 
11 load "Element_P3"
12 assert(mpisize == 2);
13 macro dimension()2// EOM
14 include "macro_ddm.idp"
 
16 int[int] l = [2, 2, 2, 2];
17 mesh T = square(50, 60, label = l, [5.0/6.0 * x, y]);
18 mesh Ttop = trunc(T, x < 1.0/3.0, label = 1);
19 Ttop = trunc(Ttop, y > 0.7, label = 10);
20 Ttop = movemesh(Ttop, [1.0/3.0 - x, y]);
21 mesh Tt = trunc(T, !(y > 0.7 || (x > 1.0/3.0 && y < 0.3)), label = 2);
 
23 meshN Th = Ttop + Tt;
24 fespace Vh(Th, P3);
25 int[int][int] intersection;
26 real[int] D;
27 {
28     fespace Ph(Th, P0);
29     Ph part = x < 1.0/3.0 ? 1 : 0;
30     plot(part, wait = 1);
31     buildWithPartitioning(Th, part[], 1, intersection, D, P3, mpiCommWorld);
32 }
 
34 macro def(i)i// EOM
35 Vh plt;
36 plt[] = D;
37 plotMPI(Th, plt, P3, def, real, cmm = "Partition of unity");
 
39 if(mpirank == 1) {
40     mpiRequest[int] rq(2);
41     Isend(processor(0, mpiCommWorld, rq[0]), Th);
42     Isend(processor(0, mpiCommWorld, rq[1]), D);
43     for(int i = 0; i < 2; ++i) mpiWaitAny(rq);
44 }
45 else { // mpirank == 0
46     mpiRequest rq;
47     meshN ThFromProcess1;
48     Irecv(processor(1, mpiCommWorld, rq), ThFromProcess1);
49     mpiWait(rq);
50     fespace VhLocalToProcess1(ThFromProcess1, P3);
51     VhLocalToProcess1 recv;
52     Irecv(processor(1, mpiCommWorld, rq), recv[]);
53     mpiWait(rq);
54     Vh punity;
55     punity[] = D;
56     plot(punity, cmm = "Partition of unity of process #0", wait = 1);
57     plot(recv, cmm = "Partition of unity of process #1", wait = 1);
58 }