45 const Foam::scalar Foam::slidingInterface::edgeCoPlanarTolDefault_ = 0.8;
68 void Foam::slidingInterface::coupleInterface(polyTopoChange& ref)
const
72 Pout<<
"void slidingInterface::coupleInterface"
73 <<
"(polyTopoChange& ref) : "
74 <<
"Coupling sliding interface " <<
name() <<
endl;
80 const faceList& faces = mesh.faces();
83 const labelList& nei = mesh.faceNeighbour();
87 faceZones[masterFaceZoneID_.
index()]();
89 const labelList& masterPatchAddr = faceZones[masterFaceZoneID_.
index()];
92 faceZones[masterFaceZoneID_.
index()].flipMap();
95 faceZones[slaveFaceZoneID_.
index()]();
97 const labelList& slavePatchAddr = faceZones[slaveFaceZoneID_.
index()];
100 faceZones[slaveFaceZoneID_.
index()].flipMap();
102 const edgeList& masterEdges = masterPatch.edges();
103 const labelListList& masterPointEdges = masterPatch.pointEdges();
104 const labelList& masterMeshPoints = masterPatch.meshPoints();
105 const pointField& masterLocalPoints = masterPatch.localPoints();
106 const labelListList& masterFaceFaces = masterPatch.faceFaces();
107 const labelListList& masterFaceEdges = masterPatch.faceEdges();
108 const Map<label>& masterMeshPointMap = masterPatch.meshPointMap();
110 const edgeList& slaveEdges = slavePatch.edges();
111 const labelListList& slavePointEdges = slavePatch.pointEdges();
112 const labelList& slaveMeshPoints = slavePatch.meshPoints();
113 const pointField& slaveLocalPoints = slavePatch.localPoints();
114 const Map<label>& slaveMeshPointMap = slavePatch.meshPointMap();
115 const vectorField& slavePointNormals = slavePatch.pointNormals();
121 slavePointPointHitsPtr_
122 && slavePointEdgeHitsPtr_
123 && slavePointFaceHitsPtr_
124 && masterPointEdgeHitsPtr_
130 "void slidingInterface::coupleInterface("
131 "polyTopoChange& ref) const"
132 ) <<
"Point projection addressing not available."
136 const labelList& slavePointPointHits = *slavePointPointHitsPtr_;
137 const labelList& slavePointEdgeHits = *slavePointEdgeHitsPtr_;
138 const List<objectHit>& slavePointFaceHits = *slavePointFaceHitsPtr_;
139 const labelList& masterPointEdgeHits = *masterPointEdgeHitsPtr_;
140 const pointField& projectedSlavePoints = *projectedSlavePointsPtr_;
143 enrichedPatch cutPatch
154 Map<point>& pointMap = cutPatch.pointMap();
157 Map<label>& pointMergeMap = cutPatch.pointMergeMap();
160 forAll (slavePointPointHits, pointI)
162 if (slavePointPointHits[pointI] >= 0)
167 slaveMeshPoints[pointI],
168 masterMeshPoints[slavePointPointHits[pointI]]
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 forAll (curSlaveEdges, slaveEdgeI)
192 labelHashSet& sm = usedMasterEdges[curSlaveEdges[slaveEdgeI]];
194 forAll (curMasterEdges, masterEdgeI)
196 sm.insert(curMasterEdges[masterEdgeI]);
200 else if (slavePointEdgeHits[pointI] > -1)
203 forAll (curSlaveEdges, slaveEdgeI)
205 usedMasterEdges[curSlaveEdges[slaveEdgeI]].insert
207 slavePointEdgeHits[pointI]
216 forAll (masterPointEdgeHits, masterPointI)
218 if (masterPointEdgeHits[masterPointI] > -1)
220 const labelList& curMasterEdges = masterPointEdges[masterPointI];
223 usedMasterEdges[masterPointEdgeHits[masterPointI]];
225 forAll (curMasterEdges, masterEdgeI)
227 sm.insert(curMasterEdges[masterEdgeI]);
240 List<DynamicList<label> > pointsIntoMasterEdges(masterEdges.size());
241 List<DynamicList<label> > pointsIntoSlaveEdges(slaveEdges.size());
244 forAll (slavePointEdgeHits, pointI)
246 if (slavePointEdgeHits[pointI] > -1)
251 masterEdges[slavePointEdgeHits[pointI]].line
254 ).nearestDist(projectedSlavePoints[pointI]).hitPoint();
262 slaveMeshPoints[pointI],
263 cutPointZoneID_.
index(),
269 pointMergeMap.insert(slaveMeshPoints[pointI], newPoint);
271 pointsIntoMasterEdges[slavePointEdgeHits[pointI]].append
297 forAll (slavePointFaceHits, pointI)
301 slavePointPointHits[pointI] < 0
302 && slavePointEdgeHits[pointI] < 0
303 && slavePointFaceHits[pointI].hit()
311 projectedSlavePoints[pointI],
312 slaveMeshPoints[pointI],
313 cutPointZoneID_.
index(),
319 pointMergeMap.insert(slaveMeshPoints[pointI], newPoint);
325 projectedSlavePoints[pointI]
330 Pout<<
"f: " << newPoint <<
" = "
331 << projectedSlavePoints[pointI] <<
endl;
336 forAll (masterPointEdgeHits, pointI)
338 if (masterPointEdgeHits[pointI] > -1)
340 pointsIntoSlaveEdges[masterPointEdgeHits[pointI]].append
342 masterMeshPoints[pointI]
379 Pout <<
"Processing slave edges " <<
endl;
382 if (!cutPointEdgePairMapPtr_)
386 "void slidingInterface::coupleInterface("
387 "polyTopoChange& ref) const"
388 ) <<
"Cut point edge pair map pointer not set."
392 Map<Pair<edge> >& addToCpepm = *cutPointEdgePairMapPtr_;
405 forAll (slaveEdges, edgeI)
407 const edge& curEdge = slaveEdges[edgeI];
411 slavePointFaceHits[curEdge.start()].hit()
412 || slavePointFaceHits[curEdge.end()].hit()
422 const label startFace =
423 slavePointFaceHits[curEdge.start()].hitObject();
424 const label endFace = slavePointFaceHits[curEdge.end()].hitObject();
427 curFaceMap.insert(startFace);
428 addedFaces.insert(startFace);
431 bool completed =
false;
433 while (nSweeps < edgeFaceEscapeLimit_)
437 if (addedFaces.found(endFace))
448 const labelList& curNbrs = masterFaceFaces[cf[cfI]];
452 if (!curFaceMap.found(curNbrs[nbrI]))
454 curFaceMap.insert(curNbrs[nbrI]);
455 addedFaces.insert(curNbrs[nbrI]);
460 if (completed)
break;
478 label nReverseSweeps = 0;
481 addedFaces.insert(endFace);
483 while (nReverseSweeps < edgeFaceEscapeLimit_)
487 if (addedFaces.found(startFace))
498 const labelList& curNbrs = masterFaceFaces[cf[cfI]];
502 if (!curFaceMap.found(curNbrs[nbrI]))
504 curFaceMap.insert(curNbrs[nbrI]);
505 addedFaces.insert(curNbrs[nbrI]);
510 if (completed)
break;
542 const labelList curFaces = curFaceMap.toc();
551 const labelList& me = masterFaceEdges[curFaces[faceI]];
555 curMasterEdgesMap.insert(me[meI]);
559 const labelList curMasterEdges = curMasterEdgesMap.toc();
572 const point& a = projectedSlavePoints[curEdge.start()];
573 const point&
b = projectedSlavePoints[curEdge.end()];
578 slaveLocalPoints[curEdge.start()]
579 + slavePointNormals[curEdge.start()]
580 + slaveLocalPoints[curEdge.end()]
581 + slavePointNormals[curEdge.end()]
585 plane cutPlane(a, b, c);
588 linePointRef curSlaveLine = curEdge.line(projectedSlavePoints);
589 const scalar curSlaveLineMag = curSlaveLine.mag();
591 forAll (curMasterEdges, masterEdgeI)
593 if (!curUme.found(curMasterEdges[masterEdgeI]))
601 const label cmeIndex = curMasterEdges[masterEdgeI];
602 const edge& cme = masterEdges[cmeIndex];
605 cutPlane.lineIntersect
607 cme.line(masterLocalPoints)
612 cutOnMaster > edgeEndCutoffTol_
613 && cutOnMaster < 1.0 - edgeEndCutoffTol_
617 point masterCutPoint =
618 masterLocalPoints[cme.start()]
619 + cutOnMaster*cme.vec(masterLocalPoints);
622 curSlaveLine.nearestDist(masterCutPoint);
632 - curSlaveLine.start()
633 ) & curSlaveLine.vec()
634 )/
sqr(curSlaveLineMag);
639 edgeCoPlanarTol_*
mag(b - a);
643 cutOnSlave > edgeEndCutoffTol_
644 && cutOnSlave < 1.0 - edgeEndCutoffTol_
645 && slaveCut.distance() < mergeTol
658 masterMeshPoints[cme.start()],
659 cutPointZoneID_.
index(),
664 pointsIntoSlaveEdges[edgeI].append(newPoint);
665 pointsIntoMasterEdges[cmeIndex].append(newPoint);
683 masterMeshPoints[cme.start()],
684 masterMeshPoints[cme.end()]
688 slaveMeshPoints[curEdge.start()],
689 slaveMeshPoints[curEdge.end()]
696 Pout<<
" " << newPoint <<
" = "
697 << masterCutPoint <<
" ";
749 forAll (pointsIntoMasterEdges, i)
751 pime[i].transfer(pointsIntoMasterEdges[i]);
756 forAll (pointsIntoSlaveEdges, i)
758 pise[i].transfer(pointsIntoSlaveEdges[i]);
762 cutPatch.calcEnrichedFaces
772 const faceList& cutFaces = cutPatch.cutFaces();
773 const labelList& cutFaceMaster = cutPatch.cutFaceMaster();
774 const labelList& cutFaceSlave = cutPatch.cutFaceSlave();
776 const labelList& masterFc = masterFaceCells();
777 const labelList& slaveFc = slaveFaceCells();
788 boolList orphanedMaster(masterPatch.size(),
false);
789 boolList orphanedSlave(slavePatch.size(),
false);
793 const face& curCutFace = cutFaces[faceI];
794 const label curMaster = cutFaceMaster[faceI];
795 const label curSlave = cutFaceSlave[faceI];
800 bool insertedFace =
false;
805 if (curCutFace == masterPatch[curMaster])
817 if (masterFc[curMaster] < slaveFc[curSlave])
826 masterPatchAddr[curMaster],
832 masterFaceZoneID_.
index(),
833 masterPatchFlip[curMaster]
846 curCutFace.reverseFace(),
847 masterPatchAddr[curMaster],
853 masterFaceZoneID_.
index(),
854 !masterPatchFlip[curMaster]
860 orphanedSlave[curSlave] =
true;
870 masterPatchAddr[curMaster],
874 masterPatchID_.
index(),
876 masterFaceZoneID_.
index(),
877 masterPatchFlip[curMaster]
885 else if (curSlave >= 0)
890 face rsf(slavePatch[curSlave]);
896 if (mpIter != pointMergeMap.end())
902 if (curCutFace == rsf)
910 if (masterFc[curMaster] < slaveFc[curSlave])
917 slavePatchAddr[curSlave],
923 slaveFaceZoneID_.
index(),
924 !slavePatchFlip[curMaster]
937 curCutFace.reverseFace(),
938 slavePatchAddr[curSlave],
944 slaveFaceZoneID_.
index(),
945 slavePatchFlip[curSlave]
951 orphanedMaster[curMaster] =
true;
961 slavePatchAddr[curSlave],
965 slavePatchID_.
index(),
967 slaveFaceZoneID_.
index(),
968 slavePatchFlip[curSlave]
980 "void slidingInterface::coupleInterface("
981 "polyTopoChange& ref) const"
982 ) <<
"Face " << faceI <<
" in cut faces has neither a master "
983 <<
"nor a slave. Error in the cutting algorithm on modify."
997 if (masterFc[curMaster] < slaveFc[curSlave])
1006 masterFc[curMaster],
1010 masterPatchAddr[curMaster],
1013 cutFaceZoneID_.
index(),
1025 curCutFace.reverseFace(),
1027 masterFc[curMaster],
1030 masterPatchAddr[curMaster],
1033 cutFaceZoneID_.
index(),
1040 orphanedSlave[curSlave] =
true;
1051 masterFc[curMaster],
1055 masterPatchAddr[curMaster],
1057 masterPatchID_.
index(),
1058 cutFaceZoneID_.
index(),
1065 orphanedMaster[curMaster] =
true;
1067 else if (curSlave >= 0)
1080 slavePatchAddr[curSlave],
1082 slavePatchID_.
index(),
1083 cutFaceZoneID_.
index(),
1089 orphanedSlave[curSlave] =
true;
1095 "void slidingInterface::coupleInterface("
1096 "polyTopoChange& ref) const"
1097 ) <<
"Face " << faceI <<
" in cut faces has neither a master "
1098 <<
"nor a slave. Error in the cutting algorithm on add."
1108 label nOrphanedMasters = 0;
1110 forAll (orphanedMaster, faceI)
1112 if (orphanedMaster[faceI])
1135 ref.setAction(polyRemoveFace(masterPatchAddr[faceI]));
1139 label nOrphanedSlaves = 0;
1141 forAll (orphanedSlave, faceI)
1143 if (orphanedSlave[faceI])
1166 ref.setAction(polyRemoveFace(slavePatchAddr[faceI]));
1172 Pout<<
"Number of orphaned faces: "
1173 <<
"master = " << nOrphanedMasters <<
" out of "
1174 << orphanedMaster.size()
1175 <<
" slave = " << nOrphanedSlaves <<
" out of "
1176 << orphanedSlave.size() <<
endl;
1195 const labelList& masterStickOuts = masterStickOutFaces();
1200 forAll (masterStickOuts, faceI)
1204 const label curFaceID = masterStickOuts[faceI];
1206 const face& oldRichFace = faces[curFaceID];
1208 bool changed =
false;
1211 face oldFace(oldRichFace.size());
1214 forAll (oldRichFace, pointI)
1216 if (ref.pointRemoved(oldRichFace[pointI]))
1223 oldFace[nOldFace] = oldRichFace[pointI];
1228 oldFace.setSize(nOldFace);
1231 DynamicList<label> newFaceLabels(2*oldFace.size());
1235 if (masterMeshPointMap.found(oldFace[pointI]))
1241 if (pointMergeMap.found(oldFace[pointI]))
1244 newFaceLabels.append
1246 pointMergeMap.find(oldFace[pointI])()
1251 newFaceLabels.append(oldFace[pointI]);
1260 const label localFirstLabel =
1261 masterMeshPointMap.find(oldFace[pointI])();
1263 const labelList& curEdges = masterPointEdges[localFirstLabel];
1265 const label nextLabel = oldFace.nextLabel(pointI);
1268 masterMeshPointMap.
find(nextLabel);
1270 if (mmpmIter != masterMeshPointMap.end())
1274 const label localNextLabel = mmpmIter();
1276 forAll (curEdges, curEdgeI)
1280 masterEdges[curEdges[curEdgeI]].otherVertex
1290 const labelList& curPime = pime[curEdges[curEdgeI]];
1298 const point& startPoint =
1299 masterLocalPoints[localFirstLabel];
1302 masterLocalPoints[localNextLabel]
1309 forAll (curPime, curPimeI)
1311 edgePointWeights[curPimeI] =
1315 pointMap.find(curPime[curPimeI])()
1325 min(edgePointWeights) < 0
1326 ||
max(edgePointWeights) > 1
1331 "void slidingInterface::"
1333 "polyTopoChange& ref) const"
1334 ) <<
"Error in master stick-out edge "
1335 <<
"point collection."
1347 passI < edgePointWeights.size();
1354 label nextPoint = -1;
1357 forAll (edgePointWeights, wI)
1359 if (edgePointWeights[wI] < dist)
1361 dist = edgePointWeights[wI];
1369 newFaceLabels.append(curPime[nextPoint]);
1370 edgePointWeights[nextPoint] = GREAT;
1381 newFaceLabels.append(oldFace[pointI]);
1387 if (newFaceLabels.size() < 3)
1391 "void slidingInterface::coupleInterface("
1392 "polyTopoChange& ref) const"
1393 ) <<
"Face " << curFaceID <<
" reduced to less than "
1394 <<
"3 points. Topological/cutting error A." <<
nl
1395 <<
"Old face: " << oldFace <<
" new face: " << newFaceLabels
1400 label modifiedFaceZone = faceZones.whichZone(curFaceID);
1401 bool modifiedFaceZoneFlip =
false;
1403 if (modifiedFaceZone >= 0)
1405 modifiedFaceZoneFlip =
1406 faceZones[modifiedFaceZone].flipMap()
1408 faceZones[modifiedFaceZone].whichFace(curFaceID)
1413 newFace.transfer(newFaceLabels);
1419 if (mesh.isInternalFace(curFaceID))
1433 modifiedFaceZoneFlip
1448 mesh.boundaryMesh().whichPatch(curFaceID),
1451 modifiedFaceZoneFlip
1463 const labelList& slaveStickOuts = slaveStickOutFaces();
1467 const Map<label>& rpm = retiredPointMap();
1471 forAll (slaveStickOuts, faceI)
1474 const label curFaceID = slaveStickOuts[faceI];
1476 const face& oldRichFace = faces[curFaceID];
1478 bool changed =
false;
1481 face oldFace(oldRichFace.size());
1484 forAll (oldRichFace, pointI)
1488 rpm.found(oldRichFace[pointI])
1489 || slaveMeshPointMap.found(oldRichFace[pointI])
1493 oldFace[nOldFace] = oldRichFace[pointI];
1498 ref.pointRemoved(oldRichFace[pointI])
1499 || masterMeshPointMap.found(oldRichFace[pointI])
1510 oldFace[nOldFace] = oldRichFace[pointI];
1515 oldFace.setSize(nOldFace);
1517 DynamicList<label> newFaceLabels(2*oldFace.size());
1523 label curP = oldFace[pointI];
1527 if (rpmIter != rpm.end())
1533 if (slaveMeshPointMap.found(curP))
1539 if (pointMergeMap.found(curP))
1542 newFaceLabels.append
1544 pointMergeMap.find(curP)()
1549 newFaceLabels.append(curP);
1559 const label localFirstLabel =
1560 slaveMeshPointMap.find(curP)();
1562 const labelList& curEdges = slavePointEdges[localFirstLabel];
1564 label nextLabel = oldFace.nextLabel(pointI);
1567 rpm.
find(nextLabel);
1569 if (rpmNextIter != rpm.end())
1571 nextLabel = rpmNextIter();
1575 slaveMeshPointMap.
find(nextLabel);
1577 if (mmpmIter != slaveMeshPointMap.end())
1581 const label localNextLabel = mmpmIter();
1583 forAll (curEdges, curEdgeI)
1587 slaveEdges[curEdges[curEdgeI]].otherVertex
1597 const labelList& curPise = pise[curEdges[curEdgeI]];
1605 const point& startPoint =
1606 projectedSlavePoints[localFirstLabel];
1609 projectedSlavePoints[localNextLabel]
1616 forAll (curPise, curPiseI)
1618 edgePointWeights[curPiseI] =
1622 pointMap.find(curPise[curPiseI])()
1632 min(edgePointWeights) < 0
1633 ||
max(edgePointWeights) > 1
1638 "void slidingInterface::"
1640 "polyTopoChange& ref) const"
1641 ) <<
"Error in slave stick-out edge "
1642 <<
"point collection."
1654 passI < edgePointWeights.size();
1661 label nextPoint = -1;
1664 forAll (edgePointWeights, wI)
1666 if (edgePointWeights[wI] < dist)
1668 dist = edgePointWeights[wI];
1676 newFaceLabels.append(curPise[nextPoint]);
1677 edgePointWeights[nextPoint] = GREAT;
1688 newFaceLabels.append(oldFace[pointI]);
1694 if (newFaceLabels.size() < 3)
1698 "void slidingInterface::coupleInterface("
1699 "polyTopoChange& ref) const"
1700 ) <<
"Face " << curFaceID <<
" reduced to less than "
1701 <<
"3 points. Topological/cutting error B." <<
nl
1702 <<
"Old face: " << oldFace <<
" new face: " << newFaceLabels
1707 label modifiedFaceZone = faceZones.whichZone(curFaceID);
1708 bool modifiedFaceZoneFlip =
false;
1710 if (modifiedFaceZone >= 0)
1712 modifiedFaceZoneFlip =
1713 faceZones[modifiedFaceZone].flipMap()
1715 faceZones[modifiedFaceZone].whichFace(curFaceID)
1720 newFace.transfer(newFaceLabels);
1725 if (mesh.isInternalFace(curFaceID))
1739 modifiedFaceZoneFlip
1754 mesh.boundaryMesh().whichPatch(curFaceID),
1757 modifiedFaceZoneFlip
1768 if (!retiredPointMapPtr_)
1772 "void slidingInterface::coupleInterface("
1773 "polyTopoChange& ref) const"
1774 ) <<
"Retired point map pointer not set."
1778 Map<label>& addToRpm = *retiredPointMapPtr_;
1783 label nRetiredPoints = 0;
1785 forAll (slaveMeshPoints, pointI)
1787 if (pointMergeMap.found(slaveMeshPoints[pointI]))
1811 slaveMeshPoints[pointI]
1817 pointMergeMap.find(slaveMeshPoints[pointI])(),
1818 slaveMeshPoints[pointI]
1827 slaveMeshPoints[pointI],
1828 points[slaveMeshPoints[pointI]],
1830 mesh.pointZones().whichZone(slaveMeshPoints[pointI]),
1839 Pout <<
"Retired " << nRetiredPoints <<
" out of "
1840 << slaveMeshPoints.size() <<
" points." <<
endl;
1845 cutFaceMasterPtr_ =
new labelList(cutPatch.cutFaceMaster());
1848 cutFaceSlavePtr_ =
new labelList(cutPatch.cutFaceSlave());
1855 Pout<<
"void slidingInterface::coupleInterface("
1856 <<
"polyTopoChange& ref) : "
1857 <<
"Finished coupling sliding interface " <<
name() <<
endl;