53 for (
auto idx : locations)
73 if (selectedElements.
empty() || subsetMap.
empty())
80 const bitSet selected(nElems, selectedElements);
86 if (selected[subsetMap[i]])
98 if (selected[subsetMap[i]])
100 subsettedElements[
n] = i;
105 return subsettedElements;
118 <<
"Mesh is not subsetted!" <<
nl
128void Foam::fvMeshSubset::calcFaceFlipMap()
const
131 const labelList& subToBaseCell = cellMap();
134 auto& faceFlipMap = *faceFlipMapPtr_;
138 const label subInt = subMesh().nInternalFaces();
140 const labelList& subOwn = subMesh().faceOwner();
141 const labelList& own = baseMesh_.faceOwner();
143 for (label subFaceI = 0; subFaceI < subInt; ++subFaceI)
145 faceFlipMap[subFaceI] = subToBaseFace[subFaceI]+1;
147 for (label subFaceI = subInt; subFaceI < subOwn.
size(); ++subFaceI)
149 const label faceI = subToBaseFace[subFaceI];
150 if (subToBaseCell[subOwn[subFaceI]] == own[faceI])
152 faceFlipMap[subFaceI] = faceI+1;
156 faceFlipMap[subFaceI] = -faceI-1;
162void Foam::fvMeshSubset::doCoupledPatches
173 label nUncoupled = 0;
182 const auto* procPatch = isA<processorPolyPatch>(pp);
186 const label nbrProci = procPatch->neighbProcNo();
190 if (!nCellsUsingFace.
empty())
205 for (
const polyPatch& pp : oldPatches)
207 const auto* procPatch = isA<processorPolyPatch>(pp);
211 const label nbrProci = procPatch->neighbProcNo();
213 UIPstream fromNeighbour(nbrProci, pBufs);
219 if (!nCellsUsingFace.
empty())
221 const labelList& nbrCellsUsingFace(nbrList);
229 nCellsUsingFace[pp.start()+i] == 1
230 && nbrCellsUsingFace[i] == 0
235 nCellsUsingFace[pp.start()+i] = 3;
245 for (
const polyPatch& pp : oldPatches)
247 const cyclicPolyPatch* cpp = isA<cyclicPolyPatch>(pp);
249 if (cpp && !nCellsUsingFace.
empty())
251 const auto& cycPatch = *cpp;
255 label thisFacei = cycPatch.start() + i;
256 label otherFacei = cycPatch.transformGlobalFace(thisFacei);
260 nCellsUsingFace[thisFacei] == 1
261 && nCellsUsingFace[otherFacei] == 0
264 nCellsUsingFace[thisFacei] = 3;
273 reduce(nUncoupled, sumOp<label>());
278 Info<<
"Uncoupled " << nUncoupled <<
" faces on coupled patches. "
279 <<
"(processorPolyPatch, cyclicPolyPatch)" <<
endl;
284void Foam::fvMeshSubset::subsetZones()
292 auto& newSubMesh = subMeshPtr_();
298 List<pointZone*>
pZones(pointZones.size());
302 const pointZone& pz = pointZones[zonei];
304 pZones[zonei] =
new pointZone
309 newSubMesh.pointZones()
320 List<faceZone*> fZones(faceZones.size());
324 const faceZone& fz = faceZones[zonei];
333 zone[fz[j]] = (fz.flipMap()[j] ? 1 : -1);
350 const label meshFacei =
faceMap()[subFacei];
351 if (zone[meshFacei] != 0)
353 subAddressing[nSub] = subFacei;
354 const label subOwner = subMesh().faceOwner()[subFacei];
355 const label baseOwner = baseMesh().faceOwner()[meshFacei];
357 const bool sameOwner = (cellMap()[subOwner] == baseOwner);
358 const bool flip = (zone[meshFacei] == 1);
359 subFlipStatus[nSub] = (sameOwner == flip);
365 fZones[zonei] =
new faceZone
371 newSubMesh.faceZones()
380 List<cellZone*> cZones(cellZones.size());
384 const cellZone& cz = cellZones[zonei];
386 cZones[zonei] =
new cellZone
391 newSubMesh.cellZones()
396 newSubMesh.addZones(
pZones, fZones, cZones);
405 subMeshPtr_(nullptr),
406 faceFlipMapPtr_(nullptr),
425 const bitSet& selectedCells,
483 subMeshPtr_.reset(
nullptr);
484 faceFlipMapPtr_.reset(
nullptr);
508 subMeshPtr_.reset(std::move(subMeshPtr));
509 faceFlipMapPtr_.reset(
nullptr);
511 pointMap_ = std::move(pointMap);
513 cellMap_ = std::move(cellMap);
514 patchMap_ = std::move(patchMap);
536 baseMesh_.time().timeName(),
546 auto& newSubMesh = subMeshPtr_();
558 forAll(newPatches, patchi)
563 oldBoundary[patchi].clone
573 newSubMesh.addFvPatches(newPatches);
584 const bitSet& selectedCells,
592 const cellList& oldCells = baseMesh().cells();
593 const faceList& oldFaces = baseMesh().faces();
594 const pointField& oldPoints = baseMesh().points();
595 const labelList& oldOwner = baseMesh().faceOwner();
596 const labelList& oldNeighbour = baseMesh().faceNeighbour();
598 const label oldNInternalFaces = baseMesh().nInternalFaces();
604 if (wantedPatchID == -1)
608 wantedPatchID = oldPatches.
findPatchID(exposedPatchName);
610 else if (wantedPatchID < 0 || wantedPatchID >= oldPatches.
size())
613 <<
"Non-existing patch index " << wantedPatchID <<
endl
614 <<
"Should be between 0 and " << oldPatches.
size()-1
624 label len = cellMap_.
size();
628 i >= 0 && (cellMap_[i] >= oldCells.
size());
634 cellMap_.resize(len);
650 label nFacesInSet = 0;
652 forAll(oldFaces, oldFacei)
654 bool faceUsed =
false;
656 if (selectedCells.
test(oldOwner[oldFacei]))
658 ++nCellsUsingFace[oldFacei];
664 baseMesh().isInternalFace(oldFacei)
665 && selectedCells.
test(oldNeighbour[oldFacei])
668 ++nCellsUsingFace[oldFacei];
677 faceMap_.
resize(nFacesInSet);
680 doCoupledPatches(syncPar, nCellsUsingFace);
684 label oldInternalPatchID = 0;
687 label nextPatchID = oldPatches.
size();
693 label nbSize = oldPatches.
size();
695 if (wantedPatchID == -1)
701 forAll(oldPatches, patchi)
703 if (isA<processorPolyPatch>(oldPatches[patchi]))
705 nextPatchID = patchi;
708 ++oldInternalPatchID;
714 for (label oldPatchi = 0; oldPatchi < nextPatchID; oldPatchi++)
716 globalPatchMap[oldPatchi] = oldPatchi;
720 label oldPatchi = nextPatchID;
721 oldPatchi < oldPatches.
size();
725 globalPatchMap[oldPatchi] = oldPatchi+1;
730 oldInternalPatchID = wantedPatchID;
731 nextPatchID = wantedPatchID+1;
747 for (label oldFacei = 0; oldFacei < oldNInternalFaces; ++oldFacei)
749 if (nCellsUsingFace[oldFacei] == 2)
751 globalFaceMap[oldFacei] = facei;
752 faceMap_[facei++] = oldFacei;
755 markUsed(oldFaces[oldFacei], globalPointMap);
760 const label nInternalFaces = facei;
766 oldPatchi < oldPatches.
size()
767 && oldPatchi < nextPatchID;
771 const polyPatch& oldPatch = oldPatches[oldPatchi];
773 label oldFacei = oldPatch.
start();
777 if (nCellsUsingFace[oldFacei] == 1)
782 globalFaceMap[oldFacei] = facei;
783 faceMap_[facei++] = oldFacei;
786 markUsed(oldFaces[oldFacei], globalPointMap);
789 ++boundaryPatchSizes[globalPatchMap[oldPatchi]];
796 for (label oldFacei = 0; oldFacei < oldNInternalFaces; ++oldFacei)
798 if (nCellsUsingFace[oldFacei] == 1)
800 globalFaceMap[oldFacei] = facei;
801 faceMap_[facei++] = oldFacei;
804 markUsed(oldFaces[oldFacei], globalPointMap);
807 ++boundaryPatchSizes[oldInternalPatchID];
814 label oldFacei = oldNInternalFaces;
815 oldFacei < oldFaces.
size();
819 if (nCellsUsingFace[oldFacei] == 3)
821 globalFaceMap[oldFacei] = facei;
822 faceMap_[facei++] = oldFacei;
825 markUsed(oldFaces[oldFacei], globalPointMap);
828 ++boundaryPatchSizes[oldInternalPatchID];
835 label oldPatchi = nextPatchID;
836 oldPatchi < oldPatches.
size();
840 const polyPatch& oldPatch = oldPatches[oldPatchi];
842 label oldFacei = oldPatch.
start();
846 if (nCellsUsingFace[oldFacei] == 1)
851 globalFaceMap[oldFacei] = facei;
852 faceMap_[facei++] = oldFacei;
855 markUsed(oldFaces[oldFacei], globalPointMap);
858 ++boundaryPatchSizes[globalPatchMap[oldPatchi]];
864 if (facei != nFacesInSet)
872 label nPointsInSet = 0;
874 forAll(globalPointMap, pointi)
876 if (globalPointMap[pointi] != -1)
881 pointMap_.setSize(nPointsInSet);
885 forAll(globalPointMap, pointi)
887 if (globalPointMap[pointi] != -1)
889 pointMap_[nPointsInSet] = pointi;
890 globalPointMap[pointi] = nPointsInSet;
916 auto iter = newFaces.
begin();
917 const auto& renumbering = globalPointMap;
920 for (label facei = 0; facei < nInternalFaces; ++facei)
922 face& newItem = *iter;
925 const face& oldItem = oldFaces[faceMap_[facei]];
932 newItem[i] = renumbering[oldItem[i]];
937 for (label facei = nInternalFaces; facei < faceMap_.size(); ++facei)
939 const label oldFacei = faceMap_[facei];
941 face& newItem = *iter;
947 baseMesh().isInternalFace(oldFacei)
948 && selectedCells.
test(oldNeighbour[oldFacei])
949 && !selectedCells.
test(oldOwner[oldFacei])
952 ? oldFaces[oldFacei].reverseFace()
961 newItem[i] = renumbering[oldItem[i]];
973 auto iter = newCells.
begin();
974 const auto& renumbering = globalFaceMap;
976 for (
const label oldCelli : cellMap_)
978 cell& newItem = *iter;
981 const labelList& oldItem = oldCells[oldCelli];
988 newItem[i] = renumbering[oldItem[i]];
1006 baseMesh_.time().timeName(),
1012 std::move(newPoints),
1013 std::move(newFaces),
1014 std::move(newCells),
1021 patchMap_.resize(nbSize);
1022 label nNewPatches = 0;
1023 label patchStart = nInternalFaces;
1031 labelList globalPatchSizes(boundaryPatchSizes);
1032 globalPatchSizes.
setSize(nextPatchID);
1050 bool samePatches =
true;
1056 samePatches =
false;
1074 label oldPatchi = 0;
1075 oldPatchi < oldPatches.
size()
1076 && oldPatchi < nextPatchID;
1080 const label newSize = boundaryPatchSizes[globalPatchMap[oldPatchi]];
1082 if (oldInternalPatchID != oldPatchi)
1087 for (label patchFacei = 0; patchFacei < newSize; patchFacei++)
1089 const label facei = patchStart+patchFacei;
1090 const label oldFacei = faceMap_[facei];
1091 map[patchFacei] = oldPatches[oldPatchi].whichFace(oldFacei);
1097 oldPatches[oldPatchi].clone
1112 oldPatches[oldPatchi].clone
1122 patchStart += newSize;
1123 patchMap_[nNewPatches] = oldPatchi;
1129 if (wantedPatchID == -1)
1131 label oldInternalSize = boundaryPatchSizes[oldInternalPatchID];
1139 if (oldInternalSize > 0)
1147 boundaryPatchSizes[oldInternalPatchID],
1160 patchStart += boundaryPatchSizes[oldInternalPatchID];
1161 patchMap_[nNewPatches] = -1;
1170 label oldPatchi = nextPatchID;
1171 oldPatchi < oldPatches.
size();
1175 const label newSize = boundaryPatchSizes[globalPatchMap[oldPatchi]];
1177 if (oldInternalPatchID != oldPatchi)
1182 for (label patchFacei = 0; patchFacei < newSize; patchFacei++)
1184 const label facei = patchStart+patchFacei;
1185 const label oldFacei = faceMap_[facei];
1186 map[patchFacei] = oldPatches[oldPatchi].whichFace(oldFacei);
1192 oldPatches[oldPatchi].clone
1207 oldPatches[oldPatchi].clone
1220 patchStart += newSize;
1221 patchMap_[nNewPatches] = oldPatchi;
1227 newBoundary.
resize(nNewPatches);
1228 patchMap_.resize(nNewPatches);
1232 subMeshPtr_().addFvPatches(newBoundary, syncPar);
1273 const label regioni,
Defines the attributes of an object for which implicit objectRegistry management is supported,...
void setSize(const label n)
Alias for resize()
void resize(const label len)
Adjust allocated size of list.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
void finishedSends(const bool wait=true)
Mark sends as done.
static void allGatherList(const List< commsStruct > &comms, List< T > &values, const int tag, const label comm)
static void listCombineAllGather(const List< commsStruct > &comms, List< T > &values, const CombineOp &cop, const int tag, const label comm)
After completion all processors have the same data.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
const T * set(const label i) const
void resize(const label newLen)
Adjust size of PtrList.
A List obtained as a section of another List.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
iterator begin() noexcept
Return an iterator to begin traversing the UList.
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
void size(const label n)
Older name for setAddressableSize.
@ nonBlocking
"nonBlocking"
static bool & parRun() noexcept
Test if this a parallel run.
label size() const noexcept
The number of elements in the list.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
labelList sortedToc() const
The indices of the on bits as a sorted labelList.
bool test(const label pos) const
Test value at specified position, never auto-vivify entries.
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
A cell is defined as a list of faces with extra functionality.
Empty front and back plane patch. Used for 2-D geometries.
A face is a list of labels corresponding to mesh vertices.
Holds a reference to the original mesh (the baseMesh) and optionally to a subset of that mesh (the su...
bool checkHasSubMesh() const
FatalError if subset has not been performed.
static word exposedPatchName
Name for exposed internal faces (default: oldInternalFaces)
void clear()
Reset subMesh and all maps.
void reset()
Reset subMesh and all maps. Same as clear()
Mesh data needed to do the Finite Volume discretisation.
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
label nNonProcessor() const
The number of patches before the first processor patch.
label findPatchID(const word &patchName, const bool allowNotFound=true) const
Find patch index given a name, return -1 if not found.
wordList names() const
Return a list of patch names.
A patch is a list of labels that address the faces in the global face list.
label start() const
Return start label of this patch in the polyMesh face list.
int myProcNo() const noexcept
Return processor number.
A class for handling words, derived from Foam::string.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
IOporosityModelList pZones(mesh)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const labelList nFaces(UPstream::listGatherValues< label >(aMesh.nFaces()))
bitSet create(const label n, const labelHashSet &locations, const bool on=true)
Create a bitSet with length n with the specified on locations.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
List< label > labelList
A List of labels.
ZoneMesh< cellZone, polyMesh > cellZoneMesh
A ZoneMesh with the type cellZone.
ZoneMesh< pointZone, polyMesh > pointZoneMesh
A ZoneMesh with the type pointZone.
static labelList subsetSubset(const label nElems, const labelUList &selectedElements, const labelUList &subsetMap)
messageStream Info
Information stream (stdout output on master, null elsewhere)
ZoneMesh< faceZone, polyMesh > faceZoneMesh
A ZoneMesh with the type faceZone.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
errorManip< error > abort(error &err)
List< bool > boolList
A List of bools.
static constexpr const zero Zero
Global zero (0)
constexpr char nl
The newline '\n' character (0x0a)
wordList patchNames(nPatches)
#define forAll(list, i)
Loop across all elements in list.
static const char *const typeName
The type name used in ensight case files.