00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "slidingInterface.H"
00028 #include "polyTopoChange.H"
00029 #include "polyMesh.H"
00030 #include "primitiveMesh.H"
00031 #include "enrichedPatch.H"
00032 #include "DynamicList.H"
00033 #include "pointHit.H"
00034 #include "triPointRef.H"
00035 #include "plane.H"
00036 #include "polyTopoChanger.H"
00037 #include "polyAddPoint.H"
00038 #include "polyRemovePoint.H"
00039 #include "polyAddFace.H"
00040 #include "polyModifyPoint.H"
00041 #include "polyModifyFace.H"
00042 #include "polyRemoveFace.H"
00043
00044
00045
00046 const Foam::scalar Foam::slidingInterface::edgeCoPlanarTol_ = 0.8;
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 void Foam::slidingInterface::coupleInterface(polyTopoChange& ref) const
00070 {
00071 if (debug)
00072 {
00073 Pout<< "void slidingInterface::coupleInterface"
00074 << "(polyTopoChange& ref) : "
00075 << "Coupling sliding interface " << name() << endl;
00076 }
00077
00078 const polyMesh& mesh = topoChanger().mesh();
00079
00080 const pointField& points = mesh.points();
00081 const faceList& faces = mesh.faces();
00082
00083 const labelList& own = mesh.faceOwner();
00084 const labelList& nei = mesh.faceNeighbour();
00085 const faceZoneMesh& faceZones = mesh.faceZones();
00086
00087 const primitiveFacePatch& masterPatch =
00088 faceZones[masterFaceZoneID_.index()]();
00089
00090 const labelList& masterPatchAddr = faceZones[masterFaceZoneID_.index()];
00091
00092 const boolList& masterPatchFlip =
00093 faceZones[masterFaceZoneID_.index()].flipMap();
00094
00095 const primitiveFacePatch& slavePatch =
00096 faceZones[slaveFaceZoneID_.index()]();
00097
00098 const labelList& slavePatchAddr = faceZones[slaveFaceZoneID_.index()];
00099
00100 const boolList& slavePatchFlip =
00101 faceZones[slaveFaceZoneID_.index()].flipMap();
00102
00103 const edgeList& masterEdges = masterPatch.edges();
00104 const labelListList& masterPointEdges = masterPatch.pointEdges();
00105 const labelList& masterMeshPoints = masterPatch.meshPoints();
00106 const pointField& masterLocalPoints = masterPatch.localPoints();
00107 const labelListList& masterFaceFaces = masterPatch.faceFaces();
00108 const labelListList& masterFaceEdges = masterPatch.faceEdges();
00109 const Map<label>& masterMeshPointMap = masterPatch.meshPointMap();
00110
00111 const edgeList& slaveEdges = slavePatch.edges();
00112 const labelListList& slavePointEdges = slavePatch.pointEdges();
00113 const labelList& slaveMeshPoints = slavePatch.meshPoints();
00114 const pointField& slaveLocalPoints = slavePatch.localPoints();
00115 const Map<label>& slaveMeshPointMap = slavePatch.meshPointMap();
00116 const vectorField& slavePointNormals = slavePatch.pointNormals();
00117
00118
00119 if
00120 (
00121 !(
00122 slavePointPointHitsPtr_
00123 && slavePointEdgeHitsPtr_
00124 && slavePointFaceHitsPtr_
00125 && masterPointEdgeHitsPtr_
00126 )
00127 )
00128 {
00129 FatalErrorIn
00130 (
00131 "void slidingInterface::coupleInterface("
00132 "polyTopoChange& ref) const"
00133 ) << "Point projection addressing not available."
00134 << abort(FatalError);
00135 }
00136
00137 const labelList& slavePointPointHits = *slavePointPointHitsPtr_;
00138 const labelList& slavePointEdgeHits = *slavePointEdgeHitsPtr_;
00139 const List<objectHit>& slavePointFaceHits = *slavePointFaceHitsPtr_;
00140 const labelList& masterPointEdgeHits = *masterPointEdgeHitsPtr_;
00141 const pointField& projectedSlavePoints = *projectedSlavePointsPtr_;
00142
00143
00144 enrichedPatch cutPatch
00145 (
00146 masterPatch,
00147 slavePatch,
00148 slavePointPointHits,
00149 slavePointEdgeHits,
00150 slavePointFaceHits
00151 );
00152
00153
00154
00155 Map<point>& pointMap = cutPatch.pointMap();
00156
00157
00158 Map<label>& pointMergeMap = cutPatch.pointMergeMap();
00159
00160
00161 forAll (slavePointPointHits, pointI)
00162 {
00163 if (slavePointPointHits[pointI] >= 0)
00164 {
00165
00166 pointMergeMap.insert
00167 (
00168 slaveMeshPoints[pointI],
00169 masterMeshPoints[slavePointPointHits[pointI]]
00170 );
00171 }
00172 }
00173
00174
00175
00176 List<labelHashSet> usedMasterEdges(slaveEdges.size());
00177
00178
00179 forAll (slavePointPointHits, pointI)
00180 {
00181
00182 const labelList& curSlaveEdges = slavePointEdges[pointI];
00183
00184 if (slavePointPointHits[pointI] > -1)
00185 {
00186 const labelList& curMasterEdges =
00187 masterPointEdges[slavePointPointHits[pointI]];
00188
00189
00190
00191 forAll (curSlaveEdges, slaveEdgeI)
00192 {
00193 labelHashSet& sm = usedMasterEdges[curSlaveEdges[slaveEdgeI]];
00194
00195 forAll (curMasterEdges, masterEdgeI)
00196 {
00197 sm.insert(curMasterEdges[masterEdgeI]);
00198 }
00199 }
00200 }
00201 else if (slavePointEdgeHits[pointI] > -1)
00202 {
00203
00204 forAll (curSlaveEdges, slaveEdgeI)
00205 {
00206 usedMasterEdges[curSlaveEdges[slaveEdgeI]].insert
00207 (
00208 slavePointEdgeHits[pointI]
00209 );
00210 }
00211 }
00212 }
00213
00214
00215
00216
00217 forAll (masterPointEdgeHits, masterPointI)
00218 {
00219 if (masterPointEdgeHits[masterPointI] > -1)
00220 {
00221 const labelList& curMasterEdges = masterPointEdges[masterPointI];
00222
00223 labelHashSet& sm =
00224 usedMasterEdges[masterPointEdgeHits[masterPointI]];
00225
00226 forAll (curMasterEdges, masterEdgeI)
00227 {
00228 sm.insert(curMasterEdges[masterEdgeI]);
00229 }
00230 }
00231 }
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 List<DynamicList<label> > pointsIntoMasterEdges(masterEdges.size());
00242 List<DynamicList<label> > pointsIntoSlaveEdges(slaveEdges.size());
00243
00244
00245 forAll (slavePointEdgeHits, pointI)
00246 {
00247 if (slavePointEdgeHits[pointI] > -1)
00248 {
00249
00250
00251 point edgeCutPoint =
00252 masterEdges[slavePointEdgeHits[pointI]].line
00253 (
00254 masterLocalPoints
00255 ).nearestDist(projectedSlavePoints[pointI]).hitPoint();
00256
00257 label newPoint =
00258 ref.setAction
00259 (
00260 polyAddPoint
00261 (
00262 edgeCutPoint,
00263 slaveMeshPoints[pointI],
00264 cutPointZoneID_.index(),
00265 true
00266 )
00267 );
00268
00269
00270 pointMergeMap.insert(slaveMeshPoints[pointI], newPoint);
00271
00272 pointsIntoMasterEdges[slavePointEdgeHits[pointI]].append
00273 (
00274 newPoint
00275 );
00276
00277
00278 pointMap.insert
00279 (
00280 newPoint,
00281 edgeCutPoint
00282 );
00283
00284 if (debug)
00285 {
00286 Pout<< "e";
00287
00288 }
00289 }
00290 }
00291
00292 if (debug)
00293 {
00294 Pout<< endl;
00295 }
00296
00297
00298 forAll (slavePointFaceHits, pointI)
00299 {
00300 if
00301 (
00302 slavePointPointHits[pointI] < 0
00303 && slavePointEdgeHits[pointI] < 0
00304 && slavePointFaceHits[pointI].hit()
00305 )
00306 {
00307 label newPoint =
00308 ref.setAction
00309 (
00310 polyAddPoint
00311 (
00312 projectedSlavePoints[pointI],
00313 slaveMeshPoints[pointI],
00314 cutPointZoneID_.index(),
00315 true
00316 )
00317 );
00318
00319
00320 pointMergeMap.insert(slaveMeshPoints[pointI], newPoint);
00321
00322
00323 pointMap.insert
00324 (
00325 newPoint,
00326 projectedSlavePoints[pointI]
00327 );
00328
00329 if (debug)
00330 {
00331 Pout<< "f: " << newPoint << " = "
00332 << projectedSlavePoints[pointI] << endl;
00333 }
00334 }
00335 }
00336
00337 forAll (masterPointEdgeHits, pointI)
00338 {
00339 if (masterPointEdgeHits[pointI] > -1)
00340 {
00341 pointsIntoSlaveEdges[masterPointEdgeHits[pointI]].append
00342 (
00343 masterMeshPoints[pointI]
00344 );
00345 }
00346 }
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378 if (debug)
00379 {
00380 Pout << "Processing slave edges " << endl;
00381 }
00382
00383 if (!cutPointEdgePairMapPtr_)
00384 {
00385 FatalErrorIn
00386 (
00387 "void slidingInterface::coupleInterface("
00388 "polyTopoChange& ref) const"
00389 ) << "Cut point edge pair map pointer not set."
00390 << abort(FatalError);
00391 }
00392
00393 Map<Pair<edge> >& addToCpepm = *cutPointEdgePairMapPtr_;
00394
00395
00396 addToCpepm.clear();
00397
00398
00399 labelHashSet curFaceMap
00400 (
00401 nFacesPerSlaveEdge_*primitiveMesh::edgesPerFace_
00402 );
00403
00404 labelHashSet addedFaces(2*primitiveMesh::edgesPerFace_);
00405
00406 forAll (slaveEdges, edgeI)
00407 {
00408 const edge& curEdge = slaveEdges[edgeI];
00409
00410 if
00411 (
00412 slavePointFaceHits[curEdge.start()].hit()
00413 || slavePointFaceHits[curEdge.end()].hit()
00414 )
00415 {
00416 labelHashSet& curUme = usedMasterEdges[edgeI];
00417
00418
00419 curFaceMap.clear();
00420 addedFaces.clear();
00421
00422
00423 const label startFace =
00424 slavePointFaceHits[curEdge.start()].hitObject();
00425 const label endFace = slavePointFaceHits[curEdge.end()].hitObject();
00426
00427
00428 curFaceMap.insert(startFace);
00429 addedFaces.insert(startFace);
00430
00431 label nSweeps = 0;
00432 bool completed = false;
00433
00434 while (nSweeps < edgeFaceEscapeLimit_)
00435 {
00436 nSweeps++;
00437
00438 if (addedFaces.found(endFace))
00439 {
00440 completed = true;
00441 }
00442
00443
00444 const labelList cf = addedFaces.toc();
00445 addedFaces.clear();
00446
00447 forAll (cf, cfI)
00448 {
00449 const labelList& curNbrs = masterFaceFaces[cf[cfI]];
00450
00451 forAll (curNbrs, nbrI)
00452 {
00453 if (!curFaceMap.found(curNbrs[nbrI]))
00454 {
00455 curFaceMap.insert(curNbrs[nbrI]);
00456 addedFaces.insert(curNbrs[nbrI]);
00457 }
00458 }
00459 }
00460
00461 if (completed) break;
00462
00463 if (debug)
00464 {
00465 Pout << ".";
00466 }
00467 }
00468
00469 if (!completed)
00470 {
00471 if (debug)
00472 {
00473 Pout << "x";
00474 }
00475
00476
00477
00478
00479 label nReverseSweeps = 0;
00480
00481 addedFaces.clear();
00482 addedFaces.insert(endFace);
00483
00484 while (nReverseSweeps < edgeFaceEscapeLimit_)
00485 {
00486 nReverseSweeps++;
00487
00488 if (addedFaces.found(startFace))
00489 {
00490 completed = true;
00491 }
00492
00493
00494 const labelList cf = addedFaces.toc();
00495 addedFaces.clear();
00496
00497 forAll (cf, cfI)
00498 {
00499 const labelList& curNbrs = masterFaceFaces[cf[cfI]];
00500
00501 forAll (curNbrs, nbrI)
00502 {
00503 if (!curFaceMap.found(curNbrs[nbrI]))
00504 {
00505 curFaceMap.insert(curNbrs[nbrI]);
00506 addedFaces.insert(curNbrs[nbrI]);
00507 }
00508 }
00509 }
00510
00511 if (completed) break;
00512
00513 if (debug)
00514 {
00515 Pout << ".";
00516 }
00517 }
00518 }
00519
00520 if (completed)
00521 {
00522 if (debug)
00523 {
00524 Pout << "+ ";
00525 }
00526 }
00527 else
00528 {
00529 if (debug)
00530 {
00531 Pout << "z ";
00532 }
00533 }
00534
00535
00536
00537
00538 labelHashSet curMasterEdgesMap
00539 (
00540 nFacesPerSlaveEdge_*primitiveMesh::edgesPerFace_
00541 );
00542
00543 const labelList curFaces = curFaceMap.toc();
00544
00545 forAll (curFaces, faceI)
00546 {
00547
00548
00549
00550
00551
00552 const labelList& me = masterFaceEdges[curFaces[faceI]];
00553
00554 forAll (me, meI)
00555 {
00556 curMasterEdgesMap.insert(me[meI]);
00557 }
00558 }
00559
00560 const labelList curMasterEdges = curMasterEdgesMap.toc();
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573 const point& a = projectedSlavePoints[curEdge.start()];
00574 const point& b = projectedSlavePoints[curEdge.end()];
00575
00576 point c =
00577 0.5*
00578 (
00579 slaveLocalPoints[curEdge.start()]
00580 + slavePointNormals[curEdge.start()]
00581 + slaveLocalPoints[curEdge.end()]
00582 + slavePointNormals[curEdge.end()]
00583 );
00584
00585
00586 plane cutPlane(a, b, c);
00587
00588
00589 linePointRef curSlaveLine = curEdge.line(projectedSlavePoints);
00590 const scalar curSlaveLineMag = curSlaveLine.mag();
00591
00592 forAll (curMasterEdges, masterEdgeI)
00593 {
00594 if (!curUme.found(curMasterEdges[masterEdgeI]))
00595 {
00596
00597 if (debug)
00598 {
00599 Pout << "n";
00600 }
00601
00602 const label cmeIndex = curMasterEdges[masterEdgeI];
00603 const edge& cme = masterEdges[cmeIndex];
00604
00605 scalar cutOnMaster =
00606 cutPlane.lineIntersect
00607 (
00608 cme.line(masterLocalPoints)
00609 );
00610
00611 if
00612 (
00613 cutOnMaster > edgeEndCutoffTol_
00614 && cutOnMaster < 1.0 - edgeEndCutoffTol_
00615 )
00616 {
00617
00618 point masterCutPoint =
00619 masterLocalPoints[cme.start()]
00620 + cutOnMaster*cme.vec(masterLocalPoints);
00621
00622 pointHit slaveCut =
00623 curSlaveLine.nearestDist(masterCutPoint);
00624
00625 if (slaveCut.hit())
00626 {
00627
00628
00629 scalar cutOnSlave =
00630 (
00631 (
00632 slaveCut.hitPoint()
00633 - curSlaveLine.start()
00634 ) & curSlaveLine.vec()
00635 )/sqr(curSlaveLineMag);
00636
00637
00638
00639 scalar mergeTol =
00640 edgeCoPlanarTol_*mag(b - a);
00641
00642 if
00643 (
00644 cutOnSlave > edgeEndCutoffTol_
00645 && cutOnSlave < 1.0 - edgeEndCutoffTol_
00646 && slaveCut.distance() < mergeTol
00647 )
00648 {
00649
00650
00651
00652
00653 label newPoint =
00654 ref.setAction
00655 (
00656 polyAddPoint
00657 (
00658 masterCutPoint,
00659 masterMeshPoints[cme.start()],
00660 cutPointZoneID_.index(),
00661 true
00662 )
00663 );
00664
00665 pointsIntoSlaveEdges[edgeI].append(newPoint);
00666 pointsIntoMasterEdges[cmeIndex].append(newPoint);
00667
00668
00669 pointMap.insert
00670 (
00671 newPoint,
00672 masterCutPoint
00673 );
00674
00675
00676
00677 addToCpepm.insert
00678 (
00679 newPoint,
00680 Pair<edge>
00681 (
00682 edge
00683 (
00684 masterMeshPoints[cme.start()],
00685 masterMeshPoints[cme.end()]
00686 ),
00687 edge
00688 (
00689 slaveMeshPoints[curEdge.start()],
00690 slaveMeshPoints[curEdge.end()]
00691 )
00692 )
00693 );
00694
00695 if (debug)
00696 {
00697 Pout<< " " << newPoint << " = "
00698 << masterCutPoint << " ";
00699 }
00700 }
00701 else
00702 {
00703 if (debug)
00704 {
00705
00706 Pout << "t";
00707 }
00708 }
00709 }
00710 else
00711 {
00712 if (debug)
00713 {
00714
00715 Pout << "x";
00716 }
00717 }
00718 }
00719 else
00720 {
00721 if (debug)
00722 {
00723
00724 Pout << "-";
00725 }
00726 }
00727 }
00728 else
00729 {
00730 if (debug)
00731 {
00732 Pout << "u";
00733 }
00734 }
00735 }
00736
00737 if (debug)
00738 {
00739 Pout << endl;
00740 }
00741 }
00742 }
00743
00744
00745
00746
00747
00748 labelListList pime(pointsIntoMasterEdges.size());
00749
00750 forAll (pointsIntoMasterEdges, i)
00751 {
00752 pime[i].transfer(pointsIntoMasterEdges[i]);
00753 }
00754
00755 labelListList pise(pointsIntoSlaveEdges.size());
00756
00757 forAll (pointsIntoSlaveEdges, i)
00758 {
00759 pise[i].transfer(pointsIntoSlaveEdges[i]);
00760 }
00761
00762
00763 cutPatch.calcEnrichedFaces
00764 (
00765 pime,
00766 pise,
00767 projectedSlavePoints
00768 );
00769
00770
00771
00772
00773 const faceList& cutFaces = cutPatch.cutFaces();
00774 const labelList& cutFaceMaster = cutPatch.cutFaceMaster();
00775 const labelList& cutFaceSlave = cutPatch.cutFaceSlave();
00776
00777 const labelList& masterFc = masterFaceCells();
00778 const labelList& slaveFc = slaveFaceCells();
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789 boolList orphanedMaster(masterPatch.size(), false);
00790 boolList orphanedSlave(slavePatch.size(), false);
00791
00792 forAll (cutFaces, faceI)
00793 {
00794 const face& curCutFace = cutFaces[faceI];
00795 const label curMaster = cutFaceMaster[faceI];
00796 const label curSlave = cutFaceSlave[faceI];
00797
00798
00799
00800
00801 bool insertedFace = false;
00802
00803 if (curMaster >= 0)
00804 {
00805
00806 if (curCutFace == masterPatch[curMaster])
00807 {
00808
00809
00810
00811
00812
00813
00814
00815 if (curSlave >= 0)
00816 {
00817
00818 if (masterFc[curMaster] < slaveFc[curSlave])
00819 {
00820
00821
00822 ref.setAction
00823 (
00824 polyModifyFace
00825 (
00826 curCutFace,
00827 masterPatchAddr[curMaster],
00828 masterFc[curMaster],
00829 slaveFc[curSlave],
00830 false,
00831 -1,
00832 false,
00833 masterFaceZoneID_.index(),
00834 masterPatchFlip[curMaster]
00835 )
00836 );
00837
00838 }
00839 else
00840 {
00841
00842
00843 ref.setAction
00844 (
00845 polyModifyFace
00846 (
00847 curCutFace.reverseFace(),
00848 masterPatchAddr[curMaster],
00849 slaveFc[curSlave],
00850 masterFc[curMaster],
00851 true,
00852 -1,
00853 false,
00854 masterFaceZoneID_.index(),
00855 !masterPatchFlip[curMaster]
00856 )
00857 );
00858 }
00859
00860
00861 orphanedSlave[curSlave] = true;
00862 }
00863 else
00864 {
00865
00866 ref.setAction
00867 (
00868 polyModifyFace
00869 (
00870 curCutFace,
00871 masterPatchAddr[curMaster],
00872 masterFc[curMaster],
00873 -1,
00874 false,
00875 masterPatchID_.index(),
00876 false,
00877 masterFaceZoneID_.index(),
00878 masterPatchFlip[curMaster]
00879 )
00880 );
00881 }
00882
00883 insertedFace = true;
00884 }
00885 }
00886 else if (curSlave >= 0)
00887 {
00888
00889
00890
00891 face rsf(slavePatch[curSlave]);
00892
00893 forAll (rsf, i)
00894 {
00895 Map<label>::const_iterator mpIter = pointMergeMap.find(rsf[i]);
00896
00897 if (mpIter != pointMergeMap.end())
00898 {
00899 rsf[i] = mpIter();
00900 }
00901 }
00902
00903 if (curCutFace == rsf)
00904 {
00905
00906
00907
00908 if (curMaster >= 0)
00909 {
00910
00911 if (masterFc[curMaster] < slaveFc[curSlave])
00912 {
00913 ref.setAction
00914 (
00915 polyModifyFace
00916 (
00917 curCutFace,
00918 slavePatchAddr[curSlave],
00919 masterFc[curMaster],
00920 slaveFc[curSlave],
00921 true,
00922 -1,
00923 false,
00924 slaveFaceZoneID_.index(),
00925 !slavePatchFlip[curMaster]
00926 )
00927 );
00928 }
00929 else
00930 {
00931
00932
00933
00934 ref.setAction
00935 (
00936 polyModifyFace
00937 (
00938 curCutFace.reverseFace(),
00939 slavePatchAddr[curSlave],
00940 slaveFc[curSlave],
00941 masterFc[curMaster],
00942 false,
00943 -1,
00944 false,
00945 slaveFaceZoneID_.index(),
00946 slavePatchFlip[curSlave]
00947 )
00948 );
00949 }
00950
00951
00952 orphanedMaster[curMaster] = true;
00953 }
00954 else
00955 {
00956
00957 ref.setAction
00958 (
00959 polyModifyFace
00960 (
00961 curCutFace,
00962 slavePatchAddr[curSlave],
00963 slaveFc[curSlave],
00964 -1,
00965 false,
00966 slavePatchID_.index(),
00967 false,
00968 slaveFaceZoneID_.index(),
00969 slavePatchFlip[curSlave]
00970 )
00971 );
00972 }
00973
00974 insertedFace = true;
00975 }
00976 }
00977 else
00978 {
00979 FatalErrorIn
00980 (
00981 "void slidingInterface::coupleInterface("
00982 "polyTopoChange& ref) const"
00983 ) << "Face " << faceI << " in cut faces has neither a master "
00984 << "nor a slave. Error in the cutting algorithm on modify."
00985 << abort(FatalError);
00986 }
00987
00988 if (!insertedFace)
00989 {
00990
00991
00992
00993 if (curMaster >= 0)
00994 {
00995 if (curSlave >= 0)
00996 {
00997
00998 if (masterFc[curMaster] < slaveFc[curSlave])
00999 {
01000
01001
01002 ref.setAction
01003 (
01004 polyAddFace
01005 (
01006 curCutFace,
01007 masterFc[curMaster],
01008 slaveFc[curSlave],
01009 -1,
01010 -1,
01011 masterPatchAddr[curMaster],
01012 false,
01013 -1,
01014 cutFaceZoneID_.index(),
01015 false
01016 )
01017 );
01018 }
01019 else
01020 {
01021
01022 ref.setAction
01023 (
01024 polyAddFace
01025 (
01026 curCutFace.reverseFace(),
01027 slaveFc[curSlave],
01028 masterFc[curMaster],
01029 -1,
01030 -1,
01031 masterPatchAddr[curMaster],
01032 true,
01033 -1,
01034 cutFaceZoneID_.index(),
01035 true
01036 )
01037 );
01038 }
01039
01040
01041 orphanedSlave[curSlave] = true;
01042 }
01043 else
01044 {
01045
01046
01047 ref.setAction
01048 (
01049 polyAddFace
01050 (
01051 curCutFace,
01052 masterFc[curMaster],
01053 -1,
01054 -1,
01055 -1,
01056 masterPatchAddr[curMaster],
01057 false,
01058 masterPatchID_.index(),
01059 cutFaceZoneID_.index(),
01060 false
01061 )
01062 );
01063 }
01064
01065
01066 orphanedMaster[curMaster] = true;
01067 }
01068 else if (curSlave >= 0)
01069 {
01070
01071
01072 ref.setAction
01073 (
01074 polyAddFace
01075 (
01076 curCutFace,
01077 slaveFc[curSlave],
01078 -1,
01079 -1,
01080 -1,
01081 slavePatchAddr[curSlave],
01082 false,
01083 slavePatchID_.index(),
01084 cutFaceZoneID_.index(),
01085 false
01086 )
01087 );
01088
01089
01090 orphanedSlave[curSlave] = true;
01091 }
01092 else
01093 {
01094 FatalErrorIn
01095 (
01096 "void slidingInterface::coupleInterface("
01097 "polyTopoChange& ref) const"
01098 ) << "Face " << faceI << " in cut faces has neither a master "
01099 << "nor a slave. Error in the cutting algorithm on add."
01100 << abort(FatalError);
01101 }
01102 }
01103 }
01104
01105
01106
01107
01108
01109 label nOrphanedMasters = 0;
01110
01111 forAll (orphanedMaster, faceI)
01112 {
01113 if (orphanedMaster[faceI])
01114 {
01115 nOrphanedMasters++;
01116
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136 ref.setAction(polyRemoveFace(masterPatchAddr[faceI]));
01137 }
01138 }
01139
01140 label nOrphanedSlaves = 0;
01141
01142 forAll (orphanedSlave, faceI)
01143 {
01144 if (orphanedSlave[faceI])
01145 {
01146 nOrphanedSlaves++;
01147
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167 ref.setAction(polyRemoveFace(slavePatchAddr[faceI]));
01168 }
01169 }
01170
01171 if (debug)
01172 {
01173 Pout<< "Number of orphaned faces: "
01174 << "master = " << nOrphanedMasters << " out of "
01175 << orphanedMaster.size()
01176 << " slave = " << nOrphanedSlaves << " out of "
01177 << orphanedSlave.size() << endl;
01178 }
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196 const labelList& masterStickOuts = masterStickOutFaces();
01197
01198
01199
01200
01201 forAll (masterStickOuts, faceI)
01202 {
01203
01204
01205 const label curFaceID = masterStickOuts[faceI];
01206
01207 const face& oldRichFace = faces[curFaceID];
01208
01209 bool changed = false;
01210
01211
01212 face oldFace(oldRichFace.size());
01213 label nOldFace = 0;
01214
01215 forAll (oldRichFace, pointI)
01216 {
01217 if (ref.pointRemoved(oldRichFace[pointI]))
01218 {
01219 changed = true;
01220 }
01221 else
01222 {
01223
01224 oldFace[nOldFace] = oldRichFace[pointI];
01225 nOldFace++;
01226 }
01227 }
01228
01229 oldFace.setSize(nOldFace);
01230
01231
01232 DynamicList<label> newFaceLabels(2*oldFace.size());
01233
01234 forAll (oldFace, pointI)
01235 {
01236 if (masterMeshPointMap.found(oldFace[pointI]))
01237 {
01238
01239
01240
01241
01242 if (pointMergeMap.found(oldFace[pointI]))
01243 {
01244 changed = true;
01245 newFaceLabels.append
01246 (
01247 pointMergeMap.find(oldFace[pointI])()
01248 );
01249 }
01250 else
01251 {
01252 newFaceLabels.append(oldFace[pointI]);
01253 }
01254
01255
01256
01257
01258
01259
01260
01261 const label localFirstLabel =
01262 masterMeshPointMap.find(oldFace[pointI])();
01263
01264 const labelList& curEdges = masterPointEdges[localFirstLabel];
01265
01266 const label nextLabel = oldFace.nextLabel(pointI);
01267
01268 Map<label>::const_iterator mmpmIter =
01269 masterMeshPointMap.find(nextLabel);
01270
01271 if (mmpmIter != masterMeshPointMap.end())
01272 {
01273
01274
01275 const label localNextLabel = mmpmIter();
01276
01277 forAll (curEdges, curEdgeI)
01278 {
01279 if
01280 (
01281 masterEdges[curEdges[curEdgeI]].otherVertex
01282 (
01283 localFirstLabel
01284 )
01285 == localNextLabel
01286 )
01287 {
01288
01289
01290
01291 const labelList& curPime = pime[curEdges[curEdgeI]];
01292
01293 if (curPime.size())
01294 {
01295 changed = true;
01296
01297
01298
01299 const point& startPoint =
01300 masterLocalPoints[localFirstLabel];
01301
01302 vector e =
01303 masterLocalPoints[localNextLabel]
01304 - startPoint;
01305
01306 e /= magSqr(e);
01307
01308 scalarField edgePointWeights(curPime.size());
01309
01310 forAll (curPime, curPimeI)
01311 {
01312 edgePointWeights[curPimeI] =
01313 (
01314 e
01315 & (
01316 pointMap.find(curPime[curPimeI])()
01317 - startPoint
01318 )
01319 );
01320 }
01321
01322 if (debug)
01323 {
01324 if
01325 (
01326 min(edgePointWeights) < 0
01327 || max(edgePointWeights) > 1
01328 )
01329 {
01330 FatalErrorIn
01331 (
01332 "void slidingInterface::"
01333 "coupleInterface("
01334 "polyTopoChange& ref) const"
01335 ) << "Error in master stick-out edge "
01336 << "point collection."
01337 << abort(FatalError);
01338 }
01339 }
01340
01341
01342
01343
01344
01345 for
01346 (
01347 label passI = 0;
01348 passI < edgePointWeights.size();
01349 passI++
01350 )
01351 {
01352
01353
01354
01355 label nextPoint = -1;
01356 scalar dist = 2;
01357
01358 forAll (edgePointWeights, wI)
01359 {
01360 if (edgePointWeights[wI] < dist)
01361 {
01362 dist = edgePointWeights[wI];
01363 nextPoint = wI;
01364 }
01365 }
01366
01367
01368
01369
01370 newFaceLabels.append(curPime[nextPoint]);
01371 edgePointWeights[nextPoint] = GREAT;
01372 }
01373 }
01374
01375 break;
01376 }
01377 }
01378 }
01379 }
01380 else
01381 {
01382 newFaceLabels.append(oldFace[pointI]);
01383 }
01384 }
01385
01386 if (changed)
01387 {
01388 if (newFaceLabels.size() < 3)
01389 {
01390 FatalErrorIn
01391 (
01392 "void slidingInterface::coupleInterface("
01393 "polyTopoChange& ref) const"
01394 ) << "Face " << curFaceID << " reduced to less than "
01395 << "3 points. Topological/cutting error A." << nl
01396 << "Old face: " << oldFace << " new face: " << newFaceLabels
01397 << abort(FatalError);
01398 }
01399
01400
01401 label modifiedFaceZone = faceZones.whichZone(curFaceID);
01402 bool modifiedFaceZoneFlip = false;
01403
01404 if (modifiedFaceZone >= 0)
01405 {
01406 modifiedFaceZoneFlip =
01407 faceZones[modifiedFaceZone].flipMap()
01408 [
01409 faceZones[modifiedFaceZone].whichFace(curFaceID)
01410 ];
01411 }
01412
01413 face newFace;
01414 newFace.transfer(newFaceLabels);
01415
01416
01417
01418
01419
01420 if (mesh.isInternalFace(curFaceID))
01421 {
01422 ref.setAction
01423 (
01424 polyModifyFace
01425 (
01426 newFace,
01427 curFaceID,
01428 own[curFaceID],
01429 nei[curFaceID],
01430 false,
01431 -1,
01432 false,
01433 modifiedFaceZone,
01434 modifiedFaceZoneFlip
01435 )
01436 );
01437 }
01438 else
01439 {
01440 ref.setAction
01441 (
01442 polyModifyFace
01443 (
01444 newFace,
01445 curFaceID,
01446 own[curFaceID],
01447 -1,
01448 false,
01449 mesh.boundaryMesh().whichPatch(curFaceID),
01450 false,
01451 modifiedFaceZone,
01452 modifiedFaceZoneFlip
01453 )
01454 );
01455 }
01456 }
01457 }
01458
01459
01460
01461
01462
01463
01464 const labelList& slaveStickOuts = slaveStickOutFaces();
01465
01466
01467
01468 const Map<label>& rpm = retiredPointMap();
01469
01470
01471
01472 forAll (slaveStickOuts, faceI)
01473 {
01474
01475 const label curFaceID = slaveStickOuts[faceI];
01476
01477 const face& oldRichFace = faces[curFaceID];
01478
01479 bool changed = false;
01480
01481
01482 face oldFace(oldRichFace.size());
01483 label nOldFace = 0;
01484
01485 forAll (oldRichFace, pointI)
01486 {
01487 if
01488 (
01489 rpm.found(oldRichFace[pointI])
01490 || slaveMeshPointMap.found(oldRichFace[pointI])
01491 )
01492 {
01493
01494 oldFace[nOldFace] = oldRichFace[pointI];
01495 nOldFace++;
01496 }
01497 else if
01498 (
01499 ref.pointRemoved(oldRichFace[pointI])
01500 || masterMeshPointMap.found(oldRichFace[pointI])
01501 )
01502 {
01503
01504
01505
01506 changed = true;
01507 }
01508 else
01509 {
01510
01511 oldFace[nOldFace] = oldRichFace[pointI];
01512 nOldFace++;
01513 }
01514 }
01515
01516 oldFace.setSize(nOldFace);
01517
01518 DynamicList<label> newFaceLabels(2*oldFace.size());
01519
01520
01521 forAll (oldFace, pointI)
01522 {
01523
01524 label curP = oldFace[pointI];
01525
01526 Map<label>::const_iterator rpmIter = rpm.find(oldFace[pointI]);
01527
01528 if (rpmIter != rpm.end())
01529 {
01530 changed = true;
01531 curP = rpmIter();
01532 }
01533
01534 if (slaveMeshPointMap.found(curP))
01535 {
01536
01537
01538
01539
01540 if (pointMergeMap.found(curP))
01541 {
01542 changed = true;
01543 newFaceLabels.append
01544 (
01545 pointMergeMap.find(curP)()
01546 );
01547 }
01548 else
01549 {
01550 newFaceLabels.append(curP);
01551 }
01552
01553
01554
01555
01556
01557
01558
01559
01560 const label localFirstLabel =
01561 slaveMeshPointMap.find(curP)();
01562
01563 const labelList& curEdges = slavePointEdges[localFirstLabel];
01564
01565 label nextLabel = oldFace.nextLabel(pointI);
01566
01567 Map<label>::const_iterator rpmNextIter =
01568 rpm.find(nextLabel);
01569
01570 if (rpmNextIter != rpm.end())
01571 {
01572 nextLabel = rpmNextIter();
01573 }
01574
01575 Map<label>::const_iterator mmpmIter =
01576 slaveMeshPointMap.find(nextLabel);
01577
01578 if (mmpmIter != slaveMeshPointMap.end())
01579 {
01580
01581
01582 const label localNextLabel = mmpmIter();
01583
01584 forAll (curEdges, curEdgeI)
01585 {
01586 if
01587 (
01588 slaveEdges[curEdges[curEdgeI]].otherVertex
01589 (
01590 localFirstLabel
01591 )
01592 == localNextLabel
01593 )
01594 {
01595
01596
01597
01598 const labelList& curPise = pise[curEdges[curEdgeI]];
01599
01600 if (curPise.size())
01601 {
01602 changed = true;
01603
01604
01605
01606 const point& startPoint =
01607 projectedSlavePoints[localFirstLabel];
01608
01609 vector e =
01610 projectedSlavePoints[localNextLabel]
01611 - startPoint;
01612
01613 e /= magSqr(e);
01614
01615 scalarField edgePointWeights(curPise.size());
01616
01617 forAll (curPise, curPiseI)
01618 {
01619 edgePointWeights[curPiseI] =
01620 (
01621 e
01622 & (
01623 pointMap.find(curPise[curPiseI])()
01624 - startPoint
01625 )
01626 );
01627 }
01628
01629 if (debug)
01630 {
01631 if
01632 (
01633 min(edgePointWeights) < 0
01634 || max(edgePointWeights) > 1
01635 )
01636 {
01637 FatalErrorIn
01638 (
01639 "void slidingInterface::"
01640 "coupleInterface("
01641 "polyTopoChange& ref) const"
01642 ) << "Error in slave stick-out edge "
01643 << "point collection."
01644 << abort(FatalError);
01645 }
01646 }
01647
01648
01649
01650
01651
01652 for
01653 (
01654 label passI = 0;
01655 passI < edgePointWeights.size();
01656 passI++
01657 )
01658 {
01659
01660
01661
01662 label nextPoint = -1;
01663 scalar dist = 2;
01664
01665 forAll (edgePointWeights, wI)
01666 {
01667 if (edgePointWeights[wI] < dist)
01668 {
01669 dist = edgePointWeights[wI];
01670 nextPoint = wI;
01671 }
01672 }
01673
01674
01675
01676
01677 newFaceLabels.append(curPise[nextPoint]);
01678 edgePointWeights[nextPoint] = GREAT;
01679 }
01680 }
01681
01682 break;
01683 }
01684 }
01685 }
01686 }
01687 else
01688 {
01689 newFaceLabels.append(oldFace[pointI]);
01690 }
01691 }
01692
01693 if (changed)
01694 {
01695 if (newFaceLabels.size() < 3)
01696 {
01697 FatalErrorIn
01698 (
01699 "void slidingInterface::coupleInterface("
01700 "polyTopoChange& ref) const"
01701 ) << "Face " << curFaceID << " reduced to less than "
01702 << "3 points. Topological/cutting error B." << nl
01703 << "Old face: " << oldFace << " new face: " << newFaceLabels
01704 << abort(FatalError);
01705 }
01706
01707
01708 label modifiedFaceZone = faceZones.whichZone(curFaceID);
01709 bool modifiedFaceZoneFlip = false;
01710
01711 if (modifiedFaceZone >= 0)
01712 {
01713 modifiedFaceZoneFlip =
01714 faceZones[modifiedFaceZone].flipMap()
01715 [
01716 faceZones[modifiedFaceZone].whichFace(curFaceID)
01717 ];
01718 }
01719
01720 face newFace;
01721 newFace.transfer(newFaceLabels);
01722
01723
01724
01725
01726 if (mesh.isInternalFace(curFaceID))
01727 {
01728 ref.setAction
01729 (
01730 polyModifyFace
01731 (
01732 newFace,
01733 curFaceID,
01734 own[curFaceID],
01735 nei[curFaceID],
01736 false,
01737 -1,
01738 false,
01739 modifiedFaceZone,
01740 modifiedFaceZoneFlip
01741 )
01742 );
01743 }
01744 else
01745 {
01746 ref.setAction
01747 (
01748 polyModifyFace
01749 (
01750 newFace,
01751 curFaceID,
01752 own[curFaceID],
01753 -1,
01754 false,
01755 mesh.boundaryMesh().whichPatch(curFaceID),
01756 false,
01757 modifiedFaceZone,
01758 modifiedFaceZoneFlip
01759 )
01760 );
01761 }
01762 }
01763 }
01764
01765
01766
01767
01768
01769 if (!retiredPointMapPtr_)
01770 {
01771 FatalErrorIn
01772 (
01773 "void slidingInterface::coupleInterface("
01774 "polyTopoChange& ref) const"
01775 ) << "Retired point map pointer not set."
01776 << abort(FatalError);
01777 }
01778
01779 Map<label>& addToRpm = *retiredPointMapPtr_;
01780
01781
01782 addToRpm.clear();
01783
01784 label nRetiredPoints = 0;
01785
01786 forAll (slaveMeshPoints, pointI)
01787 {
01788 if (pointMergeMap.found(slaveMeshPoints[pointI]))
01789 {
01790
01791
01792 nRetiredPoints++;
01793
01794
01795
01796
01797
01798
01799
01800
01801
01802
01803
01804
01805
01806
01807
01808 ref.setAction
01809 (
01810 polyRemovePoint
01811 (
01812 slaveMeshPoints[pointI]
01813 )
01814 );
01815
01816 addToRpm.insert
01817 (
01818 pointMergeMap.find(slaveMeshPoints[pointI])(),
01819 slaveMeshPoints[pointI]
01820 );
01821 }
01822 else
01823 {
01824 ref.setAction
01825 (
01826 polyModifyPoint
01827 (
01828 slaveMeshPoints[pointI],
01829 points[slaveMeshPoints[pointI]],
01830 false,
01831 mesh.pointZones().whichZone(slaveMeshPoints[pointI]),
01832 true
01833 )
01834 );
01835 }
01836 }
01837
01838 if (debug)
01839 {
01840 Pout << "Retired " << nRetiredPoints << " out of "
01841 << slaveMeshPoints.size() << " points." << endl;
01842 }
01843
01844
01845 if (cutFaceMasterPtr_) deleteDemandDrivenData(cutFaceMasterPtr_);
01846 cutFaceMasterPtr_ = new labelList(cutPatch.cutFaceMaster());
01847
01848 if (cutFaceSlavePtr_) deleteDemandDrivenData(cutFaceSlavePtr_);
01849 cutFaceSlavePtr_ = new labelList(cutPatch.cutFaceSlave());
01850
01851
01852 attached_ = true;
01853
01854 if (debug)
01855 {
01856 Pout<< "void slidingInterface::coupleInterface("
01857 << "polyTopoChange& ref) : "
01858 << "Finished coupling sliding interface " << name() << endl;
01859 }
01860 }
01861
01862
01863