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-2022 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/SUBTRACT/NEW).
35 
36 SourceFiles
37  topoSetSource.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Foam_topoSetSource_H
42 #define Foam_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
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 various actions
101  enum setAction
102  {
103  // Fundamental actions
104  ADD,
106  NEW,
107 
108  // Derived/intrinsic actions
113  LIST,
116  DELETE = SUBTRACT,
117  };
118 
119  //- The setActions enum text.
120  //- Names: "new", add", "subtract", "subset", "invert",
121  //- "clear", "remove", "list", "ignore"
122  static const Enum<setAction> actionNames;
124  //- The setAction enum text when combining selections.
125  //- Names: "use", "add", "subtract", "subset", "invert", "ignore"
126  //
127  // \note The "use" is like "new" (start from empty + ADD)
128  static const Enum<setAction> combineNames;
129 
130 
131 protected:
133  static const string illegalSource_;
134 
135  //- A table of usage strings
138  //- Class with constructor to add usage string to table
139  class addToUsageTable
140  {
141  public:
143  addToUsageTable(const word& name, const string& msg)
144  {
145  if (!usageTablePtr_)
146  {
148  }
149  usageTablePtr_->insert(name, msg);
150  }
153  {
154  if (usageTablePtr_)
155  {
156  delete usageTablePtr_;
157  usageTablePtr_ = nullptr;
158  }
159  }
160  };
161 
162 
163  // Protected Data
164 
165  //- Reference to the mesh
166  const polyMesh& mesh_;
167 
168  //- Output verbosity (default: true)
169  bool verbose_;
170 
171 
172  // Protected Member Functions
173 
174  //- Detect and remove any values less than 0 or ge maxLabel.
175  // \return false if invalid elements were detected (and removed)
176  static bool check(labelList& list, const label maxLabel);
177 
178  //- Add or delete id from set. Add when 'add' is true
179  void addOrDelete(topoSet& set, const label id, const bool add) const;
180 
181  //- Add or delete labels from set. Add when 'add' is true
182  void addOrDelete
183  (
184  topoSet& set,
185  const labelUList& labels,
186  const bool add
187  ) const;
188 
189  //- Add or delete labels from set. Add when 'add' is true
190  void addOrDelete
191  (
192  topoSet& set,
193  const bitSet& labels,
194  const bool add
195  ) const;
196 
197 
198  //- No copy construct
199  topoSetSource(const topoSetSource&) = delete;
200 
201  //- No copy assignment
202  void operator=(const topoSetSource&) = delete;
203 
204 
205 public:
206 
207  //- Runtime type information
208  TypeName("topoSetSource");
209 
210 
211  // Static Functions
212 
213  //- Check state of stream.
214  static Istream& checkIs(Istream& is);
215 
216  //- True if a "set" source
217  static inline bool isSetSource(const sourceType t) noexcept
218  {
219  return (t & SET_SOURCE);
220  }
221 
222  //- True if a "zone" source
223  static inline bool isZoneSource(const sourceType t) noexcept
224  {
225  return (t & ZONE_SOURCE);
226  }
227 
228  //- True if "cell" geometric type
229  static inline bool isCell(const sourceType t) noexcept
230  {
231  return (t & CELL_TYPE);
232  }
233 
234  //- True if "face" geometric type
235  static inline bool isFace(const sourceType t) noexcept
236  {
237  return (t & FACE_TYPE);
238  }
239 
240  //- True if "point" geometric type
241  static inline bool isPoint(const sourceType t) noexcept
242  {
243  return (t & POINT_TYPE);
244  }
245 
246 
247  // Declare run-time constructor selection table
249  // For the dictionary constructor
251  (
252  autoPtr,
254  word,
255  (
256  const polyMesh& mesh,
257  const dictionary& dict
258  ),
259  (mesh, dict)
260  );
261 
262  // For the Istream constructor
264  (
265  autoPtr,
267  istream,
268  (
269  const polyMesh& mesh,
270  Istream& is
271  ),
272  (mesh, is)
273  );
274 
275 
276  //- Class used for the read-construction of
277  // PtrLists of topoSetSource
278  class iNew
279  {
280  const polyMesh& mesh_;
281 
282  public:
283 
284  iNew(const polyMesh& mesh)
285  :
286  mesh_(mesh)
287  {}
288 
290  {
291  const word sourceTypeName(is);
292  dictionary dict(is);
293  return topoSetSource::New(sourceTypeName, mesh_, dict);
294  }
295  };
296 
297 
298  static const string& usage(const word& name)
299  {
300  if (!usageTablePtr_)
301  {
302  usageTablePtr_ = new HashTable<string>();
303  }
304 
305  return usageTablePtr_->lookup(name, illegalSource_);
306  }
307 
308 
309  // Constructors
310 
311  //- Construct from mesh, with preferred verbosity
312  explicit topoSetSource(const polyMesh& mesh, bool verbose = true);
313 
314  //- Construct from mesh, use "verbose" entry if present
315  topoSetSource(const polyMesh& mesh, const dictionary& dict);
316 
317 
318  //- Clone (disallowed)
319  autoPtr<topoSetSource> clone() const
320  {
322  return nullptr;
323  }
324 
325 
326  // Selectors
327 
328  //- Return a reference to the selected topoSetSource
330  (
331  const word& topoSetSourceType,
332  const polyMesh& mesh,
333  const dictionary& dict
334  );
335 
336  //- Return a reference to the selected topoSetSource
338  (
339  const word& topoSetSourceType,
340  const polyMesh& mesh,
341  Istream& is
342  );
343 
344 
345  //- Destructor
346  virtual ~topoSetSource() = default;
347 
348 
349  // Member Functions
350 
351  //- Reference to the mesh
352  const polyMesh& mesh() const noexcept
353  {
354  return mesh_;
355  }
356 
357  //- Get output verbosity
358  bool verbose() const noexcept
359  {
360  return verbose_;
361  }
362 
363  //- Enable/disable verbose output
364  // \return old value
365  bool verbose(bool on) noexcept
366  {
367  bool old(verbose_);
368  verbose_ = on;
369  return old;
370  }
371 
372  //- Use "verbose" entry (if present) to enable/disable verbose output
373  void verbose(const dictionary& dict);
374 
375 
376  // Member Functions
377 
378  //- The source category (cell/face/point combined with set/zone)
379  virtual sourceType setType() const = 0;
380 
381  //- Apply specified action to the topoSet
382  virtual void applyToSet
383  (
384  const topoSetSource::setAction action,
385  topoSet& set
386  ) const = 0;
387 
388 
389  // Housekeeping
390 
391  //- Deprecated(2018-07) convert string to action
392  // \deprecated(2018-07) - use actionNames[] directly
393  static setAction toAction(const word& actionName)
394  {
395  return actionNames[actionName];
396  }
397 };
398 
399 
400 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
401 
402 } // End namespace Foam
403 
404 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
405 
406 #endif
407 
408 // ************************************************************************* //
topoSetSource(const topoSetSource &)=delete
No copy construct.
static bool isSetSource(const sourceType t) noexcept
True if a "set" source.
Geometric type is "cell".
Definition: topoSetSource.H:75
dictionary dict
void operator=(const topoSetSource &)=delete
No copy assignment.
static const Enum< setAction > actionNames
The setActions enum text. Names: "new", add", "subtract", "subset", "invert", "clear", "remove", "list", "ignore".
static const string & usage(const word &name)
bool verbose_
Output verbosity (default: true)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Create a new set and ADD elements to it.
Add elements to current set.
static bool isPoint(const sourceType t) noexcept
True if "point" geometric type.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Clear the set, possibly creating it.
declareRunTimeSelectionTable(autoPtr, topoSetSource, word,(const polyMesh &mesh, const dictionary &dict),(mesh, dict))
Invert the elements in the current set.
static Istream & checkIs(Istream &is)
Check state of stream.
A source based on mesh zone.
Definition: topoSetSource.H:84
Remove the set (from the file system)
virtual sourceType setType() const =0
The source category (cell/face/point combined with set/zone)
Print contents of the set.
virtual ~topoSetSource()=default
Destructor.
iNew(const polyMesh &mesh)
static bool isCell(const sourceType t) noexcept
True if "cell" geometric type.
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when &#39;add&#39; is true.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
Geometric type is "point".
Definition: topoSetSource.H:77
Class used for the read-construction of.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
Union of elements with current set.
const polyMesh & mesh() const noexcept
Reference to the mesh.
setAction
Enumeration defining various actions.
static const string illegalSource_
bool verbose() const noexcept
Get output verbosity.
A HashTable similar to std::unordered_map.
Definition: HashTable.H:108
TypeName("topoSetSource")
Runtime type information.
const polyMesh & mesh_
Reference to the mesh.
addToUsageTable(const word &name, const string &msg)
const direction noexcept
Definition: Scalar.H:258
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
autoPtr< topoSetSource > clone() const
Clone (disallowed)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
Subtract elements from current set.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const =0
Apply specified action to the topoSet.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
autoPtr< topoSetSource > operator()(Istream &is) const
Class with constructor to add usage string to table.
static HashTable< string > * usageTablePtr_
A table of usage strings.
sourceType
Enumeration defining the types of sources.
Definition: topoSetSource.H:72
static bool isZoneSource(const sourceType t) noexcept
True if a "zone" source.
static setAction toAction(const word &actionName)
Deprecated(2018-07) convert string to action.
static bool check(labelList &list, const label maxLabel)
Detect and remove any values less than 0 or ge maxLabel.
Definition: topoSetSource.C:83
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Macros to ease declaration of run-time selection tables.
"ignore" no-op action
A source based on topoSet.
Definition: topoSetSource.H:79
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:686
static bool isFace(const sourceType t) noexcept
True if "face" geometric type.
static const Enum< setAction > combineNames
The setAction enum text when combining selections. Names: "use", "add", "subtract", "subset", "invert", "ignore".
Geometric type is "face".
Definition: topoSetSource.H:76
Namespace for OpenFOAM.