50 if (fvMeshSubsetPtr_.empty())
53 <<
"void setCellSubset(const labelHashSet& cellsToSubset)" <<
endl
54 <<
"before attempting to access subset data"
75 pointMap.insert(curPoints[pointI], 0);
88 pointMap[curPoints[pointI]] = 0;
103 label nUncoupled = 0;
110 forAll(oldPatches, oldPatchI)
112 const polyPatch& pp = oldPatches[oldPatchI];
114 if (isA<processorPolyPatch>(pp))
117 refCast<const processorPolyPatch>(pp);
129 forAll(oldPatches, oldPatchI)
131 const polyPatch& pp = oldPatches[oldPatchI];
133 if (isA<processorPolyPatch>(pp))
136 refCast<const processorPolyPatch>(pp);
140 labelList nbrCellsUsingFace(fromNeighbour);
148 nCellsUsingFace[pp.
start()+i] == 1
149 && nbrCellsUsingFace[i] == 0
154 nCellsUsingFace[pp.
start()+i] = 3;
163 forAll(oldPatches, oldPatchI)
165 const polyPatch& pp = oldPatches[oldPatchI];
167 if (isA<cyclicPolyPatch>(pp))
170 refCast<const cyclicPolyPatch>(pp);
179 nCellsUsingFace[thisFaceI] == 1
180 && nCellsUsingFace[otherFaceI] == 0
183 nCellsUsingFace[thisFaceI] = 3;
197 Info<<
"Uncoupled " << nUncoupled <<
" faces on coupled patches. "
198 <<
"(processorPolyPatch, cyclicPolyPatch)" <<
endl;
212 forAll(selectedElements, i)
214 selected[selectedElements[i]] =
true;
221 if (selected[subsetMap[i]])
233 if (selected[subsetMap[i]])
235 subsettedElements[
n++] = i;
239 return subsettedElements;
261 fvMeshSubsetPtr_().pointZones()
311 if (
zone[meshFaceI] != 0)
313 subAddressing[nSub] = subFaceI;
314 label subOwner = subMesh().faceOwner()[subFaceI];
315 label baseOwner = baseMesh().faceOwner()[meshFaceI];
317 bool sameOwner = (cellMap()[subOwner] == baseOwner);
318 bool flip = (
zone[meshFaceI] == 1);
319 subFlipStatus[nSub] = (sameOwner == flip);
331 fvMeshSubsetPtr_().faceZones()
347 subset(baseMesh().nCells(), cz, cellMap()),
349 fvMeshSubsetPtr_().cellZones()
355 fvMeshSubsetPtr_().addZones(pZonePtrs, fZonePtrs, cZonePtrs);
362 const label currentRegion
369 if (region[cellI] == currentRegion)
376 label nRemove = baseMesh().nCells() - nKeep;
382 if (region[cellI] != currentRegion)
384 cellsToRemove[nRemove++] = cellI;
388 return cellsToRemove;
398 fvMeshSubsetPtr_(NULL),
417 const cellList& oldCells = baseMesh().cells();
418 const faceList& oldFaces = baseMesh().faces();
419 const pointField& oldPoints = baseMesh().points();
420 const labelList& oldOwner = baseMesh().faceOwner();
421 const labelList& oldNeighbour = baseMesh().faceNeighbour();
423 label wantedPatchID = patchID;
425 if (wantedPatchID == -1)
429 wantedPatchID = oldPatches.
findPatchID(
"oldInternalFaces");
431 else if (wantedPatchID < 0 || wantedPatchID >= oldPatches.
size())
434 <<
"Non-existing patch index " << wantedPatchID <<
endl
435 <<
"Should be between 0 and " << oldPatches.
size()-1
441 faceFlipMapPtr_.clear();
444 cellMap_ = globalCellMap.
toc();
450 const label avgNFacesPerCell = 6;
451 const label avgNPointsPerFace = 4;
454 label nCellsInSet = cellMap_.size();
458 Map<label> facesToSubset(avgNFacesPerCell*nCellsInSet);
463 const labelList& curFaces = oldCells[cellMap_[cellI]];
467 if (!facesToSubset.found(curFaces[faceI]))
469 facesToSubset.insert(curFaces[faceI], 1);
473 facesToSubset[curFaces[faceI]]++;
479 Map<label> globalFaceMap(facesToSubset.size());
482 Map<label> globalPointMap(avgNPointsPerFace*facesToSubset.size());
487 labelList facesToc = facesToSubset.toc();
489 faceMap_.setSize(facesToc.
size());
494 if (facesToSubset[facesToc[faceI]] == 2)
497 faceMap_[globalFaceMap.size()] = facesToc[faceI];
498 globalFaceMap.insert(facesToc[faceI], globalFaceMap.size());
501 markPoints(oldFaces[facesToc[faceI]], globalPointMap);
506 label nInternalFaces = globalFaceMap.size();
511 if (wantedPatchID != -1)
513 oldPatchStart = oldPatches[wantedPatchID].start();
520 for (; faceI< facesToc.
size(); faceI++)
522 if (facesToc[faceI] >= oldPatchStart)
528 !baseMesh().isInternalFace(facesToc[faceI])
529 && facesToSubset[facesToc[faceI]] == 1
533 faceMap_[globalFaceMap.size()] = facesToc[faceI];
534 globalFaceMap.insert(facesToc[faceI], globalFaceMap.size());
537 markPoints(oldFaces[facesToc[faceI]], globalPointMap);
542 forAll(facesToc, intFaceI)
546 baseMesh().isInternalFace(facesToc[intFaceI])
547 && facesToSubset[facesToc[intFaceI]] == 1
551 faceMap_[globalFaceMap.size()] = facesToc[intFaceI];
552 globalFaceMap.insert(facesToc[intFaceI], globalFaceMap.size());
555 markPoints(oldFaces[facesToc[intFaceI]], globalPointMap);
560 for (; faceI< facesToc.
size(); faceI++)
564 !baseMesh().isInternalFace(facesToc[faceI])
565 && facesToSubset[facesToc[faceI]] == 1
569 faceMap_[globalFaceMap.size()] = facesToc[faceI];
570 globalFaceMap.insert(facesToc[faceI], globalFaceMap.size());
573 markPoints(oldFaces[facesToc[faceI]], globalPointMap);
580 pointMap_ = globalPointMap.toc();
585 globalPointMap[pointMap_[pointI]] = pointI;
588 Pout<<
"Number of cells in new mesh: " << nCellsInSet <<
endl;
589 Pout<<
"Number of faces in new mesh: " << globalFaceMap.size() <<
endl;
590 Pout<<
"Number of points in new mesh: " << globalPointMap.size() <<
endl;
595 label nNewPoints = 0;
599 newPoints[nNewPoints] = oldPoints[pointMap_[pointI]];
603 faceList newFaces(globalFaceMap.size());
608 for (
label faceI = 0; faceI < nInternalFaces; faceI++)
610 const face& oldF = oldFaces[faceMap_[faceI]];
616 newF[i] = globalPointMap[oldF[i]];
619 newFaces[nNewFaces] = newF;
626 label oldInternalPatchID = -1;
628 if (wantedPatchID == -1)
632 oldInternalPatchID = nbSize;
638 oldInternalPatchID = wantedPatchID;
648 for (
label faceI = nInternalFaces; faceI < faceMap_.size(); faceI++)
650 label oldFaceI = faceMap_[faceI];
652 face oldF = oldFaces[oldFaceI];
655 if (baseMesh().isInternalFace(oldFaceI))
660 !globalCellMap.
found(oldOwner[oldFaceI])
661 && globalCellMap.
found(oldNeighbour[oldFaceI])
664 oldF = oldFaces[oldFaceI].reverseFace();
668 boundaryPatchSizes[oldInternalPatchID]++;
676 boundaryPatchSizes[patchOfFace]++;
683 newF[i] = globalPointMap[oldF[i]];
686 newFaces[nNewFaces] = newF;
699 const labelList& oldC = oldCells[cellMap_[cellI]];
705 newC[i] = globalFaceMap[oldC[i]];
708 newCells[nNewCells] =
cell(newC);
714 fvMeshSubsetPtr_.clear();
716 fvMeshSubsetPtr_.reset
722 baseMesh().
name() +
"SubSet",
737 patchMap_.setSize(nbSize);
738 label nNewPatches = 0;
739 label patchStart = nInternalFaces;
741 forAll(oldPatches, patchI)
743 if (boundaryPatchSizes[patchI] > 0)
746 newBoundary[nNewPatches] = oldPatches[patchI].
clone
750 boundaryPatchSizes[patchI],
754 patchStart += boundaryPatchSizes[patchI];
755 patchMap_[nNewPatches] = patchI;
760 if (wantedPatchID == -1)
763 if (boundaryPatchSizes[oldInternalPatchID] > 0)
768 boundaryPatchSizes[oldInternalPatchID],
772 emptyPolyPatch::typeName
777 patchMap_[nNewPatches] = -1;
783 newBoundary.
setSize(nNewPatches);
784 patchMap_.setSize(nNewPatches);
787 fvMeshSubsetPtr_().addFvPatches(newBoundary);
797 const label currentRegion,
802 const cellList& oldCells = baseMesh().cells();
803 const faceList& oldFaces = baseMesh().faces();
804 const pointField& oldPoints = baseMesh().points();
805 const labelList& oldOwner = baseMesh().faceOwner();
806 const labelList& oldNeighbour = baseMesh().faceNeighbour();
808 const label oldNInternalFaces = baseMesh().nInternalFaces();
812 if (region.
size() != oldCells.
size())
815 <<
"Size of region " << region.
size()
816 <<
" is not equal to number of cells in mesh " << oldCells.
size()
821 label wantedPatchID = patchID;
823 if (wantedPatchID == -1)
827 wantedPatchID = oldPatches.
findPatchID(
"oldInternalFaces");
829 else if (wantedPatchID < 0 || wantedPatchID >= oldPatches.
size())
832 <<
"Non-existing patch index " << wantedPatchID <<
endl
833 <<
"Should be between 0 and " << oldPatches.
size()-1
838 faceFlipMapPtr_.clear();
841 cellMap_.setSize(oldCells.
size());
842 label nCellsInSet = 0;
846 if (region[oldCellI] == currentRegion)
848 cellMap_[nCellsInSet++] = oldCellI;
851 cellMap_.setSize(nCellsInSet);
866 label nFacesInSet = 0;
867 forAll(oldFaces, oldFaceI)
869 bool faceUsed =
false;
871 if (region[oldOwner[oldFaceI]] == currentRegion)
873 nCellsUsingFace[oldFaceI]++;
879 baseMesh().isInternalFace(oldFaceI)
880 && (region[oldNeighbour[oldFaceI]] == currentRegion)
883 nCellsUsingFace[oldFaceI]++;
895 doCoupledPatches(syncPar, nCellsUsingFace);
899 label oldInternalPatchID = 0;
910 if (wantedPatchID == -1)
916 forAll(oldPatches, patchI)
918 if (isA<processorPolyPatch>(oldPatches[patchI]))
920 nextPatchID = patchI;
923 oldInternalPatchID++;
929 for (
label oldPatchI = 0; oldPatchI < nextPatchID; oldPatchI++)
931 globalPatchMap[oldPatchI] = oldPatchI;
935 label oldPatchI = nextPatchID;
936 oldPatchI < oldPatches.
size();
940 globalPatchMap[oldPatchI] = oldPatchI+1;
945 oldInternalPatchID = wantedPatchID;
946 nextPatchID = wantedPatchID+1;
956 labelList globalPointMap(oldPoints.size(), -1);
962 for (
label oldFaceI = 0; oldFaceI < oldNInternalFaces; oldFaceI++)
964 if (nCellsUsingFace[oldFaceI] == 2)
966 globalFaceMap[oldFaceI] = faceI;
967 faceMap_[faceI++] = oldFaceI;
970 markPoints(oldFaces[oldFaceI], globalPointMap);
975 label nInternalFaces = faceI;
981 oldPatchI < oldPatches.
size()
982 && oldPatchI < nextPatchID;
986 const polyPatch& oldPatch = oldPatches[oldPatchI];
992 if (nCellsUsingFace[oldFaceI] == 1)
997 globalFaceMap[oldFaceI] = faceI;
998 faceMap_[faceI++] = oldFaceI;
1001 markPoints(oldFaces[oldFaceI], globalPointMap);
1004 boundaryPatchSizes[globalPatchMap[oldPatchI]]++;
1011 for (
label oldFaceI = 0; oldFaceI < oldNInternalFaces; oldFaceI++)
1013 if (nCellsUsingFace[oldFaceI] == 1)
1015 globalFaceMap[oldFaceI] = faceI;
1016 faceMap_[faceI++] = oldFaceI;
1019 markPoints(oldFaces[oldFaceI], globalPointMap);
1022 boundaryPatchSizes[oldInternalPatchID]++;
1029 label oldFaceI = oldNInternalFaces;
1030 oldFaceI < oldFaces.
size();
1034 if (nCellsUsingFace[oldFaceI] == 3)
1036 globalFaceMap[oldFaceI] = faceI;
1037 faceMap_[faceI++] = oldFaceI;
1040 markPoints(oldFaces[oldFaceI], globalPointMap);
1043 boundaryPatchSizes[oldInternalPatchID]++;
1050 label oldPatchI = nextPatchID;
1051 oldPatchI < oldPatches.
size();
1055 const polyPatch& oldPatch = oldPatches[oldPatchI];
1061 if (nCellsUsingFace[oldFaceI] == 1)
1066 globalFaceMap[oldFaceI] = faceI;
1067 faceMap_[faceI++] = oldFaceI;
1070 markPoints(oldFaces[oldFaceI], globalPointMap);
1073 boundaryPatchSizes[globalPatchMap[oldPatchI]]++;
1079 if (faceI != nFacesInSet)
1087 label nPointsInSet = 0;
1089 forAll(globalPointMap, pointI)
1091 if (globalPointMap[pointI] != -1)
1096 pointMap_.setSize(nPointsInSet);
1100 forAll(globalPointMap, pointI)
1102 if (globalPointMap[pointI] != -1)
1104 pointMap_[nPointsInSet] = pointI;
1105 globalPointMap[pointI] = nPointsInSet;
1117 label nNewPoints = 0;
1119 forAll(pointMap_, pointI)
1121 newPoints[nNewPoints] = oldPoints[pointMap_[pointI]];
1125 faceList newFaces(faceMap_.size());
1127 label nNewFaces = 0;
1130 for (
label faceI = 0; faceI < nInternalFaces; faceI++)
1132 const face& oldF = oldFaces[faceMap_[faceI]];
1138 newF[i] = globalPointMap[oldF[i]];
1141 newFaces[nNewFaces] = newF;
1148 for (
label faceI = nInternalFaces; faceI < faceMap_.size(); faceI++)
1150 label oldFaceI = faceMap_[faceI];
1152 face oldF = oldFaces[oldFaceI];
1155 if (baseMesh().isInternalFace(oldFaceI))
1160 region[oldOwner[oldFaceI]] != currentRegion
1161 && region[oldNeighbour[oldFaceI]] == currentRegion
1164 oldF = oldFaces[oldFaceI].reverseFace();
1173 newF[i] = globalPointMap[oldF[i]];
1176 newFaces[nNewFaces] = newF;
1185 label nNewCells = 0;
1189 const labelList& oldC = oldCells[cellMap_[cellI]];
1195 newC[i] = globalFaceMap[oldC[i]];
1198 newCells[nNewCells] =
cell(newC);
1204 fvMeshSubsetPtr_.clear();
1212 fvMeshSubsetPtr_.reset
1233 patchMap_.setSize(nbSize);
1234 label nNewPatches = 0;
1235 label patchStart = nInternalFaces;
1243 labelList globalPatchSizes(boundaryPatchSizes);
1244 globalPatchSizes.
setSize(nextPatchID);
1264 bool samePatches =
true;
1270 samePatches =
false;
1288 label oldPatchI = 0;
1289 oldPatchI < oldPatches.
size()
1290 && oldPatchI < nextPatchID;
1294 label newSize = boundaryPatchSizes[globalPatchMap[oldPatchI]];
1297 newBoundary[nNewPatches] = oldPatches[oldPatchI].
clone
1305 patchStart += newSize;
1306 patchMap_[nNewPatches] = oldPatchI;
1312 if (wantedPatchID == -1)
1314 label oldInternalSize = boundaryPatchSizes[oldInternalPatchID];
1322 if (oldInternalSize > 0)
1327 boundaryPatchSizes[oldInternalPatchID],
1331 emptyPolyPatch::typeName
1339 patchStart += boundaryPatchSizes[oldInternalPatchID];
1340 patchMap_[nNewPatches] = -1;
1349 label oldPatchI = nextPatchID;
1350 oldPatchI < oldPatches.
size();
1354 label newSize = boundaryPatchSizes[globalPatchMap[oldPatchI]];
1357 newBoundary[nNewPatches] = oldPatches[oldPatchI].
clone
1368 patchStart += newSize;
1369 patchMap_[nNewPatches] = oldPatchI;
1375 newBoundary.
setSize(nNewPatches);
1376 patchMap_.setSize(nNewPatches);
1380 fvMeshSubsetPtr_().addFvPatches(newBoundary, syncPar);
1390 const label patchID,
1394 labelList region(baseMesh().nCells(), 0);
1398 region[iter.key()] = 1;
1400 setLargeCellSubset(region, 1, patchID, syncPar);
1407 const label currentRegion,
1408 const bool syncCouples
1412 labelList cellsToRemove(getCellsToRemove(region, currentRegion));
1421 const label currentRegion,
1424 const bool syncCouples
1428 labelList cellsToRemove(getCellsToRemove(region, currentRegion));
1459 pointMap_ = map().pointMap();
1460 faceMap_ = map().faceMap();
1461 cellMap_ = map().cellMap();
1468 return fvMeshSubsetPtr_.valid();
1476 return fvMeshSubsetPtr_();
1484 return fvMeshSubsetPtr_();
1506 if (!faceFlipMapPtr_.valid())
1509 const labelList& subToBaseCell = cellMap();
1512 labelList& faceFlipMap = faceFlipMapPtr_();
1516 label subInt = subMesh().nInternalFaces();
1517 const labelList& subOwn = subMesh().faceOwner();
1518 const labelList& own = baseMesh_.faceOwner();
1520 for (
label subFaceI = 0; subFaceI < subInt; subFaceI++)
1522 faceFlipMap[subFaceI] = subToBaseFace[subFaceI]+1;
1524 for (
label subFaceI = subInt; subFaceI < subOwn.
size(); subFaceI++)
1526 label faceI = subToBaseFace[subFaceI];
1527 if (subToBaseCell[subOwn[subFaceI]] == own[faceI])
1529 faceFlipMap[subFaceI] = faceI+1;
1533 faceFlipMap[subFaceI] = -faceI-1;
1538 return faceFlipMapPtr_();