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

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