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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::topoSetSource
29
30Description
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
36SourceFiles
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
55namespace Foam
56{
57
58// Forward Declarations
59class dictionary;
60class polyMesh;
61class bitSet;
62class topoSet;
63
64/*---------------------------------------------------------------------------*\
65 Class topoSetSource Declaration
66\*---------------------------------------------------------------------------*/
68class topoSetSource
69{
70public:
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,
82 SET_SOURCE = 0x10,
87 ZONE_SOURCE = 0x20,
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
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;
123
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
131protected:
133 static const string illegalSource_;
134
135 //- A table of usage strings
137
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
205public:
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
248
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:
284 iNew(const polyMesh& mesh)
285 :
286 mesh_(mesh)
287 {}
290 {
291 const word sourceTypeName(is);
292 dictionary dict(is);
293 return topoSetSource::New(sourceTypeName, mesh_, dict);
294 }
295 };
296
298 static const string& usage(const word& name)
299 {
300 if (!usageTablePtr_)
301 {
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)
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// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
A HashTable similar to std::unordered_map.
Definition: HashTable.H:123
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
Class with constructor to add usage string to table.
addToUsageTable(const word &name, const string &msg)
Class used for the read-construction of.
iNew(const polyMesh &mesh)
autoPtr< topoSetSource > operator()(Istream &is) const
Base class of a source for a topoSet.
Definition: topoSetSource.H:68
static bool isZoneSource(const sourceType t) noexcept
True if a "zone" source.
virtual sourceType setType() const =0
The source category (cell/face/point combined with set/zone)
static bool isPoint(const sourceType t) noexcept
True if "point" geometric type.
static const string illegalSource_
sourceType
Enumeration defining the types of sources.
Definition: topoSetSource.H:75
@ CELL_TYPE
Geometric type is "cell".
Definition: topoSetSource.H:77
@ POINTSET_SOURCE
Points as set.
Definition: topoSetSource.H:84
@ FACESET_SOURCE
Faces as set.
Definition: topoSetSource.H:83
@ FACEZONE_SOURCE
Faces as zone.
Definition: topoSetSource.H:88
@ UNKNOWN_SOURCE
Placeholder.
Definition: topoSetSource.H:76
@ POINTZONE_SOURCE
Points as zone.
Definition: topoSetSource.H:89
@ CELLSET_SOURCE
Cells as set.
Definition: topoSetSource.H:82
@ CELLZONE_SOURCE
Cells as zone.
Definition: topoSetSource.H:87
@ POINT_TYPE
Geometric type is "point".
Definition: topoSetSource.H:79
@ ZONE_SOURCE
A source based on mesh zone.
Definition: topoSetSource.H:86
@ FACE_TYPE
Geometric type is "face".
Definition: topoSetSource.H:78
@ SET_SOURCE
A source based on topoSet.
Definition: topoSetSource.H:81
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
static bool check(labelList &list, const label maxLabel)
Detect and remove any values less than 0 or ge maxLabel.
Definition: topoSetSource.C:90
static setAction toAction(const word &actionName)
Deprecated(2018-07) convert string to action.
topoSetSource(const topoSetSource &)=delete
No copy construct.
static bool isCell(const sourceType t) noexcept
True if "cell" geometric type.
setAction
Enumeration defining various actions.
@ CLEAR
Clear the set, possibly creating it.
@ SUBSET
Union of elements with current set.
@ LIST
Print contents of the set.
@ REMOVE
Remove the set (from the file system)
@ IGNORE
"ignore" no-op action
@ SUBTRACT
Subtract elements from current set.
@ INVERT
Invert the elements in the current set.
@ ADD
Add elements to current set.
@ NEW
Create a new set and ADD elements to it.
static bool isFace(const sourceType t) noexcept
True if "face" geometric type.
void operator=(const topoSetSource &)=delete
No copy assignment.
virtual ~topoSetSource()=default
Destructor.
static HashTable< string > * usageTablePtr_
A table of usage strings.
static const string & usage(const word &name)
declareRunTimeSelectionTable(autoPtr, topoSetSource, word,(const polyMesh &mesh, const dictionary &dict),(mesh, dict))
declareRunTimeSelectionTable(autoPtr, topoSetSource, istream,(const polyMesh &mesh, Istream &is),(mesh, is))
bool verbose_
Output verbosity (default: true)
autoPtr< topoSetSource > clone() const
Clone (disallowed)
bool verbose() const noexcept
Get output verbosity.
const polyMesh & mesh() const noexcept
Reference to the mesh.
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
TypeName("topoSetSource")
Runtime type information.
const polyMesh & mesh_
Reference to the mesh.
static Istream & checkIs(Istream &is)
Check state of stream.
static const Enum< setAction > actionNames
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const =0
Apply specified action to the topoSet.
static const Enum< setAction > combineNames
static bool isSetSource(const sourceType t) noexcept
True if a "set" source.
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:67
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
Namespace for OpenFOAM.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
const direction noexcept
Definition: Scalar.H:223
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Macros to ease declaration of run-time selection tables.
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes)
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73