43 const Foam::label Foam::enrichedPatch::maxFaceSizeDebug_ = 100;
53 void Foam::enrichedPatch::calcCutFaces()
const
55 if (cutFacesPtr_ || cutFaceMasterPtr_ || cutFaceSlavePtr_)
58 <<
"Cut faces addressing already calculated."
74 DynamicList<face> cf(2*lf.size());
75 DynamicList<label> cfMaster(2*lf.size());
76 DynamicList<label> cfSlave(2*lf.size());
106 const face& curLocalFace = lf[facei];
107 const face& curGlobalFace = enFaces[facei];
144 boolList usedFaceEdges(curLocalFace.size(),
false);
146 SLList<edge> edgeSeeds;
149 edgeList cfe = curLocalFace.edges();
150 for (
const edge&
e : cfe)
156 const vector normal = curLocalFace.unitNormal(lp);
158 while (edgeSeeds.size())
162 const edge curEdge = edgeSeeds.removeHead();
165 const label curEdgeWhich = curLocalFace.which(curEdge.start());
172 && curLocalFace.nextLabel(curEdgeWhich) == curEdge.end()
177 if (usedFaceEdges[curEdgeWhich])
continue;
179 usedFaceEdges[curEdgeWhich] =
true;
183 if (edgesUsedTwice.found(curEdge))
continue;
192 DynamicList<label> cutFaceGlobalPoints(2*curLocalFace.size());
193 DynamicList<label> cutFaceLocalPoints(2*curLocalFace.size());
196 label prevPointLabel = curEdge.start();
197 cutFaceGlobalPoints.append(
mp[prevPointLabel]);
198 cutFaceLocalPoints.append(prevPointLabel);
202 label curPointLabel = curEdge.end();
203 point curPoint = lp[curPointLabel];
204 cutFaceGlobalPoints.append(
mp[curPointLabel]);
205 cutFaceLocalPoints.append(curPointLabel);
207 bool completedCutFace =
false;
209 label faceSizeDebug = maxFaceSizeDebug_;
217 const labelList& nextPoints = pp[curPointLabel];
224 vector ahead = curPoint - lp[prevPointLabel];
225 ahead -= normal*(normal & ahead);
235 scalar atanTurn = -GREAT;
236 label bestAtanPoint = -1;
242 if (nextPoints[nextI] != prevPointLabel)
248 vector newDir = lp[nextPoints[nextI]] - curPoint;
251 newDir -= normal*(normal & newDir);
252 scalar magNewDir =
mag(newDir);
256 if (magNewDir < SMALL)
259 <<
"projection error: slave patch probably "
260 <<
"does not project onto master. "
261 <<
"Please switch on "
262 <<
"enriched patch debug for more info"
268 const scalar curAtanTurn =
269 atan2(newDir & right, newDir & ahead);
273 if (curAtanTurn > atanTurn)
275 bestAtanPoint = nextPoints[nextI];
276 atanTurn = curAtanTurn;
294 const label whichNextPoint = curLocalFace.which(curPointLabel);
299 && curLocalFace.nextLabel(whichNextPoint) == bestAtanPoint
300 && usedFaceEdges[whichNextPoint]
309 completedCutFace =
true;
313 if (edgesUsedTwice.found(edge(curPointLabel, bestAtanPoint)))
317 completedCutFace =
true;
322 if (completedCutFace)
continue;
325 if (
mp[bestAtanPoint] == cutFaceGlobalPoints[0])
329 completedCutFace =
true;
333 Pout<<
" local: " << cutFaceLocalPoints
334 <<
" one side: " << facei;
339 cutFaceGlobal.transfer(cutFaceGlobalPoints);
341 cf.append(cutFaceGlobal);
344 cutFaceLocal.transfer(cutFaceLocalPoints);
354 forAll(cutFaceLocal, cuti)
356 const edge curCutFaceEdge
359 cutFaceLocal.nextLabel(cuti)
363 auto euoIter = edgesUsedOnce.find(curCutFaceEdge);
365 if (!euoIter.found())
370 edgesUsedOnce.insert(curCutFaceEdge);
377 edgesUsedOnce.erase(euoIter);
378 edgesUsedTwice.insert(curCutFaceEdge);
381 const label curCutFaceEdgeWhich = curLocalFace.which
383 curCutFaceEdge.start()
388 curCutFaceEdgeWhich > -1
389 && curLocalFace.nextLabel(curCutFaceEdgeWhich)
390 == curCutFaceEdge.end()
400 usedFaceEdges[curCutFaceEdgeWhich] =
true;
410 edgeSeeds.append(curCutFaceEdge.reverseEdge());
434 if (facei < slavePatch_.size())
436 const auto mpfAddrIter =
437 masterPointFaceAddr.cfind(cutFaceGlobal[0]);
439 bool otherSideFound =
false;
441 if (mpfAddrIter.found())
446 const labelList& masterFacesOfPZero = mpfAddrIter();
448 labelList hits(masterFacesOfPZero.size(), 1);
453 pointi < cutFaceGlobal.size();
457 const auto mpfAddrPointIter =
458 masterPointFaceAddr.cfind
460 cutFaceGlobal[pointi]
463 if (!mpfAddrPointIter.found())
475 for (
const label facei : curMasterFaces)
477 forAll(masterFacesOfPZero, j)
479 if (facei == masterFacesOfPZero[j])
493 if (hits[pointi] == cutFaceGlobal.size())
496 otherSideFound =
true;
500 masterFacesOfPZero[pointi]
503 cfSlave.append(facei);
511 Pout<<
" other side: "
512 << masterFacesOfPZero[pointi]
520 if (!otherSideFound || miss)
528 cfSlave.append(facei);
540 cfSlave.append(facei);
550 cfMaster.append(facei - slavePatch_.size());
557 prevPointLabel = curPointLabel;
558 curPointLabel = bestAtanPoint;
559 curPoint = lp[curPointLabel];
560 cutFaceGlobalPoints.append(
mp[curPointLabel]);
561 cutFaceLocalPoints.append(curPointLabel);
563 if (
debug || cutFaceGlobalPoints.size() > faceSizeDebug)
568 forAll(cutFaceGlobalPoints, checkI)
572 label checkJ = checkI + 1;
573 checkJ < cutFaceGlobalPoints.size();
579 cutFaceGlobalPoints[checkI]
580 == cutFaceGlobalPoints[checkJ]
584 cutFaceLocalPoints.shrink();
588 if (facei < slavePatch_.size())
590 origFace = slavePatch_[facei];
598 [facei - slavePatch_.size()];
602 [facei - slavePatch_.size()];
606 <<
"Duplicate point found in cut face. "
607 <<
"Error in the face cutting "
608 <<
"algorithm for global face "
609 << origFace <<
" local face "
610 << origFaceLocal <<
nl
611 <<
"Slave size: " << slavePatch_.size()
613 << masterPatch_.size()
614 <<
" index: " << facei <<
".\n"
615 <<
"Face: " << curGlobalFace <<
nl
616 <<
"Cut face: " << cutFaceGlobalPoints
617 <<
" local: " << cutFaceLocalPoints
619 << face(cutFaceLocalPoints).points(lp)
626 }
while (!completedCutFace);
631 Pout<<
" Finished face " << facei <<
endl;
637 cutFacesPtr_.reset(
new faceList(std::move(cf)));
638 cutFaceMasterPtr_.reset(
new labelList(std::move(cfMaster)));
639 cutFaceSlavePtr_.reset(
new labelList(std::move(cfSlave)));
643 void Foam::enrichedPatch::clearCutFaces()
645 cutFacesPtr_.reset(
nullptr);
646 cutFaceMasterPtr_.reset(
nullptr);
647 cutFaceSlavePtr_.reset(
nullptr);
660 return *cutFacesPtr_;
666 if (!cutFaceMasterPtr_)
671 return *cutFaceMasterPtr_;
677 if (!cutFaceSlavePtr_)
682 return *cutFaceSlavePtr_;