OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

coupleSlidingInterface.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00045 
00046 const Foam::scalar Foam::slidingInterface::edgeCoPlanarTol_ = 0.8;
00047 
00048 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00049 
00050 // Index of debug signs:
00051 // Index of debug signs:
00052 // . - loop of the edge-to-face interaction detection
00053 // x - reversal of direction in edge-to-face interaction detection
00054 // + - complete edge-to-face interaction detection
00055 // z - incomplete edge-to-face interaction detection.  This may be OK for edges
00056 //     crossing from one to the other side of multiply connected master patch
00057 
00058 // e - adding a point on edge
00059 // f - adding a point on face
00060 // . - collecting edges off another face for edge-to-edge cut
00061 // + - finished collection of edges
00062 // * - cut both master and slave
00063 // n - cutting new edge
00064 // t - intersection exists but it is outside of tolerance
00065 // x - missed slave edge in cut
00066 // - - missed master edge in cut
00067 // u - edge already used in cutting
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     // Collect projection addressing
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     // Create enriched patch
00144     enrichedPatch cutPatch
00145     (
00146         masterPatch,
00147         slavePatch,
00148         slavePointPointHits,
00149         slavePointEdgeHits,
00150         slavePointFaceHits
00151     );
00152 
00153     // Get reference to list of added point for the enriched patch.
00154     // This will be used for point addition
00155     Map<point>& pointMap = cutPatch.pointMap();
00156 
00157     // Get reference to the list of merged points
00158     Map<label>& pointMergeMap = cutPatch.pointMergeMap();
00159 
00160     // Create mapping for every merged point of the slave patch
00161     forAll (slavePointPointHits, pointI)
00162     {
00163         if (slavePointPointHits[pointI] >= 0)
00164         {
00165 // Pout << "Inserting point merge pair: " << slaveMeshPoints[pointI] << " : " << masterMeshPoints[slavePointPointHits[pointI]] << endl;
00166             pointMergeMap.insert
00167             (
00168                 slaveMeshPoints[pointI],
00169                 masterMeshPoints[slavePointPointHits[pointI]]
00170             );
00171         }
00172     }
00173 
00174     // Collect the list of used edges for every slave edge
00175 
00176     List<labelHashSet> usedMasterEdges(slaveEdges.size());
00177 
00178     // Collect of slave point hits
00179     forAll (slavePointPointHits, pointI)
00180     {
00181         // For point hits, add all point-edges from master side to all point
00182         const labelList& curSlaveEdges = slavePointEdges[pointI];
00183 
00184         if (slavePointPointHits[pointI] > -1)
00185         {
00186             const labelList& curMasterEdges =
00187                 masterPointEdges[slavePointPointHits[pointI]];
00188 
00189             // Mark all current master edges as used for all the current slave
00190             // edges
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             // For edge hits, add the master edge
00204             forAll (curSlaveEdges, slaveEdgeI)
00205             {
00206                 usedMasterEdges[curSlaveEdges[slaveEdgeI]].insert
00207                 (
00208                     slavePointEdgeHits[pointI]
00209                 );
00210             }
00211         }
00212     }
00213 
00214     // Collect off master point hits
00215     // For every master point that has hit an edge, add all edges coming from
00216     // that point to the slave edge that has been hit
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 //     Pout << "used edges: " << endl;
00234 //     forAll (usedMasterEdges, edgeI)
00235 //     {
00236 //         Pout << "edge: " << edgeI << " used: " << usedMasterEdges[edgeI].toc() << endl;
00237 //     }
00238 
00239     // For every master and slave edge make a list of points to be added into
00240     // that edge.
00241     List<DynamicList<label> > pointsIntoMasterEdges(masterEdges.size());
00242     List<DynamicList<label> > pointsIntoSlaveEdges(slaveEdges.size());
00243 
00244     // Add all points from the slave patch that have hit the edge
00245     forAll (slavePointEdgeHits, pointI)
00246     {
00247         if (slavePointEdgeHits[pointI] > -1)
00248         {
00249             // Create a new point on the master edge
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,             // point
00263                         slaveMeshPoints[pointI],  // master point
00264                         cutPointZoneID_.index(),  // zone for point
00265                         true                      // supports a cell
00266                     )
00267                 );
00268 //             Pout << "Inserting merge pair off edge: " << slaveMeshPoints[pointI] << " " << newPoint << " cut point: " << edgeCutPoint << " orig: " << slaveLocalPoints[pointI] << " proj: " << projectedSlavePoints[pointI] << endl;
00269             // Add the new edge point into the merge map
00270             pointMergeMap.insert(slaveMeshPoints[pointI], newPoint);
00271 
00272             pointsIntoMasterEdges[slavePointEdgeHits[pointI]].append
00273             (
00274                 newPoint
00275             );
00276 
00277             // Add the point into the enriched patch map
00278             pointMap.insert
00279             (
00280                 newPoint,
00281                 edgeCutPoint
00282             );
00283 
00284             if (debug)
00285             {
00286                 Pout<< "e";
00287 //                 Pout<< newPoint << " = " << edgeCutPoint << endl;
00288             }
00289         }
00290     }
00291 
00292     if (debug)
00293     {
00294         Pout<< endl;
00295     }
00296 
00297     // Add all points from the slave patch that have hit a face
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],   // point
00313                         slaveMeshPoints[pointI],        // master point
00314                         cutPointZoneID_.index(),        // zone for point
00315                         true                            // supports a cell
00316                     )
00317                 );
00318 //             Pout << "Inserting merge pair off face: " << slaveMeshPoints[pointI] << " " << newPoint << endl;
00319             // Add the new edge point into the merge map
00320             pointMergeMap.insert(slaveMeshPoints[pointI], newPoint);
00321 
00322             // Add the point into the enriched patch map
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     // Cut all slave edges.
00349     // Collect all master edges the slave edge interacts with.  Skip
00350     // all the edges already marked as used.  For every unused edge,
00351     // calculate the cut and insert the new point into the master and
00352     // slave edge.
00353     // For the edge selection algorithm, see, comment in
00354     // slidingInterfaceProjectPoints.C.
00355     // Edge cutting algoritm:
00356     // As the master patch defines the cutting surface, the newly
00357     // inserted point needs to be on the master edge.  Also, in 3-D
00358     // the pair of edges generally misses each other rather than
00359     // intersect.  Therefore, the intersection is calculated using the
00360     // plane the slave edge defines during projection.  The plane is
00361     // defined by the centrepoint of the edge in the original
00362     // configuration and the projected end points.  In case of flat
00363     // geometries (when the three points are colinear), the plane is
00364     // defined by the two projected end-points and the slave edge
00365     // normal used as the in-plane vector.  When the intersection
00366     // point is created, it is added as a new point for both the
00367     // master and the slave edge.
00368     // In order to be able to re-create the points on edges in mesh
00369     // motion without the topology change, the edge pair used to
00370     // create the cut point needs to be recorded in
00371     // cutPointEdgePairMap
00372 
00373     // Note.  "Processing slave edges" code is repeated twice in the
00374     // sliding intergace coupling in order to allow the point
00375     // projection to be done separately from the actual cutting.
00376     // Please change consistently with slidingInterfaceProjectPoints.C
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     // Clear the old map
00396     addToCpepm.clear();
00397 
00398     // Create a map of faces the edge can interact with
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 //             Pout<< "Doing edge " << edgeI << " curEdge: " << curEdge << " curUme: " << curUme << endl;
00418             // Clear the maps
00419             curFaceMap.clear();
00420             addedFaces.clear();
00421 
00422             // Grab the faces for start and end points.
00423             const label startFace =
00424                 slavePointFaceHits[curEdge.start()].hitObject();
00425             const label endFace = slavePointFaceHits[curEdge.end()].hitObject();
00426 //             Pout << "startFace: " << slavePointFaceHits[curEdge.start()] << " endFace: " << slavePointFaceHits[curEdge.end()] << endl;
00427             // Insert the start face into the list
00428             curFaceMap.insert(startFace);
00429             addedFaces.insert(startFace);
00430 //             Pout << "curFaceMap: " << curFaceMap.toc() << endl;
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                 // Add all face neighbours of face in the map
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                 // It is impossible to reach the end from the start, probably
00477                 // due to disconnected domain.  Do search in opposite direction
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                     // Add all face neighbours of face in the map
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             // Collect the edges
00536 
00537             // Create a map of edges the edge can interact with
00538             labelHashSet curMasterEdgesMap
00539             (
00540                 nFacesPerSlaveEdge_*primitiveMesh::edgesPerFace_
00541             );
00542 
00543             const labelList curFaces = curFaceMap.toc();
00544 //             Pout << "curFaces: " << curFaces << endl;
00545             forAll (curFaces, faceI)
00546             {
00547 //                 Pout<< "face: " << curFaces[faceI] << " "
00548 //                     << masterPatch[curFaces[faceI]]
00549 //                     << " local: "
00550 //                     << masterPatch.localFaces()[curFaces[faceI]]
00551 //                     << endl;
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             // For all master edges to intersect, skip the ones
00563             // already used and cut the rest with a cutting plane.  If
00564             // the intersection point, falls inside of both edges, it
00565             // is valid.
00566 
00567             // Note.
00568             // The edge cutting code is repeated in
00569             // slidingInterface::modifyMotionPoints.  This is done for
00570             // efficiency reasons and avoids multiple creation of cutting
00571             // planes.  Please update both simultaneously.
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()] // Add start normal
00581                   + slaveLocalPoints[curEdge.end()]
00582                   + slavePointNormals[curEdge.end()] // Add end normal
00583                 );
00584 
00585             // Create the plane
00586             plane cutPlane(a, b, c);
00587 //             Pout << "a: " << a << " b: " << b << " c: " << c << " plane: " << cutPlane << endl;
00588 
00589             linePointRef curSlaveLine = curEdge.line(projectedSlavePoints);
00590             const scalar curSlaveLineMag = curSlaveLine.mag();
00591 //             Pout << "curSlaveLine: " << curSlaveLine << endl;
00592             forAll (curMasterEdges, masterEdgeI)
00593             {
00594                 if (!curUme.found(curMasterEdges[masterEdgeI]))
00595                 {
00596                     // New edge
00597                     if (debug)
00598                     {
00599                         Pout << "n";
00600                     }
00601 
00602                     const label cmeIndex = curMasterEdges[masterEdgeI];
00603                     const edge& cme = masterEdges[cmeIndex];
00604 //                     Pout<< "Edge " << cmeIndex << " cme: " << cme << " line: " << cme.line(masterLocalPoints) << endl;
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                         // Master is cut, check the slave
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                             // Strict checking of slave cut to avoid capturing
00628                             // end points.
00629                             scalar cutOnSlave =
00630                                 (
00631                                     (
00632                                         slaveCut.hitPoint()
00633                                       - curSlaveLine.start()
00634                                     ) & curSlaveLine.vec()
00635                                 )/sqr(curSlaveLineMag);
00636 
00637                             // Calculate merge tolerance from the
00638                             // target edge length
00639                             scalar mergeTol =
00640                                 edgeCoPlanarTol_*mag(b - a);
00641 //                             Pout << "cutOnMaster: " << cutOnMaster << " masterCutPoint: " << masterCutPoint << " slaveCutPoint: " << slaveCut.hitPoint() << " slaveCut.distance(): " << slaveCut.distance() << " slave length: " << mag(b - a) << " mergeTol: " << mergeTol << " 1: " << mag(b - a) << " 2: " << cme.line(masterLocalPoints).mag() << endl;
00642                             if
00643                             (
00644                                 cutOnSlave > edgeEndCutoffTol_
00645                              && cutOnSlave < 1.0 - edgeEndCutoffTol_
00646                              && slaveCut.distance() < mergeTol
00647                             )
00648                             {
00649                                 // Cut both master and slave.  Add point
00650                                 // to edge points The point is nominally
00651                                 // added from the start of the master edge
00652                                 // and added to the cut point zone
00653                                 label newPoint =
00654                                     ref.setAction
00655                                     (
00656                                         polyAddPoint
00657                                         (
00658                                             masterCutPoint,           // point
00659                                             masterMeshPoints[cme.start()],// m p
00660                                             cutPointZoneID_.index(),  // zone
00661                                             true                      // active
00662                                         )
00663                                     );
00664 //                                 Pout << "Inserting point: " << newPoint << " as edge to edge intersection.  Slave edge: " << edgeI << " " << curEdge << " master edge: " << cmeIndex << " " << cme << endl;
00665                                 pointsIntoSlaveEdges[edgeI].append(newPoint);
00666                                 pointsIntoMasterEdges[cmeIndex].append(newPoint);
00667 
00668                                 // Add the point into the enriched patch map
00669                                 pointMap.insert
00670                                 (
00671                                     newPoint,
00672                                     masterCutPoint
00673                                 );
00674 
00675                                 // Record which two edges intersect to
00676                                 // create cut point
00677                                 addToCpepm.insert
00678                                 (
00679                                     newPoint,    // Cut point index
00680                                     Pair<edge>
00681                                     (
00682                                         edge
00683                                         (
00684                                             masterMeshPoints[cme.start()],
00685                                             masterMeshPoints[cme.end()]
00686                                         ),    // Master edge
00687                                         edge
00688                                         (
00689                                             slaveMeshPoints[curEdge.start()],
00690                                             slaveMeshPoints[curEdge.end()]
00691                                         )// Slave edge
00692                                     )
00693                                 );
00694 
00695                                 if (debug)
00696                                 {
00697                                     Pout<< " " << newPoint << " = "
00698                                         << masterCutPoint << " ";
00699                                 }
00700                             }
00701                             else
00702                             {
00703                                 if (debug)
00704                                 {
00705                                     // Intersection exists but it is too far
00706                                     Pout << "t";
00707                                 }
00708                             }
00709                         }
00710                         else
00711                         {
00712                             if (debug)
00713                             {
00714                                 // Missed slave edge
00715                                 Pout << "x";
00716                             }
00717                         }
00718                     }
00719                     else
00720                     {
00721                         if (debug)
00722                         {
00723                             // Missed master edge
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         } // End if both ends missing
00742     } // End for all slave edges
00743 
00744 //     Pout << "pointsIntoMasterEdges: " << pointsIntoMasterEdges << endl;
00745 //     Pout << "pointsIntoSlaveEdges: " << pointsIntoSlaveEdges << endl;
00746 
00747     // Re-pack the points into edges lists
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     // Prepare the enriched faces
00763     cutPatch.calcEnrichedFaces
00764     (
00765         pime,
00766         pise,
00767         projectedSlavePoints
00768     );
00769 
00770     // Demand driven calculate the cut faces. Apart from the
00771     // cutFaces/cutFaceMaster/cutFaceSlave no information from the cutPatch
00772     // is used anymore!
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     // Couple the interface
00781 
00782     // Algorithm:
00783     // 1) Go through the cut faces and check if the cut face is the same as the
00784     //    defining master or slave.  If so, modify the appropriate
00785     //    face and mark the other for relegation into the face zone.
00786     // 2) If different, mark both sides for relegation and insert the new face
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 //         Pout << "Doing insertion of face " << faceI << ": ";
00799 
00800         // Check if the face has changed topologically
00801         bool insertedFace = false;
00802 
00803         if (curMaster >= 0)
00804         {
00805             // Face has got a master
00806             if (curCutFace == masterPatch[curMaster])
00807             {
00808                 // Face is equal to master.  Modify master face.
00809 //                 Pout << "Face is equal to master and is ";
00810 
00811                 // If the face has got both master and slave, it is an
00812                 // internal face; otherwise it is a patch face in the
00813                 // master patch.  Keep it in the master face zone.
00814 
00815                 if (curSlave >= 0)
00816                 {
00817 //                     Pout << "internal" << endl;
00818                     if (masterFc[curMaster] < slaveFc[curSlave])
00819                     {
00820                         // Cut face should point into slave.
00821                         // Be careful about flips in zone!
00822                         ref.setAction
00823                         (
00824                             polyModifyFace
00825                             (
00826                                 curCutFace,                  // new face
00827                                 masterPatchAddr[curMaster],  // master face id
00828                                 masterFc[curMaster],         // owner
00829                                 slaveFc[curSlave],           // neighbour
00830                                 false,                       // flux flip
00831                                 -1,                          // patch ID
00832                                 false,                       // remove from zone
00833                                 masterFaceZoneID_.index(),   // zone ID
00834                                 masterPatchFlip[curMaster]   // zone flip
00835                             )
00836                         );
00837 //                         Pout << "modifying master face. Old master: " << masterPatch[curMaster] << " new face: " << curCutFace.reverseFace() << " own: " << masterFc[curMaster] << " nei: " << slaveFc[curSlave] << endl;
00838                     }
00839                     else
00840                     {
00841                         // Cut face should point into master.  Flip required.
00842                         // Be careful about flips in zone!
00843                         ref.setAction
00844                         (
00845                             polyModifyFace
00846                             (
00847                                 curCutFace.reverseFace(),    // new face
00848                                 masterPatchAddr[curMaster],  // master face id
00849                                 slaveFc[curSlave],           // owner
00850                                 masterFc[curMaster],         // neighbour
00851                                 true,                        // flux flip
00852                                 -1,                          // patch ID
00853                                 false,                       // remove from zone
00854                                 masterFaceZoneID_.index(),   // zone ID
00855                                 !masterPatchFlip[curMaster]  // zone flip
00856                             )
00857                         );
00858                     }
00859 
00860                     // Orphan the slave
00861                     orphanedSlave[curSlave] = true;
00862                 }
00863                 else
00864                 {
00865 //                     Pout << "master boundary" << endl;
00866                     ref.setAction
00867                     (
00868                         polyModifyFace
00869                         (
00870                             curCutFace,                  // new face
00871                             masterPatchAddr[curMaster],  // master face index
00872                             masterFc[curMaster],         // owner
00873                             -1,                          // neighbour
00874                             false,                       // flux flip
00875                             masterPatchID_.index(),      // patch ID
00876                             false,                       // remove from zone
00877                             masterFaceZoneID_.index(),   // zone ID
00878                             masterPatchFlip[curMaster]   // zone flip
00879                         )
00880                     );
00881                 }
00882 
00883                 insertedFace = true;
00884             }
00885         }
00886         else if (curSlave >= 0)
00887         {
00888             // Face has got a slave
00889 
00890             // Renumber the slave face into merged labels
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                 // Face is equal to slave.  Modify slave face.
00906 //                 Pout << "Face is equal to slave and is ";
00907 
00908                 if (curMaster >= 0)
00909                 {
00910 //                     Pout << "regular internal" << endl;
00911                     if (masterFc[curMaster] < slaveFc[curSlave])
00912                     {
00913                         ref.setAction
00914                         (
00915                             polyModifyFace
00916                             (
00917                                 curCutFace,                  // new face
00918                                 slavePatchAddr[curSlave],    // master face id
00919                                 masterFc[curMaster],         // owner
00920                                 slaveFc[curSlave],           // neighbour
00921                                 true,                        // flux flip
00922                                 -1,                          // patch ID
00923                                 false,                       // remove from zone
00924                                 slaveFaceZoneID_.index(),    // zone ID
00925                                 !slavePatchFlip[curMaster]   // zone flip
00926                             )
00927                         );
00928                     }
00929                     else
00930                     {
00931                         // Cut face should point into master.
00932                         // Be careful about flips in zone!
00933 //                         Pout << "flipped internal" << endl;
00934                         ref.setAction
00935                         (
00936                             polyModifyFace
00937                             (
00938                                 curCutFace.reverseFace(),    // new face
00939                                 slavePatchAddr[curSlave],    // master face id
00940                                 slaveFc[curSlave],           // owner
00941                                 masterFc[curMaster],         // neighbour
00942                                 false,                       // flux flip
00943                                 -1,                          // patch ID
00944                                 false,                       // remove from zone
00945                                 slaveFaceZoneID_.index(),    // zone ID
00946                                 slavePatchFlip[curSlave]     // zone flip
00947                             )
00948                         );
00949                     }
00950 
00951                     // Orphan the master
00952                     orphanedMaster[curMaster] = true;
00953                 }
00954                 else
00955                 {
00956 //                     Pout << "slave boundary" << endl;
00957                     ref.setAction
00958                     (
00959                         polyModifyFace
00960                         (
00961                             curCutFace,                  // new face
00962                             slavePatchAddr[curSlave],    // master face index
00963                             slaveFc[curSlave],           // owner
00964                             -1,                          // neighbour
00965                             false,                       // flux flip
00966                             slavePatchID_.index(),       // patch ID
00967                             false,                       // remove from zone
00968                             slaveFaceZoneID_.index(),    // zone ID
00969                             slavePatchFlip[curSlave]     // zone flip
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             // Face is different from both master and slave
00991 //             Pout << "Face different from both master and slave" << endl;
00992 
00993             if (curMaster >= 0)
00994             {
00995                 if (curSlave >= 0)
00996                 {
00997                     // Add internal face
00998                     if (masterFc[curMaster] < slaveFc[curSlave])
00999                     {
01000 //                         Pout << "Adding internal face " << curCutFace << " owner: " << masterFc[curMaster] << " slave: " << slaveFc[curSlave] << " master face: " << masterPatchAddr[curMaster] << endl;
01001                         // Cut face should point into slave.
01002                         ref.setAction
01003                         (
01004                             polyAddFace
01005                             (
01006                                 curCutFace,                  // new face
01007                                 masterFc[curMaster],         // owner
01008                                 slaveFc[curSlave],           // neighbour
01009                                 -1,                          // master point
01010                                 -1,                          // master edge
01011                                 masterPatchAddr[curMaster],  // master face id
01012                                 false,                       // flux flip
01013                                 -1,                          // patch ID
01014                                 cutFaceZoneID_.index(),      // zone ID
01015                                 false                        // zone flip
01016                             )
01017                         );
01018                     }
01019                     else
01020                     {
01021                         // Cut face should point into master.  Flip required.
01022                         ref.setAction
01023                         (
01024                             polyAddFace
01025                             (
01026                                 curCutFace.reverseFace(),    // new face
01027                                 slaveFc[curSlave],           // owner
01028                                 masterFc[curMaster],         // neighbour
01029                                 -1,                          // master point
01030                                 -1,                          // master edge
01031                                 masterPatchAddr[curMaster],  // master face id
01032                                 true,                        // flux flip
01033                                 -1,                          // patch ID
01034                                 cutFaceZoneID_.index(),      // zone ID
01035                                 true                         // zone flip
01036                             )
01037                         );
01038                     }
01039 
01040                     // Orphan slave
01041                     orphanedSlave[curSlave] = true;
01042                 }
01043                 else
01044                 {
01045 //                 Pout << "Adding solo master face " << curCutFace << " owner: " << masterFc[curMaster] << " master face: " << masterPatchAddr[curMaster] << endl;
01046                     // Add master patch face
01047                     ref.setAction
01048                     (
01049                         polyAddFace
01050                         (
01051                             curCutFace,                  // new face
01052                             masterFc[curMaster],         // owner
01053                             -1,                          // neighbour
01054                             -1,                          // master point
01055                             -1,                          // master edge
01056                             masterPatchAddr[curMaster],  // master face index
01057                             false,                       // flux flip
01058                             masterPatchID_.index(),      // patch ID
01059                             cutFaceZoneID_.index(),      // zone ID
01060                             false                        // zone flip
01061                         )
01062                     );
01063                 }
01064 
01065                 // Orphan master
01066                 orphanedMaster[curMaster] = true;
01067             }
01068             else if (curSlave >= 0)
01069             {
01070 //                 Pout << "Adding solo slave face " << curCutFace << " owner: " << slaveFc[curSlave] << " master face: " << slavePatchAddr[curSlave] << endl;
01071                 // Add slave patch face
01072                 ref.setAction
01073                 (
01074                     polyAddFace
01075                     (
01076                         curCutFace,                  // new face
01077                         slaveFc[curSlave],           // owner
01078                         -1,                          // neighbour
01079                         -1,                          // master point
01080                         -1,                          // master edge
01081                         slavePatchAddr[curSlave],    // master face index
01082                         false,                       // flux flip
01083                         slavePatchID_.index(),       // patch ID
01084                         cutFaceZoneID_.index(),      // zone ID
01085                         false                        // zone flip
01086                     )
01087                 );
01088 
01089                 // Orphan slave
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     // Move the orphaned faces into the face zone
01106 //     Pout << "Orphaned master faces: " << orphanedMaster << endl;
01107 //     Pout << "Orphaned slave faces: " << orphanedSlave << endl;
01108 
01109     label nOrphanedMasters = 0;
01110 
01111     forAll (orphanedMaster, faceI)
01112     {
01113         if (orphanedMaster[faceI])
01114         {
01115             nOrphanedMasters++;
01116 
01118             //ref.setAction
01119             //(
01120             //    polyModifyFace
01121             //    (
01122             //        masterPatch[faceI],                 // new face
01123             //        masterPatchAddr[faceI],             // master face index
01124             //        -1,                                 // owner
01125             //        -1,                                 // neighbour
01126             //        false,                              // flux flip
01127             //        -1,                                 // patch ID
01128             //        false,                              // remove from zone
01129             //        masterFaceZoneID_.index(),          // zone ID
01130             //        false                               // zone flip
01131             //    )
01132             //);
01133 
01134             //Pout<< "**MJ:deleting master face " << masterPatchAddr[faceI]
01135             //    << " old verts:" << masterPatch[faceI] << endl;
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             //ref.setAction
01150             //(
01151             //    polyModifyFace
01152             //    (
01153             //        slavePatch[faceI],                // new face
01154             //        slavePatchAddr[faceI],            // slave face index
01155             //        -1,                               // owner
01156             //        -1,                               // neighbour
01157             //        false,                            // flux flip
01158             //        -1,                               // patch ID
01159             //        false,                            // remove from zone
01160             //        slaveFaceZoneID_.index(),         // zone ID
01161             //        false                             // zone flip
01162             //    )
01163             //);
01164 
01165             //Pout<< "**MJ:deleting slave face " << slavePatchAddr[faceI]
01166             //    << " old verts:" << slavePatch[faceI] << endl;
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     // Finished coupling the plane of sliding interface.
01181 
01182     // Modify faces influenced by the sliding interface
01183     // These are the faces belonging to the master and slave cell
01184     // layer which have not already been modified.
01185     // Modification comes in three types:
01186     // 1) eliminate the points that have been removed when the old sliding
01187     //    interface has been removed
01188     // 2) Merge the slave points that have hit points on the master patch
01189     // 3) Introduce new points resulting from the new sliding interface cut
01190 
01191     // Collect all affected faces
01192 
01193     // Master side
01194 
01195     // Grab the list of faces in the layer
01196     const labelList& masterStickOuts = masterStickOutFaces();
01197 
01198 //     Pout << "masterStickOuts: " << masterStickOuts << endl;
01199 
01200     // Re-create the master stick-out faces
01201     forAll (masterStickOuts, faceI)
01202     {
01203         // Renumber the face and remove additional points
01204 
01205         const label curFaceID = masterStickOuts[faceI];
01206 
01207         const face& oldRichFace = faces[curFaceID];
01208 
01209         bool changed = false;
01210 
01211         // Remove removed points from the face
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                 // Point off patch
01224                 oldFace[nOldFace] = oldRichFace[pointI];
01225                 nOldFace++;
01226             }
01227         }
01228 
01229         oldFace.setSize(nOldFace);
01230 
01231 //         Pout << "old rich master face: " << oldRichFace << " old face: " << oldFace << endl;
01232         DynamicList<label> newFaceLabels(2*oldFace.size());
01233 
01234         forAll (oldFace, pointI)
01235         {
01236             if (masterMeshPointMap.found(oldFace[pointI]))
01237             {
01238                 // Point is in master patch. Add it
01239 
01240                 // If the point is a direct hit, grab its label; otherwise
01241                 // keep the original
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                 // Find if there are additional points inserted onto the edge
01256                 // between current point and the next point
01257                 // Algorithm:
01258                 // 1) Find all the edges in the master patch coming
01259                 //    out of the current point.
01260                 // 2) If the next point in the face to pick the right edge
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 //                     Pout << "found label pair " << oldFace[pointI] << " and " << nextLabel;
01274                     // Find the points on the edge between them
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 //                             Pout << " found edge: " << curEdges[curEdgeI] << endl;
01289 
01290                             // Get points on current edge
01291                             const labelList& curPime = pime[curEdges[curEdgeI]];
01292 
01293                             if (curPime.size())
01294                             {
01295                                 changed = true;
01296                                 // Pout << "curPime: " << curPime << endl;
01297                                 // Insert the edge points into the face
01298                                 // in the correct order
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                                 // Go through the points and collect
01342                                 // them based on weights from lower to
01343                                 // higher.  This gives the correct
01344                                 // order of points along the edge.
01345                                 for
01346                                 (
01347                                     label passI = 0;
01348                                     passI < edgePointWeights.size();
01349                                     passI++
01350                                 )
01351                                 {
01352                                     // Max weight can only be one, so
01353                                     // the sorting is done by
01354                                     // elimination.
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                                     // Insert the next point and reset
01368                                     // its weight to exclude it from
01369                                     // future picks
01370                                     newFaceLabels.append(curPime[nextPoint]);
01371                                     edgePointWeights[nextPoint] = GREAT;
01372                                 }
01373                             }
01374 
01375                             break;
01376                         } // End of found edge
01377                     } // End of looking through current edges
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             // Get face zone and its flip
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             //Pout << "Modifying master stick-out face " << curFaceID
01417             //    << " old face: " << oldFace << " new face: " << newFace << endl;
01418 
01419             // Modify the face
01420             if (mesh.isInternalFace(curFaceID))
01421             {
01422                 ref.setAction
01423                 (
01424                     polyModifyFace
01425                     (
01426                         newFace,                // modified face
01427                         curFaceID,              // label of face being modified
01428                         own[curFaceID],         // owner
01429                         nei[curFaceID],         // neighbour
01430                         false,                  // face flip
01431                         -1,                     // patch for face
01432                         false,                  // remove from zone
01433                         modifiedFaceZone,       // zone for face
01434                         modifiedFaceZoneFlip    // face flip in zone
01435                     )
01436                 );
01437             }
01438             else
01439             {
01440                 ref.setAction
01441                 (
01442                     polyModifyFace
01443                     (
01444                         newFace,                // modified face
01445                         curFaceID,              // label of face being modified
01446                         own[curFaceID],         // owner
01447                         -1,                     // neighbour
01448                         false,                  // face flip
01449                         mesh.boundaryMesh().whichPatch(curFaceID), // patch for face
01450                         false,                  // remove from zone
01451                         modifiedFaceZone,       // zone for face
01452                         modifiedFaceZoneFlip    // face flip in zone
01453                     )
01454                 );
01455             }
01456         }
01457     }
01458 
01459 //     Pout << "Finished master side" << endl;
01460 
01461     // Slave side
01462 
01463     // Grab the list of faces in the layer
01464     const labelList& slaveStickOuts = slaveStickOutFaces();
01465 
01466 //     Pout << "slaveStickOuts: " << slaveStickOuts << endl;
01467 
01468     const Map<label>& rpm = retiredPointMap();
01469 
01470     // Re-create the slave stick-out faces
01471 
01472     forAll (slaveStickOuts, faceI)
01473     {
01474         // Renumber the face and remove additional points
01475         const label curFaceID = slaveStickOuts[faceI];
01476 
01477         const face& oldRichFace = faces[curFaceID];
01478 
01479         bool changed = false;
01480 
01481         // Remove removed points from the face
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                 // Point definitely live. Add it
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                 // Point removed and not on slave patch
01504                 // (first if takes care of that!) or
01505                 // point belonging to master patch
01506                 changed = true;
01507             }
01508             else
01509             {
01510                 // Point off patch
01511                 oldFace[nOldFace] = oldRichFace[pointI];
01512                 nOldFace++;
01513             }
01514         }
01515 
01516         oldFace.setSize(nOldFace);
01517 
01518         DynamicList<label> newFaceLabels(2*oldFace.size());
01519 
01520 //         Pout << "old rich slave face: " << oldRichFace << " old face: " << oldFace << endl;
01521         forAll (oldFace, pointI)
01522         {
01523             // Try to find the point in retired points
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                 // Point is in slave patch. Add it
01537 
01538                 // If the point is a direct hit, grab its label; otherwise
01539                 // keep the original
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                 // Find if there are additional points inserted onto the edge
01554                 // between current point and the next point
01555                 // Algorithm:
01556                 // 1) Find all the edges in the slave patch coming
01557                 //    out of the current point.
01558                 // 2) Use the next point in the face to pick the right edge
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                     // Both points on the slave patch.
01581                     // Find the points on the edge between them
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 //                             Pout << " found edge: " << curEdges[curEdgeI] << endl;
01596 
01597                             // Get points on current edge
01598                             const labelList& curPise = pise[curEdges[curEdgeI]];
01599 
01600                             if (curPise.size())
01601                             {
01602                                 changed = true;
01603 //                                 Pout << "curPise: " << curPise << endl;
01604                                 // Insert the edge points into the face
01605                                 // in the correct order
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                                 // Go through the points and collect
01649                                 // them based on weights from lower to
01650                                 // higher.  This gives the correct
01651                                 // order of points along the edge.
01652                                 for
01653                                 (
01654                                     label passI = 0;
01655                                     passI < edgePointWeights.size();
01656                                     passI++
01657                                 )
01658                                 {
01659                                     // Max weight can only be one, so
01660                                     // the sorting is done by
01661                                     // elimination.
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                                     // Insert the next point and reset
01675                                     // its weight to exclude it from
01676                                     // future picks
01677                                     newFaceLabels.append(curPise[nextPoint]);
01678                                     edgePointWeights[nextPoint] = GREAT;
01679                                 }
01680                             }
01681 
01682                             break;
01683                         }
01684                     } // End of found edge
01685                 } // End of looking through current edges
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             // Get face zone and its flip
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 //             Pout << "Modifying slave stick-out face " << curFaceID << " old face: " << oldFace << " new face: " << newFace << endl;
01724 
01725             // Modify the face
01726             if (mesh.isInternalFace(curFaceID))
01727             {
01728                 ref.setAction
01729                 (
01730                     polyModifyFace
01731                     (
01732                         newFace,                // modified face
01733                         curFaceID,              // label of face being modified
01734                         own[curFaceID],         // owner
01735                         nei[curFaceID],         // neighbour
01736                         false,                  // face flip
01737                         -1,                     // patch for face
01738                         false,                  // remove from zone
01739                         modifiedFaceZone,       // zone for face
01740                         modifiedFaceZoneFlip    // face flip in zone
01741                     )
01742                 );
01743             }
01744             else
01745             {
01746                 ref.setAction
01747                 (
01748                     polyModifyFace
01749                     (
01750                         newFace,                // modified face
01751                         curFaceID,              // label of face being modified
01752                         own[curFaceID],         // owner
01753                         -1,                     // neighbour
01754                         false,                  // face flip
01755                         mesh.boundaryMesh().whichPatch(curFaceID), // patch for face
01756                         false,                  // remove from zone
01757                         modifiedFaceZone,       // zone for face
01758                         modifiedFaceZoneFlip    // face flip in zone
01759                     )
01760                 );
01761             }
01762         }
01763     }
01764 
01765     // Activate and retire slave patch points
01766     // This needs to be done last, so that the map of removed points
01767     // does not get damaged by point modifications
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     // Clear the old map
01782     addToRpm.clear();
01783 
01784     label nRetiredPoints = 0;
01785 
01786     forAll (slaveMeshPoints, pointI)
01787     {
01788         if (pointMergeMap.found(slaveMeshPoints[pointI]))
01789         {
01790             // Retire the point - only used for supporting the detached
01791             // slave patch
01792             nRetiredPoints++;
01793 
01794             //ref.setAction
01795             //(
01796             //    polyModifyPoint
01797             //    (
01798             //        slaveMeshPoints[pointI],             // point ID
01799             //        points[slaveMeshPoints[pointI]],     // point
01800             //        false,                               // remove from zone
01801             //        mesh.pointZones().whichZone(slaveMeshPoints[pointI]),// zone
01802             //        false                                // in a cell
01803             //    )
01804             //);
01805             //Pout<< "MJ retire slave point " << slaveMeshPoints[pointI]
01806             //    << " coord " << points[slaveMeshPoints[pointI]]
01807             //    << endl;
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],             // point ID
01829                     points[slaveMeshPoints[pointI]],     // point
01830                     false,                               // remove from zone
01831                     mesh.pointZones().whichZone(slaveMeshPoints[pointI]),// zone
01832                     true                                 // in a cell
01833                 )
01834             );
01835         }
01836     }
01837 
01838     if (debug)
01839     {
01840         Pout << "Retired " << nRetiredPoints << " out of "
01841             << slaveMeshPoints.size() << " points." << endl;
01842     }
01843 
01844     // Grab cut face master and slave addressing
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     // Finished coupling
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 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd