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

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