53 for (
auto idx : locations)
69 bool Foam::fvMeshSubset::checkCellSubset()
const
71 if (!fvMeshSubsetPtr_)
74 <<
"setCellSubset()" <<
nl
75 <<
"before attempting to access subset data"
85 void Foam::fvMeshSubset::calcFaceFlipMap()
const
88 const labelList& subToBaseCell = cellMap();
90 faceFlipMapPtr_.reset(
new labelList(subToBaseFace.size()));
91 auto& faceFlipMap = *faceFlipMapPtr_;
95 const label subInt = subMesh().nInternalFaces();
97 const labelList& subOwn = subMesh().faceOwner();
98 const labelList& own = baseMesh_.faceOwner();
100 for (label subFaceI = 0; subFaceI < subInt; ++subFaceI)
102 faceFlipMap[subFaceI] = subToBaseFace[subFaceI]+1;
104 for (label subFaceI = subInt; subFaceI < subOwn.size(); ++subFaceI)
106 const label faceI = subToBaseFace[subFaceI];
107 if (subToBaseCell[subOwn[subFaceI]] == own[faceI])
109 faceFlipMap[subFaceI] = faceI+1;
113 faceFlipMap[subFaceI] = -faceI-1;
119 void Foam::fvMeshSubset::doCoupledPatches
128 const polyBoundaryMesh& oldPatches = baseMesh().
boundaryMesh();
130 label nUncoupled = 0;
137 for (
const polyPatch& pp : oldPatches)
139 if (isA<processorPolyPatch>(pp))
141 const processorPolyPatch& procPatch =
142 refCast<const processorPolyPatch>(pp);
144 UOPstream toNeighbour(procPatch.neighbProcNo(), pBufs);
146 if (!nCellsUsingFace.empty())
149 SubList<label>(nCellsUsingFace, pp.size(), pp.start());
158 pBufs.finishedSends();
161 for (
const polyPatch& pp : oldPatches)
163 if (isA<processorPolyPatch>(pp))
165 const processorPolyPatch& procPatch =
166 refCast<const processorPolyPatch>(pp);
168 UIPstream fromNeighbour(procPatch.neighbProcNo(), pBufs);
174 if (!nCellsUsingFace.empty())
176 const labelList& nbrCellsUsingFace(nbrList);
184 nCellsUsingFace[pp.start()+i] == 1
185 && nbrCellsUsingFace[i] == 0
190 nCellsUsingFace[pp.start()+i] = 3;
200 for (
const polyPatch& pp : oldPatches)
202 if (isA<cyclicPolyPatch>(pp))
204 const cyclicPolyPatch& cycPatch =
205 refCast<const cyclicPolyPatch>(pp);
207 if (!nCellsUsingFace.empty())
211 label thisFacei = cycPatch.start() + i;
212 label otherFacei = cycPatch.transformGlobalFace(thisFacei);
216 nCellsUsingFace[thisFacei] == 1
217 && nCellsUsingFace[otherFacei] == 0
220 nCellsUsingFace[thisFacei] = 3;
230 reduce(nUncoupled, sumOp<label>());
235 Info<<
"Uncoupled " << nUncoupled <<
" faces on coupled patches. "
236 <<
"(processorPolyPatch, cyclicPolyPatch)" <<
endl;
241 void Foam::fvMeshSubset::removeCellsImpl
243 const bitSet& cellsToRemove,
246 const bool syncCouples
250 polyTopoChange meshMod(baseMesh());
252 removeCells cellRemover(baseMesh(), syncCouples);
254 cellRemover.setRefinement
263 autoPtr<mapPolyMesh> map = meshMod.makeMesh
278 pointMap_ = map().pointMap();
279 faceMap_ = map().faceMap();
280 cellMap_ = map().cellMap();
281 patchMap_ =
identity(baseMesh().boundaryMesh().size());
293 const bitSet selected(nElems, selectedElements);
299 if (selected[subsetMap[i]])
311 if (selected[subsetMap[i]])
313 subsettedElements[
n] = i;
318 return subsettedElements;
322 void Foam::fvMeshSubset::subsetZones()
330 List<pointZone*> pZonePtrs(pointZones.size());
334 const pointZone& pz = pointZones[zonei];
336 pZonePtrs[zonei] =
new pointZone
339 subsetSubset(baseMesh().
nPoints(), pz, pointMap()),
341 fvMeshSubsetPtr_().pointZones()
352 List<faceZone*> fZonePtrs(faceZones.size());
356 const faceZone& fz = faceZones[zonei];
389 const label meshFacei =
faceMap()[subFacei];
390 if (zone[meshFacei] != 0)
392 subAddressing[nSub] = subFacei;
393 const label subOwner = subMesh().faceOwner()[subFacei];
394 const label baseOwner = baseMesh().
faceOwner()[meshFacei];
396 const bool sameOwner = (cellMap()[subOwner] == baseOwner);
397 const bool flip = (zone[meshFacei] == 1);
398 subFlipStatus[nSub] = (sameOwner == flip);
404 fZonePtrs[zonei] =
new faceZone
410 fvMeshSubsetPtr_().faceZones()
418 List<cellZone*> cZonePtrs(cellZones.size());
422 const cellZone& cz = cellZones[zonei];
424 cZonePtrs[zonei] =
new cellZone
427 subsetSubset(baseMesh().nCells(), cz, cellMap()),
429 fvMeshSubsetPtr_().cellZones()
435 fvMeshSubsetPtr_().addZones(pZonePtrs, fZonePtrs, cZonePtrs);
441 const bitSet& selectedCells
445 bitSet cellsToRemove(selectedCells);
448 cellsToRemove.resize(baseMesh().nCells(),
false);
451 cellsToRemove.flip();
453 return cellsToRemove;
475 Foam::fvMeshSubset::fvMeshSubset(
const fvMesh& baseMesh)
478 fvMeshSubsetPtr_(nullptr),
479 faceFlipMapPtr_(nullptr),
487 Foam::fvMeshSubset::fvMeshSubset
490 const bitSet& selectedCells,
492 const bool syncCouples
497 setCellSubset(selectedCells,
patchID, syncCouples);
501 Foam::fvMeshSubset::fvMeshSubset
506 const bool syncCouples
511 setCellSubset(selectedCells,
patchID, syncCouples);
515 Foam::fvMeshSubset::fvMeshSubset
520 const bool syncCouples
525 setCellSubset(selectedCells,
patchID, syncCouples);
529 Foam::fvMeshSubset::fvMeshSubset
535 const bool syncCouples
540 setCellSubset(regioni, regions,
patchID, syncCouples);
548 fvMeshSubsetPtr_.reset(
nullptr);
549 faceFlipMapPtr_.reset(
nullptr);
560 const bitSet& selectedCells,
577 if (wantedPatchID == -1)
581 wantedPatchID = oldPatches.
findPatchID(exposedPatchName);
583 else if (wantedPatchID < 0 || wantedPatchID >= oldPatches.size())
586 <<
"Non-existing patch index " << wantedPatchID <<
endl
587 <<
"Should be between 0 and " << oldPatches.size()-1
600 label len = cellMap_.size();
604 i >= 0 && (cellMap_[i] >= oldCells.size());
626 label nFacesInSet = 0;
627 forAll(oldFaces, oldFacei)
629 bool faceUsed =
false;
631 if (selectedCells.
test(oldOwner[oldFacei]))
633 ++nCellsUsingFace[oldFacei];
640 && selectedCells.
test(oldNeighbour[oldFacei])
643 ++nCellsUsingFace[oldFacei];
652 faceMap_.setSize(nFacesInSet);
655 doCoupledPatches(syncPar, nCellsUsingFace);
659 label oldInternalPatchID = 0;
662 label nextPatchID = oldPatches.size();
665 labelList globalPatchMap(oldPatches.size());
668 label nbSize = oldPatches.size();
670 if (wantedPatchID == -1)
676 forAll(oldPatches, patchi)
678 if (isA<processorPolyPatch>(oldPatches[patchi]))
680 nextPatchID = patchi;
683 ++oldInternalPatchID;
689 for (label oldPatchi = 0; oldPatchi < nextPatchID; oldPatchi++)
691 globalPatchMap[oldPatchi] = oldPatchi;
695 label oldPatchi = nextPatchID;
696 oldPatchi < oldPatches.size();
700 globalPatchMap[oldPatchi] = oldPatchi+1;
705 oldInternalPatchID = wantedPatchID;
706 nextPatchID = wantedPatchID+1;
709 globalPatchMap =
identity(oldPatches.size());
716 labelList globalPointMap(oldPoints.size(), -1);
717 labelList globalFaceMap(oldFaces.size(), -1);
722 for (label oldFacei = 0; oldFacei < oldNInternalFaces; ++oldFacei)
724 if (nCellsUsingFace[oldFacei] == 2)
726 globalFaceMap[oldFacei] = facei;
727 faceMap_[facei++] = oldFacei;
730 markUsed(oldFaces[oldFacei], globalPointMap);
735 const label nInternalFaces = facei;
741 oldPatchi < oldPatches.size()
742 && oldPatchi < nextPatchID;
746 const polyPatch& oldPatch = oldPatches[oldPatchi];
748 label oldFacei = oldPatch.
start();
752 if (nCellsUsingFace[oldFacei] == 1)
757 globalFaceMap[oldFacei] = facei;
758 faceMap_[facei++] = oldFacei;
761 markUsed(oldFaces[oldFacei], globalPointMap);
764 ++boundaryPatchSizes[globalPatchMap[oldPatchi]];
771 for (label oldFacei = 0; oldFacei < oldNInternalFaces; ++oldFacei)
773 if (nCellsUsingFace[oldFacei] == 1)
775 globalFaceMap[oldFacei] = facei;
776 faceMap_[facei++] = oldFacei;
779 markUsed(oldFaces[oldFacei], globalPointMap);
782 ++boundaryPatchSizes[oldInternalPatchID];
789 label oldFacei = oldNInternalFaces;
790 oldFacei < oldFaces.size();
794 if (nCellsUsingFace[oldFacei] == 3)
796 globalFaceMap[oldFacei] = facei;
797 faceMap_[facei++] = oldFacei;
800 markUsed(oldFaces[oldFacei], globalPointMap);
803 ++boundaryPatchSizes[oldInternalPatchID];
810 label oldPatchi = nextPatchID;
811 oldPatchi < oldPatches.size();
815 const polyPatch& oldPatch = oldPatches[oldPatchi];
817 label oldFacei = oldPatch.
start();
821 if (nCellsUsingFace[oldFacei] == 1)
826 globalFaceMap[oldFacei] = facei;
827 faceMap_[facei++] = oldFacei;
830 markUsed(oldFaces[oldFacei], globalPointMap);
833 ++boundaryPatchSizes[globalPatchMap[oldPatchi]];
839 if (facei != nFacesInSet)
847 label nPointsInSet = 0;
849 forAll(globalPointMap, pointi)
851 if (globalPointMap[pointi] != -1)
856 pointMap_.setSize(nPointsInSet);
860 forAll(globalPointMap, pointi)
862 if (globalPointMap[pointi] != -1)
864 pointMap_[nPointsInSet] = pointi;
865 globalPointMap[pointi] = nPointsInSet;
891 auto iter = newFaces.begin();
892 const auto& renumbering = globalPointMap;
895 for (label facei = 0; facei < nInternalFaces; ++facei)
897 face& newItem = *iter;
900 const face& oldItem = oldFaces[faceMap_[facei]];
903 newItem.
resize(oldItem.size());
907 newItem[i] = renumbering[oldItem[i]];
912 for (label facei = nInternalFaces; facei < faceMap_.size(); ++facei)
914 const label oldFacei = faceMap_[facei];
916 face& newItem = *iter;
923 && selectedCells.
test(oldNeighbour[oldFacei])
924 && !selectedCells.
test(oldOwner[oldFacei])
927 ? oldFaces[oldFacei].reverseFace()
932 newItem.
resize(oldItem.size());
936 newItem[i] = renumbering[oldItem[i]];
948 auto iter = newCells.begin();
949 const auto& renumbering = globalFaceMap;
951 for (
const label oldCelli : cellMap_)
953 cell& newItem = *iter;
956 const labelList& oldItem = oldCells[oldCelli];
959 newItem.
resize(oldItem.size());
963 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]];
1059 newBoundary[nNewPatches] = oldPatches[oldPatchi].
clone
1067 patchStart += newSize;
1068 patchMap_[nNewPatches] = oldPatchi;
1074 if (wantedPatchID == -1)
1076 label oldInternalSize = boundaryPatchSizes[oldInternalPatchID];
1084 if (oldInternalSize > 0)
1089 boundaryPatchSizes[oldInternalPatchID],
1093 emptyPolyPatch::typeName
1101 patchStart += boundaryPatchSizes[oldInternalPatchID];
1102 patchMap_[nNewPatches] = -1;
1111 label oldPatchi = nextPatchID;
1112 oldPatchi < oldPatches.size();
1116 const label newSize = boundaryPatchSizes[globalPatchMap[oldPatchi]];
1119 newBoundary[nNewPatches] = oldPatches[oldPatchi].
clone
1130 patchStart += newSize;
1131 patchMap_[nNewPatches] = oldPatchi;
1137 newBoundary.
setSize(nNewPatches);
1138 patchMap_.setSize(nNewPatches);
1142 fvMeshSubsetPtr_().addFvPatches(newBoundary, syncPar);
1183 const label regioni,
1200 const bitSet& selectedCells,
1201 const bool syncCouples
1212 const label regioni,
1214 const bool syncCouples
1225 const bitSet& selectedCells,
1228 const bool syncCouples
1233 getCellsToRemove(selectedCells),
1243 const label selectRegion,
1247 const bool syncCouples
1252 getCellsToRemove(selectRegion, regions),