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

slidingInterfaceAttachedAddressing.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/mapPolyMesh.H>
00029 #include <dynamicMesh/polyTopoChanger.H>
00030 
00031 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00032 
00033 void Foam::slidingInterface::calcAttachedAddressing() const
00034 {
00035     if (debug)
00036     {
00037         Pout<< "void Foam::slidingInterface::calcAttachedAddressing() const "
00038             << " for object " << name() << " : "
00039             << "Calculating zone face-cell addressing."
00040             << endl;
00041     }
00042 
00043     if (!attached_)
00044     {
00045         // Clear existing addressing
00046         clearAttachedAddressing();
00047 
00048         const polyMesh& mesh = topoChanger().mesh();
00049         const labelList& own = mesh.faceOwner();
00050         const labelList& nei = mesh.faceNeighbour();
00051         const faceZoneMesh& faceZones = mesh.faceZones();
00052 
00053         // Master side
00054 
00055         const primitiveFacePatch& masterPatch =
00056             faceZones[masterFaceZoneID_.index()]();
00057 
00058         const labelList& masterPatchFaces =
00059             faceZones[masterFaceZoneID_.index()];
00060 
00061         const boolList& masterFlip =
00062             faceZones[masterFaceZoneID_.index()].flipMap();
00063 
00064         masterFaceCellsPtr_ = new labelList(masterPatchFaces.size());
00065         labelList& mfc = *masterFaceCellsPtr_;
00066 
00067         forAll (masterPatchFaces, faceI)
00068         {
00069             if (masterFlip[faceI])
00070             {
00071                 mfc[faceI] = nei[masterPatchFaces[faceI]];
00072             }
00073             else
00074             {
00075                 mfc[faceI] = own[masterPatchFaces[faceI]];
00076             }
00077         }
00078 
00079         // Slave side
00080 
00081         const primitiveFacePatch& slavePatch =
00082             faceZones[slaveFaceZoneID_.index()]();
00083 
00084         const labelList& slavePatchFaces =
00085             faceZones[slaveFaceZoneID_.index()];
00086 
00087         const boolList& slaveFlip =
00088             faceZones[slaveFaceZoneID_.index()].flipMap();
00089 
00090         slaveFaceCellsPtr_ = new labelList(slavePatchFaces.size());
00091         labelList& sfc = *slaveFaceCellsPtr_;
00092 
00093         forAll (slavePatchFaces, faceI)
00094         {
00095             if (slaveFlip[faceI])
00096             {
00097                 sfc[faceI] = nei[slavePatchFaces[faceI]];
00098             }
00099             else
00100             {
00101                 sfc[faceI] = own[slavePatchFaces[faceI]];
00102             }
00103         }
00104 
00105         // Check that the addressing is valid
00106         if (min(mfc) < 0 || min(sfc) < 0)
00107         {
00108             if (debug)
00109             {
00110                 forAll (mfc, faceI)
00111                 {
00112                     if (mfc[faceI] < 0)
00113                     {
00114                         Pout << "No cell next to master patch face " << faceI
00115                             << ".  Global face no: " << mfc[faceI]
00116                             << " own: " << own[masterPatchFaces[faceI]]
00117                             << " nei: " << nei[masterPatchFaces[faceI]]
00118                             << " flip: " << masterFlip[faceI] << endl;
00119                     }
00120                 }
00121 
00122                 forAll (sfc, faceI)
00123                 {
00124                     if (sfc[faceI] < 0)
00125                     {
00126                         Pout << "No cell next to slave patch face " << faceI
00127                             << ".  Global face no: " << sfc[faceI]
00128                             << " own: " << own[slavePatchFaces[faceI]]
00129                             << " nei: " << nei[slavePatchFaces[faceI]]
00130                             << " flip: " << slaveFlip[faceI] << endl;
00131                     }
00132                 }
00133             }
00134 
00135             FatalErrorIn
00136             (
00137                 "void slidingInterface::calcAttachedAddressing()"
00138                 "const"
00139             )   << "Error is zone face-cell addressing.  Probable error in "
00140                 << "decoupled mesh or sliding interface definition."
00141                 << abort(FatalError);
00142         }
00143 
00144         // Calculate stick-out faces
00145         const labelListList& pointFaces = mesh.pointFaces();
00146 
00147         // Master side
00148         labelHashSet masterStickOutFaceMap
00149         (
00150             primitiveMesh::facesPerCell_*(masterPatch.size())
00151         );
00152 
00153         const labelList& masterMeshPoints = masterPatch.meshPoints();
00154 
00155         forAll (masterMeshPoints, pointI)
00156         {
00157             const labelList& curFaces = pointFaces[masterMeshPoints[pointI]];
00158 
00159             forAll (curFaces, faceI)
00160             {
00161                 // Check if the face belongs to the master face zone;
00162                 // if not add it
00163                 if
00164                 (
00165                     faceZones.whichZone(curFaces[faceI])
00166                  != masterFaceZoneID_.index()
00167                 )
00168                 {
00169                     masterStickOutFaceMap.insert(curFaces[faceI]);
00170                 }
00171             }
00172         }
00173 
00174         masterStickOutFacesPtr_ = new labelList(masterStickOutFaceMap.toc());
00175 
00176         // Slave side
00177         labelHashSet slaveStickOutFaceMap
00178         (
00179             primitiveMesh::facesPerCell_*(slavePatch.size())
00180         );
00181 
00182         const labelList& slaveMeshPoints = slavePatch.meshPoints();
00183 
00184         forAll (slaveMeshPoints, pointI)
00185         {
00186             const labelList& curFaces = pointFaces[slaveMeshPoints[pointI]];
00187 
00188             forAll (curFaces, faceI)
00189             {
00190                 // Check if the face belongs to the slave face zone;
00191                 // if not add it
00192                 if
00193                 (
00194                     faceZones.whichZone(curFaces[faceI])
00195                  != slaveFaceZoneID_.index()
00196                 )
00197                 {
00198                     slaveStickOutFaceMap.insert(curFaces[faceI]);
00199                 }
00200             }
00201         }
00202 
00203         slaveStickOutFacesPtr_ = new labelList(slaveStickOutFaceMap.toc());
00204 
00205 
00206         // Retired point addressing does not exist at this stage.
00207         // It will be filled when the interface is coupled.  
00208         retiredPointMapPtr_ =
00209             new Map<label>
00210             (
00211                 2*faceZones[slaveFaceZoneID_.index()]().nPoints()
00212             );
00213 
00214         // Ditto for cut point edge map.  This is a rough guess of its size
00215         // 
00216         cutPointEdgePairMapPtr_ =
00217             new Map<Pair<edge> >
00218             (
00219                 faceZones[slaveFaceZoneID_.index()]().nEdges()
00220             );
00221     }
00222     else
00223     {
00224         FatalErrorIn
00225         (
00226             "void slidingInterface::calcAttachedAddressing() const"
00227         )   << "The interface is attached.  The zone face-cell addressing "
00228             << "cannot be assembled for object " << name()
00229             << abort(FatalError);
00230     }
00231 
00232     if (debug)
00233     {
00234         Pout<< "void Foam::slidingInterface::calcAttachedAddressing() const "
00235             << " for object " << name() << " : "
00236             << "Finished calculating zone face-cell addressing."
00237             << endl;
00238     }
00239 }
00240 
00241 
00242 void Foam::slidingInterface::clearAttachedAddressing() const
00243 {
00244     deleteDemandDrivenData(masterFaceCellsPtr_);
00245     deleteDemandDrivenData(slaveFaceCellsPtr_);
00246 
00247     deleteDemandDrivenData(masterStickOutFacesPtr_);
00248     deleteDemandDrivenData(slaveStickOutFacesPtr_);
00249 
00250     deleteDemandDrivenData(retiredPointMapPtr_);
00251     deleteDemandDrivenData(cutPointEdgePairMapPtr_);
00252 }
00253 
00254 
00255 void Foam::slidingInterface::renumberAttachedAddressing
00256 (
00257     const mapPolyMesh& m
00258 ) const
00259 {
00260     // Get reference to reverse cell renumbering
00261     // The renumbering map is needed the other way around, i.e. giving
00262     // the new cell number for every old cell next to the interface.
00263     const labelList& reverseCellMap = m.reverseCellMap();
00264     
00265     const labelList& mfc = masterFaceCells();
00266     const labelList& sfc = slaveFaceCells();
00267 
00268     // Master side
00269     labelList* newMfcPtr = new labelList(mfc.size(), -1);
00270     labelList& newMfc = *newMfcPtr;
00271 
00272     const labelList& mfzRenumber =
00273         m.faceZoneFaceMap()[masterFaceZoneID_.index()];
00274 
00275     forAll (mfc, faceI)
00276     {
00277         label newCellI = reverseCellMap[mfc[mfzRenumber[faceI]]];
00278 
00279         if (newCellI >= 0)
00280         {
00281             newMfc[faceI] = newCellI;
00282         }
00283     }
00284 
00285     // Slave side
00286     labelList* newSfcPtr = new labelList(sfc.size(), -1);
00287     labelList& newSfc = *newSfcPtr;
00288 
00289     const labelList& sfzRenumber =
00290         m.faceZoneFaceMap()[slaveFaceZoneID_.index()];
00291 
00292     forAll (sfc, faceI)
00293     {
00294         label newCellI = reverseCellMap[sfc[sfzRenumber[faceI]]];
00295 
00296         if (newCellI >= 0)
00297         {
00298             newSfc[faceI] = newCellI;
00299         }
00300     }
00301 
00302     if (debug)
00303     {
00304         // Check if all the mapped cells are live
00305         if (min(newMfc) < 0 || min(newSfc) < 0)
00306         {
00307             FatalErrorIn
00308             (
00309                 "void slidingInterface::renumberAttachedAddressing("
00310                 "const mapPolyMesh& m) const"
00311             )   << "Error in cell renumbering for object " << name()
00312                 << ".  Some of master cells next "
00313                 << "to the interface have been removed."
00314                 << abort(FatalError);
00315         }
00316     }
00317 
00318     // Renumber stick-out faces
00319 
00320     const labelList& reverseFaceMap = m.reverseFaceMap();
00321     
00322     // Master side
00323     const labelList& msof = masterStickOutFaces();
00324 
00325     labelList* newMsofPtr = new labelList(msof.size(), -1);
00326     labelList& newMsof = *newMsofPtr;
00327 
00328     forAll (msof, faceI)
00329     {
00330         label newFaceI = reverseFaceMap[msof[faceI]];
00331 
00332         if (newFaceI >= 0)
00333         {
00334             newMsof[faceI] = newFaceI;
00335         }
00336     }
00337 //     Pout << "newMsof: " << newMsof << endl;
00338     // Slave side
00339     const labelList& ssof = slaveStickOutFaces();
00340 
00341     labelList* newSsofPtr = new labelList(ssof.size(), -1);
00342     labelList& newSsof = *newSsofPtr;
00343 
00344     forAll (ssof, faceI)
00345     {
00346         label newFaceI = reverseFaceMap[ssof[faceI]];
00347 
00348         if (newFaceI >= 0)
00349         {
00350             newSsof[faceI] = newFaceI;
00351         }
00352     }
00353 //     Pout << "newSsof: " << newSsof << endl;
00354     if (debug)
00355     {
00356         // Check if all the mapped cells are live
00357         if (min(newMsof) < 0 || min(newSsof) < 0)
00358         {
00359             FatalErrorIn
00360             (
00361                 "void slidingInterface::renumberAttachedAddressing("
00362                 "const mapPolyMesh& m) const"
00363             )   << "Error in face renumbering for object " << name()
00364                 << ".  Some of stick-out next "
00365                 << "to the interface have been removed."
00366                 << abort(FatalError);
00367         }
00368     }
00369 
00370     // Renumber the retired point map. Need to take a copy!
00371     const Map<label> rpm = retiredPointMap();
00372 
00373     Map<label>* newRpmPtr = new Map<label>(rpm.size());
00374     Map<label>& newRpm = *newRpmPtr;
00375 
00376     const labelList rpmToc = rpm.toc();
00377 
00378     // Get reference to point renumbering
00379     const labelList& reversePointMap = m.reversePointMap();
00380 
00381     label key, value;
00382 
00383     forAll (rpmToc, rpmTocI)
00384     {
00385         key = reversePointMap[rpmToc[rpmTocI]];
00386 
00387         value = reversePointMap[rpm.find(rpmToc[rpmTocI])()];
00388 
00389         if (debug)
00390         {
00391             // Check if all the mapped cells are live
00392             if (key < 0 || value < 0)
00393             {
00394                 FatalErrorIn
00395                 (
00396                     "void slidingInterface::renumberAttachedAddressing("
00397                     "const mapPolyMesh& m) const"
00398                 )   << "Error in retired point numbering for object "
00399                     << name() << ".  Some of master "
00400                     << "points have been removed."
00401                     << abort(FatalError);
00402             }
00403         }
00404 
00405         newRpm.insert(key, value);
00406     }
00407 
00408     // Renumber the cut point edge pair map. Need to take a copy!
00409     const Map<Pair<edge> > cpepm = cutPointEdgePairMap();
00410 
00411     Map<Pair<edge> >* newCpepmPtr = new Map<Pair<edge> >(cpepm.size());
00412     Map<Pair<edge> >& newCpepm = *newCpepmPtr;
00413 
00414     const labelList cpepmToc = cpepm.toc();
00415 
00416     forAll (cpepmToc, cpepmTocI)
00417     {
00418         key = reversePointMap[cpepmToc[cpepmTocI]];
00419 
00420         const Pair<edge>& oldPe = cpepm.find(cpepmToc[cpepmTocI])();
00421 
00422         // Re-do the edges in global addressing
00423         const label ms = reversePointMap[oldPe.first().start()];
00424         const label me = reversePointMap[oldPe.first().end()];
00425 
00426         const label ss = reversePointMap[oldPe.second().start()];
00427         const label se = reversePointMap[oldPe.second().end()];
00428 
00429         if (debug)
00430         {
00431             // Check if all the mapped cells are live
00432             if (key < 0 || ms < 0 || me < 0 || ss < 0 || se < 0)
00433             {
00434                 FatalErrorIn
00435                 (
00436                     "void slidingInterface::renumberAttachedAddressing("
00437                     "const mapPolyMesh& m) const"
00438                 )   << "Error in cut point edge pair map numbering for object "
00439                     << name() << ".  Some of master points have been removed."
00440                     << abort(FatalError);
00441             }
00442         }
00443 
00444         newCpepm.insert(key, Pair<edge>(edge(ms, me), edge(ss, se)));
00445     }
00446 
00447     if (!projectedSlavePointsPtr_)
00448     {
00449         FatalErrorIn
00450         (
00451             "void slidingInterface::renumberAttachedAddressing("
00452             "const mapPolyMesh& m) const"
00453         )   << "Error in projected point numbering for object " << name()
00454             << abort(FatalError);
00455     }
00456 
00457     // Renumber the projected slave zone points
00458     const pointField& projectedSlavePoints = *projectedSlavePointsPtr_;
00459 
00460     pointField* newProjectedSlavePointsPtr
00461     (
00462         new pointField(projectedSlavePoints.size())
00463     );
00464     pointField& newProjectedSlavePoints = *newProjectedSlavePointsPtr;
00465 
00466     const labelList& sfzPointRenumber =
00467         m.faceZonePointMap()[slaveFaceZoneID_.index()];
00468 
00469     forAll (newProjectedSlavePoints, pointI)
00470     {
00471         if (sfzPointRenumber[pointI] > -1)
00472         {
00473             newProjectedSlavePoints[pointI] =
00474                 projectedSlavePoints[sfzPointRenumber[pointI]];
00475         }
00476     }
00477 
00478     // Re-set the lists
00479     clearAttachedAddressing();
00480 
00481     deleteDemandDrivenData(projectedSlavePointsPtr_);
00482     
00483     masterFaceCellsPtr_ = newMfcPtr;
00484     slaveFaceCellsPtr_ = newSfcPtr;
00485 
00486     masterStickOutFacesPtr_ = newMsofPtr;
00487     slaveStickOutFacesPtr_ = newSsofPtr;
00488 
00489     retiredPointMapPtr_ = newRpmPtr;
00490     cutPointEdgePairMapPtr_ = newCpepmPtr;
00491     projectedSlavePointsPtr_ = newProjectedSlavePointsPtr;
00492 }
00493 
00494 
00495 const Foam::labelList& Foam::slidingInterface::masterFaceCells() const
00496 {
00497     if (!masterFaceCellsPtr_)
00498     {
00499         FatalErrorIn
00500         (
00501             "const labelList& slidingInterface::masterFaceCells() const"
00502         )   << "Master zone face-cell addressing not available for object "
00503             << name()
00504             << abort(FatalError);
00505     }
00506 
00507     return *masterFaceCellsPtr_;
00508 }
00509 
00510 
00511 const Foam::labelList& Foam::slidingInterface::slaveFaceCells() const
00512 {
00513     if (!slaveFaceCellsPtr_)
00514     {
00515         FatalErrorIn
00516         (
00517             "const labelList& slidingInterface::slaveFaceCells() const"
00518         )   << "Slave zone face-cell addressing not available for object "
00519             << name()
00520             << abort(FatalError);
00521     }
00522 
00523     return *slaveFaceCellsPtr_;
00524 }
00525 
00526 
00527 const Foam::labelList& Foam::slidingInterface::masterStickOutFaces() const
00528 {
00529     if (!masterStickOutFacesPtr_)
00530     {
00531         FatalErrorIn
00532         (
00533             "const labelList& slidingInterface::masterStickOutFaces() const"
00534         )   << "Master zone stick-out face addressing not available for object "
00535             << name()
00536             << abort(FatalError);
00537     }
00538 
00539     return *masterStickOutFacesPtr_;
00540 }
00541 
00542 
00543 const Foam::labelList& Foam::slidingInterface::slaveStickOutFaces() const
00544 {
00545     if (!slaveStickOutFacesPtr_)
00546     {
00547         FatalErrorIn
00548         (
00549             "const labelList& slidingInterface::slaveStickOutFaces() const"
00550         )   << "Slave zone stick-out face addressing not available for object "
00551             << name()
00552             << abort(FatalError);
00553     }
00554 
00555     return *slaveStickOutFacesPtr_;
00556 }
00557 
00558 
00559 const Foam::Map<Foam::label>& Foam::slidingInterface::retiredPointMap() const
00560 {
00561     if (!retiredPointMapPtr_)
00562     {
00563         FatalErrorIn
00564         (
00565             "const Map<label>& slidingInterface::retiredPointMap() const"
00566         )   << "Retired point map not available for object " << name()
00567             << abort(FatalError);
00568     }
00569 
00570     return *retiredPointMapPtr_;
00571 }
00572 
00573 
00574 const Foam::Map<Foam::Pair<Foam::edge> >&
00575 Foam::slidingInterface::cutPointEdgePairMap() const
00576 {
00577     if (!cutPointEdgePairMapPtr_)
00578     {
00579         FatalErrorIn
00580         (
00581             "const Map<Pair<edge> >& slidingInterface::"
00582             "cutPointEdgePairMap() const"
00583         )   << "Retired point map not available for object " << name()
00584             << abort(FatalError);
00585     }
00586 
00587     return *cutPointEdgePairMapPtr_;
00588 }
00589 
00590 
00591 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines