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-2024 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"
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  //- Optional transformation for geometric data
173 
174 
175  // Protected Member Functions
177  //- Detect and remove any values less than 0 or ge maxLabel.
178  // \return false if invalid elements were detected (and removed)
179  static bool check(labelList& list, const label maxLabel);
180 
181  //- Add or delete id from set. Add when 'add' is true
182  void addOrDelete(topoSet& set, const label id, const bool add) const;
183 
184  //- Add or delete labels from set. Add when 'add' is true
185  void addOrDelete
186  (
187  topoSet& set,
188  const labelUList& labels,
189  const bool add
190  ) const;
191 
192  //- Add or delete labels from set. Add when 'add' is true
193  void addOrDelete
194  (
195  topoSet& set,
196  const bitSet& labels,
197  const bool add
198  ) const;
199 
200 
201  //- No copy construct
202  topoSetSource(const topoSetSource&) = delete;
203 
204  //- No copy assignment
205  void operator=(const topoSetSource&) = delete;
206 
207 
208 public:
209 
210  //- Runtime type information
211  TypeName("topoSetSource");
212 
213 
214  // Static Functions
215 
216  //- Check state of stream.
217  static Istream& checkIs(Istream& is);
218 
219  //- True if a "set" source
220  static inline bool isSetSource(const sourceType t) noexcept
221  {
222  return (t & SET_SOURCE);
223  }
224 
225  //- True if a "zone" source
226  static inline bool isZoneSource(const sourceType t) noexcept
227  {
228  return (t & ZONE_SOURCE);
229  }
230 
231  //- True if "cell" geometric type
232  static inline bool isCell(const sourceType t) noexcept
233  {
234  return (t & CELL_TYPE);
235  }
236 
237  //- True if "face" geometric type
238  static inline bool isFace(const sourceType t) noexcept
239  {
240  return (t & FACE_TYPE);
241  }
242 
243  //- True if "point" geometric type
244  static inline bool isPoint(const sourceType t) noexcept
245  {
246  return (t & POINT_TYPE);
247  }
248 
249 
250  // Declare run-time constructor selection table
251 
252  // For the dictionary constructor
254  (
255  autoPtr,
257  word,
258  (
259  const polyMesh& mesh,
260  const dictionary& dict
261  ),
262  (mesh, dict)
263  );
264 
265  // For the Istream constructor
267  (
268  autoPtr,
270  istream,
271  (
272  const polyMesh& mesh,
273  Istream& is
274  ),
275  (mesh, is)
276  );
278 
279  //- Class used for the read-construction of
280  // PtrLists of topoSetSource
281  class iNew
282  {
283  const polyMesh& mesh_;
284 
285  public:
286 
287  iNew(const polyMesh& mesh)
288  :
289  mesh_(mesh)
290  {}
291 
293  {
294  const word sourceTypeName(is);
295  dictionary dict(is);
296  return topoSetSource::New(sourceTypeName, mesh_, dict);
297  }
298  };
299 
300 
301  static const string& usage(const word& name)
302  {
303  if (!usageTablePtr_)
304  {
305  usageTablePtr_ = new HashTable<string>();
306  }
307 
308  return usageTablePtr_->lookup(name, illegalSource_);
309  }
310 
311 
312  // Constructors
313 
314  //- Construct from mesh, with preferred verbosity
315  explicit topoSetSource(const polyMesh& mesh, bool verbose = true);
316 
317  //- Construct from mesh, use "verbose" entry if present
318  topoSetSource(const polyMesh& mesh, const dictionary& dict);
319 
320 
321  //- Clone (disallowed)
322  autoPtr<topoSetSource> clone() const
323  {
325  return nullptr;
326  }
327 
328 
329  // Selectors
330 
331  //- Return a reference to the selected topoSetSource
333  (
334  const word& topoSetSourceType,
335  const polyMesh& mesh,
337  );
338 
339  //- Return a reference to the selected topoSetSource
341  (
342  const word& topoSetSourceType,
343  const polyMesh& mesh,
344  Istream& is
345  );
346 
347 
348  //- Destructor
349  virtual ~topoSetSource() = default;
350 
351 
352  // Member Functions
353 
354  //- Reference to the mesh
355  const polyMesh& mesh() const noexcept
356  {
357  return mesh_;
358  }
359 
360  //- Get output verbosity
361  bool verbose() const noexcept
362  {
363  return verbose_;
364  }
365 
366  //- Enable/disable verbose output
367  // \return old value
368  bool verbose(bool on) noexcept
369  {
370  bool old(verbose_);
371  verbose_ = on;
372  return old;
373  }
374 
375  //- Use "verbose" entry (if present) to enable/disable verbose output
376  void verbose(const dictionary& dict);
377 
378 
379  // Member Functions
380 
381  //- The source category (cell/face/point combined with set/zone)
382  virtual sourceType setType() const = 0;
383 
384  //- Apply specified action to the topoSet
385  virtual void applyToSet
386  (
387  const topoSetSource::setAction action,
388  topoSet& set
389  ) const = 0;
390 
391 
392  //- True if coordinate transform is active.
393  bool hasTransform() const noexcept { return bool(transformPtr_); }
394 
395  //- Coordinate transform (optionally) coordinates.
396  //- Returns reference to input data if no transform is active.
397  tmp<pointField> transform(const pointField& points) const;
398 
399 
400  // Housekeeping
401 
402  //- Deprecated(2018-07) convert string to action
403  // \deprecated(2018-07) - use actionNames[] directly
404  static setAction toAction(const word& actionName)
405  {
406  return actionNames[actionName];
407  }
408 
409  //- Helper: extract wordList of patches/zones from dictionary. Returns
410  // true if zone(s). Order of parsing is
411  // sets, zones, set, zone
412  static bool readNames(const dictionary& dict, wordList& names);
413 };
414 
415 
416 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
417 
418 } // End namespace Foam
419 
420 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
422 #endif
423 
424 // ************************************************************************* //
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".
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
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.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
const pointField & points
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.
bool hasTransform() const noexcept
True if coordinate transform is active.
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.
Basic run-time type information using word as the type&#39;s name. Used to enhance the standard RTTI to c...
List< word > wordList
List of word.
Definition: fileName.H:59
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
autoPtr< solidBodyMotionFunction > transformPtr_
Optional transformation for geometric data.
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
tmp< pointField > transform(const pointField &points) const
Coordinate transform (optionally) coordinates. Returns reference to input data if no transform is act...
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:84
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
static bool readNames(const dictionary &dict, wordList &names)
Helper: extract wordList of patches/zones from dictionary. Returns.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
"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:696
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.