44 static constexpr Foam::label
BLOCKED = -2;
53 template<
class Container>
56 const label len = input.
size();
60 for (label i = 0; i < len; ++i)
62 output[i] = input[i].
size();
73 void Foam::regionSplit::updateFacePair
79 DynamicList<label>& facesChanged
84 if (faceRegion[face1] >= 0)
86 faceRegion[face0] = faceRegion[face1];
87 facesChanged.append(face0);
89 else if (faceRegion[face1] ==
BLOCKED)
95 else if (faceRegion[face0] >= 0)
99 faceRegion[face1] = faceRegion[face0];
100 facesChanged.append(face1);
102 else if (faceRegion[face1] ==
BLOCKED)
107 else if (faceRegion[face1] != faceRegion[face0])
110 <<
"Problem : coupled face " << face0
112 <<
" has region " << faceRegion[face0]
113 <<
" but coupled face " << face1
114 <<
" has region " << faceRegion[face1] <<
nl
115 <<
"Is your blocked faces specification"
116 <<
" synchronized across coupled boundaries?" <<
endl
123 void Foam::regionSplit::fillSeedMask
125 const List<labelPair>& explicitConnections,
126 const label seedCellId,
127 const label markValue,
133 cellRegion[seedCellId] = markValue;
136 changedFaces_.clear();
137 for (
const label facei :
mesh().
cells()[seedCellId])
141 faceRegion[facei] = markValue;
142 changedFaces_.append(facei);
150 while (changedFaces_.size())
152 changedCells_.
clear();
154 for (
const label facei : changedFaces_)
160 cellRegion[own] = markValue;
161 changedCells_.
append(own);
164 if (
mesh().isInternalFace(facei))
170 cellRegion[nei] = markValue;
171 changedCells_.
append(nei);
178 Pout<<
" Changed cells / faces : "
179 << changedCells_.size() <<
" / " << changedFaces_.size()
180 <<
" before sync" <<
endl;
184 changedFaces_.clear();
185 for (
const label celli : changedCells_)
187 for (
const label facei :
mesh().
cells()[celli])
191 faceRegion[facei] = markValue;
192 changedFaces_.append(facei);
201 for (
const polyPatch& pp :
patches)
205 isA<cyclicPolyPatch>(pp)
206 && refCast<const cyclicPolyPatch>(pp).owner()
211 const cyclicPolyPatch& cycPatch =
212 refCast<const cyclicPolyPatch>(pp);
214 label face0 = cycPatch.start();
218 const label face1 = cycPatch.transformGlobalFace(face0);
233 for (
const labelPair& pr : explicitConnections)
246 Pout<<
" Changed faces : "
247 << changedFaces_.size()
248 <<
" after sync" <<
endl;
254 Foam::label Foam::regionSplit::calcLocalRegionSplit
257 const List<labelPair>& explicitConnections,
262 clockValue timing(
debug);
266 if (blockedFace.size())
269 boolList syncBlockedFace(blockedFace);
272 forAll(syncBlockedFace, facei)
274 if (syncBlockedFace[facei] != blockedFace[facei])
277 <<
"Face " << facei <<
" not synchronised. My value:"
278 << blockedFace[facei] <<
" coupled value:"
279 << syncBlockedFace[facei]
286 changedCells_.reserve(mesh_.nCells());
287 changedFaces_.reserve(mesh_.nFaces());
294 if (blockedFace.size())
296 forAll(blockedFace, facei)
298 if (blockedFace[facei])
310 label nLocalRegions = 0;
312 for (label seedCellId = 0; seedCellId < cellRegion.size(); ++seedCellId)
316 for (; seedCellId < cellRegion.size(); ++seedCellId)
324 if (seedCellId >= cellRegion.size())
342 changedCells_.clearStorage();
343 changedFaces_.clearStorage();
349 if (cellRegion[celli] < 0)
352 <<
"cell:" << celli <<
" region:" << cellRegion[celli]
362 <<
"face:" << facei <<
" region:" << faceRegion[facei]
368 DebugInfo <<
"regionSplit = " << double(timing.elapsed()) <<
"s\n";
370 return nLocalRegions;
376 const bool doGlobalRegions,
378 const List<labelPair>& explicitConnections,
383 const label nLocalRegions = calcLocalRegionSplit
390 if (!doGlobalRegions)
395 return reduceRegions(nLocalRegions, blockedFace, cellRegion);
404 const bool doGlobalRegions
410 globalNumberingPtr_ = calcRegionSplit
424 const bool doGlobalRegions
430 globalNumberingPtr_ = calcRegionSplit
445 const bool doGlobalRegions
451 globalNumberingPtr_ = calcRegionSplit
465 const label numLocalRegions,
476 <<
"The cellRegion size " << cellRegion.size()
477 <<
" is not equal to the of number of cells "
486 const label nLocalRegions =
502 for (
const label regioni : cellRegion)
504 localToGlobal.insert(regioni, globalRegions.
toGlobal(regioni));
535 bool emitWarning =
true;
541 Pout<<
nl <<
"-- Starting Iteration --" <<
endl;
544 updateLookup.clear();
562 const label meshFacei = pp.start()+patchFacei;
564 if (!blockedFace[meshFacei])
567 const label orig = cellRegion[
faceCells[patchFacei]];
569 patchNbrRegion[patchFacei] = localToGlobal[orig];
591 const label meshFacei = pp.start()+patchFacei;
593 if (!blockedFace[meshFacei])
597 const label orig = cellRegion[
faceCells[patchFacei]];
599 const label sent = localToGlobal[orig];
600 const label recv = patchNbrRegion[patchFacei];
606 Pout<<
"Warning in regionSplit:"
607 " received unassigned on "
608 << pp.
name() <<
" at patchFace "
610 <<
". Check synchronisation in caller"
614 else if (recv < sent)
618 auto fnd = updateLookup.find(sent);
621 updateLookup.insert(sent, recv);
623 else if (recv < *fnd)
645 labelList keys(localToGlobal.sortedToc());
649 vals[i] = localToGlobal[keys[i]];
652 Pout<<
"Updated local regions:" <<
nl
658 Pout<<
"Updated " << localToGlobal.size()
659 <<
" local regions" <<
endl;
679 const label regioni = iter.val();
681 if (globalRegions.
isLocal(regioni))
683 localRegion.insert(regioni);
687 nCompact = localRegion.size();
693 const auto& globalCompact = *globalCompactPtr;
703 updateLookup.clear();
725 const label regioni = iter.val();
727 if (globalRegions.
isLocal(regioni))
732 globalCompact.toGlobal(updateLookup.size())
737 nonLocal[globalRegions.
whichProcID(regioni)].insert(regioni);
743 Pout<<
" per processor nonLocal regions: "
749 forAll(sendNonLocal, proci)
751 sendNonLocal[proci] = nonLocal[proci].toc();
758 Pstream::exchange<labelList, label>
773 for (label& regioni : send)
775 regioni = updateLookup[regioni];
780 Pstream::exchange<labelList, label>
794 forAll(recvNonLocal, proci)
796 const labelList& send = sendNonLocal[proci];
797 const labelList& recv = recvNonLocal[proci];
801 updateLookup.insert(send[i], recv[i]);
814 cellRegion[celli] = localToGlobal[cellRegion[celli]];
818 <<
"regionSplit::reduceRegions = " << double(timing.
elapsed()) <<
"s\n";
820 return globalCompactPtr;