45 bool Foam::fvMeshSubset::checkCellSubset()
const 47 if (fvMeshSubsetPtr_.empty())
49 FatalErrorIn(
"bool fvMeshSubset::checkCellSubset() const")
50 <<
"Mesh subset not set. Please set the cell map using " 51 <<
"void setCellSubset(const labelHashSet& cellsToSubset)" <<
endl 52 <<
"before attempting to access subset data" 64 void Foam::fvMeshSubset::markPoints
73 pointMap.insert(curPoints[pointI], 0);
78 void Foam::fvMeshSubset::markPoints
86 pointMap[curPoints[pointI]] = 0;
93 void Foam::fvMeshSubset::doCoupledPatches
99 const polyBoundaryMesh& oldPatches = baseMesh().boundaryMesh();
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);
120 << SubList<label>(nCellsUsingFace, pp.size(), pp.start());
124 pBufs.finishedSends();
127 forAll(oldPatches, oldPatchI)
129 const polyPatch& pp = oldPatches[oldPatchI];
131 if (isA<processorPolyPatch>(pp))
133 const processorPolyPatch& procPatch =
134 refCast<const processorPolyPatch>(pp);
136 UIPstream fromNeighbour(procPatch.neighbProcNo(), pBufs);
138 labelList nbrCellsUsingFace(fromNeighbour);
146 nCellsUsingFace[pp.start()+i] == 1
147 && nbrCellsUsingFace[i] == 0
152 nCellsUsingFace[pp.start()+i] = 3;
161 forAll(oldPatches, oldPatchI)
163 const polyPatch& pp = oldPatches[oldPatchI];
165 if (isA<cyclicPolyPatch>(pp))
167 const cyclicPolyPatch& cycPatch =
168 refCast<const cyclicPolyPatch>(pp);
172 label thisFaceI = cycPatch.start() + i;
173 label otherFaceI = cycPatch.transformGlobalFace(thisFaceI);
177 nCellsUsingFace[thisFaceI] == 1
178 && nCellsUsingFace[otherFaceI] == 0
181 nCellsUsingFace[thisFaceI] = 3;
190 reduce(nUncoupled, sumOp<label>());
195 Info<<
"Uncoupled " << nUncoupled <<
" faces on coupled patches. " 196 <<
"(processorPolyPatch, cyclicPolyPatch)" <<
endl;
210 forAll(selectedElements, i)
212 selected[selectedElements[i]] =
true;
219 if (selected[subsetMap[i]])
231 if (selected[subsetMap[i]])
233 subsettedElements[n++] = i;
237 return subsettedElements;
241 void Foam::fvMeshSubset::subsetZones()
248 List<pointZone*> pZonePtrs(pointZones.size());
252 const pointZone& pz = pointZones[i];
254 pZonePtrs[i] =
new pointZone
259 fvMeshSubsetPtr_().pointZones()
271 List<faceZone*> fZonePtrs(faceZones.size());
275 const faceZone& fz = faceZones[i];
309 if (zone[meshFaceI] != 0)
311 subAddressing[nSub] = subFaceI;
312 label subOwner = subMesh().faceOwner()[subFaceI];
313 label baseOwner = baseMesh().faceOwner()[meshFaceI];
315 bool sameOwner = (cellMap()[subOwner] == baseOwner);
316 bool flip = (zone[meshFaceI] == 1);
317 subFlipStatus[nSub] = (sameOwner == flip);
323 fZonePtrs[i] =
new faceZone
329 fvMeshSubsetPtr_().faceZones()
336 List<cellZone*> cZonePtrs(cellZones.size());
340 const cellZone& cz = cellZones[i];
342 cZonePtrs[i] =
new cellZone
345 subset(baseMesh().nCells(), cz, cellMap()),
347 fvMeshSubsetPtr_().cellZones()
353 fvMeshSubsetPtr_().addZones(pZonePtrs, fZonePtrs, cZonePtrs);
360 Foam::fvMeshSubset::fvMeshSubset(
const fvMesh& baseMesh)
363 fvMeshSubsetPtr_(NULL),
387 label wantedPatchID = patchID;
389 if (wantedPatchID == -1)
393 wantedPatchID = oldPatches.
findPatchID(
"oldInternalFaces");
395 else if (wantedPatchID < 0 || wantedPatchID >= oldPatches.
size())
399 "fvMeshSubset::setCellSubset(const labelHashSet&" 400 ", const label patchID)" 401 ) <<
"Non-existing patch index " << wantedPatchID <<
endl 402 <<
"Should be between 0 and " << oldPatches.
size()-1
407 cellMap_ = globalCellMap.
toc();
413 const label avgNFacesPerCell = 6;
414 const label avgNPointsPerFace = 4;
421 Map<label> facesToSubset(avgNFacesPerCell*nCellsInSet);
426 const labelList& curFaces = oldCells[cellMap_[cellI]];
430 if (!facesToSubset.
found(curFaces[faceI]))
432 facesToSubset.
insert(curFaces[faceI], 1);
436 facesToSubset[curFaces[faceI]]++;
445 Map<label> globalPointMap(avgNPointsPerFace*facesToSubset.
size());
457 if (facesToSubset[facesToc[faceI]] == 2)
460 faceMap_[globalFaceMap.size()] = facesToc[faceI];
461 globalFaceMap.
insert(facesToc[faceI], globalFaceMap.
size());
464 markPoints(oldFaces[facesToc[faceI]], globalPointMap);
469 label nInternalFaces = globalFaceMap.size();
474 if (wantedPatchID != -1)
476 oldPatchStart = oldPatches[wantedPatchID].start();
483 for (; faceI< facesToc.
size(); faceI++)
485 if (facesToc[faceI] >= oldPatchStart)
492 && facesToSubset[facesToc[faceI]] == 1
496 faceMap_[globalFaceMap.size()] = facesToc[faceI];
497 globalFaceMap.insert(facesToc[faceI], globalFaceMap.size());
500 markPoints(oldFaces[facesToc[faceI]], globalPointMap);
505 forAll(facesToc, intFaceI)
509 baseMesh().isInternalFace(facesToc[intFaceI])
510 && facesToSubset[facesToc[intFaceI]] == 1
514 faceMap_[globalFaceMap.size()] = facesToc[intFaceI];
515 globalFaceMap.
insert(facesToc[intFaceI], globalFaceMap.
size());
518 markPoints(oldFaces[facesToc[intFaceI]], globalPointMap);
523 for (; faceI< facesToc.
size(); faceI++)
528 && facesToSubset[facesToc[faceI]] == 1
532 faceMap_[globalFaceMap.size()] = facesToc[faceI];
533 globalFaceMap.insert(facesToc[faceI], globalFaceMap.size());
536 markPoints(oldFaces[facesToc[faceI]], globalPointMap);
543 pointMap_ = globalPointMap.toc();
548 globalPointMap[pointMap_[pointI]] = pointI;
551 Pout<<
"Number of cells in new mesh: " << nCellsInSet <<
endl;
552 Pout<<
"Number of faces in new mesh: " << globalFaceMap.size() <<
endl;
553 Pout<<
"Number of points in new mesh: " << globalPointMap.size() <<
endl;
558 label nNewPoints = 0;
562 newPoints[nNewPoints] = oldPoints[pointMap_[pointI]];
566 faceList newFaces(globalFaceMap.size());
571 for (
label faceI = 0; faceI < nInternalFaces; faceI++)
573 const face& oldF = oldFaces[faceMap_[faceI]];
579 newF[i] = globalPointMap[oldF[i]];
582 newFaces[nNewFaces] = newF;
589 label oldInternalPatchID = -1;
591 if (wantedPatchID == -1)
595 oldInternalPatchID = nbSize;
601 oldInternalPatchID = wantedPatchID;
611 for (
label faceI = nInternalFaces; faceI < faceMap_.
size(); faceI++)
613 label oldFaceI = faceMap_[faceI];
615 face oldF = oldFaces[oldFaceI];
623 !globalCellMap.
found(oldOwner[oldFaceI])
624 && globalCellMap.
found(oldNeighbour[oldFaceI])
627 oldF = oldFaces[oldFaceI].reverseFace();
631 boundaryPatchSizes[oldInternalPatchID]++;
639 boundaryPatchSizes[patchOfFace]++;
646 newF[i] = globalPointMap[oldF[i]];
649 newFaces[nNewFaces] = newF;
662 const labelList& oldC = oldCells[cellMap_[cellI]];
668 newC[i] = globalFaceMap[oldC[i]];
671 newCells[nNewCells] =
cell(newC);
677 fvMeshSubsetPtr_.clear();
679 fvMeshSubsetPtr_.reset
701 label nNewPatches = 0;
702 label patchStart = nInternalFaces;
704 forAll(oldPatches, patchI)
706 if (boundaryPatchSizes[patchI] > 0)
709 newBoundary[nNewPatches] = oldPatches[patchI].
clone 713 boundaryPatchSizes[patchI],
717 patchStart += boundaryPatchSizes[patchI];
718 patchMap_[nNewPatches] = patchI;
723 if (wantedPatchID == -1)
726 if (boundaryPatchSizes[oldInternalPatchID] > 0)
731 boundaryPatchSizes[oldInternalPatchID],
735 emptyPolyPatch::typeName
740 patchMap_[nNewPatches] = -1;
746 newBoundary.
setSize(nNewPatches);
747 patchMap_.
setSize(nNewPatches);
750 fvMeshSubsetPtr_().addFvPatches(newBoundary);
760 const label currentRegion,
775 if (region.
size() != oldCells.
size())
779 "fvMeshSubset::setCellSubset(const labelList&" 780 ", const label, const label, const bool)" 781 ) <<
"Size of region " << region.
size()
782 <<
" is not equal to number of cells in mesh " << oldCells.
size()
787 label wantedPatchID = patchID;
789 if (wantedPatchID == -1)
793 wantedPatchID = oldPatches.
findPatchID(
"oldInternalFaces");
795 else if (wantedPatchID < 0 || wantedPatchID >= oldPatches.
size())
799 "fvMeshSubset::setCellSubset(const labelList&" 800 ", const label, const label, const bool)" 801 ) <<
"Non-existing patch index " << wantedPatchID <<
endl 802 <<
"Should be between 0 and " << oldPatches.
size()-1
809 label nCellsInSet = 0;
813 if (region[oldCellI] == currentRegion)
815 cellMap_[nCellsInSet++] = oldCellI;
833 label nFacesInSet = 0;
834 forAll(oldFaces, oldFaceI)
836 bool faceUsed =
false;
838 if (region[oldOwner[oldFaceI]] == currentRegion)
840 nCellsUsingFace[oldFaceI]++;
847 && (region[oldNeighbour[oldFaceI]] == currentRegion)
850 nCellsUsingFace[oldFaceI]++;
862 doCoupledPatches(syncPar, nCellsUsingFace);
866 label oldInternalPatchID = 0;
877 if (wantedPatchID == -1)
883 forAll(oldPatches, patchI)
885 if (isA<processorPolyPatch>(oldPatches[patchI]))
887 nextPatchID = patchI;
890 oldInternalPatchID++;
896 for (
label oldPatchI = 0; oldPatchI < nextPatchID; oldPatchI++)
898 globalPatchMap[oldPatchI] = oldPatchI;
902 label oldPatchI = nextPatchID;
903 oldPatchI < oldPatches.
size();
907 globalPatchMap[oldPatchI] = oldPatchI+1;
912 oldInternalPatchID = wantedPatchID;
913 nextPatchID = wantedPatchID+1;
929 for (
label oldFaceI = 0; oldFaceI < oldNInternalFaces; oldFaceI++)
931 if (nCellsUsingFace[oldFaceI] == 2)
933 globalFaceMap[oldFaceI] = faceI;
934 faceMap_[faceI++] = oldFaceI;
937 markPoints(oldFaces[oldFaceI], globalPointMap);
942 label nInternalFaces = faceI;
948 oldPatchI < oldPatches.
size()
949 && oldPatchI < nextPatchID;
953 const polyPatch& oldPatch = oldPatches[oldPatchI];
959 if (nCellsUsingFace[oldFaceI] == 1)
964 globalFaceMap[oldFaceI] = faceI;
965 faceMap_[faceI++] = oldFaceI;
968 markPoints(oldFaces[oldFaceI], globalPointMap);
971 boundaryPatchSizes[globalPatchMap[oldPatchI]]++;
978 for (
label oldFaceI = 0; oldFaceI < oldNInternalFaces; oldFaceI++)
980 if (nCellsUsingFace[oldFaceI] == 1)
982 globalFaceMap[oldFaceI] = faceI;
983 faceMap_[faceI++] = oldFaceI;
986 markPoints(oldFaces[oldFaceI], globalPointMap);
989 boundaryPatchSizes[oldInternalPatchID]++;
996 label oldFaceI = oldNInternalFaces;
997 oldFaceI < oldFaces.
size();
1001 if (nCellsUsingFace[oldFaceI] == 3)
1003 globalFaceMap[oldFaceI] = faceI;
1004 faceMap_[faceI++] = oldFaceI;
1007 markPoints(oldFaces[oldFaceI], globalPointMap);
1010 boundaryPatchSizes[oldInternalPatchID]++;
1017 label oldPatchI = nextPatchID;
1018 oldPatchI < oldPatches.
size();
1022 const polyPatch& oldPatch = oldPatches[oldPatchI];
1028 if (nCellsUsingFace[oldFaceI] == 1)
1033 globalFaceMap[oldFaceI] = faceI;
1034 faceMap_[faceI++] = oldFaceI;
1037 markPoints(oldFaces[oldFaceI], globalPointMap);
1040 boundaryPatchSizes[globalPatchMap[oldPatchI]]++;
1046 if (faceI != nFacesInSet)
1050 "fvMeshSubset::setCellSubset(const labelList&" 1051 ", const label, const label, const bool)" 1057 label nPointsInSet = 0;
1059 forAll(globalPointMap, pointI)
1061 if (globalPointMap[pointI] != -1)
1066 pointMap_.
setSize(nPointsInSet);
1070 forAll(globalPointMap, pointI)
1072 if (globalPointMap[pointI] != -1)
1074 pointMap_[nPointsInSet] = pointI;
1075 globalPointMap[pointI] = nPointsInSet;
1087 label nNewPoints = 0;
1089 forAll(pointMap_, pointI)
1091 newPoints[nNewPoints] = oldPoints[pointMap_[pointI]];
1097 label nNewFaces = 0;
1100 for (
label faceI = 0; faceI < nInternalFaces; faceI++)
1102 const face& oldF = oldFaces[faceMap_[faceI]];
1108 newF[i] = globalPointMap[oldF[i]];
1111 newFaces[nNewFaces] = newF;
1118 for (
label faceI = nInternalFaces; faceI < faceMap_.
size(); faceI++)
1120 label oldFaceI = faceMap_[faceI];
1122 face oldF = oldFaces[oldFaceI];
1130 region[oldOwner[oldFaceI]] != currentRegion
1131 && region[oldNeighbour[oldFaceI]] == currentRegion
1134 oldF = oldFaces[oldFaceI].reverseFace();
1143 newF[i] = globalPointMap[oldF[i]];
1146 newFaces[nNewFaces] = newF;
1155 label nNewCells = 0;
1159 const labelList& oldC = oldCells[cellMap_[cellI]];
1165 newC[i] = globalFaceMap[oldC[i]];
1168 newCells[nNewCells] =
cell(newC);
1174 fvMeshSubsetPtr_.clear();
1182 fvMeshSubsetPtr_.reset
1204 label nNewPatches = 0;
1205 label patchStart = nInternalFaces;
1213 labelList globalPatchSizes(boundaryPatchSizes);
1214 globalPatchSizes.
setSize(nextPatchID);
1234 bool samePatches =
true;
1236 for (
label procI = 1; procI < patchNames.
size(); procI++)
1238 if (patchNames[procI] != patchNames[0])
1240 samePatches =
false;
1258 label oldPatchI = 0;
1259 oldPatchI < oldPatches.
size()
1260 && oldPatchI < nextPatchID;
1264 label newSize = boundaryPatchSizes[globalPatchMap[oldPatchI]];
1267 newBoundary[nNewPatches] = oldPatches[oldPatchI].
clone 1275 patchStart += newSize;
1276 patchMap_[nNewPatches] = oldPatchI;
1282 if (wantedPatchID == -1)
1284 label oldInternalSize = boundaryPatchSizes[oldInternalPatchID];
1292 if (oldInternalSize > 0)
1297 boundaryPatchSizes[oldInternalPatchID],
1301 emptyPolyPatch::typeName
1309 patchStart += boundaryPatchSizes[oldInternalPatchID];
1310 patchMap_[nNewPatches] = -1;
1319 label oldPatchI = nextPatchID;
1320 oldPatchI < oldPatches.
size();
1324 label newSize = boundaryPatchSizes[globalPatchMap[oldPatchI]];
1327 newBoundary[nNewPatches] = oldPatches[oldPatchI].
clone 1338 patchStart += newSize;
1339 patchMap_[nNewPatches] = oldPatchI;
1345 newBoundary.
setSize(nNewPatches);
1346 patchMap_.
setSize(nNewPatches);
1350 fvMeshSubsetPtr_().addFvPatches(newBoundary, syncPar);
1360 const label patchID,
1368 region[iter.key()] = 1;
1376 return fvMeshSubsetPtr_.valid();
1384 return fvMeshSubsetPtr_();
1392 return fvMeshSubsetPtr_();
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
static bool & parRun()
Is this a parallel run?
Mesh data needed to do the Finite Volume discretisation.
void setCellSubset(const labelHashSet &globalCellMap, const label patchID=-1)
Set the subset. Create "oldInternalFaces" patch for exposed.
ZoneMesh< cellZone, polyMesh > cellZoneMesh
A ZoneMesh with the type cellZone.
label size() const
Return the number of elements in the PtrList.
Foam::autoPtr< IOobject > clone() const
Clone.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
wordList patchNames(nPatches)
word name(const complex &)
Return a string representation of a complex.
A cell is defined as a list of faces with extra functionality.
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
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.
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface...
void size(const label)
Override size to be inconsistent with allocated storage.
const cellList & cells() const
const fvMesh & subMesh() const
Return reference to subset mesh.
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
const labelList & cellMap() const
Return cell map.
A patch is a list of labels that address the faces in the global face list.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
wordList names() const
Return a list of patch names.
A face is a list of labels corresponding to mesh vertices.
const fvMesh & baseMesh() const
Original mesh.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Empty front and back plane patch. Used for 2-D geometries.
void setSize(const label)
Reset size of List.
Ostream & endl(Ostream &os)
Add newline and flush stream.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
virtual const pointField & points() const
Return raw points.
static void listCombineGather(const List< commsStruct > &comms, List< T > &Value, const CombineOp &cop, const int tag, const label comm)
static void listCombineScatter(const List< commsStruct > &comms, List< T > &Value, const int tag, const label comm)
Scatter data. Reverse of combineGather.
label whichPatch(const label faceIndex) const
Return patch index for a given face label.
Template functions to aid in the implementation of demand driven data.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
label size() const
Return number of elements in table.
List< Key > toc() const
Return the table of contents.
errorManip< error > abort(error &err)
virtual const labelList & faceOwner() const
Return face owner.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
const labelList & pointMap() const
Return point map.
const labelList & patchMap() const
Return patch map.
ZoneMesh< pointZone, polyMesh > pointZoneMesh
A ZoneMesh with the type pointZone.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
label start() const
Return start label of this patch in the polyMesh face list.
label nInternalFaces() const
ZoneMesh< faceZone, polyMesh > faceZoneMesh
A ZoneMesh with the type faceZone.
List< label > labelList
A List of labels.
ListType subset(const UList< T > &select, const T &value, const ListType &)
Extract elements of List when select is a certain value.
virtual const faceList & faces() const
Return raw faces.
const labelList & faceMap() const
Return face map.
virtual const labelList & faceNeighbour() const
Return face neighbour.
label findPatchID(const word &patchName) const
Find patch index given a name.
bool found(const Key &) const
Return true if hashedEntry is found in table.
bool hasSubMesh() const
Have subMesh?
prefixOSstream Pout(cout,"Pout")
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
List< bool > boolList
Bool container classes.
static const label labelMax