| 1 |
load "medit" |
| 2 |
load "MUMPS_mpi" |
| 3 |
|
| 4 |
include "getARGV.idp"// to process command line options |
| 5 |
|
| 6 |
include "ffddm_parameters.idp" |
| 7 |
|
| 8 |
include "ffddm_partitioning.idp" |
| 9 |
|
| 10 |
include "ffddm_coarsemeshCS.idp" |
| 11 |
|
| 12 |
include "ffddm_geneoCS.idp" |
| 13 |
|
| 14 |
include "ffddm_functions.idp" |
| 15 |
|
| 16 |
include "ffddm_geneoCS_3rdlvl.idp" |
| 17 |
|
| 18 |
include "ffddm_geneoCS_saddlepoint.idp" |
| 19 |
|
| 20 |
func string removespaces(string& str) { |
| 21 |
string res = ""; |
| 22 |
for (int i = 0; i < str.size; i++) |
| 23 |
if (str(i:i) != " " && str(i:i) != "\t" && str(i:i) != "\n") |
| 24 |
res = res + str(i:i); |
| 25 |
return res; |
| 26 |
} |
| 27 |
|
| 28 |
macro ffddmsetupPrecondinit(pr) |
| 29 |
IFMACRO(!pr#setupprecondinit) |
| 30 |
|
| 31 |
IFMACRO(pr#localmacroaug,1) |
| 32 |
matrix pr#CSinterp; |
| 33 |
ENDIFMACRO |
| 34 |
|
| 35 |
matrix<pr#prfe#K> pr#AglobEprec; |
| 36 |
pr#Tmatrix<pr#prfe#K>[int] pr#aR(pr#prfe#prmesh#npart); /* local (ras or Robin) matrices (for the preconditioner) */ |
| 37 |
matrix<pr#prfe#K> pr#aRdEprec; |
| 38 |
|
| 39 |
string pr#prec = "none"; |
| 40 |
|
| 41 |
int pr#bCM = 0; |
| 42 |
|
| 43 |
string pr#corr = "none"; |
| 44 |
|
| 45 |
pr#Tmatrix<pr#prfe#K> pr#E; |
| 46 |
pr#prfe#K[int,int] pr#E0(1,1); |
| 47 |
matrix<pr#prfe#K> pr#ZCM,pr#ZCMi,pr#ECM; |
| 48 |
real pr#regularizeE = 0; |
| 49 |
|
| 50 |
int pr#si, pr#sg=0; |
| 51 |
|
| 52 |
int[int] pr#sizelg(pr#prfe#prmesh#npart), pr#offseti(pr#prfe#prmesh#npart); |
| 53 |
|
| 54 |
int[int] pr#sizelgworld(mpiSize(pr#prfe#prmesh#mpicomm)), pr#offsetiworld(mpiSize(pr#prfe#prmesh#mpicomm)); |
| 55 |
|
| 56 |
int pr#ncoarsespace = 0; |
| 57 |
|
| 58 |
pr#prfe#K[int][int] pr#Z(0); |
| 59 |
|
| 60 |
int pr#nbiter = 0; |
| 61 |
real[int] pr#reshistory(0); |
| 62 |
|
| 63 |
pr#prfe#K[int][int] pr#RitzValues(0),pr#RitzHarmonicValues(0); |
| 64 |
|
| 65 |
ffddmgeneratePrecondfunctions(pr,pr#prfe) |
| 66 |
|
| 67 |
NewMacro pr#setupprecondinit()1 EndMacro |
| 68 |
ENDIFMACRO |
| 69 |
// EOM |
| 70 |
|
| 71 |
macro ffddmsetupOperatorinit(pr,preffe,preffe2) |
| 72 |
IFMACRO(!pr#setupoperatorinit) |
| 73 |
|
| 74 |
IFMACRO(pr#bem,1) |
| 75 |
NewMacro pr#Tmatrix() HMatrix EndMacro |
| 76 |
ENDIFMACRO |
| 77 |
IFMACRO(!pr#bem) |
| 78 |
NewMacro pr#Tmatrix() matrix EndMacro |
| 79 |
ENDIFMACRO |
| 80 |
|
| 81 |
NewMacro pr#localmacroaug preffe#prmesh#buildAug EndMacro |
| 82 |
|
| 83 |
NewMacro pr#prfe()preffe EndMacro |
| 84 |
NewMacro pr#prfe2()preffe2 EndMacro |
| 85 |
int pr#isrect = Stringification(preffe) != Stringification(preffe2); |
| 86 |
|
| 87 |
NewMacro pr#fromVhi(ui,VhName,res) |
| 88 |
if (preffe#prmesh#isincomm) |
| 89 |
{ |
| 90 |
string str = Stringification(VhName); |
| 91 |
string svhglob = Stringification(preffe#Vhglob); |
| 92 |
string svhi = Stringification(preffe#Vhi); |
| 93 |
string svhaug = Stringification(preffe#AugVhi); |
| 94 |
string svhcoarse = Stringification(pr#VhCoarse); |
| 95 |
str = removespaces(str); |
| 96 |
svhglob = removespaces(svhglob); |
| 97 |
svhi = removespaces(svhi); |
| 98 |
svhaug = removespaces(svhaug); |
| 99 |
svhcoarse = removespaces(svhcoarse); |
| 100 |
|
| 101 |
if (bseq) { |
| 102 |
assert(ui.n == preffe#Vhglob.ndof); |
| 103 |
if (str == svhglob) { |
| 104 |
res = ui; |
| 105 |
} |
| 106 |
else if (str == svhi) { |
| 107 |
res = ui; |
| 108 |
} |
| 109 |
else if (str == svhaug) { |
| 110 |
assert(0); |
| 111 |
IFMACRO(pr#localmacroaug,0) |
| 112 |
cout << "you need to use ffddmbuildaug" << endl; |
| 113 |
assert(0); |
| 114 |
ENDIFMACRO |
| 115 |
IFMACRO(pr#localmacroaug,1) |
| 116 |
res = preffe#Auginterp*ui; |
| 117 |
ENDIFMACRO |
| 118 |
} |
| 119 |
else if (str == svhcoarse) { |
| 120 |
IFMACRO(pr#localmacroaug,0) |
| 121 |
cout << "you need to use ffddmbuildaug" << endl; |
| 122 |
assert(0); |
| 123 |
ENDIFMACRO |
| 124 |
IFMACRO(pr#localmacroaug,1) |
| 125 |
res = pr#CSinterp*ui; |
| 126 |
ENDIFMACRO |
| 127 |
} |
| 128 |
else { |
| 129 |
cout << "***** TODO *****" << endl; |
| 130 |
assert(0); |
| 131 |
} |
| 132 |
} |
| 133 |
else { |
| 134 |
assert(ui.n == preffe#Vhi.ndof); |
| 135 |
if (str == svhi) { |
| 136 |
res = ui; |
| 137 |
} |
| 138 |
else if (str == svhaug) { |
| 139 |
IFMACRO(pr#localmacroaug,0) |
| 140 |
cout << "you need to use ffddmbuildaug" << endl; |
| 141 |
assert(0); |
| 142 |
ENDIFMACRO |
| 143 |
IFMACRO(pr#localmacroaug,1) |
| 144 |
preffe#K[int] tmp = ui .* preffe#Dk[mpiRank(preffe#prmesh#commddm)]; |
| 145 |
res = preffe#Auginterp'*tmp; |
| 146 |
preffe#Augupdate(res,false); |
| 147 |
ENDIFMACRO |
| 148 |
} |
| 149 |
else if (str == svhcoarse) { |
| 150 |
IFMACRO(pr#localmacroaug,0) |
| 151 |
cout << "you need to use ffddmbuildaug" << endl; |
| 152 |
assert(0); |
| 153 |
ENDIFMACRO |
| 154 |
IFMACRO(pr#localmacroaug,1) |
| 155 |
preffe#K[int] tmp(res.n); |
| 156 |
if (!preffe#prmesh#excluded) { |
| 157 |
preffe#K[int] ls = ui .* preffe#Dk[mpiRank(preffe#prmesh#commddm)]; |
| 158 |
tmp = pr#CSinterp*ls; |
| 159 |
} |
| 160 |
else |
| 161 |
tmp = 0; |
| 162 |
res = 0; |
| 163 |
mpiReduce(tmp,res,processor(0,preffe#prmesh#mpicomm),mpiSUM); |
| 164 |
if (mpiRank(preffe#prmesh#mpicomm) < preffe#prmesh#pCS) |
| 165 |
broadcast(processor(0,preffe#prmesh#commCS),res); |
| 166 |
ENDIFMACRO |
| 167 |
} |
| 168 |
else { |
| 169 |
preffe#K[int] inttmp(VhName.ndof); |
| 170 |
inttmp = 0; |
| 171 |
if (!preffe#prmesh#excluded) { |
| 172 |
IFMACRO(preffe#K,complex) |
| 173 |
matrix Mintr = interpolate(preffe#Vhi,VhName); |
| 174 |
matrix<complex> Mint = Mintr; |
| 175 |
ENDIFMACRO |
| 176 |
IFMACRO(preffe#K,real) |
| 177 |
matrix Mint = interpolate(preffe#Vhi,VhName); |
| 178 |
ENDIFMACRO |
| 179 |
preffe#K[int] inttmp2 = ui .* preffe#Dk[mpiRank(preffe#prmesh#commddm)]; |
| 180 |
inttmp = Mint'*inttmp2; |
| 181 |
} |
| 182 |
mpiAllReduce(inttmp,res,preffe#prmesh#mpicomm,mpiSUM); |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
EndMacro |
| 187 |
|
| 188 |
real pr#tdirect = 0, pr#teigenv = 0, pr#tbuildE = 0, pr#ttotal = 0; |
| 189 |
real pr#tgmresi, pr#tpreci, pr#tmvi, pr#tfactoi, pr#ttotali; |
| 190 |
real pr#tgmres = 0, pr#tprec = 0, pr#tmv = 0, pr#tfacto =0; |
| 191 |
real pr#tscalprod = 0; |
| 192 |
real pr#tloc = 0, pr#tglob = 0; |
| 193 |
real pr#tcsi, pr#tcs = 0; |
| 194 |
real pr#ttotalelapsed = mpiWtime(); |
| 195 |
|
| 196 |
NewMacro pr#writesummary |
| 197 |
if (preffe#prmesh#isincomm) |
| 198 |
{ |
| 199 |
real[int] timings = [preffe#prmesh#tdecomp,pr#tfacto,pr#tbuildE,pr#tgmres,pr#tmv,pr#tprec,pr#tcs,pr#teigenv,pr#tdirect]; |
| 200 |
real[int] timingsg(timings.n); |
| 201 |
timingsg = 0; |
| 202 |
mpiAllReduce(timings,timingsg,preffe#prmesh#mpicomm,mpiMAX); |
| 203 |
if (mpiRank(preffe#prmesh#mpicomm) == 0) { |
| 204 |
cout << "["+Stringification(pr)+"] timings - decomp and partition : " << timingsg[0] << endl; |
| 205 |
cout << "["+Stringification(pr)+"] timings - assembly and factorization local matrices : " << timingsg[1] << endl; |
| 206 |
cout << "["+Stringification(pr)+"] timings - assembly and factorization coarse problem : " << timingsg[2] << endl; |
| 207 |
cout << "["+Stringification(pr)+"] timings - GMRES : " << timingsg[3] << endl; |
| 208 |
cout << "["+Stringification(pr)+"] timings - MV : " << timingsg[4] << endl; |
| 209 |
cout << "["+Stringification(pr)+"] timings - PREC : " << timingsg[5] << endl; |
| 210 |
cout << "["+Stringification(pr)+"] timings - COARSE SOLVE : " << timingsg[6] << endl; |
| 211 |
/*cout << "timings - scalprod : " << timingsg[7] << endl;*/ |
| 212 |
cout << "["+Stringification(pr)+"] timings - total_sum : " << timingsg[3]+timingsg[0]+timingsg[1]+timingsg[2]+timingsg[7]+timingsg[8] << endl; |
| 213 |
cout << "["+Stringification(pr)+"] timings - total elapsed wall time : " << mpiWtime()-pr#ttotalelapsed << endl; |
| 214 |
} |
| 215 |
pr#tgmres = 0; pr#tmv = 0; pr#tprec = 0; pr#tcs = 0; pr#tscalprod = 0; |
| 216 |
} |
| 217 |
EndMacro |
| 218 |
|
| 219 |
int pr#verbosity = ffddmverbosity; |
| 220 |
|
| 221 |
int pr#bdirect = ffddmbdirect; |
| 222 |
|
| 223 |
pr#Tmatrix<preffe#K> pr#Aglobal; |
| 224 |
matrix<preffe#K>[int] pr#aRd(preffe#prmesh#npart); /* local Dirichlet matrices for parallel matrix vector product */ |
| 225 |
matrix<preffe#K> pr#matN; |
| 226 |
|
| 227 |
matrix<preffe#K> pr#matdirect; |
| 228 |
pr#matdirect.resize(1,1); |
| 229 |
|
| 230 |
IFMACRO((pr#withhpddm)|(pr#withpetsc)|(pr#withpetscksp)) |
| 231 |
if (!bpara){ |
| 232 |
if (mpiRank(preffe#prmesh#mpicomm) == 0) |
| 233 |
cout << "["+Stringification(pr)+"] Error: HPDDM/PETSc is to be used only in parallel mode" << endl; |
| 234 |
assert(bpara); |
| 235 |
} |
| 236 |
|
| 237 |
int[int][int] pr#intersectionhpddm(1 + preffe#prmesh#numberIntersection); |
| 238 |
{ |
| 239 |
pr#intersectionhpddm[0].resize(preffe#prmesh#arrayIntersection.n); |
| 240 |
pr#intersectionhpddm[0] = preffe#prmesh#arrayIntersection; |
| 241 |
preffe#K[int] CC; |
| 242 |
int[int] II; |
| 243 |
for (int j=0; j<preffe#prmesh#numberIntersection;j++) { |
| 244 |
[II, pr#intersectionhpddm[1 + j], CC] = preffe#restrictionIntersection[j]; |
| 245 |
if (CC[CC.n-1] == 0) |
| 246 |
pr#intersectionhpddm[1 + j].resize(CC.n-1); |
| 247 |
} |
| 248 |
} |
| 249 |
ENDIFMACRO |
| 250 |
|
| 251 |
IFMACRO(pr#withhpddm) |
| 252 |
load "hpddm" |
| 253 |
pr#aRd[mpiRank(preffe#prmesh#commddm)].resize(preffe#Dk[mpiRank(preffe#prmesh#commddm)].n, preffe#Dk[mpiRank(preffe#prmesh#commddm)].n); |
| 254 |
IFMACRO(preffe#K,real) |
| 255 |
schwarz<preffe#K> pr#hpddmOP(pr#aRd[mpiRank(preffe#prmesh#commddm)], pr#intersectionhpddm, preffe#Dk[mpiRank(preffe#prmesh#commddm)], scaled = false, communicator = preffe#prmesh#commddm); |
| 256 |
ENDIFMACRO |
| 257 |
IFMACRO(preffe#K,complex) |
| 258 |
real[int] pr#hpddmDk = preffe#Dk[mpiRank(preffe#prmesh#commddm)].re; |
| 259 |
schwarz<preffe#K> pr#hpddmOP(pr#aRd[mpiRank(preffe#prmesh#commddm)], pr#intersectionhpddm, pr#hpddmDk, scaled = false, communicator = preffe#prmesh#commddm); |
| 260 |
ENDIFMACRO |
| 261 |
set(pr#hpddmOP,sparams="-hpddm_"+Stringification(pr)+"_verbosity "+pr#verbosity+" -hpddm_"+Stringification(pr)+"_schwarz_method " +ffddmprecond, prefix=Stringification(pr)+"_"); |
| 262 |
if (preffe#prmesh#inexactCSsplit == 1) |
| 263 |
set(pr#hpddmOP,sparams="-hpddm_"+Stringification(pr)+"_reuse_preconditioner 1", prefix=Stringification(pr)+"_"); |
| 264 |
ENDIFMACRO |
| 265 |
|
| 266 |
IFMACRO((pr#withpetsc)|(pr#withpetscksp)|(pr#CSwithpetsc)) |
| 267 |
IFMACRO(preffe#K,real) |
| 268 |
load "PETSc" |
| 269 |
ENDIFMACRO |
| 270 |
IFMACRO(preffe#K,complex) |
| 271 |
load "PETSc-complex" |
| 272 |
ENDIFMACRO |
| 273 |
ENDIFMACRO |
| 274 |
|
| 275 |
IFMACRO((pr#withpetsc)|(pr#withpetscksp)) |
| 276 |
pr#aRd[mpiRank(preffe#prmesh#commddm)].resize(preffe#Dk[mpiRank(preffe#prmesh#commddm)].n, preffe#Dk[mpiRank(preffe#prmesh#commddm)].n); |
| 277 |
IFMACRO(preffe#K,real) |
| 278 |
real[int] pr#petscDk = preffe#Dk[mpiRank(preffe#prmesh#commddm)]; |
| 279 |
ENDIFMACRO |
| 280 |
IFMACRO(preffe#K,complex) |
| 281 |
real[int] pr#petscDk = preffe#Dk[mpiRank(preffe#prmesh#commddm)].re; |
| 282 |
ENDIFMACRO |
| 283 |
Mat<preffe#K> pr#petscOP(pr#aRd[mpiRank(preffe#prmesh#commddm)], pr#intersectionhpddm, pr#petscDk, communicator = preffe#prmesh#commddm); |
| 284 |
ENDIFMACRO |
| 285 |
|
| 286 |
IFMACRO(pr#withpetscksp) |
| 287 |
Mat<preffe#K> pr#petsckspOP(pr#petscOP); |
| 288 |
ENDIFMACRO |
| 289 |
|
| 290 |
IFMACRO(pr#CSwithpetsc) |
| 291 |
Mat<preffe#K> pr#petscE(0,communicator = preffe#prmesh#commCS); |
| 292 |
ENDIFMACRO |
| 293 |
|
| 294 |
NewMacro pr#localmacrominoverlap() preffe#prmesh#mminoverlap EndMacro |
| 295 |
|
| 296 |
IFMACRO(!pr#prfegeneo) |
| 297 |
IFMACRO(pr#localmacrominoverlap,0) |
| 298 |
NewMacro pr#prfegeneo() preffe EndMacro |
| 299 |
ENDIFMACRO |
| 300 |
|
| 301 |
IFMACRO(pr#localmacrominoverlap,1) |
| 302 |
NewMacro pr#prfegeneo() preffe#Aug EndMacro |
| 303 |
ENDIFMACRO |
| 304 |
ENDIFMACRO |
| 305 |
|
| 306 |
ffddmgenerateOperatorfunctions(pr,preffe) |
| 307 |
|
| 308 |
IFMACRO(pr#superwithchunk) |
| 309 |
ffddmsetupOperatorinit(pr#chunk,pr#chunk,pr#chunk) |
| 310 |
ENDIFMACRO |
| 311 |
|
| 312 |
ffddmsetupPrecondinit(pr) |
| 313 |
|
| 314 |
NewMacro pr#setupoperatorinit()1 EndMacro |
| 315 |
ENDIFMACRO |
| 316 |
// EOM |
| 317 |
|
| 318 |
|
| 319 |
macro ffddmsetupOperatorBeminit(pr,preffe) |
| 320 |
NewMacro pr#bem()1 EndMacro |
| 321 |
ffddmsetupOperatorinit(pr,preffe,preffe) |
| 322 |
// EOM |
| 323 |
|
| 324 |
macro ffddmsetupinit(pr,preffe) |
| 325 |
ffddmsetupOperatorinit(pr,preffe,preffe) |
| 326 |
// EOM |
| 327 |
|
| 328 |
macro ffddmsetupOperatorRect(pr,preffe,preffe2,Varf) |
| 329 |
|
| 330 |
ffddmsetupOperatorinit(pr,preffe,preffe2) |
| 331 |
|
| 332 |
if (preffe#prmesh#isincomm) |
| 333 |
{ |
| 334 |
preffe#prmesh#tic(pr#tfactoi) |
| 335 |
|
| 336 |
IFMACRO(pr#bem,1) |
| 337 |
if (!preffe#prmesh#excluded) { |
| 338 |
Varf(vaglobal,preffe#prmesh#Thglob,preffe#Vhglob) |
| 339 |
pr#Aglobal = vaglobal(preffe#Vhglob,preffe#Vhglob,commworld=pr#prfe#prmesh#commddm); |
| 340 |
} |
| 341 |
ENDIFMACRO |
| 342 |
|
| 343 |
IFMACRO(!pr#bem) |
| 344 |
if (pr#bdirect || bseq) { |
| 345 |
IFMACRO(pr#myOperator) |
| 346 |
pr#myOperator(pr#Aglobal, preffe#prmesh#Thglob, preffe#Vhglob) |
| 347 |
ENDIFMACRO |
| 348 |
IFMACRO(!pr#myOperator) |
| 349 |
Varf(vaglobal,preffe#prmesh#Thglob,preffe#Vhglob) |
| 350 |
pr#Aglobal = vaglobal(preffe#Vhglob,preffe2#Vhglob,sym=vsym*(!pr#isrect),tgv=vtgvelim); |
| 351 |
ENDIFMACRO |
| 352 |
} |
| 353 |
|
| 354 |
preffe#K[int] rhsFull(1), rhs(1); |
| 355 |
|
| 356 |
for(int i = 0;i<preffe#prmesh#npart;++i) |
| 357 |
if ((!preffe#prmesh#excluded) && ((!bpara) || (i == mpiRank(preffe#prmesh#commddm)))) { |
| 358 |
|
| 359 |
preffe#prmesh#Thi = preffe#prmesh#aTh[i]; |
| 360 |
|
| 361 |
NewMacro localmacroaug preffe#prmesh#buildAug EndMacro |
| 362 |
IFMACRO(localmacroaug,1) |
| 363 |
preffe#prmesh#AugThi = preffe#prmesh#AugaTh[i]; |
| 364 |
ENDIFMACRO |
| 365 |
IFMACRO(localmacroaug,0) |
| 366 |
preffe#prmesh#meshN preffe#prmesh#AugThi = preffe#prmesh#Thi + preffe#prmesh#aThborder[i]; /* local mesh augmented of one layer to define local Dirichlet matrices without the global matrix*/ |
| 367 |
fespace preffe#AugVhi(preffe#prmesh#AugThi, preffe#fPk); |
| 368 |
matrix preffe#Auginterp; |
| 369 |
if (preffe#prmesh#Thi.nt > 0) { |
| 370 |
int[int] n2o = (0:preffe#prmesh#Thi.nt-1); |
| 371 |
int[int] renum = restrict(preffe#Vhi, preffe#AugVhi,n2o); |
| 372 |
int[int] Ic = (0:preffe#Vhi.ndof-1); |
| 373 |
real[int] Kc(preffe#Vhi.ndof); |
| 374 |
Kc = 1; |
| 375 |
preffe#Auginterp = [Ic,renum,Kc]; |
| 376 |
} |
| 377 |
preffe#Auginterp.resize(preffe#Vhi.ndof, preffe#AugVhi.ndof); |
| 378 |
ENDIFMACRO |
| 379 |
|
| 380 |
if (bpara) |
| 381 |
{ |
| 382 |
if (preffe#prmesh#overlap > 0) { |
| 383 |
|
| 384 |
if (!pr#isrect) { |
| 385 |
IFMACRO(pr#myOperator) |
| 386 |
pr#myOperator(pr#aRd[i], preffe#prmesh#AugThi, preffe#AugVhi) |
| 387 |
ENDIFMACRO |
| 388 |
IFMACRO(!pr#myOperator) |
| 389 |
Varf(vPb, preffe#prmesh#AugThi, preffe#AugVhi) |
| 390 |
if (preffe#prmesh#inexactCSsplit > 1) |
| 391 |
pr#aRd[i] = vPb(preffe#AugVhi, preffe#AugVhi,sym=vsym,tgv=vtgvelim,solver=GMRES); |
| 392 |
else |
| 393 |
pr#aRd[i] = vPb(preffe#AugVhi, preffe#AugVhi,sym=vsym,tgv=vtgv,solver=GMRES); |
| 394 |
ENDIFMACRO |
| 395 |
renumbering(pr#aRd[i], preffe#Auginterp, eps=-1); |
| 396 |
} |
| 397 |
else { |
| 398 |
NewMacro localmacroaug2 preffe2#prmesh#buildAug EndMacro |
| 399 |
IFMACRO(localmacroaug2,1) |
| 400 |
preffe2#prmesh#AugThi = preffe2#prmesh#AugaTh[i]; |
| 401 |
ENDIFMACRO |
| 402 |
IFMACRO(localmacroaug2,0) |
| 403 |
preffe2#prmesh#meshN preffe2#prmesh#AugThi = preffe2#prmesh#Thi + preffe2#prmesh#aThborder[i]; |
| 404 |
ENDIFMACRO |
| 405 |
|
| 406 |
IFMACRO(!pr#myOperator) |
| 407 |
matrix<preffe#K> Auginterp2; |
| 408 |
fespace AugVhi2(preffe2#prmesh#AugThi, preffe2#fPk); |
| 409 |
if (preffe2#prmesh#Thi.nt > 0) { |
| 410 |
int[int] n2o = (0:preffe2#prmesh#Thi.nt-1); |
| 411 |
int[int] renum = restrict(preffe2#Vhi, AugVhi2,n2o); |
| 412 |
int[int] Ic = (0:preffe2#Vhi.ndof-1); |
| 413 |
preffe#K[int] Kc(preffe2#Vhi.ndof); |
| 414 |
Kc = 1; |
| 415 |
Auginterp2 = [Ic,renum,Kc]; |
| 416 |
} |
| 417 |
Auginterp2.resize(preffe2#Vhi.ndof, AugVhi2.ndof); |
| 418 |
matrix<preffe#K> Auginterp1 = preffe#Auginterp; |
| 419 |
|
| 420 |
Varf(vPb, preffe2#prmesh#AugThi, preffe2#AugVhi) |
| 421 |
pr#aRd[i] = vPb(preffe#AugVhi, AugVhi2,sym=0,tgv=vtgv,solver=GMRES); |
| 422 |
|
| 423 |
matrix<preffe#K> tmp = pr#aRd[i]*Auginterp1'; |
| 424 |
pr#aRd[i] = Auginterp2*tmp; |
| 425 |
ENDIFMACRO |
| 426 |
} |
| 427 |
|
| 428 |
IFMACRO(pr#withhpddm) |
| 429 |
ChangeOperator(pr#hpddmOP,pr#aRd[mpiRank(preffe#prmesh#commddm)]); |
| 430 |
ENDIFMACRO |
| 431 |
IFMACRO(pr#withpetsc) |
| 432 |
Mat<preffe#K> mat(pr#aRd[mpiRank(preffe#prmesh#commddm)], pr#intersectionhpddm, pr#petscDk, communicator = preffe#prmesh#commddm); |
| 433 |
pr#petscOP = mat; |
| 434 |
ENDIFMACRO |
| 435 |
} |
| 436 |
else { |
| 437 |
; |
| 438 |
IFMACRO(!pr#myOperator) |
| 439 |
Varf(vN,preffe#prmesh#Thi,preffe#Vhi) |
| 440 |
pr#matN = vN(preffe#Vhi,preffe2#Vhi,sym=vsym*(!pr#isrect),tgv=vtgv,solver=GMRES); |
| 441 |
ENDIFMACRO |
| 442 |
IFMACRO(pr#myOperator) |
| 443 |
pr#myOperator(pr#matN, preffe#prmesh#Thi, preffe#Vhi) |
| 444 |
ENDIFMACRO |
| 445 |
IFMACRO(pr#withhpddm) |
| 446 |
ChangeOperator(pr#hpddmOP,pr#matN); |
| 447 |
ENDIFMACRO |
| 448 |
IFMACRO(pr#withpetsc) |
| 449 |
Mat<preffe#K> mat(pr#matN, pr#intersectionhpddm, pr#petscDk, communicator = preffe#prmesh#commddm); |
| 450 |
pr#petscOP = mat; |
| 451 |
ENDIFMACRO |
| 452 |
} |
| 453 |
pr#matdirect.resize(1,1); |
| 454 |
} |
| 455 |
|
| 456 |
} |
| 457 |
if (bseq) |
| 458 |
preffe#prmesh#Thi = preffe#prmesh#Thglob; |
| 459 |
ENDIFMACRO |
| 460 |
|
| 461 |
preffe#prmesh#toc(pr#tfactoi,"",pr#tfacto) |
| 462 |
} |
| 463 |
//EOM |
| 464 |
|
| 465 |
macro ffddmsetupOperator(pr,preffe,Varf) |
| 466 |
ffddmsetupOperatorRect(pr,preffe,preffe,Varf) |
| 467 |
//EOM |
| 468 |
|
| 469 |
macro ffddmsetupOperatorBem(pr,preffe,Varf) |
| 470 |
ffddmsetupOperatorBeminit(pr,preffe) |
| 471 |
ffddmsetupOperator(pr,preffe,Varf) |
| 472 |
//EOM |
| 473 |
|
| 474 |
macro ffddmsetupPrecond(pr,VarfPrec) |
| 475 |
|
| 476 |
pr#prec = ffddmprecond; |
| 477 |
|
| 478 |
if (pr#prfe#prmesh#isincomm) |
| 479 |
{ |
| 480 |
pr#prfe#prmesh#tic(pr#tfactoi) |
| 481 |
|
| 482 |
pr#prfe#K[int] rhsFull(1), rhs(1); |
| 483 |
|
| 484 |
for(int i = 0;i<pr#prfe#prmesh#npart;++i) |
| 485 |
if ((!pr#prfe#prmesh#excluded) && ((!bpara) || (i == mpiRank(pr#prfe#prmesh#commddm)))) { |
| 486 |
|
| 487 |
if (pr#verbosity > 1 && !bpara) cout << "["+Stringification(pr)+"] Domain :" << i << "/" << pr#prfe#prmesh#npart << endl; |
| 488 |
|
| 489 |
IFMACRO((!VarfPrec)&(!pr#myPrecond)) |
| 490 |
if (bseq) cout << "Error in ffddmsetupPrecond: you need to provide the varf macro for the preconditioner in sequential mode" << endl; |
| 491 |
assert(!bseq); |
| 492 |
pr#aR[i] = pr#aRd[i]; |
| 493 |
ENDIFMACRO |
| 494 |
IFMACRO((VarfPrec)|(pr#myPrecond)) |
| 495 |
pr#prfe#prmesh#Thi = pr#prfe#prmesh#aTh[i]; |
| 496 |
|
| 497 |
if (pr#prfe#prmesh#Thi.nt > 0) { |
| 498 |
if (pr#prec == "oras" || pr#prec == "soras"){ |
| 499 |
IFMACRO(pr#myPrecond) |
| 500 |
pr#myPrecond(pr#aR[i], pr#prfe#prmesh#Thi, pr#prfe#Vhi) |
| 501 |
ENDIFMACRO |
| 502 |
IFMACRO(!pr#myPrecond) |
| 503 |
VarfPrec(RobinInt,pr#prfe#prmesh#Thi,pr#prfe#Vhi) |
| 504 |
if (pr#prfe#prmesh#inexactCSsplit > 1) |
| 505 |
pr#aR[i] = RobinInt(pr#prfe#Vhi,pr#prfe#Vhi,sym=vsym,tgv=vtgvelim,solver=GMRES,commworld=pr#prfe#prmesh#commself); |
| 506 |
else |
| 507 |
pr#aR[i] = RobinInt(pr#prfe#Vhi,pr#prfe#Vhi,sym=vsym,tgv=vtgv,solver=GMRES,commworld=pr#prfe#prmesh#commself); |
| 508 |
ENDIFMACRO |
| 509 |
} |
| 510 |
else if (pr#prec == "ras" || pr#prec == "asm") { |
| 511 |
NewMacro localmacroaug pr#prfe#prmesh#buildAug EndMacro |
| 512 |
IFMACRO(localmacroaug,1) |
| 513 |
pr#prfe#prmesh#AugThi = pr#prfe#prmesh#AugaTh[i]; |
| 514 |
ENDIFMACRO |
| 515 |
IFMACRO(localmacroaug,0) |
| 516 |
pr#prfe#prmesh#meshN pr#prfe#prmesh#AugThi = pr#prfe#prmesh#Thi + pr#prfe#prmesh#aThborder[i]; /* local mesh augmented of one layer to define local Dirichlet matrices without the global matrix*/ |
| 517 |
fespace pr#prfe#AugVhi(pr#prfe#prmesh#AugThi, pr#prfe#fPk); |
| 518 |
int[int] n2o = (0:pr#prfe#prmesh#Thi.nt-1); |
| 519 |
int[int] renum = restrict(pr#prfe#Vhi, pr#prfe#AugVhi,n2o); |
| 520 |
int[int] Ic = (0:pr#prfe#Vhi.ndof-1); |
| 521 |
real[int] Kc(pr#prfe#Vhi.ndof); |
| 522 |
Kc = 1; |
| 523 |
IFMACRO(!pr#bem) |
| 524 |
matrix pr#prfe#Auginterp; /* need to keep Auginterp in bem case, otherwise define it only in scope */ |
| 525 |
ENDIFMACRO |
| 526 |
pr#prfe#Auginterp = [Ic,renum,Kc]; |
| 527 |
pr#prfe#Auginterp.resize(pr#prfe#Vhi.ndof, pr#prfe#AugVhi.ndof); |
| 528 |
ENDIFMACRO |
| 529 |
|
| 530 |
IFMACRO(pr#myPrecond) |
| 531 |
pr#myPrecond(pr#aR[i], pr#prfe#prmesh#AugThi, pr#prfe#AugVhi) |
| 532 |
ENDIFMACRO |
| 533 |
IFMACRO(!pr#myPrecond) |
| 534 |
VarfPrec(vPb, pr#prfe#prmesh#AugThi, pr#prfe#AugVhi) |
| 535 |
if (pr#prfe#prmesh#inexactCSsplit > 1) |
| 536 |
pr#aR[i] = vPb(pr#prfe#AugVhi, pr#prfe#AugVhi,sym=vsym,tgv=vtgvelim,solver=GMRES,commworld=pr#prfe#prmesh#commself); |
| 537 |
else |
| 538 |
pr#aR[i] = vPb(pr#prfe#AugVhi, pr#prfe#AugVhi,sym=vsym,tgv=vtgv,solver=GMRES,commworld=pr#prfe#prmesh#commself); |
| 539 |
ENDIFMACRO |
| 540 |
IFMACRO(!pr#bem) |
| 541 |
renumbering(pr#aR[i], pr#prfe#Auginterp, eps=-1); |
| 542 |
ENDIFMACRO |
| 543 |
} |
| 544 |
else if (pr#prec != "none") |
| 545 |
assert(0); |
| 546 |
} |
| 547 |
ENDIFMACRO |
| 548 |
IFMACRO((!pr#withhpddm)&(!pr#withpetsc)) |
| 549 |
IFMACRO(!pr#bem) |
| 550 |
set(pr#aR[i],solver = sparsesolver,sym=vsym,commworld=pr#prfe#prmesh#commself,factorize=3); |
| 551 |
ENDIFMACRO |
| 552 |
IFMACRO(pr#bem,1) |
| 553 |
set(pr#aR[i],solver = "HLU",factorize=3); |
| 554 |
ENDIFMACRO |
| 555 |
ENDIFMACRO |
| 556 |
} |
| 557 |
if (bseq) |
| 558 |
pr#prfe#prmesh#Thi = pr#prfe#prmesh#Thglob; |
| 559 |
|
| 560 |
pr#prfe#prmesh#toc(pr#tfactoi,"",pr#tfacto) |
| 561 |
} |
| 562 |
//EOM |
| 563 |
|
| 564 |
macro ffddmsetupPrecondchunk(pr,VarfPrec) |
| 565 |
if (ffddmprecond != "oras") { |
| 566 |
cout << "Error in ffddmsetupPrecondchunk: only works with oras for now" << endl; |
| 567 |
assert(0); |
| 568 |
} |
| 569 |
pr#prec = ffddmprecond; |
| 570 |
ffddmsetupOperator(pr#chunk,pr#chunk,VarfPrec) |
| 571 |
//EOM |
| 572 |
|
| 573 |
macro ffddmsetup(pr,preffe,Varf,VarfPrec) |
| 574 |
ffddmsetupOperator(pr,preffe,Varf) |
| 575 |
ffddmsetupPrecond(pr,VarfPrec) |
| 576 |
// EOM |
| 577 |
|
| 578 |
macro ffddmbuildrhs(pr,Varfrhs,rhs) |
| 579 |
if (pr#prfe#prmesh#isincomm) |
| 580 |
{ |
| 581 |
if (pr#bdirect || bseq) |
| 582 |
{ |
| 583 |
{ |
| 584 |
Varfrhs(vaglobalrhs,pr#prfe#prmesh#Thglob,pr#prfe#Vhglob) |
| 585 |
rhs.resize(pr#prfe#Vhglob.ndof); |
| 586 |
rhs = vaglobalrhs(0,pr#prfe#Vhglob,tgv=vtgvelim); |
| 587 |
} |
| 588 |
} |
| 589 |
|
| 590 |
if (bpara && !pr#prfe#prmesh#excluded) |
| 591 |
{ |
| 592 |
|
| 593 |
pr#prfe#prmesh#Thi = pr#prfe#prmesh#aTh[mpiRank(pr#prfe#prmesh#commddm)]; |
| 594 |
|
| 595 |
rhs.resize(pr#prfe#Vhi.ndof); |
| 596 |
|
| 597 |
Varfrhs(vPbrhs, pr#prfe#prmesh#Thi, pr#prfe#Vhi) |
| 598 |
rhs = vPbrhs(0,pr#prfe#Vhi,tgv=vtgvelim); |
| 599 |
|
| 600 |
pr#prfe#update(rhs, pr#prfe#prmesh#overlap > 0); |
| 601 |
} |
| 602 |
} |
| 603 |
// EOM |
| 604 |
|
| 605 |
macro ffddmset(pr,param,value) |
| 606 |
pr#param = value; |
| 607 |
// EOM |
| 608 |
|
| 609 |
macro ffddmplot(pr,sol,msg) |
| 610 |
pr#mplot(sol,msg) |
| 611 |
// EOM |