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

pointZone.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     A subset of mesh points.
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "pointZone.H"
00031 #include "addToRunTimeSelectionTable.H"
00032 #include "pointZoneMesh.H"
00033 #include "polyMesh.H"
00034 #include "primitiveMesh.H"
00035 #include "demandDrivenData.H"
00036 
00037 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00038 
00039 namespace Foam
00040 {
00041     defineTypeNameAndDebug(pointZone, 0);
00042     defineRunTimeSelectionTable(pointZone, dictionary);
00043     addToRunTimeSelectionTable(pointZone, pointZone, dictionary);
00044 }
00045 
00046 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00047 
00048 const Foam::Map<Foam::label>& Foam::pointZone::pointLookupMap() const
00049 {
00050     if (!pointLookupMapPtr_)
00051     {
00052         calcPointLookupMap();
00053     }
00054 
00055     return *pointLookupMapPtr_;
00056 }
00057 
00058 
00059 void Foam::pointZone::calcPointLookupMap() const
00060 {
00061     if (debug)
00062     {
00063         Info<< "void pointZone::calcPointLookupMap() const : "
00064             << "Calculating point lookup map"
00065             << endl;
00066     }
00067 
00068     if (pointLookupMapPtr_)
00069     {
00070         FatalErrorIn
00071         (
00072             "void pointZone::calcPointLookupMap() const"
00073         )   << "point lookup map already calculated"
00074             << abort(FatalError);
00075     }
00076 
00077     const labelList& addr = *this;
00078 
00079     pointLookupMapPtr_ = new Map<label>(2*addr.size());
00080     Map<label>& plm = *pointLookupMapPtr_;
00081 
00082     forAll (addr, pointI)
00083     {
00084         plm.insert(addr[pointI], pointI);
00085     }
00086 
00087     if (debug)
00088     {
00089         Info<< "void pointZone::calcPointLookupMap() const : "
00090             << "Finished calculating point lookup map"
00091             << endl;
00092     }
00093 }
00094 
00095 
00096 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00097 
00098 // Construct from components
00099 Foam::pointZone::pointZone
00100 (
00101     const word& name,
00102     const labelList& addr,
00103     const label index,
00104     const pointZoneMesh& zm
00105 )
00106 :
00107     labelList(addr),
00108     name_(name),
00109     index_(index),
00110     zoneMesh_(zm),
00111     pointLookupMapPtr_(NULL)
00112 {}
00113 
00114 
00115 Foam::pointZone::pointZone
00116 (
00117     const word& name,
00118     const Xfer<labelList>& addr,
00119     const label index,
00120     const pointZoneMesh& zm
00121 )
00122 :
00123     labelList(addr),
00124     name_(name),
00125     index_(index),
00126     zoneMesh_(zm),
00127     pointLookupMapPtr_(NULL)
00128 {}
00129 
00130 
00131 // Construct from dictionary
00132 Foam::pointZone::pointZone
00133 (
00134     const word& name,
00135     const dictionary& dict,
00136     const label index,
00137     const pointZoneMesh& zm
00138 )
00139 :
00140     labelList(dict.lookup("pointLabels")),
00141     name_(name),
00142     index_(index),
00143     zoneMesh_(zm),
00144     pointLookupMapPtr_(NULL)
00145 {}
00146 
00147 
00148 // Construct given the original zone and resetting the
00149 // point list and zone mesh information
00150 Foam::pointZone::pointZone
00151 (
00152     const pointZone& pz,
00153     const labelList& addr,
00154     const label index,
00155     const pointZoneMesh& zm
00156 )
00157 :
00158     labelList(addr),
00159     name_(pz.name()),
00160     index_(index),
00161     zoneMesh_(zm),
00162     pointLookupMapPtr_(NULL)
00163 {}
00164 
00165 
00166 Foam::pointZone::pointZone
00167 (
00168     const pointZone& pz,
00169     const Xfer<labelList>& addr,
00170     const label index,
00171     const pointZoneMesh& zm
00172 )
00173 :
00174     labelList(addr),
00175     name_(pz.name()),
00176     index_(index),
00177     zoneMesh_(zm),
00178     pointLookupMapPtr_(NULL)
00179 {}
00180 
00181 
00182 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00183 
00184 Foam::pointZone::~pointZone()
00185 {
00186     clearAddressing();
00187 }
00188 
00189 
00190 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00191 
00192 Foam::label Foam::pointZone::whichPoint(const label globalPointID) const
00193 {
00194     const Map<label>& plm = pointLookupMap();
00195 
00196     Map<label>::const_iterator plmIter = plm.find(globalPointID);
00197 
00198     if (plmIter == plm.end())
00199     {
00200         return -1;
00201     }
00202     else
00203     {
00204         return plmIter();
00205     }
00206 }
00207 
00208 
00209 const Foam::pointZoneMesh& Foam::pointZone::zoneMesh() const
00210 {
00211     return zoneMesh_;
00212 }
00213 
00214 
00215 void Foam::pointZone::clearAddressing()
00216 {
00217     deleteDemandDrivenData(pointLookupMapPtr_);
00218 }
00219 
00220 
00221 bool Foam::pointZone::checkDefinition(const bool report) const
00222 {
00223     const labelList& addr = *this;
00224 
00225     bool boundaryError = false;
00226 
00227     forAll(addr, i)
00228     {
00229         if (addr[i] < 0 || addr[i] >= zoneMesh_.mesh().points().size())
00230         {
00231             boundaryError = true;
00232 
00233             if (report)
00234             {
00235                 SeriousErrorIn
00236                 (
00237                     "bool pointZone::checkDefinition("
00238                     "const bool report) const"
00239                 )   << "Zone " << name()
00240                     << " contains invalid point label " << addr[i] << nl
00241                     << "Valid point labels are 0.."
00242                     << zoneMesh_.mesh().points().size()-1 << endl;
00243             }
00244         }
00245     }
00246     return boundaryError;
00247 }
00248 
00249 
00250 void Foam::pointZone::write(Ostream& os) const
00251 {
00252     os  << nl << name()
00253         << nl << static_cast<const labelList&>(*this);
00254 }
00255 
00256 
00257 void Foam::pointZone::writeDict(Ostream& os) const
00258 {
00259     os  << nl << name() << nl << token::BEGIN_BLOCK << nl
00260         << "    type " << type() << token::END_STATEMENT << nl;
00261 
00262     writeEntry("pointLabels", os);
00263 
00264     os  << token::END_BLOCK << endl;
00265 }
00266 
00267 
00268 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00269 
00270 void Foam::pointZone::operator=(const pointZone& cz)
00271 {
00272     clearAddressing();
00273     labelList::operator=(cz);
00274 }
00275 
00276 
00277 void Foam::pointZone::operator=(const labelList& addr)
00278 {
00279     clearAddressing();
00280     labelList::operator=(addr);
00281 }
00282 
00283 
00284 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
00285 
00286 Foam::Ostream& Foam::operator<<(Ostream& os, const pointZone& p)
00287 {
00288     p.write(os);
00289     os.check("Ostream& operator<<(Ostream& f, const pointZone& p");
00290     return os;
00291 }
00292 
00293 
00294 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd