44 bool Foam::fvMeshSubset::checkCellSubset()
const 46 if (fvMeshSubsetPtr_.empty())
49 <<
"void setCellSubset(const labelHashSet& cellsToSubset)" <<
endl 50 <<
"before attempting to access subset data" 62 void Foam::fvMeshSubset::markPoints
71 pointMap.insert(curPoints[pointi], 0);
76 void Foam::fvMeshSubset::markPoints
84 pointMap[curPoints[pointi]] = 0;
89 void Foam::fvMeshSubset::doCoupledPatches
92 Map<label>& facesToSubset,
101 label nUncoupled = 0;
108 forAll(oldPatches, oldPatchi)
110 const polyPatch& pp = oldPatches[oldPatchi];
112 if (isA<processorPolyPatch>(pp))
114 const processorPolyPatch& procPatch =
115 refCast<const processorPolyPatch>(pp);
117 UOPstream toNeighbour(procPatch.neighbProcNo(), pBufs);
119 if (!facesToSubset.empty())
121 DynamicList<label> patchFacesToSubset;
126 facesToSubset.found(pp.start()+i)
127 && facesToSubset[pp.start()+i] == 1
130 patchFacesToSubset.append(i);
133 toNeighbour << patchFacesToSubset;
135 else if (!nCellsUsingFace.empty())
138 SubList<label>(nCellsUsingFace, pp.size(), pp.start());
147 pBufs.finishedSends();
150 forAll(oldPatches, oldPatchi)
152 const polyPatch& pp = oldPatches[oldPatchi];
154 if (isA<processorPolyPatch>(pp))
156 const processorPolyPatch& procPatch =
157 refCast<const processorPolyPatch>(pp);
159 UIPstream fromNeighbour(procPatch.neighbProcNo(), pBufs);
165 if (!facesToSubset.empty())
173 facesToSubset.found(pp.start()+i)
174 && facesToSubset[pp.start()+i] == 1
175 && !nbrPatchFacesToSubset.found(i)
180 facesToSubset[pp.start()+i] = 3;
185 else if (!nCellsUsingFace.empty())
187 const labelList& nbrCellsUsingFace(nbrList);
195 nCellsUsingFace[pp.start()+i] == 1
196 && nbrCellsUsingFace[i] == 0
201 nCellsUsingFace[pp.start()+i] = 3;
211 forAll(oldPatches, oldPatchi)
213 const polyPatch& pp = oldPatches[oldPatchi];
215 if (isA<cyclicPolyPatch>(pp))
217 const cyclicPolyPatch& cycPatch =
218 refCast<const cyclicPolyPatch>(pp);
220 if (!facesToSubset.empty())
224 const label thisFacei = cycPatch.start() + i;
225 const label otherFacei =
226 cycPatch.transformGlobalFace(thisFacei);
230 facesToSubset.found(thisFacei)
231 && facesToSubset[thisFacei] == 1
232 && !facesToSubset.found(otherFacei)
235 facesToSubset[thisFacei] = 3;
240 else if (!nCellsUsingFace.empty())
244 const label thisFacei = cycPatch.start() + i;
245 const label otherFacei =
246 cycPatch.transformGlobalFace(thisFacei);
250 nCellsUsingFace[thisFacei] == 1
251 && nCellsUsingFace[otherFacei] == 0
254 nCellsUsingFace[thisFacei] = 3;
264 reduce(nUncoupled, sumOp<label>());
269 Info<<
"Uncoupled " << nUncoupled <<
" faces on coupled patches. " 270 <<
"(processorPolyPatch, cyclicPolyPatch)" <<
endl;
284 forAll(selectedElements, i)
286 selected[selectedElements[i]] =
true;
293 if (selected[subsetMap[i]])
305 if (selected[subsetMap[i]])
307 subsettedElements[n++] = i;
311 return subsettedElements;
315 void Foam::fvMeshSubset::subsetZones()
322 List<pointZone*> pZonePtrs(pointZones.size());
326 const pointZone& pz = pointZones[i];
328 pZonePtrs[i] =
new pointZone
333 fvMeshSubsetPtr_().pointZones()
343 List<faceZone*> fZonePtrs(faceZones.size());
347 const faceZone& fz = faceZones[i];
381 if (zone[meshFacei] != 0)
383 subAddressing[nSub] = subFacei;
387 const bool sameOwner = (
cellMap()[subOwner] == baseOwner);
388 const bool flip = (zone[meshFacei] == 1);
389 subFlipStatus[nSub] = (sameOwner == flip);
395 fZonePtrs[i] =
new faceZone
401 fvMeshSubsetPtr_().faceZones()
408 List<cellZone*> cZonePtrs(cellZones.size());
412 const cellZone& cz = cellZones[i];
414 cZonePtrs[i] =
new cellZone
419 fvMeshSubsetPtr_().cellZones()
425 fvMeshSubsetPtr_().addZones(pZonePtrs, fZonePtrs, cZonePtrs);
432 const label currentRegion
439 if (region[cellI] == currentRegion)
452 if (region[cellI] != currentRegion)
454 cellsToRemove[nRemove++] = cellI;
458 return cellsToRemove;
467 fvMeshSubsetPtr_(nullptr),
493 label wantedPatchID = patchID;
495 if (wantedPatchID == -1)
499 wantedPatchID = oldPatches.
findPatchID(
"oldInternalFaces");
501 else if (wantedPatchID < 0 || wantedPatchID >= oldPatches.
size())
504 <<
"Non-existing patch index " << wantedPatchID <<
endl 505 <<
"Should be between 0 and " << oldPatches.
size()-1
511 faceFlipMapPtr_.clear();
514 cellMap_ = globalCellMap.
toc();
520 const label avgNFacesPerCell = 6;
521 const label avgNPointsPerFace = 4;
524 const label nCellsInSet = cellMap_.
size();
528 Map<label> facesToSubset(avgNFacesPerCell*nCellsInSet);
533 const labelList& curFaces = oldCells[cellMap_[celli]];
537 if (!facesToSubset.
found(curFaces[facei]))
539 facesToSubset.
insert(curFaces[facei], 1);
543 facesToSubset[curFaces[facei]]++;
550 doCoupledPatches(syncPar, facesToSubset, empty);
556 Map<label> globalPointMap(avgNPointsPerFace*facesToSubset.
size());
568 if (facesToSubset[facesToc[facei]] == 2)
571 faceMap_[globalFaceMap.size()] = facesToc[facei];
572 globalFaceMap.
insert(facesToc[facei], globalFaceMap.
size());
575 markPoints(oldFaces[facesToc[facei]], globalPointMap);
580 const label nInternalFaces = globalFaceMap.size();
585 if (wantedPatchID != -1)
587 oldPatchStart = oldPatches[wantedPatchID].start();
594 for (; facei< facesToc.
size(); facei++)
596 if (facesToc[facei] >= oldPatchStart)
603 && facesToSubset[facesToc[facei]] == 1
607 faceMap_[globalFaceMap.size()] = facesToc[facei];
608 globalFaceMap.insert(facesToc[facei], globalFaceMap.size());
611 markPoints(oldFaces[facesToc[facei]], globalPointMap);
616 forAll(facesToc, intFacei)
621 baseMesh().isInternalFace(facesToc[intFacei])
622 && facesToSubset[facesToc[intFacei]] == 1
625 !
baseMesh().isInternalFace(facesToc[intFacei])
626 && facesToSubset[facesToc[intFacei]] == 3
631 faceMap_[globalFaceMap.size()] = facesToc[intFacei];
632 globalFaceMap.
insert(facesToc[intFacei], globalFaceMap.
size());
635 markPoints(oldFaces[facesToc[intFacei]], globalPointMap);
640 for (; facei< facesToc.
size(); facei++)
645 && facesToSubset[facesToc[facei]] == 1
649 faceMap_[globalFaceMap.size()] = facesToc[facei];
650 globalFaceMap.insert(facesToc[facei], globalFaceMap.size());
653 markPoints(oldFaces[facesToc[facei]], globalPointMap);
660 pointMap_ = globalPointMap.toc();
665 globalPointMap[pointMap_[pointi]] = pointi;
671 label nNewPoints = 0;
675 newPoints[nNewPoints] = oldPoints[pointMap_[pointi]];
679 faceList newFaces(globalFaceMap.size());
684 for (
label facei = 0; facei < nInternalFaces; facei++)
686 const face& oldF = oldFaces[faceMap_[facei]];
692 newF[i] = globalPointMap[oldF[i]];
695 newFaces[nNewFaces] = newF;
702 label oldInternalPatchID = -1;
704 if (wantedPatchID == -1)
708 oldInternalPatchID = nbSize;
714 oldInternalPatchID = wantedPatchID;
724 for (
label facei = nInternalFaces; facei < faceMap_.
size(); facei++)
726 const label oldFacei = faceMap_[facei];
728 face oldF = oldFaces[oldFacei];
736 !globalCellMap.
found(oldOwner[oldFacei])
737 && globalCellMap.
found(oldNeighbour[oldFacei])
740 oldF = oldFaces[oldFacei].reverseFace();
744 boundaryPatchSizes[oldInternalPatchID]++;
746 else if (facesToSubset[oldFacei] == 3)
749 boundaryPatchSizes[oldInternalPatchID]++;
757 boundaryPatchSizes[patchOfFace]++;
764 newF[i] = globalPointMap[oldF[i]];
767 newFaces[nNewFaces] = newF;
780 const labelList& oldC = oldCells[cellMap_[celli]];
786 newC[i] = globalFaceMap[oldC[i]];
789 newCells[nNewCells] =
cell(newC);
795 fvMeshSubsetPtr_.clear();
797 fvMeshSubsetPtr_.reset
819 label nNewPatches = 0;
820 label patchStart = nInternalFaces;
825 if (boundaryPatchSizes[
patchi] > 0)
828 newBoundary[nNewPatches] = oldPatches[
patchi].
clone 830 fvMeshSubsetPtr_().boundaryMesh(),
832 boundaryPatchSizes[
patchi],
836 patchStart += boundaryPatchSizes[
patchi];
837 patchMap_[nNewPatches] =
patchi;
842 if (wantedPatchID == -1)
845 if (boundaryPatchSizes[oldInternalPatchID] > 0)
850 boundaryPatchSizes[oldInternalPatchID],
853 fvMeshSubsetPtr_().boundaryMesh(),
854 internalPolyPatch::typeName
859 patchMap_[nNewPatches] = -1;
869 newBoundary.
setSize(nNewPatches);
870 patchMap_.
setSize(nNewPatches);
873 fvMeshSubsetPtr_().addFvPatches(newBoundary);
883 const label currentRegion,
898 if (region.
size() != oldCells.
size())
901 <<
"Size of region " << region.
size()
902 <<
" is not equal to number of cells in mesh " << oldCells.
size()
907 label wantedPatchID = patchID;
909 if (wantedPatchID == -1)
913 wantedPatchID = oldPatches.
findPatchID(
"oldInternalFaces");
915 else if (wantedPatchID < 0 || wantedPatchID >= oldPatches.
size())
918 <<
"Non-existing patch index " << wantedPatchID <<
endl 919 <<
"Should be between 0 and " << oldPatches.
size()-1
924 faceFlipMapPtr_.clear();
928 label nCellsInSet = 0;
932 if (region[oldCelli] == currentRegion)
934 cellMap_[nCellsInSet++] = oldCelli;
952 label nFacesInSet = 0;
953 forAll(oldFaces, oldFacei)
955 bool faceUsed =
false;
957 if (region[oldOwner[oldFacei]] == currentRegion)
959 nCellsUsingFace[oldFacei]++;
966 && (region[oldNeighbour[oldFacei]] == currentRegion)
969 nCellsUsingFace[oldFacei]++;
982 doCoupledPatches(syncPar, empty, nCellsUsingFace);
986 label oldInternalPatchID = 0;
997 if (wantedPatchID == -1)
1005 if (isA<processorPolyPatch>(oldPatches[
patchi]))
1010 oldInternalPatchID++;
1016 for (
label oldPatchi = 0; oldPatchi < nextPatchID; oldPatchi++)
1018 globalPatchMap[oldPatchi] = oldPatchi;
1022 label oldPatchi = nextPatchID;
1023 oldPatchi < oldPatches.
size();
1027 globalPatchMap[oldPatchi] = oldPatchi + 1;
1032 oldInternalPatchID = wantedPatchID;
1033 nextPatchID = wantedPatchID + 1;
1039 labelList boundaryPatchSizes(nbSize, 0);
1049 for (
label oldFacei = 0; oldFacei < oldNInternalFaces; oldFacei++)
1051 if (nCellsUsingFace[oldFacei] == 2)
1053 globalFaceMap[oldFacei] = facei;
1054 faceMap_[facei++] = oldFacei;
1057 markPoints(oldFaces[oldFacei], globalPointMap);
1062 label nInternalFaces = facei;
1067 label oldPatchi = 0;
1068 oldPatchi < oldPatches.
size()
1069 && oldPatchi < nextPatchID;
1073 const polyPatch& oldPatch = oldPatches[oldPatchi];
1079 if (nCellsUsingFace[oldFacei] == 1)
1084 globalFaceMap[oldFacei] = facei;
1085 faceMap_[facei++] = oldFacei;
1088 markPoints(oldFaces[oldFacei], globalPointMap);
1091 boundaryPatchSizes[globalPatchMap[oldPatchi]]++;
1098 for (
label oldFacei = 0; oldFacei < oldNInternalFaces; oldFacei++)
1100 if (nCellsUsingFace[oldFacei] == 1)
1102 globalFaceMap[oldFacei] = facei;
1103 faceMap_[facei++] = oldFacei;
1106 markPoints(oldFaces[oldFacei], globalPointMap);
1109 boundaryPatchSizes[oldInternalPatchID]++;
1116 label oldFacei = oldNInternalFaces;
1117 oldFacei < oldFaces.
size();
1121 if (nCellsUsingFace[oldFacei] == 3)
1123 globalFaceMap[oldFacei] = facei;
1124 faceMap_[facei++] = oldFacei;
1127 markPoints(oldFaces[oldFacei], globalPointMap);
1130 boundaryPatchSizes[oldInternalPatchID]++;
1137 label oldPatchi = nextPatchID;
1138 oldPatchi < oldPatches.
size();
1142 const polyPatch& oldPatch = oldPatches[oldPatchi];
1148 if (nCellsUsingFace[oldFacei] == 1)
1153 globalFaceMap[oldFacei] = facei;
1154 faceMap_[facei++] = oldFacei;
1157 markPoints(oldFaces[oldFacei], globalPointMap);
1160 boundaryPatchSizes[globalPatchMap[oldPatchi]]++;
1166 if (facei != nFacesInSet)
1174 label nPointsInSet = 0;
1176 forAll(globalPointMap, pointi)
1178 if (globalPointMap[pointi] != -1)
1183 pointMap_.
setSize(nPointsInSet);
1187 forAll(globalPointMap, pointi)
1189 if (globalPointMap[pointi] != -1)
1191 pointMap_[nPointsInSet] = pointi;
1192 globalPointMap[pointi] = nPointsInSet;
1201 label nNewPoints = 0;
1203 forAll(pointMap_, pointi)
1205 newPoints[nNewPoints] = oldPoints[pointMap_[pointi]];
1211 label nNewFaces = 0;
1214 for (
label facei = 0; facei < nInternalFaces; facei++)
1216 const face& oldF = oldFaces[faceMap_[facei]];
1222 newF[i] = globalPointMap[oldF[i]];
1225 newFaces[nNewFaces] = newF;
1232 for (
label facei = nInternalFaces; facei < faceMap_.
size(); facei++)
1234 const label oldFacei = faceMap_[facei];
1236 face oldF = oldFaces[oldFacei];
1244 region[oldOwner[oldFacei]] != currentRegion
1245 && region[oldNeighbour[oldFacei]] == currentRegion
1248 oldF = oldFaces[oldFacei].reverseFace();
1257 newF[i] = globalPointMap[oldF[i]];
1260 newFaces[nNewFaces] = newF;
1269 label nNewCells = 0;
1273 const labelList& oldC = oldCells[cellMap_[celli]];
1279 newC[i] = globalFaceMap[oldC[i]];
1282 newCells[nNewCells] =
cell(newC);
1288 fvMeshSubsetPtr_.clear();
1296 fvMeshSubsetPtr_.reset
1318 label nNewPatches = 0;
1319 label patchStart = nInternalFaces;
1327 labelList globalPatchSizes(boundaryPatchSizes);
1328 globalPatchSizes.
setSize(nextPatchID);
1348 bool samePatches =
true;
1350 for (
label proci = 1; proci < patchNames.
size(); proci++)
1352 if (patchNames[proci] != patchNames[0])
1354 samePatches =
false;
1372 label oldPatchi = 0;
1373 oldPatchi < oldPatches.
size()
1374 && oldPatchi < nextPatchID;
1378 const label newSize = boundaryPatchSizes[globalPatchMap[oldPatchi]];
1381 newBoundary[nNewPatches] = oldPatches[oldPatchi].
clone 1383 fvMeshSubsetPtr_().boundaryMesh(),
1389 patchStart += newSize;
1390 patchMap_[nNewPatches] = oldPatchi;
1396 if (wantedPatchID == -1)
1398 label oldInternalSize = boundaryPatchSizes[oldInternalPatchID];
1406 if (oldInternalSize > 0)
1411 boundaryPatchSizes[oldInternalPatchID],
1414 fvMeshSubsetPtr_().boundaryMesh(),
1415 internalPolyPatch::typeName
1420 patchStart += boundaryPatchSizes[oldInternalPatchID];
1421 patchMap_[nNewPatches] = -1;
1434 label oldPatchi = nextPatchID;
1435 oldPatchi < oldPatches.
size();
1439 const label newSize = boundaryPatchSizes[globalPatchMap[oldPatchi]];
1442 newBoundary[nNewPatches] = oldPatches[oldPatchi].
clone 1444 fvMeshSubsetPtr_().boundaryMesh(),
1450 patchStart += newSize;
1451 patchMap_[nNewPatches] = oldPatchi;
1457 newBoundary.
setSize(nNewPatches);
1458 patchMap_.
setSize(nNewPatches);
1462 fvMeshSubsetPtr_().addFvPatches(newBoundary, syncPar);
1472 const label patchID,
1480 region[iter.key()] = 1;
1489 const label currentRegion,
1490 const bool syncCouples
1494 const labelList cellsToRemove(getCellsToRemove(region, currentRegion));
1503 const label currentRegion,
1506 const bool syncCouples
1510 labelList cellsToRemove(getCellsToRemove(region, currentRegion));
1541 pointMap_ = map().pointMap();
1542 faceMap_ = map().faceMap();
1543 cellMap_ = map().cellMap();
1550 return fvMeshSubsetPtr_.valid();
1558 return fvMeshSubsetPtr_();
1566 return fvMeshSubsetPtr_();
1588 if (!faceFlipMapPtr_.valid())
1602 for (
label subFacei = 0; subFacei < subInt; subFacei++)
1604 faceFlipMap[subFacei] = subToBaseFace[subFacei] + 1;
1606 for (
label subFacei = subInt; subFacei < subOwn.
size(); subFacei++)
1608 const label facei = subToBaseFace[subFacei];
1609 if (subToBaseCell[subOwn[subFacei]] == own[facei])
1611 faceFlipMap[subFacei] = facei + 1;
1615 faceFlipMap[subFacei] = -facei - 1;
1620 return faceFlipMapPtr_();
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Constraint patch to hold internal faces exposed by sub-setting.
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
autoPtr< IOobject > clone() const
Clone.
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.
const meshCellZones & cellZones() const
Return cell zones.
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.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
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.
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 labelList & faceFlipMap() const
Return face map with sign to encode flipped faces.
const cellList & cells() const
static void listCombineGather(const List< commsStruct > &comms, List< T > &Value, const CombineOp &cop, const int tag, const label comm)
fvMeshSubset(const fvMesh &)
Construct given a mesh to subset.
label size() const
Return number of elements in table.
const labelList & faceMap() const
Return face map.
const meshPointZones & pointZones() const
Return point zones.
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.
const labelList & patchMap() const
Return patch map.
const fvMesh & subMesh() const
Return reference to subset mesh.
labelList getExposedFaces(const labelList ®ion, const label currentRegion, const bool syncCouples=true) const
Get labels of exposed faces.
bool found(const Key &) const
Return true if hashedEntry is found in table.
wordList names() const
Return a list of patch names.
wordList patchNames(nPatches)
virtual const labelList & faceOwner() const
Return face owner.
const labelList & pointMap() const
Return point map.
static const label labelMax
List< label > labelList
A List of labels.
const labelList & cellMap() const
Return cell map.
virtual const faceList & faces() const
Return raw faces.
MeshZones< pointZone, polyMesh > meshPointZones
A MeshZones with the type pointZone.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
errorManip< error > abort(error &err)
MeshZones< cellZone, polyMesh > meshCellZones
A MeshZones with the type cellZone.
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.
MeshZones< faceZone, polyMesh > meshFaceZones
A MeshZones with the type faceZone.
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.
A cell is defined as a list of faces with extra functionality.
const meshFaceZones & faceZones() const
Return face zones.
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.
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 fvMesh & baseMesh() const
Original mesh.
bool hasSubMesh() const
Have subMesh?