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

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