Loading...
Searching...
No Matches
topoSet.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) 2016-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::topoSet
29
30Description
31 General set of labels of mesh quantity (points, cells, faces).
32
33SourceFiles
34 topoSet.C
35 topoSetTemplates.C
36
37\*---------------------------------------------------------------------------*/
38
39#ifndef Foam_topoSet_H
40#define Foam_topoSet_H
41
42#include "HashSet.H"
43#include "regIOobject.H"
44#include "labelList.H"
45#include "typeInfo.H"
46#include "autoPtr.H"
47#include "pointField.H"
48
49// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50
51namespace Foam
52{
53
54// Forward Declarations
55class mapPolyMesh;
56class polyMesh;
57class primitiveMesh;
60/*---------------------------------------------------------------------------*\
61 Class topoSet Declaration
62\*---------------------------------------------------------------------------*/
63
64class topoSet
65:
66 public regIOobject,
67 public labelHashSet
68{
69protected:
70
71 // Protected Member Functions
72
73 //- Read into labelHashSet if IOobject flags set. Return true if read.
74 bool readIOcontents(const word& wantedType, labelHashSet& contents);
75
76 //- Check limits on addressable range.
77 void checkLabels(const labelUList& labels, const label maxSize);
78
79 //- Check limits on addressable range.
80 void checkLabels(const labelHashSet& labels, const label maxSize);
81
82 //- Update map from map.
83 // Used to update cell/face labels after morphing
84 virtual void updateLabels(const labelUList& map);
85
86 //- Check limits on addressable range.
87 virtual void check(const label maxSize);
88
89 //- Write part of contents nicely formatted.
90 // Prints labels only.
91 // \returns number of labels written
92 label writeDebug
93 (
94 Ostream& os,
95 const label maxElem,
97 ) const;
98
99 //- Write part of contents nicely formatted.
100 // Prints label and corresponding coordinate.
101 // \returns number of labels written
102 label writeDebug
103 (
104 Ostream& os,
105 const pointField& coords,
106 const label maxElem,
108 ) const;
109
110 //- Write labels and coordinates columnwise to os. Truncate to maxLen.
111 void writeDebug
112 (
113 Ostream& os,
114 const pointField& coords,
115 const label maxLen
116 ) const;
117
118 //- No copy construct
119 topoSet(const topoSet&) = delete;
120
121
122public:
123
124 //- Runtime type information
125 TypeName("topoSet");
126
127
128 // Static
129
130 //- Debug switch to disallow the use of generic sets
131 static int disallowGenericSets;
132
133 //- Name of file set will use.
134 static fileName localPath(const polyMesh& mesh, const word& name);
136 //- Find IOobject in the polyMesh/sets/ (used as constructor helper)
138 (
139 const polyMesh& mesh,
140 const word& name,
144 );
145
146 //- Find IOobject in the polyMesh/sets/ (used as constructor helper)
148 (
149 const polyMesh& mesh,
150 const word& name,
154 )
155 {
156 return findIOobject(mesh, name, rOpt, wOpt, reg);
157 }
158
159 //- Find IOobject in the polyMesh/sets/ (used as constructor helper)
161 (
162 const Time& runTime,
163 const word& name,
167 );
168
169
170 // Declare run-time constructor selection table
171
172 // For the direct constructor
174 (
175 autoPtr,
176 topoSet,
177 word,
178 (
179 const polyMesh& mesh,
180 const word& name,
183 ),
184 (mesh, name, rOpt, wOpt)
185 );
186
187 // For the constructor from size
189 (
190 autoPtr,
191 topoSet,
192 size,
193 (
194 const polyMesh& mesh,
195 const word& name,
196 const label size,
198 ),
199 (mesh, name, size, wOpt)
200 );
202 // For the constructor as copy
204 (
205 autoPtr,
206 topoSet,
207 set,
208 (
209 const polyMesh& mesh,
210 const word& name,
211 const topoSet& set,
213 ),
214 (mesh, name, set, wOpt)
215 );
217
218 // Constructors
219
220 //- Construct from IOobject as explicitly passed type.
221 // Can't use typeName info here since subclasses not yet instantiated
222 topoSet(const IOobject& io, const word& wantedType);
223
224 //- Construct empty (no-read) with IOobject information
225 topoSet(const IOobject& io, const Foam::zero);
226
227 //- Construct empty (no-read) with initial labelHashSet capacity,
228 //- with IOobject information
229 topoSet(const IOobject& io, const label initialCapacity);
230
231 //- Copy construct (no-read) from labelHashSet,
232 //- with IOobject information.
233 topoSet(const IOobject& io, const labelHashSet& labels);
234
235 //- Move construct (no-read) from labelHashSet,
236 //- with IOobject information.
237 topoSet(const IOobject& io, labelHashSet&& labels);
238
239 //- Construct from polyMesh and name.
240 // Searches for a polyMesh/sets directory but not beyond the
241 // mesh.facesInstance().
242 topoSet
243 (
244 const polyMesh& mesh,
245 const word& wantedType,
246 const word& name,
250 );
251
252 //- Construct empty (no-read) with initial labelHashSet capacity.
253 // Searches for a polyMesh/sets directory but not beyond the
254 // mesh.facesInstance().
255 topoSet
256 (
257 const polyMesh& mesh,
258 const word& name,
259 const label initialCapacity,
262 );
263
264 //- Copy construct (no-read) from labelHashSet.
265 // Searches for a polyMesh/sets directory but not beyond the
266 // mesh.facesInstance().
267 topoSet
268 (
269 const polyMesh& mesh,
270 const word& name,
271 const labelHashSet& labels,
274 );
275
276 //- Move construct (no-read) from labelHashSet.
277 // Searches for a polyMesh/sets directory but not beyond the
278 // mesh.facesInstance().
279 topoSet
280 (
281 const polyMesh& mesh,
282 const word& name,
283 labelHashSet&& labels,
286 );
287
288 //- Copy construct (no-read) from list of labels.
289 // Searches for a polyMesh/sets directory but not beyond the
290 // mesh.facesInstance().
291 topoSet
292 (
293 const polyMesh& mesh,
294 const word& name,
295 const labelUList& labels,
298 );
299
300
301 //- Clone
302 autoPtr<topoSet> clone() const
303 {
305 return nullptr;
306 }
307
308
309 // Selectors
310
311 //- Return a pointer to a toposet read from file
312 static autoPtr<topoSet> New
313 (
314 const word& setType,
315 const polyMesh& mesh,
316 const word& name,
319 );
320
321 //- Return a pointer to a new toposet of given size
322 static autoPtr<topoSet> New
323 (
324 const word& setType,
325 const polyMesh& mesh,
326 const word& name,
327 const label size,
329 );
330
331 //- Return a pointer to a new toposet as copy of another toposet
332 static autoPtr<topoSet> New
333 (
334 const word& setType,
335 const polyMesh& mesh,
336 const word& name,
337 const topoSet& set,
339 );
340
341
342 //- Destructor
343 virtual ~topoSet() = default;
344
345
346 // Member Functions
347
348 //- Has the given index?
349 virtual bool contains(const label id) const;
350
351 //- Has the given index?
352 virtual bool found(const label id) const;
353
354 //- Set an index
355 virtual bool set(const label id);
356
357 //- Unset an index
358 virtual bool unset(const label id);
359
360 //- Set multiple indices
361 virtual void set(const labelUList& labels);
362
363 //- Unset multiple indices
364 virtual void unset(const labelUList& labels);
365
366 //- Invert contents.
367 // Insert all members [0,maxLen) which were not in set.
368 virtual void invert(const label maxLen);
369
370 //- Subset contents. Only elements present in both sets remain.
371 virtual void subset(const labelUList& elems);
372
373 //- Subset contents. Only elements present in both sets remain.
374 virtual void subset(const topoSet& set);
375
376 //- Add given elements to the set
377 virtual void addSet(const labelUList& elems);
378
379 //- Add given elements to the set
380 virtual void addSet(const topoSet& set);
381
382 //- Subtract given elements from the set
383 virtual void subtractSet(const labelUList& elems);
384
385 //- Subtract given elements from the set
386 virtual void subtractSet(const topoSet& set);
387
388
389 //- Sync set across coupled patches.
390 virtual void sync(const polyMesh& mesh);
391
392 //- Write labels columnwise to os. Truncate to maxLen.
393 virtual void writeDebug(Ostream& os, const label maxLen) const;
394
395 //- Like above but also writes mesh related quantity
396 //- (usually coordinate).
397 virtual void writeDebug
398 (
399 Ostream& os,
400 const primitiveMesh&,
401 const label maxLen
402 ) const = 0;
403
404 //- Write contents.
405 virtual bool writeData(Ostream&) const;
406
407 //- Update any stored data for new labels. Not implemented.
408 virtual void updateMesh(const mapPolyMesh& morphMap);
409
410 //- Update any stored data for mesh redistribution.
411 virtual void distribute(const mapDistributePolyMesh&) = 0;
412
413 //- Return max allowable index (+1). Not implemented.
414 virtual label maxSize(const polyMesh& mesh) const = 0;
415
416 //- Helper: call updateMesh on all items in container
417 //- (and updates instance)
418 template<class Container>
419 static void updateMesh
420 (
421 const fileName& instance,
422 const mapPolyMesh&,
423 Container& items
424 );
425
426 //- Helper: set instance on all items in container
427 template<class Container>
428 static void setInstance
429 (
430 const fileName& instance,
431 Container& items
432 );
433
434 //- Helper: remove all sets files from mesh instance
435 static void removeFiles(const polyMesh&);
436
437
438 // Member Operators
439
440 //- Copy labelHashSet part only
441 void operator=(const topoSet&);
442
443
444 // Housekeeping
445
446 //- Deprecated(2018-10) subtract elements present in set.
447 // \deprecated(2018-10) - use subtractSet instead
448 FOAM_DEPRECATED_FOR(2018-10, "subtractSet()")
449 virtual void deleteSet(const topoSet& set) { this->subtractSet(set); }
450};
451
452
453// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
454
455} // End namespace Foam
456
457// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
458
459#ifdef NoRepository
460 #include "topoSetTemplates.C"
461#endif
462
463// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
464
465#endif
466
467// ************************************************************************* //
bool found
typename parent_type::const_key_iterator const_iterator
Definition HashSet.H:131
label size() const noexcept
The number of elements in table.
Definition HashTable.H:358
registerOption
Enumeration for use with registerObject(). Values map to bool (false/true).
@ LEGACY_REGISTER
Legacy/default registration request (bool: true).
readOption
Enumeration defining read preferences.
@ MUST_READ
Reading required.
writeOption
Enumeration defining write preferences.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
const fileName & instance() const noexcept
Read access to instance path component.
Definition IOobjectI.H:289
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A class for handling file names.
Definition fileName.H:75
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
Cell-face mesh analysis engine.
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
Definition regIOobject.C:43
General set of labels of mesh quantity (points, cells, faces).
Definition topoSet.H:63
virtual void deleteSet(const topoSet &set)
Deprecated(2018-10) subtract elements present in set.
Definition topoSet.H:565
virtual void distribute(const mapDistributePolyMesh &)=0
Update any stored data for mesh redistribution.
static void removeFiles(const polyMesh &)
Helper: remove all sets files from mesh instance.
Definition topoSet.C:693
virtual bool writeData(Ostream &) const
Write contents.
Definition topoSet.C:681
virtual void invert(const label maxLen)
Invert contents.
Definition topoSet.C:569
virtual bool unset(const label id)
Unset an index.
Definition topoSet.C:551
bool readIOcontents(const word &wantedType, labelHashSet &contents)
Read into labelHashSet if IOobject flags set. Return true if read.
Definition topoSet.C:139
static fileName localPath(const polyMesh &mesh, const word &name)
Name of file set will use.
Definition topoSet.C:127
void operator=(const topoSet &)
Copy labelHashSet part only.
Definition topoSet.C:715
autoPtr< topoSet > clone() const
Clone.
Definition topoSet.H:358
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const =0
Like above but also writes mesh related quantity (usually coordinate).
static autoPtr< topoSet > New(const word &setType, const polyMesh &mesh, const word &name, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, IOobjectOption::writeOption wOpt=IOobjectOption::NO_WRITE)
Return a pointer to a toposet read from file.
Definition topoSet.C:48
void checkLabels(const labelUList &labels, const label maxSize)
Check limits on addressable range.
Definition topoSet.C:220
topoSet(const topoSet &)=delete
No copy construct.
virtual label maxSize(const polyMesh &mesh) const =0
Return max allowable index (+1). Not implemented.
static int disallowGenericSets
Debug switch to disallow the use of generic sets.
Definition topoSet.H:151
declareRunTimeSelectionTable(autoPtr, topoSet, set,(const polyMesh &mesh, const word &name, const topoSet &set, IOobjectOption::writeOption wOpt),(mesh, name, set, wOpt))
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches.
Definition topoSet.C:646
TypeName("topoSet")
Runtime type information.
virtual void subset(const labelUList &elems)
Subset contents. Only elements present in both sets remain.
Definition topoSet.C:597
declareRunTimeSelectionTable(autoPtr, topoSet, size,(const polyMesh &mesh, const word &name, const label size, IOobjectOption::writeOption wOpt),(mesh, name, size, wOpt))
static IOobject findIOobject(const polyMesh &mesh, const word &name, IOobjectOption::registerOption reg, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, IOobjectOption::writeOption wOpt=IOobjectOption::NO_WRITE)
Find IOobject in the polyMesh/sets/ (used as constructor helper).
Definition topoSet.H:174
static IOobject findIOobject(const polyMesh &mesh, const word &name, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, IOobjectOption::writeOption wOpt=IOobjectOption::NO_WRITE, IOobjectOption::registerOption reg=IOobjectOption::LEGACY_REGISTER)
Find IOobject in the polyMesh/sets/ (used as constructor helper).
Definition topoSet.C:352
virtual void subtractSet(const labelUList &elems)
Subtract given elements from the set.
Definition topoSet.C:639
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels. Not implemented.
Definition topoSet.C:687
static void setInstance(const fileName &instance, Container &items)
Helper: set instance on all items in container.
declareRunTimeSelectionTable(autoPtr, topoSet, word,(const polyMesh &mesh, const word &name, IOobjectOption::readOption rOpt, IOobjectOption::writeOption wOpt),(mesh, name, rOpt, wOpt))
label writeDebug(Ostream &os, const label maxElem, labelHashSet::const_iterator &iter) const
Write part of contents nicely formatted.
Definition topoSet.C:260
virtual bool contains(const label id) const
Has the given index?
Definition topoSet.C:533
virtual void updateLabels(const labelUList &map)
Update map from map.
Definition topoSet.C:164
virtual bool set(const label id)
Set an index.
Definition topoSet.C:545
virtual ~topoSet()=default
Destructor.
virtual void check(const label maxSize)
Check limits on addressable range.
Definition topoSet.C:252
virtual void addSet(const labelUList &elems)
Add given elements to the set.
Definition topoSet.C:625
A class for handling words, derived from Foam::string.
Definition word.H:66
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
dynamicFvMesh & mesh
engineTime & runTime
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition error.H:688
OBJstream os(runTime.globalPath()/outputName)
const auto & io
Namespace for OpenFOAM.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition HashSet.H:85
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).
#define FOAM_DEPRECATED_FOR(since, replacement)
Definition stdFoam.H:43
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