33 const Foam::scalar Foam::slidingInterface::pointMergeTolDefault_ = 0.05;
34 const Foam::scalar Foam::slidingInterface::edgeMergeTolDefault_ = 0.01;
35 const Foam::label Foam::slidingInterface::nFacesPerSlaveEdgeDefault_ = 5;
36 const Foam::label Foam::slidingInterface::edgeFaceEscapeLimitDefault_ = 10;
38 const Foam::scalar Foam::slidingInterface::integralAdjTolDefault_ = 0.05;
40 Foam::slidingInterface::edgeMasterCatchFractionDefault_ = 0.4;
41 const Foam::scalar Foam::slidingInterface::edgeEndCutoffTolDefault_ = 0.0001;
57 bool Foam::slidingInterface::projectPoints()
const 61 Pout<<
"bool slidingInterface::projectPoints() : " 62 <<
" for object " <<
name() <<
" : " 63 <<
"Projecting slave points onto master surface." <<
endl;
93 mesh.faceZones()[masterFaceZoneID_.
index()]();
96 mesh.faceZones()[slaveFaceZoneID_.
index()]();
101 const pointField& masterLocalPoints = masterPatch.localPoints();
102 const faceList& masterLocalFaces = masterPatch.localFaces();
103 const edgeList& masterEdges = masterPatch.edges();
104 const labelListList& masterEdgeFaces = masterPatch.edgeFaces();
105 const labelListList& masterFaceEdges = masterPatch.faceEdges();
106 const labelListList& masterFaceFaces = masterPatch.faceFaces();
113 const pointField& slaveLocalPoints = slavePatch.localPoints();
114 const edgeList& slaveEdges = slavePatch.edges();
115 const labelListList& slaveEdgeFaces = slavePatch.edgeFaces();
116 const vectorField& slavePointNormals = slavePatch.pointNormals();
126 scalarField minMasterPointLength(masterLocalPoints.size(), great);
127 scalarField minMasterFaceLength(masterPatch.size(), great);
129 forAll(masterEdges, edgeI)
131 const edge& curEdge = masterEdges[edgeI];
133 const scalar curLength =
134 masterEdges[edgeI].mag(masterLocalPoints);
137 minMasterPointLength[curEdge.start()] =
140 minMasterPointLength[curEdge.start()],
144 minMasterPointLength[curEdge.end()] =
147 minMasterPointLength[curEdge.end()],
152 const labelList& curFaces = masterEdgeFaces[edgeI];
156 minMasterFaceLength[curFaces[facei]] =
159 minMasterFaceLength[curFaces[facei]],
169 scalarField minSlavePointLength(slaveLocalPoints.size(), great);
170 scalarField minSlaveFaceLength(slavePatch.size(), great);
174 const edge& curEdge = slaveEdges[edgeI];
176 const scalar curLength =
177 slaveEdges[edgeI].mag(slaveLocalPoints);
180 minSlavePointLength[curEdge.start()] =
183 minSlavePointLength[curEdge.start()],
187 minSlavePointLength[curEdge.end()] =
190 minSlavePointLength[curEdge.end()],
195 const labelList& curFaces = slaveEdgeFaces[edgeI];
199 minSlaveFaceLength[curFaces[facei]] =
202 minSlaveFaceLength[curFaces[facei]],
214 List<objectHit> slavePointFaceHits =
215 slavePatch.projectPoints
236 forAll(slavePointFaceHits, pointi)
238 if (slavePointFaceHits[pointi].hit())
244 Pout<<
"Number of hits in point projection: " << nHits
245 <<
" out of " << slavePointFaceHits.size() <<
" points." 250 if (projectedSlavePointsPtr_)
delete projectedSlavePointsPtr_;
252 projectedSlavePointsPtr_ =
254 pointField& projectedSlavePoints = *projectedSlavePointsPtr_;
258 label nAdjustedPoints = 0;
266 Pout<<
"bool slidingInterface::projectPoints() for object " 268 <<
"Adjusting point projection for integral match: ";
271 forAll(slavePointFaceHits, pointi)
273 if (slavePointFaceHits[pointi].hit())
276 projectedSlavePoints[pointi] =
278 [slavePointFaceHits[pointi].hitObject()].ray
280 slaveLocalPoints[pointi],
281 slavePointNormals[pointi],
290 masterLocalFaces[slavePointFaceHits[pointi].hitObject()].ray
292 slaveLocalPoints[pointi],
293 slavePointNormals[pointi],
298 const point nearPoint = missAdjust.missPoint();
299 const point missPoint =
300 slaveLocalPoints[pointi]
301 + slavePointNormals[pointi]*missAdjust.distance();
304 const scalar mergeTol =
305 integralAdjTol_*minSlavePointLength[pointi];
308 if (
mag(nearPoint - missPoint) < mergeTol)
321 projectedSlavePoints[pointi] = nearPoint;
323 slavePointFaceHits[pointi] =
324 objectHit(
true, slavePointFaceHits[pointi].hitObject());
330 projectedSlavePoints[pointi] = slaveLocalPoints[pointi];
345 else if (matchType_ ==
PARTIAL)
347 forAll(slavePointFaceHits, pointi)
349 if (slavePointFaceHits[pointi].hit())
352 projectedSlavePoints[pointi] =
354 [slavePointFaceHits[pointi].hitObject()].ray
356 slaveLocalPoints[pointi],
357 slavePointNormals[pointi],
365 projectedSlavePoints[pointi] = slaveLocalPoints[pointi];
372 <<
" for object " <<
name()
378 Pout<<
"Number of adjusted points in projection: " 379 << nAdjustedPoints <<
endl;
382 scalar minEdgeLength = great;
384 label nShortEdges = 0;
388 el = slaveEdges[edgeI].mag(projectedSlavePoints);
392 Pout<<
"Point projection problems for edge: " 393 << slaveEdges[edgeI] <<
". Length = " << el
399 minEdgeLength =
min(minEdgeLength, el);
405 <<
" short projected edges " 406 <<
"after adjustment for object " <<
name()
411 Pout<<
" ... projection OK." <<
endl;
422 labelList slavePointPointHits(slaveLocalPoints.size(), -1);
423 labelList masterPointPointHits(masterLocalPoints.size(), -1);
436 label nMergedPoints = 0;
438 forAll(projectedSlavePoints, pointi)
440 if (slavePointFaceHits[pointi].hit())
443 point& curPoint = projectedSlavePoints[pointi];
446 const face& hitFace =
447 masterLocalFaces[slavePointFaceHits[pointi].hitObject()];
449 label mergePoint = -1;
450 scalar mergeDist = great;
453 forAll(hitFace, hitPointi)
456 mag(masterLocalPoints[hitFace[hitPointi]] - curPoint);
459 const scalar mergeTol =
463 minSlavePointLength[pointi],
464 minMasterPointLength[hitFace[hitPointi]]
467 if (dist < mergeTol && dist < mergeDist)
469 mergePoint = hitFace[hitPointi];
487 slavePointPointHits[pointi] = mergePoint;
488 curPoint = masterLocalPoints[mergePoint];
489 masterPointPointHits[mergePoint] = pointi;
500 scalar minEdgeLength = great;
505 el = slaveEdges[edgeI].mag(projectedSlavePoints);
509 Pout<<
"Point projection problems for edge: " 510 << slaveEdges[edgeI] <<
". Length = " << el
514 minEdgeLength =
min(minEdgeLength, el);
517 if (minEdgeLength < small)
520 <<
" after point merge for object " <<
name()
525 Pout<<
" ... point merge OK." <<
endl;
531 labelList slavePointEdgeHits(slaveLocalPoints.size(), -1);
533 label nMovedPoints = 0;
535 forAll(projectedSlavePoints, pointi)
538 if (slavePointPointHits[pointi] < 0)
541 point& curPoint = projectedSlavePoints[pointi];
545 masterFaceEdges[slavePointFaceHits[pointi].hitObject()];
548 const scalar mergeLength =
551 minSlavePointLength[pointi],
552 minMasterFaceLength[slavePointFaceHits[pointi].hitObject()]
555 const scalar mergeTol = pointMergeTol_*mergeLength;
557 scalar minDistance = great;
559 forAll(hitFaceEdges, edgeI)
561 const edge& curEdge = masterEdges[hitFaceEdges[edgeI]];
564 curEdge.line(masterLocalPoints).nearestDist(curPoint);
569 mag(edgeHit.hitPoint() - projectedSlavePoints[pointi]);
571 if (dist < mergeTol && dist < minDistance)
576 slavePointEdgeHits[pointi] = hitFaceEdges[edgeI];
577 projectedSlavePoints[pointi] = edgeHit.hitPoint();
596 if (slavePointEdgeHits[pointi] > -1)
600 point& curPoint = projectedSlavePoints[pointi];
602 const edge& hitMasterEdge =
603 masterEdges[slavePointEdgeHits[pointi]];
605 label mergePoint = -1;
606 scalar mergeDist = great;
608 forAll(hitMasterEdge, hmeI)
611 mag(masterLocalPoints[hitMasterEdge[hmeI]] - curPoint);
614 const scalar mergeTol =
618 minSlavePointLength[pointi],
619 minMasterPointLength[hitMasterEdge[hmeI]]
622 if (hmeDist < mergeTol && hmeDist < mergeDist)
624 mergePoint = hitMasterEdge[hmeI];
641 slavePointPointHits[pointi] = mergePoint;
642 curPoint = masterLocalPoints[mergePoint];
643 masterPointPointHits[mergePoint] = pointi;
645 slavePointFaceHits[pointi] =
646 objectHit(
true, slavePointFaceHits[pointi].hitObject());
650 slavePointEdgeHits[pointi] = -1;
658 Pout<<
"Number of merged master points: " << nMergedPoints <<
nl 659 <<
"Number of adjusted slave points: " << nMovedPoints <<
endl;
662 scalar minEdgeLength = great;
667 el = slaveEdges[edgeI].mag(projectedSlavePoints);
671 Pout<<
"Point projection problems for edge: " 672 << slaveEdges[edgeI] <<
". Length = " << el
676 minEdgeLength =
min(minEdgeLength, el);
679 if (minEdgeLength < small)
682 <<
" after correction for object " <<
name()
728 labelList masterPointEdgeHits(masterLocalPoints.size(), -1);
729 scalarField masterPointEdgeDist(masterLocalPoints.size(), great);
739 Pout<<
"Processing slave edges " <<
endl;
752 const edge& curEdge = slaveEdges[edgeI];
760 const label startFace =
761 slavePointFaceHits[curEdge.start()].hitObject();
762 const label endFace = slavePointFaceHits[curEdge.end()].hitObject();
765 curFaceMap.insert(startFace);
766 addedFaces.insert(startFace);
778 bool completed =
false;
780 while (nSweeps < edgeFaceEscapeLimit_)
784 if (addedFaces.found(endFace))
795 const labelList& curNbrs = masterFaceFaces[cf[cfI]];
799 if (!curFaceMap.found(curNbrs[nbrI]))
801 curFaceMap.insert(curNbrs[nbrI]);
802 addedFaces.insert(curNbrs[nbrI]);
807 if (completed)
break;
825 label nReverseSweeps = 0;
828 curFaceMap.insert(endFace);
829 addedFaces.insert(endFace);
831 while (nReverseSweeps < edgeFaceEscapeLimit_)
835 if (addedFaces.found(startFace))
846 const labelList& curNbrs = masterFaceFaces[cf[cfI]];
850 if (!curFaceMap.found(curNbrs[nbrI]))
852 curFaceMap.insert(curNbrs[nbrI]);
853 addedFaces.insert(curNbrs[nbrI]);
858 if (completed)
break;
890 const labelList curFaces = curFaceMap.toc();
894 const face& f = masterLocalFaces[curFaces[facei]];
898 curPointMap.insert(f[pointi]);
902 const labelList curMasterPoints = curPointMap.toc();
906 linePointRef edgeLine = curEdge.line(projectedSlavePoints);
908 const vector edgeVec = edgeLine.vec();
909 const scalar edgeMag = edgeLine.mag();
915 scalar slaveCatchDist =
916 edgeMasterCatchFraction_*edgeMag
921 projectedSlavePoints[curEdge.start()]
922 - slaveLocalPoints[curEdge.start()]
926 projectedSlavePoints[curEdge.end()]
927 - slaveLocalPoints[curEdge.end()]
939 vector edgeNormalInPlane =
942 slavePointNormals[curEdge.start()]
943 + slavePointNormals[curEdge.end()]
946 edgeNormalInPlane /=
mag(edgeNormalInPlane);
948 forAll(curMasterPoints, pointi)
950 const label cmp = curMasterPoints[pointi];
956 slavePointPointHits[curEdge.start()] == cmp
957 || slavePointPointHits[curEdge.end()] == cmp
958 || masterPointPointHits[cmp] > -1
967 edgeLine.nearestDist(masterLocalPoints[cmp]);
969 if (edgeLineHit.hit())
978 ((edgeLineHit.hitPoint() - edgeLine.start()) & edgeVec)
981 scalar distInEdgePlane =
984 edgeLineHit.distance(),
988 masterLocalPoints[cmp]
989 - edgeLineHit.hitPoint()
1009 cutOnSlave > edgeEndCutoffTol_
1010 && cutOnSlave < 1.0 - edgeEndCutoffTol_
1011 && distInEdgePlane < edgeMergeTol_*edgeMag
1012 && edgeLineHit.distance()
1016 masterPointEdgeDist[cmp]
1022 if (masterPointEdgeHits[cmp] == -1)
1035 masterPointEdgeHits[cmp] = edgeI;
1036 masterPointEdgeDist[cmp] = edgeLineHit.distance();
1070 Pout<<
"bool slidingInterface::projectPoints() for object " 1072 <<
"Finished projecting points. Topology = ";
1099 slavePointPointHitsPtr_ =
new labelList(slavePointPointHits);
1102 slavePointEdgeHitsPtr_ =
new labelList(slavePointEdgeHits);
1105 slavePointFaceHitsPtr_ =
new List<objectHit>(slavePointFaceHits);
1108 masterPointEdgeHitsPtr_ =
new labelList(masterPointEdgeHits);
1112 Pout<<
"(Detached interface) changing." <<
endl;
1123 !slavePointPointHitsPtr_
1124 || !slavePointEdgeHitsPtr_
1125 || !slavePointFaceHitsPtr_
1126 || !masterPointEdgeHitsPtr_
1131 slavePointPointHitsPtr_ =
new labelList(slavePointPointHits);
1134 slavePointEdgeHitsPtr_ =
new labelList(slavePointEdgeHits);
1137 slavePointFaceHitsPtr_ =
new List<objectHit>(slavePointFaceHits);
1140 masterPointEdgeHitsPtr_ =
new labelList(masterPointEdgeHits);
1144 Pout<<
"(Attached interface restart) changing." <<
endl;
1151 if (slavePointPointHits != (*slavePointPointHitsPtr_))
1155 Pout<<
"(Point projection) ";
1161 if (slavePointEdgeHits != (*slavePointEdgeHitsPtr_))
1165 Pout<<
"(Edge projection) ";
1173 bool faceHitsDifferent =
false;
1175 const List<objectHit>& oldPointFaceHits = *slavePointFaceHitsPtr_;
1177 forAll(slavePointFaceHits, pointi)
1181 slavePointPointHits[pointi] < 0
1182 && slavePointEdgeHits[pointi] < 0
1186 if (slavePointFaceHits[pointi] != oldPointFaceHits[pointi])
1189 faceHitsDifferent =
true;
1195 if (faceHitsDifferent)
1199 Pout<<
"(Face projection) ";
1206 if (masterPointEdgeHits != (*masterPointEdgeHitsPtr_))
1210 Pout<<
"(Master point projection) ";
1221 slavePointPointHitsPtr_ =
new labelList(slavePointPointHits);
1224 slavePointEdgeHitsPtr_ =
new labelList(slavePointEdgeHits);
1227 slavePointFaceHitsPtr_ =
new List<objectHit>(slavePointFaceHits);
1230 masterPointEdgeHitsPtr_ =
new labelList(masterPointEdgeHits);
1250 void Foam::slidingInterface::clearPointProjection()
const 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.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Vector< scalar > vector
A scalar version of the templated Vector.
static const unsigned edgesPerFace_
Estimated number of edges per cell.
static const unsigned pointsPerFace_
Estimated number of points per face.
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
vectorField pointField
pointField is a vectorField.
line< point, const point & > linePointRef
Line using referred points.
void clear()
Clear the list, i.e. set size to zero.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
List< label > labelList
A List of labels.
errorManip< error > abort(error &err)
label index() const
Return index of first matching zone.
PrimitivePatch< List< face >, const pointField & > primitiveFacePatch
Foam::primitiveFacePatch.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
const polyTopoChanger & topoChanger() const
Return reference to morph engine.
vector point
Point is a vector.
prefixOSstream Pout(cout, "Pout")
const word & name() const
Return name of this modifier.
dimensioned< scalar > mag(const dimensioned< Type > &)
Field< vector > vectorField
Specialisation of Field<T> for vector.
PointHit< point > pointHit
const polyMesh & mesh() const
Return the mesh reference.
void deleteDemandDrivenData(DataPtr &dataPtr)