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];
142 boolList usedFaceEdges(curLocalFace.size(),
false);
144 SLList<edge> edgeSeeds;
147 edgeList cfe = curLocalFace.edges();
148 forAll(curLocalFace, edgeI)
150 edgeSeeds.append(cfe[edgeI]);
154 const vector normal = curLocalFace.normal(lp);
156 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);
201 label curPointLabel = curEdge.end();
202 point curPoint = lp[curPointLabel];
203 cutFaceGlobalPoints.append(mp[curPointLabel]);
204 cutFaceLocalPoints.append(curPointLabel);
206 bool completedCutFace =
false;
208 label faceSizeDebug = maxFaceSizeDebug_;
216 const labelList& nextPoints = pp[curPointLabel];
223 vector ahead = curPoint - lp[prevPointLabel];
224 ahead -= normal*(normal & ahead);
227 vector right = 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" 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 HashSet<edge, Hash<edge>>::iterator euoIter =
364 edgesUsedOnce.find(curCutFaceEdge);
366 if (euoIter == edgesUsedOnce.end())
371 edgesUsedOnce.insert(curCutFaceEdge);
378 edgesUsedOnce.erase(euoIter);
379 edgesUsedTwice.insert(curCutFaceEdge);
382 const label curCutFaceEdgeWhich = curLocalFace.which
384 curCutFaceEdge.start()
389 curCutFaceEdgeWhich > -1
390 && curLocalFace.nextLabel(curCutFaceEdgeWhich)
391 == curCutFaceEdge.end()
401 usedFaceEdges[curCutFaceEdgeWhich] =
true;
411 edgeSeeds.append(curCutFaceEdge.reverseEdge());
435 if (facei < slavePatch_.size())
438 masterPointFaceAddr.
find(cutFaceGlobal[0]);
440 bool otherSideFound =
false;
442 if (mpfAddrIter != masterPointFaceAddr.end())
447 const labelList& masterFacesOfPZero = mpfAddrIter();
449 labelList hits(masterFacesOfPZero.size(), 1);
454 pointi < cutFaceGlobal.size();
460 masterPointFaceAddr.
find 462 cutFaceGlobal[pointi]
468 == masterPointFaceAddr.end()
483 forAll(masterFacesOfPZero, j)
488 == masterFacesOfPZero[j]
503 if (hits[pointi] == cutFaceGlobal.size())
506 otherSideFound =
true;
510 masterFacesOfPZero[pointi]
513 cfSlave.append(facei);
521 Pout<<
" other side: " 522 << masterFacesOfPZero[pointi]
530 if (!otherSideFound || miss)
538 cfSlave.append(facei);
550 cfSlave.append(facei);
560 cfMaster.append(facei - slavePatch_.size());
567 prevPointLabel = curPointLabel;
568 curPointLabel = bestAtanPoint;
569 curPoint = lp[curPointLabel];
570 cutFaceGlobalPoints.append(mp[curPointLabel]);
571 cutFaceLocalPoints.append(curPointLabel);
573 if (debug || cutFaceGlobalPoints.size() > faceSizeDebug)
578 forAll(cutFaceGlobalPoints, checkI)
582 label checkJ = checkI + 1;
583 checkJ < cutFaceGlobalPoints.size();
589 cutFaceGlobalPoints[checkI]
590 == cutFaceGlobalPoints[checkJ]
594 cutFaceLocalPoints.shrink();
598 if (facei < slavePatch_.size())
600 origFace = slavePatch_[facei];
608 [facei - slavePatch_.size()];
612 [facei - slavePatch_.size()];
616 <<
"Duplicate point found in cut face. " 617 <<
"Error in the face cutting " 618 <<
"algorithm for global face " 619 << origFace <<
" local face " 620 << origFaceLocal <<
nl 621 <<
"Slave size: " << slavePatch_.size()
623 << masterPatch_.size()
624 <<
" index: " << facei <<
".\n" 625 <<
"Face: " << curGlobalFace <<
nl 626 <<
"Cut face: " << cutFaceGlobalPoints
627 <<
" local: " << cutFaceLocalPoints
629 << face(cutFaceLocalPoints).points(lp)
636 }
while (!completedCutFace);
641 Pout<<
" Finished face " << facei <<
endl;
651 cutFaceMasterPtr_->
transfer(cfMaster);
654 cutFaceSlavePtr_->
transfer(cfSlave);
658 void Foam::enrichedPatch::clearCutFaces()
675 return *cutFacesPtr_;
681 if (!cutFaceMasterPtr_)
686 return *cutFaceMasterPtr_;
692 if (!cutFaceSlavePtr_)
697 return *cutFaceSlavePtr_;
List< labelList > labelListList
A List of labelList.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const labelList & cutFaceMaster() const
Return cut face master list.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const faceList & cutFaces() const
Return list of cut faces.
HashTable< T, label, Hash< label > >::const_iterator const_iterator
static const unsigned edgesPerPoint_
Estimated number of edges per point.
Vector< scalar > vector
A scalar version of the templated Vector.
const Map< labelList > & masterPointFaces() const
Master point face addressing.
List< bool > boolList
Bool container classes.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
const faceList & enrichedFaces() const
Return enriched faces.
vectorField pointField
pointField is a vectorField.
const labelList & cutFaceSlave() const
Return cut face slave list.
List< label > labelList
A List of labels.
errorManip< error > abort(error &err)
const labelListList & pointPoints() const
Return point-point addressing.
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
const pointField & localPoints() const
Return local points.
vector point
Point is a vector.
prefixOSstream Pout(cout, "Pout")
const List< FaceType > & localFaces() const
Return patch faces addressing into local point list.
dimensioned< scalar > mag(const dimensioned< Type > &)
const faceList & localFaces() const
Return local faces.
const labelList & meshPoints() const
Return mesh points.
void deleteDemandDrivenData(DataPtr &dataPtr)
void transfer(List< T > &)
Transfer the contents of the argument List into this list.