Debian Codegraph @

idp/macro_ddm_substructuring.idp

raw
1 include "macro_ddm.idp"
2
3 macro partitionSubstructuring(meshName, interfaceNb, globalName, PhGlobal, part, s, ndofSkeleton, BC, comm, fakeInterface, labDirichlet)
4 meshName = trunc(globalName, abs(part - mpiRank(comm)) < 0.1, label = fakeInterface);
5 fespace VhGlobal(globalName, P1);
6 PhGlobal supp = abs(part - mpiRank(comm)) < 0.1;
7 VhGlobal suppSmooth;
8 AddLayers(globalName, supp[], 2, suppSmooth[]);
9 ndofSkeleton.resize(1);
10 ndofSkeleton[0].resize(0);
11 {
12 int[int] n2o;
13 meshN neighbors = trunc(globalName, suppSmooth > 0.001, new2old = n2o);
14 int[int] partOverlap(n2o.n);
15 for[i, v : n2o] partOverlap[i] = part[][v];
16 Unique(partOverlap, ndofSkeleton[0], remove = mpiRank(comm));
17 }
18 VhGlobal[int] partitionIntersection(ndofSkeleton[0].n);
19 if(s > 1) {
20 globalName = trunc(globalName, suppSmooth > 0.001, split = s, label = fakeInterface);
21 supp = abs(part - mpiRank(comm)) < 0.1;
22 suppSmooth = 0;
23 AddLayers(globalName, supp[], 2, suppSmooth[]);
24 meshName = trunc(meshName, 1, split = s);
25 }
26 globalName = trunc(globalName, suppSmooth > 0.501, label = fakeInterface);
27 real eps = intN(globalName)(1.0);
28 real[int] epsTab(ndofSkeleton[0].n);
29 mpiRequest[int] rq(2 * ndofSkeleton[0].n);
30 for(int j = 0; j < ndofSkeleton[0].n; ++j)
31 Irecv(processor(ndofSkeleton[0][j], comm, rq[j]), epsTab[j]);
32 for(int j = 0; j < ndofSkeleton[0].n; ++j)
33 Isend(processor(ndofSkeleton[0][j], comm, rq[ndofSkeleton[0].n + j]), eps);
34 VhGlobal phi = 0;
35 part = part;
36 int numberIntersection = 0;
37 for(int k = 0; k < 2 * ndofSkeleton[0].n; ++k)
38 mpiWaitAny(rq);
39 for(int i = 0; i < ndofSkeleton[0].n; ++i) {
40 PhGlobal suppPartition = abs(ndofSkeleton[0][i] - part) < 0.1;
41 AddLayers(globalName, suppPartition[], 1, phi[]);
42 if(intN(globalName)(phi) / min(eps, epsTab[i]) > 1.0e-10) {
43 partitionIntersection[numberIntersection] = phi;
44 ndofSkeleton[0][numberIntersection++] = ndofSkeleton[0][i];
45 }
46 }
47 if(numberIntersection != ndofSkeleton[0].n)
48 ndofSkeleton[0].resize(numberIntersection);
49 Wh def(interface);
50 varf vPbInterface(def(u), def(v)) = on(fakeInterface, BC(u, 1.0)) + on(labDirichlet, BC(u, 0.0));
51 interface[] = vPbInterface(0, Wh, tgv = 1);
52 matrix[int] R(ndofSkeleton[0].n);
53
54 for(int i = 0; i < ndofSkeleton[0].n; ++i) {
55 meshN meshIntersection = trunc(globalName, (part == mpiRank(comm) || part == ndofSkeleton[0][i]) && partitionIntersection[i] > 1e-6, label = fakeInterface);
56 fespace WhIntersection(meshIntersection, Pk);
57 R[i] = interpolate(WhIntersection, Wh, inside = 1);
58 }
59 buildSkeleton(interface[], R, ndofSkeleton, interface = interfaceNb, redundancy = getARGV("-redundancy", 1), communicator = comm);// EOM
60
61 macro buildSubstructuringWithPartitioning(Th, interfaceNb, userPartitioning, fakeInterface, labDirichlet, labNeumann, s, intersection, P, BC, comm, excluded)
62 {
63 real timing = mpiWtime();
64 fespace WhLocal(Th, Pk);
65 if(mpiSize(comm) > 1 && !excluded) {
66 meshN ThGlobal = Th;
67 fespace PhGlobal(ThGlobal, P0);
68 PhGlobal partGlobal;
69 if(userPartitioning.n != PhGlobal.ndof) {
70 if(mpiRank(comm) == 0) {
71 if(verbosity > 0)
72 cout.scientific << " --- global mesh of " << ThGlobal.nt << " elements (prior to refinement) partitioned with " << Stringification(partitioner);
73 timing = mpiWtime();
74 partitionerSeq(partGlobal[], ThGlobal, mpiSize(comm));
75 }
76 partitionerPar(partGlobal[], ThGlobal, comm, mpiSize(comm));
77 if(mpiRank(comm) == 0 && verbosity > 0)
78 cout.scientific << " (in " << mpiWtime() - timing << ")" << endl;
79 timing = mpiWtime();
80 }
81 else {
82 partGlobal[] = userPartitioning;
83 broadcast(processor(0, comm), partGlobal[]);
84 }
85 partitionSubstructuring(Th, interfaceNb, ThGlobal, PhGlobal, partGlobal, s, intersection, BC, comm, fakeInterface, labDirichlet)
86 }
87 else if(mpiSize(comm) == 1) {
88 if(s > 1)
89 Th = trunc(Th, 1, split = s);
90 Wh def(interface);
91 varf vPbInterface(def(u), def(v)) = on(labNeumann, BC(u, 1.0)) + on(labDirichlet, BC(u, 0.0));
92 interface[] = vPbInterface(0, Wh, tgv = 1);
93 interfaceNb.resize(Wh.ndof);
94 int j = 0;
95 for(int i = 0; i < Wh.ndof; ++i) {
96 if(interface[][i] > 0.9)
97 interfaceNb[j++] = i;
98 }
99 interfaceNb.resize(j);
100 }
101 mpiBarrier(mpiCommWorld);
102 if(verbosity > 0 && mpirank == 0) cout.scientific << " --- partition of unity built (in " << mpiWtime() - timing << ")" << endl;
103 }// EOM
104
105 macro buildSubstructuring(Th, interfaceNb, fakeInterface, labDirichlet, labNeumann, s, intersection, P, BC, comm, excluded)
106 {
107 real[int] emptyArray(0);
108 buildSubstructuringWithPartitioning(Th, interfaceNb, emptyArray, fakeInterface, labDirichlet, labNeumann, s, intersection, P, BC, comm, excluded)
109 }// EOM