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

topoSetSource.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::topoSetSource
00026 
00027 Description
00028     Base class of a source for a topoSet.
00029 
00030     Implementer has to modify the given set (see applyToSet) according to
00031     its function and the setAction (one of add/delete/new)
00032 
00033 SourceFiles
00034     topoSetSource.C
00035 
00036 \*---------------------------------------------------------------------------*/
00037 
00038 #ifndef topoSetSource_H
00039 #define topoSetSource_H
00040 
00041 #include <OpenFOAM/pointField.H>
00042 #include <OpenFOAM/word.H>
00043 #include <OpenFOAM/labelList.H>
00044 #include <OpenFOAM/faceList.H>
00045 #include <OpenFOAM/typeInfo.H>
00046 #include <OpenFOAM/runTimeSelectionTables.H>
00047 #include <OpenFOAM/autoPtr.H>
00048 #include <OpenFOAM/NamedEnum.H>
00049 #include <OpenFOAM/HashTable.H>
00050 
00051 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00052 
00053 namespace Foam
00054 {
00055 
00056 // Forward declaration of classes
00057 class polyMesh;
00058 class topoSet;
00059 
00060 /*---------------------------------------------------------------------------*\
00061                            Class topoSetSource Declaration
00062 \*---------------------------------------------------------------------------*/
00063 
00064 class topoSetSource
00065 {
00066 public:
00067 
00068     // Public data types
00069 
00070         //- Enumeration defining the valid actions
00071         enum setAction
00072         {
00073             CLEAR,
00074             NEW,
00075             INVERT,
00076             ADD,
00077             DELETE,
00078             SUBSET,
00079             LIST,
00080             REMOVE
00081         };
00082 
00083 protected:
00084 
00085         //- A table of usage strings
00086         static HashTable<string>* usageTablePtr_;
00087 
00088         //- Class with constructor to add usage string to table
00089         class addToUsageTable
00090         {
00091         public:
00092 
00093             addToUsageTable(const word& name, const string& msg)
00094             {
00095                 if (!usageTablePtr_)
00096                 {
00097                     usageTablePtr_ = new HashTable<string>();
00098                 }
00099                 usageTablePtr_->insert(name, msg);
00100             }
00101 
00102             ~addToUsageTable()
00103             {
00104                 if (usageTablePtr_)
00105                 {
00106                     delete usageTablePtr_;
00107                     usageTablePtr_ = NULL;
00108                 }
00109             }
00110         };
00111 
00112 
00113     // Protected data
00114 
00115         const polyMesh& mesh_;
00116 
00117         //- Add (if bool) cellI to set or delete cellI from set.
00118         void addOrDelete(topoSet& set, const label cellI, const bool) const;
00119 
00120 
00121 private:
00122 
00123         static const NamedEnum<setAction, 8> actionNames_;
00124 
00125         static const string illegalSource_;
00126 
00127 
00128     // Private Member Functions
00129 
00130         //- Disallow default bitwise copy construct
00131         topoSetSource(const topoSetSource&);
00132 
00133         //- Disallow default bitwise assignment
00134         void operator=(const topoSetSource&);
00135 
00136 
00137 public:
00138 
00139     //- Runtime type information
00140     TypeName("topoSetSource");
00141 
00142 
00143     // Static Functions
00144 
00145         //- Convert string to action
00146         static setAction toAction(const word& actionName)
00147         {
00148             return actionNames_[actionName];
00149         }
00150 
00151         //- Check state of stream.
00152         static Istream& checkIs(Istream& is);
00153 
00154     // Declare run-time constructor selection table
00155 
00156         // For the dictionary constructor
00157         declareRunTimeSelectionTable
00158         (
00159             autoPtr,
00160             topoSetSource,
00161             word,
00162             (
00163                 const polyMesh& mesh,
00164                 const dictionary& dict
00165             ),
00166             (mesh, dict)
00167         );
00168 
00169         // For the Istream constructor
00170         declareRunTimeSelectionTable
00171         (
00172             autoPtr,
00173             topoSetSource,
00174             istream,
00175             (
00176                 const polyMesh& mesh,
00177                 Istream& is
00178             ),
00179             (mesh, is)
00180         );
00181 
00182 
00183         //- Class used for the read-construction of
00184         //  PtrLists of topoSetSource
00185         class iNew
00186         {
00187             const polyMesh& mesh_;
00188 
00189         public:
00190 
00191             iNew(const polyMesh& mesh)
00192             :
00193                 mesh_(mesh)
00194             {}
00195 
00196             autoPtr<topoSetSource> operator()(Istream& is) const
00197             {
00198                 word topoSetSourceType(is);
00199                 dictionary dict(is);
00200                 return topoSetSource::New(topoSetSourceType, mesh_, dict);
00201             }
00202         };
00203 
00204 
00205         static const string& usage(const word& name)
00206         {
00207             if (!usageTablePtr_)
00208             {
00209                 usageTablePtr_ = new HashTable<string>();
00210             }
00211 
00212             const HashTable<string>& usageTable = *usageTablePtr_;
00213 
00214             if (usageTable.found(name))
00215             {
00216                 return usageTable[name];
00217             }
00218             else
00219             {
00220                 return illegalSource_;
00221             }
00222         }
00223 
00224 
00225     // Constructors
00226 
00227         //- Construct from components
00228         topoSetSource(const polyMesh& mesh);
00229 
00230         //- Clone
00231         autoPtr<topoSetSource> clone() const
00232         {
00233             notImplemented("autoPtr<topoSetSource> clone() const");
00234             return autoPtr<topoSetSource>(NULL);
00235         }
00236 
00237 
00238     // Selectors
00239 
00240         //- Return a reference to the selected topoSetSource
00241         static autoPtr<topoSetSource> New
00242         (
00243             const word& topoSetSourceType,
00244             const polyMesh& mesh,
00245             const dictionary& dict
00246         );
00247 
00248         //- Return a reference to the selected topoSetSource
00249         static autoPtr<topoSetSource> New
00250         (
00251             const word& topoSetSourceType,
00252             const polyMesh& mesh,
00253             Istream& is
00254         );
00255 
00256 
00257     // Destructor
00258 
00259         virtual ~topoSetSource();
00260 
00261 
00262     // Member Functions
00263 
00264         const polyMesh& mesh() const
00265         {
00266             return mesh_;
00267         }
00268 
00269 
00270     // Member Functions
00271 
00272         virtual void applyToSet(const setAction action, topoSet&) const = 0;
00273 
00274 };
00275 
00276 
00277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00278 
00279 } // End namespace Foam
00280 
00281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00282 
00283 #endif
00284 
00285 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines