OpenFOAM logo
Open Source CFD Toolkit

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-2005 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 Class
00026     topoSetSource
00027 
00028 Description
00029     Base class of source for a topoSet. Implementer has to modify
00030     the given set (see applyToSet) according to its function and the
00031     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 "pointField.H"
00042 #include "word.H"
00043 #include "labelList.H"
00044 #include "faceList.H"
00045 #include "typeInfo.H"
00046 #include "runTimeSelectionTables.H"
00047 #include "autoPtr.H"
00048 #include "NamedEnum.H"
00049 #include "HashTable.H"
00050 
00051 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00052 
00053 namespace Foam
00054 {
00055 
00056 // Class forward declarations
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         };
00081 
00082 protected:
00083 
00084         //- Class with constructor to add usage string to table.
00085         static HashTable<string>* usageTablePtr_;
00086 
00087         class addToUsageTable
00088         {
00089         public:
00090 
00091             addToUsageTable(const word& name, const string& msg)
00092             {
00093                 if (!usageTablePtr_)
00094                 {
00095                     usageTablePtr_ = new HashTable<string>();
00096                 }
00097                 usageTablePtr_->insert(name, msg);
00098             }
00099         };
00100 
00101 
00102     // Protected data
00103 
00104         const polyMesh& mesh_;
00105 
00106         //- Add (if bool) cellI to set or delete cellI from set.
00107         void addOrDelete(topoSet& set, const label cellI, const bool) const;
00108 
00109 
00110 private:
00111 
00112         static const NamedEnum<setAction, 7> actionNames_;
00113 
00114         static const string illegalSource_;
00115 
00116 
00117     // Private Member Functions
00118 
00119         //- Disallow default bitwise copy construct
00120         topoSetSource(const topoSetSource&);
00121 
00122         //- Disallow default bitwise assignment
00123         void operator=(const topoSetSource&);
00124 
00125 
00126 public:
00127 
00128     //- Runtime type information
00129     TypeName("topoSetSource");
00130 
00131 
00132     // Static Functions
00133 
00134         //- Convert string to action
00135         static setAction toAction(const word& actionName)
00136         {
00137             return actionNames_[actionName];
00138         }
00139 
00140         //- Check state of stream.
00141         static Istream& checkIs(Istream& is);
00142 
00143     // Declare run-time constructor selection table
00144 
00145         // For the dictionary constructor
00146         declareRunTimeSelectionTable
00147         (
00148             autoPtr,
00149             topoSetSource,
00150             word,
00151             (
00152                 const polyMesh& mesh,
00153                 const dictionary& dict
00154             ),
00155             (mesh, dict)
00156         );
00157 
00158         // For the Istream constructor
00159         declareRunTimeSelectionTable
00160         (
00161             autoPtr,
00162             topoSetSource,
00163             istream,
00164             (
00165                 const polyMesh& mesh,
00166                 Istream& is
00167             ),
00168             (mesh, is)
00169         );
00170 
00171 
00172         //- Class used for the read-construction of
00173         //  PtrLists of topoSetSource
00174         class iNew
00175         {
00176             const polyMesh& mesh_;
00177 
00178         public:
00179 
00180             iNew(const polyMesh& mesh)
00181             :
00182                 mesh_(mesh)
00183             {}
00184 
00185             autoPtr<topoSetSource> operator()(Istream& is) const
00186             {
00187                 word topoSetSourceType(is);
00188                 dictionary dict(is);                    
00189                 return topoSetSource::New(topoSetSourceType, mesh_, dict);
00190             }
00191         };
00192 
00193 
00194         static const string& usage(const word& name)
00195         {
00196             if (!usageTablePtr_)
00197             {
00198                 usageTablePtr_ = new HashTable<string>();
00199             }
00200 
00201             const HashTable<string>& usageTable = *usageTablePtr_;
00202 
00203             if (usageTable.found(name))
00204             {
00205                 return usageTable[name];
00206             }
00207             else
00208             {
00209                 return illegalSource_;
00210             }
00211         }
00212 
00213 
00214     // Constructors
00215 
00216         //- Construct from components
00217         topoSetSource(const polyMesh& mesh);
00218 
00219         //- Clone
00220         autoPtr<topoSetSource> clone() const
00221         {
00222             notImplemented("autoPtr<topoSetSource> clone() const");
00223             return autoPtr<topoSetSource>(NULL);
00224         }
00225 
00226 
00227     // Selectors
00228 
00229         //- Return a reference to the selected topoSetSource
00230         static autoPtr<topoSetSource> New
00231         (
00232             const word& topoSetSourceType,
00233             const polyMesh& mesh,
00234             const dictionary& dict
00235         );
00236 
00237         //- Return a reference to the selected topoSetSource
00238         static autoPtr<topoSetSource> New
00239         (
00240             const word& topoSetSourceType,
00241             const polyMesh& mesh,
00242             Istream& is
00243         );
00244 
00245 
00246     // Destructor
00247 
00248         virtual ~topoSetSource();
00249 
00250 
00251     // Member Functions
00252 
00253         const polyMesh& mesh() const
00254         {
00255             return mesh_;
00256         }
00257 
00258 
00259     // Member Functions
00260 
00261         virtual void applyToSet(const setAction action, topoSet&) const = 0;
00262 
00263 };
00264 
00265 
00266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00267 
00268 } // End namespace Foam
00269 
00270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00271 
00272 #endif
00273 
00274 // ************************************************************************* //
For further information go to www.openfoam.org