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

pointPatchMapper.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 \*---------------------------------------------------------------------------*/
00025 
00026 #include "pointPatchMapper.H"
00027 #include <OpenFOAM/pointPatch.H>
00028 #include <OpenFOAM/mapPolyMesh.H>
00029 #include <OpenFOAM/faceMapper.H>
00030 #include <OpenFOAM/demandDrivenData.H>
00031 
00032 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00033 
00034 void Foam::pointPatchMapper::calcAddressing() const
00035 {
00036     if
00037     (
00038         directAddrPtr_
00039      || interpolationAddrPtr_
00040      || weightsPtr_
00041     )
00042     {
00043         FatalErrorIn
00044         (
00045             "void pointPatchMapper::calcAddressing() const"
00046         )   << "Addressing already calculated"
00047             << abort(FatalError);
00048     }
00049 
00050     if (direct())
00051     {
00052         // Direct mapping.
00053         directAddrPtr_ = new labelList(mpm_.patchPointMap()[patch_.index()]);
00054         labelList& addr = *directAddrPtr_;
00055 
00056         forAll(addr, i)
00057         {
00058             if (addr[i] < 0)
00059             {
00060                 addr[i] = 0;
00061             }
00062         }
00063     }
00064     else
00065     {
00066         // Interpolative mapping.
00067 
00068         // NOTE: Incorrect:
00069         // FOR NOW only takes first patch point instead of averaging all
00070         // patch points. Problem is we don't know what points were in the patch
00071         // for points that were merged.
00072 
00073         interpolationAddrPtr_ = new labelListList(size());
00074         labelListList& addr = *interpolationAddrPtr_;
00075 
00076         weightsPtr_ = new scalarListList(addr.size());
00077         scalarListList& w = *weightsPtr_;
00078 
00079         const labelList& ppm = mpm_.patchPointMap()[patch_.index()];
00080 
00081         forAll(ppm, i)
00082         {
00083             if (ppm[i] >= 0)
00084             {
00085                 addr[i] = labelList(1, ppm[i]);
00086                 w[i] = scalarList(1, 1.0);
00087             }
00088             else
00089             {
00090                 // Inserted point. Map from point0 (arbitrary choice)
00091                 addr[i] = labelList(1, 0);
00092                 w[i] = scalarList(1, 1.0);
00093             }
00094         }
00095     }
00096 }
00097 
00098 
00099 void Foam::pointPatchMapper::clearOut()
00100 {
00101     deleteDemandDrivenData(directAddrPtr_);
00102     deleteDemandDrivenData(interpolationAddrPtr_);
00103     deleteDemandDrivenData(weightsPtr_);
00104 }
00105 
00106 
00107 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00108 
00109 // Construct from components
00110 Foam::pointPatchMapper::pointPatchMapper
00111 (
00112     const pointPatch& patch,
00113     const pointMapper& pointMap,
00114     const mapPolyMesh& mpm
00115 )
00116 :
00117     pointPatchFieldMapper(),
00118     patch_(patch),
00119     pointMapper_(pointMap),
00120     mpm_(mpm),
00121     sizeBeforeMapping_
00122     (
00123         patch_.index() < mpm_.oldPatchNMeshPoints().size()
00124       ? mpm_.oldPatchNMeshPoints()[patch_.index()]
00125       : 0
00126     ),
00127     directAddrPtr_(NULL),
00128     interpolationAddrPtr_(NULL),
00129     weightsPtr_(NULL)
00130 {}
00131 
00132 
00133 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00134 
00135 Foam::pointPatchMapper::~pointPatchMapper()
00136 {
00137     clearOut();
00138 }
00139 
00140 
00141 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00142 
00143 const Foam::unallocLabelList& Foam::pointPatchMapper::directAddressing() const
00144 {
00145     if (!direct())
00146     {
00147         FatalErrorIn
00148         (
00149             "const unallocLabelList& pointPatchMapper::directAddressing() const"
00150         )   << "Requested direct addressing for an interpolative mapper."
00151             << abort(FatalError);
00152     }
00153 
00154     if (!directAddrPtr_)
00155     {
00156         calcAddressing();
00157     }
00158 
00159     return *directAddrPtr_;
00160 }
00161 
00162 
00163 const Foam::labelListList& Foam::pointPatchMapper::addressing() const
00164 {
00165     if (direct())
00166     {
00167         FatalErrorIn
00168         (
00169             "const labelListList& pointPatchMapper::addressing() const"
00170         )   << "Requested interpolative addressing for a direct mapper."
00171             << abort(FatalError);
00172     }
00173 
00174     if (!interpolationAddrPtr_)
00175     {
00176         calcAddressing();
00177     }
00178 
00179     return *interpolationAddrPtr_;
00180 }
00181 
00182 
00183 const Foam::scalarListList& Foam::pointPatchMapper::weights() const
00184 {
00185     if (direct())
00186     {
00187         FatalErrorIn
00188         (
00189             "const scalarListList& pointPatchMapper::weights() const"
00190         )   << "Requested interpolative weights for a direct mapper."
00191             << abort(FatalError);
00192     }
00193 
00194     if (!weightsPtr_)
00195     {
00196         calcAddressing();
00197     }
00198 
00199     return *weightsPtr_;
00200 }
00201 
00202 
00203 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00204 
00205 
00206 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
00207 
00208 
00209 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00210 
00211 
00212 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines