48 const Foam::scalar Foam::slidingInterface::edgeCoPlanarTolDefault_ = 0.8;
72 void Foam::slidingInterface::coupleInterface(polyTopoChange&
ref)
const
77 <<
": Coupling sliding interface " <<
name() <<
endl;
88 faceZones[masterFaceZoneID_.
index()]();
90 const labelList& masterPatchAddr = faceZones[masterFaceZoneID_.
index()];
93 faceZones[masterFaceZoneID_.
index()].flipMap();
96 faceZones[slaveFaceZoneID_.
index()]();
98 const labelList& slavePatchAddr = faceZones[slaveFaceZoneID_.
index()];
101 faceZones[slaveFaceZoneID_.
index()].flipMap();
103 const edgeList& masterEdges = masterPatch.edges();
104 const labelListList& masterPointEdges = masterPatch.pointEdges();
105 const labelList& masterMeshPoints = masterPatch.meshPoints();
106 const pointField& masterLocalPoints = masterPatch.localPoints();
107 const labelListList& masterFaceFaces = masterPatch.faceFaces();
108 const labelListList& masterFaceEdges = masterPatch.faceEdges();
109 const Map<label>& masterMeshPointMap = masterPatch.meshPointMap();
111 const edgeList& slaveEdges = slavePatch.edges();
112 const labelListList& slavePointEdges = slavePatch.pointEdges();
113 const labelList& slaveMeshPoints = slavePatch.meshPoints();
114 const pointField& slaveLocalPoints = slavePatch.localPoints();
115 const Map<label>& slaveMeshPointMap = slavePatch.meshPointMap();
116 const vectorField& slavePointNormals = slavePatch.pointNormals();
122 slavePointPointHitsPtr_
123 && slavePointEdgeHitsPtr_
124 && slavePointFaceHitsPtr_
125 && masterPointEdgeHitsPtr_
130 <<
"Point projection addressing not available."
134 const labelList& slavePointPointHits = *slavePointPointHitsPtr_;
135 const labelList& slavePointEdgeHits = *slavePointEdgeHitsPtr_;
136 const List<objectHit>& slavePointFaceHits = *slavePointFaceHitsPtr_;
137 const labelList& masterPointEdgeHits = *masterPointEdgeHitsPtr_;
138 const pointField& projectedSlavePoints = *projectedSlavePointsPtr_;
141 enrichedPatch cutPatch
152 Map<point>& pointMap = cutPatch.pointMap();
155 Map<label>& pointMergeMap = cutPatch.pointMergeMap();
158 forAll(slavePointPointHits, pointi)
160 const label slaveHitPti = slavePointPointHits[pointi];
162 if (slaveHitPti >= 0)
166 slaveMeshPoints[pointi],
167 masterMeshPoints[slaveHitPti]
175 List<labelHashSet> usedMasterEdges(slaveEdges.size());
178 forAll(slavePointPointHits, pointi)
181 const labelList& curSlaveEdges = slavePointEdges[pointi];
183 if (slavePointPointHits[pointi] > -1)
186 masterPointEdges[slavePointPointHits[pointi]];
190 for (
const label slaveEdgei : curSlaveEdges)
192 usedMasterEdges[slaveEdgei].insert(curMasterEdges);
195 else if (slavePointEdgeHits[pointi] > -1)
198 for (
const label slaveEdgei : curSlaveEdges)
200 usedMasterEdges[slaveEdgei].insert
202 slavePointEdgeHits[pointi]
211 forAll(masterPointEdgeHits, masterPointi)
213 if (masterPointEdgeHits[masterPointi] > -1)
215 const labelList& curMasterEdges = masterPointEdges[masterPointi];
217 usedMasterEdges[masterPointEdgeHits[masterPointi]].insert
234 List<DynamicList<label>> pointsIntoMasterEdges(masterEdges.size());
235 List<DynamicList<label>> pointsIntoSlaveEdges(slaveEdges.size());
238 forAll(slavePointEdgeHits, pointi)
240 if (slavePointEdgeHits[pointi] > -1)
244 const point edgeCutPoint =
245 masterEdges[slavePointEdgeHits[pointi]].line
248 ).nearestDist(projectedSlavePoints[pointi]).hitPoint();
256 slaveMeshPoints[pointi],
257 cutPointZoneID_.
index(),
265 slaveMeshPoints[pointi],
269 pointsIntoMasterEdges[slavePointEdgeHits[pointi]].append
303 forAll(slavePointFaceHits, pointi)
307 slavePointPointHits[pointi] < 0
308 && slavePointEdgeHits[pointi] < 0
309 && slavePointFaceHits[pointi].hit()
317 projectedSlavePoints[pointi],
318 slaveMeshPoints[pointi],
319 cutPointZoneID_.
index(),
332 slaveMeshPoints[pointi],
340 projectedSlavePoints[pointi]
346 << projectedSlavePoints[pointi] <<
endl;
351 forAll(masterPointEdgeHits, pointi)
353 if (masterPointEdgeHits[pointi] > -1)
355 pointsIntoSlaveEdges[masterPointEdgeHits[pointi]].append
357 masterMeshPoints[pointi]
394 Pout<<
"Processing slave edges" <<
endl;
397 if (!cutPointEdgePairMapPtr_)
400 <<
"Cut point edge pair map pointer not set."
404 Map<Pair<edge>>& addToCpepm = *cutPointEdgePairMapPtr_;
419 const edge& curEdge = slaveEdges[edgeI];
423 slavePointFaceHits[curEdge.start()].hit()
424 || slavePointFaceHits[curEdge.end()].hit()
435 const label startFace =
436 slavePointFaceHits[curEdge.start()].hitObject();
438 const label endFace =
439 slavePointFaceHits[curEdge.end()].hitObject();
445 bool completed =
false;
456 curFaceMap.
insert(startFace);
457 addedFaces.insert(startFace);
464 nSweeps < edgeFaceEscapeLimit_;
468 completed = addedFaces.found(endFace);
474 for (
const label cfi : cf)
476 const labelList& curNbrs = masterFaceFaces[cfi];
478 for (
const label nbri : curNbrs)
480 if (curFaceMap.insert(nbri))
482 addedFaces.insert(nbri);
487 if (completed)
break;
509 addedFaces.insert(endFace);
514 nSweeps < edgeFaceEscapeLimit_;
518 completed = addedFaces.found(startFace);
524 for (
const label cfi : cf)
526 const labelList& curNbrs = masterFaceFaces[cfi];
528 for (
const label nbri : curNbrs)
530 if (curFaceMap.insert(nbri))
532 addedFaces.insert(nbri);
537 if (completed)
break;
569 for (
const label facei : curFaceMap)
577 curMasterEdgesMap.insert(masterFaceEdges[facei]);
580 const labelList curMasterEdges(curMasterEdgesMap.toc());
581 curMasterEdgesMap.clear();
594 const point& a = projectedSlavePoints[curEdge.start()];
595 const point&
b = projectedSlavePoints[curEdge.end()];
600 slaveLocalPoints[curEdge.start()]
601 + slavePointNormals[curEdge.start()]
602 + slaveLocalPoints[curEdge.end()]
603 + slavePointNormals[curEdge.end()]
607 const plane cutPlane(a,
b,
c);
616 curEdge.line(projectedSlavePoints);
618 const scalar curSlaveLineMag = curSlaveLine.mag();
622 for (
const label cmeIndex : curMasterEdges)
624 if (!curUme.found(cmeIndex))
632 const edge& cme = masterEdges[cmeIndex];
639 const scalar cutOnMaster =
640 cutPlane.lineIntersect
642 cme.line(masterLocalPoints)
647 cutOnMaster > edgeEndCutoffTol_
648 && cutOnMaster < 1.0 - edgeEndCutoffTol_
652 const point masterCutPoint =
653 masterLocalPoints[cme.start()]
654 + cutOnMaster*cme.vec(masterLocalPoints);
657 curSlaveLine.nearestDist(masterCutPoint);
663 const scalar cutOnSlave =
667 - curSlaveLine.start()
668 ) & curSlaveLine.vec()
669 )/
sqr(curSlaveLineMag);
673 const scalar mergeTol = edgeCoPlanarTol_*
mag(
b - a);
689 cutOnSlave > edgeEndCutoffTol_
690 && cutOnSlave < 1.0 - edgeEndCutoffTol_
691 && slaveCut.distance() < mergeTol
704 masterMeshPoints[cme.start()],
705 cutPointZoneID_.
index(),
718 pointsIntoSlaveEdges[edgeI].append
722 pointsIntoMasterEdges[cmeIndex].append
743 masterMeshPoints[cme.start()],
744 masterMeshPoints[cme.end()]
748 slaveMeshPoints[curEdge.start()],
749 slaveMeshPoints[curEdge.end()]
757 << masterCutPoint <<
" ";
809 forAll(pointsIntoMasterEdges, i)
811 pime[i].transfer(pointsIntoMasterEdges[i]);
816 forAll(pointsIntoSlaveEdges, i)
818 pise[i].transfer(pointsIntoSlaveEdges[i]);
822 cutPatch.calcEnrichedFaces
832 const faceList& cutFaces = cutPatch.cutFaces();
833 const labelList& cutFaceMaster = cutPatch.cutFaceMaster();
834 const labelList& cutFaceSlave = cutPatch.cutFaceSlave();
836 const labelList& masterFc = masterFaceCells();
837 const labelList& slaveFc = slaveFaceCells();
848 boolList orphanedMaster(masterPatch.size(),
false);
849 boolList orphanedSlave(slavePatch.size(),
false);
853 const face& curCutFace = cutFaces[facei];
854 const label curMaster = cutFaceMaster[facei];
855 const label curSlave = cutFaceSlave[facei];
860 bool insertedFace =
false;
865 if (curCutFace == masterPatch[curMaster])
877 if (masterFc[curMaster] < slaveFc[curSlave])
886 masterPatchAddr[curMaster],
892 masterFaceZoneID_.
index(),
893 masterPatchFlip[curMaster]
911 curCutFace.reverseFace(),
912 masterPatchAddr[curMaster],
918 masterFaceZoneID_.
index(),
919 !masterPatchFlip[curMaster]
925 orphanedSlave[curSlave] =
true;
935 masterPatchAddr[curMaster],
939 masterPatchID_.
index(),
941 masterFaceZoneID_.
index(),
942 masterPatchFlip[curMaster]
950 else if (curSlave >= 0)
955 face rsf(slavePatch[curSlave]);
959 rsf[i] = pointMergeMap.lookup(rsf[i], rsf[i]);
962 if (curCutFace == rsf)
970 if (masterFc[curMaster] < slaveFc[curSlave])
977 slavePatchAddr[curSlave],
983 slaveFaceZoneID_.
index(),
984 !slavePatchFlip[curMaster]
997 curCutFace.reverseFace(),
998 slavePatchAddr[curSlave],
1000 masterFc[curMaster],
1004 slaveFaceZoneID_.
index(),
1005 slavePatchFlip[curSlave]
1011 orphanedMaster[curMaster] =
true;
1021 slavePatchAddr[curSlave],
1025 slavePatchID_.
index(),
1027 slaveFaceZoneID_.
index(),
1028 slavePatchFlip[curSlave]
1033 insertedFace =
true;
1039 <<
"Face " << facei <<
" in cut faces has neither a master "
1040 <<
"nor a slave. Error in the cutting algorithm on modify."
1054 if (masterFc[curMaster] < slaveFc[curSlave])
1068 masterFc[curMaster],
1072 masterPatchAddr[curMaster],
1075 cutFaceZoneID_.
index(),
1087 curCutFace.reverseFace(),
1089 masterFc[curMaster],
1092 masterPatchAddr[curMaster],
1095 cutFaceZoneID_.
index(),
1102 orphanedSlave[curSlave] =
true;
1117 masterFc[curMaster],
1121 masterPatchAddr[curMaster],
1123 masterPatchID_.
index(),
1124 cutFaceZoneID_.
index(),
1131 orphanedMaster[curMaster] =
true;
1133 else if (curSlave >= 0)
1150 slavePatchAddr[curSlave],
1152 slavePatchID_.
index(),
1153 cutFaceZoneID_.
index(),
1159 orphanedSlave[curSlave] =
true;
1164 <<
"Face " << facei <<
" in cut faces has neither a master "
1165 <<
"nor a slave. Error in the cutting algorithm on add."
1175 label nOrphanedMasters = 0;
1177 forAll(orphanedMaster, facei)
1179 if (orphanedMaster[facei])
1202 ref.setAction(polyRemoveFace(masterPatchAddr[facei]));
1206 label nOrphanedSlaves = 0;
1208 forAll(orphanedSlave, facei)
1210 if (orphanedSlave[facei])
1233 ref.setAction(polyRemoveFace(slavePatchAddr[facei]));
1239 Pout<<
"Orphaned faces: "
1240 <<
"master = " << nOrphanedMasters <<
"/"
1241 << orphanedMaster.size()
1242 <<
" slave = " << nOrphanedSlaves <<
"/"
1243 << orphanedSlave.size() <<
endl;
1262 const labelList& masterStickOuts = masterStickOutFaces();
1267 for (
const label curFaceID : masterStickOuts)
1270 const face& oldRichFace = faces[curFaceID];
1272 bool changed =
false;
1275 face oldFace(oldRichFace.size());
1278 for (
const label pointi : oldRichFace)
1280 if (
ref.pointRemoved(pointi))
1287 oldFace[nOldFace] = pointi;
1292 oldFace.setSize(nOldFace);
1297 DynamicList<label> newFaceLabels(2*oldFace.size());
1301 const label localFirstLabel =
1302 masterMeshPointMap.lookup(oldFace[pointi], -1);
1304 if (localFirstLabel != -1)
1310 newFaceLabels.append
1312 pointMergeMap.lookup(oldFace[pointi], oldFace[pointi])
1315 if (newFaceLabels.last() != oldFace[pointi])
1327 const labelList& curEdges = masterPointEdges[localFirstLabel];
1329 const label nextLabel = oldFace.nextLabel(pointi);
1331 const label localNextLabel =
1332 masterMeshPointMap.lookup(nextLabel, -1);
1334 if (localNextLabel != -1)
1340 for (
const label curEdgei : curEdges)
1344 masterEdges[curEdgei].otherVertex
1354 const labelList& curPime = pime[curEdgei];
1362 const point& startPoint =
1363 masterLocalPoints[localFirstLabel];
1365 const point& endPoint =
1366 masterLocalPoints[localNextLabel];
1368 vector e = (endPoint - startPoint);
1374 forAll(curPime, curPimeI)
1376 edgePointWeights[curPimeI] =
1380 pointMap[curPime[curPimeI]]
1390 min(edgePointWeights) < 0
1391 ||
max(edgePointWeights) > 1
1395 <<
"Error in master stick-out edge "
1396 <<
"point collection."
1408 passI < edgePointWeights.size();
1415 label nextPoint = -1;
1418 forAll(edgePointWeights, wI)
1420 if (edgePointWeights[wI] < dist)
1422 dist = edgePointWeights[wI];
1430 newFaceLabels.append(curPime[nextPoint]);
1431 edgePointWeights[nextPoint] = GREAT;
1442 newFaceLabels.append(oldFace[pointi]);
1448 if (newFaceLabels.size() < 3)
1451 <<
"Face " << curFaceID <<
" reduced to less than "
1452 <<
"3 points. Topological/cutting error A." <<
nl
1453 <<
"Old face: " << oldFace <<
" new face: " << newFaceLabels
1458 const label modifiedFaceZone = faceZones.whichZone(curFaceID);
1460 const bool modifiedFaceZoneFlip =
1462 modifiedFaceZone >= 0
1464 faceZones[modifiedFaceZone].flipMap()
1466 faceZones[modifiedFaceZone].whichFace(curFaceID)
1472 newFace.transfer(newFaceLabels);
1478 if (
mesh.isInternalFace(curFaceID))
1492 modifiedFaceZoneFlip
1507 mesh.boundaryMesh().whichPatch(curFaceID),
1511 modifiedFaceZoneFlip
1523 const labelList& slaveStickOuts = slaveStickOutFaces();
1527 const Map<label>& rpm = retiredPointMap();
1531 for (
const label curFaceID : slaveStickOuts)
1534 const face& oldRichFace = faces[curFaceID];
1536 bool changed =
false;
1539 face oldFace(oldRichFace.size());
1542 for (
const label pointi : oldRichFace)
1547 || slaveMeshPointMap.found(pointi)
1551 oldFace[nOldFace] = pointi;
1554 else if (
ref.pointRemoved(pointi))
1563 oldFace[nOldFace] = pointi;
1568 oldFace.setSize(nOldFace);
1570 DynamicList<label> newFaceLabels(2*oldFace.size());
1579 const label curP = rpm.lookup(oldFace[pointi], oldFace[pointi]);
1581 if (curP != oldFace[pointi])
1586 const label localFirstLabel = slaveMeshPointMap.lookup(curP, -1);
1588 if (localFirstLabel != -1)
1594 newFaceLabels.append
1596 pointMergeMap.lookup(curP, curP)
1599 if (newFaceLabels.last() != curP)
1611 const labelList& curEdges = slavePointEdges[localFirstLabel];
1613 label nextLabel = oldFace.nextLabel(pointi);
1615 nextLabel = rpm.lookup(nextLabel, nextLabel);
1617 const label localNextLabel =
1618 slaveMeshPointMap.lookup(nextLabel, -1);
1620 if (localNextLabel != -1)
1625 for (
const label curEdgei : curEdges)
1629 slaveEdges[curEdgei].otherVertex
1640 const labelList& curPise = pise[curEdgei];
1649 const point& startPoint =
1650 projectedSlavePoints[localFirstLabel];
1652 const point& endPoint =
1653 projectedSlavePoints[localNextLabel];
1655 vector e = endPoint - startPoint;
1661 forAll(curPise, curPiseI)
1663 edgePointWeights[curPiseI] =
1667 pointMap[curPise[curPiseI]]
1677 min(edgePointWeights) < 0
1678 ||
max(edgePointWeights) > 1
1682 <<
"Error in slave stick-out edge "
1683 <<
"point collection."
1695 passI < edgePointWeights.size();
1702 label nextPoint = -1;
1705 forAll(edgePointWeights, wI)
1707 if (edgePointWeights[wI] < dist)
1709 dist = edgePointWeights[wI];
1717 newFaceLabels.append(curPise[nextPoint]);
1718 edgePointWeights[nextPoint] = GREAT;
1729 newFaceLabels.append(oldFace[pointi]);
1735 if (newFaceLabels.size() < 3)
1738 <<
"Face " << curFaceID <<
" reduced to less than "
1739 <<
"3 points. Topological/cutting error B." <<
nl
1740 <<
"Old face: " << oldFace <<
" new face: " << newFaceLabels
1745 const label modifiedFaceZone =
1746 faceZones.whichZone(curFaceID);
1748 const bool modifiedFaceZoneFlip
1750 modifiedFaceZone >= 0
1752 faceZones[modifiedFaceZone].flipMap()
1754 faceZones[modifiedFaceZone].whichFace(curFaceID)
1760 newFace.transfer(newFaceLabels);
1767 if (
mesh.isInternalFace(curFaceID))
1781 modifiedFaceZoneFlip
1796 mesh.boundaryMesh().whichPatch(curFaceID),
1800 modifiedFaceZoneFlip
1811 if (!retiredPointMapPtr_)
1814 <<
"Retired point map pointer not set."
1818 Map<label>& addToRpm = *retiredPointMapPtr_;
1823 label nRetiredPoints = 0;
1825 for (
const label slavePointi : slaveMeshPoints)
1827 const label masterPointi = pointMergeMap.lookup(slavePointi, -1);
1829 if (slavePointi == masterPointi)
1834 else if (masterPointi != -1)
1863 addToRpm.insert(masterPointi, slavePointi);
1874 mesh.pointZones().whichZone(slavePointi),
1883 Pout<<
"Retired " << nRetiredPoints <<
"/"
1884 << slaveMeshPoints.size() <<
" points." <<
endl;
1888 cutFaceMasterPtr_.reset(
new labelList(cutPatch.cutFaceMaster()));
1889 cutFaceSlavePtr_.reset(
new labelList(cutPatch.cutFaceSlave()));
1897 <<
": Finished coupling sliding interface " <<
name() <<
endl;