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_
129 <<
"Point projection addressing not available." 133 const labelList& slavePointPointHits = *slavePointPointHitsPtr_;
134 const labelList& slavePointEdgeHits = *slavePointEdgeHitsPtr_;
135 const List<objectHit>& slavePointFaceHits = *slavePointFaceHitsPtr_;
136 const labelList& masterPointEdgeHits = *masterPointEdgeHitsPtr_;
137 const pointField& projectedSlavePoints = *projectedSlavePointsPtr_;
140 enrichedPatch cutPatch
151 Map<point>& pointMap = cutPatch.pointMap();
154 Map<label>& pointMergeMap = cutPatch.pointMergeMap();
157 forAll(slavePointPointHits, pointi)
159 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]);
242 List<DynamicList<label>> pointsIntoMasterEdges(masterEdges.size());
243 List<DynamicList<label>> pointsIntoSlaveEdges(slaveEdges.size());
246 forAll(slavePointEdgeHits, pointi)
248 if (slavePointEdgeHits[pointi] > -1)
253 masterEdges[slavePointEdgeHits[pointi]].line
256 ).nearestDist(projectedSlavePoints[pointi]).hitPoint();
264 slaveMeshPoints[pointi],
265 cutPointZoneID_.
index(),
278 pointMergeMap.insert(slaveMeshPoints[pointi], newPoint);
280 pointsIntoMasterEdges[slavePointEdgeHits[pointi]].append
306 forAll(slavePointFaceHits, pointi)
310 slavePointPointHits[pointi] < 0
311 && slavePointEdgeHits[pointi] < 0
312 && slavePointFaceHits[pointi].hit()
320 projectedSlavePoints[pointi],
321 slaveMeshPoints[pointi],
322 cutPointZoneID_.
index(),
333 pointMergeMap.insert(slaveMeshPoints[pointi], newPoint);
339 projectedSlavePoints[pointi]
344 Pout<<
"f: " << newPoint <<
" = " 345 << projectedSlavePoints[pointi] <<
endl;
350 forAll(masterPointEdgeHits, pointi)
352 if (masterPointEdgeHits[pointi] > -1)
354 pointsIntoSlaveEdges[masterPointEdgeHits[pointi]].append
356 masterMeshPoints[pointi]
393 Pout<<
"Processing slave edges " <<
endl;
396 if (!cutPointEdgePairMapPtr_)
399 <<
"Cut point edge pair map pointer not set." 403 Map<Pair<edge>>& addToCpepm = *cutPointEdgePairMapPtr_;
418 const edge& curEdge = slaveEdges[edgeI];
422 slavePointFaceHits[curEdge.start()].hit()
423 || slavePointFaceHits[curEdge.end()].hit()
438 const label startFace =
439 slavePointFaceHits[curEdge.start()].hitObject();
440 const label endFace = slavePointFaceHits[curEdge.end()].hitObject();
447 curFaceMap.insert(startFace);
448 addedFaces.insert(startFace);
453 bool completed =
false;
455 while (nSweeps < edgeFaceEscapeLimit_)
459 if (addedFaces.found(endFace))
470 const labelList& curNbrs = masterFaceFaces[cf[cfI]];
474 if (!curFaceMap.found(curNbrs[nbrI]))
476 curFaceMap.insert(curNbrs[nbrI]);
477 addedFaces.insert(curNbrs[nbrI]);
482 if (completed)
break;
500 label nReverseSweeps = 0;
503 addedFaces.insert(endFace);
505 while (nReverseSweeps < edgeFaceEscapeLimit_)
509 if (addedFaces.found(startFace))
520 const labelList& curNbrs = masterFaceFaces[cf[cfI]];
524 if (!curFaceMap.found(curNbrs[nbrI]))
526 curFaceMap.insert(curNbrs[nbrI]);
527 addedFaces.insert(curNbrs[nbrI]);
532 if (completed)
break;
564 const labelList curFaces = curFaceMap.toc();
576 const labelList& me = masterFaceEdges[curFaces[facei]];
580 curMasterEdgesMap.insert(me[meI]);
584 const labelList curMasterEdges = curMasterEdgesMap.toc();
597 const point& a = projectedSlavePoints[curEdge.start()];
598 const point& b = projectedSlavePoints[curEdge.end()];
603 slaveLocalPoints[curEdge.start()]
604 + slavePointNormals[curEdge.start()]
605 + slaveLocalPoints[curEdge.end()]
606 + slavePointNormals[curEdge.end()]
610 plane cutPlane(a, b, c);
618 linePointRef curSlaveLine = curEdge.line(projectedSlavePoints);
619 const scalar curSlaveLineMag = curSlaveLine.mag();
623 forAll(curMasterEdges, masterEdgeI)
625 if (!curUme.found(curMasterEdges[masterEdgeI]))
633 const label cmeIndex = curMasterEdges[masterEdgeI];
634 const edge& cme = masterEdges[cmeIndex];
642 cutPlane.lineIntersect
644 cme.line(masterLocalPoints)
649 cutOnMaster > edgeEndCutoffTol_
650 && cutOnMaster < 1.0 - edgeEndCutoffTol_
654 point masterCutPoint =
655 masterLocalPoints[cme.start()]
656 + cutOnMaster*cme.vec(masterLocalPoints);
659 curSlaveLine.nearestDist(masterCutPoint);
669 - curSlaveLine.start()
670 ) & curSlaveLine.vec()
671 )/
sqr(curSlaveLineMag);
675 scalar mergeTol = edgeCoPlanarTol_*
mag(b - a);
691 cutOnSlave > edgeEndCutoffTol_
692 && cutOnSlave < 1.0 - edgeEndCutoffTol_
693 && slaveCut.distance() < mergeTol
706 masterMeshPoints[cme.start()],
707 cutPointZoneID_.
index(),
720 pointsIntoSlaveEdges[edgeI].append(newPoint);
721 pointsIntoMasterEdges[cmeIndex].append
742 masterMeshPoints[cme.start()],
743 masterMeshPoints[cme.end()]
747 slaveMeshPoints[curEdge.start()],
748 slaveMeshPoints[curEdge.end()]
755 Pout<<
" " << newPoint <<
" = " 756 << masterCutPoint <<
" ";
808 forAll(pointsIntoMasterEdges, i)
810 pime[i].transfer(pointsIntoMasterEdges[i]);
815 forAll(pointsIntoSlaveEdges, i)
817 pise[i].transfer(pointsIntoSlaveEdges[i]);
821 cutPatch.calcEnrichedFaces
831 const faceList& cutFaces = cutPatch.cutFaces();
832 const labelList& cutFaceMaster = cutPatch.cutFaceMaster();
833 const labelList& cutFaceSlave = cutPatch.cutFaceSlave();
835 const labelList& masterFc = masterFaceCells();
836 const labelList& slaveFc = slaveFaceCells();
847 boolList orphanedMaster(masterPatch.size(),
false);
848 boolList orphanedSlave(slavePatch.size(),
false);
852 const face& curCutFace = cutFaces[facei];
853 const label curMaster = cutFaceMaster[facei];
854 const label curSlave = cutFaceSlave[facei];
859 bool insertedFace =
false;
864 if (curCutFace == masterPatch[curMaster])
876 if (masterFc[curMaster] < slaveFc[curSlave])
885 masterPatchAddr[curMaster],
891 masterFaceZoneID_.
index(),
892 masterPatchFlip[curMaster]
910 curCutFace.reverseFace(),
911 masterPatchAddr[curMaster],
917 masterFaceZoneID_.
index(),
918 !masterPatchFlip[curMaster]
924 orphanedSlave[curSlave] =
true;
934 masterPatchAddr[curMaster],
938 masterPatchID_.
index(),
940 masterFaceZoneID_.
index(),
941 masterPatchFlip[curMaster]
949 else if (curSlave >= 0)
954 face rsf(slavePatch[curSlave]);
960 if (mpIter != pointMergeMap.end())
966 if (curCutFace == rsf)
974 if (masterFc[curMaster] < slaveFc[curSlave])
981 slavePatchAddr[curSlave],
987 slaveFaceZoneID_.
index(),
988 !slavePatchFlip[curMaster]
1001 curCutFace.reverseFace(),
1002 slavePatchAddr[curSlave],
1004 masterFc[curMaster],
1008 slaveFaceZoneID_.
index(),
1009 slavePatchFlip[curSlave]
1015 orphanedMaster[curMaster] =
true;
1025 slavePatchAddr[curSlave],
1029 slavePatchID_.
index(),
1031 slaveFaceZoneID_.
index(),
1032 slavePatchFlip[curSlave]
1037 insertedFace =
true;
1043 <<
"Face " << facei <<
" in cut faces has neither a master " 1044 <<
"nor a slave. Error in the cutting algorithm on modify." 1058 if (masterFc[curMaster] < slaveFc[curSlave])
1072 masterFc[curMaster],
1076 masterPatchAddr[curMaster],
1079 cutFaceZoneID_.
index(),
1091 curCutFace.reverseFace(),
1093 masterFc[curMaster],
1096 masterPatchAddr[curMaster],
1099 cutFaceZoneID_.
index(),
1106 orphanedSlave[curSlave] =
true;
1121 masterFc[curMaster],
1125 masterPatchAddr[curMaster],
1127 masterPatchID_.
index(),
1128 cutFaceZoneID_.
index(),
1135 orphanedMaster[curMaster] =
true;
1137 else if (curSlave >= 0)
1154 slavePatchAddr[curSlave],
1156 slavePatchID_.
index(),
1157 cutFaceZoneID_.
index(),
1163 orphanedSlave[curSlave] =
true;
1168 <<
"Face " << facei <<
" in cut faces has neither a master " 1169 <<
"nor a slave. Error in the cutting algorithm on add." 1179 label nOrphanedMasters = 0;
1181 forAll(orphanedMaster, facei)
1183 if (orphanedMaster[facei])
1206 ref.setAction(polyRemoveFace(masterPatchAddr[facei]));
1210 label nOrphanedSlaves = 0;
1212 forAll(orphanedSlave, facei)
1214 if (orphanedSlave[facei])
1237 ref.setAction(polyRemoveFace(slavePatchAddr[facei]));
1243 Pout<<
"Number of orphaned faces: " 1244 <<
"master = " << nOrphanedMasters <<
" out of " 1245 << orphanedMaster.size()
1246 <<
" slave = " << nOrphanedSlaves <<
" out of " 1247 << orphanedSlave.size() <<
endl;
1266 const labelList& masterStickOuts = masterStickOutFaces();
1271 forAll(masterStickOuts, facei)
1275 const label curFaceID = masterStickOuts[facei];
1277 const face& oldRichFace = faces[curFaceID];
1279 bool changed =
false;
1282 face oldFace(oldRichFace.size());
1285 forAll(oldRichFace, pointi)
1287 if (ref.pointRemoved(oldRichFace[pointi]))
1294 oldFace[nOldFace] = oldRichFace[pointi];
1299 oldFace.setSize(nOldFace);
1305 DynamicList<label> newFaceLabels(2*oldFace.size());
1309 if (masterMeshPointMap.found(oldFace[pointi]))
1315 if (pointMergeMap.found(oldFace[pointi]))
1318 newFaceLabels.append
1320 pointMergeMap.find(oldFace[pointi])()
1325 newFaceLabels.append(oldFace[pointi]);
1334 const label localFirstLabel =
1335 masterMeshPointMap.find(oldFace[pointi])();
1337 const labelList& curEdges = masterPointEdges[localFirstLabel];
1339 const label nextLabel = oldFace.nextLabel(pointi);
1342 masterMeshPointMap.find(nextLabel);
1344 if (mmpmIter != masterMeshPointMap.end())
1349 const label localNextLabel = mmpmIter();
1351 forAll(curEdges, curEdgeI)
1355 masterEdges[curEdges[curEdgeI]].otherVertex
1366 const labelList& curPime = pime[curEdges[curEdgeI]];
1374 const point& startPoint =
1375 masterLocalPoints[localFirstLabel];
1378 masterLocalPoints[localNextLabel]
1385 forAll(curPime, curPimeI)
1387 edgePointWeights[curPimeI] =
1391 pointMap.find(curPime[curPimeI])()
1401 min(edgePointWeights) < 0
1402 ||
max(edgePointWeights) > 1
1406 <<
"Error in master stick-out edge " 1407 <<
"point collection." 1419 passI < edgePointWeights.size();
1426 label nextPoint = -1;
1429 forAll(edgePointWeights, wI)
1431 if (edgePointWeights[wI] < dist)
1433 dist = edgePointWeights[wI];
1441 newFaceLabels.append(curPime[nextPoint]);
1442 edgePointWeights[nextPoint] = great;
1453 newFaceLabels.append(oldFace[pointi]);
1459 if (newFaceLabels.size() < 3)
1462 <<
"Face " << curFaceID <<
" reduced to less than " 1463 <<
"3 points. Topological/cutting error A." <<
nl 1464 <<
"Old face: " << oldFace <<
" new face: " << newFaceLabels
1469 label modifiedFaceZone = faceZones.whichZone(curFaceID);
1470 bool modifiedFaceZoneFlip =
false;
1472 if (modifiedFaceZone >= 0)
1474 modifiedFaceZoneFlip =
1475 faceZones[modifiedFaceZone].flipMap()
1477 faceZones[modifiedFaceZone].whichFace(curFaceID)
1482 newFace.transfer(newFaceLabels);
1490 if (mesh.isInternalFace(curFaceID))
1504 modifiedFaceZoneFlip
1519 mesh.boundaryMesh().whichPatch(curFaceID),
1523 modifiedFaceZoneFlip
1535 const labelList& slaveStickOuts = slaveStickOutFaces();
1539 const Map<label>& rpm = retiredPointMap();
1543 forAll(slaveStickOuts, facei)
1546 const label curFaceID = slaveStickOuts[facei];
1548 const face& oldRichFace = faces[curFaceID];
1550 bool changed =
false;
1553 face oldFace(oldRichFace.size());
1556 forAll(oldRichFace, pointi)
1560 rpm.found(oldRichFace[pointi])
1561 || slaveMeshPointMap.found(oldRichFace[pointi])
1565 oldFace[nOldFace] = oldRichFace[pointi];
1570 ref.pointRemoved(oldRichFace[pointi])
1571 || masterMeshPointMap.found(oldRichFace[pointi])
1582 oldFace[nOldFace] = oldRichFace[pointi];
1587 oldFace.setSize(nOldFace);
1589 DynamicList<label> newFaceLabels(2*oldFace.size());
1598 label curP = oldFace[pointi];
1602 if (rpmIter != rpm.end())
1608 if (slaveMeshPointMap.found(curP))
1614 if (pointMergeMap.found(curP))
1617 newFaceLabels.append
1619 pointMergeMap.find(curP)()
1624 newFaceLabels.append(curP);
1634 const label localFirstLabel =
1635 slaveMeshPointMap.find(curP)();
1637 const labelList& curEdges = slavePointEdges[localFirstLabel];
1639 label nextLabel = oldFace.nextLabel(pointi);
1642 rpm.find(nextLabel);
1644 if (rpmNextIter != rpm.end())
1646 nextLabel = rpmNextIter();
1650 slaveMeshPointMap.find(nextLabel);
1652 if (mmpmIter != slaveMeshPointMap.end())
1656 const label localNextLabel = mmpmIter();
1658 forAll(curEdges, curEdgeI)
1662 slaveEdges[curEdges[curEdgeI]].otherVertex
1673 const labelList& curPise = pise[curEdges[curEdgeI]];
1681 const point& startPoint =
1682 projectedSlavePoints[localFirstLabel];
1685 projectedSlavePoints[localNextLabel]
1692 forAll(curPise, curPiseI)
1694 edgePointWeights[curPiseI] =
1698 pointMap.find(curPise[curPiseI])()
1708 min(edgePointWeights) < 0
1709 ||
max(edgePointWeights) > 1
1713 <<
"Error in slave stick-out edge " 1714 <<
"point collection." 1726 passI < edgePointWeights.size();
1733 label nextPoint = -1;
1736 forAll(edgePointWeights, wI)
1738 if (edgePointWeights[wI] < dist)
1740 dist = edgePointWeights[wI];
1748 newFaceLabels.append(curPise[nextPoint]);
1749 edgePointWeights[nextPoint] = great;
1760 newFaceLabels.append(oldFace[pointi]);
1766 if (newFaceLabels.size() < 3)
1769 <<
"Face " << curFaceID <<
" reduced to less than " 1770 <<
"3 points. Topological/cutting error B." <<
nl 1771 <<
"Old face: " << oldFace <<
" new face: " << newFaceLabels
1776 label modifiedFaceZone = faceZones.whichZone(curFaceID);
1777 bool modifiedFaceZoneFlip =
false;
1779 if (modifiedFaceZone >= 0)
1781 modifiedFaceZoneFlip =
1782 faceZones[modifiedFaceZone].flipMap()
1784 faceZones[modifiedFaceZone].whichFace(curFaceID)
1789 newFace.transfer(newFaceLabels);
1797 if (mesh.isInternalFace(curFaceID))
1811 modifiedFaceZoneFlip
1826 mesh.boundaryMesh().whichPatch(curFaceID),
1830 modifiedFaceZoneFlip
1841 if (!retiredPointMapPtr_)
1844 <<
"Retired point map pointer not set." 1848 Map<label>& addToRpm = *retiredPointMapPtr_;
1853 label nRetiredPoints = 0;
1855 forAll(slaveMeshPoints, pointi)
1857 if (pointMergeMap.found(slaveMeshPoints[pointi]))
1882 slaveMeshPoints[pointi]
1888 pointMergeMap.find(slaveMeshPoints[pointi])(),
1889 slaveMeshPoints[pointi]
1898 slaveMeshPoints[pointi],
1899 points[slaveMeshPoints[pointi]],
1901 mesh.pointZones().whichZone(slaveMeshPoints[pointi]),
1910 Pout<<
"Retired " << nRetiredPoints <<
" out of " 1911 << slaveMeshPoints.size() <<
" points." <<
endl;
1916 cutFaceMasterPtr_ =
new labelList(cutPatch.cutFaceMaster());
1919 cutFaceSlavePtr_ =
new labelList(cutPatch.cutFaceSlave());
1926 Pout<<
"void slidingInterface::coupleInterface(" 1927 <<
"polyTopoChange& ref) : " 1928 <<
"Finished coupling sliding interface " <<
name() <<
endl;
List< labelList > labelListList
A List of labelList.
ZoneMesh< faceZone, polyMesh > faceZoneMesh
A ZoneMesh with the type faceZone.
#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.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Ostream & endl(Ostream &os)
Add newline and flush stream.
HashTable< label, label, Hash< label > >::const_iterator const_iterator
Vector< scalar > vector
A scalar version of the templated Vector.
static const unsigned edgesPerFace_
Estimated number of edges per cell.
List< bool > boolList
Bool container classes.
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.
void clear()
Clear all entries from table.
List< label > labelList
A List of labels.
errorManip< error > abort(error &err)
label index() const
Return index of first matching zone.
dimensioned< scalar > magSqr(const dimensioned< Type > &)
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)