48 bool Foam::fvMeshSubset::checkCellSubset()
const 50 if (fvMeshSubsetPtr_.empty())
53 <<
"void setCellSubset(const labelHashSet& cellsToSubset)" <<
endl 54 <<
"before attempting to access subset data" 66 void Foam::fvMeshSubset::markPoints
75 pointMap.insert(curPoints[pointi], 0);
80 void Foam::fvMeshSubset::markPoints
88 pointMap[curPoints[pointi]] = 0;
93 void Foam::fvMeshSubset::doCoupledPatches
96 Map<label>& facesToSubset,
103 const polyBoundaryMesh& oldPatches = baseMesh().boundaryMesh();
105 label nUncoupled = 0;
112 forAll(oldPatches, oldPatchi)
114 const polyPatch& pp = oldPatches[oldPatchi];
116 if (isA<processorPolyPatch>(pp))
118 const processorPolyPatch& procPatch =
119 refCast<const processorPolyPatch>(pp);
121 UOPstream toNeighbour(procPatch.neighbProcNo(), pBufs);
123 if (!facesToSubset.empty())
125 DynamicList<label> patchFacesToSubset;
130 facesToSubset.found(pp.start()+i)
131 && facesToSubset[pp.start()+i] == 1
134 patchFacesToSubset.append(i);
137 toNeighbour << patchFacesToSubset;
139 else if (!nCellsUsingFace.empty())
142 SubList<label>(nCellsUsingFace, pp.size(), pp.start());
151 pBufs.finishedSends();
154 forAll(oldPatches, oldPatchi)
156 const polyPatch& pp = oldPatches[oldPatchi];
158 if (isA<processorPolyPatch>(pp))
160 const processorPolyPatch& procPatch =
161 refCast<const processorPolyPatch>(pp);
163 UIPstream fromNeighbour(procPatch.neighbProcNo(), pBufs);
169 if (!facesToSubset.empty())
177 facesToSubset.found(pp.start()+i)
178 && facesToSubset[pp.start()+i] == 1
179 && !nbrPatchFacesToSubset.found(i)
184 facesToSubset[pp.start()+i] = 3;
189 else if (!nCellsUsingFace.empty())
191 const labelList& nbrCellsUsingFace(nbrList);
199 nCellsUsingFace[pp.start()+i] == 1
200 && nbrCellsUsingFace[i] == 0
205 nCellsUsingFace[pp.start()+i] = 3;
215 forAll(oldPatches, oldPatchi)
217 const polyPatch& pp = oldPatches[oldPatchi];
219 if (isA<cyclicPolyPatch>(pp))
221 const cyclicPolyPatch& cycPatch =
222 refCast<const cyclicPolyPatch>(pp);
224 if (!facesToSubset.empty())
228 label thisFacei = cycPatch.start() + i;
229 label otherFacei = cycPatch.transformGlobalFace(thisFacei);
233 facesToSubset.found(thisFacei)
234 && facesToSubset[thisFacei] == 1
235 && !facesToSubset.found(otherFacei)
238 facesToSubset[thisFacei] = 3;
243 else if (!nCellsUsingFace.empty())
247 label thisFacei = cycPatch.start() + i;
248 label otherFacei = cycPatch.transformGlobalFace(thisFacei);
252 nCellsUsingFace[thisFacei] == 1
253 && nCellsUsingFace[otherFacei] == 0
256 nCellsUsingFace[thisFacei] = 3;
266 reduce(nUncoupled, sumOp<label>());
271 Info<<
"Uncoupled " << nUncoupled <<
" faces on coupled patches. " 272 <<
"(processorPolyPatch, cyclicPolyPatch)" <<
endl;
286 forAll(selectedElements, i)
288 selected[selectedElements[i]] =
true;
295 if (selected[subsetMap[i]])
307 if (selected[subsetMap[i]])
309 subsettedElements[n++] = i;
313 return subsettedElements;
317 void Foam::fvMeshSubset::subsetZones()
324 List<pointZone*> pZonePtrs(pointZones.size());
328 const pointZone& pz = pointZones[i];
330 pZonePtrs[i] =
new pointZone
335 fvMeshSubsetPtr_().pointZones()
347 List<faceZone*> fZonePtrs(faceZones.size());
351 const faceZone& fz = faceZones[i];
385 if (zone[meshFacei] != 0)
387 subAddressing[nSub] = subFacei;
388 label subOwner = subMesh().faceOwner()[subFacei];
389 label baseOwner = baseMesh().faceOwner()[meshFacei];
391 bool sameOwner = (cellMap()[subOwner] == baseOwner);
392 bool flip = (zone[meshFacei] == 1);
393 subFlipStatus[nSub] = (sameOwner == flip);
399 fZonePtrs[i] =
new faceZone
405 fvMeshSubsetPtr_().faceZones()
412 List<cellZone*> cZonePtrs(cellZones.size());
416 const cellZone& cz = cellZones[i];
418 cZonePtrs[i] =
new cellZone
421 subset(baseMesh().nCells(), cz, cellMap()),
423 fvMeshSubsetPtr_().cellZones()
429 fvMeshSubsetPtr_().addZones(pZonePtrs, fZonePtrs, cZonePtrs);
436 const label currentRegion
443 if (region[cellI] == currentRegion)
450 label nRemove = baseMesh().nCells() - nKeep;
456 if (region[cellI] != currentRegion)
458 cellsToRemove[nRemove++] = cellI;
462 return cellsToRemove;
468 Foam::fvMeshSubset::fvMeshSubset(
const fvMesh& baseMesh)
471 fvMeshSubsetPtr_(nullptr),
497 label wantedPatchID = patchID;
499 if (wantedPatchID == -1)
503 wantedPatchID = oldPatches.
findPatchID(
"oldInternalFaces");
505 else if (wantedPatchID < 0 || wantedPatchID >= oldPatches.
size())
508 <<
"Non-existing patch index " << wantedPatchID <<
endl 509 <<
"Should be between 0 and " << oldPatches.
size()-1
515 faceFlipMapPtr_.clear();
518 cellMap_ = globalCellMap.
toc();
524 const label avgNFacesPerCell = 6;
525 const label avgNPointsPerFace = 4;
532 Map<label> facesToSubset(avgNFacesPerCell*nCellsInSet);
537 const labelList& curFaces = oldCells[cellMap_[celli]];
541 if (!facesToSubset.
found(curFaces[facei]))
543 facesToSubset.
insert(curFaces[facei], 1);
547 facesToSubset[curFaces[facei]]++;
554 doCoupledPatches(syncPar, facesToSubset, empty);
560 Map<label> globalPointMap(avgNPointsPerFace*facesToSubset.
size());
572 if (facesToSubset[facesToc[facei]] == 2)
575 faceMap_[globalFaceMap.size()] = facesToc[facei];
576 globalFaceMap.
insert(facesToc[facei], globalFaceMap.
size());
579 markPoints(oldFaces[facesToc[facei]], globalPointMap);
584 label nInternalFaces = globalFaceMap.size();
589 if (wantedPatchID != -1)
591 oldPatchStart = oldPatches[wantedPatchID].start();
598 for (; facei< facesToc.
size(); facei++)
600 if (facesToc[facei] >= oldPatchStart)
607 && facesToSubset[facesToc[facei]] == 1
611 faceMap_[globalFaceMap.size()] = facesToc[facei];
612 globalFaceMap.insert(facesToc[facei], globalFaceMap.size());
615 markPoints(oldFaces[facesToc[facei]], globalPointMap);
620 forAll(facesToc, intFacei)
625 baseMesh().isInternalFace(facesToc[intFacei])
626 && facesToSubset[facesToc[intFacei]] == 1
629 !
baseMesh().isInternalFace(facesToc[intFacei])
630 && facesToSubset[facesToc[intFacei]] == 3
635 faceMap_[globalFaceMap.size()] = facesToc[intFacei];
636 globalFaceMap.
insert(facesToc[intFacei], globalFaceMap.
size());
639 markPoints(oldFaces[facesToc[intFacei]], globalPointMap);
644 for (; facei< facesToc.
size(); facei++)
649 && facesToSubset[facesToc[facei]] == 1
653 faceMap_[globalFaceMap.size()] = facesToc[facei];
654 globalFaceMap.insert(facesToc[facei], globalFaceMap.size());
657 markPoints(oldFaces[facesToc[facei]], globalPointMap);
664 pointMap_ = globalPointMap.toc();
669 globalPointMap[pointMap_[pointi]] = pointi;
679 label nNewPoints = 0;
683 newPoints[nNewPoints] = oldPoints[pointMap_[pointi]];
687 faceList newFaces(globalFaceMap.size());
692 for (
label facei = 0; facei < nInternalFaces; facei++)
694 const face& oldF = oldFaces[faceMap_[facei]];
700 newF[i] = globalPointMap[oldF[i]];
703 newFaces[nNewFaces] = newF;
710 label oldInternalPatchID = -1;
712 if (wantedPatchID == -1)
716 oldInternalPatchID = nbSize;
722 oldInternalPatchID = wantedPatchID;
732 for (
label facei = nInternalFaces; facei < faceMap_.
size(); facei++)
734 label oldFacei = faceMap_[facei];
736 face oldF = oldFaces[oldFacei];
744 !globalCellMap.
found(oldOwner[oldFacei])
745 && globalCellMap.
found(oldNeighbour[oldFacei])
748 oldF = oldFaces[oldFacei].reverseFace();
752 boundaryPatchSizes[oldInternalPatchID]++;
754 else if (facesToSubset[oldFacei] == 3)
757 boundaryPatchSizes[oldInternalPatchID]++;
765 boundaryPatchSizes[patchOfFace]++;
772 newF[i] = globalPointMap[oldF[i]];
775 newFaces[nNewFaces] = newF;
788 const labelList& oldC = oldCells[cellMap_[celli]];
794 newC[i] = globalFaceMap[oldC[i]];
797 newCells[nNewCells] =
cell(newC);
803 fvMeshSubsetPtr_.clear();
805 fvMeshSubsetPtr_.reset
827 label nNewPatches = 0;
828 label patchStart = nInternalFaces;
833 if (boundaryPatchSizes[
patchi] > 0)
836 newBoundary[nNewPatches] = oldPatches[
patchi].
clone 840 boundaryPatchSizes[
patchi],
844 patchStart += boundaryPatchSizes[
patchi];
845 patchMap_[nNewPatches] =
patchi;
850 if (wantedPatchID == -1)
853 if (boundaryPatchSizes[oldInternalPatchID] > 0)
858 boundaryPatchSizes[oldInternalPatchID],
862 emptyPolyPatch::typeName
867 patchMap_[nNewPatches] = -1;
873 newBoundary.
setSize(nNewPatches);
874 patchMap_.
setSize(nNewPatches);
877 fvMeshSubsetPtr_().addFvPatches(newBoundary);
887 const label currentRegion,
902 if (region.
size() != oldCells.
size())
905 <<
"Size of region " << region.
size()
906 <<
" is not equal to number of cells in mesh " << oldCells.
size()
911 label wantedPatchID = patchID;
913 if (wantedPatchID == -1)
917 wantedPatchID = oldPatches.
findPatchID(
"oldInternalFaces");
919 else if (wantedPatchID < 0 || wantedPatchID >= oldPatches.
size())
922 <<
"Non-existing patch index " << wantedPatchID <<
endl 923 <<
"Should be between 0 and " << oldPatches.
size()-1
928 faceFlipMapPtr_.clear();
932 label nCellsInSet = 0;
936 if (region[oldCelli] == currentRegion)
938 cellMap_[nCellsInSet++] = oldCelli;
956 label nFacesInSet = 0;
957 forAll(oldFaces, oldFacei)
959 bool faceUsed =
false;
961 if (region[oldOwner[oldFacei]] == currentRegion)
963 nCellsUsingFace[oldFacei]++;
970 && (region[oldNeighbour[oldFacei]] == currentRegion)
973 nCellsUsingFace[oldFacei]++;
986 doCoupledPatches(syncPar, empty, nCellsUsingFace);
990 label oldInternalPatchID = 0;
1001 if (wantedPatchID == -1)
1009 if (isA<processorPolyPatch>(oldPatches[
patchi]))
1014 oldInternalPatchID++;
1020 for (
label oldPatchi = 0; oldPatchi < nextPatchID; oldPatchi++)
1022 globalPatchMap[oldPatchi] = oldPatchi;
1026 label oldPatchi = nextPatchID;
1027 oldPatchi < oldPatches.
size();
1031 globalPatchMap[oldPatchi] = oldPatchi+1;
1036 oldInternalPatchID = wantedPatchID;
1037 nextPatchID = wantedPatchID+1;
1043 labelList boundaryPatchSizes(nbSize, 0);
1053 for (
label oldFacei = 0; oldFacei < oldNInternalFaces; oldFacei++)
1055 if (nCellsUsingFace[oldFacei] == 2)
1057 globalFaceMap[oldFacei] = facei;
1058 faceMap_[facei++] = oldFacei;
1061 markPoints(oldFaces[oldFacei], globalPointMap);
1066 label nInternalFaces = facei;
1071 label oldPatchi = 0;
1072 oldPatchi < oldPatches.
size()
1073 && oldPatchi < nextPatchID;
1077 const polyPatch& oldPatch = oldPatches[oldPatchi];
1083 if (nCellsUsingFace[oldFacei] == 1)
1088 globalFaceMap[oldFacei] = facei;
1089 faceMap_[facei++] = oldFacei;
1092 markPoints(oldFaces[oldFacei], globalPointMap);
1095 boundaryPatchSizes[globalPatchMap[oldPatchi]]++;
1102 for (
label oldFacei = 0; oldFacei < oldNInternalFaces; oldFacei++)
1104 if (nCellsUsingFace[oldFacei] == 1)
1106 globalFaceMap[oldFacei] = facei;
1107 faceMap_[facei++] = oldFacei;
1110 markPoints(oldFaces[oldFacei], globalPointMap);
1113 boundaryPatchSizes[oldInternalPatchID]++;
1120 label oldFacei = oldNInternalFaces;
1121 oldFacei < oldFaces.
size();
1125 if (nCellsUsingFace[oldFacei] == 3)
1127 globalFaceMap[oldFacei] = facei;
1128 faceMap_[facei++] = oldFacei;
1131 markPoints(oldFaces[oldFacei], globalPointMap);
1134 boundaryPatchSizes[oldInternalPatchID]++;
1141 label oldPatchi = nextPatchID;
1142 oldPatchi < oldPatches.
size();
1146 const polyPatch& oldPatch = oldPatches[oldPatchi];
1152 if (nCellsUsingFace[oldFacei] == 1)
1157 globalFaceMap[oldFacei] = facei;
1158 faceMap_[facei++] = oldFacei;
1161 markPoints(oldFaces[oldFacei], globalPointMap);
1164 boundaryPatchSizes[globalPatchMap[oldPatchi]]++;
1170 if (facei != nFacesInSet)
1178 label nPointsInSet = 0;
1180 forAll(globalPointMap, pointi)
1182 if (globalPointMap[pointi] != -1)
1187 pointMap_.
setSize(nPointsInSet);
1191 forAll(globalPointMap, pointi)
1193 if (globalPointMap[pointi] != -1)
1195 pointMap_[nPointsInSet] = pointi;
1196 globalPointMap[pointi] = nPointsInSet;
1208 label nNewPoints = 0;
1210 forAll(pointMap_, pointi)
1212 newPoints[nNewPoints] = oldPoints[pointMap_[pointi]];
1218 label nNewFaces = 0;
1221 for (
label facei = 0; facei < nInternalFaces; facei++)
1223 const face& oldF = oldFaces[faceMap_[facei]];
1229 newF[i] = globalPointMap[oldF[i]];
1232 newFaces[nNewFaces] = newF;
1239 for (
label facei = nInternalFaces; facei < faceMap_.
size(); facei++)
1241 label oldFacei = faceMap_[facei];
1243 face oldF = oldFaces[oldFacei];
1251 region[oldOwner[oldFacei]] != currentRegion
1252 && region[oldNeighbour[oldFacei]] == currentRegion
1255 oldF = oldFaces[oldFacei].reverseFace();
1264 newF[i] = globalPointMap[oldF[i]];
1267 newFaces[nNewFaces] = newF;
1276 label nNewCells = 0;
1280 const labelList& oldC = oldCells[cellMap_[celli]];
1286 newC[i] = globalFaceMap[oldC[i]];
1289 newCells[nNewCells] =
cell(newC);
1295 fvMeshSubsetPtr_.clear();
1303 fvMeshSubsetPtr_.reset
1325 label nNewPatches = 0;
1326 label patchStart = nInternalFaces;
1334 labelList globalPatchSizes(boundaryPatchSizes);
1335 globalPatchSizes.
setSize(nextPatchID);
1355 bool samePatches =
true;
1357 for (
label proci = 1; proci < patchNames.
size(); proci++)
1359 if (patchNames[proci] != patchNames[0])
1361 samePatches =
false;
1379 label oldPatchi = 0;
1380 oldPatchi < oldPatches.
size()
1381 && oldPatchi < nextPatchID;
1385 label newSize = boundaryPatchSizes[globalPatchMap[oldPatchi]];
1388 newBoundary[nNewPatches] = oldPatches[oldPatchi].
clone 1396 patchStart += newSize;
1397 patchMap_[nNewPatches] = oldPatchi;
1403 if (wantedPatchID == -1)
1405 label oldInternalSize = boundaryPatchSizes[oldInternalPatchID];
1413 if (oldInternalSize > 0)
1418 boundaryPatchSizes[oldInternalPatchID],
1422 emptyPolyPatch::typeName
1430 patchStart += boundaryPatchSizes[oldInternalPatchID];
1431 patchMap_[nNewPatches] = -1;
1440 label oldPatchi = nextPatchID;
1441 oldPatchi < oldPatches.
size();
1445 label newSize = boundaryPatchSizes[globalPatchMap[oldPatchi]];
1448 newBoundary[nNewPatches] = oldPatches[oldPatchi].
clone 1459 patchStart += newSize;
1460 patchMap_[nNewPatches] = oldPatchi;
1466 newBoundary.
setSize(nNewPatches);
1467 patchMap_.
setSize(nNewPatches);
1471 fvMeshSubsetPtr_().addFvPatches(newBoundary, syncPar);
1481 const label patchID,
1489 region[iter.key()] = 1;
1498 const label currentRegion,
1499 const bool syncCouples
1503 labelList cellsToRemove(getCellsToRemove(region, currentRegion));
1512 const label currentRegion,
1515 const bool syncCouples
1519 labelList cellsToRemove(getCellsToRemove(region, currentRegion));
1550 pointMap_ = map().pointMap();
1551 faceMap_ = map().faceMap();
1552 cellMap_ = map().cellMap();
1559 return fvMeshSubsetPtr_.valid();
1567 return fvMeshSubsetPtr_();
1575 return fvMeshSubsetPtr_();
1597 if (!faceFlipMapPtr_.valid())
1611 for (
label subFaceI = 0; subFaceI < subInt; subFaceI++)
1613 faceFlipMap[subFaceI] = subToBaseFace[subFaceI]+1;
1615 for (
label subFaceI = subInt; subFaceI < subOwn.
size(); subFaceI++)
1617 label faceI = subToBaseFace[subFaceI];
1618 if (subToBaseCell[subOwn[subFaceI]] == own[faceI])
1620 faceFlipMap[subFaceI] = faceI+1;
1624 faceFlipMap[subFaceI] = -faceI-1;
1629 return faceFlipMapPtr_();
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
const labelList & patchMap() const
Return patch map.
autoPtr< IOobject > clone() const
Clone.
ZoneMesh< faceZone, polyMesh > faceZoneMesh
A ZoneMesh with the type faceZone.
static void listCombineScatter(const List< commsStruct > &comms, List< T > &Value, const int tag, const label comm)
Scatter data. Reverse of combineGather.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
A face is a list of labels corresponding to mesh vertices.
void setRefinement(const labelList &cellsToRemove, const labelList &facesToExpose, const labelList &patchIDs, polyTopoChange &) const
Play commands into polyTopoChange to remove cells.
autoPtr< mapPolyMesh > makeMesh(autoPtr< fvMesh > &newMesh, const IOobject &io, const polyMesh &mesh, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Create new mesh with old mesh patches.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
label nInternalFaces() const
virtual const labelList & faceNeighbour() const
Return face neighbour.
const labelList & faceFlipMap() const
Return face map with sign to encode flipped faces.
void size(const label)
Override size to be inconsistent with allocated storage.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Given list of cells to remove insert all the topology changes.
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface...
Ostream & endl(Ostream &os)
Add newline and flush stream.
label findPatchID(const word &patchName) const
Find patch index given a name.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
const cellList & cells() const
static void listCombineGather(const List< commsStruct > &comms, List< T > &Value, const CombineOp &cop, const int tag, const label comm)
label size() const
Return number of elements in table.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
virtual const pointField & points() const
Return raw points.
List< bool > boolList
Bool container classes.
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
labelList getExposedFaces(const labelList ®ion, const label currentRegion, const bool syncCouples=true) const
Two step subsetting.
bool found(const Key &) const
Return true if hashedEntry is found in table.
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
wordList names() const
Return a list of patch names.
wordList patchNames(nPatches)
virtual const labelList & faceOwner() const
Return face owner.
const labelList & faceMap() const
Return face map.
static const label labelMax
List< label > labelList
A List of labels.
ZoneMesh< pointZone, polyMesh > pointZoneMesh
A ZoneMesh with the type pointZone.
virtual const faceList & faces() const
Return raw faces.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
errorManip< error > abort(error &err)
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
void setCellSubset(const labelHashSet &globalCellMap, const label patchID=-1, const bool syncPar=true)
Set the subset. Create "oldInternalFaces" patch for exposed.
Empty front and back plane patch. Used for 2-D geometries.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
word name(const complex &)
Return a string representation of a complex.
label size() const
Return the number of elements in the UPtrList.
void setSize(const label)
Reset size of List.
Template functions to aid in the implementation of demand driven data.
static bool & parRun()
Is this a parallel run?
static label nProcs(const label communicator=0)
Number of processes in parallel run.
const fvMesh & subMesh() const
Return reference to subset mesh.
A cell is defined as a list of faces with extra functionality.
Mesh data needed to do the Finite Volume discretisation.
Direct mesh changes based on v1.3 polyTopoChange syntax.
label start() const
Return start label of this patch in the polyMesh face list.
ListType subset(const UList< T > &select, const T &value, const ListType &)
Extract elements of List when select is a certain value.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
labelList getExposedFaces(const labelList &cellsToRemove) const
Get labels of exposed faces.
List< Key > toc() const
Return the table of contents.
A patch is a list of labels that address the faces in the global face list.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
label whichPatch(const label faceIndex) const
Return patch index for a given face label.
void setLargeCellSubset(const labelList ®ion, const label currentRegion, const label patchID=-1, const bool syncCouples=true)
Set the subset from all cells with region == currentRegion.
const labelList & cellMap() const
Return cell map.
const fvMesh & baseMesh() const
Original mesh.
ZoneMesh< cellZone, polyMesh > cellZoneMesh
A ZoneMesh with the type cellZone.
const labelList & pointMap() const
Return point map.
bool hasSubMesh() const
Have subMesh?