FreeFOAM The Cross-Platform CFD Toolkit
topoSetSource.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::topoSetSource
26 
27 Description
28  Base class of a source for a topoSet.
29 
30  Implementer has to modify the given set (see applyToSet) according to
31  its function and the setAction (one of add/delete/new)
32 
33 SourceFiles
34  topoSetSource.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef topoSetSource_H
39 #define topoSetSource_H
40 
41 #include <OpenFOAM/pointField.H>
42 #include <OpenFOAM/word.H>
43 #include <OpenFOAM/labelList.H>
44 #include <OpenFOAM/faceList.H>
45 #include <OpenFOAM/typeInfo.H>
47 #include <OpenFOAM/autoPtr.H>
48 #include <OpenFOAM/NamedEnum.H>
49 #include <OpenFOAM/HashTable.H>
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 
56 // Forward declaration of classes
57 class polyMesh;
58 class topoSet;
59 
60 /*---------------------------------------------------------------------------*\
61  Class topoSetSource Declaration
62 \*---------------------------------------------------------------------------*/
63 
65 {
66 public:
67 
68  // Public data types
69 
70  //- Enumeration defining the valid actions
71  enum setAction
72  {
74  NEW,
76  ADD,
81  };
82 
83 protected:
84 
85  //- A table of usage strings
87 
88  //- Class with constructor to add usage string to table
90  {
91  public:
92 
93  addToUsageTable(const word& name, const string& msg)
94  {
95  if (!usageTablePtr_)
96  {
98  }
99  usageTablePtr_->insert(name, msg);
100  }
101 
103  {
104  if (usageTablePtr_)
105  {
106  delete usageTablePtr_;
107  usageTablePtr_ = NULL;
108  }
109  }
110  };
111 
112 
113  // Protected data
114 
115  const polyMesh& mesh_;
116 
117  //- Add (if bool) cellI to set or delete cellI from set.
118  void addOrDelete(topoSet& set, const label cellI, const bool) const;
119 
120 
121 private:
122 
123  static const NamedEnum<setAction, 8> actionNames_;
124 
125  static const string illegalSource_;
126 
127 
128  // Private Member Functions
129 
130  //- Disallow default bitwise copy construct
132 
133  //- Disallow default bitwise assignment
134  void operator=(const topoSetSource&);
135 
136 
137 public:
138 
139  //- Runtime type information
140  TypeName("topoSetSource");
141 
142 
143  // Static Functions
144 
145  //- Convert string to action
146  static setAction toAction(const word& actionName)
147  {
148  return actionNames_[actionName];
149  }
150 
151  //- Check state of stream.
152  static Istream& checkIs(Istream& is);
153 
154  // Declare run-time constructor selection table
155 
156  // For the dictionary constructor
158  (
159  autoPtr,
161  word,
162  (
163  const polyMesh& mesh,
164  const dictionary& dict
165  ),
166  (mesh, dict)
167  );
168 
169  // For the Istream constructor
171  (
172  autoPtr,
174  istream,
175  (
176  const polyMesh& mesh,
177  Istream& is
178  ),
179  (mesh, is)
180  );
181 
182 
183  //- Class used for the read-construction of
184  // PtrLists of topoSetSource
185  class iNew
186  {
187  const polyMesh& mesh_;
188 
189  public:
190 
191  iNew(const polyMesh& mesh)
192  :
193  mesh_(mesh)
194  {}
195 
197  {
198  word topoSetSourceType(is);
199  dictionary dict(is);
200  return topoSetSource::New(topoSetSourceType, mesh_, dict);
201  }
202  };
203 
204 
205  static const string& usage(const word& name)
206  {
207  if (!usageTablePtr_)
208  {
210  }
211 
212  const HashTable<string>& usageTable = *usageTablePtr_;
213 
214  if (usageTable.found(name))
215  {
216  return usageTable[name];
217  }
218  else
219  {
220  return illegalSource_;
221  }
222  }
223 
224 
225  // Constructors
226 
227  //- Construct from components
228  topoSetSource(const polyMesh& mesh);
229 
230  //- Clone
232  {
233  notImplemented("autoPtr<topoSetSource> clone() const");
234  return autoPtr<topoSetSource>(NULL);
235  }
236 
237 
238  // Selectors
239 
240  //- Return a reference to the selected topoSetSource
242  (
243  const word& topoSetSourceType,
244  const polyMesh& mesh,
245  const dictionary& dict
246  );
247 
248  //- Return a reference to the selected topoSetSource
250  (
251  const word& topoSetSourceType,
252  const polyMesh& mesh,
253  Istream& is
254  );
255 
256 
257  // Destructor
258 
259  virtual ~topoSetSource();
260 
261 
262  // Member Functions
263 
264  const polyMesh& mesh() const
265  {
266  return mesh_;
267  }
268 
269 
270  // Member Functions
271 
272  virtual void applyToSet(const setAction action, topoSet&) const = 0;
273 
274 };
275 
276 
277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
278 
279 } // End namespace Foam
280 
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 
283 #endif
284 
285 // ************************ vim: set sw=4 sts=4 et: ************************ //