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-2021 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 dictionary;
60 class polyMesh;
61 class bitSet;
62 class topoSet;
63 
64 /*---------------------------------------------------------------------------*\
65  Class topoSetSource Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 class topoSetSource
69 {
70 public:
71 
72  // Public Data Types
73 
74  //- Enumeration defining the types of sources
75  enum sourceType
76  {
78  CELL_TYPE = 0x1,
79  FACE_TYPE = 0x2,
80  POINT_TYPE = 0x4,
81 
82  SET_SOURCE = 0x10,
86 
87  ZONE_SOURCE = 0x20,
91 
92  CELLSETSOURCE = CELLSET_SOURCE, // Compat (2019-11)
93  FACESETSOURCE = FACESET_SOURCE, // Compat (2019-11)
94  POINTSETSOURCE = POINTSET_SOURCE, // Compat (2019-11)
95  CELLZONESOURCE = CELLZONE_SOURCE, // Compat (2019-11)
96  FACEZONESOURCE = FACEZONE_SOURCE, // Compat (2019-11)
97  POINTZONESOURCE = POINTZONE_SOURCE, // Compat (2019-11)
98  };
99 
100  //- Enumeration defining the valid actions
101  enum setAction
102  {
103  // Fundamental actions
104  ADD,
105  NEW,
106  SUBTRACT,
107 
108  // Derived/intrinsic actions
113  LIST,
114 
115  DELETE = SUBTRACT,
116  };
117 
118  //- The setActions text representations
119  static const Enum<setAction> actionNames;
120 
121 
122 protected:
123 
124  static const string illegalSource_;
125 
126  //- A table of usage strings
128 
129  //- Class with constructor to add usage string to table
130  class addToUsageTable
131  {
132  public:
133 
134  addToUsageTable(const word& name, const string& msg)
135  {
136  if (!usageTablePtr_)
137  {
139  }
140  usageTablePtr_->insert(name, msg);
141  }
142 
144  {
145  if (usageTablePtr_)
146  {
147  delete usageTablePtr_;
148  usageTablePtr_ = nullptr;
149  }
150  }
151  };
152 
153 
154  // Protected Data
155 
156  //- Reference to the mesh
157  const polyMesh& mesh_;
158 
159  //- Output verbosity (default: true)
160  bool verbose_;
161 
162 
163  // Protected Member Functions
164 
165  //- Detect and remove any values less than 0 or ge maxLabel.
166  // \return false if invalid elements were detected (and removed)
167  static bool check(labelList& list, const label maxLabel);
168 
169  //- Add or delete id from set. Add when 'add' is true
170  void addOrDelete(topoSet& set, const label id, const bool add) const;
171 
172  //- Add or delete labels from set. Add when 'add' is true
173  void addOrDelete
174  (
175  topoSet& set,
176  const labelUList& labels,
177  const bool add
178  ) const;
179 
180  //- Add or delete labels from set. Add when 'add' is true
181  void addOrDelete
182  (
183  topoSet& set,
184  const bitSet& labels,
185  const bool add
186  ) const;
187 
188 
189  //- No copy construct
190  topoSetSource(const topoSetSource&) = delete;
191 
192  //- No copy assignment
193  void operator=(const topoSetSource&) = delete;
194 
195 
196 public:
197 
198  //- Runtime type information
199  TypeName("topoSetSource");
200 
201 
202  // Static Functions
203 
204  //- Check state of stream.
205  static Istream& checkIs(Istream& is);
206 
207  //- True if a "set" source
208  static inline bool isSetSource(const sourceType t) noexcept
209  {
210  return (t & SET_SOURCE);
211  }
212 
213  //- True if a "zone" source
214  static inline bool isZoneSource(const sourceType t) noexcept
215  {
216  return (t & ZONE_SOURCE);
217  }
218 
219  //- True if "cell" geometric type
220  static inline bool isCell(const sourceType t) noexcept
221  {
222  return (t & CELL_TYPE);
223  }
224 
225  //- True if "face" geometric type
226  static inline bool isFace(const sourceType t) noexcept
227  {
228  return (t & FACE_TYPE);
229  }
230 
231  //- True if "point" geometric type
232  static inline bool isPoint(const sourceType t) noexcept
233  {
234  return (t & POINT_TYPE);
235  }
236 
237 
238  // Declare run-time constructor selection table
239 
240  // For the dictionary constructor
242  (
243  autoPtr,
245  word,
246  (
247  const polyMesh& mesh,
248  const dictionary& dict
249  ),
250  (mesh, dict)
251  );
252 
253  // For the Istream constructor
255  (
256  autoPtr,
258  istream,
259  (
260  const polyMesh& mesh,
261  Istream& is
262  ),
263  (mesh, is)
264  );
265 
266 
267  //- Class used for the read-construction of
268  // PtrLists of topoSetSource
269  class iNew
270  {
271  const polyMesh& mesh_;
272 
273  public:
274 
275  iNew(const polyMesh& mesh)
276  :
277  mesh_(mesh)
278  {}
279 
281  {
282  const word sourceTypeName(is);
283  dictionary dict(is);
284  return topoSetSource::New(sourceTypeName, mesh_, dict);
285  }
286  };
287 
288 
289  static const string& usage(const word& name)
290  {
291  if (!usageTablePtr_)
292  {
294  }
295 
296  return usageTablePtr_->lookup(name, illegalSource_);
297  }
298 
299 
300  // Constructors
301 
302  //- Construct from mesh, with preferred verbosity
303  explicit topoSetSource(const polyMesh& mesh, bool verbose = true);
304 
305  //- Construct from mesh, use "verbose" entry if present
306  topoSetSource(const polyMesh& mesh, const dictionary& dict);
307 
308 
309  //- Clone (disallowed)
311  {
313  return nullptr;
314  }
315 
316 
317  // Selectors
318 
319  //- Return a reference to the selected topoSetSource
321  (
322  const word& topoSetSourceType,
323  const polyMesh& mesh,
324  const dictionary& dict
325  );
326 
327  //- Return a reference to the selected topoSetSource
329  (
330  const word& topoSetSourceType,
331  const polyMesh& mesh,
332  Istream& is
333  );
334 
335 
336  //- Destructor
337  virtual ~topoSetSource() = default;
338 
339 
340  // Member Functions
341 
342  //- Reference to the mesh
343  const polyMesh& mesh() const noexcept
344  {
345  return mesh_;
346  }
347 
348  //- Get output verbosity
349  bool verbose() const noexcept
350  {
351  return verbose_;
352  }
353 
354  //- Enable/disable verbose output
355  // \return old value
356  bool verbose(bool on) noexcept
357  {
358  bool old(verbose_);
359  verbose_ = on;
360  return old;
361  }
362 
363  //- Use "verbose" entry (if present) to enable/disable verbose output
364  void verbose(const dictionary& dict);
365 
366 
367  // Member Functions
368 
369  //- The source category (cell/face/point combined with set/zone)
370  virtual sourceType setType() const = 0;
371 
372  //- Apply specified action to the topoSet
373  virtual void applyToSet
374  (
375  const topoSetSource::setAction action,
376  topoSet& set
377  ) const = 0;
378 
379 
380  // Housekeeping
381 
382  //- Deprecated(2018-07) convert string to action
383  // \deprecated(2018-07) - use actionNames[] directly
384  static setAction toAction(const word& actionName)
385  {
386  return actionNames[actionName];
387  }
388 };
389 
390 
391 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
392 
393 } // End namespace Foam
394 
395 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
396 
397 #endif
398 
399 // ************************************************************************* //
Foam::topoSetSource::POINTZONE_SOURCE
Points as zone.
Definition: topoSetSource.H:89
Foam::topoSetSource::iNew::operator()
autoPtr< topoSetSource > operator()(Istream &is) const
Definition: topoSetSource.H:279
Foam::topoSetSource::usageTablePtr_
static HashTable< string > * usageTablePtr_
A table of usage strings.
Definition: topoSetSource.H:126
Foam::topoSetSource::sourceType
sourceType
Enumeration defining the types of sources.
Definition: topoSetSource.H:74
Foam::topoSetSource::ADD
Add elements to current set.
Definition: topoSetSource.H:103
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:110
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
HashTable.H
Foam::topoSetSource::FACESETSOURCE
Definition: topoSetSource.H:92
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:142
typeInfo.H
Foam::topoSetSource::toAction
static setAction toAction(const word &actionName)
Deprecated(2018-07) convert string to action.
Definition: topoSetSource.H:383
Foam::topoSetSource::CELL_TYPE
Geometric type is "cell".
Definition: topoSetSource.H:77
Foam::topoSetSource::FACEZONESOURCE
Definition: topoSetSource.H:95
Foam::topoSetSource::POINTZONESOURCE
Definition: topoSetSource.H:96
Foam::topoSetSource::usage
static const string & usage(const word &name)
Definition: topoSetSource.H:288
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:129
Foam::topoSetSource::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const =0
Apply specified action to the topoSet.
Foam::topoSetSource::isFace
static bool isFace(const sourceType t) noexcept
True if "face" geometric type.
Definition: topoSetSource.H:225
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:100
Foam::topoSetSource::isCell
static bool isCell(const sourceType t) noexcept
True if "cell" geometric type.
Definition: topoSetSource.H:219
Foam::topoSetSource::illegalSource_
static const string illegalSource_
Definition: topoSetSource.H:123
Foam::topoSetSource::verbose
bool verbose() const noexcept
Get output verbosity.
Definition: topoSetSource.H:348
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:104
faceList.H
Foam::topoSetSource::isSetSource
static bool isSetSource(const sourceType t) noexcept
True if a "set" source.
Definition: topoSetSource.H:207
Foam::topoSetSource::CELLZONE_SOURCE
Cells as zone.
Definition: topoSetSource.H:87
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:517
Foam::topoSetSource::ZONE_SOURCE
A source based on mesh zone.
Definition: topoSetSource.H:86
Foam::topoSetSource::FACESET_SOURCE
Faces as set.
Definition: topoSetSource.H:83
Foam::topoSetSource::verbose_
bool verbose_
Output verbosity (default: true)
Definition: topoSetSource.H:159
Foam::topoSetSource::POINTSETSOURCE
Definition: topoSetSource.H:93
labelList.H
Foam::topoSetSource::FACE_TYPE
Geometric type is "face".
Definition: topoSetSource.H:78
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::topoSetSource::CELLZONESOURCE
Definition: topoSetSource.H:94
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:114
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:74
Foam::topoSetSource::operator=
void operator=(const topoSetSource &)=delete
No copy assignment.
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::topoSetSource::SUBSET
Union of elements with current set.
Definition: topoSetSource.H:108
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::topoSetSource::clone
autoPtr< topoSetSource > clone() const
Clone (disallowed)
Definition: topoSetSource.H:309
Foam::topoSetSource::CELLSETSOURCE
Definition: topoSetSource.H:91
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 current set.
Definition: topoSetSource.H:105
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:110
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::topoSetSource
Base class of a source for a topoSet.
Definition: topoSetSource.H:67
Foam::topoSetSource::iNew::iNew
iNew(const polyMesh &mesh)
Definition: topoSetSource.H:274
Foam::HashTable
A HashTable similar to std::unordered_map.
Definition: HashTable.H:105
Foam::topoSetSource::FACEZONE_SOURCE
Faces as zone.
Definition: topoSetSource.H:88
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::LIST
Print contents of the set.
Definition: topoSetSource.H:112
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:156
Foam::topoSetSource::setType
virtual sourceType setType() const =0
The source category (cell/face/point combined with set/zone)
Foam::UList< label >
Foam::topoSetSource::REMOVE
Remove the set (from the file system)
Definition: topoSetSource.H:111
Foam::topoSetSource::mesh
const polyMesh & mesh() const noexcept
Reference to the mesh.
Definition: topoSetSource.H:342
Foam::topoSetSource::~topoSetSource
virtual ~topoSetSource()=default
Destructor.
Foam::topoSetSource::INVERT
Invert the elements in the current set.
Definition: topoSetSource.H:109
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:171
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::topoSetSource::addToUsageTable::addToUsageTable
addToUsageTable(const word &name, const string &msg)
Definition: topoSetSource.H:133
Foam::topoSetSource::isPoint
static bool isPoint(const sourceType t) noexcept
True if "point" geometric type.
Definition: topoSetSource.H:231
Foam::topoSetSource::UNKNOWN_SOURCE
Placeholder.
Definition: topoSetSource.H:76
Foam::topoSetSource::isZoneSource
static bool isZoneSource(const sourceType t) noexcept
True if a "zone" source.
Definition: topoSetSource.H:213
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Reference to the mesh.
Definition: topoSetSource.H:156
Foam::topoSetSource::POINT_TYPE
Geometric type is "point".
Definition: topoSetSource.H:79
Foam::topoSetSource::SET_SOURCE
A source based on topoSet.
Definition: topoSetSource.H:81
Foam::topoSetSource::iNew
Class used for the read-construction of.
Definition: topoSetSource.H:268
Foam::topoSetSource::actionNames
static const Enum< setAction > actionNames
The setActions text representations.
Definition: topoSetSource.H:118
autoPtr.H
Enum.H