40 const Foam::label Foam::enrichedPatch::maxFaceSizeDebug_ = 100;
50 void Foam::enrichedPatch::calcCutFaces()
const
52 if (cutFacesPtr_ || cutFaceMasterPtr_ || cutFaceSlavePtr_)
55 <<
"Cut faces addressing already calculated."
71 DynamicList<face> cf(2*lf.size());
72 DynamicList<label> cfMaster(2*lf.size());
73 DynamicList<label> cfSlave(2*lf.size());
97 HashSet<edge, Hash<edge> > edgesUsedOnce(pp.size());
98 HashSet<edge, Hash<edge> > edgesUsedTwice
104 const face& curLocalFace = lf[faceI];
105 const face& curGlobalFace = enFaces[faceI];
138 boolList usedFaceEdges(curLocalFace.size(),
false);
140 SLList<edge> edgeSeeds;
143 edgeList cfe = curLocalFace.edges();
144 forAll (curLocalFace, edgeI)
146 edgeSeeds.append(cfe[edgeI]);
150 vector normal = curLocalFace.normal(lp);
151 normal /=
mag(normal);
153 while (edgeSeeds.size())
156 const edge curEdge = edgeSeeds.removeHead();
159 const label curEdgeWhich = curLocalFace.which(curEdge.start());
166 && curLocalFace.nextLabel(curEdgeWhich) == curEdge.end()
171 if (usedFaceEdges[curEdgeWhich])
continue;
173 usedFaceEdges[curEdgeWhich] =
true;
177 if (edgesUsedTwice.found(curEdge))
continue;
181 DynamicList<label> cutFaceGlobalPoints(2*curLocalFace.size());
182 DynamicList<label> cutFaceLocalPoints(2*curLocalFace.size());
185 label prevPointLabel = curEdge.start();
186 cutFaceGlobalPoints.append(mp[prevPointLabel]);
187 cutFaceLocalPoints.append(prevPointLabel);
190 label curPointLabel = curEdge.end();
191 point curPoint = lp[curPointLabel];
192 cutFaceGlobalPoints.append(mp[curPointLabel]);
193 cutFaceLocalPoints.append(curPointLabel);
195 bool completedCutFace =
false;
197 label faceSizeDebug = maxFaceSizeDebug_;
203 const labelList& nextPoints = pp[curPointLabel];
206 vector ahead = curPoint - lp[prevPointLabel];
207 ahead -= normal*(normal & ahead);
210 vector right = normal ^ ahead;
214 scalar atanTurn = -GREAT;
215 label bestAtanPoint = -1;
217 forAll (nextPoints, nextI)
221 if (nextPoints[nextI] != prevPointLabel)
224 vector newDir = lp[nextPoints[nextI]] - curPoint;
226 newDir -= normal*(normal & newDir);
227 scalar magNewDir =
mag(newDir);
230 if (magNewDir < SMALL)
234 "void enrichedPatch::"
235 "calcCutFaces() const"
236 ) <<
"Zero length edge detected. Probable "
237 <<
"projection error: slave patch probably "
238 <<
"does not project onto master. "
239 <<
"Please switch on "
240 <<
"enriched patch debug for more info"
247 atan2(newDir & right, newDir & ahead);
251 if (curAtanTurn > atanTurn)
253 bestAtanPoint = nextPoints[nextI];
254 atanTurn = curAtanTurn;
265 const label whichNextPoint = curLocalFace.which(curPointLabel);
270 && curLocalFace.nextLabel(whichNextPoint) == bestAtanPoint
271 && usedFaceEdges[whichNextPoint]
277 completedCutFace =
true;
281 if (edgesUsedTwice.found(edge(curPointLabel, bestAtanPoint)))
285 completedCutFace =
true;
289 if (completedCutFace)
continue;
292 if (mp[bestAtanPoint] == cutFaceGlobalPoints[0])
296 completedCutFace =
true;
300 Pout<<
" local: " << cutFaceLocalPoints
301 <<
" one side: " << faceI;
306 cutFaceGlobal.transfer(cutFaceGlobalPoints);
308 cf.append(cutFaceGlobal);
311 cutFaceLocal.transfer(cutFaceLocalPoints);
317 forAll (cutFaceLocal, cutI)
319 const edge curCutFaceEdge
322 cutFaceLocal.nextLabel(cutI)
326 HashSet<edge, Hash<edge> >::iterator euoIter =
327 edgesUsedOnce.find(curCutFaceEdge);
329 if (euoIter == edgesUsedOnce.end())
332 edgesUsedOnce.insert(curCutFaceEdge);
337 edgesUsedOnce.erase(euoIter);
338 edgesUsedTwice.insert(curCutFaceEdge);
341 const label curCutFaceEdgeWhich = curLocalFace.which(curCutFaceEdge.start());
345 curCutFaceEdgeWhich > -1
346 && curLocalFace.nextLabel(curCutFaceEdgeWhich) == curCutFaceEdge.end()
351 usedFaceEdges[curCutFaceEdgeWhich] =
true;
357 edgeSeeds.append(curCutFaceEdge.reverseEdge());
381 if (faceI < slavePatch_.size())
384 masterPointFaceAddr.
find(cutFaceGlobal[0]);
386 bool otherSideFound =
false;
388 if (mpfAddrIter != masterPointFaceAddr.end())
393 const labelList& masterFacesOfPZero = mpfAddrIter();
395 labelList hits(masterFacesOfPZero.size(), 1);
400 pointI < cutFaceGlobal.size();
406 masterPointFaceAddr.
find
408 cutFaceGlobal[pointI]
414 == masterPointFaceAddr.end()
427 forAll (curMasterFaces, i)
429 forAll (masterFacesOfPZero, j)
434 == masterFacesOfPZero[j]
449 if (hits[pointI] == cutFaceGlobal.size())
452 otherSideFound =
true;
456 masterFacesOfPZero[pointI]
459 cfSlave.append(faceI);
464 cf[cf.size() - 1].reverseFace();
468 Pout<<
" other side: "
469 << masterFacesOfPZero[pointI]
477 if (!otherSideFound || miss)
485 cfSlave.append(faceI);
497 cfSlave.append(faceI);
507 cfMaster.append(faceI - slavePatch_.size());
514 prevPointLabel = curPointLabel;
515 curPointLabel = bestAtanPoint;
516 curPoint = lp[curPointLabel];
517 cutFaceGlobalPoints.append(mp[curPointLabel]);
518 cutFaceLocalPoints.append(curPointLabel);
520 if (debug || cutFaceGlobalPoints.size() > faceSizeDebug)
525 forAll (cutFaceGlobalPoints, checkI)
529 label checkJ = checkI + 1;
530 checkJ < cutFaceGlobalPoints.size();
536 cutFaceGlobalPoints[checkI]
537 == cutFaceGlobalPoints[checkJ]
541 cutFaceLocalPoints.shrink();
545 if (faceI < slavePatch_.size())
547 origFace = slavePatch_[faceI];
555 [faceI - slavePatch_.size()];
559 [faceI - slavePatch_.size()];
564 "void enrichedPatch::"
565 "calcCutFaces() const"
566 ) <<
"Duplicate point found in cut face. "
567 <<
"Error in the face cutting "
568 <<
"algorithm for global face "
569 << origFace <<
" local face "
570 << origFaceLocal <<
nl
571 <<
"Slave size: " << slavePatch_.size()
573 << masterPatch_.size()
574 <<
" index: " << faceI <<
".\n"
575 <<
"Face: " << curGlobalFace <<
nl
576 <<
"Cut face: " << cutFaceGlobalPoints
577 <<
" local: " << cutFaceLocalPoints
579 << face(cutFaceLocalPoints).points(lp)
586 }
while (!completedCutFace);
591 Pout <<
" Finished face " << faceI <<
endl;
601 cutFaceMasterPtr_->
transfer(cfMaster);
604 cutFaceSlavePtr_->
transfer(cfSlave);
608 void Foam::enrichedPatch::clearCutFaces()
625 return *cutFacesPtr_;
631 if (!cutFaceMasterPtr_)
636 return *cutFaceMasterPtr_;
642 if (!cutFaceSlavePtr_)
647 return *cutFaceSlavePtr_;