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

faceMapper.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 "faceMapper.H"
00028 #include "demandDrivenData.H"
00029 #include "polyMesh.H"
00030 #include "mapPolyMesh.H"
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 
00035 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00036 
00037 void Foam::faceMapper::calcAddressing() const
00038 {
00039     if
00040     (
00041         directAddrPtr_
00042      || interpolationAddrPtr_
00043      || weightsPtr_
00044      || insertedFaceLabelsPtr_
00045     )
00046     {
00047         FatalErrorIn("void faceMapper::calcAddressing() const")
00048             << "Addressing already calculated."
00049             << abort(FatalError);
00050     }
00051 
00052     if (direct())
00053     {
00054         // Direct addressing, no weights
00055 
00056         directAddrPtr_ = new labelList(mpm_.faceMap());
00057         labelList& directAddr = *directAddrPtr_;
00058 
00059         // Reset the size of addressing list to contain only live faces
00060         directAddr.setSize(mesh_.nFaces());
00061 
00062         insertedFaceLabelsPtr_ = new labelList(mesh_.nFaces());
00063         labelList& insertedFaces = *insertedFaceLabelsPtr_;
00064 
00065         label nInsertedFaces = 0;
00066 
00067         forAll (directAddr, faceI)
00068         {
00069             if (directAddr[faceI] < 0)
00070             {
00071                 // Found inserted face
00072                 directAddr[faceI] = 0;
00073                 insertedFaces[nInsertedFaces] = faceI;
00074                 nInsertedFaces++;
00075             }
00076         }
00077 
00078         insertedFaces.setSize(nInsertedFaces);
00079     }
00080     else
00081     {
00082         // Interpolative addressing
00083 
00084         interpolationAddrPtr_ = new labelListList(mesh_.nFaces());
00085         labelListList& addr = *interpolationAddrPtr_;
00086 
00087         weightsPtr_ = new scalarListList(mesh_.nFaces());
00088         scalarListList& w = *weightsPtr_;
00089 
00090         const List<objectMap>& ffp = mpm_.facesFromPointsMap();
00091 
00092         forAll (ffp, ffpI)
00093         {
00094             // Get addressing
00095             const labelList& mo = ffp[ffpI].masterObjects();
00096 
00097             label faceI = ffp[ffpI].index();
00098 
00099             if (addr[faceI].size())
00100             {
00101                 FatalErrorIn("void faceMapper::calcAddressing() const")
00102                     << "Master face " << faceI
00103                     << " mapped from point faces " << mo
00104                     << " already destination of mapping." << abort(FatalError);
00105             }
00106 
00107             // Map from masters, uniform weights
00108             addr[faceI] = mo;
00109             w[faceI] = scalarList(mo.size(), 1.0/mo.size());
00110         }
00111 
00112         const List<objectMap>& ffe = mpm_.facesFromEdgesMap();
00113 
00114         forAll (ffe, ffeI)
00115         {
00116             // Get addressing
00117             const labelList& mo = ffe[ffeI].masterObjects();
00118 
00119             label faceI = ffe[ffeI].index();
00120 
00121             if (addr[faceI].size())
00122             {
00123                 FatalErrorIn("void faceMapper::calcAddressing() const")
00124                     << "Master face " << faceI
00125                     << " mapped from edge faces " << mo
00126                     << " already destination of mapping." << abort(FatalError);
00127             }
00128 
00129             // Map from masters, uniform weights
00130             addr[faceI] = mo;
00131             w[faceI] = scalarList(mo.size(), 1.0/mo.size());
00132         }
00133 
00134         const List<objectMap>& fff = mpm_.facesFromFacesMap();
00135 
00136         forAll (fff, fffI)
00137         {
00138             // Get addressing
00139             const labelList& mo = fff[fffI].masterObjects();
00140 
00141             label faceI = fff[fffI].index();
00142 
00143             if (addr[faceI].size())
00144             {
00145                 FatalErrorIn("void faceMapper::calcAddressing() const")
00146                     << "Master face " << faceI
00147                     << " mapped from face faces " << mo
00148                     << " already destination of mapping." << abort(FatalError);
00149             }
00150 
00151             // Map from masters, uniform weights
00152             addr[faceI] = mo;
00153             w[faceI] = scalarList(mo.size(), 1.0/mo.size());
00154         }
00155 
00156 
00157         // Do mapped faces. Note that can already be set from facesFromFaces
00158         // so check if addressing size still zero.
00159         const labelList& fm = mpm_.faceMap();
00160 
00161         forAll (fm, faceI)
00162         {
00163             if (fm[faceI] > -1 && addr[faceI].empty())
00164             {
00165                 // Mapped from a single face
00166                 addr[faceI] = labelList(1, fm[faceI]);
00167                 w[faceI] = scalarList(1, 1.0);
00168             }
00169         }
00170 
00171 
00172         // Grab inserted points (for them the size of addressing is still zero)
00173 
00174         insertedFaceLabelsPtr_ = new labelList(mesh_.nFaces());
00175         labelList& insertedFaces = *insertedFaceLabelsPtr_;
00176 
00177         label nInsertedFaces = 0;
00178 
00179         forAll (addr, faceI)
00180         {
00181             if (addr[faceI].empty())
00182             {
00183                 // Mapped from a dummy face
00184                 addr[faceI] = labelList(1, 0);
00185                 w[faceI] = scalarList(1, 1.0);
00186 
00187                 insertedFaces[nInsertedFaces] = faceI;
00188                 nInsertedFaces++;
00189             }
00190         }
00191 
00192         insertedFaces.setSize(nInsertedFaces);
00193     }
00194 }
00195 
00196 
00197 void Foam::faceMapper::clearOut()
00198 {
00199     deleteDemandDrivenData(directAddrPtr_);
00200     deleteDemandDrivenData(interpolationAddrPtr_);
00201     deleteDemandDrivenData(weightsPtr_);
00202     deleteDemandDrivenData(insertedFaceLabelsPtr_);
00203 }
00204 
00205 
00206 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00207 
00208 // Construct from components
00209 Foam::faceMapper::faceMapper(const mapPolyMesh& mpm)
00210 :
00211     mesh_(mpm.mesh()),
00212     mpm_(mpm),
00213     insertedFaces_(true),
00214     direct_(false),
00215     directAddrPtr_(NULL),
00216     interpolationAddrPtr_(NULL),
00217     weightsPtr_(NULL),
00218     insertedFaceLabelsPtr_(NULL)
00219 {
00220     // Check for possibility of direct mapping
00221     if
00222     (
00223         mpm_.facesFromPointsMap().empty() 
00224      && mpm_.facesFromEdgesMap().empty()
00225      && mpm_.facesFromFacesMap().empty()
00226     )
00227     {
00228         direct_ = true;
00229     }
00230     else
00231     {
00232         direct_ = false;
00233     }
00234 
00235     // Check for inserted faces
00236     if (direct_ && (mpm_.faceMap().empty() || min(mpm_.faceMap()) > -1))
00237     {
00238         insertedFaces_ = false;
00239     }
00240     else
00241     {
00242         // Need to check all 3 lists to see if there are inserted faces
00243         // with no owner
00244 
00245         // Make a copy of the face map, add the entries for faces from points
00246         // and faces from edges and check for left-overs
00247         labelList fm(mesh_.nFaces(), -1);
00248 
00249         const List<objectMap>& ffp = mpm_.facesFromPointsMap();
00250 
00251         forAll (ffp, ffpI)
00252         {
00253             fm[ffp[ffpI].index()] = 0;
00254         }
00255 
00256         const List<objectMap>& ffe = mpm_.facesFromEdgesMap();
00257 
00258         forAll (ffe, ffeI)
00259         {
00260             fm[ffe[ffeI].index()] = 0;
00261         }
00262 
00263         const List<objectMap>& fff = mpm_.facesFromFacesMap();
00264 
00265         forAll (fff, fffI)
00266         {
00267             fm[fff[fffI].index()] = 0;
00268         }
00269 
00270         if (min(fm) < 0)
00271         {
00272             insertedFaces_ = true;
00273         }
00274     }
00275 }
00276 
00277 
00278 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00279 
00280 Foam::faceMapper::~faceMapper()
00281 {
00282     clearOut();
00283 }
00284 
00285 
00286 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00287 
00288 Foam::label Foam::faceMapper::size() const
00289 {
00290     return mesh_.nFaces();
00291 }
00292 
00293 
00294 Foam::label Foam::faceMapper::sizeBeforeMapping() const
00295 {
00296     return mpm_.nOldFaces();
00297 }
00298 
00299 
00300 Foam::label Foam::faceMapper::internalSizeBeforeMapping() const
00301 {
00302     return mpm_.nOldInternalFaces();
00303 }
00304 
00305 
00306 const Foam::unallocLabelList& Foam::faceMapper::directAddressing() const
00307 {
00308     if (!direct())
00309     {
00310         FatalErrorIn
00311         (
00312             "const unallocLabelList& faceMapper::directAddressing() const"
00313         )   << "Requested direct addressing for an interpolative mapper."
00314             << abort(FatalError);
00315     }
00316 
00317     if (!insertedObjects())
00318     {
00319         // No inserted faces.  Re-use faceMap
00320         return mpm_.faceMap();
00321     }
00322     else
00323     {
00324         if (!directAddrPtr_)
00325         {
00326             calcAddressing();
00327         }
00328 
00329         return *directAddrPtr_;
00330     }
00331 }
00332 
00333 
00334 const Foam::labelListList& Foam::faceMapper::addressing() const
00335 {
00336     if (direct())
00337     {
00338         FatalErrorIn
00339         (
00340             "const labelListList& faceMapper::addressing() const"
00341         )   << "Requested interpolative addressing for a direct mapper."
00342             << abort(FatalError);
00343     }
00344 
00345     if (!interpolationAddrPtr_)
00346     {
00347         calcAddressing();
00348     }
00349 
00350     return *interpolationAddrPtr_;
00351 }
00352 
00353 
00354 const Foam::scalarListList& Foam::faceMapper::weights() const
00355 {
00356     if (direct())
00357     {
00358         FatalErrorIn
00359         (
00360             "const scalarListList& faceMapper::weights() const"
00361         )   << "Requested interpolative weights for a direct mapper."
00362             << abort(FatalError);
00363     }
00364 
00365     if (!weightsPtr_)
00366     {
00367         calcAddressing();
00368     }
00369 
00370     return *weightsPtr_;
00371 }
00372 
00373 
00374 const Foam::labelList& Foam::faceMapper::insertedObjectLabels() const
00375 {
00376     if (!insertedFaceLabelsPtr_)
00377     {
00378         if (!insertedObjects())
00379         {
00380             // There are no inserted faces
00381             insertedFaceLabelsPtr_ = new labelList(0);
00382         }
00383         else
00384         {
00385             calcAddressing();
00386         }
00387     }
00388 
00389     return *insertedFaceLabelsPtr_;
00390 }
00391 
00392 
00393 const Foam::labelHashSet& Foam::faceMapper::flipFaceFlux() const
00394 {
00395     return mpm_.flipFaceFlux();
00396 }
00397 
00398 
00399 Foam::label Foam::faceMapper::nOldInternalFaces() const
00400 {
00401     return mpm_.nOldInternalFaces();
00402 }
00403 
00404 
00405 const Foam::labelList& Foam::faceMapper::oldPatchStarts() const
00406 {
00407     return mpm_.oldPatchStarts();
00408 }
00409 
00410 
00411 const Foam::labelList& Foam::faceMapper::oldPatchSizes() const
00412 {
00413     return mpm_.oldPatchSizes();
00414 }
00415 
00416 
00417 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00418 
00419 
00420 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
00421 
00422 
00423 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00424 
00425 
00426 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd