topoSet.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::topoSet
26 
27 Description
28  General set of labels of mesh quantity (points, cells, faces).
29 
30  Contains various 'notImplemented' functions, but I do not want to make
31  this class abstract since it is quite handy to work on topoSets.
32 
33 SourceFiles
34  topoSet.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef topoSet_H
39 #define topoSet_H
40 
41 #include "HashSet.H"
42 #include "regIOobject.H"
43 #include "labelList.H"
44 #include "typeInfo.H"
45 #include "autoPtr.H"
46 #include "pointField.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 
54 class polyTopoChangeMap;
55 class polyMesh;
56 class primitiveMesh;
57 
58 /*---------------------------------------------------------------------------*\
59  Class topoSet Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 class topoSet
63 :
64  public regIOobject,
65  public labelHashSet
66 {
67 protected:
68 
69  // Protected Member Functions
70 
71  //- Update map from map. Used to update cell/face labels
72  // after morphing
73  void updateLabels(const labelList& map);
74 
75  //- Check validity of contents.
76  void check(const label maxLabel);
77 
78  //- Write part of contents nicely formatted. Prints labels only.
79  void writeDebug
80  (
81  Ostream& os,
82  const label maxElem,
84  label& elemI
85  ) const;
86 
87  //- Write part of contents nicely formatted. Prints label
88  // and corresponding coordinate.
89  void writeDebug
90  (
91  Ostream& os,
92  const pointField& coords,
93  const label maxElem,
95  label& elemI
96  ) const;
97 
98  //- Write labels and coordinates columnwise to os. Truncate to maxLen.
99  void writeDebug
100  (
101  Ostream& os,
102  const pointField& coords,
103  const label maxLen
104  ) const;
105 
106 
107 public:
108 
109  //- Runtime type information
110  TypeName("topoSet");
111 
112 
113  // Static
114 
115  //- Name of file set will use.
116  static fileName localPath(const polyMesh& mesh, const word& name);
117 
118 
119  // Declare run-time constructor selection table
120 
121  // For the direct constructor
123  (
124  autoPtr,
125  topoSet,
126  word,
127  (
128  const polyMesh& mesh,
129  const word& name,
130  readOption r,
131  writeOption w
132  ),
133  (mesh, name, r, w)
134  );
135 
136  // For the constructor from size
138  (
139  autoPtr,
140  topoSet,
141  size,
142  (
143  const polyMesh& mesh,
144  const word& name,
145  const label size,
146  writeOption w
147  ),
148  (mesh, name, size, w)
149  );
150 
151  // For the constructor as copy
153  (
154  autoPtr,
155  topoSet,
156  set,
157  (
158  const polyMesh& mesh,
159  const word& name,
160  const topoSet& set,
161  writeOption w
162  ),
163  (mesh, name, set, w)
164  );
165 
166 
167  // Constructors
168 
169 
170  //- Construct from IOobject as explicitly passed type.
171  // Can't use typeName info here since subclasses not yet instantiated
172  topoSet(const IOobject&, const word& wantedType);
173 
174  //- Construct from polyMesh and name. Searches for a polyMesh/sets
175  // directory but not beyond mesh.facesInstance.
176  topoSet
177  (
178  const polyMesh& mesh,
179  const word& wantedType,
180  const word& name,
183  );
184 
185  //- Construct empty from additional size of labelHashSet.
186  // Searches for a polyMesh/sets
187  // directory but not beyond mesh.facesInstance.
188  topoSet
189  (
190  const polyMesh& mesh,
191  const word& name,
192  const label,
194  );
195 
196  //- Construct empty from additional labelHashSet
197  // Searches for a polyMesh/sets
198  // directory but not beyond mesh.facesInstance.
199  topoSet
200  (
201  const polyMesh& mesh,
202  const word& name,
203  const labelHashSet&,
205  );
206 
207  //- Construct empty from IOobject and size.
208  topoSet(const IOobject&, const label size);
209 
210  //- Construct from IOobject and labelHashSet.
211  topoSet(const IOobject&, const labelHashSet&);
212 
213  //- Disallow default bitwise copy construction
214  topoSet(const topoSet&) = delete;
215 
216 
217  //- Clone
218  autoPtr<topoSet> clone() const
219  {
221  return autoPtr<topoSet>(nullptr);
222  }
223 
224 
225  // Selectors
226 
227  //- Return a pointer to a toposet read from file
228  static autoPtr<topoSet> New
229  (
230  const word& setType,
231  const polyMesh& mesh,
232  const word& name,
235  );
236 
237  //- Return a pointer to a new toposet of given size
238  static autoPtr<topoSet> New
239  (
240  const word& setType,
241  const polyMesh& mesh,
242  const word& name,
243  const label size,
245  );
246 
247  //- Return a pointer to a new toposet as copy of another toposet
248  static autoPtr<topoSet> New
249  (
250  const word& setType,
251  const polyMesh& mesh,
252  const word& name,
253  const topoSet& set,
255  );
256 
257 
258  //- Destructor
259  virtual ~topoSet();
260 
261 
262  // Member Functions
263 
264  //- Invert contents. (insert all members 0..maxLen-1 which were not in
265  // set)
266  virtual void invert(const label maxLen);
267 
268  //- Subset contents. Only elements present in both sets remain.
269  virtual void subset(const topoSet& set);
270 
271  //- Add elements present in set.
272  virtual void addSet(const topoSet& set);
273 
274  //- Delete elements present in set.
275  virtual void deleteSet(const topoSet& set);
276 
277  //- Sync set across coupled patches.
278  virtual void sync(const polyMesh& mesh);
279 
280  //- Write labels columnwise to os. Truncate to maxLen.
281  virtual void writeDebug(Ostream& os, const label maxLen) const;
282 
283  //- Like above but also writes mesh related quantity
284  // (usually coordinate).
285  virtual void writeDebug
286  (
287  Ostream& os,
288  const primitiveMesh&,
289  const label maxLen
290  ) const = 0;
291 
292  //- Write contents.
293  virtual bool writeData(Ostream&) const;
294 
295  //- Update any stored data for new labels. Not implemented.
296  virtual void topoChange(const polyTopoChangeMap& map);
297 
298  //- Return max allowable index (+1). Not implemented.
299  virtual label maxSize(const polyMesh& mesh) const = 0;
300 
301 
302  // Member Operators
303 
304  //- Copy labelHashSet part only
305  void operator=(const topoSet&);
306 };
307 
308 
309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
310 
311 } // End namespace Foam
312 
313 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
314 
315 #endif
316 
317 // ************************************************************************* //
bool set(const label &key)
Same as insert (cannot overwrite nil content)
Definition: HashSet.H:123
An STL-conforming const_iterator.
Definition: HashTable.H:498
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
readOption
Enumeration defining the read options.
Definition: IOobject.H:117
const word & name() const
Return name.
Definition: IOobject.H:310
writeOption
Enumeration defining the write options.
Definition: IOobject.H:126
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A class for handling file names.
Definition: fileName.H:82
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:75
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:65
virtual void deleteSet(const topoSet &set)
Delete elements present in set.
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.
void writeDebug(Ostream &os, const label maxElem, topoSet::const_iterator &iter, label &elemI) const
Write part of contents nicely formatted. Prints labels only.
virtual void addSet(const topoSet &set)
Add elements present in set.
void operator=(const topoSet &)
Copy labelHashSet part only.
void check(const label maxLabel)
Check validity of contents.
virtual void topoChange(const polyTopoChangeMap &map)
Update any stored data for new labels. Not implemented.
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
void updateLabels(const labelList &map)
Update map from map. Used to update cell/face labels.
topoSet(const IOobject &, const word &wantedType)
Construct from IOobject as explicitly passed type.
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches.
virtual label maxSize(const polyMesh &mesh) const =0
Return max allowable index (+1). Not implemented.
TypeName("topoSet")
Runtime type information.
virtual bool writeData(Ostream &) const
Write contents.
virtual ~topoSet()
Destructor.
static fileName localPath(const polyMesh &mesh, const word &name)
Name of file set will use.
declareRunTimeSelectionTable(autoPtr, topoSet, word,(const polyMesh &mesh, const word &name, readOption r, writeOption w),(mesh, name, r, w))
autoPtr< topoSet > clone() const
Clone.
Definition: topoSet.H:217
virtual void invert(const label maxLen)
Invert contents. (insert all members 0..maxLen-1 which were not in.
A class for handling words, derived from string.
Definition: word.H:62
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
Namespace for OpenFOAM.
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:59
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...