FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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