53 for (
auto idx : locations)
69 bool Foam::fvMeshSubset::checkCellSubset()
const
71 if (fvMeshSubsetPtr_.empty())
74 <<
"setCellSubset()" <<
nl
75 <<
"before attempting to access subset data"
85 void Foam::fvMeshSubset::calcFaceFlipMap()
const
88 const labelList& subToBaseCell = cellMap();
90 faceFlipMapPtr_.clear();
91 faceFlipMapPtr_.reset(
new labelList(subToBaseFace.size()));
92 labelList& faceFlipMap = *faceFlipMapPtr_;
96 const label subInt = subMesh().nInternalFaces();
98 const labelList& subOwn = subMesh().faceOwner();
99 const labelList& own = baseMesh_.faceOwner();
101 for (
label subFaceI = 0; subFaceI < subInt; ++subFaceI)
103 faceFlipMap[subFaceI] = subToBaseFace[subFaceI]+1;
105 for (
label subFaceI = subInt; subFaceI < subOwn.size(); ++subFaceI)
107 const label faceI = subToBaseFace[subFaceI];
108 if (subToBaseCell[subOwn[subFaceI]] == own[faceI])
110 faceFlipMap[subFaceI] = faceI+1;
114 faceFlipMap[subFaceI] = -faceI-1;
120 void Foam::fvMeshSubset::doCoupledPatches
129 const polyBoundaryMesh& oldPatches = baseMesh().
boundaryMesh();
131 label nUncoupled = 0;
138 for (
const polyPatch& pp : oldPatches)
140 if (isA<processorPolyPatch>(pp))
142 const processorPolyPatch& procPatch =
143 refCast<const processorPolyPatch>(pp);
145 UOPstream toNeighbour(procPatch.neighbProcNo(), pBufs);
147 if (!nCellsUsingFace.empty())
150 SubList<label>(nCellsUsingFace, pp.size(), pp.start());
159 pBufs.finishedSends();
162 for (
const polyPatch& pp : oldPatches)
164 if (isA<processorPolyPatch>(pp))
166 const processorPolyPatch& procPatch =
167 refCast<const processorPolyPatch>(pp);
169 UIPstream fromNeighbour(procPatch.neighbProcNo(), pBufs);
175 if (!nCellsUsingFace.empty())
177 const labelList& nbrCellsUsingFace(nbrList);
185 nCellsUsingFace[pp.start()+i] == 1
186 && nbrCellsUsingFace[i] == 0
191 nCellsUsingFace[pp.start()+i] = 3;
201 for (
const polyPatch& pp : oldPatches)
203 if (isA<cyclicPolyPatch>(pp))
205 const cyclicPolyPatch& cycPatch =
206 refCast<const cyclicPolyPatch>(pp);
208 if (!nCellsUsingFace.empty())
212 label thisFacei = cycPatch.start() + i;
213 label otherFacei = cycPatch.transformGlobalFace(thisFacei);
217 nCellsUsingFace[thisFacei] == 1
218 && nCellsUsingFace[otherFacei] == 0
221 nCellsUsingFace[thisFacei] = 3;
231 reduce(nUncoupled, sumOp<label>());
236 Info<<
"Uncoupled " << nUncoupled <<
" faces on coupled patches. "
237 <<
"(processorPolyPatch, cyclicPolyPatch)" <<
endl;
242 void Foam::fvMeshSubset::removeCellsImpl
244 const bitSet& cellsToRemove,
247 const bool syncCouples
251 polyTopoChange meshMod(baseMesh());
253 removeCells cellRemover(baseMesh(), syncCouples);
255 cellRemover.setRefinement
264 autoPtr<mapPolyMesh> map = meshMod.makeMesh
279 pointMap_ = map().pointMap();
280 faceMap_ = map().faceMap();
281 cellMap_ = map().cellMap();
282 patchMap_ =
identity(baseMesh().boundaryMesh().size());
294 const bitSet selected(nElems, selectedElements);
300 if (selected[subsetMap[i]])
312 if (selected[subsetMap[i]])
314 subsettedElements[
n] = i;
319 return subsettedElements;
323 void Foam::fvMeshSubset::subsetZones()
331 List<pointZone*> pZonePtrs(pointZones.size());
335 const pointZone& pz = pointZones[zonei];
337 pZonePtrs[zonei] =
new pointZone
340 subsetSubset(baseMesh().
nPoints(), pz, pointMap()),
342 fvMeshSubsetPtr_().pointZones()
353 List<faceZone*> fZonePtrs(faceZones.size());
357 const faceZone& fz = faceZones[zonei];
391 if (zone[meshFacei] != 0)
393 subAddressing[nSub] = subFacei;
394 const label subOwner = subMesh().faceOwner()[subFacei];
397 const bool sameOwner = (cellMap()[subOwner] == baseOwner);
398 const bool flip = (zone[meshFacei] == 1);
399 subFlipStatus[nSub] = (sameOwner == flip);
405 fZonePtrs[zonei] =
new faceZone
411 fvMeshSubsetPtr_().faceZones()
419 List<cellZone*> cZonePtrs(cellZones.size());
423 const cellZone& cz = cellZones[zonei];
425 cZonePtrs[zonei] =
new cellZone
428 subsetSubset(baseMesh().nCells(), cz, cellMap()),
430 fvMeshSubsetPtr_().cellZones()
436 fvMeshSubsetPtr_().addZones(pZonePtrs, fZonePtrs, cZonePtrs);
442 const bitSet& selectedCells
446 bitSet cellsToRemove(selectedCells);
449 cellsToRemove.resize(baseMesh().nCells(),
false);
452 cellsToRemove.flip();
454 return cellsToRemove;
476 Foam::fvMeshSubset::fvMeshSubset(
const fvMesh& baseMesh)
479 fvMeshSubsetPtr_(nullptr),
480 faceFlipMapPtr_(nullptr),
488 Foam::fvMeshSubset::fvMeshSubset
491 const bitSet& selectedCells,
493 const bool syncCouples
498 setCellSubset(selectedCells,
patchID, syncCouples);
502 Foam::fvMeshSubset::fvMeshSubset
507 const bool syncCouples
512 setCellSubset(selectedCells,
patchID, syncCouples);
516 Foam::fvMeshSubset::fvMeshSubset
521 const bool syncCouples
526 setCellSubset(selectedCells,
patchID, syncCouples);
530 Foam::fvMeshSubset::fvMeshSubset
536 const bool syncCouples
541 setCellSubset(regioni, regions,
patchID, syncCouples);
549 fvMeshSubsetPtr_.clear();
550 faceFlipMapPtr_.clear();
561 const bitSet& selectedCells,
578 if (wantedPatchID == -1)
582 wantedPatchID = oldPatches.
findPatchID(exposedPatchName);
584 else if (wantedPatchID < 0 || wantedPatchID >= oldPatches.size())
587 <<
"Non-existing patch index " << wantedPatchID <<
endl
588 <<
"Should be between 0 and " << oldPatches.size()-1
601 label len = cellMap_.size();
605 i >= 0 && (cellMap_[i] >= oldCells.size());
627 label nFacesInSet = 0;
628 forAll(oldFaces, oldFacei)
630 bool faceUsed =
false;
632 if (selectedCells.
test(oldOwner[oldFacei]))
634 ++nCellsUsingFace[oldFacei];
641 && selectedCells.
test(oldNeighbour[oldFacei])
644 ++nCellsUsingFace[oldFacei];
653 faceMap_.setSize(nFacesInSet);
656 doCoupledPatches(syncPar, nCellsUsingFace);
660 label oldInternalPatchID = 0;
663 label nextPatchID = oldPatches.size();
666 labelList globalPatchMap(oldPatches.size());
669 label nbSize = oldPatches.size();
671 if (wantedPatchID == -1)
677 forAll(oldPatches, patchi)
679 if (isA<processorPolyPatch>(oldPatches[patchi]))
681 nextPatchID = patchi;
684 ++oldInternalPatchID;
690 for (
label oldPatchi = 0; oldPatchi < nextPatchID; oldPatchi++)
692 globalPatchMap[oldPatchi] = oldPatchi;
696 label oldPatchi = nextPatchID;
697 oldPatchi < oldPatches.size();
701 globalPatchMap[oldPatchi] = oldPatchi+1;
706 oldInternalPatchID = wantedPatchID;
707 nextPatchID = wantedPatchID+1;
710 globalPatchMap =
identity(oldPatches.size());
717 labelList globalPointMap(oldPoints.size(), -1);
718 labelList globalFaceMap(oldFaces.size(), -1);
723 for (
label oldFacei = 0; oldFacei < oldNInternalFaces; ++oldFacei)
725 if (nCellsUsingFace[oldFacei] == 2)
727 globalFaceMap[oldFacei] = facei;
728 faceMap_[facei++] = oldFacei;
731 markUsed(oldFaces[oldFacei], globalPointMap);
736 const label nInternalFaces = facei;
742 oldPatchi < oldPatches.size()
743 && oldPatchi < nextPatchID;
747 const polyPatch& oldPatch = oldPatches[oldPatchi];
753 if (nCellsUsingFace[oldFacei] == 1)
758 globalFaceMap[oldFacei] = facei;
759 faceMap_[facei++] = oldFacei;
762 markUsed(oldFaces[oldFacei], globalPointMap);
765 ++boundaryPatchSizes[globalPatchMap[oldPatchi]];
772 for (
label oldFacei = 0; oldFacei < oldNInternalFaces; ++oldFacei)
774 if (nCellsUsingFace[oldFacei] == 1)
776 globalFaceMap[oldFacei] = facei;
777 faceMap_[facei++] = oldFacei;
780 markUsed(oldFaces[oldFacei], globalPointMap);
783 ++boundaryPatchSizes[oldInternalPatchID];
790 label oldFacei = oldNInternalFaces;
791 oldFacei < oldFaces.size();
795 if (nCellsUsingFace[oldFacei] == 3)
797 globalFaceMap[oldFacei] = facei;
798 faceMap_[facei++] = oldFacei;
801 markUsed(oldFaces[oldFacei], globalPointMap);
804 ++boundaryPatchSizes[oldInternalPatchID];
811 label oldPatchi = nextPatchID;
812 oldPatchi < oldPatches.size();
816 const polyPatch& oldPatch = oldPatches[oldPatchi];
822 if (nCellsUsingFace[oldFacei] == 1)
827 globalFaceMap[oldFacei] = facei;
828 faceMap_[facei++] = oldFacei;
831 markUsed(oldFaces[oldFacei], globalPointMap);
834 ++boundaryPatchSizes[globalPatchMap[oldPatchi]];
840 if (facei != nFacesInSet)
848 label nPointsInSet = 0;
850 forAll(globalPointMap, pointi)
852 if (globalPointMap[pointi] != -1)
857 pointMap_.setSize(nPointsInSet);
861 forAll(globalPointMap, pointi)
863 if (globalPointMap[pointi] != -1)
865 pointMap_[nPointsInSet] = pointi;
866 globalPointMap[pointi] = nPointsInSet;
892 auto iter = newFaces.begin();
893 const auto& renumbering = globalPointMap;
896 for (
label facei = 0; facei < nInternalFaces; ++facei)
898 face& newItem = *iter;
901 const face& oldItem = oldFaces[faceMap_[facei]];
904 newItem.
resize(oldItem.size());
908 newItem[i] = renumbering[oldItem[i]];
913 for (
label facei = nInternalFaces; facei < faceMap_.size(); ++facei)
915 const label oldFacei = faceMap_[facei];
917 face& newItem = *iter;
924 && selectedCells.
test(oldNeighbour[oldFacei])
925 && !selectedCells.
test(oldOwner[oldFacei])
928 ? oldFaces[oldFacei].reverseFace()
933 newItem.
resize(oldItem.size());
937 newItem[i] = renumbering[oldItem[i]];
949 auto iter = newCells.begin();
950 const auto& renumbering = globalFaceMap;
952 for (
const label oldCelli : cellMap_)
954 cell& newItem = *iter;
957 const labelList& oldItem = oldCells[oldCelli];
960 newItem.
resize(oldItem.size());
964 newItem[i] = renumbering[oldItem[i]];
987 std::move(newPoints),
996 patchMap_.setSize(nbSize);
997 label nNewPatches = 0;
998 label patchStart = nInternalFaces;
1006 labelList globalPatchSizes(boundaryPatchSizes);
1007 globalPatchSizes.
setSize(nextPatchID);
1027 bool samePatches =
true;
1033 samePatches =
false;
1051 label oldPatchi = 0;
1052 oldPatchi < oldPatches.size()
1053 && oldPatchi < nextPatchID;
1057 const label newSize = boundaryPatchSizes[globalPatchMap[oldPatchi]];
1060 newBoundary[nNewPatches] = oldPatches[oldPatchi].
clone
1068 patchStart += newSize;
1069 patchMap_[nNewPatches] = oldPatchi;
1075 if (wantedPatchID == -1)
1077 label oldInternalSize = boundaryPatchSizes[oldInternalPatchID];
1085 if (oldInternalSize > 0)
1090 boundaryPatchSizes[oldInternalPatchID],
1094 emptyPolyPatch::typeName
1102 patchStart += boundaryPatchSizes[oldInternalPatchID];
1103 patchMap_[nNewPatches] = -1;
1112 label oldPatchi = nextPatchID;
1113 oldPatchi < oldPatches.size();
1117 const label newSize = boundaryPatchSizes[globalPatchMap[oldPatchi]];
1120 newBoundary[nNewPatches] = oldPatches[oldPatchi].
clone
1131 patchStart += newSize;
1132 patchMap_[nNewPatches] = oldPatchi;
1138 newBoundary.
setSize(nNewPatches);
1139 patchMap_.setSize(nNewPatches);
1143 fvMeshSubsetPtr_().addFvPatches(newBoundary, syncPar);
1184 const label regioni,
1201 const bitSet& selectedCells,
1202 const bool syncCouples
1213 const label regioni,
1215 const bool syncCouples
1226 const bitSet& selectedCells,
1229 const bool syncCouples
1234 getCellsToRemove(selectedCells),
1244 const label selectRegion,
1248 const bool syncCouples
1253 getCellsToRemove(selectRegion, regions),