| 1 |
IFMACRO(!macroDDMidp) |
| 2 |
macro macroDDMidp()1// EOM |
| 3 |
include "getARGV.idp" |
| 4 |
IFMACRO(!partitioner) |
| 5 |
macro partitioner()metis// EOM |
| 6 |
ENDIFMACRO |
| 7 |
IFMACRO(partitioner,metis) |
| 8 |
load "metis" |
| 9 |
macro partitionerSeq(part, Th, size){ if(size <= 1) part = 0; else metisdual(part, Th, size); }// EOM |
| 10 |
macro partitionerPar(part, Th, comm, size)broadcast(processor(0, comm), part)// EOM |
| 11 |
ENDIFMACRO |
| 12 |
IFMACRO(partitioner,scotch) |
| 13 |
load "scotch" |
| 14 |
macro partitionerSeq(part, Th, size){ if(size <= 1) part = 0; else scotch(part, Th, size); }// EOM |
| 15 |
macro partitionerPar(part, Th, comm, size)broadcast(processor(0, comm), part)// EOM |
| 16 |
ENDIFMACRO |
| 17 |
IFMACRO(partitioner,parmetis) |
| 18 |
load "parmetis" |
| 19 |
macro partitionerSeq(part, Th, size)// EOM |
| 20 |
macro partitionerPar(part, Th, comm, size)parmetis(part, Th, size, communicator = comm, worker = getARGV("-parmetis_worker", 1))// EOM |
| 21 |
ENDIFMACRO |
| 22 |
IFMACRO(!partitionerSeq) |
| 23 |
cout << "The macro 'partitioner' must be set to 'metis', 'scotch', or 'parmetis'" << endl; |
| 24 |
exit(1); |
| 25 |
ENDIFMACRO |
| 26 |
IFMACRO(dimension,2) |
| 27 |
macro meshN()mesh// EOM // two-dimensional problem |
| 28 |
macro intN()int2d// EOM // two-dimensional integral |
| 29 |
macro intN1()int1d// EOM // one-dimensional integral |
| 30 |
macro readmeshN()readmesh// EOM // two-dimensional problem |
| 31 |
macro defVel(uP)[uP, uP#Y]// EOM // two-dimensional velocity for convect/advect |
| 32 |
ENDIFMACRO |
| 33 |
IFMACRO((dimension,3S)|(dimension,3L)) |
| 34 |
if(mpirank == 0) cout << "Deprecated \"dimension\" value, switch to: \n NewMacro dimension()3 EndMacro\n NewMacro meshtype()S EndMacro (for meshS, or L for meshL)" << endl; |
| 35 |
ENDIFMACRO |
| 36 |
IFMACRO((dimension,3)|(dimension,3S)|(dimension,3L)) |
| 37 |
IFMACRO(dimension,3S) |
| 38 |
NewMacro meshtype()S EndMacro /* TODO FIXME: remove at some point (deprecated since July 2025) */ |
| 39 |
ENDIFMACRO |
| 40 |
IFMACRO(dimension,3L) |
| 41 |
NewMacro meshtype()L EndMacro /* TODO FIXME: remove at some point (deprecated since July 2025) */ |
| 42 |
ENDIFMACRO |
| 43 |
IFMACRO(!meshtype) |
| 44 |
NewMacro meshtype()V EndMacro |
| 45 |
ENDIFMACRO |
| 46 |
IFMACRO(meshtype,V) |
| 47 |
macro meshN()mesh3// EOM // three-dimensional problem |
| 48 |
macro intN()int3d// EOM // three-dimensional integral |
| 49 |
macro intN1()int2d// EOM // two-dimensional integral |
| 50 |
macro readmeshN()readmesh3// EOM // three-dimensional problem |
| 51 |
macro defVel(uP)[uP, uP#Y, uP#Z]// EOM // three-dimensional velocity for convect/advect |
| 52 |
ENDIFMACRO |
| 53 |
IFMACRO(meshtype,S) |
| 54 |
macro meshN()meshS// EOM // three-dimensional surface problem |
| 55 |
macro intN()int2d// EOM // two-dimensional integral |
| 56 |
macro intN1()int1d// EOM // one-dimensional integral |
| 57 |
macro readmeshN()readmeshS// EOM // three-dimensional surface problem |
| 58 |
macro intNxN()int2dx2d// EOM // two-dimensional integral for BEM |
| 59 |
ENDIFMACRO |
| 60 |
IFMACRO(meshtype,L) |
| 61 |
macro meshN()meshL// EOM // three-dimensional line problem |
| 62 |
macro intN()int1d// EOM // one-dimensional integral |
| 63 |
macro intN1()int0d// EOM // zero-dimensional integral |
| 64 |
macro readmeshN()readmeshL// EOM // three-dimensional line problem |
| 65 |
macro intNxN()int1dx1d// EOM // one-dimensional integral for BEM |
| 66 |
ENDIFMACRO |
| 67 |
ENDIFMACRO |
| 68 |
|
| 69 |
macro plotDmesh(Th, params) |
| 70 |
if(!NoGraphicWindow || usedARGV("-fglut") != -1) { |
| 71 |
fespace PhPlotPrivate(Th, P0); |
| 72 |
PhPlotPrivate plt; |
| 73 |
if(Th.nt) |
| 74 |
plt[] = mpirank; |
| 75 |
NewMacro defPlt#Th(uPrivate)uPrivate EndMacro |
| 76 |
plotMPI(Th, plt, P0, defPlt#Th, real, params) |
| 77 |
}// |
| 78 |
|
| 79 |
macro plotD(Th, uPrivate, params) |
| 80 |
if(!NoGraphicWindow || usedARGV("-fglut") != -1) { |
| 81 |
fespace VhPlotPrivate(Th, P1); |
| 82 |
VhPlotPrivate plt; |
| 83 |
if(Th.nt) |
| 84 |
plt = uPrivate; |
| 85 |
NewMacro defPlt#Th(vPrivate)vPrivate EndMacro |
| 86 |
plotMPI(Th, plt, P1, defPlt#Th, real, params) |
| 87 |
}// |
| 88 |
|
| 89 |
macro plotMPI(Th, uPrivate, Pk, def, K, params) |
| 90 |
if(!NoGraphicWindow || usedARGV("-fglut") != -1) { |
| 91 |
IFMACRO(!meshN) |
| 92 |
NewMacro meshN()mesh EndMacro |
| 93 |
ENDIFMACRO |
| 94 |
IFMACRO(!def) |
| 95 |
NewMacro def(i)i EndMacro |
| 96 |
ENDIFMACRO |
| 97 |
meshN ThCurrent = Th; |
| 98 |
fespace XhPlotPrivate(ThCurrent, Pk); |
| 99 |
XhPlotPrivate<K> def(uSend); |
| 100 |
if(ThCurrent.nt) |
| 101 |
def(uSend) = uPrivate; |
| 102 |
if(mpirank == 0) { |
| 103 |
meshN[int] meshTab(mpisize); |
| 104 |
XhPlotPrivate<K>[int] def(uTab)(mpisize); |
| 105 |
if(ThCurrent.nt) |
| 106 |
uTab[0][] = uSend[]; |
| 107 |
meshTab[0] = ThCurrent; |
| 108 |
mpiRequest[int] rq(mpisize - 1); |
| 109 |
for(int i = 1; i < mpisize; ++i) |
| 110 |
Irecv(processor(i, mpiCommWorld, rq[i - 1]), meshTab[i]); |
| 111 |
mpiWaitAll(rq); |
| 112 |
for(int i = 1; i < mpisize; ++i) { |
| 113 |
ThCurrent = meshTab[i]; |
| 114 |
if(ThCurrent.nt) |
| 115 |
Irecv(processor(i, mpiCommWorld, rq[i - 1]), uTab[i][]); |
| 116 |
} |
| 117 |
mpiWaitAll(rq); |
| 118 |
plot(def(uTab), params); |
| 119 |
} |
| 120 |
else { |
| 121 |
mpiRequest[int] rq(2); |
| 122 |
Isend(processor(0, rq[0]), ThCurrent); |
| 123 |
if(ThCurrent.nt) |
| 124 |
Isend(processor(0, rq[1]), uSend[]); |
| 125 |
mpiWaitAll(rq); |
| 126 |
} |
| 127 |
}// EOM |
| 128 |
|
| 129 |
macro partitionPrivate(meshName, borderName, globalName, PhGlobalPrivate, VhGlobalPrivate, part, rank, size, s, overlap, level, prolongation, D, P, intersection, comm, fakeInterface, PkPart, defPart, initPart, bs) { |
| 130 |
int backupSM = searchMethod; |
| 131 |
searchMethod = 1; |
| 132 |
assert(level >= 1); |
| 133 |
IFMACRO(!privateCreatePartition) |
| 134 |
IFMACRO(!privateCreateMat) |
| 135 |
intersection.resize(1); |
| 136 |
intersection[0].resize(0); |
| 137 |
PhGlobalPrivate supp; |
| 138 |
VhGlobalPrivate suppSmooth; |
| 139 |
IFMACRO(privateDmesh#N2O) |
| 140 |
int[int] n2oSplitPrivate(0); |
| 141 |
ENDIFMACRO |
| 142 |
{ |
| 143 |
int constant = rank; |
| 144 |
for[i, value : supp[]] value = abs(part[][i] - constant) < 0.1; |
| 145 |
AddLayers(VhGlobalPrivate, supp[], 2 * overlap, suppSmooth[]); |
| 146 |
int[int] n2o; |
| 147 |
meshN neighbors; |
| 148 |
bool connected = false; |
| 149 |
for[i, value : suppSmooth[]] if(abs(value - 0.5) < 0.5) connected = true; |
| 150 |
if(!connected) |
| 151 |
n2o.resize(0); |
| 152 |
else |
| 153 |
neighbors = trunc(globalName, suppSmooth > 0.001 && suppSmooth < 0.999, new2old = n2o); |
| 154 |
Unique(part[], intersection[0], remove = constant); |
| 155 |
if(suppSmooth[].max < 0.01) intersection[0].resize(0); |
| 156 |
if(s > 1 && level <= 1) { |
| 157 |
IFMACRO(!privateDmesh#N2O) |
| 158 |
globalName = trunc(globalName, suppSmooth > 0.001, split = s); |
| 159 |
ENDIFMACRO |
| 160 |
IFMACRO(privateDmesh#N2O) |
| 161 |
globalName = trunc(globalName, suppSmooth > 0.001, split = s, new2old = n2oSplitPrivate); |
| 162 |
ENDIFMACRO |
| 163 |
supp = abs(part - constant) < 0.1; |
| 164 |
suppSmooth = 0; |
| 165 |
AddLayers(VhGlobalPrivate, supp[], 2 * overlap, suppSmooth[]); |
| 166 |
} |
| 167 |
} |
| 168 |
int[int] n2oGlobalPrivate, n2oNeighbor; |
| 169 |
IFMACRO(!privateDmesh#CartesianPartitioning) |
| 170 |
if(suppSmooth[].max > 0.01) globalName = trunc(globalName, suppSmooth > 0.001, label = 9999, new2old = n2oGlobalPrivate); |
| 171 |
ENDIFMACRO |
| 172 |
real eps = globalName.measure; |
| 173 |
real[int] epsTab(intersection[0].n); |
| 174 |
mpiRequest[int] rq(2 * intersection[0].n); |
| 175 |
if(mpiSize(comm) == size) { |
| 176 |
for(int j = 0; j < intersection[0].n; ++j) |
| 177 |
Irecv(processor(intersection[0][j], comm, rq[j]), epsTab[j]); |
| 178 |
for(int j = 0; j < intersection[0].n; ++j) |
| 179 |
Isend(processor(intersection[0][j], comm, rq[intersection[0].n + j]), eps); |
| 180 |
} |
| 181 |
else |
| 182 |
epsTab = 1.0e+30; |
| 183 |
suppSmooth = suppSmooth; |
| 184 |
IFMACRO(!privateDmesh#N2O) |
| 185 |
if(suppSmooth[].max > 0.01) meshName[level - 1] = trunc(globalName, suppSmooth > 0.501, label = fakeInterface, new2old = n2oNeighbor); |
| 186 |
else { |
| 187 |
meshN empty; |
| 188 |
meshName[level - 1] = empty; |
| 189 |
} |
| 190 |
IFMACRO(privateDmesh#CartesianPartitioning) |
| 191 |
real[int] bb(2 * dimension); |
| 192 |
boundingbox(meshName[level - 1], bb); |
| 193 |
meshName[level - 1] = trunc(globalName, x > bb[0] && x < bb[1] && y > bb[2] && y < bb[3] |
| 194 |
IFMACRO(dimension,3) |
| 195 |
&& z > bb[4] && z < bb[5] |
| 196 |
ENDIFMACRO |
| 197 |
, label = fakeInterface); |
| 198 |
globalName = meshName[level - 1]; |
| 199 |
n2oNeighbor = 0:globalName.nt - 1; |
| 200 |
ENDIFMACRO |
| 201 |
ENDIFMACRO |
| 202 |
IFMACRO(privateDmesh#N2O) |
| 203 |
if(suppSmooth[].max > 0.01) meshName[level - 1] = trunc(globalName, suppSmooth > 0.501, label = fakeInterface, new2old = privateDmesh#N2O); |
| 204 |
else { |
| 205 |
meshN empty; |
| 206 |
meshName[level - 1] = empty; |
| 207 |
} |
| 208 |
IFMACRO(privateDmesh#CartesianPartitioning) |
| 209 |
real[int] bb(2 * dimension); |
| 210 |
boundingbox(meshName[level - 1], bb); |
| 211 |
meshName[level - 1] = trunc(globalName, x > bb[0] && x < bb[1] && y > bb[2] && y < bb[3] |
| 212 |
IFMACRO(dimension,3) |
| 213 |
&& z > bb[4] && z < bb[5] |
| 214 |
ENDIFMACRO |
| 215 |
, label = fakeInterface, new2old = privateDmesh#N2O); |
| 216 |
globalName = meshName[level - 1]; |
| 217 |
n2oNeighbor = 0:globalName.nt - 1; |
| 218 |
ENDIFMACRO |
| 219 |
IFMACRO(!privateDmesh#CartesianPartitioning) |
| 220 |
{ |
| 221 |
int[int] backup = privateDmesh#N2O; |
| 222 |
int[int] new = n2oGlobalPrivate(privateDmesh#N2O); |
| 223 |
privateDmesh#N2O.resize(new.n); |
| 224 |
privateDmesh#N2O = new; |
| 225 |
n2oNeighbor.resize(backup.n); |
| 226 |
n2oNeighbor = backup; |
| 227 |
if(n2oSplitPrivate.n > 0) { |
| 228 |
int nSplitPrivate = 1; |
| 229 |
while(nSplitPrivate < n2oSplitPrivate.n && n2oSplitPrivate[nSplitPrivate] == n2oSplitPrivate[0]) |
| 230 |
nSplitPrivate++; |
| 231 |
for[m, val : privateDmesh#N2O] |
| 232 |
val = n2oSplitPrivate[val] * nSplitPrivate + val % nSplitPrivate; |
| 233 |
} |
| 234 |
} |
| 235 |
ENDIFMACRO |
| 236 |
ENDIFMACRO |
| 237 |
if(meshName[level - 1].nt) { |
| 238 |
if(level > 1) { |
| 239 |
prolongation.resize(level - 1); |
| 240 |
if(s > 1) { |
| 241 |
meshN globalNameRefined = globalName; |
| 242 |
for(int i = level - 1; i > 0; --i) { |
| 243 |
globalNameRefined = trunc(globalNameRefined, 1, split = s); |
| 244 |
meshName[i - 1] = trunc(globalNameRefined, suppSmooth > 0.501, label = fakeInterface); |
| 245 |
fespace WhLocalRefinedPrivate(meshName[i - 1], P); |
| 246 |
fespace WhLocalCoarsePrivate(meshName[i], P); |
| 247 |
prolongation[i - 1] = interpolate(WhLocalRefinedPrivate, WhLocalCoarsePrivate); |
| 248 |
} |
| 249 |
} |
| 250 |
else |
| 251 |
for(int i = level - 1; i > 0; --i) |
| 252 |
meshName[i - 1] = meshName[i]; |
| 253 |
} |
| 254 |
if(!removeZeros && (fakeInterface != -111111 || overlap != 1)) { |
| 255 |
if(suppSmooth[].min < 0.501) { |
| 256 |
supp = supp; |
| 257 |
borderName[level - 1] = trunc(globalName, (suppSmooth > (overlap - 0.999) / real(2 * overlap)) && (suppSmooth < 0.501), label = (abs(fakeInterface) + 1) * 100); |
| 258 |
if(s > 1) |
| 259 |
for(int i = level - 2; i >= 0; --i) { |
| 260 |
borderName[i] = trunc(borderName[i + 1], 1, split = s, label = (abs(fakeInterface) + 1) * 100); |
| 261 |
meshN tempRefined = meshName[i] + borderName[i]; |
| 262 |
fespace PhRefinedPrivate(tempRefined, P0); |
| 263 |
PhRefinedPrivate suppRefined = supp; |
| 264 |
fespace VhBorderRefinedPrivate(borderName[i], P1); |
| 265 |
VhBorderRefinedPrivate suppBorder = suppRefined; |
| 266 |
borderName[i] = trunc(borderName[i], suppBorder > 0.01); |
| 267 |
} |
| 268 |
else |
| 269 |
for(int i = level - 2; i >= 0; --i) |
| 270 |
borderName[i] = borderName[i + 1]; |
| 271 |
} |
| 272 |
} |
| 273 |
fespace VhLocalPrivate(meshName[level - 1], P1); |
| 274 |
IFMACRO(!privateDmesh#meshName) |
| 275 |
NewMacro privateDmesh#meshName#intersectionDef()partitionIntersectionTab EndMacro |
| 276 |
real[int][int] partitionIntersectionTab(1 + intersection[0].n); |
| 277 |
privateDmesh#meshName#intersectionDef[0].resize(intersection[0].n); |
| 278 |
ENDIFMACRO |
| 279 |
IFMACRO(privateBuildDmesh) |
| 280 |
privateDmesh#meshName#intersectionDef.resize(1 + intersection[0].n); |
| 281 |
privateDmesh#meshName#intersectionDef[0].resize(intersection[0].n); |
| 282 |
ENDIFMACRO |
| 283 |
VhLocalPrivate khi = max(2 * suppSmooth - 1.0, 0.0); |
| 284 |
VhLocalPrivate sum; |
| 285 |
sum[] = khi[]; |
| 286 |
VhGlobalPrivate phi; |
| 287 |
if(n2oGlobalPrivate.n == globalName.nt && s == 1) { |
| 288 |
real[int] restrictionPart(n2oGlobalPrivate.n); |
| 289 |
restrictionPart = part[](n2oGlobalPrivate); |
| 290 |
part = 0.0; |
| 291 |
part[] = restrictionPart; |
| 292 |
} |
| 293 |
else |
| 294 |
part = part; |
| 295 |
n2oGlobalPrivate.resize(0); |
| 296 |
int numberIntersection = 0; |
| 297 |
if(suppSmooth[].max > 0.01) { |
| 298 |
int[int] restriction = restrict(VhLocalPrivate, VhGlobalPrivate, n2oNeighbor); |
| 299 |
n2oNeighbor.resize(0); |
| 300 |
mpiWaitAll(rq); |
| 301 |
for(int i = 0; i < intersection[0].n; ++i) { |
| 302 |
PhGlobalPrivate suppPartition = abs(part - intersection[0][i]) < 0.1; |
| 303 |
AddLayers(VhGlobalPrivate, suppPartition[], overlap, phi[]); |
| 304 |
if(min(eps, epsTab[i]) > 0.0) { |
| 305 |
if(intN(globalName, qforder = 2)(phi) / min(eps, epsTab[i]) > 1.0e-10) { |
| 306 |
privateDmesh#meshName#intersectionDef[1 + numberIntersection].resize(restriction.n); |
| 307 |
privateDmesh#meshName#intersectionDef[1 + numberIntersection] = phi[](restriction); |
| 308 |
if(!trueRestrict) |
| 309 |
sum[] += privateDmesh#meshName#intersectionDef[1 + numberIntersection]; |
| 310 |
intersection[0][numberIntersection++] = intersection[0][i]; |
| 311 |
} |
| 312 |
} |
| 313 |
} |
| 314 |
} |
| 315 |
if(numberIntersection != intersection[0].n) { |
| 316 |
intersection[0].resize(numberIntersection); |
| 317 |
privateDmesh#meshName#intersectionDef.resize(1 + numberIntersection); |
| 318 |
} |
| 319 |
intersection.resize(1 + level * numberIntersection); |
| 320 |
ENDIFMACRO |
| 321 |
IFMACRO(privateCreateMat) |
| 322 |
assert(level == 1); |
| 323 |
int numberIntersection = privateDmesh#meshName#intersectionDef.n - 1; |
| 324 |
intersection.resize(1 + level * numberIntersection); |
| 325 |
intersection[0].resize(numberIntersection); |
| 326 |
intersection[0] = lround(privateDmesh#meshName#intersectionDef[0]); |
| 327 |
fespace VhLocalPrivate(meshName[level - 1], P1); |
| 328 |
IFMACRO(privateDmesh#N2O) |
| 329 |
IFMACRO(privateDmesh#Original) |
| 330 |
IFMACRO(privateDmesh#Restriction) |
| 331 |
{ |
| 332 |
fespace WhLocalPrivate(meshName[level - 1], P); |
| 333 |
fespace WhOriginalPrivate(privateDmesh#Original, P); |
| 334 |
privateDmesh#Restriction.resize(WhOriginalPrivate.ndof); |
| 335 |
privateDmesh#Restriction = restrict(WhLocalPrivate, WhOriginalPrivate, privateDmesh#N2O); |
| 336 |
} |
| 337 |
ENDIFMACRO |
| 338 |
ENDIFMACRO |
| 339 |
ENDIFMACRO |
| 340 |
ENDIFMACRO |
| 341 |
IFMACRO(privateBuildDmesh) |
| 342 |
privateDmesh#meshName#intersectionDef[0].resize(numberIntersection); |
| 343 |
for[i, value : intersection[0]] privateDmesh#meshName#intersectionDef[0][i] = value; |
| 344 |
ENDIFMACRO |
| 345 |
meshN[int] meshIntersection(numberIntersection); |
| 346 |
IFMACRO(!privateCreateMat) |
| 347 |
int[int][int] n2oIntersection(0); |
| 348 |
if(trueRestrict && mpiSize(comm) == size && removeZeros) |
| 349 |
n2oIntersection.resize(numberIntersection); |
| 350 |
ENDIFMACRO |
| 351 |
for(int j = 0; j < (s == 1 ? 1 : level); ++j) { |
| 352 |
for(int i = 0; i < numberIntersection; ++i) { |
| 353 |
int[int] n2o; |
| 354 |
VhLocalPrivate partitionIntersection; |
| 355 |
partitionIntersection[] = privateDmesh#meshName#intersectionDef[1 + i]; |
| 356 |
meshIntersection[i] = trunc(meshName[j], partitionIntersection > 1.0e-6, new2old = n2o, label = 9999); |
| 357 |
IFMACRO(privateDmesh#CartesianPartitioning) |
| 358 |
real[int] bb(2 * dimension); |
| 359 |
boundingbox(meshIntersection[i], bb); |
| 360 |
meshIntersection[i] = trunc(meshName[j], x > bb[0] && x < bb[1] && y > bb[2] && y < bb[3] |
| 361 |
IFMACRO(dimension,3) |
| 362 |
&& z > bb[4] && z < bb[5] |
| 363 |
ENDIFMACRO |
| 364 |
, new2old = n2o, label = 9999); |
| 365 |
ENDIFMACRO |
| 366 |
IFMACRO(!privateCreateMat) |
| 367 |
if(j == 0 && trueRestrict && mpiSize(comm) == size && removeZeros) { |
| 368 |
n2oIntersection[i].resize(n2o.n); |
| 369 |
n2oIntersection[i] = n2o; |
| 370 |
} |
| 371 |
if(!removeZeros) |
| 372 |
ENDIFMACRO |
| 373 |
{ |
| 374 |
IFMACRO(vectorialfe) |
| 375 |
fespace singleComponentWhPrivate(meshName[j], vectorialfe); |
| 376 |
fespace WhIntersectionPrivate(meshIntersection[i], vectorialfe); |
| 377 |
ENDIFMACRO |
| 378 |
IFMACRO(!vectorialfe) |
| 379 |
fespace singleComponentWhPrivate(meshName[j], P); |
| 380 |
fespace WhIntersectionPrivate(meshIntersection[i], P); |
| 381 |
ENDIFMACRO |
| 382 |
intersection[1 + i + j * numberIntersection] = restrict(WhIntersectionPrivate, singleComponentWhPrivate, n2o); |
| 383 |
} |
| 384 |
} |
| 385 |
} |
| 386 |
IFMACRO(!privateCreateMat) |
| 387 |
if(s == 1 && level > 1 && !removeZeros) |
| 388 |
for(int j = 1; j < level; ++j) |
| 389 |
for(int i = 0; i < numberIntersection; ++i) { |
| 390 |
intersection[1 + i + j * numberIntersection].resize(intersection[1 + i].n); |
| 391 |
intersection[1 + i + j * numberIntersection] = intersection[1 + i]; |
| 392 |
} |
| 393 |
for(int i = 0; i < level - 1; ++i) { |
| 394 |
fespace VhRefinedPrivate(meshName[i], P1); |
| 395 |
fespace PhRefinedPrivate(meshName[i], P0); |
| 396 |
PhRefinedPrivate partRefined = part; |
| 397 |
PhRefinedPrivate supp = abs(partRefined - rank) < 0.1; |
| 398 |
varf vSupp(uPrivate, vPrivate) = intN(meshName[i], qforder = 1)(supp * vPrivate); |
| 399 |
VhRefinedPrivate khiL; |
| 400 |
khiL[] = vSupp(0, VhRefinedPrivate); |
| 401 |
khiL = khiL > 0.0; |
| 402 |
VhRefinedPrivate sum = khiL; |
| 403 |
for(int j = 0; j < numberIntersection; ++j) { |
| 404 |
supp = abs(partRefined - intersection[0][j]) < 0.1; |
| 405 |
VhRefinedPrivate phiL; |
| 406 |
phiL[] = vSupp(0, VhRefinedPrivate); |
| 407 |
phiL = phiL > 0.0; |
| 408 |
sum[] += phiL[]; |
| 409 |
} |
| 410 |
khiL[] ./= sum[]; |
| 411 |
fespace WhRefinedPrivate(meshName[i], PkPart); |
| 412 |
WhRefinedPrivate defPart(func2vec); |
| 413 |
defPart(func2vec) = initPart(khiL); |
| 414 |
D[i].resize(WhRefinedPrivate.ndof); |
| 415 |
D[i] = func2vec[]; |
| 416 |
} |
| 417 |
if(!trueRestrict) |
| 418 |
khi[] ./= sum[]; |
| 419 |
else { |
| 420 |
khi = abs(part - rank) < 0.1; |
| 421 |
VhLocalPrivate sigma = part; |
| 422 |
for(int i = 0; i < numberIntersection; ++i) { |
| 423 |
if(rank < intersection[0][i]) { |
| 424 |
for[j, value : khi[]] { |
| 425 |
if(value > 0.9 && abs(sigma[][j] - intersection[0][i]) < 0.1) |
| 426 |
value = 0.0; |
| 427 |
} |
| 428 |
} |
| 429 |
} |
| 430 |
} |
| 431 |
if(trueRestrict && mpiSize(comm) == size && removeZeros) { |
| 432 |
assert(level == 1); |
| 433 |
meshN ThIntersection; |
| 434 |
mpiRequest[int] rq(2 * numberIntersection); |
| 435 |
int[int] skip(0); |
| 436 |
{ |
| 437 |
fespace PhIntersectionPrivate(ThIntersection, P0); |
| 438 |
PhIntersectionPrivate[int] recv(numberIntersection); |
| 439 |
PhIntersectionPrivate[int] send(numberIntersection); |
| 440 |
for(int i = 0; i < numberIntersection; ++i) { |
| 441 |
ThIntersection = meshIntersection[i]; |
| 442 |
Irecv(processor(intersection[0][i], comm, rq[i]), recv[i][]); |
| 443 |
send[i] = khi; |
| 444 |
Isend(processor(intersection[0][i], comm, rq[numberIntersection + i]), send[i][]); |
| 445 |
} |
| 446 |
real[int] tmpRemove(meshName[0].nt); |
| 447 |
int[int] n2oRemove; |
| 448 |
IFMACRO(!privateDmesh#N2O) |
| 449 |
meshName[0] = trunc(meshName[0], khi > 1.0e-6, label = 9999, new2old = n2oRemove); |
| 450 |
ENDIFMACRO |
| 451 |
IFMACRO(privateDmesh#N2O) |
| 452 |
{ |
| 453 |
int[int] n2oFilter; |
| 454 |
meshName[0] = trunc(meshName[0], khi > 1.0e-6, label = 9999, new2old = n2oRemove); |
| 455 |
n2oFilter.resize(n2oRemove.n); |
| 456 |
n2oFilter = privateDmesh#N2O(n2oRemove); |
| 457 |
privateDmesh#N2O.resize(n2oFilter.n); |
| 458 |
privateDmesh#N2O = n2oFilter; |
| 459 |
} |
| 460 |
ENDIFMACRO |
| 461 |
khi = khi; |
| 462 |
fespace PhLocalPrivate(meshName[0], P0); |
| 463 |
for(int k = 0; k < 2 * numberIntersection; ++k) { |
| 464 |
int i = mpiWaitAny(rq); |
| 465 |
if(i < numberIntersection) { |
| 466 |
ThIntersection = meshIntersection[i]; |
| 467 |
PhIntersectionPrivate intersection = send[i] > 1.0e-6 && recv[i] > 1.0e-6; |
| 468 |
if(intersection[].l2 > 1.0e-6) { |
| 469 |
tmpRemove = 0.0; |
| 470 |
tmpRemove(n2oIntersection[i]) = intersection[]; |
| 471 |
PhLocalPrivate afterTrunc; |
| 472 |
afterTrunc[] = tmpRemove(n2oRemove); |
| 473 |
meshIntersection[i] = trunc(meshName[0], afterTrunc > 1.0e-6, label = 9999, new2old = n2oIntersection[i]); |
| 474 |
} |
| 475 |
else { |
| 476 |
skip.resize(skip.n + 1); |
| 477 |
skip[skip.n - 1] = i; |
| 478 |
} |
| 479 |
} |
| 480 |
} |
| 481 |
} |
| 482 |
skip.sort; |
| 483 |
real[int][int] recv(numberIntersection); |
| 484 |
real[int][int] send(numberIntersection); |
| 485 |
int j = 0; |
| 486 |
for(int i = 0; i < numberIntersection; ++i) { |
| 487 |
bool skipped = false; |
| 488 |
if(j < skip.n) { |
| 489 |
if(skip[j] == i) { |
| 490 |
++j; |
| 491 |
skipped = true; |
| 492 |
} |
| 493 |
} |
| 494 |
if(!skipped) { |
| 495 |
recv[i].resize(meshIntersection[i].nv); |
| 496 |
Irecv(processor(intersection[0][i], comm, rq[i]), recv[i]); |
| 497 |
fespace VhIntersectionPrivate(meshIntersection[i], P1); |
| 498 |
int[int] restriction = restrict(VhIntersectionPrivate, VhLocalPrivate, n2oIntersection[i]); |
| 499 |
send[i].resize(meshIntersection[i].nv); |
| 500 |
send[i] = khi[](restriction); |
| 501 |
Isend(processor(intersection[0][i], comm, rq[numberIntersection + i]), send[i]); |
| 502 |
} |
| 503 |
} |
| 504 |
mpiWaitAll(rq); |
| 505 |
intersection.resize(1 + numberIntersection - skip.n); |
| 506 |
j = 0; |
| 507 |
for(int i = 0; i < numberIntersection; ++i) { |
| 508 |
bool skipped = false; |
| 509 |
if(j < skip.n) { |
| 510 |
if(skip[j] == i) { |
| 511 |
++j; |
| 512 |
skipped = true; |
| 513 |
} |
| 514 |
} |
| 515 |
if(!skipped) { |
| 516 |
IFMACRO(vectorialfe) |
| 517 |
fespace singleComponentWhPrivate(meshName[0], vectorialfe); |
| 518 |
fespace WhIntersectionPrivate(meshIntersection[i], vectorialfe); |
| 519 |
ENDIFMACRO |
| 520 |
IFMACRO(!vectorialfe) |
| 521 |
fespace singleComponentWhPrivate(meshName[0], P); |
| 522 |
fespace WhIntersectionPrivate(meshIntersection[i], P); |
| 523 |
ENDIFMACRO |
| 524 |
intersection[1 + i - j] = restrict(WhIntersectionPrivate, singleComponentWhPrivate, n2oIntersection[i]); |
| 525 |
fespace VhIntersectionPrivate(meshIntersection[i], P1); |
| 526 |
int[int] restriction = restrict(VhIntersectionPrivate, VhLocalPrivate, n2oIntersection[i]); |
| 527 |
privateDmesh#meshName#intersectionDef[1 + i - j].resize(VhLocalPrivate.ndof); |
| 528 |
privateDmesh#meshName#intersectionDef[1 + i - j] = 0.0; |
| 529 |
privateDmesh#meshName#intersectionDef[1 + i - j](restriction) = recv[i]; |
| 530 |
intersection[0][i - j] = intersection[0][i]; |
| 531 |
} |
| 532 |
} |
| 533 |
numberIntersection -= skip.n; |
| 534 |
intersection[0].resize(numberIntersection); |
| 535 |
privateDmesh#meshName#intersectionDef.resize(1 + numberIntersection); |
| 536 |
privateDmesh#meshName#intersectionDef[0].resize(numberIntersection); |
| 537 |
for[i, value : intersection[0]] privateDmesh#meshName#intersectionDef[0][i] = value; |
| 538 |
if(fakeInterface != -111111 || overlap != 1) { |
| 539 |
PhGlobalPrivate suppPartition = khi > 0.1; |
| 540 |
AddLayers(VhGlobalPrivate, suppPartition[], 1, phi[]); |
| 541 |
borderName[0] = trunc(globalName, phi > 0.001 && phi < 0.501, label = (abs(fakeInterface) + 1) * 100); |
| 542 |
} |
| 543 |
} |
| 544 |
ENDIFMACRO |
| 545 |
IFMACRO(vectorialfe) |
| 546 |
if(bs > 1) |
| 547 |
for(int i = 0; i < intersection.n - 1; ++i) { |
| 548 |
int n = intersection[1 + i].n; |
| 549 |
intersection[1 + i].resize(n * bs); |
| 550 |
for(int j = n - 1; j != -1; --j) |
| 551 |
for(int k = bs - 1; k != -1; --k) |
| 552 |
intersection[1 + i][j * bs + k] = intersection[1 + i][j] * bs + k; |
| 553 |
} |
| 554 |
ENDIFMACRO |
| 555 |
ENDIFMACRO |
| 556 |
IFMACRO(privateCreatePartition) |
| 557 |
fespace VhLocalPrivate(meshName[level - 1], P1); |
| 558 |
IFMACRO(!privateCreateMat) |
| 559 |
VhLocalPrivate khi; |
| 560 |
ENDIFMACRO |
| 561 |
ENDIFMACRO |
| 562 |
IFMACRO(privateCreateMat) |
| 563 |
VhLocalPrivate khi; |
| 564 |
if(VhLocalPrivate.ndof) khi[] = privateDmesh#meshName#khiDef[0]; |
| 565 |
ENDIFMACRO |
| 566 |
fespace WhPartPrivate(meshName[level - 1], PkPart); |
| 567 |
WhPartPrivate defPart(func2vec); |
| 568 |
D[level - 1].resize(WhPartPrivate.ndof); |
| 569 |
if(WhPartPrivate.ndof) { |
| 570 |
if((WhPartPrivate.ndof % meshName[level - 1].nt) == 0 && WhPartPrivate.ndof != meshName[level - 1].nv) { |
| 571 |
int constant = rank; |
| 572 |
IFMACRO(privateCreateMat) |
| 573 |
fespace PhLocalPrivate(meshName[level - 1], P0); |
| 574 |
PhLocalPrivate partLocal; |
| 575 |
partLocal[] = privateDmesh#meshName#khiDef[1]; |
| 576 |
defPart(func2vec) = initPart(abs(partLocal - constant) < 0.1); |
| 577 |
ENDIFMACRO |
| 578 |
IFMACRO(!privateCreateMat) |
| 579 |
defPart(func2vec) = initPart(abs(part - constant) < 0.1); |
| 580 |
ENDIFMACRO |
| 581 |
} |
| 582 |
else if(WhPartPrivate.ndof == meshName[level - 1].nv && (WhPartPrivate.ndof % meshName[level - 1].nt) != 0) |
| 583 |
func2vec[] = khi[]; |
| 584 |
else |
| 585 |
defPart(func2vec) = initPart(khi); |
| 586 |
D[level - 1] = func2vec[]; |
| 587 |
} |
| 588 |
IFMACRO(privateDmesh#PostProcessD) |
| 589 |
privateDmesh#PostProcessD(D[level - 1]); |
| 590 |
ENDIFMACRO |
| 591 |
IFMACRO(!privateCreatePartition) |
| 592 |
IFMACRO(!privateCreateMat) |
| 593 |
IFMACRO(privateBuildDmesh) |
| 594 |
fespace PhLocalPrivate(meshName[level - 1], P0); |
| 595 |
PhLocalPrivate partLocal; |
| 596 |
partLocal = part; |
| 597 |
privateDmesh#meshName#khiDef[1].resize(partLocal[].n); |
| 598 |
privateDmesh#meshName#khiDef[1] = partLocal[]; |
| 599 |
ENDIFMACRO |
| 600 |
ENDIFMACRO |
| 601 |
ENDIFMACRO |
| 602 |
IFMACRO(!privateCreatePartition) |
| 603 |
IFMACRO(!privateCreateMat) |
| 604 |
} |
| 605 |
IFMACRO(privateBuildDmesh) |
| 606 |
else { |
| 607 |
privateDmesh#meshName#intersectionDef.resize(1); |
| 608 |
privateDmesh#meshName#intersectionDef[0].resize(0); |
| 609 |
} |
| 610 |
ENDIFMACRO |
| 611 |
ENDIFMACRO |
| 612 |
ENDIFMACRO |
| 613 |
searchMethod = backupSM; |
| 614 |
}// EOM |
| 615 |
|
| 616 |
macro DmeshSave(ThName, name) |
| 617 |
IFMACRO(privateDmesh#ThName) |
| 618 |
{ |
| 619 |
IFMACRO(!ThName#Comm) |
| 620 |
NewMacro ThName#Comm()mpiCommWorld EndMacro |
| 621 |
ENDIFMACRO |
| 622 |
IFMACRO(!dimension) |
| 623 |
NewMacro dimension()2 EndMacro |
| 624 |
ENDIFMACRO |
| 625 |
IFMACRO(dimension,3) |
| 626 |
savemesh(ThName, name + "_" + mpiRank(ThName#Comm) + "_" + mpiSize(ThName#Comm) + ".meshb"); |
| 627 |
ENDIFMACRO |
| 628 |
IFMACRO(dimension,2) |
| 629 |
savemesh(ThName, name + "_" + mpiRank(ThName#Comm) + "_" + mpiSize(ThName#Comm) + ".msh"); |
| 630 |
ENDIFMACRO |
| 631 |
ofstream khi(name + "_" + mpiRank(ThName#Comm) + "_" + mpiSize(ThName#Comm) + ".khi"); |
| 632 |
khi << privateDmesh#ThName#khi << endl; |
| 633 |
khi << privateDmesh#ThName#intersection << endl; |
| 634 |
IFMACRO(ThName#N2O) |
| 635 |
khi << ThName#N2O << endl; |
| 636 |
ENDIFMACRO |
| 637 |
} |
| 638 |
ENDIFMACRO |
| 639 |
IFMACRO(!privateDmesh#ThName) |
| 640 |
assert(0); |
| 641 |
ENDIFMACRO |
| 642 |
EndMacro |
| 643 |
|
| 644 |
macro DmeshLoad(ThName, name) |
| 645 |
IFMACRO(!privateDmesh#ThName) |
| 646 |
NewMacro privateDmesh#ThName()privateDmesh#ThName EndMacro |
| 647 |
NewMacro privateDmesh#ThName#khi()privateDmesh#ThName#khiDef EndMacro |
| 648 |
NewMacro privateDmesh#ThName#intersection()privateDmesh#ThName#intersectionDef EndMacro |
| 649 |
real[int][int] privateDmesh#ThName#khi(2); |
| 650 |
real[int][int] privateDmesh#ThName#intersection; |
| 651 |
ENDIFMACRO |
| 652 |
{ |
| 653 |
IFMACRO(!ThName#Comm) |
| 654 |
NewMacro ThName#Comm()mpiCommWorld EndMacro |
| 655 |
ENDIFMACRO |
| 656 |
IFMACRO(!dimension) |
| 657 |
NewMacro dimension()2 EndMacro |
| 658 |
ENDIFMACRO |
| 659 |
IFMACRO(dimension,3) |
| 660 |
ThName = readmesh3(name + "_" + mpiRank(ThName#Comm) + "_" + mpiSize(ThName#Comm) + ".meshb"); |
| 661 |
ENDIFMACRO |
| 662 |
IFMACRO(dimension,2) |
| 663 |
ThName = readmesh(name + "_" + mpiRank(ThName#Comm) + "_" + mpiSize(ThName#Comm) + ".msh"); |
| 664 |
ENDIFMACRO |
| 665 |
privateDmesh#ThName#khi.resize(2); |
| 666 |
privateDmesh#ThName#khi[0].resize(ThName.nv); |
| 667 |
privateDmesh#ThName#khi[1].resize(ThName.nt); |
| 668 |
if(mpiSize(ThName#Comm) > 1) { |
| 669 |
ifstream khi(name + "_" + mpiRank(ThName#Comm) + "_" + mpiSize(ThName#Comm) + ".khi"); |
| 670 |
int m; |
| 671 |
khi >> m; |
| 672 |
assert(m == 2); |
| 673 |
khi >> privateDmesh#ThName#khi[0]; |
| 674 |
khi >> privateDmesh#ThName#khi[1]; |
| 675 |
khi >> m; |
| 676 |
privateDmesh#ThName#intersection.resize(m); |
| 677 |
for(int j = 0; j < m; ++j) { |
| 678 |
int n; |
| 679 |
khi >> n; |
| 680 |
privateDmesh#ThName#intersection[j].resize(n); |
| 681 |
for[i, value : privateDmesh#ThName#intersection[j]] |
| 682 |
khi >> value; |
| 683 |
} |
| 684 |
IFMACRO(ThName#N2O) |
| 685 |
ThName#N2O.resize(ThName.nt); |
| 686 |
khi >> ThName#N2O; |
| 687 |
ENDIFMACRO |
| 688 |
} |
| 689 |
else { |
| 690 |
privateDmesh#ThName#khi[0] = 1.0; |
| 691 |
privateDmesh#ThName#khi[1] = 1.0; |
| 692 |
IFMACRO(ThName#N2O) |
| 693 |
ThName#N2O.resize(ThName.nt); |
| 694 |
ThName#N2O = 0:ThName.nt - 1; |
| 695 |
ENDIFMACRO |
| 696 |
} |
| 697 |
} |
| 698 |
EndMacro |
| 699 |
|
| 700 |
macro DmeshCreate(ThName) |
| 701 |
IFMACRO(!privateDmesh#ThName) |
| 702 |
NewMacro privateDmesh#ThName()privateDmesh#ThName EndMacro |
| 703 |
NewMacro privateDmesh#ThName#khi()privateDmesh#ThName#khiDef EndMacro |
| 704 |
NewMacro privateDmesh#ThName#intersection()privateDmesh#ThName#intersectionDef EndMacro |
| 705 |
real[int][int] privateDmesh#ThName#khi(2); |
| 706 |
real[int][int] privateDmesh#ThName#intersection; |
| 707 |
ENDIFMACRO |
| 708 |
{ |
| 709 |
IFMACRO(!meshN) |
| 710 |
IFMACRO((dimension,3S)|(dimension,3L)) |
| 711 |
if(mpirank == 0) cout << "Deprecated \"dimension\" value, switch to: \n NewMacro dimension()3 EndMacro\n NewMacro meshtype()S EndMacro (for meshS, or L for meshL)" << endl; |
| 712 |
ENDIFMACRO |
| 713 |
IFMACRO((dimension,3)|(dimension,3S)|(dimension,3L)) |
| 714 |
IFMACRO(dimension,3S) |
| 715 |
NewMacro meshtype()S EndMacro /* TODO FIXME: remove at some point (deprecated since July 2025) */ |
| 716 |
ENDIFMACRO |
| 717 |
IFMACRO(dimension,3L) |
| 718 |
NewMacro meshtype()L EndMacro /* TODO FIXME: remove at some point (deprecated since July 2025) */ |
| 719 |
ENDIFMACRO |
| 720 |
IFMACRO(!meshtype) |
| 721 |
NewMacro meshtype()V EndMacro |
| 722 |
ENDIFMACRO |
| 723 |
IFMACRO(meshtype,V) |
| 724 |
NewMacro meshN()mesh3 EndMacro /* three-dimensional problem */ |
| 725 |
NewMacro intN()int3d EndMacro /* three-dimensional integral */ |
| 726 |
ENDIFMACRO |
| 727 |
IFMACRO(meshtype,S) |
| 728 |
NewMacro meshN()meshS EndMacro /* three-dimensional surface problem */ |
| 729 |
NewMacro intN()int2d EndMacro /* two-dimensional integral */ |
| 730 |
ENDIFMACRO |
| 731 |
IFMACRO(meshtype,L) |
| 732 |
NewMacro meshN()meshL EndMacro /* three-dimensional line problem */ |
| 733 |
NewMacro intN()int1d EndMacro /* one-dimensional integral */ |
| 734 |
ENDIFMACRO |
| 735 |
ENDIFMACRO |
| 736 |
IFMACRO(!meshN) |
| 737 |
NewMacro meshN()mesh EndMacro /* two-dimensional problem */ |
| 738 |
NewMacro intN()int2d EndMacro /* two-dimensional integral */ |
| 739 |
ENDIFMACRO |
| 740 |
ENDIFMACRO |
| 741 |
IFMACRO(!ThName#Comm) |
| 742 |
NewMacro ThName#Comm()mpiCommWorld EndMacro |
| 743 |
ENDIFMACRO |
| 744 |
NewMacro privateBuildDmesh()1 EndMacro |
| 745 |
int[int][int] intersection; |
| 746 |
NewMacro privateDmesh#ThTab()privateDmesh#ThName EndMacro |
| 747 |
NewMacro privateDmesh#ThTab#khi()privateDmesh#ThName#khiDef EndMacro |
| 748 |
NewMacro privateDmesh#ThTab#intersection()privateDmesh#ThName#intersectionDef EndMacro |
| 749 |
IFMACRO(ThName#N2O) |
| 750 |
NewMacro privateDmesh#N2O()ThName#N2O EndMacro |
| 751 |
IFMACRO(ThName#Periodicity) |
| 752 |
if(mpirank == 0) cout << "Deprecated \"" << Stringification(ThName) << "Periodicity\" macro, switch to: \n NewMacro " << Stringification(ThName) << "Periodic() EndMacro" << endl; /* TODO FIXME: remove at some point (deprecated since January 2026) */ |
| 753 |
ENDIFMACRO |
| 754 |
IFMACRO(ThName#Periodic) |
| 755 |
IFMACRO(ThName#Periodicity) |
| 756 |
exit(21); /* not currently implemented */ |
| 757 |
ENDIFMACRO |
| 758 |
NewMacro privateDmesh#Periodic()ThName#Periodic EndMacro |
| 759 |
ENDIFMACRO |
| 760 |
ENDIFMACRO |
| 761 |
IFMACRO(ThName#UserPartitioning) |
| 762 |
IFMACRO(ThName#RefinementFactor) |
| 763 |
exit(11); /* not currently implemented */ |
| 764 |
ENDIFMACRO |
| 765 |
IFMACRO(!ThName#Overlap) |
| 766 |
buildWithPartitioning(ThName, ThName#UserPartitioning, 1, intersection, privateDmesh#ThName#khi[0], P1, ThName#Comm); |
| 767 |
ENDIFMACRO |
| 768 |
IFMACRO(ThName#Overlap) |
| 769 |
assert(ThName#Overlap > 0); |
| 770 |
meshN privateBorder; |
| 771 |
int privateS = 1; |
| 772 |
buildOverlapWithPartitioning(ThName, privateBorder, ThName#UserPartitioning, -111111, privateS, ThName#Overlap, intersection, privateDmesh#ThName#khi[0], P1, ThName#Comm, false); |
| 773 |
ENDIFMACRO |
| 774 |
ENDIFMACRO |
| 775 |
IFMACRO((ThName#Periodic)|(ThName#Periodicity)) |
| 776 |
IFMACRO(ThName#RefinementFactor) |
| 777 |
exit(12); /* not currently implemented */ |
| 778 |
ENDIFMACRO |
| 779 |
IFMACRO(ThName#Overlap) |
| 780 |
assert(ThName#Overlap > 0); |
| 781 |
meshN privateBorder; |
| 782 |
int privateS = 1; |
| 783 |
IFMACRO(!ThName#Periodicity) |
| 784 |
buildOverlap(ThName, privateBorder, -111111, privateS, ThName#Overlap, intersection, privateDmesh#ThName#khi[0], P1, ThName#Comm, false) |
| 785 |
ENDIFMACRO |
| 786 |
IFMACRO(ThName#Periodicity) |
| 787 |
buildOverlapPeriodic(ThName, privateBorder, -111111, privateS, ThName#Overlap, intersection, privateDmesh#ThName#khi[0], P1, ThName#Comm, false, ThName#Periodicity) |
| 788 |
ENDIFMACRO |
| 789 |
ENDIFMACRO |
| 790 |
IFMACRO(!ThName#Overlap) |
| 791 |
IFMACRO(!ThName#Periodicity) |
| 792 |
build(ThName, 1, intersection, privateDmesh#ThName#khi[0], P1, ThName#Comm); |
| 793 |
ENDIFMACRO |
| 794 |
IFMACRO(ThName#Periodicity) |
| 795 |
buildPeriodic(ThName, 1, intersection, privateDmesh#ThName#khi[0], P1, ThName#Comm, ThName#Periodicity); |
| 796 |
ENDIFMACRO |
| 797 |
ENDIFMACRO |
| 798 |
ENDIFMACRO |
| 799 |
IFMACRO(!ThName#UserPartitioning) |
| 800 |
IFMACRO((!ThName#Periodic)&(!ThName#Periodicity)) |
| 801 |
IFMACRO(ThName#CartesianPartitioning) |
| 802 |
IFMACRO(!dimension) |
| 803 |
NewMacro dimension()2 EndMacro |
| 804 |
ENDIFMACRO |
| 805 |
IFMACRO((meshtype,S)|(meshtype,L)) |
| 806 |
exit(106); /* not currently implemented */ |
| 807 |
ENDIFMACRO |
| 808 |
NewMacro privateDmesh#CartesianPartitioning() EndMacro |
| 809 |
IFMACRO(ThName#RefinementFactor) |
| 810 |
exit(13); /* not currently implemented */ |
| 811 |
ENDIFMACRO |
| 812 |
IFMACRO((removeZeros,true)|(trueRestrict,true)) |
| 813 |
exit(103); /* not currently implemented */ |
| 814 |
ENDIFMACRO |
| 815 |
ENDIFMACRO |
| 816 |
IFMACRO(!ThName#RefinementFactor) |
| 817 |
int privateS = 1; |
| 818 |
ENDIFMACRO |
| 819 |
IFMACRO(ThName#RefinementFactor) |
| 820 |
int privateS = ThName#RefinementFactor; |
| 821 |
ENDIFMACRO |
| 822 |
IFMACRO(ThName#Overlap) |
| 823 |
assert(ThName#Overlap > 0); |
| 824 |
meshN privateBorder; |
| 825 |
buildOverlap(ThName, privateBorder, -111111, privateS, ThName#Overlap, intersection, privateDmesh#ThName#khi[0], P1, ThName#Comm, false); |
| 826 |
ENDIFMACRO |
| 827 |
IFMACRO(!ThName#Overlap) |
| 828 |
build(ThName, privateS, intersection, privateDmesh#ThName#khi[0], P1, ThName#Comm); |
| 829 |
ENDIFMACRO |
| 830 |
ENDIFMACRO |
| 831 |
ENDIFMACRO |
| 832 |
} |
| 833 |
EndMacro |
| 834 |
|
| 835 |
macro DmeshReconstruct(ThName) |
| 836 |
IFMACRO(!privateDmesh#ThName) |
| 837 |
NewMacro privateDmesh#ThName()privateDmesh#ThName EndMacro |
| 838 |
NewMacro privateDmesh#ThName#khi()privateDmesh#ThName#khiDef EndMacro |
| 839 |
NewMacro privateDmesh#ThName#intersection()privateDmesh#ThName#intersectionDef EndMacro |
| 840 |
real[int][int] privateDmesh#ThName#khi(2); |
| 841 |
real[int][int] privateDmesh#ThName#intersection; |
| 842 |
ENDIFMACRO |
| 843 |
IFMACRO(!ThName#Comm) |
| 844 |
NewMacro ThName#Comm()mpiCommWorld EndMacro |
| 845 |
ENDIFMACRO |
| 846 |
if(ThName#Comm) { |
| 847 |
IFMACRO(!dimension) |
| 848 |
NewMacro dimension()2 EndMacro |
| 849 |
ENDIFMACRO |
| 850 |
IFMACRO(!meshN) |
| 851 |
NewMacro meshN()mesh EndMacro |
| 852 |
NewMacro intN()int2d EndMacro |
| 853 |
ENDIFMACRO |
| 854 |
int[int] neighbors; |
| 855 |
{ |
| 856 |
real[int] bb(2 * dimension); |
| 857 |
boundingbox(ThName, bb); |
| 858 |
real[int] bbAll(2 * dimension * mpiSize(ThName#Comm)); |
| 859 |
mpiAllgather(bb, bbAll, ThName#Comm); |
| 860 |
real hmax; |
| 861 |
{ |
| 862 |
real tmp = ThName.hmax; |
| 863 |
mpiAllReduce(tmp, hmax, ThName#Comm, mpiMAX); |
| 864 |
} |
| 865 |
int between = 0; |
| 866 |
int size = mpiSize(ThName#Comm); |
| 867 |
int rank = mpiRank(ThName#Comm); |
| 868 |
for(int i = 0; i < size; ++i) { |
| 869 |
if(i != rank && |
| 870 |
IFMACRO(dimension,2) |
| 871 |
!(bbAll[1 + 4 * i] < bb[0] - hmax |
| 872 |
|| bbAll[0 + 4 * i] > bb[1] + hmax |
| 873 |
|| bbAll[3 + 4 * i] < bb[2] - hmax |
| 874 |
|| bbAll[2 + 4 * i] > bb[3] + hmax) |
| 875 |
ENDIFMACRO |
| 876 |
IFMACRO(dimension,3) |
| 877 |
!(bbAll[1 + 6 * i] < bb[0] - hmax |
| 878 |
|| bbAll[0 + 6 * i] > bb[1] + hmax |
| 879 |
|| bbAll[3 + 6 * i] < bb[2] - hmax |
| 880 |
|| bbAll[2 + 6 * i] > bb[3] + hmax |
| 881 |
|| bbAll[5 + 6 * i] < bb[4] - hmax |
| 882 |
|| bbAll[4 + 6 * i] > bb[5] + hmax) |
| 883 |
ENDIFMACRO |
| 884 |
) { |
| 885 |
neighbors.resize(neighbors.n + 1); |
| 886 |
neighbors[neighbors.n - 1] = i; |
| 887 |
} |
| 888 |
} |
| 889 |
} |
| 890 |
DmeshReconstructWithNeighbors(ThName, neighbors) |
| 891 |
} |
| 892 |
EndMacro |
| 893 |
macro DmeshReconstructWithNeighbors(ThName, neighborsName) |
| 894 |
IFMACRO(!privateDmesh#ThName) |
| 895 |
NewMacro privateDmesh#ThName()privateDmesh#ThName EndMacro |
| 896 |
NewMacro privateDmesh#ThName#khi()privateDmesh#ThName#khiDef EndMacro |
| 897 |
NewMacro privateDmesh#ThName#intersection()privateDmesh#ThName#intersectionDef EndMacro |
| 898 |
real[int][int] privateDmesh#ThName#khi(2); |
| 899 |
real[int][int] privateDmesh#ThName#intersection; |
| 900 |
ENDIFMACRO |
| 901 |
{ |
| 902 |
IFMACRO(!ThName#Comm) |
| 903 |
NewMacro ThName#Comm()mpiCommWorld EndMacro |
| 904 |
ENDIFMACRO |
| 905 |
real[int] part; |
| 906 |
{ |
| 907 |
if(verbosity > 0) |
| 908 |
mpiBarrier(ThName#Comm); |
| 909 |
real timerReconstruction = mpiWtime(); |
| 910 |
varf vG(uPrivate, vPrivate) = on(labels(ThName), uPrivate = 1.0); |
| 911 |
fespace VhGammaPrivate(ThName, P1); |
| 912 |
VhGammaPrivate gamma; |
| 913 |
gamma[] = vG(0, VhGammaPrivate, tgv = -1); |
| 914 |
meshN[int] ThTab(neighborsName.n + 2); |
| 915 |
neighborsName.sort; |
| 916 |
int between = 0; |
| 917 |
int rank = mpiRank(ThName#Comm); |
| 918 |
for(int i = 0; i < neighborsName.n; ++i) |
| 919 |
if(neighborsName[i] > rank) { |
| 920 |
between = i; |
| 921 |
break; |
| 922 |
} |
| 923 |
if(neighborsName.n) |
| 924 |
if(neighborsName[neighborsName.n - 1] < rank) |
| 925 |
between = neighborsName.n; |
| 926 |
mpiRequest[int] rqRecv(neighborsName.n); |
| 927 |
for[i, value : neighborsName] |
| 928 |
Irecv(processor(value, ThName#Comm, rqRecv[i]), ThTab[i + (i >= between)]); |
| 929 |
IFMACRO(!ThName#Overlap) |
| 930 |
ThTab[between] = trunc(ThName, gamma > 0.01, label = -111112); |
| 931 |
ENDIFMACRO |
| 932 |
IFMACRO(ThName#Overlap) |
| 933 |
ThTab[between] = ThName; |
| 934 |
ENDIFMACRO |
| 935 |
mpiRequest[int] rqSend(neighborsName.n); |
| 936 |
for[i, value : neighborsName] |
| 937 |
IFMACRO(!ThName#Overlap) |
| 938 |
Isend(processor(value, ThName#Comm, rqSend[i]), ThTab[between]); |
| 939 |
ENDIFMACRO |
| 940 |
IFMACRO(ThName#Overlap) |
| 941 |
Isend(processor(value, ThName#Comm, rqSend[i]), ThName); |
| 942 |
ENDIFMACRO |
| 943 |
IFMACRO(!ThName#Overlap) |
| 944 |
ThTab[neighborsName.n + 1] = trunc(ThName, gamma < 0.01, label = -111112); |
| 945 |
ENDIFMACRO |
| 946 |
mpiWaitAll(rqRecv); |
| 947 |
IFMACRO(dimension,3) |
| 948 |
ThName = gluemesh(ThTab); |
| 949 |
ThName = change(ThName, rmlfaces = -111112); |
| 950 |
ENDIFMACRO |
| 951 |
IFMACRO(dimension,2) |
| 952 |
ThName = gluemesh(ThTab, labtodel = -111112); |
| 953 |
ENDIFMACRO |
| 954 |
part.resize(ThName.nt); |
| 955 |
int m = 0; |
| 956 |
for(int i = 0; i < between; ++i) { |
| 957 |
part(m:m + ThTab[i].nt - 1) = neighborsName[i]; |
| 958 |
m += ThTab[i].nt; |
| 959 |
} |
| 960 |
part(m:m + ThTab[between].nt - 1) = rank; |
| 961 |
m += ThTab[between].nt; |
| 962 |
for(int i = between; i < neighborsName.n; ++i) { |
| 963 |
part(m:m + ThTab[i + 1].nt - 1) = neighborsName[i]; |
| 964 |
m += ThTab[i + 1].nt; |
| 965 |
} |
| 966 |
if(m != ThName.nt) |
| 967 |
part(m:ThName.nt - 1) = rank; |
| 968 |
mpiWaitAll(rqSend); |
| 969 |
if(verbosity > 0) { |
| 970 |
mpiBarrier(ThName#Comm); |
| 971 |
if(mpiRank(ThName#Comm) == 0) |
| 972 |
cout.scientific << " --- distributed mesh reconstructed (in " << mpiWtime() - timerReconstruction << ")" << endl; |
| 973 |
} |
| 974 |
} |
| 975 |
NewMacro privateBuildDmesh()1 EndMacro |
| 976 |
NewMacro privateReconstructDmesh()1 EndMacro |
| 977 |
int[int][int] intersection; |
| 978 |
NewMacro privateDmesh#ThTab()privateDmesh#ThName EndMacro |
| 979 |
NewMacro privateDmesh#ThTab#khi()privateDmesh#ThName#khiDef EndMacro |
| 980 |
NewMacro privateDmesh#ThTab#intersection()privateDmesh#ThName#intersectionDef EndMacro |
| 981 |
IFMACRO(ThName#N2O) |
| 982 |
NewMacro privateDmesh#N2O()ThName#N2O EndMacro |
| 983 |
ENDIFMACRO |
| 984 |
IFMACRO(ThName#Overlap) |
| 985 |
meshN ThBorder; |
| 986 |
buildOverlapWithPartitioning(ThName, ThBorder, part, -111111, 1, ThName#Overlap, intersection, privateDmesh#ThName#khi[0], P1, ThName#Comm, false); |
| 987 |
ENDIFMACRO |
| 988 |
IFMACRO(!ThName#Overlap) |
| 989 |
buildWithPartitioning(ThName, part, 1, intersection, privateDmesh#ThName#khi[0], P1, ThName#Comm); |
| 990 |
ENDIFMACRO |
| 991 |
} |
| 992 |
EndMacro |
| 993 |
macro DmeshInitialize(NewName) |
| 994 |
IFMACRO(!privateDmesh#NewName) |
| 995 |
NewMacro privateDmesh#NewName()privateDmesh#NewName EndMacro |
| 996 |
NewMacro privateDmesh#NewName#khi()privateDmesh#NewName#khiDef EndMacro |
| 997 |
NewMacro privateDmesh#NewName#intersection()privateDmesh#NewName#intersectionDef EndMacro |
| 998 |
real[int][int] privateDmesh#NewName#khi(2); |
| 999 |
real[int][int] privateDmesh#NewName#intersection; |
| 1000 |
ENDIFMACRO |
| 1001 |
EndMacro |
| 1002 |
macro DmeshCopy(OldName, NewName) |
| 1003 |
DmeshInitialize(NewName) |
| 1004 |
IFMACRO(privateDmesh#OldName) |
| 1005 |
NewName = OldName; |
| 1006 |
privateDmesh#NewName#khi[0].resize(privateDmesh#OldName#khi[0].n); |
| 1007 |
privateDmesh#NewName#khi[0] = privateDmesh#OldName#khi[0]; |
| 1008 |
privateDmesh#NewName#khi[1].resize(privateDmesh#OldName#khi[1].n); |
| 1009 |
privateDmesh#NewName#khi[1] = privateDmesh#OldName#khi[1]; |
| 1010 |
privateDmesh#NewName#intersection.resize(privateDmesh#OldName#intersection.n); |
| 1011 |
for(int i = 0; i < privateDmesh#NewName#intersection.n; ++i) { |
| 1012 |
privateDmesh#NewName#intersection[i].resize(privateDmesh#OldName#intersection[i].n); |
| 1013 |
privateDmesh#NewName#intersection[i] = privateDmesh#OldName#intersection[i]; |
| 1014 |
} |
| 1015 |
ENDIFMACRO |
| 1016 |
EndMacro |
| 1017 |
macro MatCreate(ThName, MatName, PkName) |
| 1018 |
IFMACRO(privateDmesh#ThName) |
| 1019 |
{ |
| 1020 |
IFMACRO(!meshN) |
| 1021 |
IFMACRO((dimension,3S)|(dimension,3L)) |
| 1022 |
if(mpirank == 0) cout << "Deprecated \"dimension\" value, switch to: \n NewMacro dimension()3 EndMacro\n NewMacro meshtype()S EndMacro (for meshS, or L for meshL)" << endl; |
| 1023 |
ENDIFMACRO |
| 1024 |
IFMACRO((dimension,3)|(dimension,3S)|(dimension,3L)) |
| 1025 |
IFMACRO(dimension,3S) |
| 1026 |
NewMacro meshtype()S EndMacro /* TODO FIXME: remove at some point (deprecated since July 2025) */ |
| 1027 |
ENDIFMACRO |
| 1028 |
IFMACRO(dimension,3L) |
| 1029 |
NewMacro meshtype()L EndMacro /* TODO FIXME: remove at some point (deprecated since July 2025) */ |
| 1030 |
ENDIFMACRO |
| 1031 |
IFMACRO(!meshtype) |
| 1032 |
NewMacro meshtype()V EndMacro |
| 1033 |
ENDIFMACRO |
| 1034 |
IFMACRO(meshtype,V) |
| 1035 |
NewMacro meshN()mesh3 EndMacro /* three-dimensional problem */ |
| 1036 |
NewMacro intN()int3d EndMacro /* three-dimensional integral */ |
| 1037 |
ENDIFMACRO |
| 1038 |
IFMACRO(meshtype,S) |
| 1039 |
NewMacro meshN()meshS EndMacro /* three-dimensional surface problem */ |
| 1040 |
NewMacro intN()int2d EndMacro /* two-dimensional integral */ |
| 1041 |
ENDIFMACRO |
| 1042 |
IFMACRO(meshtype,L) |
| 1043 |
NewMacro meshN()meshL EndMacro /* three-dimensional line problem */ |
| 1044 |
NewMacro intN()int1d EndMacro /* one-dimensional integral */ |
| 1045 |
ENDIFMACRO |
| 1046 |
ENDIFMACRO |
| 1047 |
IFMACRO(!meshN) |
| 1048 |
NewMacro meshN()mesh EndMacro /* two-dimensional problem */ |
| 1049 |
NewMacro intN()int2d EndMacro /* two-dimensional integral */ |
| 1050 |
ENDIFMACRO |
| 1051 |
ENDIFMACRO |
| 1052 |
IFMACRO(!ThName#Comm) |
| 1053 |
NewMacro ThName#Comm()mpiCommWorld EndMacro |
| 1054 |
ENDIFMACRO |
| 1055 |
IFMACRO(!privateCreateMatCheckDmesh) |
| 1056 |
if(ThName.nv != privateDmesh#ThName#khi[0].n || (privateDmesh#ThName#khi[1].n && ThName.nt != privateDmesh#ThName#khi[1].n)) { |
| 1057 |
DmeshCreate(ThName) |
| 1058 |
} |
| 1059 |
ENDIFMACRO |
| 1060 |
NewMacro privateCreateMat()1 EndMacro |
| 1061 |
int[int][int] intersection; |
| 1062 |
real[int][int] DTab(1); |
| 1063 |
meshN[int] ThTab(1); |
| 1064 |
ThTab[0] = ThName; |
| 1065 |
NewMacro privateDmesh#ThTab()privateDmesh#ThName EndMacro |
| 1066 |
NewMacro privateDmesh#ThTab#khi()privateDmesh#ThName#khiDef EndMacro |
| 1067 |
NewMacro privateDmesh#ThTab#intersection()privateDmesh#ThName#intersectionDef EndMacro |
| 1068 |
IFMACRO(!def) |
| 1069 |
NewMacro def(i)i EndMacro |
| 1070 |
ENDIFMACRO |
| 1071 |
IFMACRO(!init) |
| 1072 |
NewMacro init(i)i EndMacro |
| 1073 |
ENDIFMACRO |
| 1074 |
if(mpiSize(ThName#Comm) > 1) { |
| 1075 |
IFMACRO(ThName#N2O) |
| 1076 |
IFMACRO(ThName#Original) |
| 1077 |
IFMACRO(ThName#Restriction) |
| 1078 |
NewMacro privateDmesh#N2O()ThName#N2O EndMacro |
| 1079 |
NewMacro privateDmesh#Original()ThName#Original EndMacro |
| 1080 |
NewMacro privateDmesh#Restriction()ThName#Restriction EndMacro |
| 1081 |
ENDIFMACRO |
| 1082 |
ENDIFMACRO |
| 1083 |
ENDIFMACRO |
| 1084 |
IFMACRO(!ThName#PkPart) |
| 1085 |
NewMacro ThName#PkPart()PkName EndMacro |
| 1086 |
ENDIFMACRO |
| 1087 |
IFMACRO(ThName#CartesianPartitioning) |
| 1088 |
NewMacro privateDmesh#CartesianPartitioning() EndMacro |
| 1089 |
IFMACRO(!dimension) |
| 1090 |
NewMacro dimension()2 EndMacro |
| 1091 |
ENDIFMACRO |
| 1092 |
ENDIFMACRO |
| 1093 |
IFMACRO(ThName#PostProcessD) |
| 1094 |
NewMacro privateDmesh#PostProcessD(arg)ThName#PostProcessD(arg) EndMacro |
| 1095 |
IFMACRO(removeZeros,true) |
| 1096 |
exit(105); /* not currently implemented */ |
| 1097 |
ENDIFMACRO |
| 1098 |
IFMACRO(trueRestrict,true) |
| 1099 |
exit(105); /* not currently implemented */ |
| 1100 |
ENDIFMACRO |
| 1101 |
ENDIFMACRO |
| 1102 |
partitionPrivate(ThTab, privateCreateMat, privateCreateMat, privateCreateMat, privateCreateMat, privateCreateMat, mpiRank(ThName#Comm), mpiSize(ThName#Comm), 1, 1, 1, privateCreateMat, DTab, PkName, intersection, ThName#Comm, -111111, ThName#PkPart, def, init, 1) |
| 1103 |
} |
| 1104 |
else { |
| 1105 |
fespace WhGlobalPrivate(ThName, PkName); |
| 1106 |
DTab[0].resize(WhGlobalPrivate.ndof); |
| 1107 |
DTab[0] = 1; |
| 1108 |
intersection.resize(0); |
| 1109 |
IFMACRO(ThName#N2O) |
| 1110 |
IFMACRO(ThName#Original) |
| 1111 |
IFMACRO(ThName#Restriction) |
| 1112 |
ThName#Restriction.resize(WhGlobalPrivate.ndof); |
| 1113 |
ThName#Restriction = 0:WhGlobalPrivate.ndof - 1; |
| 1114 |
ENDIFMACRO |
| 1115 |
ENDIFMACRO |
| 1116 |
ENDIFMACRO |
| 1117 |
} |
| 1118 |
IFMACRO(!privateCreatePartition) |
| 1119 |
constructor(MatName, DTab[0].n, intersection, DTab[0], communicator = ThName#Comm); |
| 1120 |
ENDIFMACRO |
| 1121 |
IFMACRO(privateCreatePartition) |
| 1122 |
privateCreatePartition.resize(DTab[0].n); |
| 1123 |
privateCreatePartition = DTab[0]; |
| 1124 |
ENDIFMACRO |
| 1125 |
} |
| 1126 |
ENDIFMACRO |
| 1127 |
IFMACRO(!privateDmesh#ThName) |
| 1128 |
DmeshCreate(ThName) |
| 1129 |
{ |
| 1130 |
IFMACRO(!meshN) |
| 1131 |
IFMACRO((dimension,3S)|(dimension,3L)) |
| 1132 |
if(mpirank == 0) cout << "Deprecated \"dimension\" value, switch to: \n NewMacro dimension()3 EndMacro\n NewMacro meshtype()S EndMacro (for meshS, or L for meshL)" << endl; |
| 1133 |
ENDIFMACRO |
| 1134 |
IFMACRO((dimension,3)|(dimension,3S)|(dimension,3L)) |
| 1135 |
IFMACRO(dimension,3S) |
| 1136 |
NewMacro meshtype()S EndMacro /* TODO FIXME: remove at some point (deprecated since July 2025) */ |
| 1137 |
ENDIFMACRO |
| 1138 |
IFMACRO(dimension,3L) |
| 1139 |
NewMacro meshtype()L EndMacro /* TODO FIXME: remove at some point (deprecated since July 2025) */ |
| 1140 |
ENDIFMACRO |
| 1141 |
IFMACRO(!meshtype) |
| 1142 |
NewMacro meshtype()V EndMacro |
| 1143 |
ENDIFMACRO |
| 1144 |
IFMACRO(meshtype,V) |
| 1145 |
NewMacro meshN()mesh3 EndMacro /* three-dimensional problem */ |
| 1146 |
NewMacro intN()int3d EndMacro /* three-dimensional integral */ |
| 1147 |
ENDIFMACRO |
| 1148 |
IFMACRO(meshtype,S) |
| 1149 |
NewMacro meshN()meshS EndMacro /* three-dimensional surface problem */ |
| 1150 |
NewMacro intN()int2d EndMacro /* two-dimensional integral */ |
| 1151 |
ENDIFMACRO |
| 1152 |
IFMACRO(meshtype,L) |
| 1153 |
NewMacro meshN()meshL EndMacro /* three-dimensional line problem */ |
| 1154 |
NewMacro intN()int1d EndMacro /* one-dimensional integral */ |
| 1155 |
ENDIFMACRO |
| 1156 |
ENDIFMACRO |
| 1157 |
IFMACRO(!meshN) |
| 1158 |
NewMacro meshN()mesh EndMacro /* two-dimensional problem */ |
| 1159 |
NewMacro intN()int2d EndMacro /* two-dimensional integral */ |
| 1160 |
ENDIFMACRO |
| 1161 |
ENDIFMACRO |
| 1162 |
NewMacro privateCreateMatCheckDmesh()1 EndMacro |
| 1163 |
MatCreate(ThName, MatName, PkName) |
| 1164 |
} |
| 1165 |
ENDIFMACRO |
| 1166 |
EndMacro |
| 1167 |
|
| 1168 |
macro PartitionCreate(ThName, PartName, PkName) |
| 1169 |
IFMACRO(!privateDmesh#ThName) |
| 1170 |
DmeshCreate(ThName) |
| 1171 |
ENDIFMACRO |
| 1172 |
{ |
| 1173 |
NewMacro privateCreateMatCheckDmesh()1 EndMacro |
| 1174 |
NewMacro privateCreatePartition()PartName EndMacro |
| 1175 |
MatCreate(ThName, privateCreatePartition, PkName) |
| 1176 |
} |
| 1177 |
EndMacro |
| 1178 |
|
| 1179 |
macro buildOverlapEdgePeriodicRecursive(Th, ThBorder, fakeInterface, s, overlap, level, prolongation, intersection, DTab, P, comm, excluded, PkPart, defPart, initPart, labPeriodic, userPartitioning, bs) { |
| 1180 |
IFMACRO(!def) |
| 1181 |
NewMacro def(i)i EndMacro |
| 1182 |
ENDIFMACRO |
| 1183 |
IFMACRO(!init) |
| 1184 |
NewMacro init(i)i EndMacro |
| 1185 |
ENDIFMACRO |
| 1186 |
Th.resize(level); |
| 1187 |
ThBorder.resize(level); |
| 1188 |
prolongation.resize(level - 1); |
| 1189 |
real timerPartition = mpiWtime(); |
| 1190 |
if(mpiSize(comm) > 1 && !excluded) { |
| 1191 |
meshN ThGlobal = Th[level - 1]; |
| 1192 |
fespace PhGlobalPrivate(ThGlobal, P0); |
| 1193 |
IFMACRO(privateDmesh#Periodic) |
| 1194 |
fespace VhGlobalPrivate(ThGlobal, P1, periodic = privateDmesh#Periodic); |
| 1195 |
ENDIFMACRO |
| 1196 |
IFMACRO(!privateDmesh#Periodic) |
| 1197 |
fespace VhGlobalPrivate(ThGlobal, P1); |
| 1198 |
ENDIFMACRO |
| 1199 |
PhGlobalPrivate partGlobal; |
| 1200 |
IFMACRO(!privateReconstructDmesh) |
| 1201 |
IFMACRO(privateDmesh#CartesianPartitioning) |
| 1202 |
{ |
| 1203 |
real[int] bb(2 * dimension); |
| 1204 |
boundingbox(ThGlobal, bb); |
| 1205 |
PhGlobalPrivate xx = x / (bb[1] - bb[0]), yy = y / (bb[3] - bb[2]) |
| 1206 |
IFMACRO(dimension,2) |
| 1207 |
; |
| 1208 |
int i = int(sqrt(mpiSize(comm))); |
| 1209 |
while(mpiSize(comm) % i != 0) |
| 1210 |
--i; |
| 1211 |
int j = mpiSize(comm) / i; |
| 1212 |
partGlobal = int(j * xx) + int(i * yy) * j; |
| 1213 |
ENDIFMACRO |
| 1214 |
IFMACRO(dimension,3) |
| 1215 |
, zz = z / (bb[5] - bb[4]); |
| 1216 |
int i = int(mpiSize(comm)^(0.333333333333333)); |
| 1217 |
while(mpiSize(comm) % i != 0) |
| 1218 |
--i; |
| 1219 |
real p = mpiSize(comm) / i; |
| 1220 |
int j = int(sqrt(p)); |
| 1221 |
while(p % j != 0) |
| 1222 |
--j; |
| 1223 |
int k = int(p / j); |
| 1224 |
partGlobal = int(i * zz) * k * j + int(j * yy) * k + int(k * xx); |
| 1225 |
ENDIFMACRO |
| 1226 |
} |
| 1227 |
ENDIFMACRO |
| 1228 |
IFMACRO(!privateDmesh#CartesianPartitioning) |
| 1229 |
if(userPartitioning.n != PhGlobalPrivate.ndof || labPeriodic.n > 0) { |
| 1230 |
timerPartition = mpiWtime(); |
| 1231 |
meshN ThGlobalPeriodic; |
| 1232 |
int[int] n2oPeriodic; |
| 1233 |
if(labPeriodic.n > 0) { |
| 1234 |
VhGlobalPrivate marker; |
| 1235 |
varf vMarker(uPrivate, vPrivate) = on(labPeriodic, uPrivate = 1.0); |
| 1236 |
marker[] = vMarker(0, VhGlobalPrivate, tgv = -1); |
| 1237 |
PhGlobalPrivate partPeriodic = marker > 0.1; |
| 1238 |
while(1) { |
| 1239 |
AddLayers(VhGlobalPrivate, partPeriodic[], 1 + overlap, marker[]); |
| 1240 |
partPeriodic = marker > 0.001; |
| 1241 |
ThGlobalPeriodic = trunc(ThGlobal, partPeriodic < 0.999, new2old = n2oPeriodic); |
| 1242 |
if(ThGlobal.nt / real(ThGlobalPeriodic.nt) > mpiSize(comm) / real(mpiSize(comm) - 1)) |
| 1243 |
break; |
| 1244 |
} |
| 1245 |
if(mpiRank(comm) == 0 && verbosity > 0) |
| 1246 |
cout.scientific << " --- part of the global mesh with periodic BC has " << ThGlobal.nt - ThGlobalPeriodic.nt << " elements, rest of the global mesh has " << ThGlobalPeriodic.nt << " elements" << endl; |
| 1247 |
} |
| 1248 |
if(mpiRank(comm) == 0) { |
| 1249 |
if(verbosity > 0) |
| 1250 |
cout.scientific << " --- global mesh of " << ThGlobal.nt << " elements (prior to refinement) partitioned with " << Stringification(partitioner); |
| 1251 |
if(labPeriodic.n > 0) { |
| 1252 |
fespace PhPeriodicPrivate(ThGlobalPeriodic, P0); |
| 1253 |
PhPeriodicPrivate partPeriodic; |
| 1254 |
if(mpiSize(comm) > 2) { |
| 1255 |
partitionerSeq(partPeriodic[], ThGlobalPeriodic, mpiSize(comm) - 1); |
| 1256 |
partPeriodic[] += 1.0; |
| 1257 |
} |
| 1258 |
else |
| 1259 |
partPeriodic[] = 1.0; |
| 1260 |
partGlobal[](n2oPeriodic) = partPeriodic[]; |
| 1261 |
} |
| 1262 |
else { |
| 1263 |
partitionerSeq(partGlobal[], ThGlobal, mpiSize(comm)); |
| 1264 |
} |
| 1265 |
} |
| 1266 |
if(labPeriodic.n > 0 && Stringification(partitioner) != "metis" && Stringification(partitioner) != "scotch") { |
| 1267 |
fespace PhPeriodicPrivate(ThGlobalPeriodic, P0); |
| 1268 |
PhPeriodicPrivate partPeriodic; |
| 1269 |
if(mpiSize(comm) > 2) { |
| 1270 |
partitionerPar(partPeriodic[], ThGlobalPeriodic, comm, mpiSize(comm) - 1); |
| 1271 |
partPeriodic[] += 1.0; |
| 1272 |
} |
| 1273 |
else |
| 1274 |
partPeriodic[] = 1.0; |
| 1275 |
partGlobal[](n2oPeriodic) = partPeriodic[]; |
| 1276 |
} |
| 1277 |
else |
| 1278 |
partitionerPar(partGlobal[], ThGlobal, comm, mpiSize(comm)); |
| 1279 |
if(mpiRank(comm) == 0 && verbosity > 0) |
| 1280 |
cout.scientific << " (in " << mpiWtime() - timerPartition << ")" << endl; |
| 1281 |
timerPartition = mpiWtime(); |
| 1282 |
} |
| 1283 |
else { |
| 1284 |
partGlobal[] = userPartitioning; |
| 1285 |
} |
| 1286 |
ENDIFMACRO |
| 1287 |
ENDIFMACRO |
| 1288 |
IFMACRO(privateReconstructDmesh) |
| 1289 |
partGlobal[] = userPartitioning; |
| 1290 |
ENDIFMACRO |
| 1291 |
IFMACRO(!trueRestrict) |
| 1292 |
bool trueRestrict = usedARGV("-true_restrict") != -1; |
| 1293 |
ENDIFMACRO |
| 1294 |
IFMACRO(!removeZeros) |
| 1295 |
bool removeZeros = trueRestrict && overlap == 1 && usedARGV("-remove_zeros") != -1; |
| 1296 |
ENDIFMACRO |
| 1297 |
if(verbosity > 0) { |
| 1298 |
mpiBarrier(comm); |
| 1299 |
timerPartition = mpiWtime(); |
| 1300 |
} |
| 1301 |
IFMACRO(privateBuildDmesh) |
| 1302 |
NewMacro defP1(i)i EndMacro |
| 1303 |
NewMacro initP1(i)i EndMacro |
| 1304 |
partitionPrivate(Th, ThBorder, ThGlobal, PhGlobalPrivate, VhGlobalPrivate, partGlobal, mpiRank(comm), mpiSize(comm), s, overlap, level, prolongation, DTab, P, intersection, comm, fakeInterface, PkPart, defP1, initP1, bs) |
| 1305 |
ENDIFMACRO |
| 1306 |
IFMACRO(!privateBuildDmesh) |
| 1307 |
partitionPrivate(Th, ThBorder, ThGlobal, PhGlobalPrivate, VhGlobalPrivate, partGlobal, mpiRank(comm), mpiSize(comm), s, overlap, level, prolongation, DTab, P, intersection, comm, fakeInterface, PkPart, defPart, initPart, bs) |
| 1308 |
ENDIFMACRO |
| 1309 |
} |
| 1310 |
else if(mpiSize(comm) == 1) { |
| 1311 |
for(int i = level - 1; i > 0; --i) { |
| 1312 |
Th[i - 1] = trunc(Th[i], 1, split = s); |
| 1313 |
fespace WhLocalRefinedPrivate(Th[i - 1], P); |
| 1314 |
fespace WhLocalCoarsePrivate(Th[i], P); |
| 1315 |
prolongation[i - 1] = interpolate(WhLocalRefinedPrivate, WhLocalCoarsePrivate); |
| 1316 |
DTab[i].resize(WhLocalCoarsePrivate.ndof); |
| 1317 |
DTab[i] = 1.0; |
| 1318 |
} |
| 1319 |
if(level == 1) { |
| 1320 |
IFMACRO(privateBuildDmesh) |
| 1321 |
IFMACRO(privateDmesh#N2O) |
| 1322 |
if(s > 1) |
| 1323 |
Th[0] = trunc(Th[0], 1, split = s, new2old = privateDmesh#N2O); |
| 1324 |
else { |
| 1325 |
privateDmesh#N2O.resize(Th[0].nt); |
| 1326 |
privateDmesh#N2O = 0:Th[0].nt-1; |
| 1327 |
} |
| 1328 |
ENDIFMACRO |
| 1329 |
IFMACRO(!privateDmesh#N2O) |
| 1330 |
if(s > 1) |
| 1331 |
Th[0] = trunc(Th[0], 1, split = s); |
| 1332 |
ENDIFMACRO |
| 1333 |
ENDIFMACRO |
| 1334 |
IFMACRO(!privateBuildDmesh) |
| 1335 |
if(s > 1) |
| 1336 |
Th[0] = trunc(Th[0], 1, split = s); |
| 1337 |
ENDIFMACRO |
| 1338 |
} |
| 1339 |
fespace WhLocalPrivate(Th[0], P); |
| 1340 |
DTab[0].resize(WhLocalPrivate.ndof); |
| 1341 |
DTab[0] = 1.0; |
| 1342 |
} |
| 1343 |
if(verbosity > 0) { |
| 1344 |
mpiBarrier(comm); |
| 1345 |
if(mpiRank(comm) == 0) |
| 1346 |
cout.scientific << " --- partition of unity built (in " << mpiWtime() - timerPartition << ")" << endl; |
| 1347 |
} |
| 1348 |
}// EOM |
| 1349 |
|
| 1350 |
macro buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, PkPart, defPart, initPart, labPeriodic, userPartitioning, bs) { |
| 1351 |
meshN[int] ThTab(1); |
| 1352 |
meshN[int] ThBorderTab(1); |
| 1353 |
real[int][int] DTab(1); |
| 1354 |
ThTab[0] = Th; |
| 1355 |
matrix[int] prolongation(0); |
| 1356 |
buildOverlapEdgePeriodicRecursive(ThTab, ThBorderTab, fakeInterface, s, overlap, 1, prolongation, intersection, DTab, P, comm, excluded, PkPart, defPart, initPart, labPeriodic, userPartitioning, bs) |
| 1357 |
Th = ThTab[0]; |
| 1358 |
ThBorder = ThBorderTab[0]; |
| 1359 |
D.resize(DTab[0].n); |
| 1360 |
D = DTab[0]; |
| 1361 |
}// EOM |
| 1362 |
|
| 1363 |
IFMACRO(vectorialfe) |
| 1364 |
macro buildOverlapEdgeRecursive(Th, ThBorder, fakeInterface, s, overlap, level, prolongation, intersection, D, P, comm, excluded, PkPart, defPart, initPart, bs) { |
| 1365 |
int[int] emptyArray(0); |
| 1366 |
real[int] emptyRealArray(0); |
| 1367 |
buildOverlapEdgePeriodicRecursive(Th, ThBorder, fakeInterface, s, overlap, level, prolongation, intersection, D, P, comm, excluded, PkPart, defPart, initPart, emptyArray, emptyRealArray, bs) |
| 1368 |
}// EOM |
| 1369 |
macro buildOverlapEdge(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, PkPart, defPart, initPart, bs) { |
| 1370 |
int[int] emptyArray(0); |
| 1371 |
real[int] emptyRealArray(0); |
| 1372 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, PkPart, defPart, initPart, emptyArray, emptyRealArray, bs) |
| 1373 |
}// EOM |
| 1374 |
macro buildOverlapEdgeWithPartitioning(Th, ThBorder, part, fakeInterface, s, overlap, intersection, D, P, comm, excluded, PkPart, defPart, initPart, bs) { |
| 1375 |
int[int] emptyArray(0); |
| 1376 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, PkPart, defPart, initPart, emptyArray, part, bs) |
| 1377 |
}// EOM |
| 1378 |
macro buildOverlapWithPartitioning(Th, ThBorder, part, fakeInterface, s, overlap, intersection, D, P, comm, excluded, bs) { |
| 1379 |
int[int] emptyArray(0); |
| 1380 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, P, def, init, emptyArray, part, bs) |
| 1381 |
}// EOM |
| 1382 |
macro buildOverlap(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, bs) { |
| 1383 |
int[int] emptyArray(0); |
| 1384 |
real[int] emptyRealArray(0); |
| 1385 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, P, def, init, emptyArray, emptyRealArray, bs) |
| 1386 |
}// EOM |
| 1387 |
macro buildOverlapPeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, labPeriodic, bs) { |
| 1388 |
real[int] emptyArray(0); |
| 1389 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, P, def, init, labPeriodic, emptyArray, bs) |
| 1390 |
}// EOM |
| 1391 |
macro buildEdgeWithPartitioning(Th, part, s, intersection, D, P, comm, PkPart, defPart, initPart, bs) { |
| 1392 |
int[int] emptyArray(0); |
| 1393 |
meshN ThBorder; |
| 1394 |
int fakeInterface = -111111; |
| 1395 |
int overlap = 1; |
| 1396 |
bool excluded = false; |
| 1397 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, intersection, D, P, comm, excluded, PkPart, defPart, initPart, emptyArray, part, bs) |
| 1398 |
}// EOM |
| 1399 |
macro buildWithPartitioning(Th, part, s, intersection, D, P, comm, bs) { |
| 1400 |
int[int] emptyArray(0); |
| 1401 |
meshN ThBorder; |
| 1402 |
int fakeInterface = -111111; |
| 1403 |
int overlap = 1; |
| 1404 |
bool excluded = false; |
| 1405 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, P, def, init, emptyArray, part, bs) |
| 1406 |
}// EOM |
| 1407 |
macro build(Th, s, intersection, D, P, comm, bs) { |
| 1408 |
int[int] emptyArray(0); |
| 1409 |
real[int] emptyRealArray(0); |
| 1410 |
meshN ThBorder; |
| 1411 |
int fakeInterface = -111111; |
| 1412 |
int overlap = 1; |
| 1413 |
bool excluded = false; |
| 1414 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, P, def, init, emptyArray, emptyRealArray, bs) |
| 1415 |
}// EOM |
| 1416 |
macro buildPeriodic(Th, s, intersection, D, P, comm, labPeriodic, bs) { |
| 1417 |
int[int] emptyArray(0); |
| 1418 |
real[int] emptyRealArray(0); |
| 1419 |
meshN ThBorder; |
| 1420 |
int fakeInterface = -111111; |
| 1421 |
int overlap = 1; |
| 1422 |
bool excluded = false; |
| 1423 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, P, def, init, labPeriodic, emptyRealArray, bs) |
| 1424 |
}// EOM |
| 1425 |
macro buildMinimalist(Th, intersection, D, P, bs) { |
| 1426 |
int[int] emptyArray(0); |
| 1427 |
real[int] emptyRealArray(0); |
| 1428 |
meshN ThBorder; |
| 1429 |
int fakeInterface = -111111; |
| 1430 |
int overlap = 1; |
| 1431 |
bool excluded = false; |
| 1432 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, 1, overlap, intersection, D, P, mpiCommWorld, excluded, P, def, init, emptyArray, emptyRealArray, bs) |
| 1433 |
}// EOM |
| 1434 |
macro buildRecursive(Th, s, level, prolongation, intersectionMat, DTab, P, comm, bsMat) { |
| 1435 |
int[int] emptyArray(0); |
| 1436 |
real[int] emptyRealArray(0); |
| 1437 |
meshN[int] ThBorderTab(level); |
| 1438 |
DTab.resize(level); |
| 1439 |
buildOverlapEdgePeriodicRecursive(Th, ThBorderTab, -111111, s, 1, level, prolongation, intersectionMat, DTab, P, comm, false, P, def, init, emptyArray, emptyRealArray, bsMat) |
| 1440 |
}// EOM |
| 1441 |
macro buildMatRecursive(Th, s, nlevel, prolongation, A, P, comm, bsMat) { |
| 1442 |
int[int] emptyArray(0); |
| 1443 |
real[int] emptyRealArray(0); |
| 1444 |
meshN[int] ThBorderTab(nlevel); |
| 1445 |
int[int][int] intersectionMat; |
| 1446 |
real[int][int] DTab(nlevel); |
| 1447 |
buildOverlapEdgePeriodicRecursive(Th, ThBorderTab, -111111, s, 1, nlevel, prolongation, intersectionMat, DTab, P, comm, false, P, def, init, emptyArray, emptyRealArray, bsMat) |
| 1448 |
for(int i = 0; i < nlevel; ++i) |
| 1449 |
constructor(A[i], DTab[i].n, intersectionMat, DTab[i], bs = bsMat, communicator = comm, level = i); |
| 1450 |
}// EOM |
| 1451 |
macro buildMatEdgeRecursive(Th, s, nlevel, prolongation, A, P, comm, PkPart, defPart, initPart, bsMat) { |
| 1452 |
int[int] emptyArray(0); |
| 1453 |
real[int] emptyRealArray(0); |
| 1454 |
meshN[int] ThBorderTab(nlevel); |
| 1455 |
int[int][int] intersectionMat; |
| 1456 |
real[int][int] DTab(nlevel); |
| 1457 |
buildOverlapEdgePeriodicRecursive(Th, ThBorderTab, -111111, s, 1, nlevel, prolongation, intersectionMat, DTab, P, comm, false, PkPart, defPart, initPart, emptyArray, emptyRealArray, bsMat) |
| 1458 |
for(int i = 0; i < nlevel; ++i) |
| 1459 |
constructor(A[i], DTab[i].n, intersectionMat, DTab[i], bs = bsMat, communicator = comm, level = i); |
| 1460 |
}// EOM |
| 1461 |
macro buildMatEdgeRecursiveWithPartitioning(Th, part, s, nlevel, prolongation, A, P, comm, PkPart, defPart, initPart, bsMat) { |
| 1462 |
int[int] emptyArray(0); |
| 1463 |
meshN[int] ThBorderTab(nlevel); |
| 1464 |
int[int][int] intersectionMat; |
| 1465 |
real[int][int] DTab(nlevel); |
| 1466 |
buildOverlapEdgePeriodicRecursive(Th, ThBorderTab, -111111, s, 1, nlevel, prolongation, intersectionMat, DTab, P, comm, false, PkPart, defPart, initPart, emptyArray, part, bsMat) |
| 1467 |
for(int i = 0; i < nlevel; ++i) |
| 1468 |
constructor(A[i], DTab[i].n, intersectionMat, DTab[i], bs = bsMat, communicator = comm, level = i); |
| 1469 |
}// EOM |
| 1470 |
macro buildMatEdgeWithPartitioning(Th, part, s, A, P, comm, PkPart, defPart, initPart, bsMat) { |
| 1471 |
real[int] DMat; |
| 1472 |
int[int][int] intersectionMat; |
| 1473 |
buildEdgeWithPartitioning(Th, part, s, intersectionMat, DMat, P, comm, PkPart, defPart, initPart, bsMat) |
| 1474 |
constructor(A, DMat.n, intersectionMat, DMat, bs = bsMat, communicator = comm); |
| 1475 |
}// EOM |
| 1476 |
macro buildMatWithPartitioning(Th, part, s, A, P, comm, bsMat) { |
| 1477 |
real[int] DMat; |
| 1478 |
int[int][int] intersectionMat; |
| 1479 |
buildWithPartitioning(Th, part, s, intersectionMat, DMat, P, comm, bsMat) |
| 1480 |
constructor(A, DMat.n, intersectionMat, DMat, bs = bsMat, communicator = comm); |
| 1481 |
}// EOM |
| 1482 |
macro buildMat(Th, s, A, P, comm, bsMat) { |
| 1483 |
real[int] DMat; |
| 1484 |
int[int][int] intersectionMat; |
| 1485 |
build(Th, s, intersectionMat, DMat, P, comm, bsMat) |
| 1486 |
constructor(A, DMat.n, intersectionMat, DMat, bs = bsMat, communicator = comm); |
| 1487 |
}// EOM |
| 1488 |
macro buildMatPeriodic(Th, s, A, P, comm, labPeriodic, bsMat) { |
| 1489 |
real[int] DMat; |
| 1490 |
int[int][int] intersectionMat; |
| 1491 |
buildPeriodic(Th, s, intersectionMat, DMat, P, comm, labPeriodic, bsMat) |
| 1492 |
constructor(A, DMat.n, intersectionMat, DMat, bs = bsMat, communicator = comm); |
| 1493 |
}// EOM |
| 1494 |
macro buildMatMinimalist(Th, A, P, bsMat) { |
| 1495 |
real[int] DMat; |
| 1496 |
int[int][int] intersectionMat; |
| 1497 |
buildMinimalist(Th, intersectionMat, DMat, P, bsMat) |
| 1498 |
constructor(A, DMat.n, intersectionMat, DMat, bs = bsMat, communicator = comm); |
| 1499 |
}// EOM |
| 1500 |
ENDIFMACRO |
| 1501 |
IFMACRO(!vectorialfe) |
| 1502 |
macro buildOverlapEdgeRecursive(Th, ThBorder, fakeInterface, s, overlap, level, prolongation, intersection, D, P, comm, excluded, PkPart, defPart, initPart) { |
| 1503 |
int[int] emptyArray(0); |
| 1504 |
real[int] emptyRealArray(0); |
| 1505 |
buildOverlapEdgePeriodicRecursive(Th, ThBorder, fakeInterface, s, overlap, level, prolongation, intersection, D, P, comm, excluded, PkPart, defPart, initPart, emptyArray, emptyRealArray, 1) |
| 1506 |
}// EOM |
| 1507 |
macro buildOverlapEdge(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, PkPart, defPart, initPart) { |
| 1508 |
int[int] emptyArray(0); |
| 1509 |
real[int] emptyRealArray(0); |
| 1510 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, PkPart, defPart, initPart, emptyArray, emptyRealArray, 1) |
| 1511 |
}// EOM |
| 1512 |
macro buildOverlapEdgeWithPartitioning(Th, ThBorder, part, fakeInterface, s, overlap, intersection, D, P, comm, excluded, PkPart, defPart, initPart) { |
| 1513 |
int[int] emptyArray(0); |
| 1514 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, PkPart, defPart, initPart, emptyArray, part, 1) |
| 1515 |
}// EOM |
| 1516 |
macro buildOverlapWithPartitioning(Th, ThBorder, part, fakeInterface, s, overlap, intersection, D, P, comm, excluded) { |
| 1517 |
int[int] emptyArray(0); |
| 1518 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, P, def, init, emptyArray, part, 1) |
| 1519 |
}// EOM |
| 1520 |
macro buildOverlap(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded) { |
| 1521 |
int[int] emptyArray(0); |
| 1522 |
real[int] emptyRealArray(0); |
| 1523 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, P, def, init, emptyArray, emptyRealArray, 1) |
| 1524 |
}// EOM |
| 1525 |
macro buildOverlapPeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, labPeriodic) { |
| 1526 |
real[int] emptyArray(0); |
| 1527 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, P, def, init, labPeriodic, emptyArray, 1) |
| 1528 |
}// EOM |
| 1529 |
macro buildEdgeWithPartitioning(Th, part, s, intersection, D, P, comm, PkPart, defPart, initPart) { |
| 1530 |
int[int] emptyArray(0); |
| 1531 |
meshN ThBorder; |
| 1532 |
int fakeInterface = -111111; |
| 1533 |
int overlap = 1; |
| 1534 |
bool excluded = false; |
| 1535 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, PkPart, defPart, initPart, emptyArray, part, 1) |
| 1536 |
}// EOM |
| 1537 |
macro buildWithPartitioning(Th, part, s, intersection, D, P, comm) { |
| 1538 |
int[int] emptyArray(0); |
| 1539 |
meshN ThBorder; |
| 1540 |
int fakeInterface = -111111; |
| 1541 |
int overlap = 1; |
| 1542 |
bool excluded = false; |
| 1543 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, P, def, init, emptyArray, part, 1) |
| 1544 |
}// EOM |
| 1545 |
macro build(Th, s, intersection, D, P, comm) { |
| 1546 |
int[int] emptyArray(0); |
| 1547 |
real[int] emptyRealArray(0); |
| 1548 |
meshN ThBorder; |
| 1549 |
int fakeInterface = -111111; |
| 1550 |
int overlap = 1; |
| 1551 |
bool excluded = false; |
| 1552 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, P, def, init, emptyArray, emptyRealArray, 1) |
| 1553 |
}// EOM |
| 1554 |
macro buildPeriodic(Th, s, intersection, D, P, comm, labPeriodic) { |
| 1555 |
int[int] emptyArray(0); |
| 1556 |
real[int] emptyRealArray(0); |
| 1557 |
meshN ThBorder; |
| 1558 |
int fakeInterface = -111111; |
| 1559 |
int overlap = 1; |
| 1560 |
bool excluded = false; |
| 1561 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, s, overlap, intersection, D, P, comm, excluded, P, def, init, labPeriodic, emptyRealArray, 1) |
| 1562 |
}// EOM |
| 1563 |
macro buildMinimalist(Th, intersection, D, P) { |
| 1564 |
int[int] emptyArray(0); |
| 1565 |
real[int] emptyRealArray(0); |
| 1566 |
meshN ThBorder; |
| 1567 |
int fakeInterface = -111111; |
| 1568 |
int overlap = 1; |
| 1569 |
bool excluded = false; |
| 1570 |
buildOverlapEdgePeriodic(Th, ThBorder, fakeInterface, 1, overlap, intersection, D, P, mpiCommWorld, excluded, P, def, init, emptyArray, emptyRealArray, 1) |
| 1571 |
}// EOM |
| 1572 |
macro buildRecursive(Th, s, level, prolongation, intersectionMat, DTab, P, comm) { |
| 1573 |
int[int] emptyArray(0); |
| 1574 |
real[int] emptyRealArray(0); |
| 1575 |
meshN[int] ThBorderTab(level); |
| 1576 |
DTab.resize(level); |
| 1577 |
buildOverlapEdgePeriodicRecursive(Th, ThBorderTab, -111111, s, 1, level, prolongation, intersectionMat, DTab, P, comm, false, P, def, init, emptyArray, emptyRealArray, 1) |
| 1578 |
}// EOM |
| 1579 |
macro buildMatRecursive(Th, s, nlevel, prolongation, A, P, comm) { |
| 1580 |
int[int] emptyArray(0); |
| 1581 |
real[int] emptyRealArray(0); |
| 1582 |
meshN[int] ThBorderTab(nlevel); |
| 1583 |
int[int][int] intersectionMat; |
| 1584 |
real[int][int] DTab(nlevel); |
| 1585 |
buildOverlapEdgePeriodicRecursive(Th, ThBorderTab, -111111, s, 1, nlevel, prolongation, intersectionMat, DTab, P, comm, false, P, def, init, emptyArray, emptyRealArray, 1) |
| 1586 |
for(int i = 0; i < nlevel; ++i) |
| 1587 |
constructor(A[i], DTab[i].n, intersectionMat, DTab[i], communicator = comm, level = i); |
| 1588 |
}// EOM |
| 1589 |
macro buildMatEdgeRecursive(Th, s, nlevel, prolongation, A, P, comm, PkPart, defPart, initPart) { |
| 1590 |
int[int] emptyArray(0); |
| 1591 |
real[int] emptyRealArray(0); |
| 1592 |
meshN[int] ThBorderTab(nlevel); |
| 1593 |
int[int][int] intersectionMat; |
| 1594 |
real[int][int] DTab(nlevel); |
| 1595 |
buildOverlapEdgePeriodicRecursive(Th, ThBorderTab, -111111, s, 1, nlevel, prolongation, intersectionMat, DTab, P, comm, false, PkPart, defPart, initPart, emptyArray, emptyRealArray, 1) |
| 1596 |
for(int i = 0; i < nlevel; ++i) |
| 1597 |
constructor(A[i], DTab[i].n, intersectionMat, DTab[i], communicator = comm, level = i); |
| 1598 |
}// EOM |
| 1599 |
macro buildMatEdgeRecursiveWithPartitioning(Th, part, s, nlevel, prolongation, A, P, comm, PkPart, defPart, initPart) { |
| 1600 |
int[int] emptyArray(0); |
| 1601 |
meshN[int] ThBorderTab(nlevel); |
| 1602 |
int[int][int] intersectionMat; |
| 1603 |
real[int][int] DTab(nlevel); |
| 1604 |
buildOverlapEdgePeriodicRecursive(Th, ThBorderTab, -111111, s, 1, nlevel, prolongation, intersectionMat, DTab, P, comm, false, PkPart, defPart, initPart, emptyArray, part, 1) |
| 1605 |
for(int i = 0; i < nlevel; ++i) |
| 1606 |
constructor(A[i], DTab[i].n, intersectionMat, DTab[i], communicator = comm, level = i); |
| 1607 |
}// EOM |
| 1608 |
macro buildMatEdgeWithPartitioning(Th, part, s, A, P, comm, PkPart, defPart, initPart) { |
| 1609 |
real[int] DMat; |
| 1610 |
int[int][int] intersectionMat; |
| 1611 |
buildEdgeWithPartitioning(Th, part, s, intersectionMat, DMat, P, comm, PkPart, defPart, initPart) |
| 1612 |
constructor(A, DMat.n, intersectionMat, DMat, communicator = comm); |
| 1613 |
}// EOM |
| 1614 |
macro buildMatWithPartitioning(Th, part, s, A, P, comm) { |
| 1615 |
real[int] DMat; |
| 1616 |
int[int][int] intersectionMat; |
| 1617 |
buildWithPartitioning(Th, part, s, intersectionMat, DMat, P, comm) |
| 1618 |
constructor(A, DMat.n, intersectionMat, DMat, communicator = comm); |
| 1619 |
}// EOM |
| 1620 |
macro buildMat(Th, s, A, P, comm) { |
| 1621 |
real[int] DMat; |
| 1622 |
int[int][int] intersectionMat; |
| 1623 |
build(Th, s, intersectionMat, DMat, P, comm) |
| 1624 |
constructor(A, DMat.n, intersectionMat, DMat, communicator = comm); |
| 1625 |
}// EOM |
| 1626 |
macro buildMatPeriodic(Th, s, A, P, comm, labPeriodic) { |
| 1627 |
real[int] DMat; |
| 1628 |
int[int][int] intersectionMat; |
| 1629 |
buildPeriodic(Th, s, intersectionMat, DMat, P, comm, labPeriodic) |
| 1630 |
constructor(A, DMat.n, intersectionMat, DMat, communicator = comm); |
| 1631 |
}// EOM |
| 1632 |
macro buildMatMinimalist(Th, A, P) { |
| 1633 |
real[int] DMat; |
| 1634 |
int[int][int] intersectionMat; |
| 1635 |
buildMinimalist(Th, intersectionMat, DMat, P) |
| 1636 |
constructor(A, DMat.n, intersectionMat, DMat); |
| 1637 |
}// EOM |
| 1638 |
ENDIFMACRO |
| 1639 |
|
| 1640 |
macro convectParallel(ThName, uVel, dt, uKhi, safety) |
| 1641 |
IFMACRO(privateDmesh#ThName) |
| 1642 |
{ |
| 1643 |
IFMACRO(!ThName#Comm) |
| 1644 |
NewMacro ThName#Comm()mpiCommWorld EndMacro |
| 1645 |
ENDIFMACRO |
| 1646 |
IFMACRO(!ThName#VelocityPk) |
| 1647 |
func ThSinglePk = P1; |
| 1648 |
ENDIFMACRO |
| 1649 |
IFMACRO(ThName#VelocityPk) |
| 1650 |
func ThSinglePk = ThName#VelocityPk; |
| 1651 |
ENDIFMACRO |
| 1652 |
if(verbosity > 0) |
| 1653 |
mpiBarrier(ThName#Comm); |
| 1654 |
real timerConvect = mpiWtime(); |
| 1655 |
if(mpiSize(ThName#Comm) == 1) { |
| 1656 |
uKhi = convect(uVel, dt, uKhi); |
| 1657 |
} |
| 1658 |
else { |
| 1659 |
int backupSM = searchMethod; |
| 1660 |
searchMethod = 0; |
| 1661 |
real[int] bb(2 * dimension); |
| 1662 |
boundingbox(ThName, bb); |
| 1663 |
bb(0) -= safety * ThName.hmax; |
| 1664 |
bb(1) += safety * ThName.hmax; |
| 1665 |
bb(2) -= safety * ThName.hmax; |
| 1666 |
bb(3) += safety * ThName.hmax; |
| 1667 |
IFMACRO(dimension,3) |
| 1668 |
bb(4) -= safety * ThName.hmax; |
| 1669 |
bb(5) += safety * ThName.hmax; |
| 1670 |
ENDIFMACRO |
| 1671 |
int size = mpiSize(ThName#Comm); |
| 1672 |
real[int] bbAll(2 * dimension * size); |
| 1673 |
mpiAllgather(bb, bbAll, ThName#Comm); |
| 1674 |
int[int] rankExchange(0); |
| 1675 |
for(int i = 0; i < size; ++i) { |
| 1676 |
IFMACRO(dimension,2) |
| 1677 |
if(!(bbAll[1 + 4 * i] < bb[0] |
| 1678 |
|| bbAll[0 + 4 * i] > bb[1] |
| 1679 |
|| bbAll[3 + 4 * i] < bb[2] |
| 1680 |
|| bbAll[2 + 4 * i] > bb[3])) |
| 1681 |
ENDIFMACRO |
| 1682 |
IFMACRO(dimension,3) |
| 1683 |
if(!(bbAll[1 + 6 * i] < bb[0] |
| 1684 |
|| bbAll[0 + 6 * i] > bb[1] |
| 1685 |
|| bbAll[3 + 6 * i] < bb[2] |
| 1686 |
|| bbAll[2 + 6 * i] > bb[3] |
| 1687 |
|| bbAll[5 + 6 * i] < bb[4] |
| 1688 |
|| bbAll[4 + 6 * i] > bb[5])) |
| 1689 |
ENDIFMACRO |
| 1690 |
{ |
| 1691 |
rankExchange.resize(rankExchange.n + 1); |
| 1692 |
rankExchange[rankExchange.n - 1] = i; |
| 1693 |
} |
| 1694 |
} |
| 1695 |
real[int] D, backupRegion(ThName.nt); |
| 1696 |
IFMACRO(dimension,2) |
| 1697 |
func PkVel = [ThSinglePk, ThSinglePk]; |
| 1698 |
ENDIFMACRO |
| 1699 |
IFMACRO(dimension,3) |
| 1700 |
func PkVel = [ThSinglePk, ThSinglePk, ThSinglePk]; |
| 1701 |
ENDIFMACRO |
| 1702 |
fespace VhVelPrivate(ThName, PkVel); |
| 1703 |
fespace VhKhiPrivate(ThName, ThSinglePk); |
| 1704 |
real[int] buffer(VhVelPrivate.ndof + VhKhiPrivate.ndof); |
| 1705 |
{ |
| 1706 |
VhVelPrivate defVel(uVelLocal) = uVel; |
| 1707 |
fespace VhKhiP1(ThName, P1); |
| 1708 |
VhKhiP1 khiP1; |
| 1709 |
khiP1[] = privateDmesh#ThName#khiDef[0]; |
| 1710 |
VhKhiPrivate khi; |
| 1711 |
if(khi[].n != khiP1[].n) |
| 1712 |
khi = khiP1; |
| 1713 |
else |
| 1714 |
khi[] = khiP1[]; |
| 1715 |
for[i, value : uVelLocal[]] value *= khi[][i / dimension]; |
| 1716 |
buffer(0:VhVelPrivate.ndof - 1) = uVelLocal[]; |
| 1717 |
buffer(VhVelPrivate.ndof:VhVelPrivate.ndof + VhKhiPrivate.ndof - 1) = khi[]; |
| 1718 |
if(khi[].n != uKhi[].n) { |
| 1719 |
khi = uKhi; |
| 1720 |
buffer(VhVelPrivate.ndof:VhVelPrivate.ndof + VhKhiPrivate.ndof - 1) .*= khi[]; |
| 1721 |
} |
| 1722 |
else |
| 1723 |
buffer(VhVelPrivate.ndof:VhVelPrivate.ndof + VhKhiPrivate.ndof - 1) .*= uKhi[]; |
| 1724 |
} |
| 1725 |
fespace PhPartPrivate(ThName, P0); |
| 1726 |
{ |
| 1727 |
PhPartPrivate backup = region; |
| 1728 |
backupRegion = backup[]; |
| 1729 |
ThName = change(ThName, fregion = privateDmesh#ThName#khiDef[1][nuTriangle]); |
| 1730 |
} |
| 1731 |
meshN[int] recvTh(rankExchange.n); |
| 1732 |
meshN[int] sendTh(rankExchange.n); |
| 1733 |
real[int][int] exchangeU(rankExchange.n + rankExchange.n); |
| 1734 |
mpiRequest[int] rqSendTh(rankExchange.n); |
| 1735 |
mpiRequest[int] rqSendU(rankExchange.n); |
| 1736 |
mpiRequest[int] rqRecvTh(rankExchange.n); |
| 1737 |
mpiRequest[int] rqRecvU(rankExchange.n); |
| 1738 |
for[i, value : rankExchange] |
| 1739 |
Irecv(processor(value, rqRecvTh[i]), recvTh[i]); |
| 1740 |
for[i, value : rankExchange] { |
| 1741 |
PhPartPrivate part; |
| 1742 |
IFMACRO(dimension,2) |
| 1743 |
part = (bbAll[0 + 4 * value] < x |
| 1744 |
&& bbAll[1 + 4 * value] > x |
| 1745 |
&& bbAll[2 + 4 * value] < y |
| 1746 |
&& bbAll[3 + 4 * value] > y) ? 1.0 : 0.0; |
| 1747 |
ENDIFMACRO |
| 1748 |
IFMACRO(dimension,3) |
| 1749 |
part = (bbAll[0 + 6 * value] < x |
| 1750 |
&& bbAll[1 + 6 * value] > x |
| 1751 |
&& bbAll[2 + 6 * value] < y |
| 1752 |
&& bbAll[3 + 6 * value] > y |
| 1753 |
&& bbAll[4 + 6 * value] < z |
| 1754 |
&& bbAll[5 + 6 * value] > z) ? 1.0 : 0.0; |
| 1755 |
ENDIFMACRO |
| 1756 |
if(part[].linfty > 1.0e-2) { |
| 1757 |
int[int] n2o; |
| 1758 |
sendTh[i] = trunc(ThName, part > 1.0e-2, new2old = n2o); |
| 1759 |
fespace VhRestrictionPrivate(sendTh[i], ThSinglePk); |
| 1760 |
int[int] map; |
| 1761 |
map = restrict(VhRestrictionPrivate, VhKhiPrivate, n2o); |
| 1762 |
exchangeU[rankExchange.n + i].resize(VhRestrictionPrivate.ndof * (dimension + 1)); |
| 1763 |
for[j, w : map] { |
| 1764 |
exchangeU[rankExchange.n + i][dimension * j] = buffer[dimension * w]; |
| 1765 |
exchangeU[rankExchange.n + i][dimension * j + 1] = buffer[dimension * w + 1]; |
| 1766 |
IFMACRO(dimension,3) |
| 1767 |
exchangeU[rankExchange.n + i][dimension * j + 2] = buffer[dimension * w + 2]; |
| 1768 |
ENDIFMACRO |
| 1769 |
exchangeU[rankExchange.n + i][VhRestrictionPrivate.ndof * dimension + j] = buffer[VhKhiPrivate.ndof * dimension + w]; |
| 1770 |
} |
| 1771 |
Isend(processor(value, rqSendTh[i]), sendTh[i]); |
| 1772 |
Isend(processor(value, rqSendU[i]), exchangeU[rankExchange.n + i]); |
| 1773 |
} |
| 1774 |
else |
| 1775 |
Isend(processor(value, rqSendTh[i]), sendTh[i]); |
| 1776 |
} |
| 1777 |
meshN gluedExchange; |
| 1778 |
{ |
| 1779 |
meshN[int] toGlue(rankExchange.n); |
| 1780 |
int j = 0; |
| 1781 |
for[i, value : rankExchange] { |
| 1782 |
int index = mpiWaitAny(rqRecvTh); |
| 1783 |
if(recvTh[index].nt) { |
| 1784 |
fespace VhRestrictionPrivate(recvTh[index], ThSinglePk); |
| 1785 |
exchangeU[index].resize(VhRestrictionPrivate.ndof * (dimension + 1)); |
| 1786 |
Irecv(processor(rankExchange[index], rqRecvU[index]), exchangeU[index]); |
| 1787 |
fespace PhRestrictionPrivate(recvTh[index], P0); |
| 1788 |
PhRestrictionPrivate ind = abs(region - rankExchange[index]) < 1.0e-2 ? 1.0 : 0.0; |
| 1789 |
if(abs(ind[].max - 1.0) < 1.0e-2) { |
| 1790 |
toGlue[j] = trunc(recvTh[index], ind > 1.0e-2); |
| 1791 |
++j; |
| 1792 |
} |
| 1793 |
} |
| 1794 |
} |
| 1795 |
toGlue.resize(j); |
| 1796 |
gluedExchange = gluemesh(toGlue); |
| 1797 |
} |
| 1798 |
meshN interpolateExchange; |
| 1799 |
fespace VhVelExchangePrivate(gluedExchange, PkVel); |
| 1800 |
fespace VhKhiExchangePrivate(gluedExchange, ThSinglePk); |
| 1801 |
VhVelExchangePrivate defVel(uVelExchange); |
| 1802 |
VhKhiExchangePrivate uKhiExchange; |
| 1803 |
for[i, value : rankExchange] { |
| 1804 |
int index = mpiWaitAny(rqRecvU); |
| 1805 |
if(index != mpiUndefined) { |
| 1806 |
if(recvTh[index].nt) { |
| 1807 |
fespace VhRestrictionPrivate(recvTh[index], ThSinglePk); |
| 1808 |
matrix R = interpolate(VhRestrictionPrivate, VhKhiExchangePrivate); |
| 1809 |
if(R.nnz != R.n) { |
| 1810 |
R.thresholding(1.0e-2); |
| 1811 |
assert(R.nnz == R.n); |
| 1812 |
} |
| 1813 |
for[i, j, value : R] { |
| 1814 |
uVelExchange[][dimension * j] += exchangeU[index][dimension * i]; |
| 1815 |
uVelExchange[][dimension * j + 1] += exchangeU[index][dimension * i + 1]; |
| 1816 |
IFMACRO(dimension,3) |
| 1817 |
uVelExchange[][dimension * j + 2] += exchangeU[index][dimension * i + 2]; |
| 1818 |
ENDIFMACRO |
| 1819 |
uKhiExchange[][j] += exchangeU[index][dimension * VhRestrictionPrivate.ndof + i]; |
| 1820 |
} |
| 1821 |
} |
| 1822 |
} |
| 1823 |
} |
| 1824 |
searchMethod = backupSM; |
| 1825 |
fespace VhPhiExchangePrivate(gluedExchange, P0); |
| 1826 |
fespace VhKhiExchangeP1(gluedExchange, P1); |
| 1827 |
int rank = mpiRank(ThName#Comm); |
| 1828 |
VhPhiExchangePrivate phi = abs(region - rank) < 1.0e-2 ? 1.0 : 0.0; |
| 1829 |
VhKhiExchangeP1 khi; |
| 1830 |
AddLayers(gluedExchange, phi[], safety, khi[]); |
| 1831 |
int[int] n2o; |
| 1832 |
meshN gluedExchangeSafety = trunc(gluedExchange, abs(khi) > 0.1, new2old = n2o); |
| 1833 |
fespace VhVelExchangeSafetyPrivate(gluedExchangeSafety, PkVel); |
| 1834 |
fespace VhKhiExchangeSafetyPrivate(gluedExchangeSafety, ThSinglePk); |
| 1835 |
int[int] map = restrict(VhKhiExchangeSafetyPrivate, VhKhiExchangePrivate, n2o); |
| 1836 |
VhVelExchangeSafetyPrivate defVel(uVelExchangeSafety); |
| 1837 |
VhKhiExchangeSafetyPrivate uKhiExchangeSafety; |
| 1838 |
uKhiExchangeSafety[] = uKhiExchange[](map); |
| 1839 |
for[j, w : map] { |
| 1840 |
uVelExchangeSafety[][dimension * j] = uVelExchange[][dimension * w]; |
| 1841 |
uVelExchangeSafety[][dimension * j + 1] = uVelExchange[][dimension * w + 1]; |
| 1842 |
IFMACRO(dimension,3) |
| 1843 |
uVelExchangeSafety[][dimension * j + 2] = uVelExchange[][dimension * w + 2]; |
| 1844 |
ENDIFMACRO |
| 1845 |
} |
| 1846 |
uKhiExchangeSafety = convect(defVel(uVelExchangeSafety), dt, uKhiExchangeSafety); |
| 1847 |
uKhi = uKhiExchangeSafety; |
| 1848 |
ThName = change(ThName, fregion = backupRegion[nuTriangle]); |
| 1849 |
mpiWaitAll(rqSendTh); |
| 1850 |
mpiWaitAll(rqSendU); |
| 1851 |
} |
| 1852 |
if(verbosity > 0) { |
| 1853 |
mpiBarrier(ThName#Comm); |
| 1854 |
if(mpiRank(ThName#Comm) == 0) |
| 1855 |
cout.scientific << " --- distributed solution convected (in " << mpiWtime() - timerConvect << ")" << endl; |
| 1856 |
} |
| 1857 |
} |
| 1858 |
ENDIFMACRO |
| 1859 |
// EOM |
| 1860 |
|
| 1861 |
macro transferBase(ThName, Pk, uA, ThNew, PkNew, uANew, P) |
| 1862 |
IFMACRO(privateDmesh#ThName) |
| 1863 |
{ |
| 1864 |
IFMACRO(!ThName#Comm) |
| 1865 |
NewMacro ThName#Comm()mpiCommWorld EndMacro |
| 1866 |
ENDIFMACRO |
| 1867 |
if(verbosity > 0) |
| 1868 |
mpiBarrier(ThName#Comm); |
| 1869 |
real timerTransfer = mpiWtime(); |
| 1870 |
IFMACRO(!def) |
| 1871 |
NewMacro def(i)i EndMacro |
| 1872 |
ENDIFMACRO |
| 1873 |
if(mpiSize(ThName#Comm) == 1) { |
| 1874 |
IFMACRO(!transfer#Q) |
| 1875 |
def(uANew) = def(uA); |
| 1876 |
ENDIFMACRO |
| 1877 |
IFMACRO(transfer#Q) |
| 1878 |
fespace VhLocalOldPrivate(ThName, Pk); |
| 1879 |
fespace VhLocalNewPrivate(ThNew, PkNew); |
| 1880 |
matrix loc = interpolate(VhLocalNewPrivate, VhLocalOldPrivate); |
| 1881 |
matrix<PetscScalar> locPetscScalar = loc; |
| 1882 |
constructor(P, uANew, uA, locPetscScalar); |
| 1883 |
ENDIFMACRO |
| 1884 |
} |
| 1885 |
else { |
| 1886 |
int backupSM = searchMethod; |
| 1887 |
searchMethod = 0; |
| 1888 |
fespace VhLocalOldPrivate(ThName, Pk); |
| 1889 |
fespace VhLocalNewPrivate(ThNew, PkNew); |
| 1890 |
IFMACRO(!transfer#Q) |
| 1891 |
if(VhLocalOldPrivate.ndof) assert(uA[].n == VhLocalOldPrivate.ndof); |
| 1892 |
if(VhLocalNewPrivate.ndof) assert(uANew[].n == VhLocalNewPrivate.ndof); |
| 1893 |
ENDIFMACRO |
| 1894 |
IFMACRO(!dimension) |
| 1895 |
NewMacro dimension()2 EndMacro |
| 1896 |
ENDIFMACRO |
| 1897 |
IFMACRO(!meshN) |
| 1898 |
NewMacro meshN()mesh EndMacro |
| 1899 |
ENDIFMACRO |
| 1900 |
IFMACRO(!ThName#NestedIn#ThNew) |
| 1901 |
real[int] bb(4 * dimension); |
| 1902 |
{ |
| 1903 |
real[int] tmp(2 * dimension); |
| 1904 |
if(ThName.nt) boundingbox(ThName, tmp); |
| 1905 |
else tmp = 1.0e+30; |
| 1906 |
bb(0:2 * dimension - 1) = tmp; |
| 1907 |
if(ThNew.nt) boundingbox(ThNew, tmp); |
| 1908 |
else tmp = 1.0e+30; |
| 1909 |
bb(2 * dimension:4 * dimension - 1) = tmp; |
| 1910 |
bb(0) -= max(ThName.hmax, ThNew.hmax); |
| 1911 |
bb(1) += max(ThName.hmax, ThNew.hmax); |
| 1912 |
bb(2) -= max(ThName.hmax, ThNew.hmax); |
| 1913 |
bb(3) += max(ThName.hmax, ThNew.hmax); |
| 1914 |
bb(4) -= max(ThName.hmax, ThNew.hmax); |
| 1915 |
bb(5) += max(ThName.hmax, ThNew.hmax); |
| 1916 |
bb(6) -= max(ThName.hmax, ThNew.hmax); |
| 1917 |
bb(7) += max(ThName.hmax, ThNew.hmax); |
| 1918 |
IFMACRO(dimension,3) |
| 1919 |
bb(8) -= max(ThName.hmax, ThNew.hmax); |
| 1920 |
bb(9) += max(ThName.hmax, ThNew.hmax); |
| 1921 |
bb(10) -= max(ThName.hmax, ThNew.hmax); |
| 1922 |
bb(11) += max(ThName.hmax, ThNew.hmax); |
| 1923 |
ENDIFMACRO |
| 1924 |
} |
| 1925 |
int size = mpiSize(ThName#Comm); |
| 1926 |
real[int] bbAll(4 * dimension * size); |
| 1927 |
mpiAllgather(bb, bbAll, ThName#Comm); |
| 1928 |
int[int] rankSend(0); |
| 1929 |
int[int] rankRecv(0); |
| 1930 |
for(int i = 0; i < size; ++i) { |
| 1931 |
IFMACRO(dimension,2) |
| 1932 |
if(!(bbAll[1 + 8 * i] < bb[4] |
| 1933 |
|| bbAll[0 + 8 * i] > bb[5] |
| 1934 |
|| bbAll[3 + 8 * i] < bb[6] |
| 1935 |
|| bbAll[2 + 8 * i] > bb[7])) |
| 1936 |
ENDIFMACRO |
| 1937 |
IFMACRO(dimension,3) |
| 1938 |
if(!(bbAll[1 + 12 * i] < bb[6] |
| 1939 |
|| bbAll[0 + 12 * i] > bb[7] |
| 1940 |
|| bbAll[3 + 12 * i] < bb[8] |
| 1941 |
|| bbAll[2 + 12 * i] > bb[9] |
| 1942 |
|| bbAll[5 + 12 * i] < bb[10] |
| 1943 |
|| bbAll[4 + 12 * i] > bb[11])) |
| 1944 |
ENDIFMACRO |
| 1945 |
{ |
| 1946 |
rankRecv.resize(rankRecv.n + 1); |
| 1947 |
rankRecv[rankRecv.n - 1] = i; |
| 1948 |
} |
| 1949 |
IFMACRO(dimension,2) |
| 1950 |
if(!(bbAll[5 + 8 * i] < bb[0] |
| 1951 |
|| bbAll[4 + 8 * i] > bb[1] |
| 1952 |
|| bbAll[7 + 8 * i] < bb[2] |
| 1953 |
|| bbAll[6 + 8 * i] > bb[3])) |
| 1954 |
ENDIFMACRO |
| 1955 |
IFMACRO(dimension,3) |
| 1956 |
if(!(bbAll[7 + 12 * i] < bb[0] |
| 1957 |
|| bbAll[6 + 12 * i] > bb[1] |
| 1958 |
|| bbAll[9 + 12 * i] < bb[2] |
| 1959 |
|| bbAll[8 + 12 * i] > bb[3] |
| 1960 |
|| bbAll[11 + 12 * i] < bb[4] |
| 1961 |
|| bbAll[10 + 12 * i] > bb[5])) |
| 1962 |
ENDIFMACRO |
| 1963 |
{ |
| 1964 |
rankSend.resize(rankSend.n + 1); |
| 1965 |
rankSend[rankSend.n - 1] = i; |
| 1966 |
} |
| 1967 |
} |
| 1968 |
real[int] D, backupRegion(ThName.nt); |
| 1969 |
VhLocalOldPrivate<PetscScalar> def(scaledU); |
| 1970 |
IFMACRO(!transfer#Q) |
| 1971 |
PartitionCreate(ThName, D, Pk) |
| 1972 |
if(VhLocalOldPrivate.ndof) scaledU[] = uA[]; |
| 1973 |
ENDIFMACRO |
| 1974 |
IFMACRO(transfer#Q) |
| 1975 |
if(VhLocalOldPrivate.ndof) { |
| 1976 |
GlobalNumbering(uA, scaledU[]); |
| 1977 |
D.resize(scaledU[].n); |
| 1978 |
D = uA.D; |
| 1979 |
} |
| 1980 |
else GlobalNumbering(uA, D); |
| 1981 |
ENDIFMACRO |
| 1982 |
for[i, value : D] scaledU[][i] *= value; |
| 1983 |
fespace PhPartPrivate(ThName, P0); |
| 1984 |
if(PhPartPrivate.ndof) { |
| 1985 |
PhPartPrivate backup = region; |
| 1986 |
backupRegion = backup[]; |
| 1987 |
int[int] newRegion(ThName.nt); |
| 1988 |
int rank = mpiRank(ThName#Comm); |
| 1989 |
for[i, value : privateDmesh#ThName#khiDef[1]] newRegion[i] = abs(value - rank) < 1.0e-2; |
| 1990 |
ThName = change(ThName, fregion = newRegion[nuTriangle]); |
| 1991 |
} |
| 1992 |
meshN[int] recvTh(rankRecv.n); |
| 1993 |
meshN[int] sendTh(rankSend.n); |
| 1994 |
PetscScalar[int][int] exchangeU(rankSend.n + rankRecv.n); |
| 1995 |
mpiRequest[int] rqSendTh(rankSend.n); |
| 1996 |
mpiRequest[int] rqSendU(rankSend.n); |
| 1997 |
mpiRequest[int] rqRecvTh(rankRecv.n); |
| 1998 |
mpiRequest[int] rqRecvU(rankRecv.n); |
| 1999 |
for[i, value : rankRecv] |
| 2000 |
Irecv(processor(value, rqRecvTh[i]), recvTh[i]); |
| 2001 |
for[i, value : rankSend] { |
| 2002 |
if(PhPartPrivate.ndof) { |
| 2003 |
PhPartPrivate part; |
| 2004 |
IFMACRO(dimension,2) |
| 2005 |
part = (bbAll[4 + 8 * value] < x |
| 2006 |
&& bbAll[5 + 8 * value] > x |
| 2007 |
&& bbAll[6 + 8 * value] < y |
| 2008 |
&& bbAll[7 + 8 * value] > y) ? 1.0 : 0.0; |
| 2009 |
ENDIFMACRO |
| 2010 |
IFMACRO(dimension,3) |
| 2011 |
part = (bbAll[6 + 12 * value] < x |
| 2012 |
&& bbAll[7 + 12 * value] > x |
| 2013 |
&& bbAll[8 + 12 * value] < y |
| 2014 |
&& bbAll[9 + 12 * value] > y |
| 2015 |
&& bbAll[10 + 12 * value] < z |
| 2016 |
&& bbAll[11 + 12 * value] > z) ? 1.0 : 0.0; |
| 2017 |
ENDIFMACRO |
| 2018 |
if(part[].linfty > 1.0e-2) { |
| 2019 |
int[int] n2o; |
| 2020 |
sendTh[i] = trunc(ThName, part > 1.0e-2, new2old = n2o); |
| 2021 |
fespace VhRestrictionPrivate(sendTh[i], Pk); |
| 2022 |
int[int] map = restrict(VhRestrictionPrivate, VhLocalOldPrivate, n2o); |
| 2023 |
exchangeU[rankRecv.n + i].resize(VhRestrictionPrivate.ndof); |
| 2024 |
exchangeU[rankRecv.n + i] = scaledU[](map); |
| 2025 |
Isend(processor(value, rqSendTh[i]), sendTh[i]); |
| 2026 |
Isend(processor(value, rqSendU[i]), exchangeU[rankRecv.n + i]); |
| 2027 |
} |
| 2028 |
} |
| 2029 |
if(exchangeU[rankRecv.n + i].n == 0) |
| 2030 |
Isend(processor(value, rqSendTh[i]), sendTh[i]); |
| 2031 |
} |
| 2032 |
meshN gluedExchange; |
| 2033 |
{ |
| 2034 |
meshN[int] toGlue(rankRecv.n); |
| 2035 |
int j = 0; |
| 2036 |
for[i, value : rankRecv] { |
| 2037 |
int index = mpiWaitAny(rqRecvTh); |
| 2038 |
if(recvTh[index].nt) { |
| 2039 |
fespace VhRestrictionPrivate(recvTh[index], Pk); |
| 2040 |
exchangeU[index].resize(VhRestrictionPrivate.ndof); |
| 2041 |
Irecv(processor(rankRecv[index], rqRecvU[index]), exchangeU[index]); |
| 2042 |
fespace PhRestrictionPrivate(recvTh[index], P0); |
| 2043 |
PhRestrictionPrivate ind = region; |
| 2044 |
if(abs(ind[].max - 1.0) < 1.0e-2) { |
| 2045 |
toGlue[j] = trunc(recvTh[index], ind > 1.0e-2); |
| 2046 |
++j; |
| 2047 |
} |
| 2048 |
} |
| 2049 |
} |
| 2050 |
toGlue.resize(j); |
| 2051 |
gluedExchange = gluemesh(toGlue); |
| 2052 |
} |
| 2053 |
meshN interpolateExchange; |
| 2054 |
fespace PhExchangePrivate(gluedExchange, P0); |
| 2055 |
fespace VhExchangePrivate(gluedExchange, Pk); |
| 2056 |
VhExchangePrivate<PetscScalar> def(uExchange); |
| 2057 |
if(VhExchangePrivate.ndof) uExchange[] = 0.0; |
| 2058 |
for[i, value : rankRecv] { |
| 2059 |
int index = mpiWaitAny(rqRecvU); |
| 2060 |
if(index != mpiUndefined) { |
| 2061 |
if(recvTh[index].nt) { |
| 2062 |
fespace VhRestrictionPrivate(recvTh[index], Pk); |
| 2063 |
VhRestrictionPrivate<PetscScalar> def(uLocal); |
| 2064 |
uLocal[] = exchangeU[index]; |
| 2065 |
matrix R = interpolate(VhExchangePrivate, VhRestrictionPrivate, inside = 1); |
| 2066 |
int[int] I, J; |
| 2067 |
real[int] C; |
| 2068 |
[I, J, C] = R; |
| 2069 |
I.resize(R.nnz); |
| 2070 |
J.resize(R.nnz); |
| 2071 |
PetscScalar[int] gathered = exchangeU[index](J); |
| 2072 |
uExchange[](I) += gathered; |
| 2073 |
} |
| 2074 |
} |
| 2075 |
} |
| 2076 |
searchMethod = backupSM; |
| 2077 |
IFMACRO(!transfer#Q) |
| 2078 |
if(VhExchangePrivate.ndof) def(uANew) = def(uExchange); |
| 2079 |
ENDIFMACRO |
| 2080 |
IFMACRO(transfer#Q) |
| 2081 |
matrix loc = interpolate(VhLocalNewPrivate, VhExchangePrivate); |
| 2082 |
matrix<PetscScalar> locPetscScalar = loc; |
| 2083 |
if(VhExchangePrivate.ndof) constructor(P, uANew, uA, locPetscScalar, numbering = uExchange[]); |
| 2084 |
else { |
| 2085 |
PetscScalar[int] empty; |
| 2086 |
constructor(P, uANew, uA, locPetscScalar, numbering = empty); |
| 2087 |
} |
| 2088 |
ENDIFMACRO |
| 2089 |
if(ThName.nt) ThName = change(ThName, fregion = backupRegion[nuTriangle]); |
| 2090 |
mpiWaitAll(rqSendTh); |
| 2091 |
mpiWaitAll(rqSendU); |
| 2092 |
ENDIFMACRO |
| 2093 |
IFMACRO(ThName#NestedIn#ThNew) |
| 2094 |
IFMACRO(!transfer#Q) |
| 2095 |
def(uANew) = def(uA); |
| 2096 |
Mat<PetscScalar> exchange; |
| 2097 |
MatCreate(ThNew, exchange, PkNew) |
| 2098 |
PetscScalar[int] tmp; |
| 2099 |
ChangeNumbering(exchange, uANew[], tmp); |
| 2100 |
ChangeNumbering(exchange, uANew[], tmp, inverse = true, exchange = true); |
| 2101 |
ENDIFMACRO |
| 2102 |
IFMACRO(transfer#Q) |
| 2103 |
matrix loc = interpolate(VhLocalNewPrivate, VhLocalOldPrivate); |
| 2104 |
matrix<PetscScalar> locPetscScalar = loc; |
| 2105 |
constructor(P, uANew, uA, locPetscScalar); |
| 2106 |
ENDIFMACRO |
| 2107 |
ENDIFMACRO |
| 2108 |
} |
| 2109 |
if(verbosity > 0) { |
| 2110 |
mpiBarrier(ThName#Comm); |
| 2111 |
if(mpiRank(ThName#Comm) == 0) |
| 2112 |
cout.scientific << " --- distributed solution transferred (in " << mpiWtime() - timerTransfer << ")" << endl; |
| 2113 |
} |
| 2114 |
} |
| 2115 |
ENDIFMACRO |
| 2116 |
IFMACRO(!privateDmesh#ThName) |
| 2117 |
assert(0); |
| 2118 |
ENDIFMACRO |
| 2119 |
// EOM |
| 2120 |
|
| 2121 |
macro MatInterpolate(ThName, Pk, A, ThNew, PkNew, ANew, P) { |
| 2122 |
NewMacro transfer#Q() EndMacro |
| 2123 |
transferBase(ThName, Pk, A, ThNew, PkNew, ANew, P) |
| 2124 |
}// EOM |
| 2125 |
|
| 2126 |
macro VecInterpolate(ThName, Pk, uPrivate, ThNew, PkNew, uNew) { |
| 2127 |
transferBase(ThName, Pk, uPrivate, ThNew, PkNew, uNew, 1) |
| 2128 |
}// EOM |
| 2129 |
|
| 2130 |
macro ParMmgCreateCommunicators(ThName, ThParMmgName, ThN2O, ThCommunicators) { |
| 2131 |
IFMACRO(!privateDmesh#ThName) |
| 2132 |
assert(0); |
| 2133 |
ENDIFMACRO |
| 2134 |
Mat<PetscScalar> A; |
| 2135 |
MatCreate(ThName, A, P1); |
| 2136 |
real[int] D(ThName.nt); |
| 2137 |
PartitionCreate(ThName, D, P0); |
| 2138 |
fespace PhPrivate(ThName, P0); |
| 2139 |
PhPrivate d; |
| 2140 |
d[] = D; |
| 2141 |
ThParMmgName = trunc(ThName, abs(d) > 1.0e-2, label = -111111, new2old = ThN2O); |
| 2142 |
fespace VhWithoutOverlapPrivate(ThParMmgName, P1); |
| 2143 |
varf vG(uPrivate, vPrivate) = on(-111111, uPrivate = 1.0); |
| 2144 |
real[int] gamma(ThParMmgName.nv); |
| 2145 |
gamma = vG(0, VhWithoutOverlapPrivate, tgv = -1); |
| 2146 |
fespace VhWithOverlapPrivate(ThName, P1); |
| 2147 |
int[int] restriction = restrict(VhWithoutOverlapPrivate, VhWithOverlapPrivate, ThN2O); |
| 2148 |
ParMmgCommunicators(A, gamma, restriction, ThCommunicators); |
| 2149 |
}// EOM |
| 2150 |
|
| 2151 |
macro DmeshGather(ThName, comm, ThGatherName) { |
| 2152 |
IFMACRO(!privateDmesh#ThName) |
| 2153 |
assert(0); |
| 2154 |
ENDIFMACRO |
| 2155 |
IFMACRO(!ThName#Comm) |
| 2156 |
NewMacro ThName#Comm()mpiCommWorld EndMacro |
| 2157 |
ENDIFMACRO |
| 2158 |
IFMACRO(!ThGatherName#Comm) |
| 2159 |
NewMacro ThGatherName#Comm()mpiCommWorld EndMacro |
| 2160 |
ENDIFMACRO |
| 2161 |
IFMACRO(!meshN) |
| 2162 |
NewMacro meshN()mesh EndMacro |
| 2163 |
ENDIFMACRO |
| 2164 |
if(verbosity > 0 && ThName#Comm) |
| 2165 |
mpiBarrier(ThName#Comm); |
| 2166 |
real timerGather = mpiWtime(); |
| 2167 |
int size; |
| 2168 |
if(ThGatherName#Comm) |
| 2169 |
size = mpiSize(comm); |
| 2170 |
else |
| 2171 |
size = 0; |
| 2172 |
int reduce; |
| 2173 |
mpiAllReduce(size, reduce, ThName#Comm, mpiSUM); |
| 2174 |
assert(reduce == mpiSize(ThName#Comm)); |
| 2175 |
meshN ThNoOverlap; |
| 2176 |
if(mpiSize(ThName#Comm) == 1) |
| 2177 |
ThNoOverlap = ThName; |
| 2178 |
else |
| 2179 |
ThNoOverlap = trunc(ThName, abs(privateDmesh#ThName#khiDef[1][nuTriangle] - mpiRank(ThName#Comm)) < 1.0e-2, label = -111112); |
| 2180 |
if(ThGatherName#Comm) { |
| 2181 |
meshN[int] recvTh(size); |
| 2182 |
mpiRequest[int] rqRecv(size - 1); |
| 2183 |
for(int i = 1; i < size; ++i) |
| 2184 |
Irecv(processor(i, comm, rqRecv[i - 1]), recvTh[i]); |
| 2185 |
recvTh[0] = ThNoOverlap; |
| 2186 |
mpiWaitAll(rqRecv); |
| 2187 |
ThGatherName = gluemesh(recvTh); |
| 2188 |
} |
| 2189 |
else { |
| 2190 |
mpiRequest rqSend; |
| 2191 |
Isend(processor(0, comm, rqSend), ThNoOverlap); |
| 2192 |
mpiWait(rqSend); |
| 2193 |
} |
| 2194 |
if(verbosity > 0 && ThName#Comm) { |
| 2195 |
mpiBarrier(ThName#Comm); |
| 2196 |
if(mpiRank(ThName#Comm) == 0) |
| 2197 |
cout.scientific << " --- distributed mesh gathered (in " << mpiWtime() - timerGather << ")" << endl; |
| 2198 |
} |
| 2199 |
} |
| 2200 |
DmeshReconstruct(ThGatherName)// EOM |
| 2201 |
|
| 2202 |
macro DmeshScatter(ThName, comm, ThScatterName) { |
| 2203 |
IFMACRO(!privateDmesh#ThName) |
| 2204 |
assert(0); |
| 2205 |
ENDIFMACRO |
| 2206 |
IFMACRO(!ThName#Comm) |
| 2207 |
NewMacro ThName#Comm()mpiCommWorld EndMacro |
| 2208 |
ENDIFMACRO |
| 2209 |
IFMACRO(!ThScatterName#Comm) |
| 2210 |
NewMacro ThScatterName#Comm()mpiCommWorld EndMacro |
| 2211 |
ENDIFMACRO |
| 2212 |
IFMACRO(!meshN) |
| 2213 |
NewMacro meshN()mesh EndMacro |
| 2214 |
ENDIFMACRO |
| 2215 |
if(verbosity > 0 && ThScatterName#Comm) |
| 2216 |
mpiBarrier(ThScatterName#Comm); |
| 2217 |
real timerScatter = mpiWtime(); |
| 2218 |
int size; |
| 2219 |
if(ThName#Comm) { |
| 2220 |
size = mpiSize(comm); |
| 2221 |
} |
| 2222 |
else |
| 2223 |
size = 0; |
| 2224 |
int reduce; |
| 2225 |
mpiAllReduce(size, reduce, ThScatterName#Comm, mpiSUM); |
| 2226 |
assert(reduce == mpiSize(ThScatterName#Comm)); |
| 2227 |
if(ThName#Comm) { |
| 2228 |
meshN ThNoOverlap; |
| 2229 |
if(mpiSize(ThName#Comm) == 1 || (privateDmesh#ThName#intersectionDef.n == 0 && privateDmesh#ThName#khiDef[0].n == 0 && privateDmesh#ThName#khiDef[1].n == 0)) |
| 2230 |
ThNoOverlap = ThName; |
| 2231 |
else |
| 2232 |
ThNoOverlap = trunc(ThName, abs(privateDmesh#ThName#khiDef[1][nuTriangle] - mpiRank(ThName#Comm)) < 1.0e-2, label = -111112); |
| 2233 |
fespace PhPartPrivate(ThNoOverlap, P0); |
| 2234 |
PhPartPrivate part; |
| 2235 |
partitionerSeq(part[], ThNoOverlap, mpiSize(comm)); |
| 2236 |
partitionerPar(part[], ThNoOverlap, mpiCommSelf, mpiSize(comm)); |
| 2237 |
meshN[int] sendTh(mpiSize(comm) - 1); |
| 2238 |
mpiRequest[int] rqSend(mpiSize(comm) - 1); |
| 2239 |
for(int i = 1; i < mpiSize(comm); ++i) { |
| 2240 |
sendTh[i - 1] = trunc(ThNoOverlap, abs(part - i) < 1.0e-2, label = -111112); |
| 2241 |
Isend(processor(i, comm, rqSend[i - 1]), sendTh[i - 1]); |
| 2242 |
} |
| 2243 |
ThScatterName = trunc(ThNoOverlap, abs(part) < 1.0e-2, label = -111112); |
| 2244 |
mpiWaitAll(rqSend); |
| 2245 |
} |
| 2246 |
else if(ThScatterName#Comm) { |
| 2247 |
mpiRequest rqRecv; |
| 2248 |
Irecv(processor(0, comm, rqRecv), ThScatterName); |
| 2249 |
mpiWait(rqRecv); |
| 2250 |
} |
| 2251 |
if(verbosity > 0 && ThScatterName#Comm) { |
| 2252 |
mpiBarrier(ThScatterName#Comm); |
| 2253 |
if(mpiRank(ThScatterName#Comm) == 0) |
| 2254 |
cout.scientific << " --- distributed mesh scattered (in " << mpiWtime() - timerScatter << ")" << endl; |
| 2255 |
} |
| 2256 |
} |
| 2257 |
DmeshReconstruct(ThScatterName)// EOM |
| 2258 |
|
| 2259 |
macro VecGather(ThName, comm, ThGatherName, Pk, uPrivate, uNew) { |
| 2260 |
IFMACRO(!privateDmesh#ThName) |
| 2261 |
assert(0); |
| 2262 |
ENDIFMACRO |
| 2263 |
IFMACRO(!privateDmesh#ThGatherName) |
| 2264 |
assert(0); |
| 2265 |
ENDIFMACRO |
| 2266 |
IFMACRO(!ThName#Comm) |
| 2267 |
NewMacro ThName#Comm()mpiCommWorld EndMacro |
| 2268 |
ENDIFMACRO |
| 2269 |
IFMACRO(!ThGatherName#Comm) |
| 2270 |
NewMacro ThGatherName#Comm()mpiCommWorld EndMacro |
| 2271 |
ENDIFMACRO |
| 2272 |
IFMACRO(!meshN) |
| 2273 |
NewMacro meshN()mesh EndMacro |
| 2274 |
ENDIFMACRO |
| 2275 |
IFMACRO(!intN) |
| 2276 |
NewMacro intN()int2d EndMacro |
| 2277 |
ENDIFMACRO |
| 2278 |
if(verbosity > 0 && ThName#Comm) |
| 2279 |
mpiBarrier(ThName#Comm); |
| 2280 |
real timerGather = mpiWtime(); |
| 2281 |
IFMACRO(with,PETSc) |
| 2282 |
PetscScalar[int] vPrivate(uPrivate[]); |
| 2283 |
{ |
| 2284 |
Mat<PetscScalar> gather; |
| 2285 |
MatCreate(ThName, gather, Pk) |
| 2286 |
PetscScalar[int] trash; |
| 2287 |
ChangeNumbering(gather, vPrivate, trash); |
| 2288 |
ChangeNumbering(gather, vPrivate, trash, inverse = true, exchange = false); |
| 2289 |
} |
| 2290 |
ENDIFMACRO |
| 2291 |
if(ThGatherName#Comm) { |
| 2292 |
meshN[int] recvTh(mpiSize(comm) - 1); |
| 2293 |
PetscScalar[int][int] recvU(mpiSize(comm) - 1); |
| 2294 |
mpiRequest[int] rqRecvTh(mpiSize(comm) - 1); |
| 2295 |
mpiRequest[int] rqRecvU(mpiSize(comm) - 1); |
| 2296 |
for(int i = 0; i < mpiSize(comm) - 1; ++i) |
| 2297 |
Irecv(processor(i + 1, comm, rqRecvTh[i]), recvTh[i]); |
| 2298 |
for(int i = 0; i < mpiSize(comm) - 1; ++i) { |
| 2299 |
int index = mpiWaitAny(rqRecvTh); |
| 2300 |
fespace VhRecvPrivate(recvTh[index], Pk); |
| 2301 |
recvU[index].resize(VhRecvPrivate.ndof); |
| 2302 |
Irecv(processor(index + 1, comm, rqRecvU[index]), recvU[index]); |
| 2303 |
} |
| 2304 |
fespace VhGlobalGatherPrivate(ThGatherName, Pk); |
| 2305 |
IFMACRO(!with) |
| 2306 |
PetscScalar[int] visited(VhGlobalGatherPrivate.ndof); |
| 2307 |
visited = 1.0; |
| 2308 |
ENDIFMACRO |
| 2309 |
{ |
| 2310 |
fespace VhRestrictionPrivate(ThName, Pk); |
| 2311 |
matrix R = interpolate(VhRestrictionPrivate, VhGlobalGatherPrivate); |
| 2312 |
IFMACRO(with,PETSc) |
| 2313 |
uNew[] += R' * vPrivate; |
| 2314 |
ENDIFMACRO |
| 2315 |
IFMACRO(!with) |
| 2316 |
PetscScalar[int] buffer = R' * uPrivate[]; |
| 2317 |
buffer .*= visited; |
| 2318 |
PetscScalar[int] ones(VhRestrictionPrivate.ndof); |
| 2319 |
ones = -1.0; |
| 2320 |
visited += R' * ones; |
| 2321 |
for[j, value : visited] value = max(abs(value), 0.0); |
| 2322 |
uNew[] += buffer; |
| 2323 |
ENDIFMACRO |
| 2324 |
} |
| 2325 |
for(int i = 0; i < mpiSize(comm) - 1; ++i) { |
| 2326 |
int index = mpiWaitAny(rqRecvU); |
| 2327 |
fespace VhRestrictionPrivate(recvTh[index], Pk); |
| 2328 |
matrix R = interpolate(VhRestrictionPrivate, VhGlobalGatherPrivate); |
| 2329 |
IFMACRO(with,PETSc) |
| 2330 |
uNew[] += R' * recvU[index]; |
| 2331 |
ENDIFMACRO |
| 2332 |
IFMACRO(!with) |
| 2333 |
PetscScalar[int] buffer = R' * recvU[index]; |
| 2334 |
buffer .*= visited; |
| 2335 |
PetscScalar[int] ones(VhRestrictionPrivate.ndof); |
| 2336 |
ones = -1.0; |
| 2337 |
visited += R' * ones; |
| 2338 |
for[j, value : visited] value = max(abs(value), 0.0); |
| 2339 |
uNew[] += buffer; |
| 2340 |
ENDIFMACRO |
| 2341 |
} |
| 2342 |
IFMACRO(with,PETSc) |
| 2343 |
Mat<PetscScalar> gather; |
| 2344 |
MatCreate(ThGatherName, gather, Pk) |
| 2345 |
exchange(gather, uNew[], scaled = false); |
| 2346 |
ENDIFMACRO |
| 2347 |
} |
| 2348 |
else { |
| 2349 |
mpiRequest[int] rqSend(2); |
| 2350 |
Isend(processor(0, comm, rqSend[0]), ThName); |
| 2351 |
fespace VhLocalGatherPrivate(ThName, Pk); |
| 2352 |
assert(uPrivate[].n == VhLocalGatherPrivate.ndof); |
| 2353 |
IFMACRO(with,PETSc) |
| 2354 |
Isend(processor(0, comm, rqSend[1]), vPrivate); |
| 2355 |
ENDIFMACRO |
| 2356 |
IFMACRO(!with) |
| 2357 |
Isend(processor(0, comm, rqSend[1]), uPrivate[]); |
| 2358 |
ENDIFMACRO |
| 2359 |
mpiWaitAll(rqSend); |
| 2360 |
} |
| 2361 |
if(verbosity > 0 && ThName#Comm) { |
| 2362 |
mpiBarrier(ThName#Comm); |
| 2363 |
if(mpiRank(ThName#Comm) == 0) |
| 2364 |
cout.scientific << " --- distributed solution gathered (in " << mpiWtime() - timerGather << ")" << endl; |
| 2365 |
} |
| 2366 |
}// EOM |
| 2367 |
|
| 2368 |
macro VecScatter(ThName, comm, ThScatterName, Pk, uPrivate, uNew) { |
| 2369 |
IFMACRO(!privateDmesh#ThName) |
| 2370 |
assert(0); |
| 2371 |
ENDIFMACRO |
| 2372 |
IFMACRO(!privateDmesh#ThScatterName) |
| 2373 |
assert(0); |
| 2374 |
ENDIFMACRO |
| 2375 |
IFMACRO(!def) |
| 2376 |
NewMacro def(i)i EndMacro |
| 2377 |
ENDIFMACRO |
| 2378 |
IFMACRO(!ThName#Comm) |
| 2379 |
NewMacro ThName#Comm()mpiCommWorld EndMacro |
| 2380 |
ENDIFMACRO |
| 2381 |
IFMACRO(!ThScatterName#Comm) |
| 2382 |
NewMacro ThScatterName#Comm()mpiCommWorld EndMacro |
| 2383 |
ENDIFMACRO |
| 2384 |
IFMACRO(!meshN) |
| 2385 |
NewMacro meshN()mesh EndMacro |
| 2386 |
ENDIFMACRO |
| 2387 |
if(verbosity > 0 && ThScatterName#Comm) |
| 2388 |
mpiBarrier(ThScatterName#Comm); |
| 2389 |
real timerScatter = mpiWtime(); |
| 2390 |
if(mpiRank(comm) == 0) { |
| 2391 |
broadcast(processor(0, comm), ThName); |
| 2392 |
broadcast(processor(0, comm), uPrivate[]); |
| 2393 |
def(uNew) = def(uPrivate); |
| 2394 |
} |
| 2395 |
else { |
| 2396 |
meshN ThGlobalScatter; |
| 2397 |
broadcast(processor(0, comm), ThGlobalScatter); |
| 2398 |
fespace VhGlobalScatterPrivate(ThGlobalScatter, Pk); |
| 2399 |
VhGlobalScatterPrivate<PetscScalar> def(uGlobalScatter); |
| 2400 |
broadcast(processor(0, comm), uGlobalScatter[]); |
| 2401 |
def(uNew) = def(uGlobalScatter); |
| 2402 |
} |
| 2403 |
if(verbosity > 0 && ThScatterName#Comm) { |
| 2404 |
mpiBarrier(ThScatterName#Comm); |
| 2405 |
if(mpiRank(ThScatterName#Comm) == 0) |
| 2406 |
cout.scientific << " --- distributed solution scattered (in " << mpiWtime() - timerScatter << ")" << endl; |
| 2407 |
} |
| 2408 |
}// EOM |
| 2409 |
|
| 2410 |
macro CoherentGlobalMesh(MatT, MatV, ThName, ThGlobal) { |
| 2411 |
IFMACRO(!ThName#Comm) |
| 2412 |
NewMacro ThName#Comm()mpiCommWorld EndMacro |
| 2413 |
ENDIFMACRO |
| 2414 |
int[int] numberingT; |
| 2415 |
int[int] numberingV; |
| 2416 |
GlobalNumbering(MatT, numberingT); |
| 2417 |
GlobalNumbering(MatV, numberingV); |
| 2418 |
fespace VhLocalPrivateT(ThName, P0); |
| 2419 |
fespace VhGlobalPrivateT(ThGlobal, P0); |
| 2420 |
fespace VhLocalPrivateV(ThName, P1); |
| 2421 |
fespace VhGlobalPrivateV(ThGlobal, P1); |
| 2422 |
PetscScalar[int] numberingScalarT(numberingT.n), globalT, reduceT(ThGlobal.nt); |
| 2423 |
PetscScalar[int] numberingScalarV(numberingV.n), globalV, reduceV(ThGlobal.nv); |
| 2424 |
for[i, value : numberingT] numberingScalarT[i] = value; |
| 2425 |
for[i, value : numberingV] numberingScalarV[i] = value; |
| 2426 |
ChangeNumbering(MatT, numberingScalarT, globalT); |
| 2427 |
ChangeNumbering(MatV, numberingScalarV, globalV); |
| 2428 |
if (ThName.nv) { |
| 2429 |
ChangeNumbering(MatT, numberingScalarT, globalT, inverse = true); |
| 2430 |
ChangeNumbering(MatV, numberingScalarV, globalV, inverse = true); |
| 2431 |
IFMACRO(ThName#N2O) |
| 2432 |
int[int] restrictionT = restrict(VhLocalPrivateT, VhGlobalPrivateT, ThName#N2O); |
| 2433 |
int[int] restrictionV = restrict(VhLocalPrivateV, VhGlobalPrivateV, ThName#N2O); |
| 2434 |
ENDIFMACRO |
| 2435 |
IFMACRO(!ThName#N2O) |
| 2436 |
int[int] restrictionT, restrictionV; |
| 2437 |
{ |
| 2438 |
fespace PhGlobalPrivate(ThGlobal, P0); |
| 2439 |
fespace PhLocalPrivate(ThName, P0); |
| 2440 |
matrix R = interpolate(PhLocalPrivate, PhGlobalPrivate); |
| 2441 |
int[int] I, J; |
| 2442 |
real[int] C; |
| 2443 |
[I, J, C] = R; |
| 2444 |
restrictionT = restrict(VhLocalPrivateT, VhGlobalPrivateT, J); |
| 2445 |
restrictionV = restrict(VhLocalPrivateV, VhGlobalPrivateV, J); |
| 2446 |
} |
| 2447 |
ENDIFMACRO |
| 2448 |
for[i, value : restrictionT] reduceT[value] = numberingScalarT[i]; |
| 2449 |
for[i, value : restrictionV] reduceV[value] = numberingScalarV[i]; |
| 2450 |
} |
| 2451 |
globalT.resize(ThGlobal.nt); |
| 2452 |
globalV.resize(ThGlobal.nv); |
| 2453 |
mpiAllReduce(reduceT, globalT, ThName#Comm, mpiSUM); |
| 2454 |
mpiAllReduce(reduceV, globalV, ThName#Comm, mpiSUM); |
| 2455 |
int[int] globalIntT(globalT.n); |
| 2456 |
int[int] globalIntV(globalV.n); |
| 2457 |
for[i, value : globalT] globalIntT[i] = abs(value); |
| 2458 |
for[i, value : globalV] globalIntV[i] = abs(value); |
| 2459 |
ThGlobal = change(ThGlobal, renumt = globalIntT, renumv = globalIntV); |
| 2460 |
}// EOM |
| 2461 |
|
| 2462 |
/* TODO FIXME: remove at some point (deprecated since May 2023) */ |
| 2463 |
macro saveDmesh(ThName, name)if (mpirank == 0) cout << "Deprecated function name, use DmeshSave()" << endl; DmeshSave(ThName, name)// EOM |
| 2464 |
macro loadDmesh(ThName, name)if (mpirank == 0) cout << "Deprecated function name, use DmeshLoad()" << endl; DmeshLoad(ThName, name)// EOM |
| 2465 |
macro buildDmesh(ThName)if (mpirank == 0) cout << "Deprecated function name, use DmeshCreate()" << endl; DmeshCreate(ThName)// EOM |
| 2466 |
macro reconstructDmesh(ThName)if (mpirank == 0) cout << "Deprecated function name, use DmeshReconstruct()" << endl; DmeshReconstruct(ThName)// EOM |
| 2467 |
macro reconstructDmeshWithNeighbors(ThName, neighborsName)if (mpirank == 0) cout << "Deprecated function name, use DmeshReconstructWithNeighbors()" << endl; DmeshReconstructWithNeighbors(ThName, neighborsName)// EOM |
| 2468 |
macro initializeDmesh(NewName)if (mpirank == 0) cout << "Deprecated function name, use DmeshInitialize()" << endl; DmeshInitialize(NewName)// EOM |
| 2469 |
macro copyDmesh(OldName, NewName)if (mpirank == 0) cout << "Deprecated function name, use DmeshCopy()" << endl; DmeshCopy(OldName, NewName)// EOM |
| 2470 |
macro scatterDmesh(ThName, comm, ThScatterName)if (mpirank == 0) cout << "Deprecated function name, use DmeshScatter()" << endl; DmeshScatter(ThName, comm, ThScatterName)// EOM |
| 2471 |
macro gatherDmesh(ThName, comm, ThGatherName)if (mpirank == 0) cout << "Deprecated function name, use DmeshGather()" << endl; DmeshGather(ThName, comm, ThGatherName)// EOM |
| 2472 |
macro createPartition(ThName, PartName, PkName)if (mpirank == 0) cout << "Deprecated function name, use PartitionCreate()" << endl; PartitionCreate(ThName, PartName, PkName)// EOM |
| 2473 |
macro createParMmgCommunicators(ThName, ThParMmgName, ThN2O, ThCommunicators)if (mpirank == 0) cout << "Deprecated function name, use ParMmgCreateCommunicators()" << endl; ParMmgCreateCommunicators(ThName, ThParMmgName, ThN2O, ThCommunicators)// EOM |
| 2474 |
macro scatterSolution(ThName, comm, ThScatterName, Pk, uPrivate, uNew)if (mpirank == 0) cout << "Deprecated function name, use VecScatter()" << endl; VecScatter(ThName, comm, ThScatterName, Pk, uPrivate, uNew)// EOM |
| 2475 |
macro gatherSolution(ThName, comm, ThGatherName, Pk, uPrivate, uNew)if (mpirank == 0) cout << "Deprecated function name, use VecGather()" << endl; VecGather(ThName, comm, ThGatherName, Pk, uPrivate, uNew)// EOM |
| 2476 |
macro transfer(ThName, Pk, uPrivate, ThNew, PkNew, uNew)if (mpirank == 0) cout << "Deprecated function name, use VecInterpolate()" << endl; VecInterpolate(ThName, Pk, uPrivate, ThNew, PkNew, uNew)// EOM |
| 2477 |
macro createMat(ThName, MatName, PkName)if (mpirank == 0) cout << "Deprecated function name, use MatCreate()" << endl; MatCreate(ThName, MatName, PkName)// EOM |
| 2478 |
macro transferMat(ThName, Pk, A, ThNew, PkNew, ANew, P)if (mpirank == 0) cout << "Deprecated function name, use MatInterpolate()" << endl; MatInterpolate(ThName, Pk, A, ThNew, PkNew, ANew, P)// EOM |
| 2479 |
ENDIFMACRO |