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

ZoneID.H

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 Class
00025     Foam::ZoneID
00026 
00027 Description
00028     A class that holds the data needed to identify a zone in a dynamic mesh.
00029 
00030     The zone is identified by name.
00031     Its index in the zoneMesh is updated if the mesh has changed.
00032 
00033 \*---------------------------------------------------------------------------*/
00034 
00035 #ifndef ZoneID_H
00036 #define ZoneID_H
00037 
00038 #include <OpenFOAM/label.H>
00039 #include <OpenFOAM/word.H>
00040 #include <OpenFOAM/polyMesh.H>
00041 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 namespace Foam
00045 {
00046 
00047 template<class ZoneType, class MeshType> class ZoneMesh;
00048 
00049 // Forward declaration of friend functions and operators
00050 
00051 template<class ZoneType> class ZoneID;
00052 
00053 template<class ZoneType>
00054 Ostream& operator<<(Ostream&, const ZoneID<ZoneType>&);
00055 
00056 /*---------------------------------------------------------------------------*\
00057                            Class ZoneID Declaration
00058 \*---------------------------------------------------------------------------*/
00059 
00060 template<class ZoneType>
00061 class ZoneID
00062 {
00063     // Private data
00064 
00065         //- Zone name
00066         word name_;
00067 
00068         //- Zone index
00069         label index_;
00070 
00071 
00072 public:
00073 
00074     // Constructors
00075 
00076         //- Construct from name
00077         ZoneID(const word& name, const ZoneMesh<ZoneType, polyMesh>& zm)
00078         :
00079             name_(name),
00080             index_(zm.findZoneID(name))
00081         {}
00082 
00083         //- Construct from Istream
00084         ZoneID(Istream& is, const ZoneMesh<ZoneType, polyMesh>& zm)
00085         :
00086             name_(is),
00087             index_(zm.findZoneID(name_))
00088         {}
00089 
00090 
00091     // Destructor - default
00092 
00093 
00094     // Member Functions
00095 
00096         // Access
00097 
00098             //- Return name
00099             const word& name() const
00100             {
00101                 return name_;
00102             }
00103 
00104             //- Return index
00105             label index() const
00106             {
00107                 return index_;
00108             }
00109 
00110             //- Has the zone been found
00111             bool active() const
00112             {
00113                 return index_ > -1;
00114             }
00115 
00116         // Edit
00117 
00118             //- Update
00119             void update(const ZoneMesh<ZoneType, polyMesh>& zm)
00120             {
00121                 index_ = zm.findZoneID(name_);
00122             }
00123 
00124 
00125     // IOstream Operators
00126 
00127         friend Ostream& operator<< <ZoneType>
00128         (
00129             Ostream& os, const ZoneID<ZoneType>& p
00130         );
00131 };
00132 
00133 
00134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00135 
00136 template<class ZoneType>
00137 Ostream& operator<<
00138 (
00139     Ostream& os, const ZoneID<ZoneType>& p
00140 )
00141 {
00142     os  << token::BEGIN_LIST
00143         << p.name_ << token::SPACE
00144         << p.index_
00145         << token::END_LIST;
00146 
00147     // Check state of Ostream
00148     os.check("Ostream& operator<<(Ostream&, const ZoneID<ZoneType>&)");
00149 
00150     return os;
00151 }
00152 
00153 
00154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00155 
00156 } // End namespace Foam
00157 
00158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00159 
00160 #endif
00161 
00162 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines