52 for (
auto idx : locations)
68 bool Foam::fvMeshSubset::checkCellSubset()
const
70 if (!fvMeshSubsetPtr_)
73 <<
"setCellSubset()" <<
nl
74 <<
"before attempting to access subset data"
84 void Foam::fvMeshSubset::calcFaceFlipMap()
const
87 const labelList& subToBaseCell = cellMap();
89 faceFlipMapPtr_.reset(
new labelList(subToBaseFace.size()));
90 auto& faceFlipMap = *faceFlipMapPtr_;
94 const label subInt = subMesh().nInternalFaces();
96 const labelList& subOwn = subMesh().faceOwner();
97 const labelList& own = baseMesh_.faceOwner();
99 for (label subFaceI = 0; subFaceI < subInt; ++subFaceI)
101 faceFlipMap[subFaceI] = subToBaseFace[subFaceI]+1;
103 for (label subFaceI = subInt; subFaceI < subOwn.size(); ++subFaceI)
105 const label faceI = subToBaseFace[subFaceI];
106 if (subToBaseCell[subOwn[subFaceI]] == own[faceI])
108 faceFlipMap[subFaceI] = faceI+1;
112 faceFlipMap[subFaceI] = -faceI-1;
118 void Foam::fvMeshSubset::doCoupledPatches
127 const polyBoundaryMesh& oldPatches = baseMesh().
boundaryMesh();
129 label nUncoupled = 0;
136 for (
const polyPatch& pp : oldPatches)
138 const auto* procPatch = isA<processorPolyPatch>(pp);
142 const label nbrProci = procPatch->neighbProcNo();
144 UOPstream toNeighbour(nbrProci, pBufs);
146 if (!nCellsUsingFace.empty())
149 SubList<label>(nCellsUsingFace, pp.size(), pp.start());
158 pBufs.finishedSends();
161 for (
const polyPatch& pp : oldPatches)
163 const auto* procPatch = isA<processorPolyPatch>(pp);
167 const label nbrProci = procPatch->neighbProcNo();
169 UIPstream fromNeighbour(nbrProci, 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 const cyclicPolyPatch* cpp = isA<cyclicPolyPatch>(pp);
205 if (cpp && !nCellsUsingFace.empty())
207 const auto& cycPatch = *cpp;
211 label thisFacei = cycPatch.start() + i;
212 label otherFacei = cycPatch.transformGlobalFace(thisFacei);
216 nCellsUsingFace[thisFacei] == 1
217 && nCellsUsingFace[otherFacei] == 0
220 nCellsUsingFace[thisFacei] = 3;
229 reduce(nUncoupled, sumOp<label>());
234 Info<<
"Uncoupled " << nUncoupled <<
" faces on coupled patches. "
235 <<
"(processorPolyPatch, cyclicPolyPatch)" <<
endl;
240 void Foam::fvMeshSubset::removeCellsImpl
242 const bitSet& cellsToRemove,
245 const bool syncCouples
249 polyTopoChange meshMod(baseMesh());
251 removeCells cellRemover(baseMesh(), syncCouples);
253 cellRemover.setRefinement
262 autoPtr<mapPolyMesh> map = meshMod.makeMesh
277 pointMap_ = map().pointMap();
278 faceMap_ = map().faceMap();
279 cellMap_ = map().cellMap();
280 patchMap_ =
identity(baseMesh().boundaryMesh().size());
292 const bitSet selected(nElems, selectedElements);
298 if (selected[subsetMap[i]])
310 if (selected[subsetMap[i]])
312 subsettedElements[
n] = i;
317 return subsettedElements;
321 void Foam::fvMeshSubset::subsetZones()
329 List<pointZone*> pZonePtrs(pointZones.size());
333 const pointZone& pz = pointZones[zonei];
335 pZonePtrs[zonei] =
new pointZone
338 subsetSubset(baseMesh().
nPoints(), pz, pointMap()),
340 fvMeshSubsetPtr_().pointZones()
351 List<faceZone*> fZonePtrs(faceZones.size());
355 const faceZone& fz = faceZones[zonei];
388 const label meshFacei =
faceMap()[subFacei];
389 if (zone[meshFacei] != 0)
391 subAddressing[nSub] = subFacei;
392 const label subOwner = subMesh().faceOwner()[subFacei];
393 const label baseOwner = baseMesh().
faceOwner()[meshFacei];
395 const bool sameOwner = (cellMap()[subOwner] == baseOwner);
396 const bool flip = (zone[meshFacei] == 1);
397 subFlipStatus[nSub] = (sameOwner == flip);
403 fZonePtrs[zonei] =
new faceZone
409 fvMeshSubsetPtr_().faceZones()
417 List<cellZone*> cZonePtrs(cellZones.size());
421 const cellZone& cz = cellZones[zonei];
423 cZonePtrs[zonei] =
new cellZone
426 subsetSubset(baseMesh().nCells(), cz, cellMap()),
428 fvMeshSubsetPtr_().cellZones()
434 fvMeshSubsetPtr_().addZones(pZonePtrs, fZonePtrs, cZonePtrs);
440 const bitSet& selectedCells
444 bitSet cellsToRemove(selectedCells);
447 cellsToRemove.resize(baseMesh().nCells(),
false);
450 cellsToRemove.flip();
452 return cellsToRemove;
474 Foam::fvMeshSubset::fvMeshSubset(
const fvMesh& baseMesh)
477 fvMeshSubsetPtr_(nullptr),
478 faceFlipMapPtr_(nullptr),
486 Foam::fvMeshSubset::fvMeshSubset
489 const bitSet& selectedCells,
491 const bool syncCouples
496 setCellSubset(selectedCells,
patchID, syncCouples);
500 Foam::fvMeshSubset::fvMeshSubset
505 const bool syncCouples
510 setCellSubset(selectedCells,
patchID, syncCouples);
514 Foam::fvMeshSubset::fvMeshSubset
519 const bool syncCouples
524 setCellSubset(selectedCells,
patchID, syncCouples);
528 Foam::fvMeshSubset::fvMeshSubset
534 const bool syncCouples
539 setCellSubset(regioni, regions,
patchID, syncCouples);
547 fvMeshSubsetPtr_.reset(
nullptr);
548 faceFlipMapPtr_.reset(
nullptr);
559 const bitSet& selectedCells,
576 if (wantedPatchID == -1)
580 wantedPatchID = oldPatches.
findPatchID(exposedPatchName);
582 else if (wantedPatchID < 0 || wantedPatchID >= oldPatches.size())
585 <<
"Non-existing patch index " << wantedPatchID <<
endl
586 <<
"Should be between 0 and " << oldPatches.size()-1
599 label len = cellMap_.size();
603 i >= 0 && (cellMap_[i] >= oldCells.size());
625 label nFacesInSet = 0;
626 forAll(oldFaces, oldFacei)
628 bool faceUsed =
false;
630 if (selectedCells.
test(oldOwner[oldFacei]))
632 ++nCellsUsingFace[oldFacei];
639 && selectedCells.
test(oldNeighbour[oldFacei])
642 ++nCellsUsingFace[oldFacei];
651 faceMap_.setSize(nFacesInSet);
654 doCoupledPatches(syncPar, nCellsUsingFace);
658 label oldInternalPatchID = 0;
661 label nextPatchID = oldPatches.size();
664 labelList globalPatchMap(oldPatches.size());
667 label nbSize = oldPatches.size();
669 if (wantedPatchID == -1)
675 forAll(oldPatches, patchi)
677 if (isA<processorPolyPatch>(oldPatches[patchi]))
679 nextPatchID = patchi;
682 ++oldInternalPatchID;
688 for (label oldPatchi = 0; oldPatchi < nextPatchID; oldPatchi++)
690 globalPatchMap[oldPatchi] = oldPatchi;
694 label oldPatchi = nextPatchID;
695 oldPatchi < oldPatches.size();
699 globalPatchMap[oldPatchi] = oldPatchi+1;
704 oldInternalPatchID = wantedPatchID;
705 nextPatchID = wantedPatchID+1;
708 globalPatchMap =
identity(oldPatches.size());
715 labelList globalPointMap(oldPoints.size(), -1);
716 labelList globalFaceMap(oldFaces.size(), -1);
721 for (label oldFacei = 0; oldFacei < oldNInternalFaces; ++oldFacei)
723 if (nCellsUsingFace[oldFacei] == 2)
725 globalFaceMap[oldFacei] = facei;
726 faceMap_[facei++] = oldFacei;
729 markUsed(oldFaces[oldFacei], globalPointMap);
734 const label nInternalFaces = facei;
740 oldPatchi < oldPatches.size()
741 && oldPatchi < nextPatchID;
745 const polyPatch& oldPatch = oldPatches[oldPatchi];
747 label oldFacei = oldPatch.
start();
751 if (nCellsUsingFace[oldFacei] == 1)
756 globalFaceMap[oldFacei] = facei;
757 faceMap_[facei++] = oldFacei;
760 markUsed(oldFaces[oldFacei], globalPointMap);
763 ++boundaryPatchSizes[globalPatchMap[oldPatchi]];
770 for (label oldFacei = 0; oldFacei < oldNInternalFaces; ++oldFacei)
772 if (nCellsUsingFace[oldFacei] == 1)
774 globalFaceMap[oldFacei] = facei;
775 faceMap_[facei++] = oldFacei;
778 markUsed(oldFaces[oldFacei], globalPointMap);
781 ++boundaryPatchSizes[oldInternalPatchID];
788 label oldFacei = oldNInternalFaces;
789 oldFacei < oldFaces.size();
793 if (nCellsUsingFace[oldFacei] == 3)
795 globalFaceMap[oldFacei] = facei;
796 faceMap_[facei++] = oldFacei;
799 markUsed(oldFaces[oldFacei], globalPointMap);
802 ++boundaryPatchSizes[oldInternalPatchID];
809 label oldPatchi = nextPatchID;
810 oldPatchi < oldPatches.size();
814 const polyPatch& oldPatch = oldPatches[oldPatchi];
816 label oldFacei = oldPatch.
start();
820 if (nCellsUsingFace[oldFacei] == 1)
825 globalFaceMap[oldFacei] = facei;
826 faceMap_[facei++] = oldFacei;
829 markUsed(oldFaces[oldFacei], globalPointMap);
832 ++boundaryPatchSizes[globalPatchMap[oldPatchi]];
838 if (facei != nFacesInSet)
846 label nPointsInSet = 0;
848 forAll(globalPointMap, pointi)
850 if (globalPointMap[pointi] != -1)
855 pointMap_.setSize(nPointsInSet);
859 forAll(globalPointMap, pointi)
861 if (globalPointMap[pointi] != -1)
863 pointMap_[nPointsInSet] = pointi;
864 globalPointMap[pointi] = nPointsInSet;
890 auto iter = newFaces.begin();
891 const auto& renumbering = globalPointMap;
894 for (label facei = 0; facei < nInternalFaces; ++facei)
896 face& newItem = *iter;
899 const face& oldItem = oldFaces[faceMap_[facei]];
902 newItem.
resize(oldItem.size());
906 newItem[i] = renumbering[oldItem[i]];
911 for (label facei = nInternalFaces; facei < faceMap_.size(); ++facei)
913 const label oldFacei = faceMap_[facei];
915 face& newItem = *iter;
922 && selectedCells.
test(oldNeighbour[oldFacei])
923 && !selectedCells.
test(oldOwner[oldFacei])
926 ? oldFaces[oldFacei].reverseFace()
931 newItem.
resize(oldItem.size());
935 newItem[i] = renumbering[oldItem[i]];
947 auto iter = newCells.begin();
948 const auto& renumbering = globalFaceMap;
950 for (
const label oldCelli : cellMap_)
952 cell& newItem = *iter;
955 const labelList& oldItem = oldCells[oldCelli];
958 newItem.
resize(oldItem.size());
962 newItem[i] = renumbering[oldItem[i]];
986 std::move(newPoints),
995 patchMap_.setSize(nbSize);
996 label nNewPatches = 0;
997 label patchStart = nInternalFaces;
1005 labelList globalPatchSizes(boundaryPatchSizes);
1006 globalPatchSizes.
setSize(nextPatchID);
1026 bool samePatches =
true;
1028 for (label proci = 1; proci <
patchNames.size(); ++proci)
1032 samePatches =
false;
1050 label oldPatchi = 0;
1051 oldPatchi < oldPatches.size()
1052 && oldPatchi < nextPatchID;
1056 const label newSize = boundaryPatchSizes[globalPatchMap[oldPatchi]];
1058 if (oldInternalPatchID != oldPatchi)
1063 for (label patchFacei = 0; patchFacei < newSize; patchFacei++)
1065 const label facei = patchStart+patchFacei;
1066 const label oldFacei = faceMap_[facei];
1067 map[patchFacei] = oldPatches[oldPatchi].whichFace(oldFacei);
1070 newBoundary[nNewPatches] = oldPatches[oldPatchi].
clone
1081 newBoundary[nNewPatches] = oldPatches[oldPatchi].
clone
1090 patchStart += newSize;
1091 patchMap_[nNewPatches] = oldPatchi;
1097 if (wantedPatchID == -1)
1099 label oldInternalSize = boundaryPatchSizes[oldInternalPatchID];
1107 if (oldInternalSize > 0)
1112 boundaryPatchSizes[oldInternalPatchID],
1116 emptyPolyPatch::typeName
1124 patchStart += boundaryPatchSizes[oldInternalPatchID];
1125 patchMap_[nNewPatches] = -1;
1134 label oldPatchi = nextPatchID;
1135 oldPatchi < oldPatches.size();
1139 const label newSize = boundaryPatchSizes[globalPatchMap[oldPatchi]];
1141 if (oldInternalPatchID != oldPatchi)
1146 for (label patchFacei = 0; patchFacei < newSize; patchFacei++)
1148 const label facei = patchStart+patchFacei;
1149 const label oldFacei = faceMap_[facei];
1150 map[patchFacei] = oldPatches[oldPatchi].whichFace(oldFacei);
1153 newBoundary[nNewPatches] = oldPatches[oldPatchi].
clone
1164 newBoundary[nNewPatches] = oldPatches[oldPatchi].
clone
1176 patchStart += newSize;
1177 patchMap_[nNewPatches] = oldPatchi;
1183 newBoundary.
setSize(nNewPatches);
1184 patchMap_.setSize(nNewPatches);
1188 fvMeshSubsetPtr_().addFvPatches(newBoundary, syncPar);
1229 const label regioni,
1246 const bitSet& selectedCells,
1247 const bool syncCouples
1258 const label regioni,
1260 const bool syncCouples
1271 const bitSet& selectedCells,
1274 const bool syncCouples
1279 getCellsToRemove(selectedCells),
1289 const label selectRegion,
1293 const bool syncCouples
1298 getCellsToRemove(selectRegion, regions),