Debian Codegraph @

idp/ffddm_geneoCS.idp

raw
1 macro ffddmdeflateglobalvector(pr,u)
2 if (pr#prfe#prmesh#isincomm)
3 {
4 pr#Z.resize(pr#Z.n+1);
5 if (!pr#prfe#prmesh#excluded) {
6 assert(u.n == pr#prfe#Vhi.ndof);
7 pr#Z[pr#Z.n-1].resize(u.n);
8 pr#Z[pr#Z.n-1] = u;
9 }
10 else
11 pr#Z[pr#Z.n-1].resize(pr#prfe#Vhi.ndof);
12 pr#sg++;
13 }
14 // EOM
15
16 macro ffddmbuildZTAZ(prT,pr,Varf)
17
18 if (pr#prfe#prmesh#isincomm)
19 {
20 pr#prfe#prmesh#tic(pr#tloc)
21
22 IFMACRO(!pr#bem)
23 pr#E.clear;
24 ENDIFMACRO
25
26 if (!bpara) {
27 assert (Stringification(prT) == Stringification(pr)); /* TODO */
28 pr#ncoarsespace = pr#si + pr#sg; /* local and global deflation vectors */
29 if (mpiRank(pr#prfe#prmesh#mpicomm) == 0)
30 cout << "["+Stringification(pr)+"] CS size = " << pr#ncoarsespace << endl;
31 }
32 else {
33 pr#ncoarsespace = 0; /* coarse space dimension */
34 mpiAllReduce(pr#si,pr#ncoarsespace,pr#prfe#prmesh#mpicomm,mpiSUM);
35 pr#ncoarsespace += pr#sg; /* add global deflation vectors */
36 }
37
38 if (pr#ncoarsespace > 0)
39 if (!bpara) {
40 IFMACRO(pr#bem,1)
41 if (mpirank == 0) cout << "TODO" << endl;
42 assert(0);
43 ENDIFMACRO
44 IFMACRO(!pr#bem)
45 pr#prfe#K[int,int] Zm(pr#prfe#Ndofglobal,pr#ncoarsespace);
46 int cpt = 0;
47 /* the 2 fors loop over the columns of Z subdomainwise */
48 for (int jj=0; jj<pr#prfe#prmesh#npart; jj++)
49 for (int ii=0; ii < pr#sizelg[jj]; ii++) {
50 pr#prfe#K[int] tmp(pr#prfe#Rih[jj].m);
51 tmp = pr#prfe#Rih[jj]'*pr#Z[cpt];
52 Zm(:,cpt) = tmp;
53 cpt++; /* keeps track of the global numbering of the columns of Z */
54 }
55 /* global deflation vectors */
56 for (int ii=0; ii < pr#sg; ii++) {
57 Zm(:,cpt) = pr#Z[cpt];
58 cpt++;
59 }
60
61 matrix<pr#prfe#K> Zms = Zm;
62 matrix<pr#prfe#K> tmp = pr#Aglobal*Zms;
63 pr#E = Zms'*tmp;
64 set(pr#E,solver=sparsesolver,sym=vsym,commworld=pr#prfe#prmesh#commself,factorize=3);
65 ENDIFMACRO
66 }
67 else {
68 /* Assemble E on proc 0
69 see PhD thesis of P.Jolivet pag 46 and following */
70
71 pr#offseti = 0; /* offseti[i]: index of the first ev of the subdomain i in the global numbering of the columns of Z */
72 for (int ii=0; ii < pr#prfe#prmesh#npart; ii++)
73 pr#offseti[ii] = (ii == 0 ? 0 : pr#offseti[ii-1] + pr#sizelg[ii-1]);
74
75 if (!pr#prfe#prmesh#exclude) {
76 pr#sizelgworld = pr#sizelg;
77 pr#offsetiworld = pr#offseti;
78 }
79 else {
80 for (int i = 0; i < mpiSize(pr#prfe#prmesh#mpicomm); i++) {
81 if (i < pr#prfe#prmesh#pCS) {
82 pr#sizelgworld[i] = 0;
83 pr#offsetiworld[i] = 0;
84 }
85 else {
86 pr#sizelgworld[i] = pr#sizelg[i-pr#prfe#prmesh#pCS];
87 pr#offsetiworld[i] = pr#offseti[i-pr#prfe#prmesh#pCS];
88 }
89 }
90 }
91
92 /* PRT */
93 prT#ncoarsespace = 0; /* coarse space dimension */
94 mpiAllReduce(prT#si,prT#ncoarsespace,prT#prfe#prmesh#mpicomm,mpiSUM);
95 prT#ncoarsespace += prT#sg; /* add global deflation vectors */
96 if (mpiRank(prT#prfe#prmesh#mpicomm) == 0)
97 cout << "["+Stringification(pr)+"] CS size = " << pr#ncoarsespace << " x " << prT#ncoarsespace << endl;
98
99 /* Assemble E on proc 0
100 see PhD thesis of P.Jolivet pag 46 and following */
101
102 if (Stringification(prT) == Stringification(pr))
103 prT#sizelg = pr#sizelg;
104
105 prT#offseti = 0; /* offseti[i]: index of the first ev of the subdomain i in the global numbering of the columns of Z */
106 for (int ii=0; ii < prT#prfe#prmesh#npart; ii++)
107 prT#offseti[ii] = (ii == 0 ? 0 : prT#offseti[ii-1] + prT#sizelg[ii-1]);
108
109 if (!prT#prfe#prmesh#exclude) {
110 prT#sizelgworld = prT#sizelg;
111 prT#offsetiworld = prT#offseti;
112 }
113 else {
114 for (int i = 0; i < mpiSize(prT#prfe#prmesh#mpicomm); i++) {
115 if (i < prT#prfe#prmesh#pCS) {
116 prT#sizelgworld[i] = 0;
117 prT#offsetiworld[i] = 0;
118 }
119 else {
120 prT#sizelgworld[i] = prT#sizelg[i-prT#prfe#prmesh#pCS];
121 prT#offsetiworld[i] = prT#offseti[i-prT#prfe#prmesh#pCS];
122 }
123 }
124 }
125
126 pr#prfe#K[int,int] AiZmi(1,1); /* A_i Z_i */
127 pr#prfe#K[int,int] AZmg(1,1); /* A Z_g for global deflation vectors */
128
129 IFMACRO(pr#localmacrominoverlap,1)
130 ffddmsetupOperator(localprAug, pr#prfe#Aug, Varf)
131 ;
132 ENDIFMACRO
133
134 IFMACRO(pr#bem,1)
135 int cpt = 0;
136 pr#prfe#K[int,int] AZmi(1,1);
137 if (!pr#prfe#prmesh#excluded && pr#si > 0)
138 AiZmi.resize(pr#prfegeneo#Dk[mpiRank(pr#prfegeneo#prmesh#commddm)].n,pr#ncoarsespace);
139
140 {
141 pr#prfe#K[int] vin(pr#prfegeneo#AugVhi.ndof*pr#si);
142 pr#prfe#K[int] vout(pr#prfegeneo#Vhglob.ndof*pr#si);
143
144 for (int j=0; j<pr#si; j++)
145 vin(j*pr#prfegeneo#AugVhi.ndof:(j+1)*pr#prfegeneo#AugVhi.ndof-1) = pr#prfegeneo#Auginterp'*pr#Z[j];
146
147 vin.im *= -1;
148 vout = pr#ADirichlettildebande'*vin;
149 vout.im *= -1;
150
151 for (int i=0; i<pr#prfe#prmesh#npart; ++i) {
152 pr#prfe#K[int] voutj(pr#prfegeneo#Vhglob.ndof*pr#sizelg[i]);
153 if (i == mpiRank(pr#prfe#prmesh#commddm))
154 voutj = vout;
155 broadcast(processor(i,pr#prfe#prmesh#commddm), voutj);
156 for (int j=0; j<pr#sizelg[i]; j++)
157 AiZmi(:,cpt++) = pr#prfe#Rih[mpiRank(pr#prfe#prmesh#commddm)]*voutj(j*pr#prfegeneo#Vhglob.ndof:(j+1)*pr#prfegeneo#Vhglob.ndof-1);
158 }
159 }
160
161 pr#prfe#K[int,int] Eig(prT#si,pr#ncoarsespace);
162 for (int jj=0; jj < pr#si; jj++) {
163 pr#prfe#K[int] Eji = AiZmi'*pr#Z[jj];
164 NewMacro localmacroK pr#prfe#K EndMacro
165 IFMACRO(localmacroK,complex)
166 Eji.im *= -1;
167 ENDIFMACRO
168 Eig(jj,:) = Eji;
169 }
170
171 pr#prfe#K[int,int][int] tabEig(pr#prfe#prmesh#npart);
172 if (mpiRank(pr#prfe#prmesh#mpicomm) < pr#prfe#prmesh#pCS) {
173 for (int i = !pr#prfe#prmesh#excluded; i < pr#prfe#prmesh#npart; i++)
174 tabEig[i].resize(prT#sizelg[i],pr#ncoarsespace);
175 mpiRequest[int] rqt(pr#prfe#prmesh#npart-(!pr#prfe#prmesh#excluded));
176 for (int i = !pr#prfe#prmesh#excluded; i < pr#prfe#prmesh#npart; i++)
177 Irecv(processor(i,pr#prfe#prmesh#mpicomm,rqt[i-!pr#prfe#prmesh#excluded]),tabEig[i]);
178 for (int i = !pr#prfe#prmesh#excluded; i < pr#prfe#prmesh#npart; i++)
179 int k = mpiWaitAny(rqt);
180 }
181 else if (!pr#prfe#prmesh#excluded) {
182 mpiRequest rqt;
183 Isend(processor(0,pr#prfe#prmesh#mpicomm,rqt),Eig);
184 mpiWait(rqt);
185 }
186
187 pr#prfe#K[int,int] E0(1,1);
188 assert (pr#prfe#prmesh#pCS == 1);
189 if (mpiRank(pr#prfe#prmesh#mpicomm) < pr#prfe#prmesh#pCS) {
190 int[int] offsetl(pr#prfe#prmesh#npart);
191 for (int i = 0; i < pr#prfe#prmesh#npart; i++)
192 offsetl[i] = (i == 0 ? 0 : offsetl[i-1] + pr#sizelg[(i-1)]);
193
194 int[int] offsetc(pr#prfe#prmesh#npart);
195 for (int i = 0; i < pr#prfe#prmesh#npart; i++)
196 offsetl[i] = (i == 0 ? 0 : offsetl[i-1] + pr#sizelg[(i-1)]);
197
198 E0.resize(offsetl[pr#prfe#prmesh#npart-1] + pr#sizelg[(pr#prfe#prmesh#npart-1)] + (mpiRank(pr#prfe#prmesh#mpicomm)==0)*prT#sg, pr#ncoarsespace);
199
200 int[int] renumi = (0:prT#sizelg[0]-1);
201 int[int] renumj = (0:pr#ncoarsespace-1);
202 for (int j=0; j<prT#sizelg[0]; j++)
203 E0(j,:) = Eig(j,:);
204
205 for (int i = !pr#prfe#prmesh#excluded; i < pr#prfe#prmesh#npart; i++) {
206 for (int j=0; j<prT#sizelg[i]; j++)
207 E0(offsetl[i]+j,:) = tabEig[i](j,:);
208 }
209 }
210
211 real[int] xg(pr#prfe#prmesh#npart);
212 real[int] yg(pr#prfe#prmesh#npart);
213 real[int] zg(pr#prfe#prmesh#npart);
214
215 real[int] xgg(pr#prfe#prmesh#npart);
216 real[int] ygg(pr#prfe#prmesh#npart);
217 real[int] zgg(pr#prfe#prmesh#npart);
218
219 for (int i = 0; i < pr#prfe#prmesh#Thi.nv; i++) {
220 xg[mpirank] += pr#prfe#prmesh#Thi(pr#prfe#prmesh#Thi(i)).x;
221 yg[mpirank] += pr#prfe#prmesh#Thi(pr#prfe#prmesh#Thi(i)).y;
222 zg[mpirank] += pr#prfe#prmesh#Thi(pr#prfe#prmesh#Thi(i)).z;
223 }
224 xg[mpirank] /= pr#prfe#prmesh#Thi.nv;
225 yg[mpirank] /= pr#prfe#prmesh#Thi.nv;
226 zg[mpirank] /= pr#prfe#prmesh#Thi.nv;
227
228 mpiAllReduce(xg, xgg, mpiCommWorld, mpiSUM);
229 mpiAllReduce(yg, ygg, mpiCommWorld, mpiSUM);
230 mpiAllReduce(zg, zgg, mpiCommWorld, mpiSUM);
231
232 if (mpirank == 0) {
233 real[int] xx(pr#ncoarsespace),yy(pr#ncoarsespace),zz(pr#ncoarsespace);
234 int cpt = 0;
235 for (int i=0; i<pr#prfe#prmesh#npart;i++)
236 for (int j=0; j<prT#sizelg[i]; j++) {
237 xx[cpt] = xgg[i];
238 yy[cpt] = ygg[i];
239 zz[cpt] = zgg[i];
240 cpt++;
241 }
242
243 pr#E = compress(E0,xx,yy,zz,commworld=mpiCommSelf);
244 set(pr#E,solver="HLU",factorize=3);
245 E0.resize(1,1);
246 }
247 ENDIFMACRO /* end if (pr#bem) */
248
249 IFMACRO(!pr#bem)
250 if (!pr#prfe#prmesh#excluded && pr#si > 0)
251 AiZmi.resize(pr#prfegeneo#Dk[mpiRank(pr#prfegeneo#prmesh#commddm)].n,pr#si);
252 int ni = pr#prfe#prmesh#excluded ? pr#prfe#Vhi.ndof : pr#prfegeneo#Dk[mpiRank(pr#prfegeneo#prmesh#commddm)].n;
253 if (pr#sg > 0)
254 AZmg.resize(ni,pr#sg);
255
256 for (int ii=0; ii < pr#si; ii++) {
257 IFMACRO(pr#localmacrominoverlap,1)
258 pr#prfe#K[int] tmp2 = pr#prfegeneo#interp'*pr#Z[ii];
259 pr#prfe#K[int] tmp = localprAug#aRd[mpiRank(pr#prfegeneo#prmesh#commddm)]*tmp2;
260 ENDIFMACRO
261 IFMACRO(pr#localmacrominoverlap,0)
262
263 IFMACRO(pr#geneofullpattern)
264 pr#prfe#K[int] tmp = pr#geneofullpatternOP(pr#Z[ii],1);
265 ENDIFMACRO
266 IFMACRO(!pr#geneofullpattern)
267 pr#prfe#K[int] tmp = pr#aRd[mpiRank(pr#prfe#prmesh#commddm)]*pr#Z[ii];
268 ENDIFMACRO
269
270 ENDIFMACRO
271 AiZmi(:,ii) = tmp;
272 }
273
274 for (int ii=0; ii < pr#sg; ii++)
275 AZmg(:,ii) = pr#A(pr#Z[pr#si+ii]);
276
277 /* step 3 of P.Jolivet thesis (page 47) */
278 pr#prfe#K[int,int][int] mrcv(pr#prfegeneo#prmesh#numberIntersection);
279 pr#prfe#K[int,int][int] msnd(pr#prfegeneo#prmesh#numberIntersection);
280
281 pr#prfe#K[int,int] Eii(prT#si,pr#si);
282 pr#prfe#K[int,int][int] Eij(pr#prfegeneo#prmesh#numberIntersection);
283
284 pr#prfe#K[int,int] Egg(prT#sg,pr#sg);
285 pr#prfe#K[int,int] Eig(prT#si,pr#sg);
286
287 if (!pr#prfe#prmesh#excluded) {
288 mpiRequest[int] rq(pr#prfegeneo#prmesh#numberIntersection*2);
289 for(int j=0;j<pr#prfegeneo#prmesh#numberIntersection;++j) {
290 msnd[j].resize(pr#prfegeneo#restrictionIntersection[j].n,pr#si);
291 mrcv[j].resize(pr#prfegeneo#restrictionIntersection[j].n,pr#sizelg[pr#prfegeneo#prmesh#arrayIntersection[j]]);
292 for (int ii=0; ii<pr#si; ii++) {
293 pr#prfe#K[int] tmp = pr#prfegeneo#restrictionIntersection[j]*AiZmi(:,ii);
294 msnd[j](:,ii) = tmp;
295 }
296 }
297 for(int j=0;j<pr#prfegeneo#prmesh#numberIntersection;++j)
298 Isend(processor(pr#prfegeneo#prmesh#arrayIntersection[j],pr#prfegeneo#prmesh#commddm,rq[j*2]),msnd[j]);
299 for(int j=0;j<pr#prfegeneo#prmesh#numberIntersection;++j)
300 Irecv(processor(pr#prfegeneo#prmesh#arrayIntersection[j],pr#prfegeneo#prmesh#commddm,rq[j*2+1]),mrcv[j]);
301 for(int j=0;j<pr#prfegeneo#prmesh#numberIntersection*2;++j)
302 int k = mpiWaitAny(rq);
303
304 /* step 4 of P.Jolivet thesis (page 47) */
305 for (int ii=0; ii < prT#si; ii++)
306 for (int jj=0; jj < pr#si; jj++) {
307 IFMACRO(pr#localmacrominoverlap,1)
308 pr#prfe#K[int] tmp = pr#prfegeneo#interp*AiZmi(:,jj);
309 Eii(ii,jj) = prT#Z[ii]'*tmp;
310 ENDIFMACRO
311 IFMACRO(pr#localmacrominoverlap,0)
312 Eii(ii,jj) = prT#Z[ii]'*AiZmi(:,jj);
313 ENDIFMACRO
314 }
315
316 if (pr#regularizeE)
317 for (int ii=0; ii<Eii.n; ii++)
318 Eii(ii,ii) += pr#regularizeE;
319
320 /* step 5 of P.Jolivet thesis (page 47) */
321 for(int j=0;j<pr#prfegeneo#prmesh#numberIntersection;++j) {
322 Eij[j].resize(prT#si,pr#sizelg[pr#prfegeneo#prmesh#arrayIntersection[j]]);
323 for (int jj=0; jj < pr#sizelg[pr#prfegeneo#prmesh#arrayIntersection[j]]; jj++) {
324 IFMACRO(pr#localmacrominoverlap,1)
325 pr#prfe#K[int] tmp2(pr#prfegeneo#restrictionIntersection[j].m);
326 tmp2 = pr#prfegeneo#restrictionIntersection[j]'*mrcv[j](:,jj);
327 pr#prfe#K[int] tmp = pr#prfegeneo#interp*tmp2;
328 ENDIFMACRO
329 IFMACRO(pr#localmacrominoverlap,0)
330 pr#prfe#K[int] tmp(pr#prfegeneo#restrictionIntersection[j].m);
331 tmp = pr#prfegeneo#restrictionIntersection[j]'*mrcv[j](:,jj);
332 ENDIFMACRO
333 for (int ii=0; ii < prT#si; ii++){
334 Eij[j](ii,jj) = prT#Z[ii]'*tmp;
335 }
336 }
337 }
338 }
339
340 /*
341 for (int jj=0; jj < pr#sg; jj++) {
342 for (int ii=0; ii < prT#sg; ii++)
343 Egg(ii,jj) = pr#prfe#scalprod(prT#Z[ii+prT#si], AZmg(:,jj));
344
345 for (int ii=0; ii < prT#si; ii++)
346 Eig(ii,jj) = prT#Z[ii]'*AZmg(:,jj);
347 }
348 */
349
350 for (int jj=0; jj < pr#sg; jj++) {
351 pr#prfe#K[int] Zd = pr#prfe#Dk[mpiRank(pr#prfe#prmesh#commddm)].*prT#Z[jj+prT#si];
352 pr#prfe#K[int] Eji = AZmg'*Zd;
353 NewMacro localmacroK pr#prfe#K EndMacro
354 IFMACRO(localmacroK,complex)
355 Eji.im *= -1;
356 ENDIFMACRO
357 pr#prfe#K[int] Ejg(Eji.n);
358 mpiAllReduce(Eji,Ejg,pr#prfe#prmesh#mpicomm,mpiSUM);
359 Egg(jj,:) = Ejg;
360
361 for (int ii=0; ii < prT#si; ii++)
362 Eig(ii,jj) = prT#Z[ii]'*AZmg(:,jj);
363 }
364 if (pr#regularizeE)
365 for (int ii=0; ii<Egg.n; ii++)
366 Egg(ii,ii) += pr#regularizeE;
367
368 IFMACRO(pr#geneofullpattern)
369 pr#prfe#K[int,int][int] Zj(pr#prfegeneo#prmesh#numberIntersection);
370 int[int] tabarrayIntersectionflat(1);
371 pr#prfe#K[int,int][int] Ekj(1);
372
373 /* on recupere les Zj */
374 if (!pr#prfe#prmesh#excluded) {
375 mpiRequest[int] rq(pr#prfegeneo#prmesh#numberIntersection*2);
376 for(int j=0;j<pr#prfegeneo#prmesh#numberIntersection;++j) {
377 msnd[j].resize(pr#prfegeneo#restrictionIntersection[j].n,pr#si);
378 mrcv[j].resize(pr#prfegeneo#restrictionIntersection[j].n,pr#sizelg[pr#prfegeneo#prmesh#arrayIntersection[j]]);
379 for (int ii=0; ii<pr#si; ii++) {
380 pr#prfe#K[int] tmp = pr#prfegeneo#restrictionIntersection[j]*pr#Z[ii];
381 msnd[j](:,ii) = tmp;
382 }
383 }
384 for(int j=0;j<pr#prfegeneo#prmesh#numberIntersection;++j)
385 Isend(processor(pr#prfegeneo#prmesh#arrayIntersection[j],pr#prfegeneo#prmesh#commddm,rq[j*2]),msnd[j]);
386 for(int j=0;j<pr#prfegeneo#prmesh#numberIntersection;++j)
387 Irecv(processor(pr#prfegeneo#prmesh#arrayIntersection[j],pr#prfegeneo#prmesh#commddm,rq[j*2+1]),mrcv[j]);
388 for(int j=0;j<pr#prfegeneo#prmesh#numberIntersection*2;++j)
389 int k = mpiWaitAny(rq);
390
391 for(int j=0;j<pr#prfegeneo#prmesh#numberIntersection;++j) {
392 Zj[j].resize(pr#prfegeneo#restrictionIntersection[j].n,pr#sizelg[pr#prfegeneo#prmesh#arrayIntersection[j]]);
393 for (int jj=0; jj < pr#sizelg[pr#prfegeneo#prmesh#arrayIntersection[j]]; jj++) {
394 Zj[j](:,jj) = mrcv[j](:,jj);
395 }
396 }
397
398 /* on envoie aux voisins sa liste des voisins */
399 int[int] tabnumberIntersection(pr#prfegeneo#prmesh#numberIntersection);
400 int[int][int] tabarrayIntersection(pr#prfegeneo#prmesh#numberIntersection);
401 for (int i=0;i<pr#prfegeneo#prmesh#numberIntersection; i++)
402 tabarrayIntersection[i].resize(1000);
403
404 mpiRequest[int] rqt(4*pr#prfegeneo#prmesh#numberIntersection);
405 for(int j=0;j<pr#prfegeneo#prmesh#numberIntersection;++j) {
406 Isend(processor(pr#prfegeneo#prmesh#arrayIntersection[j],pr#prfegeneo#prmesh#commddm,rqt[4*j]),pr#prfegeneo#prmesh#numberIntersection);
407 Isend(processor(pr#prfegeneo#prmesh#arrayIntersection[j],pr#prfegeneo#prmesh#commddm,rqt[4*j+1]),pr#prfegeneo#prmesh#arrayIntersection);
408 }
409 for(int j=0;j<pr#prfegeneo#prmesh#numberIntersection;++j) {
410 Irecv(processor(pr#prfegeneo#prmesh#arrayIntersection[j],pr#prfegeneo#prmesh#commddm,rqt[4*j+2]),tabnumberIntersection[j]);
411 Irecv(processor(pr#prfegeneo#prmesh#arrayIntersection[j],pr#prfegeneo#prmesh#commddm,rqt[4*j+3]),tabarrayIntersection[j]);
412 }
413 for(int j=0;j<4*pr#prfegeneo#prmesh#numberIntersection;++j)
414 int k = mpiWaitAny(rqt);
415
416 int tabarrayIntersectionsum = 0;
417 int[int] tablgsum(pr#prfegeneo#prmesh#numberIntersection);
418 int[int][int] taboffset(pr#prfegeneo#prmesh#numberIntersection);
419 int mylgsum = 0;
420 int[int] myoffset(pr#prfegeneo#prmesh#numberIntersection);
421 for (int j=0; j<pr#prfegeneo#prmesh#numberIntersection; j++) {
422 tabarrayIntersection[j].resize(tabnumberIntersection[j]);
423 tabarrayIntersectionsum += tabarrayIntersection[j].n;
424 mylgsum += pr#sizelg[pr#prfegeneo#prmesh#arrayIntersection[j]];
425 myoffset[j] = (j == 0 ? 0 : myoffset[j-1] + pr#sizelg[pr#prfegeneo#prmesh#arrayIntersection[j-1]]);
426 taboffset[j].resize(tabarrayIntersection[j].n);
427 for (int i=0; i<tabarrayIntersection[j].n; i++) {
428 tablgsum[j] += pr#sizelg[tabarrayIntersection[j][i]];
429 taboffset[j][i] = (i == 0 ? 0 : taboffset[j][i-1] + pr#sizelg[tabarrayIntersection[j][i-1]]);
430 }
431 }
432
433 /* on calcule Si Zj et on envoie aux k */
434 mpiRequest[int] rq2(pr#prfegeneo#prmesh#numberIntersection*2);
435
436 for(int k=0;k<pr#prfegeneo#prmesh#numberIntersection;++k) {
437 msnd[k].resize(pr#prfegeneo#restrictionIntersection[k].n, mylgsum);
438 mrcv[k].resize(pr#prfegeneo#restrictionIntersection[k].n, tablgsum[k]);
439 }
440
441 for(int j=0;j<pr#prfegeneo#prmesh#numberIntersection;++j) {
442
443 for (int jj=0; jj<pr#sizelg[pr#prfegeneo#prmesh#arrayIntersection[j]]; jj++) {
444 pr#prfe#K[int] tmp(pr#prfegeneo#restrictionIntersection[j].m);
445 tmp = pr#prfegeneo#restrictionIntersection[j]'*Zj[j](:,jj);
446
447 pr#prfe#K[int] tmp2 = pr#geneofullpatternOP(tmp,1);
448
449 /* k == i */
450 for (int kk=0; kk < prT#si; kk++){
451 Eij[j](kk,jj) += prT#Z[kk]'*tmp2;
452 }
453
454 for(int k=0;k<pr#prfegeneo#prmesh#numberIntersection;++k) {
455 msnd[k](:,myoffset[j]+jj) = pr#prfegeneo#restrictionIntersection[k]*tmp2;
456 }
457 }
458 }
459
460 for(int k=0;k<pr#prfegeneo#prmesh#numberIntersection;++k)
461 Isend(processor(pr#prfegeneo#prmesh#arrayIntersection[k],pr#prfegeneo#prmesh#commddm,rq2[2*k]),msnd[k]);
462
463 for(int k=0;k<pr#prfegeneo#prmesh#numberIntersection;++k)
464 Irecv(processor(pr#prfegeneo#prmesh#arrayIntersection[k],pr#prfegeneo#prmesh#commddm,rq2[2*k+1]),mrcv[k]);
465
466 for(int j=0;j<2*pr#prfegeneo#prmesh#numberIntersection;++j)
467 int k = mpiWaitAny(rq2);
468
469 /* on calcule Zk Si Zj */
470 int[int] tabtmp(tabarrayIntersectionsum);
471
472 int cpt = 0;
473 for(int i=0;i<pr#prfegeneo#prmesh#numberIntersection;++i)
474 for (int j=0; j<tabarrayIntersection[i].n; j++)
475 tabtmp[cpt++] = tabarrayIntersection[i][j];
476 Unique(tabtmp,tabarrayIntersectionflat);
477
478 Ekj.resize(mpiSize(pr#prfegeneo#prmesh#commddm));
479
480 cpt = 0;
481 for(int i=0;i<pr#prfegeneo#prmesh#numberIntersection;++i) {
482 pr#prfe#K[int] tmp(pr#prfegeneo#restrictionIntersection[i].m);
483 for (int j=0; j<tabarrayIntersection[i].n; j++) {
484 if (Ekj[tabarrayIntersection[i][j]].n != prT#si) {
485 Ekj[tabarrayIntersection[i][j]].resize(prT#si,pr#sizelg[tabarrayIntersection[i][j]]);
486 Ekj[tabarrayIntersection[i][j]] = 0;
487 }
488 for (int jj=0; jj<pr#sizelg[tabarrayIntersection[i][j]]; jj++) {
489 tmp = pr#prfegeneo#restrictionIntersection[i]'*mrcv[i](:,taboffset[i][j]+jj);
490
491 for (int kk=0; kk < prT#si; kk++){
492 Ekj[tabarrayIntersection[i][j]](kk,jj) += prT#Z[kk]'*tmp;
493 }
494 }
495 cpt++;
496 }
497 }
498 }
499 ENDIFMACRO
500
501 IFMACRO(!pr#geneofullpattern)
502 int fullnumberIntersection = pr#prfegeneo#prmesh#numberIntersection;
503 int[int] fullarrayIntersection = pr#prfegeneo#prmesh#arrayIntersection;
504 ENDIFMACRO
505 IFMACRO(pr#geneofullpattern)
506 int fullnumberIntersection = pr#prfegeneo#prmesh#numberIntersection + tabarrayIntersectionflat.n;
507 int[int] fullarrayIntersection = [pr#prfegeneo#prmesh#arrayIntersection,tabarrayIntersectionflat];
508 ENDIFMACRO
509
510 if(!pr#prfe#prmesh#binexactCS) {
511
512 /* send Eij to processor p in commCS which assembles them inside E */
513
514 int locnpart = pr#prfe#prmesh#npart/pr#prfe#prmesh#pCS;
515 locnpart += pr#prfe#prmesh#npart-locnpart*pr#prfe#prmesh#pCS > mpiRank(pr#prfe#prmesh#mpicomm);
516
517 func int rkrdd(int i) {return i*pr#prfe#prmesh#pCS+mpiRank(pr#prfe#prmesh#mpicomm);};
518 func int rkr(int i) {return pr#prfe#prmesh#exclude*pr#prfe#prmesh#pCS+rkrdd(i);};
519
520 func int rks(int i) {return i%pr#prfe#prmesh#pCS;};
521
522 int[int] tabnumberIntersection(locnpart);
523 if (mpiRank(pr#prfe#prmesh#mpicomm) < pr#prfe#prmesh#pCS) {
524 mpiRequest[int] rqt(locnpart-(!pr#prfe#prmesh#excluded));
525 for (int i = !pr#prfe#prmesh#excluded; i < locnpart; i++)
526 Irecv(processor(rkr(i),pr#prfe#prmesh#mpicomm,rqt[i-!pr#prfe#prmesh#excluded]),tabnumberIntersection[i]);
527 for (int i = !pr#prfe#prmesh#excluded; i < locnpart; i++)
528 int k = mpiWaitAny(rqt);
529 }
530 else if (!pr#prfe#prmesh#excluded) {
531 mpiRequest rqt;
532 Isend(processor(rks(mpiRank(pr#prfe#prmesh#mpicomm)),pr#prfe#prmesh#mpicomm,rqt),fullnumberIntersection);
533 mpiWait(rqt);
534 }
535
536 int[int][int] tabarrayIntersection(locnpart); /* i: global numbering of neighbouring subdomains of proc i */
537
538 if (mpiRank(pr#prfe#prmesh#mpicomm) < pr#prfe#prmesh#pCS) {
539 for (int i = !pr#prfe#prmesh#excluded; i < locnpart; i++)
540 tabarrayIntersection[i].resize(tabnumberIntersection[i]);
541 mpiRequest[int] rqt(locnpart-(!pr#prfe#prmesh#excluded));
542 for (int i = !pr#prfe#prmesh#excluded; i < locnpart; i++)
543 Irecv(processor(rkr(i),pr#prfe#prmesh#mpicomm,rqt[i-!pr#prfe#prmesh#excluded]),tabarrayIntersection[i]);
544 for (int i = !pr#prfe#prmesh#excluded; i < locnpart; i++)
545 int k = mpiWaitAny(rqt);
546 }
547 else if (!pr#prfe#prmesh#excluded) {
548 mpiRequest rqt;
549 Isend(processor(rks(mpiRank(pr#prfe#prmesh#mpicomm)),pr#prfe#prmesh#mpicomm,rqt),fullarrayIntersection);
550 mpiWait(rqt);
551 }
552
553 int nbij = 0;
554 if (mpiRank(pr#prfe#prmesh#mpicomm) < pr#prfe#prmesh#pCS)
555 for (int i = !pr#prfe#prmesh#excluded; i < locnpart; i++)
556 nbij += tabnumberIntersection[i];
557
558 pr#prfe#K[int,int][int] tabEij(nbij); /* big vector of full matrices for the blocks Eij */
559 pr#prfe#K[int,int][int] tabEii(locnpart); /* big vector of full matrices for the blocks Eii */
560 pr#prfe#K[int,int][int] tabEig(locnpart); /* big vector of full matrices for the blocks Eig */
561
562 /* commCS procs resize tabEii and receive Eii blocks */
563 if (mpiRank(pr#prfe#prmesh#mpicomm) < pr#prfe#prmesh#pCS) {
564 for (int i = !pr#prfe#prmesh#excluded; i < locnpart; i++)
565 tabEii[i].resize(prT#sizelg[rkrdd(i)],pr#sizelg[rkrdd(i)]);
566 mpiRequest[int] rqt(locnpart-(!pr#prfe#prmesh#excluded));
567 for (int i = !pr#prfe#prmesh#excluded; i < locnpart; i++)
568 Irecv(processor(rkr(i),pr#prfe#prmesh#mpicomm,rqt[i-!pr#prfe#prmesh#excluded]),tabEii[i]);
569 for (int i = !pr#prfe#prmesh#excluded; i < locnpart; i++)
570 int k = mpiWaitAny(rqt);
571 }
572 else if (!pr#prfe#prmesh#excluded) {
573 mpiRequest rqt;
574 Isend(processor(rks(mpiRank(pr#prfe#prmesh#mpicomm)),pr#prfe#prmesh#mpicomm,rqt),Eii);
575 mpiWait(rqt);
576 }
577
578 /* commCS procs resize tabEij and receive Eij blocks */
579 if (mpiRank(pr#prfe#prmesh#mpicomm) < pr#prfe#prmesh#pCS) {
580 int cpt = 0;
581 for (int i = !pr#prfe#prmesh#excluded; i < locnpart; i++)
582 for (int j=0; j < tabnumberIntersection[i]; j++) {
583 tabEij[cpt].resize(prT#sizelg[rkrdd(i)],pr#sizelg[tabarrayIntersection[i][j]]);
584 cpt++;
585 }
586 mpiRequest[int] rqt(nbij);
587 cpt = 0;
588 for (int i = !pr#prfe#prmesh#excluded; i < locnpart; i++)
589 for (int j=0; j < tabnumberIntersection[i]; j++) {
590 Irecv(processor(rkr(i),pr#prfe#prmesh#mpicomm,rqt[cpt]),tabEij[cpt]);
591 cpt++;
592 }
593 for (int i=0; i < nbij; i++)
594 int k = mpiWaitAny(rqt);
595 }
596 else if (!pr#prfe#prmesh#excluded) {
597 mpiRequest[int] rqt(fullnumberIntersection);
598 for (int i=0; i < pr#prfegeneo#prmesh#numberIntersection; i++)
599 Isend(processor(rks(mpiRank(pr#prfe#prmesh#mpicomm)),pr#prfe#prmesh#mpicomm,rqt[i]),Eij[i]);
600 IFMACRO(pr#geneofullpattern)
601 for (int i=0; i < fullnumberIntersection-pr#prfegeneo#prmesh#numberIntersection; i++)
602 Isend(processor(rks(mpiRank(pr#prfe#prmesh#mpicomm)),pr#prfe#prmesh#mpicomm,rqt[pr#prfegeneo#prmesh#numberIntersection+i]),Ekj[tabarrayIntersectionflat[i]]);
603 ENDIFMACRO
604 for (int i=0; i < fullnumberIntersection; i++)
605 int k = mpiWaitAny(rqt);
606 }
607
608 /* commCS procs resize tabEig and receive Eig blocks */
609 if (mpiRank(pr#prfe#prmesh#mpicomm) < pr#prfe#prmesh#pCS) {
610 for (int i = !pr#prfe#prmesh#excluded; i < locnpart; i++)
611 tabEig[i].resize(prT#sizelg[rkrdd(i)],pr#sg);
612 mpiRequest[int] rqt(locnpart-(!pr#prfe#prmesh#excluded));
613 for (int i = !pr#prfe#prmesh#excluded; i < locnpart; i++)
614 Irecv(processor(rkr(i),pr#prfe#prmesh#mpicomm,rqt[i-!pr#prfe#prmesh#excluded]),tabEig[i]);
615 for (int i = !pr#prfe#prmesh#excluded; i < locnpart; i++)
616 int k = mpiWaitAny(rqt);
617 }
618 else if (!pr#prfe#prmesh#excluded) {
619 mpiRequest rqt;
620 Isend(processor(rks(mpiRank(pr#prfe#prmesh#mpicomm)),pr#prfe#prmesh#mpicomm,rqt),Eig);
621 mpiWait(rqt);
622 }
623
624 if (mpiRank(pr#prfe#prmesh#mpicomm) < pr#prfe#prmesh#pCS) { /* fill E with Eii and Eij */
625 int[int] offsetl(locnpart);
626 for (int i = 0; i < locnpart; i++)
627 offsetl[i] = (i == 0 ? 0 : offsetl[i-1] + pr#sizelg[rkrdd(i-1)]);
628
629 int[int] offsetc(locnpart);
630 for (int i = 0; i < locnpart; i++)
631 offsetl[i] = (i == 0 ? 0 : offsetl[i-1] + pr#sizelg[rkrdd(i-1)]);
632
633 pr#E.resize(offsetl[locnpart-1] + pr#sizelg[rkrdd(locnpart-1)] + (mpiRank(pr#prfe#prmesh#mpicomm)==0)*prT#sg, pr#ncoarsespace);
634 /* TODO prT#sg > 0 works only when pCS = 1 */
635 assert(!prT#sg || pr#prfe#prmesh#pCS == 1);
636
637 if (!pr#prfe#prmesh#excluded) {
638 int k = mpiRank(pr#prfe#prmesh#mpicomm);
639 /* block Epp */
640 int[int] renumi = (0:prT#sizelg[k]-1);
641 int[int] renumj = (pr#offseti[k]:pr#offseti[k]+prT#sizelg[k]-1);
642 pr#E += Eii(renumi^-1,renumj^-1);
643
644 /* blocks Epj */
645 for(int j=0;j<pr#prfegeneo#prmesh#numberIntersection;++j) {
646 int rj = pr#prfegeneo#prmesh#arrayIntersection[j];
647 int[int] renumi = (0:prT#sizelg[k]-1);
648 int[int] renumj = (pr#offseti[rj]:pr#offseti[rj]+prT#sizelg[rj]-1);
649 pr#E += Eij[j](renumi^-1,renumj^-1);
650 }
651
652 /* blocks Epg */
653 if (pr#sg > 0) {
654 renumi = (0:prT#sizelg[k]-1);
655 renumj = (pr#ncoarsespace-pr#sg:pr#ncoarsespace-1);
656 pr#E += Eig(renumi^-1,renumj^-1);
657 pr#prfe#K[int,int] Eigt = Eig';
658 pr#E += Eigt(renumj^-1,renumi^-1); /* TODO works only in the symmetric case */
659 }
660
661 IFMACRO(pr#geneofullpattern)
662 for(int j=0;j<fullnumberIntersection-pr#prfegeneo#prmesh#numberIntersection;++j) {
663 int rj = fullarrayIntersection[pr#prfegeneo#prmesh#numberIntersection+j];
664 int[int] renumi = (0:prT#sizelg[k]-1);
665 int[int] renumj = (pr#offseti[rj]:pr#offseti[rj]+prT#sizelg[rj]-1);
666 pr#E += Ekj[tabarrayIntersectionflat[j]](renumi^-1,renumj^-1);
667 }
668 ENDIFMACRO
669 }
670
671 int cpt = 0;
672 for (int i = !pr#prfe#prmesh#excluded; i < locnpart; i++) {
673 /* blocks Eii */
674 int[int] renumi = (offsetl[i]:offsetl[i]+prT#sizelg[rkrdd(i)]-1);
675 int[int] renumj = (pr#offseti[rkrdd(i)]:pr#offseti[rkrdd(i)]+prT#sizelg[rkrdd(i)]-1);
676 pr#E += tabEii[i](renumi^-1,renumj^-1);
677
678 /* blocks Eij */
679 for(int j=0;j<tabnumberIntersection[i];++j) {
680 int rj = tabarrayIntersection[i][j];
681 int[int] renumi = (offsetl[i]:offsetl[i]+prT#sizelg[rkrdd(i)]-1);
682 int[int] renumj = (pr#offseti[rj]:pr#offseti[rj]+prT#sizelg[rj]-1);
683 pr#E += tabEij[cpt](renumi^-1,renumj^-1);
684 cpt++;
685 }
686
687 /* blocks Eig */
688 if (pr#sg > 0) {
689 renumi = (offsetl[i]:offsetl[i]+prT#sizelg[rkrdd(i)]-1);
690 renumj = (pr#ncoarsespace-pr#sg:pr#ncoarsespace-1);
691 pr#E += tabEig[i](renumi^-1,renumj^-1);
692 pr#prfe#K[int,int] Eigt = tabEig[i]';
693 pr#E += Eigt(renumj^-1,renumi^-1); /* TODO works only in the symmetric case */
694 }
695 }
696
697 /* block Egg */
698 if (mpiRank(pr#prfe#prmesh#mpicomm) == 0 && pr#sg > 0) {
699 int[int] renumi = (pr#ncoarsespace-pr#sg:pr#ncoarsespace-1);
700 pr#E += Egg(renumi^-1,renumi^-1);
701 }
702
703 IFMACRO(pr#CSwithpetsc)
704 Mat pr#petsctmp(pr#E.n,communicator = pr#prfe#prmesh#commCS);
705 pr#petsctmp = pr#E;
706 pr#petscE = pr#petsctmp;
707 MatDestroy(pr#petsctmp);
708 pr#E.resize(1,1);
709 ENDIFMACRO
710 pr#E0.resize(1,1);
711 IFMACRO(!pr#CSwithpetsc)
712 int[int] Rl(offsetl[locnpart-1] + pr#sizelg[rkrdd(locnpart-1)] + (mpiRank(pr#prfe#prmesh#mpicomm) == 0)*pr#sg);
713 for (int i = 0; i < locnpart; i++)
714 for (int jj=0; jj< pr#sizelg[rkrdd(i)]; jj++)
715 Rl[offsetl[i]+jj] = pr#offseti[rkrdd(i)]+jj;
716 if (mpiRank(pr#prfe#prmesh#mpicomm) == 0)
717 for (int i = 0; i < pr#sg; i++)
718 Rl[offsetl[locnpart-1] + pr#sizelg[rkrdd(locnpart-1)] + i] = pr#ncoarsespace-pr#sg+i;
719 pr#E.resize(Rl.n, pr#ncoarsespace);
720 if (Rl.n > 0) {
721 int[int] Rlc = (0:Rl.n-1);
722 pr#prfe#K[int] Rlk(Rl.n);
723 Rlk = 1;
724 matrix<pr#prfe#K> mRl = [Rlc,Rl,Rlk];
725 mRl.resize(Rl.n, pr#ncoarsespace);
726 pr#E = mRl'*pr#E;
727 }
728 else
729 pr#E.resize(pr#ncoarsespace, pr#ncoarsespace);
730 ENDIFMACRO
731 }
732
733 IFMACRO(!pr#CSwithpetsc)
734 if (!pr#prfe#prmesh#binexactCS)
735 if (Stringification(prT) == Stringification(pr))
736 if (mpiRank(pr#prfe#prmesh#mpicomm) < pr#prfe#prmesh#pCS)
737 set(pr#E,solver="MUMPS",sym=vsym,commworld=pr#prfe#prmesh#commCS,master=-1,factorize=3);
738 ENDIFMACRO
739 }
740 else {
741
742 NewMacro localmacroinexact pr#prfe#prmesh#minexactgeneoCS EndMacro
743 IFMACRO (localmacroinexact,1)
744
745 ffddmsetupsuper(pr)
746
747 int[int][int] inisuperwithoverlap(pr#prfe#prmesh#listofsupers.n);
748 int[int]inisuperwithoverlapsize(pr#prfe#prmesh#listofsupers.n);
749 inisuperwithoverlapsize = 0;
750 for (int i=0; i<inisuperwithoverlap.n; i++)
751 inisuperwithoverlap[i].resize(1000);
752
753 mpiRequest[int] rq(2*(pr#prfe#prmesh#listofsupers.n-pr#prfe#prmesh#issuper)+2*pr#prfe#prmesh#issuper*(pr#prfe#prmesh#insuperwithoverlap.n-!pr#prfe#prmesh#excluded));
754 int cpt = 0;
755 if (pr#prfe#prmesh#issuper) {
756 for (int i=!pr#prfe#prmesh#excluded;i<pr#prfe#prmesh#insuperwithoverlap.n;i++) {
757 Isend(processor(pr#prfe#prmesh#insuperwithoverlap[i]+pr#prfe#prmesh#pCS*pr#prfe#prmesh#exclude,pr#prfe#prmesh#mpicomm,rq[cpt++]),pr#prfe#prmesh#insuperwithoverlap.n);
758 Isend(processor(pr#prfe#prmesh#insuperwithoverlap[i]+pr#prfe#prmesh#pCS*pr#prfe#prmesh#exclude,pr#prfe#prmesh#mpicomm,rq[cpt++]),pr#prfe#prmesh#insuperwithoverlap);
759 }
760 }
761 for (int is=0; is < pr#prfe#prmesh#listofsupers.n; is++) {
762 int isuper = pr#prfe#prmesh#listofsupers[is];
763 if (!pr#prfe#prmesh#issuper || pr#prfe#prmesh#mysuperrank != isuper) {
764 Irecv(processor(pr#prfe#prmesh#rankofsuper(isuper),pr#prfe#prmesh#mpicomm,rq[cpt++]),inisuperwithoverlapsize[is]);
765 Irecv(processor(pr#prfe#prmesh#rankofsuper(isuper),pr#prfe#prmesh#mpicomm,rq[cpt++]),inisuperwithoverlap[is]);
766 }
767 }
768 for (int i=0;i < cpt;i++)
769 int k = mpiWaitAny(rq);
770
771 for (int is=0;is < pr#prfe#prmesh#listofsupers.n; is++) {
772 int isuper = pr#prfe#prmesh#listofsupers[is];
773 if (pr#prfe#prmesh#issuper && pr#prfe#prmesh#mysuperrank == isuper) {
774 inisuperwithoverlap[is].resize(pr#prfe#prmesh#insuperwithoverlap.n);
775 inisuperwithoverlap[is] = pr#prfe#prmesh#insuperwithoverlap;
776 }
777 else
778 inisuperwithoverlap[is].resize(inisuperwithoverlapsize[is]);
779 }
780
781 int[int][int] indicesofneighbors(pr#prfe#prmesh#listofsupers.n);
782 for (int is=0; is < pr#prfe#prmesh#listofsupers.n; is++) {
783 int isuper = pr#prfe#prmesh#listofsupers[is];
784 indicesofneighbors[is].resize(pr#prfe#prmesh#arrayIntersection.n);
785 cpt = 0;
786 for (int i=0; i<pr#prfe#prmesh#arrayIntersection.n; i++)
787 for (int j=0; j<inisuperwithoverlap[is].n;j++)
788 if (pr#prfe#prmesh#arrayIntersection[i] == inisuperwithoverlap[is][j])
789 indicesofneighbors[is][cpt++] = i;
790 indicesofneighbors[is].resize(cpt);
791 }
792
793 int[int][int] neighbors(pr#prfe#prmesh#listofsupers.n);
794 for (int is=0; is < pr#prfe#prmesh#listofsupers.n; is++) {
795 neighbors[is].resize(indicesofneighbors[is].n);
796 for (int i=0;i<indicesofneighbors[is].n;i++)
797 neighbors[is][i] = pr#prfe#prmesh#arrayIntersection[indicesofneighbors[is][i]];
798 }
799
800 int[int] tabnumberIntersection(pr#prfe#prmesh#insuperwithoverlap.n); /* i: number of neighbours of processor i */
801 int[int][int] tabarrayIntersection(pr#prfe#prmesh#insuperwithoverlap.n);
802 if (pr#prfe#prmesh#issuper)
803 for (int i=!pr#prfe#prmesh#excluded; i<pr#prfe#prmesh#insuperwithoverlap.n; i++)
804 tabarrayIntersection[i].resize(1000);
805
806 mpiRequest[int] rqt(2*(pr#prfe#prmesh#listofsupers.n-pr#prfe#prmesh#issuper)+2*pr#prfe#prmesh#issuper*(pr#prfe#prmesh#insuperwithoverlap.n-!pr#prfe#prmesh#excluded));
807
808 cpt = 0;
809 for (int is=0; is < pr#prfe#prmesh#listofsupers.n; is++) {
810 int isuper = pr#prfe#prmesh#listofsupers[is];
811 if (!pr#prfe#prmesh#issuper || pr#prfe#prmesh#mysuperrank != isuper) {
812 Isend(processor(pr#prfe#prmesh#rankofsuper(isuper),pr#prfe#prmesh#mpicomm,rqt[cpt++]),neighbors[is].n);
813 Isend(processor(pr#prfe#prmesh#rankofsuper(isuper),pr#prfe#prmesh#mpicomm,rqt[cpt++]),neighbors[is]);
814 }
815 else {
816 for (int i = !pr#prfe#prmesh#excluded; i < inisuperwithoverlap[is].n; i++) {
817 Irecv(processor(inisuperwithoverlap[is][i]+pr#prfe#prmesh#pCS*pr#prfe#prmesh#exclude,pr#prfe#prmesh#mpicomm,rqt[cpt++]),tabnumberIntersection[i]);
818 Irecv(processor(inisuperwithoverlap[is][i]+pr#prfe#prmesh#pCS*pr#prfe#prmesh#exclude,pr#prfe#prmesh#mpicomm,rqt[cpt++]),tabarrayIntersection[i]);
819 }
820 }
821 }
822
823 for (int i=0;i < cpt;i++)
824 int k = mpiWaitAny(rqt);
825
826 if (pr#prfe#prmesh#issuper)
827 for (int i=!pr#prfe#prmesh#excluded; i<pr#prfe#prmesh#insuperwithoverlap.n; i++)
828 tabarrayIntersection[i].resize(tabnumberIntersection[i]);
829
830 int nbrqmpiexcl = 0;
831
832 for (int is=0; is < pr#prfe#prmesh#listofsupers.n; is++) {
833 if (!pr#prfe#prmesh#issuper || pr#prfe#prmesh#mysuperrank != pr#prfe#prmesh#listofsupers[is])
834 nbrqmpiexcl += indicesofneighbors[is].n;
835 }
836
837 int is = 0;
838 int nbij = 0;
839
840 if (pr#prfe#prmesh#issuper) {
841 for (int i=0; i< pr#prfe#prmesh#listofsupers.n; i++)
842 if (pr#prfe#prmesh#listofsupers[i] == pr#prfe#prmesh#mysuperrank)
843 is = i;
844
845 for (int i = !pr#prfe#prmesh#excluded; i < inisuperwithoverlap[is].n; i++)
846 nbij += tabnumberIntersection[i];
847 }
848
849 mpiRequest[int] rqs(pr#prfe#prmesh#listofsupers.n-pr#prfe#prmesh#issuper+nbrqmpiexcl+pr#prfe#prmesh#issuper*(inisuperwithoverlap[is].n-!pr#prfe#prmesh#excluded+nbij));
850 cpt = 0;
851 for (int is=0; is < pr#prfe#prmesh#listofsupers.n; is++) {
852 int isuper = pr#prfe#prmesh#listofsupers[is];
853 if (!pr#prfe#prmesh#issuper || pr#prfe#prmesh#mysuperrank != isuper)
854 Isend(processor(pr#prfe#prmesh#rankofsuper(isuper),pr#prfe#prmesh#mpicomm,rqs[cpt++]),Eii);
855 }
856
857 int cptmpi = 0;
858 for (int is=0; is < pr#prfe#prmesh#listofsupers.n; is++) {
859 int isuper = pr#prfe#prmesh#listofsupers[is];
860 for(int j=0;j<indicesofneighbors[is].n;++j) {
861 if (!pr#prfe#prmesh#issuper || pr#prfe#prmesh#mysuperrank != isuper) {
862 Isend(processor(pr#prfe#prmesh#rankofsuper(isuper),pr#prfe#prmesh#mpicomm,rqs[pr#prfe#prmesh#listofsupers.n-pr#prfe#prmesh#issuper+cptmpi++]),Eij[indicesofneighbors[is][j]]);
863 }
864 }
865 }
866
867 pr#prfe#K[int,int][int] tabEij(nbij); /* big vector of full matrices for the blocks Sij */
868 pr#prfe#K[int,int][int] tabEii(inisuperwithoverlap[is].n); /* big vector of full matrices for the blocks Sii */
869
870 if (pr#prfe#prmesh#issuper) {
871
872 int isuper = pr#prfe#prmesh#mysuperrank;
873
874 /* on proc 0 resize tabSii and receive Sii blocks */
875 for (int i = !pr#prfe#prmesh#excluded; i < inisuperwithoverlap[is].n; i++) {
876 tabEii[i].resize(pr#sizelg[inisuperwithoverlap[is][i]],pr#sizelg[inisuperwithoverlap[is][i]]);
877 Irecv(processor(inisuperwithoverlap[is][i]+pr#prfe#prmesh#pCS*pr#prfe#prmesh#exclude,pr#prfe#prmesh#mpicomm,rqs[pr#prfe#prmesh#listofsupers.n-pr#prfe#prmesh#issuper+nbrqmpiexcl+i-!pr#prfe#prmesh#excluded]),tabEii[i]);
878 }
879
880 /* on proc 0 resize tabSij and receive Sij blocks */
881 int cpt = 0;
882 for (int i = !pr#prfe#prmesh#excluded; i < inisuperwithoverlap[is].n; i++)
883 for (int j=0; j < tabnumberIntersection[i]; j++) {
884 tabEij[cpt].resize(pr#sizelg[inisuperwithoverlap[is][i]],pr#sizelg[tabarrayIntersection[i][j]]);
885 Irecv(processor(inisuperwithoverlap[is][i]+pr#prfe#prmesh#pCS*pr#prfe#prmesh#exclude,pr#prfe#prmesh#mpicomm,rqs[pr#prfe#prmesh#listofsupers.n-pr#prfe#prmesh#issuper+nbrqmpiexcl+inisuperwithoverlap[is].n-!pr#prfe#prmesh#excluded+cpt]),tabEij[cpt]);
886 cpt++;
887 }
888 }
889
890 for (int i=0; i<pr#prfe#prmesh#listofsupers.n-pr#prfe#prmesh#issuper+nbrqmpiexcl+pr#prfe#prmesh#issuper*(inisuperwithoverlap[is].n-!pr#prfe#prmesh#excluded+nbij); i++)
891 int k = mpiWaitAny(rqs);
892
893 if (pr#prfe#prmesh#issuper) {
894
895 int isuper = pr#prfe#prmesh#mysuperrank;
896
897 /* fill E0 with Eii and Eij */
898 pr#E0.resize(pr#prfe#superDk[mpiRank(pr#prfe#prmesh#commsuper)].n,pr#prfe#superDk[mpiRank(pr#prfe#prmesh#commsuper)].n);
899 pr#E0 = 0;
900
901 if (!pr#prfe#prmesh#excluded) {
902 /* block E00 */
903 for (int jj=0; jj< pr#sizelg[mpiRank(pr#prfe#prmesh#commddm)]; jj++)
904 pr#E0(pr#superlocalnuminv[pr#offseti[mpiRank(pr#prfe#prmesh#commddm)]]:pr#superlocalnuminv[pr#offseti[mpiRank(pr#prfe#prmesh#commddm)]]+pr#sizelg[mpiRank(pr#prfe#prmesh#commddm)]-1,
905 pr#superlocalnuminv[pr#offseti[mpiRank(pr#prfe#prmesh#commddm)]]+jj) = Eii(:,jj);
906 /* blocks E0j */
907 for(int j=0;j<indicesofneighbors[is].n;++j)
908 for (int jj=0; jj< pr#sizelg[pr#prfe#prmesh#arrayIntersection[indicesofneighbors[is][j]]]; jj++)
909 pr#E0(pr#superlocalnuminv[pr#offseti[mpiRank(pr#prfe#prmesh#commddm)]]:pr#superlocalnuminv[pr#offseti[mpiRank(pr#prfe#prmesh#commddm)]]+pr#sizelg[mpiRank(pr#prfe#prmesh#commddm)]-1,
910 pr#superlocalnuminv[pr#offseti[pr#prfe#prmesh#arrayIntersection[indicesofneighbors[is][j]]]]+jj) = Eij[j](:,jj);
911 }
912
913 cpt = 0;
914 for (int i = !pr#prfe#prmesh#excluded; i < inisuperwithoverlap[is].n; i++) {
915 /* blocks Eii */
916 for (int jj=0; jj< pr#sizelg[inisuperwithoverlap[is][i]]; jj++)
917 pr#E0(pr#superlocalnuminv[pr#offseti[inisuperwithoverlap[is][i]]]:pr#superlocalnuminv[pr#offseti[inisuperwithoverlap[is][i]]]+pr#sizelg[inisuperwithoverlap[is][i]]-1,
918 pr#superlocalnuminv[pr#offseti[inisuperwithoverlap[is][i]]]+jj) = tabEii[i](:,jj);
919 /* blocks Eij */
920 for(int j=0;j<tabnumberIntersection[i];++j) {
921 for (int jj=0; jj< pr#sizelg[tabarrayIntersection[i][j]]; jj++) {
922 pr#E0(pr#superlocalnuminv[pr#offseti[inisuperwithoverlap[is][i]]]:pr#superlocalnuminv[pr#offseti[inisuperwithoverlap[is][i]]]+pr#sizelg[inisuperwithoverlap[is][i]]-1,
923 pr#superlocalnuminv[pr#offseti[tabarrayIntersection[i][j]]]+jj) = tabEij[cpt](:,jj);
924 }
925 cpt++;
926 }
927 }
928
929 if (pr#prfe#prmesh#binexactgeneoCS == 1) {
930
931 pr#superaRd[mpiRank(pr#prfe#prmesh#commsuper)] = pr#E0;
932
933 /*
934 matrix E0s = E0;
935 pr#superaRd[mpiRank(pr#prfe#prmesh#commsuper)] = pr#RsuperCS*E0s;
936 pr#superaRd[mpiRank(pr#prfe#prmesh#commsuper)] = pr#superaRd[mpiRank(pr#prfe#prmesh#commsuper)]*pr#RsuperCS';
937 */
938
939 pr#superaR[mpiRank(pr#prfe#prmesh#commsuper)] = pr#superaRd[mpiRank(pr#prfe#prmesh#commsuper)];
940
941 set(pr#superaR[mpiRank(pr#prfe#prmesh#commsuper)],solver=sparsesolver,commworld=pr#prfe#prmesh#supercommself,factorize=3);
942 }
943 else {
944 pr#E = pr#E0;
945 pr#E0.resize(1,1);
946 pr#E = pr#prfe#superDih[mpiRank(pr#prfe#prmesh#commsuper)]*pr#E;
947 pr#E = pr#RsuperCS'*pr#E;
948 pr#E = pr#E*pr#RsuperCS;
949 set(pr#E,solver="MUMPS",sym=vsym,commworld=pr#prfe#prmesh#commsuper,master=-1,factorize=3);
950 }
951 }
952
953 ENDIFMACRO
954 ;
955 }
956 ENDIFMACRO /* end if (!pr#bem) */
957
958 }
959 pr#prfe#prmesh#toc(pr#tloc,"building E",pr#tbuildE)
960 }
961
962 // EOM
963
964 macro ffddmbuildgeneoZ(pr,Varf)
965
966 pr#bCM = 0;
967
968 if (pr#prfe#prmesh#isincomm)
969 {
970 int nev = ffddmnu;
971
972 IFMACRO(pr#withhpddm)
973 string prefix = Stringification(pr)+"_";
974 set(pr#hpddmOP,sparams="-hpddm_"+prefix+"geneo_threshold "+ffddmtau+" -hpddm_"+prefix+"geneo_nu "+nev, prefix=prefix);
975
976 pr#prfe#prmesh#tic(pr#tloc)
977
978 IFMACRO(!pr#algebraic)
979 {
980 Varf(vN,pr#prfe#prmesh#Thi,pr#prfe#Vhi)
981 pr#matN = vN(pr#prfe#Vhi,pr#prfe#Vhi,sym=vsym,tgv=vtgv,solver=GMRES);
982 }
983 ENDIFMACRO
984 AttachCoarseOperator(pr#prfe#prmesh#commddm, pr#hpddmOP, A = pr#matN);
985
986 pr#prfe#prmesh#toc(pr#tloc,"building E",pr#tbuildE)
987
988 ENDIFMACRO
989
990 IFMACRO(!pr#withhpddm)
991
992 if (!bpara)
993 pr#Z.resize(nev*pr#prfe#prmesh#npart);
994 else if (!pr#prfe#prmesh#excluded)
995 pr#Z.resize(nev);
996
997 pr#si=0;
998 pr#prfe#prmesh#tic(pr#tloc)
999
1000 int[int] sizel(pr#prfe#prmesh#npart);
1001
1002 for(int i=0;i<pr#prfe#prmesh#npart;++i)
1003 if ((!pr#prfe#prmesh#excluded) && ((!bpara) || (i == mpiRank(pr#prfe#prmesh#commddm)))) {
1004 pr#prfe#prmesh#Thi=pr#prfe#prmesh#aTh[i];
1005
1006 matrix<pr#prfe#K> weightedTmp;
1007
1008 weightedTmp=pr#aR[i]*pr#prfe#Dih[i];
1009
1010 matrix<pr#prfe#K> weighted;
1011
1012 weighted=pr#prfe#Dih[i]*weightedTmp;
1013
1014 /*
1015 pr#prfe#K[int] dofsinoverlap(pr#prfe#Dk[i].n);
1016 dofsinoverlap = 1;
1017 pr#prfe#update(dofsinoverlap,false);
1018 for [j,bj: dofsinoverlap] bj = abs(bj) > 1;
1019
1020 matrix<pr#prfe#K> Movl = dofsinoverlap;
1021
1022 weighted = weighted*Movl;
1023 weighted = Movl*weighted;
1024 */
1025
1026 IFMACRO(!pr#algebraic)
1027 {
1028 if (pr#prfe#prmesh#overlap > 0) {
1029 Varf(vN,pr#prfe#prmesh#Thi,pr#prfe#Vhi)
1030 pr#matN = vN(pr#prfe#Vhi,pr#prfe#Vhi,sym=vsym,tgv=vtgv,solver=GMRES);
1031 }
1032 }
1033 ENDIFMACRO
1034
1035 if (ffddminertia) {
1036 nev = ffddmnu;
1037 matrix<pr#prfe#K> NA = pr#matN-ffddmtau*weighted;
1038 int[int] info(40);
1039 set(NA,solver = sparsesolver,sym=1,commworld=pr#prfe#prmesh#commself,factorize=3,info=info);
1040 int ninertia = info[11];
1041 if (pr#verbosity >= 1 && ninertia > nev) cout << "["+Stringification(pr)+"] " << nev << " Warning: inertia = " << ninertia << ", maximum number of eigenvectors too low (" << nev << ", from -ffddm_geneo_nu) in subdomain " << i << endl;
1042 nev = min(nev,ninertia);
1043 if (pr#verbosity >= 10) cout << "["+Stringification(pr)+"] " << nev << " eigenvectors will be computed in subdomain " << i << endl;
1044 }
1045
1046 set(pr#matN,solver = sparsesolver,sym=1,commworld=pr#prfe#prmesh#commself);
1047
1048 pr#prfe#K[int,int] eV(pr#prfe#Dk[i].n,nev);
1049 pr#prfe#K[int] ev(nev);
1050
1051 int kk = EigenValue(pr#matN,weighted,sym=1,value=ev,rawvector=eV,ncv=max(20,3*nev));
1052
1053 IFMACRO(!pr#superalgebraic)
1054 pr#matN.clear;
1055 ENDIFMACRO
1056
1057 int nok = 0;
1058
1059 for(int j=0;j<nev;++j) {
1060 if (j == 0 || ffddmtau == 0 || real(ev[j]) < ffddmtau) {
1061 /*if (mpirank == 0) cout << i << " " << pr#si << " " << ev[j] << endl;*/
1062 pr#Z[pr#si].resize(pr#prfe#Dk[i].n);
1063 pr#Z[pr#si] = pr#prfe#Dk[i].*eV(:,j);
1064 if (pr#Z[pr#si].sum < 0) pr#Z[pr#si] *= -1;
1065 pr#si+=1;
1066 nok+=1;
1067 }
1068 }
1069
1070 sizel[i] = nok; /* number of ev for subdomain i */
1071 }
1072 pr#Z.resize(pr#si);
1073
1074 /* pr#sizelg stores the number of ev for every subdomain */
1075 if (!bpara)
1076 pr#sizelg = sizel;
1077 else {
1078 pr#sizelg = 0;
1079 mpiAllReduce(sizel,pr#sizelg,pr#prfe#prmesh#mpicomm,mpiSUM);
1080 }
1081
1082 if (bseq)
1083 pr#prfe#prmesh#Thi = pr#prfe#prmesh#Thglob;
1084
1085 pr#prfe#prmesh#toc(pr#tloc,"local eigenvalue problems",pr#teigenv)
1086
1087 ENDIFMACRO
1088 }
1089 // EOM
1090
1091 macro ffddmgeneosetup(pr,Varf)
1092 ffddmbuildgeneoZ(pr,Varf)
1093 ffddmbuildZTAZ(pr,pr,Varf)
1094 if (pr#prfe#prmesh#isincomm)
1095 pr#corr = ffddmcorrection;
1096 // EOM
1097
1098 macro ffddmdtnsetup(pr,Varf,Varfmass,VarfDirichlet,lambdamax)
1099
1100 pr#bCM = 0;
1101
1102 pr#regularizeE = 1e-12;
1103
1104 if (pr#prfe#prmesh#isincomm)
1105 {
1106 pr#corr = ffddmcorrection; /* Correction scheme used */
1107
1108 int nev = ffddmnu; /* Maximum number of eigenvectors per subdomain */
1109
1110 IFMACRO(pr#withhpddm)
1111 string prefix = Stringification(pr)+"_";
1112 set(pr#hpddmOP,sparams="-hpddm_"+prefix+"geneo_threshold "+ffddmtau+" -hpddm_"+prefix+"geneo_nu "+nev, prefix=prefix);
1113
1114 pr#prfe#prmesh#tic(pr#tloc)
1115
1116 IFMACRO(!pr#algebraic)
1117 {
1118 Varf(vN,pr#prfe#prmesh#Thi,pr#prfe#Vhi)
1119 pr#matN = vN(pr#prfe#Vhi,pr#prfe#Vhi,sym=vsym,tgv=vtgv,solver=GMRES);
1120 }
1121 ENDIFMACRO
1122
1123 varf vmass(def(u),def(v)) = pr#prfe#prmesh#intbN(pr#prfe#prmesh#Thi,ffddminterfacelabel)(pr#prfe#mdef(u)'*pr#prfe#mdef(v));
1124 matrix<pr#prfe#K> mmass = vmass(pr#prfe#Vhi,pr#prfe#Vhi);
1125
1126 AttachCoarseOperator(pr#prfe#prmesh#commddm, pr#hpddmOP, A = pr#matN, B = mmass, pattern = pr#aRd[mpiRank(pr#prfe#prmesh#commddm)]);
1127
1128 pr#prfe#prmesh#toc(pr#tloc,"building E",pr#tbuildE)
1129
1130 ENDIFMACRO
1131
1132 IFMACRO(!pr#withhpddm)
1133
1134 if (!bpara) /* If sequential */
1135 pr#Z.resize(nev*pr#prfe#prmesh#npart);
1136 else if (!pr#prfe#prmesh#excluded)
1137 pr#Z.resize(nev);
1138
1139 pr#si=0;
1140 pr#prfe#prmesh#tic(pr#tloc) /* For timings */
1141
1142 int[int] sizel(pr#prfe#prmesh#npart);
1143
1144 for(int i=0;i<pr#prfe#prmesh#npart;++i) /* Loop over the subdomains */
1145 if ((!pr#prfe#prmesh#excluded) && ((!bpara) || (i == mpiRank(pr#prfe#prmesh#commddm)))) { /* If subdomain assigned to this processor */
1146 pr#prfe#prmesh#Thi=pr#prfe#prmesh#aTh[i]; /* Local mesh */
1147
1148 /* Start DtN part */
1149 varf vv(pr#prfe#mdef(u), pr#prfe#mdef(v)) = on(ffddminterfacelabel, pr#prfe#mdef(u) = pr#prfe#minit(1)); /* Mark interface */
1150 real[int] b10 = vv(0,pr#prfe#Vhi,tgv=1);
1151
1152 IFMACRO(VarfDirichlet)
1153 VarfDirichlet(vDir,pr#prfe#prmesh#Thi,pr#prfe#Vhi) /* Mark Dirichlet dofs */
1154 real[int] bDir = vDir(0,pr#prfe#Vhi,tgv=1);
1155 b10 = bDir ? 0 : b10; /* Remove Dirichlet dofs from interface */
1156 ENDIFMACRO
1157
1158 int ndof10 = 0, ndofint = 0; /* Set up interface and interior DOFs */
1159 for (int j=0;j<b10.n;j++) {
1160 if (b10[j]) {
1161 ndof10++;
1162 b10[j] = ndof10; /* Enumerate interface DOFs */
1163 }
1164 else {
1165 ndofint++;
1166 b10[j] = -ndofint; /* Enumerate interior DOFs (using negative index) */
1167 }
1168 }
1169
1170 /* For restriction operators */
1171 int[int] Ii(ndof10),Ji(ndof10);
1172 pr#prfe#K[int] Ki(ndof10);
1173 int[int] Iiint(ndofint),Jiint(ndofint);
1174 pr#prfe#K[int] Kiint(ndofint);
1175 for (int j=0;j<b10.n;j++) {
1176 if (b10[j] > 0) {
1177 Ji[b10[j]-1] = j;
1178 Ii[b10[j]-1] = b10[j]-1;
1179 Ki[b10[j]-1] = 1;
1180 }
1181 else {
1182 Jiint[-b10[j]-1] = j;
1183 Iiint[-b10[j]-1] = -b10[j]-1;
1184 Kiint[-b10[j]-1] = 1;
1185 }
1186 }
1187
1188 /* Restriction operators */
1189 matrix<pr#prfe#K> R10 = [Ii,Ji,Ki];
1190 matrix<pr#prfe#K> Rint = [Iiint,Jiint,Kiint];
1191
1192 R10.resize(ndof10,pr#prfe#Vhi.ndof);
1193 Rint.resize(ndofint,pr#prfe#Vhi.ndof);
1194
1195 IFMACRO(!pr#algebraic)
1196 {
1197 if (pr#prfe#prmesh#overlap > 0) {
1198 Varf(vN,pr#prfe#prmesh#Thi,pr#prfe#Vhi)
1199 pr#matN = vN(pr#prfe#Vhi,pr#prfe#Vhi,sym=vsym,tgv=1e+30,solver=GMRES);
1200 }
1201 }
1202 ENDIFMACRO
1203
1204 /* Local stiffness matrices */
1205 matrix<pr#prfe#K> A10t = R10*pr#matN;
1206 matrix<pr#prfe#K> A10 = A10t*R10';
1207
1208 matrix<pr#prfe#K> Aintt = Rint*pr#matN;
1209 matrix<pr#prfe#K> Aint = Aintt*Rint';
1210 set(Aint,solver=sparsesolver,commworld=pr#prfe#prmesh#commself);
1211
1212 /* Transfer operators as part of the Schur complement */
1213 matrix<pr#prfe#K> Aint10t = Rint*pr#matN;
1214 matrix<pr#prfe#K> Aint10 = Aint10t*R10';
1215
1216 matrix<pr#prfe#K> A10intt = R10*pr#matN;
1217 matrix<pr#prfe#K> A10int = A10intt*Rint';
1218
1219 /* Interface mass matrix */
1220 Varfmass(vmass,pr#prfe#prmesh#Thi,pr#prfe#Vhi)
1221 matrix<pr#prfe#K> mmass = vmass(pr#prfe#Vhi,pr#prfe#Vhi,solver=GMRES);
1222 matrix<pr#prfe#K> mmass10t = R10*mmass;
1223 matrix<pr#prfe#K> mmass10 = mmass10t*R10';
1224 set(mmass10,solver=sparsesolver,commworld=pr#prfe#prmesh#commself);
1225
1226 /* Set up for interface eigenvectors and eigenvalues */
1227 pr#prfe#K[int,int] eVC(ndof10,nev);
1228 pr#prfe#K[int] ev(nev);
1229
1230 pr#prfe#K[int] tmp(pr#prfe#Vhi.ndof); /* For extension of eigenfunction */
1231
1232 pr#prfe#K[int] vinta(ndofint), vintb(ndofint);
1233 pr#prfe#K[int] v10a(ndof10), v10b(ndof10);
1234
1235 int cptA = 0, cptB = 0;
1236
1237 /* Left-hand side of the generalised eigenproblem */
1238 func pr#prfe#K[int] FA(pr#prfe#K[int] & u) {
1239 vinta = Aint10*u;
1240 vintb = Aint^-1*vinta;
1241 v10a = A10int*vintb;
1242 v10b = A10*u;
1243 v10b -= v10a;
1244 cptA++;
1245 return v10b;
1246 }
1247
1248 /* Right-hand side of the generalised eigenproblem */
1249 func pr#prfe#K[int] FB(pr#prfe#K[int] & u) {
1250 cptB++;
1251 v10a = mmass10*u;
1252 return v10a;
1253 }
1254
1255 /* Solve for right-hand side of generalised eigenproblem */
1256 func pr#prfe#K[int] FB1(pr#prfe#K[int] & u) {
1257 cptB++;
1258 v10a = mmass10^-1*u;
1259 return v10a;
1260 }
1261
1262 int ncv = max(2*nev+1,100);
1263
1264 int kk = complexEigenValue(ndof10,A=FA,B=FB,B1=FB1,value=ev,rawvector=eVC,which="SR",mode=2,ncv=ncv,tol=0.001);
1265
1266 int nok = 0;
1267
1268 for(int j=0;j<nev;++j)
1269 {
1270 if(j<kk && (real(ev[j]) < lambdamax)) /* Criterion 4.3 of Lea's paper */
1271 {
1272 if (mpiRank(pr#prfe#prmesh#commddm) == 0) cout << "Eigenvalue " << i << "," << nok << " " << ev[j] << endl;
1273 /* Retain eigenfuntion on interface */
1274 tmp = R10'*eVC(:,j);
1275 /* Extend eigenfunctions into the domain */
1276 pr#prfe#K[int] tmp2 = Aint10*eVC(:,j);
1277 pr#prfe#K[int] tmp3 = Aint^-1*tmp2;
1278 tmp3 *= -1;
1279 tmp += Rint'*tmp3;
1280 /* Now tmp is as in Definition 4.4 of Lea's paper.*/
1281
1282 pr#Z[pr#si].resize(pr#prfe#Dk[i].n);
1283 pr#Z[pr#si]= tmp .* pr#prfe#Dk[i];
1284
1285 pr#si+=1;
1286 nok+=1;
1287 }
1288 }
1289
1290 sizel[i] = nok; /* number of ev for subdomain i */
1291 }
1292 pr#Z.resize(pr#si);
1293
1294 /* pr#sizelg stores the number of ev for every subdomain */
1295 if (!bpara)
1296 pr#sizelg = sizel;
1297 else {
1298 pr#sizelg = 0;
1299 mpiAllReduce(sizel,pr#sizelg,pr#prfe#prmesh#mpicomm,mpiSUM);
1300 }
1301
1302 if (bseq)
1303 pr#prfe#prmesh#Thi = pr#prfe#prmesh#Thglob;
1304
1305 pr#prfe#prmesh#toc(pr#tloc,"local eigenvalue problems",pr#teigenv)
1306
1307 ffddmbuildZTAZ(pr,pr,Varf)
1308
1309 ENDIFMACRO
1310 }
1311 // EOM
1312
1313 macro ffddmharmonicgeneosetup(pr,Varf,VarfLap,VarfIP,lambdamax)
1314
1315 pr#bCM = 0;
1316
1317 pr#regularizeE = 1e-12;
1318
1319 if (pr#prfe#prmesh#isincomm)
1320 {
1321 int nev = ffddmnu;
1322
1323 IFMACRO(!pr#withhpddm)
1324
1325 if (!bpara)
1326 pr#Z.resize(nev*pr#prfe#prmesh#npart);
1327 else if (!pr#prfe#prmesh#excluded)
1328 pr#Z.resize(nev);
1329
1330 pr#si=0;
1331 pr#prfe#prmesh#tic(pr#tloc)
1332
1333 int[int] sizel(pr#prfe#prmesh#npart);
1334
1335 for(int i=0;i<pr#prfe#prmesh#npart;++i)
1336 if ((!pr#prfe#prmesh#excluded) && ((!bpara) || (i == mpiRank(pr#prfe#prmesh#commddm)))) {
1337 pr#prfe#prmesh#Thi=pr#prfe#prmesh#aTh[i];
1338
1339 int nbdofint = 0;
1340 matrix<pr#prfe#K> bA, bB;
1341
1342 {
1343 VarfIP(vIP,pr#prfe#prmesh#Thi,pr#prfe#Vhi)
1344 matrix<pr#prfe#K> pr#matIP = vIP(pr#prfe#Vhi,pr#prfe#Vhi,sym=0,tgv=-10,solver=GMRES);
1345
1346 VarfLap(vL,pr#prfe#prmesh#Thi,pr#prfe#Vhi)
1347 matrix<pr#prfe#K> pr#matLap = vL(pr#prfe#Vhi,pr#prfe#Vhi,sym=0,tgv=-1,solver=GMRES);
1348
1349 Varf(vH,pr#prfe#prmesh#Thi,pr#prfe#Vhi)
1350 matrix<pr#prfe#K> pr#matH = vH(pr#prfe#Vhi,pr#prfe#Vhi,sym=0,tgv=-1,solver=GMRES);
1351
1352 matrix<pr#prfe#K> weightedTmp = pr#matIP*pr#prfe#Dih[i];
1353 matrix<pr#prfe#K> weighted = pr#prfe#Dih[i]*weightedTmp;
1354
1355 varf vext(u,v) = on(ffddminterfacelabel,u=1);
1356
1357 pr#prfe#K[int] bext = vext(0,pr#prfe#Vhi,tgv=1);
1358
1359 int[int] II(bext.n), JJ(bext.n);
1360 pr#prfe#K[int] KK(bext.n);
1361
1362 for (int jj=0; jj<bext.n; jj++)
1363 if (!abs(bext[jj])) {
1364 II[nbdofint] = nbdofint; JJ[nbdofint] = jj;
1365 KK[nbdofint] = 1;
1366 nbdofint++;
1367 }
1368
1369 matrix<pr#prfe#K> Rint = [II,JJ,KK];
1370 Rint.resize(nbdofint,bext.n);
1371
1372 matrix<pr#prfe#K> mzeros(nbdofint,nbdofint);
1373
1374 matrix<pr#prfe#K> mBB = Rint*pr#matH;
1375
1376 bA = [[pr#matLap,mBB'],[mBB,mzeros]];
1377
1378 bB = [[weighted,0],[0,mzeros]];
1379 bB.resize(weighted.n+nbdofint,weighted.n+nbdofint);
1380 }
1381
1382 /* set(bA,solver = sparsesolver,sym=1,commworld=pr#prfe#prmesh#commself); */
1383
1384 pr#prfe#K[int] ev(nev);
1385 pr#prfe#K[int,int] eVV(pr#prfe#Dk[i].n + nbdofint,nev);
1386
1387 NewMacro localmacroK pr#prfe#K EndMacro
1388 IFMACRO(localmacroK,real)
1389 load "PETSc"
1390 ENDIFMACRO
1391 IFMACRO(localmacroK,complex)
1392 load "PETSc-complex"
1393 ENDIFMACRO
1394
1395 Mat<pr#prfe#K> SA(bA,communicator=mpiCommSelf);
1396
1397 Mat<pr#prfe#K> SB(bB,communicator=mpiCommSelf);
1398
1399 int k = EPSSolve(SA,SB, sparams =
1400 "-prefix_push harmonicgeneo_ "+
1401 "-eps_nev "+nev+" "+
1402 "-eps_type krylovschur "+
1403 "-eps_target_largest_magnitude "+
1404 "-eps_gen_non_hermitian "+
1405 /*"-eps_pos_gen_non_hermitian "+*/
1406 "-eps_target 0. "+
1407 "-eps_tol 1e-12 "+
1408 "-eps_conv_abs "+
1409 "-st_type sinvert "+
1410 "-st_pc_type lu "+
1411 "-st_pc_factor_mat_solver_type mumps "+
1412 "-st_mat_mumps_icntl_14 330 "+
1413 "-bv_orthog_type mgs " +
1414 "-bv_orthog_refine always " +
1415 (mpiRank(pr#prfe#prmesh#commddm) == 0 ?"-eps_error_absolute ::ascii_info_detail ":" ")+
1416 "-prefix_pop",
1417 values = ev, array = eVV, prefix="harmonicgeneo_");
1418
1419 /* int kk = EigenValue(bA,bB,value=ev,rawvector=eVV,ncv=max(20,3*nev),tol=1e-12); */
1420
1421 int nok = 0;
1422
1423 for(int j=0;j<nev;++j) {
1424 if (j == 0 || ffddmtau == 0 || (real(ev[j]) > 0 && real(ev[j]) < lambdamax)) {
1425 /* if (mpirank == 0) cout << i << " " << pr#si << " " << ev[j] << endl; */
1426 if (pr#verbosity >= 1 && abs(imag(ev[j])) > 1e-6) cout << "["+Stringification(pr)+"] Warning in ffddmharmonicgeneosetup: nonzero imaginary part " << imag(ev[j]) << " of eigenvalue " << j << endl;
1427 pr#Z[pr#si].resize(pr#prfe#Dk[i].n);
1428 pr#Z[pr#si] = pr#prfe#Dk[i].*eVV(0:pr#prfe#Dk[i].n-1,j);
1429 if (pr#Z[pr#si].sum < 0) pr#Z[pr#si] *= -1;
1430 pr#si+=1;
1431 nok+=1;
1432 }
1433 }
1434 sizel[i] = nok; /* number of ev for subdomain i */
1435 }
1436 pr#Z.resize(pr#si);
1437
1438 /* pr#sizelg stores the number of ev for every subdomain */
1439 if (!bpara)
1440 pr#sizelg = sizel;
1441 else {
1442 pr#sizelg = 0;
1443 mpiAllReduce(sizel,pr#sizelg,pr#prfe#prmesh#mpicomm,mpiSUM);
1444 }
1445
1446 if (bseq)
1447 pr#prfe#prmesh#Thi = pr#prfe#prmesh#Thglob;
1448
1449 pr#prfe#prmesh#toc(pr#tloc,"local eigenvalue problems",pr#teigenv)
1450
1451 ENDIFMACRO
1452 }
1453
1454 ffddmbuildZTAZ(pr,pr,Varf)
1455 if (pr#prfe#prmesh#isincomm)
1456 pr#corr = ffddmcorrection;
1457
1458 // EOM
1459
1460 macro ffddmextendedharmonicgeneosetup(pr,Varf,VarfC)
1461
1462 pr#bCM = 0;
1463
1464 pr#regularizeE = 1e-12;
1465
1466 if (pr#prfe#prmesh#isincomm)
1467 {
1468 int nev = ffddmnu;
1469
1470 IFMACRO(!pr#withhpddm)
1471
1472 if (!bpara)
1473 pr#Z.resize(nev*pr#prfe#prmesh#npart);
1474 else if (!pr#prfe#prmesh#excluded)
1475 pr#Z.resize(nev);
1476
1477 pr#si=0;
1478 pr#prfe#prmesh#tic(pr#tloc)
1479
1480 int[int] sizel(pr#prfe#prmesh#npart);
1481
1482 for(int i=0;i<pr#prfe#prmesh#npart;++i)
1483 if ((!pr#prfe#prmesh#excluded) && ((!bpara) || (i == mpiRank(pr#prfe#prmesh#commddm)))) {
1484 pr#prfe#prmesh#Thi=pr#prfe#prmesh#aTh[i];
1485 pr#prfe#prmesh#AugThi=pr#prfe#prmesh#AugaTh[i];
1486
1487 matrix pr#prfe#AugAuginterp;
1488 matrix<pr#prfe#K> ADirichlettilde, CDirichlettilde;
1489
1490 {
1491 pr#prfe#prmesh#meshN pr#prfe#prmesh#AugAugThi = pr#prfe#prmesh#AugThi + pr#prfe#prmesh#AugaThborder[i];
1492 fespace pr#prfe#AugAugVhi(pr#prfe#prmesh#AugAugThi, pr#prfe#fPk);
1493 int[int] n2o = (0:pr#prfe#prmesh#AugThi.nt-1);
1494 int[int] renum = restrict(pr#prfe#AugVhi, pr#prfe#AugAugVhi,n2o);
1495 int[int] Ic = (0:pr#prfe#AugVhi.ndof-1);
1496 real[int] Kc(pr#prfe#AugVhi.ndof);
1497 Kc = 1;
1498 pr#prfe#AugAuginterp = [Ic,renum,Kc];
1499 pr#prfe#AugAuginterp.resize(pr#prfe#AugVhi.ndof, pr#prfe#AugAugVhi.ndof);
1500
1501 Varf(vPb, pr#prfe#prmesh#AugAugThi, pr#prfe#AugAugVhi)
1502 ADirichlettilde = vPb(pr#prfe#AugAugVhi, pr#prfe#AugAugVhi,sym=vsym,tgv=-10,solver=GMRES);
1503 renumbering(ADirichlettilde, pr#prfe#AugAuginterp, eps=-1);
1504
1505 VarfC(vPbC, pr#prfe#prmesh#AugAugThi, pr#prfe#AugAugVhi)
1506 CDirichlettilde = vPbC(pr#prfe#AugAugVhi, pr#prfe#AugAugVhi,sym=vsym,tgv=-10,solver=GMRES);
1507 renumbering(CDirichlettilde, pr#prfe#AugAuginterp, eps=-1);
1508 }
1509
1510 pr#prfe#K[int] Dktilde = pr#prfe#Auginterp' * pr#prfe#Dk[i];
1511
1512 pr#prfe#K[int] vi(pr#prfe#Dk[i].n), wi(pr#prfe#Dk[i].n), via(Dktilde.n), wia(Dktilde.n), zia(Dktilde.n);
1513
1514 func pr#prfe#K[int] localsolver(pr#prfe#K[int] &ui) {
1515 vi = ui;
1516 if (pr#prec == "soras") { vi = pr#prfe#Dk[i].*ui; }
1517 wi = pr#aR[i]^-1 * vi;
1518 vi = wi;
1519 if (pr#prec != "asm") { vi = pr#prfe#Dk[i].*wi; }
1520 return vi;
1521 }
1522
1523 func pr#prfe#K[int] localsolveradjoint(pr#prfe#K[int] &ui) {
1524 vi = ui;
1525 if (pr#prec != "asm") { vi = pr#prfe#Dk[i].*ui; }
1526 wi = pr#aR[i]'^-1 * vi;
1527 vi = wi;
1528 if (pr#prec == "soras") { vi = pr#prfe#Dk[i].*wi; }
1529 return vi;
1530 }
1531
1532 func pr#prfe#K[int] Cweightedfunc(pr#prfe#K[int] &uia)
1533 {
1534 via = ADirichlettilde*uia;
1535 vi = pr#prfe#Auginterp*via;
1536 wi = localsolver(vi);
1537 via = pr#prfe#Auginterp'*wi;
1538 wia = Dktilde.*uia;
1539 wia -= via;
1540 zia = CDirichlettilde*wia;
1541 vi = pr#prfe#Auginterp*zia;
1542 wi = localsolveradjoint(vi);
1543 via = pr#prfe#Auginterp'*wi;
1544 wia = ADirichlettilde'*via;
1545 via = Dktilde.*zia;
1546 via -= wia;
1547 return via;
1548 };
1549
1550 NewMacro localmacroK pr#prfe#K EndMacro
1551 IFMACRO(localmacroK,real)
1552 load "PETSc"
1553 ENDIFMACRO
1554 IFMACRO(localmacroK,complex)
1555 load "PETSc-complex"
1556 ENDIFMACRO
1557
1558 Mat<pr#prfe#K> Cweightedopshell(pr#prfe#AugDk[i].n, communicator = mpiCommSelf);
1559 Mat<pr#prfe#K> Cweightedop(Cweightedopshell, Cweightedfunc);
1560
1561 {
1562 VarfC(vN,pr#prfe#prmesh#AugThi,pr#prfe#AugVhi)
1563 pr#matN = vN(pr#prfe#AugVhi,pr#prfe#AugVhi,sym=vsym,tgv=-1,solver=GMRES);
1564 }
1565
1566 Mat<pr#prfe#K> PetscCNeumanntilde(pr#matN, communicator = mpiCommSelf);
1567
1568 pr#prfe#K[int,int] eV(pr#prfe#AugDk[i].n,nev);
1569 pr#prfe#K[int] ev(nev);
1570
1571 int k = EPSSolve(PetscCNeumanntilde, Cweightedop, sparams =
1572 "-prefix_push extendedharmonicgeneo_ "+
1573 "-eps_nev "+nev+" "+
1574 "-eps_type krylovschur "+
1575 "-eps_target_largest_magnitude "+
1576 "-eps_gen_non_hermitian "+
1577 /*"-bv_definite_tol 1e-5 "+*/
1578 "-eps_target 0. "+
1579 "-eps_tol 1e-12 "+
1580 "-eps_conv_abs "+
1581 "-st_type sinvert "+
1582 "-st_pc_type lu "+
1583 "-st_pc_factor_mat_solver_type mumps "+
1584 "-bv_orthog_type mgs " +
1585 "-bv_orthog_refine always " +
1586 (mpiRank(pr#prfe#prmesh#commddm) == 0 ?"-eps_error_absolute ::ascii_info_detail ":" ")+
1587 "-prefix_pop",
1588 values = ev, array = eV, prefix="extendedharmonicgeneo_");
1589
1590 IFMACRO(!pr#superalgebraic)
1591 pr#matN.clear;
1592 ENDIFMACRO
1593
1594 int nok = 0;
1595
1596 for(int j=0;j<nev;++j) {
1597 if (j == 0 || ffddmtau == 0 || (real(ev[j]) > 0 && real(ev[j]) < ffddmtau)) {
1598 /*if (mpirank == 0) cout << i << " " << pr#si << " " << ev[j] << endl;*/
1599 assert(pr#prec != "asm"); /* otherwise eigenvector in tilde Omega */
1600 if (pr#verbosity >= 1 && abs(imag(ev[j])) > 1e-6) cout << "["+Stringification(pr)+"] Warning in ffddmextendedharmonicgeneosetup: nonzero imaginary part " << imag(ev[j]) << " of eigenvalue " << j << endl;
1601 pr#Z[pr#si].resize(pr#prfe#Dk[i].n);
1602 via = ADirichlettilde*eV(:,j);
1603 vi = pr#prfe#Auginterp*via;
1604 wi = localsolver(vi);
1605 via = pr#prfe#Auginterp'*wi;
1606 wia = Dktilde.*eV(:,j);
1607 wia -= via;
1608 pr#Z[pr#si] = pr#prfe#Auginterp*wia;
1609 if (pr#Z[pr#si].sum < 0) pr#Z[pr#si] *= -1;
1610 pr#si+=1;
1611 nok+=1;
1612 }
1613 }
1614
1615 sizel[i] = nok; /* number of ev for subdomain i */
1616 }
1617 pr#Z.resize(pr#si);
1618
1619 /* pr#sizelg stores the number of ev for every subdomain */
1620 if (!bpara)
1621 pr#sizelg = sizel;
1622 else {
1623 pr#sizelg = 0;
1624 mpiAllReduce(sizel,pr#sizelg,pr#prfe#prmesh#mpicomm,mpiSUM);
1625 }
1626
1627 if (bseq)
1628 pr#prfe#prmesh#Thi = pr#prfe#prmesh#Thglob;
1629
1630 pr#prfe#prmesh#toc(pr#tloc,"local eigenvalue problems",pr#teigenv)
1631
1632 ENDIFMACRO
1633 }
1634
1635 ffddmbuildZTAZ(pr,pr,Varf)
1636 if (pr#prfe#prmesh#isincomm)
1637 pr#corr = ffddmcorrection;
1638
1639 // EOM
1640
1641 macro ffddmgeneohelmholtzsetup(pr,Varf,VarfA)
1642
1643 pr#bCM = 0;
1644
1645 if (pr#prfe#prmesh#isincomm)
1646 {
1647
1648 int nev = ffddmnu;
1649
1650 IFMACRO(!pr#withhpddm)
1651
1652 if (!bpara)
1653 pr#Z.resize(nev*pr#prfe#prmesh#npart);
1654 else if (!pr#prfe#prmesh#excluded)
1655 pr#Z.resize(nev);
1656
1657 pr#si=0;
1658 pr#prfe#prmesh#tic(pr#tloc)
1659
1660 int[int] sizel(pr#prfe#prmesh#npart);
1661
1662 for(int i=0;i<pr#prfe#prmesh#npart;++i)
1663 if ((!pr#prfe#prmesh#excluded) && ((!bpara) || (i == mpiRank(pr#prfe#prmesh#commddm)))) {
1664 pr#prfe#prmesh#Thi=pr#prfe#prmesh#aTh[i];
1665
1666 VarfA(vA,pr#prfe#prmesh#Thi,pr#prfe#Vhi)
1667 matrix<pr#prfe#K> pr#aRprec = vA(pr#prfe#Vhi,pr#prfe#Vhi,sym=0,tgv=-10,solver=GMRES);
1668
1669 pr#prfe#K[int,int] eV(pr#prfe#Dk[i].n,nev);
1670 pr#prfe#K[int] ev(nev);
1671
1672 matrix<pr#prfe#K> weightedTmp;
1673 weightedTmp=pr#aRprec*pr#prfe#Dih[i];
1674 matrix<pr#prfe#K> weighted;
1675 weighted=pr#prfe#Dih[i]*weightedTmp; /* = D_i A_i D_i */
1676
1677 IFMACRO(!pr#algebraic)
1678 {
1679 Varf(vN,pr#prfe#prmesh#Thi,pr#prfe#Vhi)
1680 pr#matN = vN(pr#prfe#Vhi,pr#prfe#Vhi,sym=0,tgv=-1,solver=GMRES);
1681 }
1682 ENDIFMACRO
1683
1684 NewMacro localmacroK pr#prfe#K EndMacro
1685 IFMACRO(localmacroK,real)
1686 load "PETSc"
1687 ENDIFMACRO
1688 IFMACRO(localmacroK,complex)
1689 load "PETSc-complex"
1690 ENDIFMACRO
1691
1692 Mat<pr#prfe#K> SA(pr#matN,communicator=pr#prfe#prmesh#commself);
1693
1694 Mat<pr#prfe#K> SB(weighted,communicator=pr#prfe#prmesh#commself);
1695
1696 int kk = EPSSolve(SA, SB, sparams =
1697 "-prefix_push Hk_GenEO_ "+
1698 "-eps_nev "+nev+" "+
1699 "-eps_type krylovschur "+
1700 "-eps_target_real "+
1701 "-eps_gen_non_hermitian "+
1702 "-eps_target -10 "+
1703 "-eps_tol 1e-12 "+
1704 "-eps_conv_abs "+
1705 "-st_type sinvert "+
1706 "-st_pc_type lu "+
1707 "-st_pc_factor_mat_solver_type mumps "+
1708 "-bv_orthog_type mgs "+
1709 "-bv_orthog_refine always "+
1710 (mpiRank(pr#prfe#prmesh#commddm) == 0 ?"-eps_error_absolute ::ascii_info_detail ":" ")+
1711 "-prefix_pop",
1712 values = ev, array = eV, prefix = "Hk_GenEO_");
1713
1714 int nok = 0;
1715
1716 for(int j=0;j<nev;++j) {
1717 if (j == 0 || ffddmtau == 0 || (real(ev[j]) < ffddmtau)) {
1718 pr#Z[pr#si].resize(pr#prfe#Dk[i].n);
1719 pr#Z[pr#si] = pr#prfe#Dk[i].*eV(:,j);
1720 if (pr#Z[pr#si].sum < 0) pr#Z[pr#si] *= -1;
1721 pr#si+=1;
1722 nok+=1;
1723 }
1724 }
1725 sizel[i] = nok;
1726 }
1727 pr#Z.resize(pr#si);
1728
1729 /* pr#sizelg stores the number of ev for every subdomain */
1730 if (!bpara)
1731 pr#sizelg = sizel;
1732 else {
1733 pr#sizelg = 0;
1734 mpiAllReduce(sizel,pr#sizelg,pr#prfe#prmesh#mpicomm,mpiSUM);
1735 }
1736
1737 if (bseq)
1738 pr#prfe#prmesh#Thi = pr#prfe#prmesh#Thglob;
1739
1740 pr#prfe#prmesh#toc(pr#tloc,"local eigenvalue problems",pr#teigenv)
1741
1742 ENDIFMACRO
1743 }
1744
1745 ffddmbuildZTAZ(pr,pr,Varf)
1746 if (pr#prfe#prmesh#isincomm)
1747 pr#corr = ffddmcorrection;
1748
1749 // EOM
1750
1751 macro ffddmextendedharmonicgeneoBEMsetup(pr,Varf,VarfC)
1752 {
1753 pr#bCM = 0;
1754
1755 pr#regularizeE = 1e-12;
1756
1757 HMatrix<complex> pr#ADirichlettildebande;
1758
1759 if (pr#prfe#prmesh#isincomm)
1760 {
1761 int nev = ffddmnu;
1762
1763 IFMACRO(!pr#withhpddm)
1764
1765 if (!bpara)
1766 pr#Z.resize(nev*pr#prfe#prmesh#npart);
1767 else if (!pr#prfe#prmesh#excluded)
1768 pr#Z.resize(nev);
1769
1770 pr#si=0;
1771 pr#prfe#prmesh#tic(pr#tloc)
1772
1773 int[int] sizel(pr#prfe#prmesh#npart);
1774
1775 for(int i=0;i<pr#prfe#prmesh#npart;++i)
1776 if ((!pr#prfe#prmesh#excluded) && ((!bpara) || (i == mpiRank(pr#prfe#prmesh#commddm)))) {
1777 pr#prfe#prmesh#Thi=pr#prfe#prmesh#aTh[i];
1778 pr#prfe#prmesh#AugThi=pr#prfe#prmesh#AugaTh[i];
1779
1780 matrix<pr#prfe#K> CDirichlettilde;
1781
1782 {
1783 Varf(vaglobal,pr#prfe#prmesh#Thglob,pr#prfe#Vhglob)
1784 pr#ADirichlettildebande = vaglobal(pr#prfe#Vhglob,pr#prfe#AugVhi,commworld=mpiCommSelf);
1785 }
1786
1787 pr#prfe#K[int] vi(pr#prfe#Dk[i].n), wi(pr#prfe#Dk[i].n), zi(pr#prfe#Dk[i].n), viAug(pr#prfe#AugDk[i].n), wiAug(pr#prfe#AugDk[i].n), viG(pr#prfe#Vhglob.ndof), wiG(pr#prfe#Vhglob.ndof);
1788
1789 func pr#prfe#K[int] localsolver(pr#prfe#K[int] &ui) {
1790 viAug = pr#prfe#Auginterp'*ui;
1791 wiAug = pr#aR[i]^-1 * viAug;
1792 wi = pr#prfe#Auginterp*wiAug;
1793 if (pr#prec != "asm") {vi = pr#prfe#Dk[i].*wi;}
1794 else {vi = wi;}
1795 return vi;
1796 }
1797
1798 func pr#prfe#K[int] localsolveradjoint(pr#prfe#K[int] &ui) {
1799 if (pr#prec != "asm") {vi = pr#prfe#Dk[i].*ui;}
1800 else {vi = ui;}
1801 viAug = pr#prfe#Auginterp'*vi;
1802 viAug.im *= -1;
1803 wiAug = pr#aR[i]^-1 * viAug;
1804 wiAug.im *= -1;
1805 wi = pr#prfe#Auginterp*wiAug;
1806 return wi;
1807 }
1808
1809 func pr#prfe#K[int] Cweightedfunc(pr#prfe#K[int] &ui) {
1810 viAug = pr#ADirichlettildebande*ui;
1811 vi = pr#prfe#Auginterp*viAug;
1812
1813 zi = localsolver(vi);
1814 wi = pr#prfe#Rih[i]*ui;
1815 wi = wi .* pr#prfe#Dk[i];
1816 wi -= zi;
1817 IFMACRO(!pr#norm)
1818 zi = CDirichlettilde*wi;
1819 ENDIFMACRO
1820 IFMACRO(pr#norm,Hm1)
1821 zi = CDirichlettilde^-1*wi;
1822 ENDIFMACRO
1823
1824 wi = localsolveradjoint(zi);
1825
1826 wiAug = pr#prfe#Auginterp'*wi;
1827 wiG = pr#ADirichlettildebande'*wiAug;
1828
1829 vi = zi .* pr#prfe#Dk[i];
1830 viG = pr#prfe#Rih[i]'*vi;
1831 viG -= wiG;
1832 return viG;
1833 }
1834
1835 NewMacro localmacroK pr#prfe#K EndMacro
1836 IFMACRO(localmacroK,real)
1837 load "PETSc"
1838 ENDIFMACRO
1839 IFMACRO(localmacroK,complex)
1840 load "PETSc-complex"
1841 ENDIFMACRO
1842
1843 Mat<pr#prfe#K> Cweightedopshell(pr#prfe#Vhglob.ndof, communicator = mpiCommSelf);
1844 Mat<pr#prfe#K> Cweightedop(Cweightedopshell, Cweightedfunc);
1845
1846 matrix<pr#prfe#K> Mnorm;
1847 IFMACRO(!pr#norm)
1848 {
1849 VarfC(vPbC, pr#prfe#prmesh#Thglob, null)
1850 Mnorm = vPbC(pr#prfe#Vhglob, pr#prfe#Vhglob, solver=GMRES);
1851 }
1852 Mat<pr#prfe#K> PetscCNeumanntilde(Mnorm, communicator = mpiCommSelf);
1853 CDirichlettilde = pr#prfe#Rih[i]*Mnorm;
1854 CDirichlettilde = CDirichlettilde*pr#prfe#Rih[i]';
1855 ENDIFMACRO
1856 IFMACRO(pr#norm,Hm1)
1857 {
1858 VarfC(vPbC, pr#prfe#prmesh#Thglob, null)
1859 Mnorm = vPbC(pr#prfe#Vhglob, pr#prfe#Vhglob, solver=sparsesolver, commworld = mpiCommSelf);
1860 }
1861 {
1862 VarfC(vPbC, pr#prfe#prmesh#Thi, null)
1863 CDirichlettilde = vPbC(pr#prfe#Vhi, pr#prfe#Vhi, solver=sparsesolver, commworld = mpiCommSelf);
1864 }
1865
1866 func pr#prfe#K[int] NeumannOP(pr#prfe#K[int] u) {
1867 pr#prfe#K[int] res = Mnorm*u;
1868 return res;
1869 }
1870
1871 func pr#prfe#K[int] NeumannOP1(pr#prfe#K[int] u) {
1872 pr#prfe#K[int] res = Mnorm^-1*u;
1873 return res;
1874 }
1875
1876 Mat<pr#prfe#K> PetscCNeumanntildeshell(pr#prfe#Vhglob.ndof, communicator = mpiCommSelf);
1877 Mat<pr#prfe#K> PetscCNeumanntilde(PetscCNeumanntildeshell, NeumannOP1);
1878 set(PetscCNeumanntilde, precon=NeumannOP, sparams="-ksp_type preonly");
1879 ENDIFMACRO
1880
1881 pr#prfe#K[int,int] eV(pr#prfe#Vhi.ndof,nev);
1882 pr#prfe#K[int] ev(nev);
1883
1884 int k = EPSSolve(PetscCNeumanntilde, Cweightedop, sparams =
1885 "-prefix_push extendedharmonicgeneoBEM_ "+
1886 "-eps_nev "+nev+" "+
1887 "-eps_type krylovschur "+
1888 "-eps_target_largest_magnitude "+
1889 "-eps_gen_non_hermitian "+
1890 /*"-bv_definite_tol 1e-5 "+*/
1891 "-eps_target 0. "+
1892 "-eps_tol 1e-12 "+
1893 "-eps_conv_abs "+
1894 "-st_type sinvert "+
1895 IFMACRO(!pr#norm)
1896 "-st_pc_type lu "+
1897 "-st_pc_factor_mat_solver_type mumps "+
1898 ENDIFMACRO
1899 IFMACRO(pr#norm,Hm1)
1900 "-st_pc_type shell "+
1901 ENDIFMACRO
1902 "-bv_orthog_type mgs " +
1903 "-bv_orthog_refine always " +
1904 (mpiRank(pr#prfe#prmesh#commddm) == 0 ? "-eps_error_absolute ::ascii_info_detail ":" ")+
1905 "-prefix_pop",
1906 values = ev, array = eV, prefix="extendedharmonicgeneoBEM_");
1907
1908 int nok = 0;
1909
1910 for(int j=0;j<min(nev,ev.n);++j) {
1911 if (j == 0 || ffddmtau == 0 || (real(ev[j]) > 0 && real(ev[j]) < ffddmtau)) {
1912 /* if (mpirank == 0) cout << i << " " << pr#si << " " << ev[j] << endl; */
1913 assert(pr#prec != "asm"); /* otherwise eigenvector in tilde Omega */
1914 /* if (pr#verbosity >= 1 && abs(imag(ev[j])) > 1e-6) cout << "["+Stringification(pr)+"] Warning in ffddmextendedharmonicgeneoBEMsetup: nonzero imaginary part " << imag(ev[j]) << " of eigenvalue " << j << endl; */
1915 pr#Z[pr#si].resize(pr#prfe#Dk[i].n);
1916 viAug = pr#ADirichlettildebande*eV(:,j);
1917 vi = pr#prfe#Auginterp*viAug;
1918 wi = localsolver(vi);
1919 zi = pr#prfe#Rih[i]*eV(:,j);
1920 zi = zi .* pr#prfe#Dk[i];
1921 zi -= wi;
1922 pr#Z[pr#si] = zi;
1923 if (pr#Z[pr#si].sum < 0) pr#Z[pr#si] *= -1;
1924 pr#si+=1;
1925 nok+=1;
1926 }
1927 }
1928
1929 sizel[i] = nok; /* number of ev for subdomain i */
1930 }
1931 pr#Z.resize(pr#si);
1932
1933 /* pr#sizelg stores the number of ev for every subdomain */
1934 if (!bpara)
1935 pr#sizelg = sizel;
1936 else {
1937 pr#sizelg = 0;
1938 mpiAllReduce(sizel,pr#sizelg,pr#prfe#prmesh#mpicomm,mpiSUM);
1939 }
1940
1941 if (bseq)
1942 pr#prfe#prmesh#Thi = pr#prfe#prmesh#Thglob;
1943
1944 pr#prfe#prmesh#toc(pr#tloc,"local eigenvalue problems",pr#teigenv)
1945
1946 ENDIFMACRO
1947 }
1948
1949 ffddmbuildZTAZ(pr,pr,Varf)
1950 if (pr#prfe#prmesh#isincomm)
1951 pr#corr = ffddmcorrection;
1952 }
1953 // EOM