Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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;
64/*---------------------------------------------------------------------------*\
65 Class topoSetSource Declaration
66\*---------------------------------------------------------------------------*/
67
68class topoSetSource
69{
70public:
71
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;
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
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
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
208public:
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
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
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 }
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)
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)
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);
414
415
416// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
417
418} // End namespace Foam
419
420// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
422#endif
423
424// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
A HashTable similar to std::unordered_map.
Definition HashTable.H:124
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A class for managing temporary objects.
Definition tmp.H:75
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
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_
bool hasTransform() const noexcept
True if coordinate transform is active.
sourceType
Enumeration defining the types of sources.
@ CELL_TYPE
Geometric type is "cell".
@ POINTSET_SOURCE
Points as set.
@ FACESET_SOURCE
Faces as set.
@ FACEZONE_SOURCE
Faces as zone.
@ UNKNOWN_SOURCE
Placeholder.
@ POINTZONE_SOURCE
Points as zone.
@ CELLSET_SOURCE
Cells as set.
@ CELLZONE_SOURCE
Cells as zone.
@ POINT_TYPE
Geometric type is "point".
@ ZONE_SOURCE
A source based on mesh zone.
@ FACE_TYPE
Geometric type is "face".
@ SET_SOURCE
A source based on topoSet.
tmp< pointField > transform(const pointField &points) const
Coordinate transform (optionally) coordinates. Returns reference to input data if no transform is act...
static bool readNames(const dictionary &dict, wordList &names)
Helper: extract wordList of patches/zones from dictionary. Returns.
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.
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.
autoPtr< solidBodyMotionFunction > transformPtr_
Optional transformation for geometric data.
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(bool on) noexcept
Enable/disable verbose output.
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
The setActions enum text. Names: "new", add", "subtract", "subset", "invert","clear",...
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const =0
Apply specified action to the topoSet.
static const Enum< setAction > combineNames
The setAction enum text when combining selections. Names: "use", "add", "subtract",...
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:63
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition error.H:688
auto & name
auto & names
const pointField & points
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
List< label > labelList
A List of labels.
Definition List.H:62
void add(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
const direction noexcept
Definition scalarImpl.H:265
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
vectorField pointField
pointField is a vectorField.
UList< label > labelUList
A UList of labels.
Definition UList.H:75
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes).
dictionary dict
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68