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

pointMapper.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 "pointMapper.H"
00028 #include "demandDrivenData.H"
00029 #include "pointMesh.H"
00030 #include "mapPolyMesh.H"
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 
00035 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00036 
00037 void Foam::pointMapper::calcAddressing() const
00038 {
00039     if
00040     (
00041         directAddrPtr_
00042      || interpolationAddrPtr_
00043      || weightsPtr_
00044      || insertedPointLabelsPtr_
00045     )
00046     {
00047         FatalErrorIn("void pointMapper::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_.pointMap());
00057         labelList& directAddr = *directAddrPtr_;
00058 
00059         // Not necessary to resize the list as there are no retired points
00060         // directAddr.setSize(pMesh_.size());
00061 
00062         insertedPointLabelsPtr_ = new labelList(pMesh_.size());
00063         labelList& insertedPoints = *insertedPointLabelsPtr_;
00064 
00065         label nInsertedPoints = 0;
00066 
00067         forAll (directAddr, pointI)
00068         {
00069             if (directAddr[pointI] < 0)
00070             {
00071                 // Found inserted point
00072                 directAddr[pointI] = 0;
00073                 insertedPoints[nInsertedPoints] = pointI;
00074                 nInsertedPoints++;
00075             }
00076         }
00077 
00078         insertedPoints.setSize(nInsertedPoints);
00079     }
00080     else
00081     {
00082         // Interpolative addressing
00083 
00084         interpolationAddrPtr_ = new labelListList(pMesh_.size());
00085         labelListList& addr = *interpolationAddrPtr_;
00086 
00087         weightsPtr_ = new scalarListList(pMesh_.size());
00088         scalarListList& w = *weightsPtr_;
00089 
00090         // Points created from other points (i.e. points merged into it).
00091         const List<objectMap>& cfc = mpm_.pointsFromPointsMap();
00092 
00093         forAll (cfc, cfcI)
00094         {
00095             // Get addressing
00096             const labelList& mo = cfc[cfcI].masterObjects();
00097 
00098             label pointI = cfc[cfcI].index();
00099 
00100             if (addr[pointI].size())
00101             {
00102                 FatalErrorIn("void pointMapper::calcAddressing() const")
00103                     << "Master point " << pointI
00104                     << " mapped from points " << mo
00105                     << " already destination of mapping." << abort(FatalError);
00106             }
00107 
00108             // Map from masters, uniform weights
00109             addr[pointI] = mo;
00110             w[pointI] = scalarList(mo.size(), 1.0/mo.size());
00111         }
00112 
00113 
00114         // Do mapped points. Note that can already be set from pointsFromPoints
00115         // so check if addressing size still zero.
00116 
00117         const labelList& cm = mpm_.pointMap();
00118 
00119         forAll (cm, pointI)
00120         {
00121             if (cm[pointI] > -1 && addr[pointI].empty())
00122             {
00123                 // Mapped from a single point
00124                 addr[pointI] = labelList(1, cm[pointI]);
00125                 w[pointI] = scalarList(1, 1.0);
00126             }
00127         }
00128 
00129         // Grab inserted points (for them the size of addressing is still zero)
00130 
00131         insertedPointLabelsPtr_ = new labelList(pMesh_.size());
00132         labelList& insertedPoints = *insertedPointLabelsPtr_;
00133 
00134         label nInsertedPoints = 0;
00135 
00136         forAll (addr, pointI)
00137         {
00138             if (addr[pointI].empty())
00139             {
00140                 // Mapped from a dummy point. Take point 0 with weight 1.
00141                 addr[pointI] = labelList(1, 0);
00142                 w[pointI] = scalarList(1, 1.0);
00143 
00144                 insertedPoints[nInsertedPoints] = pointI;
00145                 nInsertedPoints++;
00146             }
00147         }
00148 
00149         insertedPoints.setSize(nInsertedPoints);
00150     }
00151 }
00152 
00153 
00154 void Foam::pointMapper::clearOut()
00155 {
00156     deleteDemandDrivenData(directAddrPtr_);
00157     deleteDemandDrivenData(interpolationAddrPtr_);
00158     deleteDemandDrivenData(weightsPtr_);
00159     deleteDemandDrivenData(insertedPointLabelsPtr_);
00160 }
00161 
00162 
00163 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00164 
00165 // Construct from components
00166 Foam::pointMapper::pointMapper(const pointMesh& pMesh, const mapPolyMesh& mpm)
00167 :
00168     pMesh_(pMesh),
00169     mpm_(mpm),
00170     insertedPoints_(true),
00171     direct_(false),
00172     directAddrPtr_(NULL),
00173     interpolationAddrPtr_(NULL),
00174     weightsPtr_(NULL),
00175     insertedPointLabelsPtr_(NULL)
00176 {
00177     // Check for possibility of direct mapping
00178     if (mpm_.pointsFromPointsMap().empty())
00179     {
00180         direct_ = true;
00181     }
00182     else
00183     {
00184         direct_ = false;
00185     }
00186 
00187     // Check for inserted points
00188     if (direct_ && (mpm_.pointMap().empty() || min(mpm_.pointMap()) > -1))
00189     {
00190         insertedPoints_ = false;
00191     }
00192     else
00193     {
00194         //Check if there are inserted points with no owner
00195 
00196         // Make a copy of the point map, add the entries for points from points
00197         // and check for left-overs
00198         labelList cm(pMesh_.size(), -1);
00199 
00200         const List<objectMap>& cfc = mpm_.pointsFromPointsMap();
00201 
00202         forAll (cfc, cfcI)
00203         {
00204             cm[cfc[cfcI].index()] = 0;
00205         }
00206 
00207         if (min(cm) < 0)
00208         {
00209             insertedPoints_ = true;
00210         }
00211     }
00212 }
00213 
00214 
00215 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00216 
00217 Foam::pointMapper::~pointMapper()
00218 {
00219     clearOut();
00220 }
00221 
00222 
00223 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00224 
00225 Foam::label Foam::pointMapper::size() const
00226 {
00227     return mpm_.pointMap().size();
00228 }
00229 
00230 
00231 Foam::label Foam::pointMapper::sizeBeforeMapping() const
00232 {
00233     return mpm_.nOldPoints();
00234 }
00235 
00236 
00237 const Foam::unallocLabelList& Foam::pointMapper::directAddressing() const
00238 {
00239     if (!direct())
00240     {
00241         FatalErrorIn
00242         (
00243             "const unallocLabelList& pointMapper::directAddressing() const"
00244         )   << "Requested direct addressing for an interpolative mapper."
00245             << abort(FatalError);
00246     }
00247 
00248     if (!insertedObjects())
00249     {
00250         // No inserted points.  Re-use pointMap
00251         return mpm_.pointMap();
00252     }
00253     else
00254     {
00255         if (!directAddrPtr_)
00256         {
00257             calcAddressing();
00258         }
00259 
00260         return *directAddrPtr_;
00261     }
00262 }
00263 
00264 
00265 const Foam::labelListList& Foam::pointMapper::addressing() const
00266 {
00267     if (direct())
00268     {
00269         FatalErrorIn
00270         (
00271             "const labelListList& pointMapper::addressing() const"
00272         )   << "Requested interpolative addressing for a direct mapper."
00273             << abort(FatalError);
00274     }
00275 
00276     if (!interpolationAddrPtr_)
00277     {
00278         calcAddressing();
00279     }
00280 
00281     return *interpolationAddrPtr_;
00282 }
00283 
00284 
00285 const Foam::scalarListList& Foam::pointMapper::weights() const
00286 {
00287     if (direct())
00288     {
00289         FatalErrorIn
00290         (
00291             "const scalarListList& pointMapper::weights() const"
00292         )   << "Requested interpolative weights for a direct mapper."
00293             << abort(FatalError);
00294     }
00295 
00296     if (!weightsPtr_)
00297     {
00298         calcAddressing();
00299     }
00300 
00301     return *weightsPtr_;
00302 }
00303 
00304 
00305 const Foam::labelList& Foam::pointMapper::insertedObjectLabels() const
00306 {
00307     if (!insertedPointLabelsPtr_)
00308     {
00309         if (!insertedObjects())
00310         {
00311             // There are no inserted points
00312             insertedPointLabelsPtr_ = new labelList(0);
00313         }
00314         else
00315         {
00316             calcAddressing();
00317         }
00318     }
00319 
00320     return *insertedPointLabelsPtr_;
00321 }
00322         
00323 
00324 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00325 
00326 
00327 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
00328 
00329 
00330 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00331 
00332 
00333 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd