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-2025 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 "pointFieldFwd.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 class polyMesh;
51 class primitiveMesh;
52 class polyTopoChangeMap;
53 
54 /*---------------------------------------------------------------------------*\
55  Class topoSet Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class topoSet
59 :
60  public regIOobject,
61  public labelHashSet
62 {
63  // Private Member Functions
64 
65  //- Write part of contents nicely formatted. Prints labels only.
66  void writeDebug
67  (
68  Ostream& os,
69  const label maxElem,
71  label& elemI
72  ) const;
73 
74  //- Write part of contents nicely formatted. Prints label
75  // and corresponding coordinate.
76  void writeDebug
77  (
78  Ostream& os,
79  const pointField& coords,
80  const label maxElem,
82  label& elemI
83  ) const;
84 
85 
86 protected:
87 
88  // Protected Member Functions
89 
90  //- Update map from map. Used to update cell/face labels
91  // after morphing
92  void updateLabels(const labelList& map);
93 
94  //- Check validity of contents.
95  void check(const label maxLabel);
96 
97  //- Write labels and coordinates columnwise to os. Truncate to maxLen.
98  void writeDebug
99  (
100  Ostream& os,
101  const pointField& coords,
102  const label maxLen
103  ) const;
104 
105 
106 public:
107 
108  //- Runtime type information
109  TypeName("topoSet");
110 
111 
112  // Static
113 
114  //- Name of file set will use.
115  static fileName localPath(const polyMesh& mesh, const word& name);
116 
117 
118  // Declare run-time constructor selection table
119 
120  // For the direct constructor
122  (
123  autoPtr,
124  topoSet,
125  word,
126  (
127  const polyMesh& mesh,
128  const word& name,
129  readOption r,
130  writeOption w
131  ),
132  (mesh, name, r, w)
133  );
134 
135  // For the constructor from size
137  (
138  autoPtr,
139  topoSet,
140  size,
141  (
142  const polyMesh& mesh,
143  const word& name,
144  const label size,
145  writeOption w
146  ),
147  (mesh, name, size, w)
148  );
149 
150  // For the constructor as copy
152  (
153  autoPtr,
154  topoSet,
155  set,
156  (
157  const polyMesh& mesh,
158  const word& name,
159  const topoSet& set,
160  writeOption w
161  ),
162  (mesh, name, set, w)
163  );
164 
165 
166  // Constructors
167 
168  //- Construct from IOobject as explicitly passed type.
169  // Can't use typeName info here since subclasses not yet instantiated
170  topoSet(const IOobject&, const word& wantedType);
171 
172  //- Construct from polyMesh and name. Searches for a polyMesh/sets
173  // directory but not beyond mesh.facesInstance.
174  topoSet
175  (
176  const polyMesh& mesh,
177  const word& wantedType,
178  const word& name,
181  );
182 
183  //- Construct empty from additional size of labelHashSet.
184  // Searches for a polyMesh/sets
185  // directory but not beyond mesh.facesInstance.
186  topoSet
187  (
188  const polyMesh& mesh,
189  const word& name,
190  const label,
192  );
193 
194  //- Construct empty from additional labelHashSet
195  // Searches for a polyMesh/sets
196  // directory but not beyond mesh.facesInstance.
197  topoSet
198  (
199  const polyMesh& mesh,
200  const word& name,
201  const labelHashSet&,
203  );
204 
205  //- Construct empty from IOobject and size.
206  topoSet(const IOobject&, const label size);
207 
208  //- Construct from IOobject and labelHashSet.
209  topoSet(const IOobject&, const labelHashSet&);
210 
211  //- Disallow default bitwise copy construction
212  topoSet(const topoSet&) = delete;
213 
214 
215  //- Clone
216  autoPtr<topoSet> clone() const
217  {
219  return autoPtr<topoSet>(nullptr);
220  }
221 
222 
223  // Selectors
224 
225  //- Return a pointer to a toposet read from file
226  static autoPtr<topoSet> New
227  (
228  const word& setType,
229  const polyMesh& mesh,
230  const word& name,
233  );
234 
235  //- Return a pointer to a new toposet of given size
236  static autoPtr<topoSet> New
237  (
238  const word& setType,
239  const polyMesh& mesh,
240  const word& name,
241  const label size,
243  );
244 
245  //- Return a pointer to a new toposet as copy of another toposet
246  static autoPtr<topoSet> New
247  (
248  const word& setType,
249  const polyMesh& mesh,
250  const word& name,
251  const topoSet& set,
253  );
254 
255 
256  //- Destructor
257  virtual ~topoSet();
258 
259 
260  // Member Functions
261 
262  //- Invert contents.
263  // Insert all members 0..maxLen-1 which were not in set
264  virtual void invert(const label maxLen);
265 
266  //- Subset contents. Only elements present in both sets remain.
267  virtual void subset(const topoSet& set);
268 
269  //- Add elements present in set.
270  virtual void addSet(const topoSet& set);
271 
272  //- Delete elements present in set.
273  virtual void deleteSet(const topoSet& set);
274 
275  //- Sync set across coupled patches.
276  virtual void sync(const polyMesh& mesh);
277 
278  //- Write labels columnwise to os. Truncate to maxLen.
279  virtual void writeDebug(Ostream& os, const label maxLen) const;
280 
281  //- Like above but also writes mesh related quantity
282  // (usually coordinate).
283  virtual void writeDebug
284  (
285  Ostream& os,
286  const primitiveMesh&,
287  const label maxLen
288  ) const = 0;
289 
290  //- Write contents.
291  virtual bool writeData(Ostream&) const;
292 
293  //- Update any stored data for new labels. Not implemented.
294  virtual void topoChange(const polyTopoChangeMap& map);
295 
296  //- Return max allowable index (+1). Not implemented.
297  virtual label maxSize(const polyMesh& mesh) const = 0;
298 
299 
300  // Member Operators
301 
302  //- Copy labelHashSet part only
303  void operator=(const topoSet&);
304 };
305 
306 
307 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
308 
309 } // End namespace Foam
310 
311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
312 
313 #endif
314 
315 // ************************************************************************* //
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:307
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:61
virtual bool writeData(Ostream &) const
Write contents.
Definition: topoSet.C:536
virtual void invert(const label maxLen)
Invert contents.
Definition: topoSet.C:444
static fileName localPath(const polyMesh &mesh, const word &name)
Name of file set will use.
Definition: topoSet.C:123
void operator=(const topoSet &)
Copy labelHashSet part only.
Definition: topoSet.C:550
virtual ~topoSet()
Destructor.
Definition: topoSet.C:438
void check(const label maxLabel)
Check validity of contents.
Definition: topoSet.C:180
void updateLabels(const labelList &map)
Update map from map. Used to update cell/face labels.
Definition: topoSet.C:134
topoSet(const IOobject &, const word &wantedType)
Construct from IOobject as explicitly passed type.
Definition: topoSet.C:289
virtual void deleteSet(const topoSet &set)
Delete elements present in set.
Definition: topoSet.C:490
virtual label maxSize(const polyMesh &mesh) const =0
Return max allowable index (+1). Not implemented.
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches.
Definition: topoSet.C:499
virtual void addSet(const topoSet &set)
Add elements present in set.
Definition: topoSet.C:481
TypeName("topoSet")
Runtime type information.
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:45
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Definition: topoSet.C:462
declareRunTimeSelectionTable(autoPtr, topoSet, word,(const polyMesh &mesh, const word &name, readOption r, writeOption w),(mesh, name, r, w))
virtual void topoChange(const polyTopoChangeMap &map)
Update any stored data for new labels. Not implemented.
Definition: topoSet.C:542
autoPtr< topoSet > clone() const
Clone.
Definition: topoSet.H:215
A class for handling words, derived from string.
Definition: word.H:62
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#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