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 SourceFiles
34  topoSet.C
35  topoSetTemplates.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef topoSet_H
40 #define 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 
51 namespace Foam
52 {
53 
54 // Forward Declarations
55 class mapPolyMesh;
56 class polyMesh;
57 class primitiveMesh;
58 class mapDistributePolyMesh;
59 
60 /*---------------------------------------------------------------------------*\
61  Class topoSet Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 class topoSet
65 :
66  public regIOobject,
67  public labelHashSet
68 {
69 protected:
70 
71  // Protected Member Functions
72 
73  //- Update map from map.
74  // Used to update cell/face labels after morphing
75  virtual void updateLabels(const labelUList& map);
76 
77  //- Check limits on addressable range.
78  virtual void check(const label maxSize);
79 
80  //- Write part of contents nicely formatted. Prints labels only.
81  void writeDebug
82  (
83  Ostream& os,
84  const label maxElem,
86  label& elemI
87  ) const;
88 
89  //- Write part of contents nicely formatted. Prints label
90  // and corresponding coordinate.
91  void writeDebug
92  (
93  Ostream& os,
94  const pointField& coords,
95  const label maxElem,
97  label& elemI
98  ) const;
99 
100  //- Write labels and coordinates columnwise to os. Truncate to maxLen.
101  void writeDebug
102  (
103  Ostream& os,
104  const pointField& coords,
105  const label maxLen
106  ) const;
107 
108  //- No copy construct
109  topoSet(const topoSet&) = delete;
110 
111 
112 public:
113 
114  //- Runtime type information
115  TypeName("topoSet");
116 
117 
118  // Static
119 
120  //- Debug switch to disallow the use of generic sets
121  static int disallowGenericSets;
122 
123  //- Name of file set will use.
124  static fileName localPath(const polyMesh& mesh, const word& name);
125 
126  //- Find IOobject in the polyMesh/sets (used as constructor helper)
127  static IOobject findIOobject
128  (
129  const polyMesh& mesh,
130  const word& name,
133  );
134 
135  //- Find IOobject in the polyMesh/sets (used as constructor helper)
136  static IOobject findIOobject
137  (
138  const Time& runTime,
139  const word& name,
142  );
143 
144 
145  // Declare run-time constructor selection table
146 
147  // For the direct constructor
149  (
150  autoPtr,
151  topoSet,
152  word,
153  (
154  const polyMesh& mesh,
155  const word& name,
156  readOption r,
157  writeOption w
158  ),
159  (mesh, name, r, w)
160  );
161 
162  // For the constructor from size
164  (
165  autoPtr,
166  topoSet,
167  size,
168  (
169  const polyMesh& mesh,
170  const word& name,
171  const label size,
172  writeOption w
173  ),
174  (mesh, name, size, w)
175  );
176 
177  // For the constructor as copy
179  (
180  autoPtr,
181  topoSet,
182  set,
183  (
184  const polyMesh& mesh,
185  const word& name,
186  const topoSet& set,
187  writeOption w
188  ),
189  (mesh, name, set, w)
190  );
191 
192 
193  // Constructors
194 
195  //- Construct from IOobject as explicitly passed type.
196  // Can't use typeName info here since subclasses not yet instantiated
197  topoSet(const IOobject& obj, const word& wantedType);
198 
199  //- Construct from polyMesh and name.
200  // Searches for a polyMesh/sets directory but not beyond the
201  // mesh.facesInstance().
202  topoSet
203  (
204  const polyMesh& mesh,
205  const word& wantedType,
206  const word& name,
209  );
210 
211  //- Construct empty from additional size of labelHashSet.
212  // Searches for a polyMesh/sets directory but not beyond the
213  // mesh.facesInstance().
214  topoSet
215  (
216  const polyMesh& mesh,
217  const word& name,
218  const label size,
220  );
221 
222  //- Construct (no-read) with copy of labelHashSet
223  // Searches for a polyMesh/sets directory but not beyond the
224  // mesh.facesInstance().
225  topoSet
226  (
227  const polyMesh& mesh,
228  const word& name,
229  const labelHashSet& labels,
231  );
232 
233  //- Construct (no-read) with moving labelHashSet
234  // Searches for a polyMesh/sets directory but not beyond the
235  // mesh.facesInstance().
236  topoSet
237  (
238  const polyMesh& mesh,
239  const word& name,
240  labelHashSet&& labels,
242  );
243 
244  //- Construct (no-read) with copy of labels
245  // Searches for a polyMesh/sets directory but not beyond the
246  // mesh.facesInstance().
247  topoSet
248  (
249  const polyMesh& mesh,
250  const word& name,
251  const labelUList& labels,
253  );
254 
255  //- Construct empty from IOobject and HashSet size.
256  topoSet(const IOobject& io, const label size);
257 
258  //- Construct from IOobject and copy of labelHashSet.
259  topoSet(const IOobject& io, const labelHashSet& labels);
260 
261  //- Construct from IOobject and move labelHashSet.
262  topoSet(const IOobject& io, labelHashSet&& labels);
263 
264 
265  //- Clone
266  autoPtr<topoSet> clone() const
267  {
269  return nullptr;
270  }
271 
272 
273  // Selectors
274 
275  //- Return a pointer to a toposet read from file
276  static autoPtr<topoSet> New
277  (
278  const word& setType,
279  const polyMesh& mesh,
280  const word& name,
283  );
284 
285  //- Return a pointer to a new toposet of given size
286  static autoPtr<topoSet> New
287  (
288  const word& setType,
289  const polyMesh& mesh,
290  const word& name,
291  const label size,
293  );
294 
295  //- Return a pointer to a new toposet as copy of another toposet
296  static autoPtr<topoSet> New
297  (
298  const word& setType,
299  const polyMesh& mesh,
300  const word& name,
301  const topoSet& set,
303  );
304 
305 
306  //- Destructor
307  virtual ~topoSet() = default;
308 
309 
310  // Member Functions
311 
312  //- Has the given index?
313  virtual bool found(const label id) const;
314 
315  //- Set an index
316  virtual bool set(const label id);
317 
318  //- Unset an index
319  virtual bool unset(const label id);
320 
321  //- Set multiple indices
322  virtual void set(const labelUList& labels);
323 
324  //- Unset multiple indices
325  virtual void unset(const labelUList& labels);
326 
327  //- Invert contents.
328  // Insert all members [0,maxLen) which were not in set.
329  virtual void invert(const label maxLen);
330 
331  //- Subset contents. Only elements present in both sets remain.
332  virtual void subset(const topoSet& set);
333 
334  //- Add elements present in set.
335  virtual void addSet(const topoSet& set);
336 
337  //- Subtract elements present in set.
338  virtual void subtractSet(const topoSet& set);
339 
340  //- Sync set across coupled patches.
341  virtual void sync(const polyMesh& mesh);
342 
343  //- Write labels columnwise to os. Truncate to maxLen.
344  virtual void writeDebug(Ostream& os, const label maxLen) const;
345 
346  //- Like above but also writes mesh related quantity
347  //- (usually coordinate).
348  virtual void writeDebug
349  (
350  Ostream& os,
351  const primitiveMesh&,
352  const label maxLen
353  ) const = 0;
354 
355  //- Write contents.
356  virtual bool writeData(Ostream&) const;
357 
358  //- Update any stored data for new labels. Not implemented.
359  virtual void updateMesh(const mapPolyMesh& morphMap);
360 
361  //- Update any stored data for mesh redistribution.
362  virtual void distribute(const mapDistributePolyMesh&) = 0;
363 
364  //- Return max allowable index (+1). Not implemented.
365  virtual label maxSize(const polyMesh& mesh) const = 0;
366 
367  //- Helper: call updateMesh on all sets in container (and
368  // updates instance)
369  template<class Container>
370  static void updateMesh
371  (
372  const fileName& instance,
373  const mapPolyMesh&,
374  Container&
375  );
376 
377  //- Helper: set instance on all sets in container
378  template<class Container>
379  static void setInstance(const fileName& instance, Container&);
380 
381  //- Helper: remove all sets files from mesh instance
382  static void removeFiles(const polyMesh&);
383 
384 
385  // Member Operators
386 
387  //- Copy labelHashSet part only
388  void operator=(const topoSet&);
389 
390 
391  // Housekeeping
392 
393  //- Deprecated(2018-10) subtract elements present in set.
394  // \deprecated(2018-10) - use subtractSet instead
395  virtual void deleteSet(const topoSet& set);
396 };
397 
398 
399 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
400 
401 } // End namespace Foam
402 
403 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
404 
405 #ifdef NoRepository
406  #include "topoSetTemplates.C"
407 #endif
408 
409 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
410 
411 #endif
412 
413 // ************************************************************************* //
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:224
Foam::topoSet::localPath
static fileName localPath(const polyMesh &mesh, const word &name)
Name of file set will use.
Definition: topoSet.C:134
regIOobject.H
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::topoSet::topoSet
topoSet(const topoSet &)=delete
No copy construct.
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:169
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::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
typeInfo.H
Foam::topoSet::operator=
void operator=(const topoSet &)
Copy labelHashSet part only.
Definition: topoSet.C:657
Foam::IOobject::instance
const fileName & instance() const noexcept
Definition: IOobjectI.H:196
Foam::topoSet::deleteSet
virtual void deleteSet(const topoSet &set)
Deprecated(2018-10) subtract elements present in set.
Definition: topoSet.C:580
Foam::topoSet::disallowGenericSets
static int disallowGenericSets
Debug switch to disallow the use of generic sets.
Definition: topoSet.H:120
Foam::topoSet::subset
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Definition: topoSet.C:559
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:55
Foam::HashSet< label, Hash< label > >
Foam::topoSet::invert
virtual void invert(const label maxLen)
Invert contents.
Definition: topoSet.C:538
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:318
Foam::HashSet::const_iterator
typename parent_type::const_key_iterator const_iterator
A const_iterator, returning reference to the key.
Definition: HashSet.H:121
Foam::topoSet::addSet
virtual void addSet(const topoSet &set)
Add elements present in set.
Definition: topoSet.C:566
Foam::IOobject::writeOption
writeOption
Enumeration defining the write options.
Definition: IOobject.H:192
Foam::topoSet::clone
autoPtr< topoSet > clone() const
Clone.
Definition: topoSet.H:265
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
Foam::topoSet::found
virtual bool found(const label id) const
Has the given index?
Definition: topoSet.C:508
Foam::topoSet::updateMesh
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels. Not implemented.
Definition: topoSet.C:629
labelList.H
Foam::Field< vector >
Foam::topoSet::set
virtual bool set(const label id)
Set an index.
Definition: topoSet.C:514
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:573
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
Foam::topoSet::maxSize
virtual label maxSize(const polyMesh &mesh) const =0
Return max allowable index (+1). Not implemented.
HashSet.H
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
pointField.H
Foam::IOobject::name
const word & name() const noexcept
Return name.
Definition: IOobjectI.H:65
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:73
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:623
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:520
Foam::topoSet::check
virtual void check(const label maxSize)
Check limits on addressable range.
Definition: topoSet.C:203
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::topoSet::TypeName
TypeName("topoSet")
Runtime type information.
Foam::IOobject::readOption
readOption
Enumeration defining the read options.
Definition: IOobject.H:183
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:586
Foam::topoSet::updateLabels
virtual void updateLabels(const labelUList &map)
Update map from map.
Definition: topoSet.C:147
Foam::topoSet::removeFiles
static void removeFiles(const polyMesh &)
Helper: remove all sets files from mesh instance.
Definition: topoSet.C:635
Foam::IOobject::MUST_READ
Definition: IOobject.H:185
autoPtr.H
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:78