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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2018-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::topoSetSource
29 
30 Description
31  Base class of a source for a \c topoSet.
32 
33  Implementer must modify the given set (see \c applyToSet) according to
34  its function and the \c setAction (one of add/delete/new).
35 
36 SourceFiles
37  topoSetSource.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef topoSetSource_H
42 #define topoSetSource_H
43 
44 #include "pointField.H"
45 #include "labelList.H"
46 #include "faceList.H"
47 #include "typeInfo.H"
48 #include "autoPtr.H"
49 #include "Enum.H"
50 #include "HashTable.H"
51 #include "runTimeSelectionTables.H"
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 namespace Foam
56 {
57 
58 // Forward Declarations
59 class polyMesh;
60 class bitSet;
61 class topoSet;
62 
63 /*---------------------------------------------------------------------------*\
64  Class topoSetSource Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 class topoSetSource
68 {
69 public:
70 
71  // Public Data Types
72 
73  //- Enumeration defining the types of sources
74  enum sourceType
75  {
77  SET_SOURCE = 0x10,
78  ZONE_SOURCE = 0x20,
79  CELL_TYPE = 0x1,
80  FACE_TYPE = 0x2,
81  POINT_TYPE = 0x4,
82 
86 
90 
91  CELLSETSOURCE = CELLSET_SOURCE, // Compat (2019-11)
92  FACESETSOURCE = FACESET_SOURCE, // Compat (2019-11)
93  POINTSETSOURCE = POINTSET_SOURCE, // Compat (2019-11)
94  CELLZONESOURCE = CELLZONE_SOURCE, // Compat (2019-11)
95  FACEZONESOURCE = FACEZONE_SOURCE, // Compat (2019-11)
96  POINTZONESOURCE = POINTZONE_SOURCE, // Compat (2019-11)
97  };
98 
99  //- Enumeration defining the valid actions
100  enum setAction
101  {
102  ADD,
107  NEW,
110  DELETE = SUBTRACT,
111  };
112 
113  //- The setActions text representations
114  static const Enum<setAction> actionNames;
115 
116 
117 protected:
118 
119  static const string illegalSource_;
120 
121  //- A table of usage strings
123 
124  //- Class with constructor to add usage string to table
125  class addToUsageTable
126  {
127  public:
128 
129  addToUsageTable(const word& name, const string& msg)
130  {
131  if (!usageTablePtr_)
132  {
134  }
135  usageTablePtr_->insert(name, msg);
136  }
137 
139  {
140  if (usageTablePtr_)
141  {
142  delete usageTablePtr_;
143  usageTablePtr_ = nullptr;
144  }
145  }
146  };
147 
148 
149  // Protected Data
150 
151  //- Reference to the mesh
152  const polyMesh& mesh_;
153 
154  //- Verbosity (default: true)
155  bool verbose_;
156 
157 
158  // Protected Member Functions
159 
160  //- Detect and remove any values less than 0 or ge maxLabel.
161  // \return false if invalid elements were detected (and removed)
162  static bool check(labelList& list, const label maxLabel);
163 
164  //- Add or delete id from set. Add when 'add' is true
165  void addOrDelete(topoSet& set, const label id, const bool add) const;
166 
167  //- Add or delete labels from set. Add when 'add' is true
168  void addOrDelete
169  (
170  topoSet& set,
171  const labelUList& labels,
172  const bool add
173  ) const;
174 
175  //- Add or delete labels from set. Add when 'add' is true
176  void addOrDelete
177  (
178  topoSet& set,
179  const bitSet& labels,
180  const bool add
181  ) const;
182 
183 
184  //- No copy construct
185  topoSetSource(const topoSetSource&) = delete;
186 
187  //- No copy assignment
188  void operator=(const topoSetSource&) = delete;
189 
190 
191 public:
192 
193  //- Runtime type information
194  TypeName("topoSetSource");
195 
196 
197  // Static Functions
198 
199  //- Check state of stream.
200  static Istream& checkIs(Istream& is);
201 
202  //- True if a "set" source
203  static inline bool isSetSource(const sourceType t)
204  {
205  return (t & SET_SOURCE);
206  }
207 
208  //- True if a "zone" source
209  static inline bool isZoneSource(const sourceType t)
210  {
211  return (t & ZONE_SOURCE);
212  }
213 
214  //- True if "cell" geometric type
215  static inline bool isCell(const sourceType t)
216  {
217  return (t & CELL_TYPE);
218  }
219 
220  //- True if "face" geometric type
221  static inline bool isFace(const sourceType t)
222  {
223  return (t & FACE_TYPE);
224  }
225 
226  //- True if "point" geometric type
227  static inline bool isPoint(const sourceType t)
228  {
229  return (t & POINT_TYPE);
230  }
231 
232 
233  // Declare run-time constructor selection table
234 
235  // For the dictionary constructor
237  (
238  autoPtr,
240  word,
241  (
242  const polyMesh& mesh,
243  const dictionary& dict
244  ),
245  (mesh, dict)
246  );
247 
248  // For the Istream constructor
250  (
251  autoPtr,
253  istream,
254  (
255  const polyMesh& mesh,
256  Istream& is
257  ),
258  (mesh, is)
259  );
260 
261 
262  //- Class used for the read-construction of
263  // PtrLists of topoSetSource
264  class iNew
265  {
266  const polyMesh& mesh_;
267 
268  public:
269 
270  iNew(const polyMesh& mesh)
271  :
272  mesh_(mesh)
273  {}
274 
276  {
277  const word sourceTypeName(is);
278  dictionary dict(is);
279  return topoSetSource::New(sourceTypeName, mesh_, dict);
280  }
281  };
282 
283 
284  static const string& usage(const word& name)
285  {
286  if (!usageTablePtr_)
287  {
289  }
290 
291  return usageTablePtr_->lookup(name, illegalSource_);
292  }
293 
294 
295  // Constructors
296 
297  //- Construct from components
298  explicit topoSetSource(const polyMesh& mesh);
299 
300  //- Clone (disallowed)
302  {
304  return nullptr;
305  }
306 
307 
308  // Selectors
309 
310  //- Return a reference to the selected topoSetSource
312  (
313  const word& topoSetSourceType,
314  const polyMesh& mesh,
315  const dictionary& dict
316  );
317 
318  //- Return a reference to the selected topoSetSource
320  (
321  const word& topoSetSourceType,
322  const polyMesh& mesh,
323  Istream& is
324  );
325 
326 
327  //- Destructor
328  virtual ~topoSetSource() = default;
329 
330 
331  // Member Functions
332 
333  //- Reference to the mesh
334  const polyMesh& mesh() const
335  {
336  return mesh_;
337  }
338 
339  //- Return the current verbosity
340  bool verbose() const
341  {
342  return verbose_;
343  }
344 
345  //- Set the current verbosity
346  void verbose(bool on)
347  {
348  verbose_ = on;
349  }
350 
351 
352  // Member Functions
353 
354  //- The source category (set/zone, cell/face/point)
355  virtual sourceType setType() const = 0;
356 
357  //- Apply specified action to the topoSet
358  virtual void applyToSet
359  (
360  const topoSetSource::setAction action,
361  topoSet& set
362  ) const = 0;
363 
364 
365  // Housekeeping
366 
367  //- Deprecated(2018-07) convert string to action
368  // \deprecated(2018-07) - use actionNames[] directly
369  static setAction toAction(const word& actionName)
370  {
371  return actionNames[actionName];
372  }
373 };
374 
375 
376 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
377 
378 } // End namespace Foam
379 
380 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
381 
382 #endif
383 
384 // ************************************************************************* //
Foam::topoSetSource::verbose
void verbose(bool on)
Set the current verbosity.
Definition: topoSetSource.H:345
Foam::topoSetSource::POINTZONE_SOURCE
Points as zone.
Definition: topoSetSource.H:88
Foam::topoSetSource::iNew::operator()
autoPtr< topoSetSource > operator()(Istream &is) const
Definition: topoSetSource.H:274
Foam::topoSetSource::usageTablePtr_
static HashTable< string > * usageTablePtr_
A table of usage strings.
Definition: topoSetSource.H:121
Foam::topoSetSource::sourceType
sourceType
Enumeration defining the types of sources.
Definition: topoSetSource.H:73
Foam::topoSetSource::ADD
Add elements to the set.
Definition: topoSetSource.H:101
Foam::Enum< setAction >
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::topoSetSource::CLEAR
Clear the set, possibly creating it.
Definition: topoSetSource.H:105
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
HashTable.H
Foam::topoSetSource::FACESETSOURCE
Definition: topoSetSource.H:91
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::topoSetSource::addToUsageTable::~addToUsageTable
~addToUsageTable()
Definition: topoSetSource.H:137
typeInfo.H
Foam::topoSetSource::toAction
static setAction toAction(const word &actionName)
Deprecated(2018-07) convert string to action.
Definition: topoSetSource.H:368
Foam::topoSetSource::CELL_TYPE
Geometric type is "cell".
Definition: topoSetSource.H:78
Foam::topoSetSource::isZoneSource
static bool isZoneSource(const sourceType t)
True if a "zone" source.
Definition: topoSetSource.H:208
Foam::topoSetSource::FACEZONESOURCE
Definition: topoSetSource.H:94
Foam::topoSetSource::POINTZONESOURCE
Definition: topoSetSource.H:95
Foam::topoSetSource::usage
static const string & usage(const word &name)
Definition: topoSetSource.H:283
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:124
Foam::topoSetSource::isCell
static bool isCell(const sourceType t)
True if "cell" geometric type.
Definition: topoSetSource.H:214
Foam::topoSetSource::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const =0
Apply specified action to the topoSet.
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:99
Foam::topoSetSource::illegalSource_
static const string illegalSource_
Definition: topoSetSource.H:118
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:106
faceList.H
Foam::topoSetSource::mesh
const polyMesh & mesh() const
Reference to the mesh.
Definition: topoSetSource.H:333
Foam::topoSetSource::CELLZONE_SOURCE
Cells as zone.
Definition: topoSetSource.H:86
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::topoSetSource::CELLSET_SOURCE
Cells as set.
Definition: topoSetSource.H:82
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:445
Foam::topoSetSource::ZONE_SOURCE
Source based on mesh zone.
Definition: topoSetSource.H:77
Foam::topoSetSource::FACESET_SOURCE
Faces as set.
Definition: topoSetSource.H:83
Foam::topoSetSource::verbose_
bool verbose_
Verbosity (default: true)
Definition: topoSetSource.H:154
Foam::topoSetSource::POINTSETSOURCE
Definition: topoSetSource.H:92
labelList.H
Foam::topoSetSource::FACE_TYPE
Geometric type is "face".
Definition: topoSetSource.H:79
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::topoSetSource::CELLZONESOURCE
Definition: topoSetSource.H:93
Foam::topoSetSource::POINTSET_SOURCE
Points as set.
Definition: topoSetSource.H:84
Foam::topoSetSource::topoSetSource
topoSetSource(const topoSetSource &)=delete
No copy construct.
Foam::topoSetSource::DELETE
Definition: topoSetSource.H:109
Foam::topoSetSource::TypeName
TypeName("topoSetSource")
Runtime type information.
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
Foam::topoSetSource::check
static bool check(labelList &list, const label maxLabel)
Detect and remove any values less than 0 or ge maxLabel.
Definition: topoSetSource.C:73
Foam::topoSetSource::operator=
void operator=(const topoSetSource &)=delete
No copy assignment.
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::topoSetSource::SUBSET
Subset with elements in the set.
Definition: topoSetSource.H:103
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::topoSetSource::clone
autoPtr< topoSetSource > clone() const
Clone (disallowed)
Definition: topoSetSource.H:300
Foam::topoSetSource::CELLSETSOURCE
Definition: topoSetSource.H:90
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
Foam::topoSetSource::SUBTRACT
Subtract elements from the set.
Definition: topoSetSource.H:102
Foam::topoSetSource::isPoint
static bool isPoint(const sourceType t)
True if "point" geometric type.
Definition: topoSetSource.H:226
Foam::topoSetSource::New
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
Definition: topoSetSource.C:109
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::topoSetSource
Base class of a source for a topoSet.
Definition: topoSetSource.H:66
Foam::topoSetSource::iNew::iNew
iNew(const polyMesh &mesh)
Definition: topoSetSource.H:269
Foam::HashTable
A HashTable similar to std::unordered_map.
Definition: HashTable.H:105
Foam::topoSetSource::FACEZONE_SOURCE
Faces as zone.
Definition: topoSetSource.H:87
pointField.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::topoSetSource::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, topoSetSource, word,(const polyMesh &mesh, const dictionary &dict),(mesh, dict))
Foam::topoSetSource::isFace
static bool isFace(const sourceType t)
True if "face" geometric type.
Definition: topoSetSource.H:220
Foam::topoSetSource::LIST
Print contents of the set.
Definition: topoSetSource.H:108
Foam::topoSetSource::verbose
bool verbose() const
Return the current verbosity.
Definition: topoSetSource.H:339
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::List< label >
Foam::topoSetSource::checkIs
static Istream & checkIs(Istream &is)
Check state of stream.
Definition: topoSetSource.C:155
Foam::topoSetSource::setType
virtual sourceType setType() const =0
The source category (set/zone, cell/face/point)
Foam::UList< label >
Foam::topoSetSource::REMOVE
Remove the set (from the file system)
Definition: topoSetSource.H:107
Foam::topoSetSource::~topoSetSource
virtual ~topoSetSource()=default
Destructor.
Foam::topoSetSource::INVERT
Invert the elements in the set.
Definition: topoSetSource.H:104
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
Definition: topoSetSource.C:170
Foam::topoSetSource::isSetSource
static bool isSetSource(const sourceType t)
True if a "set" source.
Definition: topoSetSource.H:202
Foam::topoSetSource::addToUsageTable::addToUsageTable
addToUsageTable(const word &name, const string &msg)
Definition: topoSetSource.H:128
Foam::topoSetSource::UNKNOWN_SOURCE
Placeholder.
Definition: topoSetSource.H:75
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Reference to the mesh.
Definition: topoSetSource.H:151
Foam::topoSetSource::POINT_TYPE
Geometric type is "point".
Definition: topoSetSource.H:80
Foam::topoSetSource::SET_SOURCE
Source based on topoSet.
Definition: topoSetSource.H:76
Foam::topoSetSource::iNew
Class used for the read-construction of.
Definition: topoSetSource.H:263
Foam::topoSetSource::actionNames
static const Enum< setAction > actionNames
The setActions text representations.
Definition: topoSetSource.H:113
autoPtr.H
Enum.H