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
00035 #include "fvMeshSubset.H"
00036 #include "boolList.H"
00037 #include "Pstream.H"
00038 #include "emptyPolyPatch.H"
00039 #include "demandDrivenData.H"
00040 #include "cyclicPolyPatch.H"
00041
00042
00043
00044 namespace Foam
00045 {
00046
00047
00048
00049 bool Foam::fvMeshSubset::checkCellSubset() const
00050 {
00051 if (fvMeshSubsetPtr_.empty())
00052 {
00053 FatalErrorIn("bool fvMeshSubset::checkCellSubset() const")
00054 << "Mesh subset not set. Please set the cell map using "
00055 << "void setCellSubset(const labelHashSet& cellsToSubset)" << endl
00056 << "before attempting to access subset data"
00057 << abort(FatalError);
00058
00059 return false;
00060 }
00061 else
00062 {
00063 return true;
00064 }
00065 }
00066
00067
00068 void Foam::fvMeshSubset::markPoints
00069 (
00070 const labelList& curPoints,
00071 Map<label>& pointMap
00072 )
00073 {
00074 forAll (curPoints, pointI)
00075 {
00076
00077 pointMap.insert(curPoints[pointI], 0);
00078 }
00079 }
00080
00081
00082 void Foam::fvMeshSubset::markPoints
00083 (
00084 const labelList& curPoints,
00085 labelList& pointMap
00086 )
00087 {
00088 forAll (curPoints, pointI)
00089 {
00090 pointMap[curPoints[pointI]] = 0;
00091 }
00092 }
00093
00094
00095
00096
00097 void Foam::fvMeshSubset::doCoupledPatches
00098 (
00099 const bool syncPar,
00100 labelList& nCellsUsingFace
00101 ) const
00102 {
00103 const polyBoundaryMesh& oldPatches = baseMesh().boundaryMesh();
00104
00105 label nUncoupled = 0;
00106
00107 if (syncPar && Pstream::parRun())
00108 {
00109
00110 forAll (oldPatches, oldPatchI)
00111 {
00112 const polyPatch& pp = oldPatches[oldPatchI];
00113
00114 if (typeid(pp) == typeid(processorPolyPatch))
00115 {
00116 const processorPolyPatch& procPatch =
00117 refCast<const processorPolyPatch>(pp);
00118
00119 OPstream toNeighbour
00120 (
00121 Pstream::blocking,
00122 procPatch.neighbProcNo()
00123 );
00124
00125 toNeighbour
00126 << SubList<label>(nCellsUsingFace, pp.size(), pp.start());
00127 }
00128 }
00129
00130
00131
00132 forAll (oldPatches, oldPatchI)
00133 {
00134 const polyPatch& pp = oldPatches[oldPatchI];
00135
00136 if (typeid(pp) == typeid(processorPolyPatch))
00137 {
00138 const processorPolyPatch& procPatch =
00139 refCast<const processorPolyPatch>(pp);
00140
00141 IPstream fromNeighbour
00142 (
00143 Pstream::blocking,
00144 procPatch.neighbProcNo()
00145 );
00146
00147 labelList nbrCellsUsingFace(fromNeighbour);
00148
00149
00150
00151 forAll (pp, i)
00152 {
00153 if
00154 (
00155 nCellsUsingFace[pp.start()+i] == 1
00156 && nbrCellsUsingFace[i] == 0
00157 )
00158 {
00159
00160
00161 nCellsUsingFace[pp.start()+i] = 3;
00162 nUncoupled++;
00163 }
00164 }
00165 }
00166 }
00167 }
00168
00169
00170 forAll (oldPatches, oldPatchI)
00171 {
00172 const polyPatch& pp = oldPatches[oldPatchI];
00173
00174 if (typeid(pp) == typeid(cyclicPolyPatch))
00175 {
00176 const cyclicPolyPatch& cycPatch =
00177 refCast<const cyclicPolyPatch>(pp);
00178
00179 forAll (cycPatch, i)
00180 {
00181 label thisFaceI = cycPatch.start() + i;
00182 label otherFaceI = cycPatch.transformGlobalFace(thisFaceI);
00183
00184 if
00185 (
00186 nCellsUsingFace[thisFaceI] == 1
00187 && nCellsUsingFace[otherFaceI] == 0
00188 )
00189 {
00190 nCellsUsingFace[thisFaceI] = 3;
00191 nUncoupled++;
00192 }
00193 }
00194 }
00195 }
00196
00197 if (syncPar)
00198 {
00199 reduce(nUncoupled, sumOp<label>());
00200 }
00201
00202 if (nUncoupled > 0)
00203 {
00204 Info<< "Uncoupled " << nUncoupled << " faces on coupled patches. "
00205 << "(processorPolyPatch, cyclicPolyPatch)" << nl
00206 << "You might need to run couplePatches to restore the patch face"
00207 << " ordering." << nl << endl;
00208 }
00209 }
00210
00211
00212 labelList Foam::fvMeshSubset::subset
00213 (
00214 const label nElems,
00215 const labelList& selectedElements,
00216 const labelList& subsetMap
00217 )
00218 {
00219
00220 boolList selected(nElems, false);
00221 forAll(selectedElements, i)
00222 {
00223 selected[selectedElements[i]] = true;
00224 }
00225
00226
00227 label n = 0;
00228 forAll(subsetMap, i)
00229 {
00230 if (selected[subsetMap[i]])
00231 {
00232 n++;
00233 }
00234 }
00235
00236
00237 labelList subsettedElements(n);
00238 n = 0;
00239
00240 forAll(subsetMap, i)
00241 {
00242 if (selected[subsetMap[i]])
00243 {
00244 subsettedElements[n++] = i;
00245 }
00246 }
00247
00248 return subsettedElements;
00249 }
00250
00251
00252 void Foam::fvMeshSubset::subsetZones()
00253 {
00254
00255
00256 const pointZoneMesh& pointZones = baseMesh().pointZones();
00257
00258
00259 List<pointZone*> pZonePtrs(pointZones.size());
00260
00261 forAll(pointZones, i)
00262 {
00263 const pointZone& pz = pointZones[i];
00264
00265 pZonePtrs[i] = new pointZone
00266 (
00267 pz.name(),
00268 subset(baseMesh().nPoints(), pz, pointMap()),
00269 i,
00270 fvMeshSubsetPtr_().pointZones()
00271 );
00272 }
00273
00274
00275
00276
00277 const faceZoneMesh& faceZones = baseMesh().faceZones();
00278
00279
00280
00281
00282 List<faceZone*> fZonePtrs(faceZones.size());
00283
00284 forAll(faceZones, i)
00285 {
00286 const faceZone& fz = faceZones[i];
00287
00288
00289 labelList subAddressing
00290 (
00291 subset
00292 (
00293 baseMesh().nFaces(),
00294 fz,
00295 faceMap()
00296 )
00297 );
00298
00299
00300 boolList fullFlipStatus(baseMesh().nFaces(), false);
00301 forAll(fz, j)
00302 {
00303 fullFlipStatus[fz[j]] = fz.flipMap()[j];
00304 }
00305
00306 boolList subFlipStatus(subAddressing.size(), false);
00307 forAll(subAddressing, j)
00308 {
00309 subFlipStatus[j] = fullFlipStatus[faceMap()[subAddressing[j]]];
00310 }
00311
00312 fZonePtrs[i] = new faceZone
00313 (
00314 fz.name(),
00315 subAddressing,
00316 subFlipStatus,
00317 i,
00318 fvMeshSubsetPtr_().faceZones()
00319 );
00320 }
00321
00322
00323 const cellZoneMesh& cellZones = baseMesh().cellZones();
00324
00325 List<cellZone*> cZonePtrs(cellZones.size());
00326
00327 forAll(cellZones, i)
00328 {
00329 const cellZone& cz = cellZones[i];
00330
00331 cZonePtrs[i] = new cellZone
00332 (
00333 cz.name(),
00334 subset(baseMesh().nCells(), cz, cellMap()),
00335 i,
00336 fvMeshSubsetPtr_().cellZones()
00337 );
00338 }
00339
00340
00341
00342 fvMeshSubsetPtr_().addZones(pZonePtrs, fZonePtrs, cZonePtrs);
00343 }
00344
00345
00346
00347
00348
00349 Foam::fvMeshSubset::fvMeshSubset(const fvMesh& baseMesh)
00350 :
00351 baseMesh_(baseMesh),
00352 fvMeshSubsetPtr_(NULL),
00353 pointMap_(0),
00354 faceMap_(0),
00355 cellMap_(0),
00356 patchMap_(0)
00357 {}
00358
00359
00360
00361
00362 void Foam::fvMeshSubset::setCellSubset
00363 (
00364 const labelHashSet& globalCellMap,
00365 const label patchID
00366 )
00367 {
00368
00369 const polyBoundaryMesh& oldPatches = baseMesh().boundaryMesh();
00370 const cellList& oldCells = baseMesh().cells();
00371 const faceList& oldFaces = baseMesh().faces();
00372 const pointField& oldPoints = baseMesh().points();
00373 const labelList& oldOwner = baseMesh().faceOwner();
00374 const labelList& oldNeighbour = baseMesh().faceNeighbour();
00375
00376 label wantedPatchID = patchID;
00377
00378 if (wantedPatchID == -1)
00379 {
00380
00381
00382 wantedPatchID = oldPatches.findPatchID("oldInternalFaces");
00383 }
00384 else if (wantedPatchID < 0 || wantedPatchID >= oldPatches.size())
00385 {
00386 FatalErrorIn
00387 (
00388 "fvMeshSubset::setCellSubset(const labelHashSet&"
00389 ", const label patchID)"
00390 ) << "Non-existing patch index " << wantedPatchID << endl
00391 << "Should be between 0 and " << oldPatches.size()-1
00392 << abort(FatalError);
00393 }
00394
00395
00396 cellMap_ = globalCellMap.toc();
00397
00398
00399 sort(cellMap_);
00400
00401
00402 const label avgNFacesPerCell = 6;
00403 const label avgNPointsPerFace = 4;
00404
00405
00406 label nCellsInSet = cellMap_.size();
00407
00408
00409
00410 Map<label> facesToSubset(avgNFacesPerCell*nCellsInSet);
00411
00412 forAll (cellMap_, cellI)
00413 {
00414
00415 const labelList& curFaces = oldCells[cellMap_[cellI]];
00416
00417 forAll (curFaces, faceI)
00418 {
00419 if (!facesToSubset.found(curFaces[faceI]))
00420 {
00421 facesToSubset.insert(curFaces[faceI], 1);
00422 }
00423 else
00424 {
00425 facesToSubset[curFaces[faceI]]++;
00426 }
00427 }
00428 }
00429
00430
00431 Map<label> globalFaceMap(facesToSubset.size());
00432
00433
00434 Map<label> globalPointMap(avgNPointsPerFace*facesToSubset.size());
00435
00436
00437
00438
00439 labelList facesToc = facesToSubset.toc();
00440 sort(facesToc);
00441 faceMap_.setSize(facesToc.size());
00442
00443
00444 forAll (facesToc, faceI)
00445 {
00446 if (facesToSubset[facesToc[faceI]] == 2)
00447 {
00448
00449 faceMap_[globalFaceMap.size()] = facesToc[faceI];
00450 globalFaceMap.insert(facesToc[faceI], globalFaceMap.size());
00451
00452
00453 markPoints(oldFaces[facesToc[faceI]], globalPointMap);
00454 }
00455 }
00456
00457
00458 label nInternalFaces = globalFaceMap.size();
00459
00460
00461
00462 label oldPatchStart = labelMax;
00463 if (wantedPatchID != -1)
00464 {
00465 oldPatchStart = oldPatches[wantedPatchID].start();
00466 }
00467
00468
00469 label faceI = 0;
00470
00471
00472 for (; faceI< facesToc.size(); faceI++)
00473 {
00474 if (facesToc[faceI] >= oldPatchStart)
00475 {
00476 break;
00477 }
00478 if
00479 (
00480 !baseMesh().isInternalFace(facesToc[faceI])
00481 && facesToSubset[facesToc[faceI]] == 1
00482 )
00483 {
00484
00485 faceMap_[globalFaceMap.size()] = facesToc[faceI];
00486 globalFaceMap.insert(facesToc[faceI], globalFaceMap.size());
00487
00488
00489 markPoints(oldFaces[facesToc[faceI]], globalPointMap);
00490 }
00491 }
00492
00493
00494 forAll(facesToc, intFaceI)
00495 {
00496 if
00497 (
00498 baseMesh().isInternalFace(facesToc[intFaceI])
00499 && facesToSubset[facesToc[intFaceI]] == 1
00500 )
00501 {
00502
00503 faceMap_[globalFaceMap.size()] = facesToc[intFaceI];
00504 globalFaceMap.insert(facesToc[intFaceI], globalFaceMap.size());
00505
00506
00507 markPoints(oldFaces[facesToc[intFaceI]], globalPointMap);
00508 }
00509 }
00510
00511
00512 for (; faceI< facesToc.size(); faceI++)
00513 {
00514 if
00515 (
00516 !baseMesh().isInternalFace(facesToc[faceI])
00517 && facesToSubset[facesToc[faceI]] == 1
00518 )
00519 {
00520
00521 faceMap_[globalFaceMap.size()] = facesToc[faceI];
00522 globalFaceMap.insert(facesToc[faceI], globalFaceMap.size());
00523
00524
00525 markPoints(oldFaces[facesToc[faceI]], globalPointMap);
00526 }
00527 }
00528
00529
00530
00531
00532 pointMap_ = globalPointMap.toc();
00533 sort(pointMap_);
00534
00535 forAll (pointMap_, pointI)
00536 {
00537 globalPointMap[pointMap_[pointI]] = pointI;
00538 }
00539
00540 Pout << "Number of cells in new mesh: " << nCellsInSet << endl;
00541 Pout << "Number of faces in new mesh: " << globalFaceMap.size() << endl;
00542 Pout << "Number of points in new mesh: " << globalPointMap.size() << endl;
00543
00544
00545 pointField newPoints(globalPointMap.size());
00546
00547 label nNewPoints = 0;
00548
00549 forAll (pointMap_, pointI)
00550 {
00551 newPoints[nNewPoints] = oldPoints[pointMap_[pointI]];
00552 nNewPoints++;
00553 }
00554
00555 faceList newFaces(globalFaceMap.size());
00556
00557 label nNewFaces = 0;
00558
00559
00560 for (label faceI = 0; faceI < nInternalFaces; faceI++)
00561 {
00562 const face& oldF = oldFaces[faceMap_[faceI]];
00563
00564 face newF(oldF.size());
00565
00566 forAll (newF, i)
00567 {
00568 newF[i] = globalPointMap[oldF[i]];
00569 }
00570
00571 newFaces[nNewFaces] = newF;
00572 nNewFaces++;
00573 }
00574
00575
00576
00577 label nbSize = oldPatches.size();
00578 label oldInternalPatchID = -1;
00579
00580 if (wantedPatchID == -1)
00581 {
00582
00583
00584 oldInternalPatchID = nbSize;
00585 nbSize++;
00586
00587 }
00588 else
00589 {
00590 oldInternalPatchID = wantedPatchID;
00591 }
00592
00593
00594
00595
00596
00597 labelList boundaryPatchSizes(nbSize, 0);
00598
00599
00600 for (label faceI = nInternalFaces; faceI < faceMap_.size(); faceI++)
00601 {
00602 label oldFaceI = faceMap_[faceI];
00603
00604 face oldF = oldFaces[oldFaceI];
00605
00606
00607 if (baseMesh().isInternalFace(oldFaceI))
00608 {
00609
00610 if
00611 (
00612 !globalCellMap.found(oldOwner[oldFaceI])
00613 && globalCellMap.found(oldNeighbour[oldFaceI])
00614 )
00615 {
00616 oldF = oldFaces[oldFaceI].reverseFace();
00617 }
00618
00619
00620 boundaryPatchSizes[oldInternalPatchID]++;
00621 }
00622 else
00623 {
00624
00625 label patchOfFace = oldPatches.whichPatch(oldFaceI);
00626
00627
00628 boundaryPatchSizes[patchOfFace]++;
00629 }
00630
00631 face newF(oldF.size());
00632
00633 forAll (newF, i)
00634 {
00635 newF[i] = globalPointMap[oldF[i]];
00636 }
00637
00638 newFaces[nNewFaces] = newF;
00639 nNewFaces++;
00640 }
00641
00642
00643
00644
00645 cellList newCells(nCellsInSet);
00646
00647 label nNewCells = 0;
00648
00649 forAll (cellMap_, cellI)
00650 {
00651 const labelList& oldC = oldCells[cellMap_[cellI]];
00652
00653 labelList newC(oldC.size());
00654
00655 forAll (newC, i)
00656 {
00657 newC[i] = globalFaceMap[oldC[i]];
00658 }
00659
00660 newCells[nNewCells] = cell(newC);
00661 nNewCells++;
00662 }
00663
00664
00665
00666 fvMeshSubsetPtr_.reset
00667 (
00668 new fvMesh
00669 (
00670 IOobject
00671 (
00672 baseMesh().name() + "SubSet",
00673 baseMesh().time().timeName(),
00674 baseMesh().time(),
00675 IOobject::NO_READ,
00676 IOobject::NO_WRITE
00677 ),
00678 xferMove(newPoints),
00679 xferMove(newFaces),
00680 xferMove(newCells)
00681 )
00682 );
00683
00684
00685
00686 List<polyPatch*> newBoundary(nbSize);
00687 patchMap_.setSize(nbSize);
00688 label nNewPatches = 0;
00689 label patchStart = nInternalFaces;
00690
00691 forAll(oldPatches, patchI)
00692 {
00693 if (boundaryPatchSizes[patchI] > 0)
00694 {
00695
00696 newBoundary[nNewPatches] = oldPatches[patchI].clone
00697 (
00698 fvMeshSubsetPtr_().boundaryMesh(),
00699 nNewPatches,
00700 boundaryPatchSizes[patchI],
00701 patchStart
00702 ).ptr();
00703
00704 patchStart += boundaryPatchSizes[patchI];
00705 patchMap_[nNewPatches] = patchI;
00706 nNewPatches++;
00707 }
00708 }
00709
00710 if (wantedPatchID == -1)
00711 {
00712
00713 if (boundaryPatchSizes[oldInternalPatchID] > 0)
00714 {
00715 newBoundary[nNewPatches] = new emptyPolyPatch
00716 (
00717 "oldInternalFaces",
00718 boundaryPatchSizes[oldInternalPatchID],
00719 patchStart,
00720 nNewPatches,
00721 fvMeshSubsetPtr_().boundaryMesh()
00722 );
00723
00724
00725
00726 patchMap_[nNewPatches] = -1;
00727 nNewPatches++;
00728 }
00729 }
00730
00731
00732 newBoundary.setSize(nNewPatches);
00733 patchMap_.setSize(nNewPatches);
00734
00735
00736 fvMeshSubsetPtr_().addFvPatches(newBoundary);
00737
00738
00739 subsetZones();
00740 }
00741
00742
00743 void Foam::fvMeshSubset::setLargeCellSubset
00744 (
00745 const labelList& region,
00746 const label currentRegion,
00747 const label patchID,
00748 const bool syncPar
00749 )
00750 {
00751 const cellList& oldCells = baseMesh().cells();
00752 const faceList& oldFaces = baseMesh().faces();
00753 const pointField& oldPoints = baseMesh().points();
00754 const labelList& oldOwner = baseMesh().faceOwner();
00755 const labelList& oldNeighbour = baseMesh().faceNeighbour();
00756 const polyBoundaryMesh& oldPatches = baseMesh().boundaryMesh();
00757 const label oldNInternalFaces = baseMesh().nInternalFaces();
00758
00759
00760
00761 if (region.size() != oldCells.size())
00762 {
00763 FatalErrorIn
00764 (
00765 "fvMeshSubset::setCellSubset(const labelList&"
00766 ", const label, const label, const bool)"
00767 ) << "Size of region " << region.size()
00768 << " is not equal to number of cells in mesh " << oldCells.size()
00769 << abort(FatalError);
00770 }
00771
00772
00773 label wantedPatchID = patchID;
00774
00775 if (wantedPatchID == -1)
00776 {
00777
00778
00779 wantedPatchID = oldPatches.findPatchID("oldInternalFaces");
00780 }
00781 else if (wantedPatchID < 0 || wantedPatchID >= oldPatches.size())
00782 {
00783 FatalErrorIn
00784 (
00785 "fvMeshSubset::setCellSubset(const labelList&"
00786 ", const label, const label, const bool)"
00787 ) << "Non-existing patch index " << wantedPatchID << endl
00788 << "Should be between 0 and " << oldPatches.size()-1
00789 << abort(FatalError);
00790 }
00791
00792
00793
00794 cellMap_.setSize(oldCells.size());
00795 label nCellsInSet = 0;
00796
00797 forAll (region, oldCellI)
00798 {
00799 if (region[oldCellI] == currentRegion)
00800 {
00801 cellMap_[nCellsInSet++] = oldCellI;
00802 }
00803 }
00804 cellMap_.setSize(nCellsInSet);
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817 labelList nCellsUsingFace(oldFaces.size(), 0);
00818
00819 label nFacesInSet = 0;
00820 forAll (oldFaces, oldFaceI)
00821 {
00822 bool faceUsed = false;
00823
00824 if (region[oldOwner[oldFaceI]] == currentRegion)
00825 {
00826 nCellsUsingFace[oldFaceI]++;
00827 faceUsed = true;
00828 }
00829
00830 if
00831 (
00832 baseMesh().isInternalFace(oldFaceI)
00833 && (region[oldNeighbour[oldFaceI]] == currentRegion)
00834 )
00835 {
00836 nCellsUsingFace[oldFaceI]++;
00837 faceUsed = true;
00838 }
00839
00840 if (faceUsed)
00841 {
00842 nFacesInSet++;
00843 }
00844 }
00845 faceMap_.setSize(nFacesInSet);
00846
00847
00848 doCoupledPatches(syncPar, nCellsUsingFace);
00849
00850
00851
00852 label oldInternalPatchID = 0;
00853
00854
00855 label nextPatchID = oldPatches.size();
00856
00857
00858 labelList globalPatchMap(oldPatches.size());
00859
00860
00861 label nbSize = oldPatches.size();
00862
00863 if (wantedPatchID == -1)
00864 {
00865
00866
00867
00868
00869 forAll(oldPatches, patchI)
00870 {
00871 if (isA<processorPolyPatch>(oldPatches[patchI]))
00872 {
00873 nextPatchID = patchI;
00874 break;
00875 }
00876 oldInternalPatchID++;
00877 }
00878
00879 nbSize++;
00880
00881
00882 for (label oldPatchI = 0; oldPatchI < nextPatchID; oldPatchI++)
00883 {
00884 globalPatchMap[oldPatchI] = oldPatchI;
00885 }
00886 for
00887 (
00888 label oldPatchI = nextPatchID;
00889 oldPatchI < oldPatches.size();
00890 oldPatchI++
00891 )
00892 {
00893 globalPatchMap[oldPatchI] = oldPatchI+1;
00894 }
00895 }
00896 else
00897 {
00898 oldInternalPatchID = wantedPatchID;
00899 nextPatchID = wantedPatchID+1;
00900
00901
00902 globalPatchMap = identity(oldPatches.size());
00903 }
00904
00905 labelList boundaryPatchSizes(nbSize, 0);
00906
00907
00908
00909 labelList globalPointMap(oldPoints.size(), -1);
00910
00911 labelList globalFaceMap(oldFaces.size(), -1);
00912 label faceI = 0;
00913
00914
00915 for (label oldFaceI = 0; oldFaceI < oldNInternalFaces; oldFaceI++)
00916 {
00917 if (nCellsUsingFace[oldFaceI] == 2)
00918 {
00919 globalFaceMap[oldFaceI] = faceI;
00920 faceMap_[faceI++] = oldFaceI;
00921
00922
00923 markPoints(oldFaces[oldFaceI], globalPointMap);
00924 }
00925 }
00926
00927
00928 label nInternalFaces = faceI;
00929
00930
00931 for
00932 (
00933 label oldPatchI = 0;
00934 oldPatchI < oldPatches.size()
00935 && oldPatchI < nextPatchID;
00936 oldPatchI++
00937 )
00938 {
00939 const polyPatch& oldPatch = oldPatches[oldPatchI];
00940
00941 label oldFaceI = oldPatch.start();
00942
00943 forAll (oldPatch, i)
00944 {
00945 if (nCellsUsingFace[oldFaceI] == 1)
00946 {
00947
00948
00949
00950 globalFaceMap[oldFaceI] = faceI;
00951 faceMap_[faceI++] = oldFaceI;
00952
00953
00954 markPoints(oldFaces[oldFaceI], globalPointMap);
00955
00956
00957 boundaryPatchSizes[globalPatchMap[oldPatchI]]++;
00958 }
00959 oldFaceI++;
00960 }
00961 }
00962
00963
00964 for (label oldFaceI = 0; oldFaceI < oldNInternalFaces; oldFaceI++)
00965 {
00966 if (nCellsUsingFace[oldFaceI] == 1)
00967 {
00968 globalFaceMap[oldFaceI] = faceI;
00969 faceMap_[faceI++] = oldFaceI;
00970
00971
00972 markPoints(oldFaces[oldFaceI], globalPointMap);
00973
00974
00975 boundaryPatchSizes[oldInternalPatchID]++;
00976 }
00977 }
00978
00979
00980 for
00981 (
00982 label oldFaceI = oldNInternalFaces;
00983 oldFaceI < oldFaces.size();
00984 oldFaceI++
00985 )
00986 {
00987 if (nCellsUsingFace[oldFaceI] == 3)
00988 {
00989 globalFaceMap[oldFaceI] = faceI;
00990 faceMap_[faceI++] = oldFaceI;
00991
00992
00993 markPoints(oldFaces[oldFaceI], globalPointMap);
00994
00995
00996 boundaryPatchSizes[oldInternalPatchID]++;
00997 }
00998 }
00999
01000
01001 for
01002 (
01003 label oldPatchI = nextPatchID;
01004 oldPatchI < oldPatches.size();
01005 oldPatchI++
01006 )
01007 {
01008 const polyPatch& oldPatch = oldPatches[oldPatchI];
01009
01010 label oldFaceI = oldPatch.start();
01011
01012 forAll (oldPatch, i)
01013 {
01014 if (nCellsUsingFace[oldFaceI] == 1)
01015 {
01016
01017
01018
01019 globalFaceMap[oldFaceI] = faceI;
01020 faceMap_[faceI++] = oldFaceI;
01021
01022
01023 markPoints(oldFaces[oldFaceI], globalPointMap);
01024
01025
01026 boundaryPatchSizes[globalPatchMap[oldPatchI]]++;
01027 }
01028 oldFaceI++;
01029 }
01030 }
01031
01032 if (faceI != nFacesInSet)
01033 {
01034 FatalErrorIn
01035 (
01036 "fvMeshSubset::setCellSubset(const labelList&"
01037 ", const label, const label, const bool)"
01038 ) << "Problem" << abort(FatalError);
01039 }
01040
01041
01042
01043 label nPointsInSet = 0;
01044
01045 forAll(globalPointMap, pointI)
01046 {
01047 if (globalPointMap[pointI] != -1)
01048 {
01049 nPointsInSet++;
01050 }
01051 }
01052 pointMap_.setSize(nPointsInSet);
01053
01054 nPointsInSet = 0;
01055
01056 forAll(globalPointMap, pointI)
01057 {
01058 if (globalPointMap[pointI] != -1)
01059 {
01060 pointMap_[nPointsInSet] = pointI;
01061 globalPointMap[pointI] = nPointsInSet;
01062 nPointsInSet++;
01063 }
01064 }
01065
01066
01067
01068
01069
01070
01071 pointField newPoints(pointMap_.size());
01072
01073 label nNewPoints = 0;
01074
01075 forAll (pointMap_, pointI)
01076 {
01077 newPoints[nNewPoints] = oldPoints[pointMap_[pointI]];
01078 nNewPoints++;
01079 }
01080
01081 faceList newFaces(faceMap_.size());
01082
01083 label nNewFaces = 0;
01084
01085
01086 for (label faceI = 0; faceI < nInternalFaces; faceI++)
01087 {
01088 const face& oldF = oldFaces[faceMap_[faceI]];
01089
01090 face newF(oldF.size());
01091
01092 forAll (newF, i)
01093 {
01094 newF[i] = globalPointMap[oldF[i]];
01095 }
01096
01097 newFaces[nNewFaces] = newF;
01098 nNewFaces++;
01099 }
01100
01101
01102
01103
01104 for (label faceI = nInternalFaces; faceI < faceMap_.size(); faceI++)
01105 {
01106 label oldFaceI = faceMap_[faceI];
01107
01108 face oldF = oldFaces[oldFaceI];
01109
01110
01111 if (baseMesh().isInternalFace(oldFaceI))
01112 {
01113
01114 if
01115 (
01116 region[oldOwner[oldFaceI]] != currentRegion
01117 && region[oldNeighbour[oldFaceI]] == currentRegion
01118 )
01119 {
01120 oldF = oldFaces[oldFaceI].reverseFace();
01121 }
01122 }
01123
01124
01125 face newF(oldF.size());
01126
01127 forAll (newF, i)
01128 {
01129 newF[i] = globalPointMap[oldF[i]];
01130 }
01131
01132 newFaces[nNewFaces] = newF;
01133 nNewFaces++;
01134 }
01135
01136
01137
01138
01139 cellList newCells(nCellsInSet);
01140
01141 label nNewCells = 0;
01142
01143 forAll (cellMap_, cellI)
01144 {
01145 const labelList& oldC = oldCells[cellMap_[cellI]];
01146
01147 labelList newC(oldC.size());
01148
01149 forAll (newC, i)
01150 {
01151 newC[i] = globalFaceMap[oldC[i]];
01152 }
01153
01154 newCells[nNewCells] = cell(newC);
01155 nNewCells++;
01156 }
01157
01158
01159
01160
01161
01162
01163
01164 fvMeshSubsetPtr_.reset
01165 (
01166 new fvMesh
01167 (
01168 IOobject
01169 (
01170 baseMesh().name(),
01171 baseMesh().time().timeName(),
01172 baseMesh().time(),
01173 IOobject::NO_READ,
01174 IOobject::NO_WRITE
01175 ),
01176 xferMove(newPoints),
01177 xferMove(newFaces),
01178 xferMove(newCells),
01179 syncPar
01180 )
01181 );
01182
01183
01184 List<polyPatch*> newBoundary(nbSize);
01185 patchMap_.setSize(nbSize);
01186 label nNewPatches = 0;
01187 label patchStart = nInternalFaces;
01188
01189
01190
01191
01192
01193
01194
01195 labelList globalPatchSizes(boundaryPatchSizes);
01196 globalPatchSizes.setSize(nextPatchID);
01197
01198 if (syncPar && Pstream::parRun())
01199 {
01200
01201 List<wordList> patchNames(Pstream::nProcs());
01202 patchNames[Pstream::myProcNo()] = oldPatches.names();
01203 patchNames[Pstream::myProcNo()].setSize(nextPatchID);
01204 Pstream::gatherList(patchNames);
01205 Pstream::scatterList(patchNames);
01206
01207
01208
01209
01210 Pstream::listCombineGather(globalPatchSizes, plusEqOp<label>());
01211 Pstream::listCombineScatter(globalPatchSizes);
01212
01213
01214
01215
01216 bool samePatches = true;
01217
01218 for (label procI = 1; procI < patchNames.size(); procI++)
01219 {
01220 if (patchNames[procI] != patchNames[0])
01221 {
01222 samePatches = false;
01223 break;
01224 }
01225 }
01226
01227 if (!samePatches)
01228 {
01229
01230
01231 globalPatchSizes = labelMax;
01232 }
01233 }
01234
01235
01236
01237
01238 for
01239 (
01240 label oldPatchI = 0;
01241 oldPatchI < oldPatches.size()
01242 && oldPatchI < nextPatchID;
01243 oldPatchI++
01244 )
01245 {
01246 label newSize = boundaryPatchSizes[globalPatchMap[oldPatchI]];
01247
01248
01249 newBoundary[nNewPatches] = oldPatches[oldPatchI].clone
01250 (
01251 fvMeshSubsetPtr_().boundaryMesh(),
01252 nNewPatches,
01253 newSize,
01254 patchStart
01255 ).ptr();
01256
01257 patchStart += newSize;
01258 patchMap_[nNewPatches] = oldPatchI;
01259 nNewPatches++;
01260 }
01261
01262
01263
01264 if (wantedPatchID == -1)
01265 {
01266 label oldInternalSize = boundaryPatchSizes[oldInternalPatchID];
01267
01268 if (syncPar)
01269 {
01270 reduce(oldInternalSize, sumOp<label>());
01271 }
01272
01273
01274 if (oldInternalSize > 0)
01275 {
01276 newBoundary[nNewPatches] = new emptyPolyPatch
01277 (
01278 "oldInternalFaces",
01279 boundaryPatchSizes[oldInternalPatchID],
01280 patchStart,
01281 nNewPatches,
01282 fvMeshSubsetPtr_().boundaryMesh()
01283 );
01284
01285
01286
01287
01288
01289
01290 patchStart += boundaryPatchSizes[oldInternalPatchID];
01291 patchMap_[nNewPatches] = -1;
01292 nNewPatches++;
01293 }
01294 }
01295
01296
01297
01298 for
01299 (
01300 label oldPatchI = nextPatchID;
01301 oldPatchI < oldPatches.size();
01302 oldPatchI++
01303 )
01304 {
01305 label newSize = boundaryPatchSizes[globalPatchMap[oldPatchI]];
01306
01307
01308 newBoundary[nNewPatches] = oldPatches[oldPatchI].clone
01309 (
01310 fvMeshSubsetPtr_().boundaryMesh(),
01311 nNewPatches,
01312 newSize,
01313 patchStart
01314 ).ptr();
01315
01316
01317
01318
01319 patchStart += newSize;
01320 patchMap_[nNewPatches] = oldPatchI;
01321 nNewPatches++;
01322 }
01323
01324
01325
01326 newBoundary.setSize(nNewPatches);
01327 patchMap_.setSize(nNewPatches);
01328
01329
01330
01331 fvMeshSubsetPtr_().addFvPatches(newBoundary, syncPar);
01332
01333
01334 subsetZones();
01335 }
01336
01337
01338 void Foam::fvMeshSubset::setLargeCellSubset
01339 (
01340 const labelHashSet& globalCellMap,
01341 const label patchID,
01342 const bool syncPar
01343 )
01344 {
01345 labelList region(baseMesh().nCells(), 0);
01346
01347 forAllConstIter (labelHashSet, globalCellMap, iter)
01348 {
01349 region[iter.key()] = 1;
01350 }
01351 setLargeCellSubset(region, 1, patchID, syncPar);
01352 }
01353
01354
01355 const fvMesh& Foam::fvMeshSubset::subMesh() const
01356 {
01357 checkCellSubset();
01358
01359 return fvMeshSubsetPtr_();
01360 }
01361
01362
01363 fvMesh& Foam::fvMeshSubset::subMesh()
01364 {
01365 checkCellSubset();
01366
01367 return fvMeshSubsetPtr_();
01368 }
01369
01370
01371 const labelList& Foam::fvMeshSubset::pointMap() const
01372 {
01373 checkCellSubset();
01374
01375 return pointMap_;
01376 }
01377
01378
01379 const labelList& Foam::fvMeshSubset::faceMap() const
01380 {
01381 checkCellSubset();
01382
01383 return faceMap_;
01384 }
01385
01386
01387 const labelList& Foam::fvMeshSubset::cellMap() const
01388 {
01389 checkCellSubset();
01390
01391 return cellMap_;
01392 }
01393
01394
01395 const labelList& Foam::fvMeshSubset::patchMap() const
01396 {
01397 checkCellSubset();
01398
01399 return patchMap_;
01400 }
01401
01402
01403
01404
01405 }
01406
01407