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