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

decoupleSlidingInterface.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 "polyMesh.H"
00029 #include "primitiveMesh.H"
00030 #include "polyTopoChange.H"
00031 #include "polyTopoChanger.H"
00032 #include "polyModifyFace.H"
00033 #include "polyModifyPoint.H"
00034 
00035 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00036 
00037 void Foam::slidingInterface::decoupleInterface
00038 (
00039     polyTopoChange& ref
00040 ) const
00041 {
00042     if (debug)
00043     {
00044         Pout<< "void slidingInterface::decoupleInterface("
00045             << "polyTopoChange& ref) const : "
00046             << "Decoupling sliding interface " << name() << endl;
00047     }
00048 
00049     if (!attached_)
00050     {
00051         if (debug)
00052         {
00053             Pout<< "void slidingInterface::decoupleInterface("
00054                 << "polyTopoChange& ref) const : "
00055                 << "Interface already decoupled." << endl;
00056         }
00057 
00058         return;
00059     }
00060 
00061     // Clear previous couple
00062     clearCouple(ref);
00063 
00064     const polyMesh& mesh = topoChanger().mesh();
00065     const faceList& faces = mesh.faces();
00066     const cellList& cells = mesh.cells();
00067 
00068     const labelList& own = mesh.faceOwner();
00069     const labelList& nei = mesh.faceNeighbour();
00070 
00071     // Master side
00072 
00073     const primitiveFacePatch& masterPatch =
00074         mesh.faceZones()[masterFaceZoneID_.index()]();
00075 
00076     const labelList& masterPatchAddr =
00077         mesh.faceZones()[masterFaceZoneID_.index()];
00078 
00079     const boolList& masterPatchFlip =
00080         mesh.faceZones()[masterFaceZoneID_.index()].flipMap();
00081 
00082     const labelList& masterFc = masterFaceCells();
00083 
00084     // Recover faces in master patch
00085 
00086     forAll (masterPatchAddr, faceI)
00087     {
00088         // Make a copy of the face and turn it if necessary
00089         face newFace = faces[masterPatchAddr[faceI]];
00090 
00091         if (masterPatchFlip[faceI])
00092         {
00093             newFace = newFace.reverseFace();
00094         }
00095 
00096         ref.setAction
00097         (
00098             polyModifyFace
00099             (
00100                 newFace,                         // new face
00101                 masterPatchAddr[faceI],          // master face index
00102                 masterFc[faceI],                 // owner
00103                 -1,                              // neighbour
00104                 false,                           // flux flip
00105                 masterPatchID_.index(),          // patch ID
00106                 false,                           // remove from zone
00107                 masterFaceZoneID_.index(),       // zone ID
00108                 false                            // zone flip.  Face corrected
00109             )
00110         );
00111 //         Pout << "Modifying master patch face no " << masterPatchAddr[faceI] << " face: " << faces[masterPatchAddr[faceI]] << " old owner: " << own[masterPatchAddr[faceI]] << " new owner: " << masterFc[faceI] << endl;
00112     }
00113 
00114     // Slave side
00115 
00116     const primitiveFacePatch& slavePatch =
00117         mesh.faceZones()[slaveFaceZoneID_.index()]();
00118 
00119     const labelList& slavePatchAddr =
00120         mesh.faceZones()[slaveFaceZoneID_.index()];
00121 
00122     const boolList& slavePatchFlip =
00123         mesh.faceZones()[slaveFaceZoneID_.index()].flipMap();
00124 
00125     const labelList& slaveFc = slaveFaceCells();
00126 
00127     // Grab retired point mapping
00128     const Map<label>& rpm = retiredPointMap();
00129 
00130     // Recover faces in slave patch
00131 
00132     forAll (slavePatchAddr, faceI)
00133     {
00134         // Make a copy of face and turn it if necessary
00135         face newFace = faces[slavePatchAddr[faceI]];
00136 
00137         if (slavePatchFlip[faceI])
00138         {
00139             newFace = newFace.reverseFace();
00140         }
00141 
00142         // Recover retired points on the slave side
00143         forAll (newFace, pointI)
00144         {
00145             Map<label>::const_iterator rpmIter = rpm.find(newFace[pointI]);
00146             if (rpmIter != rpm.end())
00147             {
00148                 // Master of retired point; grab its original
00149 //                 Pout << "Reinstating retired point: " << newFace[pointI] << " with old: " << rpm.find(newFace[pointI])() << endl;
00150                 newFace[pointI] = rpmIter();
00151             }
00152         }
00153 
00154         ref.setAction
00155         (
00156             polyModifyFace
00157             (
00158                 newFace,                         // new face
00159                 slavePatchAddr[faceI],           // master face index
00160                 slaveFc[faceI],                  // owner
00161                 -1,                              // neighbour
00162                 false,                           // flux flip
00163                 slavePatchID_.index(),           // patch ID
00164                 false,                           // remove from zone
00165                 slaveFaceZoneID_.index(),        // zone ID
00166                 false                            // zone flip.  Face corrected
00167             )
00168         );
00169     }
00170 
00171     // Re-create the master stick-out faces
00172 
00173     // Grab the list of faces in the layer
00174     const labelList& masterStickOuts = masterStickOutFaces();
00175 
00176     forAll (masterStickOuts, faceI)
00177     {
00178         // Renumber the face and remove additional points
00179 
00180         const label curFaceID = masterStickOuts[faceI];
00181 
00182         const face& oldFace = faces[curFaceID];
00183 
00184         DynamicList<label> newFaceLabels(oldFace.size());
00185 
00186         bool changed = false;
00187 
00188         forAll (oldFace, pointI)
00189         {
00190             // Check if the point is removed
00191             if (ref.pointRemoved(oldFace[pointI]))
00192             {
00193                 // Point removed; skip it
00194                 changed = true;
00195             }
00196             else
00197             {
00198                 newFaceLabels.append(oldFace[pointI]);
00199             }
00200         }
00201 
00202         if (changed)
00203         {
00204             if (newFaceLabels.size() < 3)
00205             {
00206                 FatalErrorIn
00207                 (
00208                     "void slidingInterface::decoupleInterface("
00209                     "polyTopoChange& ref) const"
00210                 )   << "Face " << curFaceID << " reduced to less than "
00211                     << "3 points.  Topological/cutting error." << nl
00212                     << "Old face: " << oldFace << " new face: " << newFaceLabels
00213                     << abort(FatalError);
00214             }
00215 
00216             // Get face zone and its flip
00217             label modifiedFaceZone = mesh.faceZones().whichZone(curFaceID);
00218             bool modifiedFaceZoneFlip = false;
00219 
00220             if (modifiedFaceZone >= 0)
00221             {
00222                 modifiedFaceZoneFlip =
00223                     mesh.faceZones()[modifiedFaceZone].flipMap()
00224                     [
00225                         mesh.faceZones()[modifiedFaceZone].whichFace(curFaceID)
00226                     ];
00227             }
00228 
00229             face newFace;
00230             newFace.transfer(newFaceLabels);
00231 
00232 //             Pout << "Modifying master stick-out face " << curFaceID << " old face: " << oldFace << " new face: " << newFace << endl;
00233 
00234             // Modify the face
00235             ref.setAction
00236             (
00237                 polyModifyFace
00238                 (
00239                     newFace,                // modified face
00240                     curFaceID,              // label of face being modified
00241                     own[curFaceID],         // owner
00242                     nei[curFaceID],         // neighbour
00243                     false,                  // face flip
00244                     mesh.boundaryMesh().whichPatch(curFaceID), // patch for face
00245                     false,                  // remove from zone
00246                     modifiedFaceZone,       // zone for face
00247                     modifiedFaceZoneFlip    // face flip in zone
00248                 )
00249             );
00250         }
00251     }
00252 
00253     // Re-create the slave stick-out faces
00254 
00255     labelHashSet slaveLayerCellFaceMap
00256     (
00257         primitiveMesh::facesPerCell_*(masterPatch.size() + slavePatch.size())
00258     );
00259 
00260     forAll (slaveFc, faceI)
00261     {
00262         const labelList& curFaces = cells[slaveFc[faceI]];
00263 
00264         forAll (curFaces, faceI)
00265         {
00266             // Check if the face belongs to the slave face zone; and
00267             // if it has been removed; if not add it
00268             if
00269             (
00270                 mesh.faceZones().whichZone(curFaces[faceI])
00271              != slaveFaceZoneID_.index()
00272              && !ref.faceRemoved(curFaces[faceI])
00273 
00274             )
00275             {
00276                 slaveLayerCellFaceMap.insert(curFaces[faceI]);
00277             }
00278         }
00279     }
00280 
00281     // Grab the list of faces in the layer
00282     const labelList& slaveStickOuts = slaveStickOutFaces();
00283 
00284     // Grab master point mapping
00285     const Map<label>& masterPm = masterPatch.meshPointMap();
00286 
00287     forAll (slaveStickOuts, faceI)
00288     {
00289         // Renumber the face and remove additional points
00290 
00291         const label curFaceID = slaveStickOuts[faceI];
00292 
00293         const face& oldFace = faces[curFaceID];
00294 
00295         DynamicList<label> newFaceLabels(oldFace.size());
00296 
00297         bool changed = false;
00298 
00299         forAll (oldFace, pointI)
00300         {
00301             // Check if the point is removed or retired
00302             if (rpm.found(oldFace[pointI]))
00303             {
00304                 // Master of retired point; grab its original
00305                 changed = true;
00306 //                 Pout << "Reinstating retired point: " << oldFace[pointI] << " with old: " << rpm.find(oldFace[pointI])() << endl;
00307                 newFaceLabels.append(rpm.find(oldFace[pointI])());
00308             }
00309             else if (ref.pointRemoved(oldFace[pointI]))
00310             {
00311                 // Point removed; skip it
00312                 changed = true;
00313             }
00314             else if (masterPm.found(oldFace[pointI]))
00315             {
00316                 // Point from master patch only; skip it
00317                 changed = true;
00318             }
00319             else
00320             {
00321                 newFaceLabels.append(oldFace[pointI]);
00322             }
00323         }
00324 
00325         if (changed)
00326         {
00327             if (newFaceLabels.size() < 3)
00328             {
00329                 FatalErrorIn
00330                 (
00331                     "void slidingInterface::decoupleInterface("
00332                     "polyTopoChange& ref) const"
00333                 )   << "Face " << curFaceID << " reduced to less than "
00334                     << "3 points.  Topological/cutting error." << nl
00335                     << "Old face: " << oldFace << " new face: " << newFaceLabels
00336                     << abort(FatalError);
00337             }
00338 
00339             // Get face zone and its flip
00340             label modifiedFaceZone = mesh.faceZones().whichZone(curFaceID);
00341             bool modifiedFaceZoneFlip = false;
00342 
00343             if (modifiedFaceZone >= 0)
00344             {
00345                 modifiedFaceZoneFlip =
00346                     mesh.faceZones()[modifiedFaceZone].flipMap()
00347                     [
00348                         mesh.faceZones()[modifiedFaceZone].whichFace(curFaceID)
00349                     ];
00350             }
00351 
00352             face newFace;
00353             newFace.transfer(newFaceLabels);
00354 
00355 //             Pout << "Modifying slave stick-out face " << curFaceID << " old face: " << oldFace << " new face: " << newFace << endl;
00356 
00357             // Modify the face
00358             ref.setAction
00359             (
00360                 polyModifyFace
00361                 (
00362                     newFace,                // modified face
00363                     curFaceID,              // label of face being modified
00364                     own[curFaceID],         // owner
00365                     nei[curFaceID],         // neighbour
00366                     false,                  // face flip
00367                     mesh.boundaryMesh().whichPatch(curFaceID), // patch for face
00368                     false,                  // remove from zone
00369                     modifiedFaceZone,       // zone for face
00370                     modifiedFaceZoneFlip    // face flip in zone
00371                 )
00372             );
00373         }
00374     }
00375 
00376     // Bring all slave patch points back to life
00377     const pointField& points = mesh.points();
00378 
00379     const labelList& slaveMeshPoints =
00380         mesh.faceZones()[slaveFaceZoneID_.index()]().meshPoints();
00381 
00382     forAll (slaveMeshPoints, pointI)
00383     {
00384         ref.setAction
00385         (
00386             polyModifyPoint
00387             (
00388                 slaveMeshPoints[pointI],             // point ID
00389                 points[slaveMeshPoints[pointI]],     // point
00390                 false,                               // remove from zone
00391                 mesh.pointZones().whichZone(slaveMeshPoints[pointI]), // zone
00392                 true                                // in a cell
00393             )
00394         );
00395     }
00396 
00397     // Clear the retired point numbering
00398     retiredPointMapPtr_->clear();
00399 
00400     // Finished decoupling
00401     attached_ = false;
00402 
00403     if (debug)
00404     {
00405         Pout<< "void slidingInterface::coupleInterface("
00406             << "polyTopoChange& ref) const : "
00407             << "Finished decoupling sliding interface " << name() << endl;
00408     }
00409 }
00410 
00411 
00412 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd