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

fvSurfaceMapper.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 Description
00026     FV surface mapper.
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "fvSurfaceMapper.H"
00031 #include "fvMesh.H"
00032 #include "mapPolyMesh.H"
00033 #include "faceMapper.H"
00034 
00035 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00036 
00037 void Foam::fvSurfaceMapper::calcAddressing() const
00038 {
00039     if
00040     (
00041         directAddrPtr_
00042      || interpolationAddrPtr_
00043      || weightsPtr_
00044      || insertedObjectLabelsPtr_
00045     )
00046     {
00047         FatalErrorIn("void fvSurfaceMapper::calcAddressing() const)")
00048             << "Addressing already calculated"
00049             << abort(FatalError);
00050     }
00051 
00052     // Mapping
00053 
00054     const label oldNInternal = faceMap_.nOldInternalFaces();
00055 
00056     // Assemble the maps
00057     if (direct())
00058     {
00059         // Direct mapping - slice to size
00060         directAddrPtr_ =
00061             new labelList
00062             (
00063                 labelList::subList(faceMap_.directAddressing(), size())
00064             );
00065         labelList& addr = *directAddrPtr_;
00066 
00067         // Adjust for creation of an internal face from a boundary face
00068         forAll (addr, faceI)
00069         {
00070             if (addr[faceI] > oldNInternal)
00071             {
00072                 addr[faceI] = 0;
00073             }
00074         }
00075     }
00076     else
00077     {
00078         // Interpolative mapping - slice to size
00079         interpolationAddrPtr_ =
00080             new labelListList
00081             (
00082                 labelListList::subList(faceMap_.addressing(), size())
00083             );
00084         labelListList& addr = *interpolationAddrPtr_;
00085 
00086         weightsPtr_ =
00087             new scalarListList
00088             (
00089                 scalarListList::subList(faceMap_.weights(), size())
00090             );
00091         scalarListList& w = *weightsPtr_;
00092         
00093         // Adjust for creation of an internal face from a boundary face
00094         forAll (addr, faceI)
00095         {
00096             if (max(addr[faceI]) >= oldNInternal)
00097             {
00098                 addr[faceI] = labelList(1, 0);
00099                 w[faceI] = scalarList(1, 1.0);
00100             }
00101         }
00102     }
00103 
00104     // Inserted objects
00105 
00106     // If there are, assemble the labels
00107     if (insertedObjects())
00108     {
00109         const labelList& insFaces = faceMap_.insertedObjectLabels();
00110 
00111         insertedObjectLabelsPtr_ = new labelList(insFaces.size());
00112         labelList& ins = *insertedObjectLabelsPtr_;
00113 
00114         label nIns = 0;
00115 
00116         forAll (insFaces, faceI)
00117         {
00118             // If the face is internal, keep it here
00119             if (insFaces[faceI] < size())
00120             {
00121                 ins[nIns] = insFaces[faceI];
00122                 nIns++;
00123             }
00124         }
00125 
00126         ins.setSize(nIns);
00127     }
00128     else
00129     {
00130         // No inserted objects
00131         insertedObjectLabelsPtr_ = new labelList(0);
00132     }
00133 }
00134 
00135 
00136 void Foam::fvSurfaceMapper::clearOut()
00137 {
00138     deleteDemandDrivenData(directAddrPtr_);
00139     deleteDemandDrivenData(interpolationAddrPtr_);
00140     deleteDemandDrivenData(weightsPtr_);
00141 
00142     deleteDemandDrivenData(insertedObjectLabelsPtr_);
00143 }
00144 
00145 
00146 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00147 
00148 // Construct from components
00149 Foam::fvSurfaceMapper::fvSurfaceMapper
00150 (
00151     const fvMesh& mesh,
00152     const faceMapper& fMapper
00153 )
00154 :
00155     mesh_(mesh),
00156     faceMap_(fMapper),
00157     directAddrPtr_(NULL),
00158     interpolationAddrPtr_(NULL),
00159     weightsPtr_(NULL),
00160     insertedObjectLabelsPtr_(NULL)
00161 {}
00162 
00163 
00164 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00165 
00166 Foam::fvSurfaceMapper::~fvSurfaceMapper()
00167 {
00168     clearOut();
00169 }
00170 
00171 
00172 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00173 
00174 const Foam::unallocLabelList& Foam::fvSurfaceMapper::directAddressing() const
00175 {
00176     if (!direct())
00177     {
00178         FatalErrorIn
00179         (
00180             "const unallocLabelList& fvSurfaceMapper::"
00181             "directAddressing() const"
00182         )   << "Requested direct addressing for an interpolative mapper."
00183             << abort(FatalError);
00184     }
00185 
00186     if (!directAddrPtr_)
00187     {
00188         calcAddressing();
00189     }
00190 
00191     return *directAddrPtr_;
00192 }
00193 
00194 
00195 const Foam::labelListList& Foam::fvSurfaceMapper::addressing() const
00196 {
00197     if (direct())
00198     {
00199         FatalErrorIn
00200         (
00201             "const labelListList& fvSurfaceMapper::addressing() const"
00202         )   << "Requested interpolative addressing for a direct mapper."
00203             << abort(FatalError);
00204     }
00205 
00206     if (!interpolationAddrPtr_)
00207     {
00208         calcAddressing();
00209     }
00210 
00211     return *interpolationAddrPtr_;
00212 }
00213 
00214 
00215 const Foam::scalarListList& Foam::fvSurfaceMapper::weights() const
00216 {
00217     if (direct())
00218     {
00219         FatalErrorIn
00220         (
00221             "const scalarListList& fvSurfaceMapper::weights() const"
00222         )   << "Requested interpolative weights for a direct mapper."
00223             << abort(FatalError);
00224     }
00225 
00226     if (!weightsPtr_)
00227     {
00228         calcAddressing();
00229     }
00230 
00231     return *weightsPtr_;
00232 }
00233 
00234 
00235 const Foam::labelList& Foam::fvSurfaceMapper::insertedObjectLabels() const
00236 {
00237     if (!insertedObjectLabelsPtr_)
00238     {
00239         calcAddressing();
00240     }
00241 
00242     return *insertedObjectLabelsPtr_;
00243 }
00244 
00245 
00246 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00247 
00248 
00249 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
00250 
00251 
00252 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00253 
00254 
00255 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd