44 void Foam::regionSplit::transferCoupledFaceRegion
47 const label otherFaceI,
50 DynamicList<label>& newChangedFaces
53 if (faceRegion[faceI] >= 0)
55 if (faceRegion[otherFaceI] == -1)
57 faceRegion[otherFaceI] = faceRegion[faceI];
58 newChangedFaces.append(otherFaceI);
60 else if (faceRegion[otherFaceI] == -2)
65 else if (faceRegion[otherFaceI] != faceRegion[faceI])
69 "regionSplit::transferCoupledFaceRegion"
70 "(const label, const label, labelList&, labelList&) const"
71 ) <<
"Problem : coupled face " << faceI
73 <<
" has region " << faceRegion[faceI]
74 <<
" but coupled face " << otherFaceI
75 <<
" has region " << faceRegion[otherFaceI]
77 <<
"Is your blocked faces specification"
78 <<
" synchronized across coupled boundaries?"
82 else if (faceRegion[faceI] == -1)
84 if (faceRegion[otherFaceI] >= 0)
86 faceRegion[faceI] = faceRegion[otherFaceI];
87 newChangedFaces.append(faceI);
89 else if (faceRegion[otherFaceI] == -2)
98 void Foam::regionSplit::fillSeedMask
100 const List<labelPair>& explicitConnections,
103 const label seedCellID,
104 const label markValue
108 cellRegion[seedCellID] = markValue;
112 const cell& cFaces = mesh_.cells()[seedCellID];
120 label faceI = cFaces[i];
122 if (faceRegion[faceI] == -1)
124 faceRegion[faceI] = markValue;
125 changedFaces[nFaces++] = faceI;
128 changedFaces.setSize(nFaces);
133 while (changedFaces.size())
141 DynamicList<label> changedCells(changedFaces.size());
145 label faceI = changedFaces[i];
147 label own = mesh_.faceOwner()[faceI];
149 if (cellRegion[own] == -1)
151 cellRegion[own] = markValue;
152 changedCells.append(own);
155 if (mesh_.isInternalFace(faceI))
157 label nei = mesh_.faceNeighbour()[faceI];
159 if (cellRegion[nei] == -1)
161 cellRegion[nei] = markValue;
162 changedCells.append(nei);
175 DynamicList<label> newChangedFaces(changedCells.size());
179 label cellI = changedCells[i];
181 const cell& cFaces = mesh_.cells()[cellI];
185 label faceI = cFaces[cFaceI];
187 if (faceRegion[faceI] == -1)
189 faceRegion[faceI] = markValue;
190 newChangedFaces.append(faceI);
206 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
210 const polyPatch& pp = patches[patchI];
212 if (isA<cyclicPolyPatch>(pp))
214 label faceI = pp.start();
216 label halfSz = pp.size()/2;
218 for (label i = 0; i < halfSz; i++)
220 label otherFaceI = refCast<const cyclicPolyPatch>(pp)
221 .transformGlobalFace(faceI);
223 transferCoupledFaceRegion
235 forAll(explicitConnections, i)
237 transferCoupledFaceRegion
239 explicitConnections[i][0],
240 explicitConnections[i][1],
252 changedFaces.transfer(newChangedFaces);
257 Foam::label Foam::regionSplit::calcRegionSplit
260 const List<labelPair>& explicitConnections,
267 if (blockedFace.size())
270 boolList syncBlockedFace(blockedFace);
273 forAll(syncBlockedFace, faceI)
275 if (syncBlockedFace[faceI] != blockedFace[faceI])
279 "regionSplit::calcRegionSplit(..)"
280 ) <<
"Face " << faceI <<
" not synchronised. My value:"
281 << blockedFace[faceI] <<
" coupled value:"
282 << syncBlockedFace[faceI]
292 labelList faceRegion(mesh_.nFaces(), -1);
294 if (blockedFace.size())
296 forAll(blockedFace, faceI)
298 if (blockedFace[faceI])
300 faceRegion[faceI] = -2;
312 label unsetCellI = 0;
318 for (; unsetCellI < mesh_.nCells(); unsetCellI++)
320 if (cellRegion[unsetCellI] == -1)
326 if (unsetCellI >= mesh_.nCells())
351 if (cellRegion[cellI] < 0)
354 <<
"cell:" << cellI <<
" region:" << cellRegion[cellI]
361 if (faceRegion[faceI] == -1)
364 <<
"face:" << faceI <<
" region:" << faceRegion[faceI]
376 globalIndex globalRegions(nRegions);
395 Pout<<
nl <<
"-- Starting Iteration --" <<
endl;
398 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
403 const polyPatch& pp = patches[patchI];
405 if (isA<processorPolyPatch>(pp))
409 label faceI = pp.start();
413 if (faceRegion[faceI] < 0)
415 myGlobalRegions[i] = faceRegion[faceI];
419 myGlobalRegions[i] = mergedGlobal
420 [globalRegions.toGlobal(faceRegion[faceI])];
429 refCast<const processorPolyPatch>(pp).neighbProcNo()
432 toProcNbr << myGlobalRegions;
443 const polyPatch& pp = patches[patchI];
445 if (isA<processorPolyPatch>(pp))
447 const processorPolyPatch& procPp =
448 refCast<const processorPolyPatch>(pp);
457 label faceI = pp.start();
463 faceRegion[faceI] < 0
467 if (faceRegion[faceI] != nbrRegions[i])
470 <<
"On patch:" << pp.name()
472 <<
" my local region:" << faceRegion[faceI]
473 <<
" neighbouring region:"
474 << nbrRegions[i] <<
nl
475 <<
"Maybe your blockedFaces are not"
476 <<
" synchronized across coupled faces?"
482 label uncompactGlobal =
483 globalRegions.toGlobal(faceRegion[faceI]);
485 label myGlobal = mergedGlobal[uncompactGlobal];
487 if (myGlobal != nbrRegions[i])
489 label minRegion =
min(myGlobal, nbrRegions[i]);
493 Pout<<
"Merging region " << myGlobal
495 <<
") and region " << nbrRegions[i]
496 <<
" (on proc " << procPp.neighbProcNo()
497 <<
") into region " << minRegion <<
endl;
500 mergedGlobal[uncompactGlobal] = minRegion;
501 mergedGlobal[myGlobal] = minRegion;
502 mergedGlobal[nbrRegions[i]] = minRegion;
514 reduce(nMerged, sumOp<label>());
518 Pout<<
"nMerged:" << nMerged <<
endl;
538 labelList mergedToCompacted(globalRegions.size(), -1);
544 label merged = mergedGlobal[i];
546 if (mergedToCompacted[merged] == -1)
548 mergedToCompacted[merged] = compactI++;
554 Pout<<
"Compacted down to " << compactI <<
" regions." <<
endl;
560 label region = cellRegion[cellI];
564 label merged = mergedGlobal[globalRegions.toGlobal(region)];
566 cellRegion[cellI] = mergedToCompacted[merged];
605 nRegions_(calcRegionSplit(blockedFace, explicitConnections, *
this))