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;
39 const Foam::scalar Foam::slidingInterface::edgeMasterCatchFractionDefault_ = 0.4;
40 const Foam::scalar Foam::slidingInterface::edgeEndCutoffTolDefault_ = 0.0001;
56 bool Foam::slidingInterface::projectPoints()
const
60 Pout<<
"bool slidingInterface::projectPoints() : "
61 <<
" for object " <<
name() <<
" : "
62 <<
"Projecting slave points onto master surface." <<
endl;
92 mesh.faceZones()[masterFaceZoneID_.
index()]();
95 mesh.faceZones()[slaveFaceZoneID_.
index()]();
100 const pointField& masterLocalPoints = masterPatch.localPoints();
101 const faceList& masterLocalFaces = masterPatch.localFaces();
102 const edgeList& masterEdges = masterPatch.edges();
103 const labelListList& masterEdgeFaces = masterPatch.edgeFaces();
104 const labelListList& masterFaceEdges = masterPatch.faceEdges();
105 const labelListList& masterFaceFaces = masterPatch.faceFaces();
112 const pointField& slaveLocalPoints = slavePatch.localPoints();
113 const edgeList& slaveEdges = slavePatch.edges();
114 const labelListList& slaveEdgeFaces = slavePatch.edgeFaces();
115 const vectorField& slavePointNormals = slavePatch.pointNormals();
125 scalarField minMasterPointLength(masterLocalPoints.size(), GREAT);
126 scalarField minMasterFaceLength(masterPatch.size(), GREAT);
128 forAll (masterEdges, edgeI)
130 const edge& curEdge = masterEdges[edgeI];
132 const scalar curLength =
133 masterEdges[edgeI].mag(masterLocalPoints);
136 minMasterPointLength[curEdge.start()] =
139 minMasterPointLength[curEdge.start()],
143 minMasterPointLength[curEdge.end()] =
146 minMasterPointLength[curEdge.end()],
151 const labelList& curFaces = masterEdgeFaces[edgeI];
155 minMasterFaceLength[curFaces[faceI]] =
158 minMasterFaceLength[curFaces[faceI]],
168 scalarField minSlavePointLength(slaveLocalPoints.size(), GREAT);
169 scalarField minSlaveFaceLength(slavePatch.size(), GREAT);
171 forAll (slaveEdges, edgeI)
173 const edge& curEdge = slaveEdges[edgeI];
175 const scalar curLength =
176 slaveEdges[edgeI].mag(slaveLocalPoints);
179 minSlavePointLength[curEdge.start()] =
182 minSlavePointLength[curEdge.start()],
186 minSlavePointLength[curEdge.end()] =
189 minSlavePointLength[curEdge.end()],
194 const labelList& curFaces = slaveEdgeFaces[edgeI];
198 minSlaveFaceLength[curFaces[faceI]] =
201 minSlaveFaceLength[curFaces[faceI]],
213 List<objectHit> slavePointFaceHits =
214 slavePatch.projectPoints
235 forAll (slavePointFaceHits, pointI)
237 if (slavePointFaceHits[pointI].hit())
243 Pout<<
"Number of hits in point projection: " << nHits
244 <<
" out of " << slavePointFaceHits.size() <<
" points."
249 if (projectedSlavePointsPtr_)
delete projectedSlavePointsPtr_;
251 projectedSlavePointsPtr_ =
253 pointField& projectedSlavePoints = *projectedSlavePointsPtr_;
257 label nAdjustedPoints = 0;
265 Pout<<
"bool slidingInterface::projectPoints() for object "
267 <<
"Adjusting point projection for integral match: ";
270 forAll (slavePointFaceHits, pointI)
272 if (slavePointFaceHits[pointI].hit())
275 projectedSlavePoints[pointI] =
277 [slavePointFaceHits[pointI].hitObject()].ray
279 slaveLocalPoints[pointI],
280 slavePointNormals[pointI],
289 masterLocalFaces[slavePointFaceHits[pointI].hitObject()].ray
291 slaveLocalPoints[pointI],
292 slavePointNormals[pointI],
297 const point nearPoint = missAdjust.missPoint();
298 const point missPoint =
299 slaveLocalPoints[pointI]
300 + slavePointNormals[pointI]*missAdjust.distance();
303 const scalar mergeTol =
304 integralAdjTol_*minSlavePointLength[pointI];
307 if (
mag(nearPoint - missPoint) < mergeTol)
320 projectedSlavePoints[pointI] = nearPoint;
322 slavePointFaceHits[pointI] =
323 objectHit(
true, slavePointFaceHits[pointI].hitObject());
329 projectedSlavePoints[pointI] = slaveLocalPoints[pointI];
344 else if (matchType_ ==
PARTIAL)
346 forAll (slavePointFaceHits, pointI)
348 if (slavePointFaceHits[pointI].hit())
351 projectedSlavePoints[pointI] =
353 [slavePointFaceHits[pointI].hitObject()].ray
355 slaveLocalPoints[pointI],
356 slavePointNormals[pointI],
364 projectedSlavePoints[pointI] = slaveLocalPoints[pointI];
372 "bool slidingInterface::projectPoints() const"
373 ) <<
"Problem in point projection. Unknown sliding match type "
374 <<
" for object " <<
name()
380 Pout<<
"Number of adjusted points in projection: "
381 << nAdjustedPoints <<
endl;
384 scalar minEdgeLength = GREAT;
386 label nShortEdges = 0;
388 forAll (slaveEdges, edgeI)
390 el = slaveEdges[edgeI].mag(projectedSlavePoints);
394 Pout<<
"Point projection problems for edge: "
395 << slaveEdges[edgeI] <<
". Length = " << el
401 minEdgeLength =
min(minEdgeLength, el);
408 "bool slidingInterface::projectPoints() const"
409 ) <<
"Problem in point projection. " << nShortEdges
410 <<
" short projected edges "
411 <<
"after adjustment for object " <<
name()
416 Pout <<
" ... projection OK." <<
endl;
427 labelList slavePointPointHits(slaveLocalPoints.size(), -1);
428 labelList masterPointPointHits(masterLocalPoints.size(), -1);
441 label nMergedPoints = 0;
443 forAll (projectedSlavePoints, pointI)
445 if (slavePointFaceHits[pointI].hit())
448 point& curPoint = projectedSlavePoints[pointI];
451 const face& hitFace =
452 masterLocalFaces[slavePointFaceHits[pointI].hitObject()];
454 label mergePoint = -1;
455 scalar mergeDist = GREAT;
458 forAll (hitFace, hitPointI)
461 mag(masterLocalPoints[hitFace[hitPointI]] - curPoint);
464 const scalar mergeTol =
468 minSlavePointLength[pointI],
469 minMasterPointLength[hitFace[hitPointI]]
472 if (dist < mergeTol && dist < mergeDist)
474 mergePoint = hitFace[hitPointI];
492 slavePointPointHits[pointI] = mergePoint;
493 curPoint = masterLocalPoints[mergePoint];
494 masterPointPointHits[mergePoint] = pointI;
505 scalar minEdgeLength = GREAT;
508 forAll (slaveEdges, edgeI)
510 el = slaveEdges[edgeI].mag(projectedSlavePoints);
514 Pout<<
"Point projection problems for edge: "
515 << slaveEdges[edgeI] <<
". Length = " << el
519 minEdgeLength =
min(minEdgeLength, el);
522 if (minEdgeLength < SMALL)
526 "bool slidingInterface::projectPoints() const"
527 ) <<
"Problem in point projection. Short projected edge "
528 <<
" after point merge for object " <<
name()
533 Pout <<
" ... point merge OK." <<
endl;
539 labelList slavePointEdgeHits(slaveLocalPoints.size(), -1);
541 label nMovedPoints = 0;
543 forAll (projectedSlavePoints, pointI)
546 if (slavePointPointHits[pointI] < 0)
549 point& curPoint = projectedSlavePoints[pointI];
553 masterFaceEdges[slavePointFaceHits[pointI].hitObject()];
556 const scalar mergeLength =
559 minSlavePointLength[pointI],
560 minMasterFaceLength[slavePointFaceHits[pointI].hitObject()]
563 const scalar mergeTol = pointMergeTol_*mergeLength;
565 scalar minDistance = GREAT;
567 forAll (hitFaceEdges, edgeI)
569 const edge& curEdge = masterEdges[hitFaceEdges[edgeI]];
572 curEdge.line(masterLocalPoints).nearestDist(curPoint);
577 mag(edgeHit.hitPoint() - projectedSlavePoints[pointI]);
579 if (dist < mergeTol && dist < minDistance)
584 slavePointEdgeHits[pointI] = hitFaceEdges[edgeI];
585 projectedSlavePoints[pointI] = edgeHit.hitPoint();
604 if (slavePointEdgeHits[pointI] > -1)
608 point& curPoint = projectedSlavePoints[pointI];
610 const edge& hitMasterEdge =
611 masterEdges[slavePointEdgeHits[pointI]];
613 label mergePoint = -1;
614 scalar mergeDist = GREAT;
616 forAll (hitMasterEdge, hmeI)
619 mag(masterLocalPoints[hitMasterEdge[hmeI]] - curPoint);
622 const scalar mergeTol =
626 minSlavePointLength[pointI],
627 minMasterPointLength[hitMasterEdge[hmeI]]
630 if (hmeDist < mergeTol && hmeDist < mergeDist)
632 mergePoint = hitMasterEdge[hmeI];
649 slavePointPointHits[pointI] = mergePoint;
650 curPoint = masterLocalPoints[mergePoint];
651 masterPointPointHits[mergePoint] = pointI;
653 slavePointFaceHits[pointI] =
654 objectHit(
true, slavePointFaceHits[pointI].hitObject());
658 slavePointEdgeHits[pointI] = -1;
666 Pout<<
"Number of merged master points: " << nMergedPoints <<
nl
667 <<
"Number of adjusted slave points: " << nMovedPoints <<
endl;
670 scalar minEdgeLength = GREAT;
673 forAll (slaveEdges, edgeI)
675 el = slaveEdges[edgeI].mag(projectedSlavePoints);
679 Pout<<
"Point projection problems for edge: "
680 << slaveEdges[edgeI] <<
". Length = " << el
684 minEdgeLength =
min(minEdgeLength, el);
687 if (minEdgeLength < SMALL)
691 "bool slidingInterface::projectPoints() const"
692 ) <<
"Problem in point projection. Short projected edge "
693 <<
" after correction for object " <<
name()
739 labelList masterPointEdgeHits(masterLocalPoints.size(), -1);
740 scalarField masterPointEdgeDist(masterLocalPoints.size(), GREAT);
750 Pout <<
"Processing slave edges " <<
endl;
761 forAll (slaveEdges, edgeI)
763 const edge& curEdge = slaveEdges[edgeI];
778 const label startFace =
779 slavePointFaceHits[curEdge.start()].hitObject();
780 const label endFace = slavePointFaceHits[curEdge.end()].hitObject();
783 curFaceMap.insert(startFace);
784 addedFaces.insert(startFace);
789 bool completed =
false;
791 while (nSweeps < edgeFaceEscapeLimit_)
795 if (addedFaces.found(endFace))
806 const labelList& curNbrs = masterFaceFaces[cf[cfI]];
810 if (!curFaceMap.found(curNbrs[nbrI]))
812 curFaceMap.insert(curNbrs[nbrI]);
813 addedFaces.insert(curNbrs[nbrI]);
818 if (completed)
break;
836 label nReverseSweeps = 0;
839 curFaceMap.insert(endFace);
840 addedFaces.insert(endFace);
842 while (nReverseSweeps < edgeFaceEscapeLimit_)
846 if (addedFaces.found(startFace))
857 const labelList& curNbrs = masterFaceFaces[cf[cfI]];
861 if (!curFaceMap.found(curNbrs[nbrI]))
863 curFaceMap.insert(curNbrs[nbrI]);
864 addedFaces.insert(curNbrs[nbrI]);
869 if (completed)
break;
901 const labelList curFaces = curFaceMap.toc();
905 const face&
f = masterLocalFaces[curFaces[faceI]];
909 curPointMap.insert(f[pointI]);
913 const labelList curMasterPoints = curPointMap.toc();
917 linePointRef edgeLine = curEdge.line(projectedSlavePoints);
919 const vector edgeVec = edgeLine.vec();
920 const scalar edgeMag = edgeLine.mag();
926 scalar slaveCatchDist =
927 edgeMasterCatchFraction_*edgeMag
932 projectedSlavePoints[curEdge.start()]
933 - slaveLocalPoints[curEdge.start()]
937 projectedSlavePoints[curEdge.end()]
938 - slaveLocalPoints[curEdge.end()]
950 vector edgeNormalInPlane =
953 slavePointNormals[curEdge.start()]
954 + slavePointNormals[curEdge.end()]
957 edgeNormalInPlane /=
mag(edgeNormalInPlane);
959 forAll (curMasterPoints, pointI)
961 const label cmp = curMasterPoints[pointI];
967 slavePointPointHits[curEdge.start()] == cmp
968 || slavePointPointHits[curEdge.end()] == cmp
969 || masterPointPointHits[cmp] > -1
978 edgeLine.nearestDist(masterLocalPoints[cmp]);
980 if (edgeLineHit.hit())
989 ((edgeLineHit.hitPoint() - edgeLine.start()) & edgeVec)
992 scalar distInEdgePlane =
995 edgeLineHit.distance(),
999 masterLocalPoints[cmp]
1000 - edgeLineHit.hitPoint()
1020 cutOnSlave > edgeEndCutoffTol_
1021 && cutOnSlave < 1.0 - edgeEndCutoffTol_
1022 && distInEdgePlane < edgeMergeTol_*edgeMag
1023 && edgeLineHit.distance()
1027 masterPointEdgeDist[cmp]
1033 if (masterPointEdgeHits[cmp] == -1)
1046 masterPointEdgeHits[cmp] = edgeI;
1047 masterPointEdgeDist[cmp] = edgeLineHit.distance();
1081 Pout<<
"bool slidingInterface::projectPoints() for object "
1083 <<
"Finished projecting points. Topology = ";
1110 slavePointPointHitsPtr_ =
new labelList(slavePointPointHits);
1113 slavePointEdgeHitsPtr_ =
new labelList(slavePointEdgeHits);
1116 slavePointFaceHitsPtr_ =
new List<objectHit>(slavePointFaceHits);
1119 masterPointEdgeHitsPtr_ =
new labelList(masterPointEdgeHits);
1123 Pout <<
"(Detached interface) changing." <<
endl;
1134 !slavePointPointHitsPtr_
1135 || !slavePointEdgeHitsPtr_
1136 || !slavePointFaceHitsPtr_
1137 || !masterPointEdgeHitsPtr_
1142 slavePointPointHitsPtr_ =
new labelList(slavePointPointHits);
1145 slavePointEdgeHitsPtr_ =
new labelList(slavePointEdgeHits);
1148 slavePointFaceHitsPtr_ =
new List<objectHit>(slavePointFaceHits);
1151 masterPointEdgeHitsPtr_ =
new labelList(masterPointEdgeHits);
1155 Pout <<
"(Attached interface restart) changing." <<
endl;
1162 if (slavePointPointHits != (*slavePointPointHitsPtr_))
1166 Pout <<
"(Point projection) ";
1172 if (slavePointEdgeHits != (*slavePointEdgeHitsPtr_))
1176 Pout <<
"(Edge projection) ";
1184 bool faceHitsDifferent =
false;
1186 const List<objectHit>& oldPointFaceHits = *slavePointFaceHitsPtr_;
1188 forAll (slavePointFaceHits, pointI)
1192 slavePointPointHits[pointI] < 0
1193 && slavePointEdgeHits[pointI] < 0
1197 if (slavePointFaceHits[pointI] != oldPointFaceHits[pointI])
1200 faceHitsDifferent =
true;
1206 if (faceHitsDifferent)
1210 Pout <<
"(Face projection) ";
1217 if (masterPointEdgeHits != (*masterPointEdgeHitsPtr_))
1221 Pout <<
"(Master point projection) ";
1232 slavePointPointHitsPtr_ =
new labelList(slavePointPointHits);
1235 slavePointEdgeHitsPtr_ =
new labelList(slavePointEdgeHits);
1238 slavePointFaceHitsPtr_ =
new List<objectHit>(slavePointFaceHits);
1241 masterPointEdgeHitsPtr_ =
new labelList(masterPointEdgeHits);
1261 void Foam::slidingInterface::clearPointProjection()
const