decomposeMesh.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "domainDecomposition.H"
00035 #include "IOstreams.H"
00036 #include "SLPtrList.H"
00037 #include "boolList.H"
00038 #include "primitiveMesh.H"
00039 #include "cyclicPolyPatch.H"
00040
00041
00042
00043 void domainDecomposition::decomposeMesh(const bool filterEmptyPatches)
00044 {
00045
00046 distributeCells();
00047
00048
00049
00050
00051 Info<< "\nCalculating original mesh data" << endl;
00052
00053
00054 const polyBoundaryMesh& patches = boundaryMesh();
00055 const faceList& fcs = faces();
00056 const labelList& owner = faceOwner();
00057 const labelList& neighbour = faceNeighbour();
00058
00059
00060
00061
00062 Info<< "\nDistributing cells to processors" << endl;
00063
00064
00065 {
00066 List<SLList<label> > procCellList(nProcs_);
00067
00068 forAll (cellToProc_, celli)
00069 {
00070 if (cellToProc_[celli] >= nProcs_)
00071 {
00072 FatalErrorIn("domainDecomposition::decomposeMesh()")
00073 << "Impossible processor label " << cellToProc_[celli]
00074 << "for cell " << celli
00075 << abort(FatalError);
00076 }
00077 else
00078 {
00079 procCellList[cellToProc_[celli]].append(celli);
00080 }
00081 }
00082
00083
00084 forAll (procCellList, procI)
00085 {
00086 procCellAddressing_[procI] = procCellList[procI];
00087 }
00088 }
00089
00090 Info << "\nDistributing faces to processors" << endl;
00091
00092
00093
00094
00095
00096
00097
00098 {
00099 List<SLList<label> > procFaceList(nProcs_);
00100
00101 forAll (neighbour, facei)
00102 {
00103 if (cellToProc_[owner[facei]] == cellToProc_[neighbour[facei]])
00104 {
00105
00106 procFaceList[cellToProc_[owner[facei]]].append(facei);
00107 }
00108 }
00109
00110
00111
00112
00113 List<SLList<label> > interProcBoundaries(nProcs_);
00114
00115
00116 List<SLList<SLList<label> > > interProcBFaces(nProcs_);
00117
00118 List<SLList<label> > procPatchIndex(nProcs_);
00119
00120 forAll (neighbour, facei)
00121 {
00122 if (cellToProc_[owner[facei]] != cellToProc_[neighbour[facei]])
00123 {
00124
00125
00126
00127
00128 label ownerProc = cellToProc_[owner[facei]];
00129 label neighbourProc = cellToProc_[neighbour[facei]];
00130
00131 SLList<label>::iterator curInterProcBdrsOwnIter =
00132 interProcBoundaries[ownerProc].begin();
00133
00134 SLList<SLList<label> >::iterator curInterProcBFacesOwnIter =
00135 interProcBFaces[ownerProc].begin();
00136
00137 bool interProcBouFound = false;
00138
00139
00140
00141 for
00142 (
00143 ;
00144 curInterProcBdrsOwnIter
00145 != interProcBoundaries[ownerProc].end()
00146 && curInterProcBFacesOwnIter
00147 != interProcBFaces[ownerProc].end();
00148 ++curInterProcBdrsOwnIter, ++curInterProcBFacesOwnIter
00149 )
00150 {
00151 if (curInterProcBdrsOwnIter() == neighbourProc)
00152 {
00153
00154 interProcBouFound = true;
00155
00156 curInterProcBFacesOwnIter().append(facei);
00157
00158 SLList<label>::iterator curInterProcBdrsNeiIter =
00159 interProcBoundaries[neighbourProc].begin();
00160
00161 SLList<SLList<label> >::iterator
00162 curInterProcBFacesNeiIter =
00163 interProcBFaces[neighbourProc].begin();
00164
00165 bool neighbourFound = false;
00166
00167
00168
00169 for
00170 (
00171 ;
00172 curInterProcBdrsNeiIter !=
00173 interProcBoundaries[neighbourProc].end()
00174 && curInterProcBFacesNeiIter !=
00175 interProcBFaces[neighbourProc].end();
00176 ++curInterProcBdrsNeiIter,
00177 ++curInterProcBFacesNeiIter
00178 )
00179 {
00180 if (curInterProcBdrsNeiIter() == ownerProc)
00181 {
00182
00183 neighbourFound = true;
00184
00185 curInterProcBFacesNeiIter().append(facei);
00186 }
00187
00188 if (neighbourFound) break;
00189 }
00190
00191 if (interProcBouFound && !neighbourFound)
00192 {
00193 FatalErrorIn("domainDecomposition::decomposeMesh()")
00194 << "Inconsistency in inter - "
00195 << "processor boundary lists for processors "
00196 << ownerProc << " and " << neighbourProc
00197 << abort(FatalError);
00198 }
00199 }
00200
00201 if (interProcBouFound) break;
00202 }
00203
00204 if (!interProcBouFound)
00205 {
00206
00207
00208
00209
00210
00211
00212 interProcBoundaries[ownerProc].append(neighbourProc);
00213 interProcBFaces[ownerProc].append(SLList<label>(facei));
00214
00215
00216 interProcBoundaries[neighbourProc].append(ownerProc);
00217 interProcBFaces[neighbourProc].append(SLList<label>(facei));
00218 }
00219 }
00220 }
00221
00222
00223
00224
00225
00226
00227
00228 forAll (procPatchSize_, procI)
00229 {
00230 procPatchSize_[procI].setSize(patches.size());
00231 procPatchStartIndex_[procI].setSize(patches.size());
00232 }
00233
00234 forAll (patches, patchi)
00235 {
00236
00237 forAll (procPatchSize_, procI)
00238 {
00239 procPatchSize_[procI][patchi] = 0;
00240 procPatchStartIndex_[procI][patchi] =
00241 procFaceList[procI].size();
00242 }
00243
00244 const label patchStart = patches[patchi].start();
00245
00246 if (typeid(patches[patchi]) != typeid(cyclicPolyPatch))
00247 {
00248
00249
00250
00251 const unallocLabelList& patchFaceCells =
00252 patches[patchi].faceCells();
00253
00254 forAll (patchFaceCells, facei)
00255 {
00256 const label curProc = cellToProc_[patchFaceCells[facei]];
00257
00258
00259 procFaceList[curProc].append(patchStart + facei);
00260
00261
00262 procPatchSize_[curProc][patchi]++;
00263 }
00264 }
00265 else
00266 {
00267
00268
00269 const polyPatch& cPatch = patches[patchi];
00270
00271 const label cycOffset = cPatch.size()/2;
00272
00273
00274 const labelList::subList firstFaceCells
00275 (
00276 cPatch.faceCells(),
00277 cycOffset
00278 );
00279
00280 const labelList::subList secondFaceCells
00281 (
00282 cPatch.faceCells(),
00283 cycOffset,
00284 cycOffset
00285 );
00286
00287 forAll (firstFaceCells, facei)
00288 {
00289 if
00290 (
00291 cellToProc_[firstFaceCells[facei]]
00292 != cellToProc_[secondFaceCells[facei]]
00293 )
00294 {
00295
00296
00297
00298
00299
00300
00301 cyclicParallel_ = true;
00302
00303 label ownerProc = cellToProc_[firstFaceCells[facei]];
00304 label neighbourProc =
00305 cellToProc_[secondFaceCells[facei]];
00306
00307 SLList<label>::iterator curInterProcBdrsOwnIter =
00308 interProcBoundaries[ownerProc].begin();
00309
00310 SLList<SLList<label> >::iterator
00311 curInterProcBFacesOwnIter =
00312 interProcBFaces[ownerProc].begin();
00313
00314 bool interProcBouFound = false;
00315
00316
00317
00318 for
00319 (
00320 ;
00321 curInterProcBdrsOwnIter !=
00322 interProcBoundaries[ownerProc].end()
00323 && curInterProcBFacesOwnIter !=
00324 interProcBFaces[ownerProc].end();
00325 ++curInterProcBdrsOwnIter,
00326 ++curInterProcBFacesOwnIter
00327 )
00328 {
00329 if (curInterProcBdrsOwnIter() == neighbourProc)
00330 {
00331
00332
00333 interProcBouFound = true;
00334
00335 curInterProcBFacesOwnIter().append
00336 (patchStart + facei);
00337
00338 SLList<label>::iterator curInterProcBdrsNeiIter
00339 = interProcBoundaries[neighbourProc].begin();
00340
00341 SLList<SLList<label> >::iterator
00342 curInterProcBFacesNeiIter =
00343 interProcBFaces[neighbourProc].begin();
00344
00345 bool neighbourFound = false;
00346
00347
00348
00349 for
00350 (
00351 ;
00352 curInterProcBdrsNeiIter
00353 != interProcBoundaries[neighbourProc].end()
00354 && curInterProcBFacesNeiIter
00355 != interProcBFaces[neighbourProc].end();
00356 ++curInterProcBdrsNeiIter,
00357 ++curInterProcBFacesNeiIter
00358 )
00359 {
00360 if (curInterProcBdrsNeiIter() == ownerProc)
00361 {
00362
00363 neighbourFound = true;
00364
00365 curInterProcBFacesNeiIter()
00366 .append
00367 (
00368 patchStart
00369 + cycOffset
00370 + facei
00371 );
00372 }
00373
00374 if (neighbourFound) break;
00375 }
00376
00377 if (interProcBouFound && !neighbourFound)
00378 {
00379 FatalErrorIn
00380 (
00381 "domainDecomposition::decomposeMesh()"
00382 ) << "Inconsistency in inter-processor "
00383 << "boundary lists for processors "
00384 << ownerProc << " and " << neighbourProc
00385 << " in cyclic boundary matching"
00386 << abort(FatalError);
00387 }
00388 }
00389
00390 if (interProcBouFound) break;
00391 }
00392
00393 if (!interProcBouFound)
00394 {
00395
00396
00397
00398
00399
00400
00401 interProcBoundaries[ownerProc]
00402 .append(neighbourProc);
00403 interProcBFaces[ownerProc]
00404 .append(SLList<label>(patchStart + facei));
00405
00406
00407 interProcBoundaries[neighbourProc]
00408 .append(ownerProc);
00409 interProcBFaces[neighbourProc]
00410 .append
00411 (
00412 SLList<label>
00413 (
00414 patchStart
00415 + cycOffset
00416 + facei
00417 )
00418 );
00419 }
00420 }
00421 else
00422 {
00423
00424 label ownerProc = cellToProc_[firstFaceCells[facei]];
00425
00426
00427 procFaceList[ownerProc].append(patchStart + facei);
00428
00429
00430 procPatchSize_[ownerProc][patchi]++;
00431
00432
00433
00434
00435
00436 }
00437 }
00438
00439
00440
00441
00442 forAll (secondFaceCells, facei)
00443 {
00444 if
00445 (
00446 cellToProc_[firstFaceCells[facei]]
00447 == cellToProc_[secondFaceCells[facei]]
00448 )
00449 {
00450
00451 label ownerProc = cellToProc_[firstFaceCells[facei]];
00452
00453
00454 procFaceList[ownerProc].append
00455 (patchStart + cycOffset + facei);
00456
00457
00458 procPatchSize_[ownerProc][patchi]++;
00459 }
00460 }
00461 }
00462 }
00463
00464
00465
00466 forAll (procFaceList, procI)
00467 {
00468
00469 SLList<label>& curProcFaces = procFaceList[procI];
00470
00471
00472 labelList& curProcFaceAddressing = procFaceAddressing_[procI];
00473
00474 labelList& curProcNeighbourProcessors =
00475 procNeighbourProcessors_[procI];
00476
00477 labelList& curProcProcessorPatchSize =
00478 procProcessorPatchSize_[procI];
00479
00480 labelList& curProcProcessorPatchStartIndex =
00481 procProcessorPatchStartIndex_[procI];
00482
00483
00484 label nFacesOnProcessor = curProcFaces.size();
00485
00486 for
00487 (
00488 SLList<SLList<label> >::iterator curInterProcBFacesIter =
00489 interProcBFaces[procI].begin();
00490 curInterProcBFacesIter != interProcBFaces[procI].end();
00491 ++curInterProcBFacesIter
00492 )
00493 {
00494 nFacesOnProcessor += curInterProcBFacesIter().size();
00495 }
00496
00497 curProcFaceAddressing.setSize(nFacesOnProcessor);
00498
00499
00500
00501
00502
00503
00504
00505 label nFaces = 0;
00506
00507
00508
00509
00510 for
00511 (
00512 SLList<label>::iterator curProcFacesIter = curProcFaces.begin();
00513 curProcFacesIter != curProcFaces.end();
00514 ++curProcFacesIter
00515 )
00516 {
00517 curProcFaceAddressing[nFaces] = curProcFacesIter() + 1;
00518 nFaces++;
00519 }
00520
00521
00522
00523
00524 curProcNeighbourProcessors.setSize
00525 (
00526 interProcBoundaries[procI].size()
00527 );
00528
00529 curProcProcessorPatchSize.setSize
00530 (
00531 interProcBoundaries[procI].size()
00532 );
00533
00534 curProcProcessorPatchStartIndex.setSize
00535 (
00536 interProcBoundaries[procI].size()
00537 );
00538
00539 label nProcPatches = 0;
00540
00541 SLList<label>::iterator curInterProcBdrsIter =
00542 interProcBoundaries[procI].begin();
00543
00544 SLList<SLList<label> >::iterator curInterProcBFacesIter =
00545 interProcBFaces[procI].begin();
00546
00547 for
00548 (
00549 ;
00550 curInterProcBdrsIter != interProcBoundaries[procI].end()
00551 && curInterProcBFacesIter != interProcBFaces[procI].end();
00552 ++curInterProcBdrsIter, ++curInterProcBFacesIter
00553 )
00554 {
00555 curProcNeighbourProcessors[nProcPatches] =
00556 curInterProcBdrsIter();
00557
00558
00559 curProcProcessorPatchStartIndex[nProcPatches] = nFaces;
00560
00561 label& curSize =
00562 curProcProcessorPatchSize[nProcPatches];
00563
00564 curSize = 0;
00565
00566
00567
00568 for
00569 (
00570 SLList<label>::iterator curFacesIter =
00571 curInterProcBFacesIter().begin();
00572 curFacesIter != curInterProcBFacesIter().end();
00573 ++curFacesIter
00574 )
00575 {
00576
00577
00578
00579
00580 if (cellToProc_[owner[curFacesIter()]] == procI)
00581 {
00582 curProcFaceAddressing[nFaces] = curFacesIter() + 1;
00583 }
00584 else
00585 {
00586
00587 curProcFaceAddressing[nFaces] = -(curFacesIter() + 1);
00588 }
00589
00590
00591 curSize++;
00592
00593 nFaces++;
00594 }
00595
00596 nProcPatches++;
00597 }
00598 }
00599 }
00600
00601 Info << "\nCalculating processor boundary addressing" << endl;
00602
00603
00604
00605
00606
00607 forAll (procPatchSize_, procI)
00608 {
00609
00610 const labelList oldPatchSizes = procPatchSize_[procI];
00611
00612 const labelList oldPatchStarts = procPatchStartIndex_[procI];
00613
00614 labelList& curPatchSizes = procPatchSize_[procI];
00615
00616 labelList& curPatchStarts = procPatchStartIndex_[procI];
00617
00618 const labelList& curProcessorPatchSizes =
00619 procProcessorPatchSize_[procI];
00620
00621 labelList& curBoundaryAddressing = procBoundaryAddressing_[procI];
00622
00623 curBoundaryAddressing.setSize
00624 (
00625 oldPatchSizes.size()
00626 + curProcessorPatchSizes.size()
00627 );
00628
00629 label nPatches = 0;
00630
00631 forAll (oldPatchSizes, patchi)
00632 {
00633 if (!filterEmptyPatches || oldPatchSizes[patchi] > 0)
00634 {
00635 curBoundaryAddressing[nPatches] = patchi;
00636
00637 curPatchSizes[nPatches] = oldPatchSizes[patchi];
00638
00639 curPatchStarts[nPatches] = oldPatchStarts[patchi];
00640
00641 nPatches++;
00642 }
00643 }
00644
00645
00646 curPatchSizes.setSize(nPatches);
00647 curPatchStarts.setSize(nPatches);
00648
00649 forAll (curProcessorPatchSizes, procPatchI)
00650 {
00651 curBoundaryAddressing[nPatches] = -1;
00652
00653 nPatches++;
00654 }
00655
00656 curBoundaryAddressing.setSize(nPatches);
00657 }
00658
00659 Info << "\nDistributing points to processors" << endl;
00660
00661
00662
00663
00664
00665 forAll (procPointAddressing_, procI)
00666 {
00667 boolList pointLabels(nPoints(), false);
00668
00669
00670 const labelList& procFaceLabels = procFaceAddressing_[procI];
00671
00672 forAll (procFaceLabels, facei)
00673 {
00674
00675 const labelList& facePoints = fcs[mag(procFaceLabels[facei]) - 1];
00676
00677 forAll (facePoints, pointi)
00678 {
00679
00680 pointLabels[facePoints[pointi]] = true;
00681 }
00682 }
00683
00684
00685 labelList& procPointLabels = procPointAddressing_[procI];
00686
00687 procPointLabels.setSize(pointLabels.size());
00688
00689 label nUsedPoints = 0;
00690
00691 forAll (pointLabels, pointi)
00692 {
00693 if (pointLabels[pointi])
00694 {
00695 procPointLabels[nUsedPoints] = pointi;
00696
00697 nUsedPoints++;
00698 }
00699 }
00700
00701
00702 procPointLabels.setSize(nUsedPoints);
00703 }
00704
00705
00706
00707
00708 {
00709 labelList pointsUsage(nPoints(), 0);
00710
00711
00712
00713 labelHashSet gSharedPoints
00714 (
00715 min(100, nPoints()/1000)
00716 );
00717
00718
00719
00720
00721
00722 for (label procI = 0; procI < nProcs_; procI++)
00723 {
00724
00725 const labelList& curFaceLabels = procFaceAddressing_[procI];
00726
00727
00728 const labelList& curProcessorPatchStarts =
00729 procProcessorPatchStartIndex_[procI];
00730
00731 const labelList& curProcessorPatchSizes =
00732 procProcessorPatchSize_[procI];
00733
00734
00735 pointsUsage = 0;
00736
00737 forAll (curProcessorPatchStarts, patchi)
00738 {
00739 const label curStart = curProcessorPatchStarts[patchi];
00740 const label curEnd = curStart + curProcessorPatchSizes[patchi];
00741
00742 for
00743 (
00744 label facei = curStart;
00745 facei < curEnd;
00746 facei++
00747 )
00748 {
00749
00750
00751
00752 const label curF = mag(curFaceLabels[facei]) - 1;
00753
00754 const face& f = fcs[curF];
00755
00756 forAll (f, pointi)
00757 {
00758 if (pointsUsage[f[pointi]] == 0)
00759 {
00760
00761 pointsUsage[f[pointi]] = patchi + 1;
00762 }
00763 else if (pointsUsage[f[pointi]] != patchi + 1)
00764 {
00765
00766 gSharedPoints.insert(f[pointi]);
00767 }
00768 }
00769 }
00770 }
00771 }
00772
00773
00774 globallySharedPoints_ = gSharedPoints.toc();
00775 sort(globallySharedPoints_);
00776 }
00777 }
Copyright © 2000-2009 OpenCFD Ltd