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 vector normal = curLocalFace.normal(lp);
155 normal /=
mag(normal);
157 while (edgeSeeds.size())
163 const edge curEdge = edgeSeeds.removeHead();
166 const label curEdgeWhich = curLocalFace.which(curEdge.start());
173 && curLocalFace.nextLabel(curEdgeWhich) == curEdge.end()
178 if (usedFaceEdges[curEdgeWhich])
continue;
180 usedFaceEdges[curEdgeWhich] =
true;
184 if (edgesUsedTwice.found(curEdge))
continue;
193 DynamicList<label> cutFaceGlobalPoints(2*curLocalFace.size());
194 DynamicList<label> cutFaceLocalPoints(2*curLocalFace.size());
197 label prevPointLabel = curEdge.start();
198 cutFaceGlobalPoints.append(mp[prevPointLabel]);
199 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);
228 vector right = normal ^ ahead;
236 scalar atanTurn = -GREAT;
237 label bestAtanPoint = -1;
243 if (nextPoints[nextI] != prevPointLabel)
249 vector newDir = lp[nextPoints[nextI]] - curPoint;
252 newDir -= normal*(normal & newDir);
253 scalar magNewDir =
mag(newDir);
257 if (magNewDir < SMALL)
260 <<
"projection error: slave patch probably " 261 <<
"does not project onto master. " 262 <<
"Please switch on " 263 <<
"enriched patch debug for more info" 270 atan2(newDir & right, newDir & ahead);
274 if (curAtanTurn > atanTurn)
276 bestAtanPoint = nextPoints[nextI];
277 atanTurn = curAtanTurn;
295 const label whichNextPoint = curLocalFace.which(curPointLabel);
300 && curLocalFace.nextLabel(whichNextPoint) == bestAtanPoint
301 && usedFaceEdges[whichNextPoint]
310 completedCutFace =
true;
314 if (edgesUsedTwice.found(edge(curPointLabel, bestAtanPoint)))
318 completedCutFace =
true;
323 if (completedCutFace)
continue;
326 if (mp[bestAtanPoint] == cutFaceGlobalPoints[0])
330 completedCutFace =
true;
334 Pout<<
" local: " << cutFaceLocalPoints
335 <<
" one side: " << facei;
340 cutFaceGlobal.transfer(cutFaceGlobalPoints);
342 cf.append(cutFaceGlobal);
345 cutFaceLocal.transfer(cutFaceLocalPoints);
355 forAll(cutFaceLocal, cutI)
357 const edge curCutFaceEdge
360 cutFaceLocal.nextLabel(cutI)
364 HashSet<edge, Hash<edge>>::iterator euoIter =
365 edgesUsedOnce.find(curCutFaceEdge);
367 if (euoIter == edgesUsedOnce.end())
372 edgesUsedOnce.insert(curCutFaceEdge);
379 edgesUsedOnce.erase(euoIter);
380 edgesUsedTwice.insert(curCutFaceEdge);
383 const label curCutFaceEdgeWhich = curLocalFace.which
385 curCutFaceEdge.start()
390 curCutFaceEdgeWhich > -1
391 && curLocalFace.nextLabel(curCutFaceEdgeWhich)
392 == curCutFaceEdge.end()
402 usedFaceEdges[curCutFaceEdgeWhich] =
true;
412 edgeSeeds.append(curCutFaceEdge.reverseEdge());
436 if (facei < slavePatch_.size())
439 masterPointFaceAddr.
find(cutFaceGlobal[0]);
441 bool otherSideFound =
false;
443 if (mpfAddrIter != masterPointFaceAddr.end())
448 const labelList& masterFacesOfPZero = mpfAddrIter();
450 labelList hits(masterFacesOfPZero.size(), 1);
455 pointi < cutFaceGlobal.size();
461 masterPointFaceAddr.
find 463 cutFaceGlobal[pointi]
469 == masterPointFaceAddr.end()
484 forAll(masterFacesOfPZero, j)
489 == masterFacesOfPZero[j]
504 if (hits[pointi] == cutFaceGlobal.size())
507 otherSideFound =
true;
511 masterFacesOfPZero[pointi]
514 cfSlave.append(facei);
522 Pout<<
" other side: " 523 << masterFacesOfPZero[pointi]
531 if (!otherSideFound || miss)
539 cfSlave.append(facei);
551 cfSlave.append(facei);
561 cfMaster.append(facei - slavePatch_.size());
568 prevPointLabel = curPointLabel;
569 curPointLabel = bestAtanPoint;
570 curPoint = lp[curPointLabel];
571 cutFaceGlobalPoints.append(mp[curPointLabel]);
572 cutFaceLocalPoints.append(curPointLabel);
574 if (debug || cutFaceGlobalPoints.size() > faceSizeDebug)
579 forAll(cutFaceGlobalPoints, checkI)
583 label checkJ = checkI + 1;
584 checkJ < cutFaceGlobalPoints.size();
590 cutFaceGlobalPoints[checkI]
591 == cutFaceGlobalPoints[checkJ]
595 cutFaceLocalPoints.shrink();
599 if (facei < slavePatch_.size())
601 origFace = slavePatch_[facei];
609 [facei - slavePatch_.size()];
613 [facei - slavePatch_.size()];
617 <<
"Duplicate point found in cut face. " 618 <<
"Error in the face cutting " 619 <<
"algorithm for global face " 620 << origFace <<
" local face " 621 << origFaceLocal <<
nl 622 <<
"Slave size: " << slavePatch_.size()
624 << masterPatch_.size()
625 <<
" index: " << facei <<
".\n" 626 <<
"Face: " << curGlobalFace <<
nl 627 <<
"Cut face: " << cutFaceGlobalPoints
628 <<
" local: " << cutFaceLocalPoints
630 << face(cutFaceLocalPoints).points(lp)
637 }
while (!completedCutFace);
642 Pout<<
" Finished face " << facei <<
endl;
652 cutFaceMasterPtr_->
transfer(cfMaster);
655 cutFaceSlavePtr_->
transfer(cfSlave);
659 void Foam::enrichedPatch::clearCutFaces()
676 return *cutFacesPtr_;
682 if (!cutFaceMasterPtr_)
687 return *cutFaceMasterPtr_;
693 if (!cutFaceSlavePtr_)
698 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.
const List< Face > & localFaces() const
Return patch faces addressing into local point list.
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")
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.