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-2019 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::topoSet
29 
30 Description
31  General set of labels of mesh quantity (points, cells, faces).
32 
33  Contains various 'notImplemented' functions, but I do not want to make
34  this class abstract since it is quite handy to work on topoSets.
35 
36 SourceFiles
37  topoSet.C
38  topoSetTemplates.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef topoSet_H
43 #define topoSet_H
44 
45 #include "HashSet.H"
46 #include "regIOobject.H"
47 #include "labelList.H"
48 #include "typeInfo.H"
49 #include "autoPtr.H"
50 #include "pointField.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 // Forward Declarations
58 class mapPolyMesh;
59 class polyMesh;
60 class primitiveMesh;
61 class mapDistributePolyMesh;
62 
63 /*---------------------------------------------------------------------------*\
64  Class topoSet Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 class topoSet
68 :
69  public regIOobject,
70  public labelHashSet
71 {
72 protected:
73 
74  // Protected Member Functions
75 
76  //- Update map from map.
77  // Used to update cell/face labels after morphing
78  virtual void updateLabels(const labelUList& map);
79 
80  //- Check limits on addressable range.
81  virtual void check(const label maxSize);
82 
83  //- Write part of contents nicely formatted. Prints labels only.
84  void writeDebug
85  (
86  Ostream& os,
87  const label maxElem,
89  label& elemI
90  ) const;
91 
92  //- Write part of contents nicely formatted. Prints label
93  // and corresponding coordinate.
94  void writeDebug
95  (
96  Ostream& os,
97  const pointField& coords,
98  const label maxElem,
100  label& elemI
101  ) const;
102 
103  //- Write labels and coordinates columnwise to os. Truncate to maxLen.
104  void writeDebug
105  (
106  Ostream& os,
107  const pointField& coords,
108  const label maxLen
109  ) const;
110 
111  //- No copy construct
112  topoSet(const topoSet&) = delete;
113 
114 
115 public:
116 
117  //- Runtime type information
118  TypeName("topoSet");
119 
120 
121  // Static
122 
123  //- Debug switch to disallow the use of generic sets
124  static int disallowGenericSets;
125 
126  //- Name of file set will use.
127  static fileName localPath(const polyMesh& mesh, const word& name);
128 
129  //- Find IOobject in the polyMesh/sets (used as constructor helper)
130  static IOobject findIOobject
131  (
132  const polyMesh& mesh,
133  const word& name,
136  );
137 
138  //- Find IOobject in the polyMesh/sets (used as constructor helper)
139  static IOobject findIOobject
140  (
141  const Time& runTime,
142  const word& name,
145  );
146 
147 
148  // Declare run-time constructor selection table
149 
150  // For the direct constructor
152  (
153  autoPtr,
154  topoSet,
155  word,
156  (
157  const polyMesh& mesh,
158  const word& name,
159  readOption r,
160  writeOption w
161  ),
162  (mesh, name, r, w)
163  );
164 
165  // For the constructor from size
167  (
168  autoPtr,
169  topoSet,
170  size,
171  (
172  const polyMesh& mesh,
173  const word& name,
174  const label size,
175  writeOption w
176  ),
177  (mesh, name, size, w)
178  );
179 
180  // For the constructor as copy
182  (
183  autoPtr,
184  topoSet,
185  set,
186  (
187  const polyMesh& mesh,
188  const word& name,
189  const topoSet& set,
190  writeOption w
191  ),
192  (mesh, name, set, w)
193  );
194 
195 
196  // Constructors
197 
198  //- Construct from IOobject as explicitly passed type.
199  // Can't use typeName info here since subclasses not yet instantiated
200  topoSet(const IOobject& obj, const word& wantedType);
201 
202  //- Construct from polyMesh and name.
203  // Searches for a polyMesh/sets directory but not beyond the
204  // mesh.facesInstance().
205  topoSet
206  (
207  const polyMesh& mesh,
208  const word& wantedType,
209  const word& name,
212  );
213 
214  //- Construct empty from additional size of labelHashSet.
215  // Searches for a polyMesh/sets directory but not beyond the
216  // mesh.facesInstance().
217  topoSet
218  (
219  const polyMesh& mesh,
220  const word& name,
221  const label size,
223  );
224 
225  //- Construct (no-read) with copy of labelHashSet
226  // Searches for a polyMesh/sets directory but not beyond the
227  // mesh.facesInstance().
228  topoSet
229  (
230  const polyMesh& mesh,
231  const word& name,
232  const labelHashSet& labels,
234  );
235 
236  //- Construct (no-read) with moving labelHashSet
237  // Searches for a polyMesh/sets directory but not beyond the
238  // mesh.facesInstance().
239  topoSet
240  (
241  const polyMesh& mesh,
242  const word& name,
243  labelHashSet&& labels,
245  );
246 
247  //- Construct (no-read) with copy of labels
248  // Searches for a polyMesh/sets directory but not beyond the
249  // mesh.facesInstance().
250  topoSet
251  (
252  const polyMesh& mesh,
253  const word& name,
254  const labelUList& labels,
256  );
257 
258  //- Construct empty from IOobject and HashSet size.
259  topoSet(const IOobject& io, const label size);
260 
261  //- Construct from IOobject and copy of labelHashSet.
262  topoSet(const IOobject& io, const labelHashSet& labels);
263 
264  //- Construct from IOobject and move labelHashSet.
265  topoSet(const IOobject& io, labelHashSet&& labels);
266 
267 
268  //- Clone
269  autoPtr<topoSet> clone() const
270  {
272  return nullptr;
273  }
274 
275 
276  // Selectors
277 
278  //- Return a pointer to a toposet read from file
279  static autoPtr<topoSet> New
280  (
281  const word& setType,
282  const polyMesh& mesh,
283  const word& name,
286  );
287 
288  //- Return a pointer to a new toposet of given size
289  static autoPtr<topoSet> New
290  (
291  const word& setType,
292  const polyMesh& mesh,
293  const word& name,
294  const label size,
296  );
297 
298  //- Return a pointer to a new toposet as copy of another toposet
299  static autoPtr<topoSet> New
300  (
301  const word& setType,
302  const polyMesh& mesh,
303  const word& name,
304  const topoSet& set,
306  );
307 
308 
309  //- Destructor
310  virtual ~topoSet() = default;
311 
312 
313  // Member Functions
314 
315  //- Has the given index?
316  virtual bool found(const label id) const;
317 
318  //- Set an index
319  virtual bool set(const label id);
320 
321  //- Unset an index
322  virtual bool unset(const label id);
323 
324  //- Set multiple indices
325  virtual void set(const labelUList& labels);
326 
327  //- Unset multiple indices
328  virtual void unset(const labelUList& labels);
329 
330  //- Invert contents.
331  // Insert all members [0,maxLen) which were not in set.
332  virtual void invert(const label maxLen);
333 
334  //- Subset contents. Only elements present in both sets remain.
335  virtual void subset(const topoSet& set);
336 
337  //- Add elements present in set.
338  virtual void addSet(const topoSet& set);
339 
340  //- Subtract elements present in set.
341  virtual void subtractSet(const topoSet& set);
342 
343  //- Sync set across coupled patches.
344  virtual void sync(const polyMesh& mesh);
345 
346  //- Write labels columnwise to os. Truncate to maxLen.
347  virtual void writeDebug(Ostream& os, const label maxLen) const;
348 
349  //- Like above but also writes mesh related quantity
350  //- (usually coordinate).
351  virtual void writeDebug
352  (
353  Ostream& os,
354  const primitiveMesh&,
355  const label maxLen
356  ) const = 0;
357 
358  //- Write contents.
359  virtual bool writeData(Ostream&) const;
360 
361  //- Update any stored data for new labels. Not implemented.
362  virtual void updateMesh(const mapPolyMesh& morphMap);
363 
364  //- Update any stored data for mesh redistribution.
365  virtual void distribute(const mapDistributePolyMesh&) = 0;
366 
367  //- Return max allowable index (+1). Not implemented.
368  virtual label maxSize(const polyMesh& mesh) const = 0;
369 
370  //- Helper: call updateMesh on all sets in container (and
371  // updates instance)
372  template<class Container>
373  static void updateMesh
374  (
375  const fileName& instance,
376  const mapPolyMesh&,
377  Container&
378  );
379 
380  //- Helper: set instance on all sets in container
381  template<class Container>
382  static void setInstance(const fileName& instance, Container&);
383 
384  //- Helper: remove all sets files from mesh instance
385  static void removeFiles(const polyMesh&);
386 
387 
388  // Member Operators
389 
390  //- Copy labelHashSet part only
391  void operator=(const topoSet&);
392 
393 
394  // Housekeeping
395 
396  //- Deprecated(2018-10) subtract elements present in set.
397  // \deprecated(2018-10) - use subtractSet instead
398  virtual void deleteSet(const topoSet& set);
399 };
400 
401 
402 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
403 
404 } // End namespace Foam
405 
406 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
407 
408 #ifdef NoRepository
409  #include "topoSetTemplates.C"
410 #endif
411 
412 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
413 
414 #endif
415 
416 // ************************************************************************* //
Foam::topoSet::writeDebug
void writeDebug(Ostream &os, const label maxElem, topoSet::const_iterator &iter, label &elemI) const
Write part of contents nicely formatted. Prints labels only.
Definition: topoSet.C:221
Foam::topoSet::localPath
static fileName localPath(const polyMesh &mesh, const word &name)
Name of file set will use.
Definition: topoSet.C:131
regIOobject.H
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
Foam::topoSet::topoSet
topoSet(const topoSet &)=delete
No copy construct.
Foam::HashTable< zero::null, label, Hash< label > >::size
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:52
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::topoSet::setInstance
static void setInstance(const fileName &instance, Container &)
Helper: set instance on all sets in container.
Definition: topoSetTemplates.C:33
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:46
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
typeInfo.H
Foam::topoSet::operator=
void operator=(const topoSet &)
Copy labelHashSet part only.
Definition: topoSet.C:660
Foam::IOobject::instance
const fileName & instance() const
Definition: IOobjectI.H:167
Foam::topoSet::deleteSet
virtual void deleteSet(const topoSet &set)
Deprecated(2018-10) subtract elements present in set.
Definition: topoSet.C:583
Foam::topoSet::disallowGenericSets
static int disallowGenericSets
Debug switch to disallow the use of generic sets.
Definition: topoSet.H:123
Foam::topoSet::subset
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Definition: topoSet.C:562
Foam::topoSet::New
static autoPtr< topoSet > New(const word &setType, const polyMesh &mesh, const word &name, readOption r=MUST_READ, writeOption w=NO_WRITE)
Return a pointer to a toposet read from file.
Definition: topoSet.C:54
Foam::HashSet< label, Hash< label > >
Foam::topoSet::invert
virtual void invert(const label maxLen)
Invert contents.
Definition: topoSet.C:541
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
topoSetTemplates.C
Foam::topoSet::findIOobject
static IOobject findIOobject(const polyMesh &mesh, const word &name, readOption r=MUST_READ, writeOption w=NO_WRITE)
Find IOobject in the polyMesh/sets (used as constructor helper)
Definition: topoSet.C:315
Foam::HashSet< label, Hash< label > >::const_iterator
typename parent_type::const_key_iterator const_iterator
A const_iterator, returning reference to the key.
Definition: HashSet.H:112
Foam::topoSet::addSet
virtual void addSet(const topoSet &set)
Add elements present in set.
Definition: topoSet.C:569
Foam::IOobject::writeOption
writeOption
Enumeration defining the write options.
Definition: IOobject.H:127
Foam::topoSet::clone
autoPtr< topoSet > clone() const
Clone.
Definition: topoSet.H:268
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:419
Foam::topoSet::found
virtual bool found(const label id) const
Has the given index?
Definition: topoSet.C:511
Foam::topoSet::updateMesh
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels. Not implemented.
Definition: topoSet.C:632
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
labelList.H
Foam::Field< vector >
Foam::topoSet::set
virtual bool set(const label id)
Set an index.
Definition: topoSet.C:517
Foam::topoSet::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, topoSet, word,(const polyMesh &mesh, const word &name, readOption r, writeOption w),(mesh, name, r, w))
Foam::topoSet::subtractSet
virtual void subtractSet(const topoSet &set)
Subtract elements present in set.
Definition: topoSet.C:576
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:66
Foam::topoSet::maxSize
virtual label maxSize(const polyMesh &mesh) const =0
Return max allowable index (+1). Not implemented.
HashSet.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
pointField.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:67
Foam::topoSet::distribute
virtual void distribute(const mapDistributePolyMesh &)=0
Update any stored data for mesh redistribution.
Foam::topoSet::writeData
virtual bool writeData(Ostream &) const
Write contents.
Definition: topoSet.C:626
Foam::topoSet::~topoSet
virtual ~topoSet()=default
Destructor.
Foam::UList< label >
Foam::topoSet::unset
virtual bool unset(const label id)
Unset an index.
Definition: topoSet.C:523
Foam::topoSet::check
virtual void check(const label maxSize)
Check limits on addressable range.
Definition: topoSet.C:200
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:160
Foam::topoSet::TypeName
TypeName("topoSet")
Runtime type information.
Foam::IOobject::readOption
readOption
Enumeration defining the read options.
Definition: IOobject.H:118
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::mapDistributePolyMesh
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Definition: mapDistributePolyMesh.H:66
Foam::topoSet::sync
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches.
Definition: topoSet.C:589
Foam::topoSet::updateLabels
virtual void updateLabels(const labelUList &map)
Update map from map.
Definition: topoSet.C:144
Foam::topoSet::removeFiles
static void removeFiles(const polyMesh &)
Helper: remove all sets files from mesh instance.
Definition: topoSet.C:638
Foam::IOobject::MUST_READ
Definition: IOobject.H:120
autoPtr.H
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:78