UnsortedMeshedSurface.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-2021 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::UnsortedMeshedSurface
26 
27 Description
28  A surface geometry mesh, in which the surface zone information is
29  conveyed by the 'zoneId' associated with each face.
30 
31  This form of surface description is particularly useful for reading in
32  surface meshes from third-party formats (eg, obj, stl, gts, etc.). It
33  can also be particularly useful for situations in which the surface
34  many be adjusted in an arbitrary manner without worrying about needed
35  to adjust the zone information (eg, surface refinement).
36 
37 See also
38  The Foam::MeshedSurface - which is organised as a surface mesh, but
39  with independent zone information.
40 
41 SourceFiles
42  UnsortedMeshedSurface.C
43 
44 \*---------------------------------------------------------------------------*/
45 
46 #ifndef UnsortedMeshedSurface_H
47 #define UnsortedMeshedSurface_H
48 
49 #include "MeshedSurface.H"
50 #include "surfZoneIdentifierList.H"
51 #include "surfZoneList.H"
52 #include "surfaceFormatsCore.H"
53 #include "runTimeSelectionTables.H"
55 #include "HashSet.H"
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 namespace Foam
60 {
61 
62 // Forward declaration of friend functions and operators
63 
64 class Time;
65 class IFstream;
66 
67 template<class Face> class MeshedSurface;
68 template<class Face> class MeshedSurfaceProxy;
69 template<class Face> class UnsortedMeshedSurface;
70 
71 /*---------------------------------------------------------------------------*\
72  Class UnsortedMeshedSurface Declaration
73 \*---------------------------------------------------------------------------*/
74 
75 template<class Face>
76 class UnsortedMeshedSurface
77 :
78  public MeshedSurface<Face>
79 {
80  // friends - despite different face representationsx
81  template<class Face2> friend class MeshedSurface;
82  template<class Face2> friend class UnsortedMeshedSurface;
83  friend class surfMesh;
84 
85 private:
86 
87  // Private Typedefs for convenience
88 
89  typedef MeshedSurface<Face> ParentType;
90  typedef MeshedSurface<Face> FriendType;
91  typedef MeshedSurfaceProxy<Face> ProxyType;
92 
93 
94  // Private Member Data
95 
96  //- The zone Id associated with each face
97  labelList zoneIds_;
98 
99  //- Zone information (face ordering nFaces/startFace only used
100  // during reading and writing)
101  List<surfZoneIdentifier> zoneToc_;
102 
103 
104  // Private Member Functions
105 
106  //- Disable resize with value
107  void resize(const label, const Face&);
108 
109  //- Disable setSize with value
110  void setSize(const label, const Face&);
111 
112 
113 protected:
114 
115  // Protected Member functions
116 
117  //- Return non-const access to the zone Ids
119  {
120  return zoneIds_;
121  }
122 
123  //- Return non-const access to the zone table-of-contents
125  {
126  return zoneToc_;
127  }
128 
129  //- Set new zones from faceMap
130  virtual void remapFaces(const labelUList& faceMap);
131 
132 
133 public:
134 
135  // Public Typedefs
136 
137  //- Face type used
138  typedef Face FaceType;
139 
140  //- Runtime type information
141  TypeName("UnsortedMeshedSurface");
142 
143 
144  // Static
145 
146  //- Can we read this file format?
147  static bool canReadType(const word& ext, const bool verbose=false);
148 
149  //- Can we read this file format?
150  static bool canRead(const fileName&, const bool verbose=false);
151 
152  //- Can we write this file format?
153  static bool canWriteType(const word& ext, const bool verbose=false);
154 
155  static wordHashSet readTypes();
156  static wordHashSet writeTypes();
157 
158 
159  // Constructors
160 
161  //- Construct null
163 
164  //- Construct by transferring components
165  // (points, faces, zone ids, zone info).
167  (
168  pointField&&,
169  List<Face>&&,
172  );
173 
174  //- Construct by transferring points, faces.
175  // Use zone information, or set single default zone
177  (
178  pointField&&,
179  List<Face>&&,
180  const labelUList& zoneSizes = labelUList(),
181  const UList<word>& zoneNames = UList<word>()
182  );
183 
184  //- Copy constructor
186 
187  //- Construct from a meshedSurface
189 
190  //- Construct by transferring the contents from a UnsortedMeshedSurface
192 
193  //- Construct by transferring the contents from a meshedSurface
195 
196  //- Construct from file name (uses extension to determine type)
198 
199  //- Construct from file name (uses extension to determine type)
200  UnsortedMeshedSurface(const fileName&, const word&);
201 
202  //- Construct from objectRegistry and a named surface
203  UnsortedMeshedSurface(const Time&, const word& surfName="");
204 
205 
206  // Declare run-time constructor selection table
207 
209  (
210  autoPtr,
212  fileExtension,
213  (
214  const fileName& name
215  ),
216  (name)
217  );
218 
219 
220  // Selectors
221 
222  //- Select constructed from filename (explicit extension)
224  (
225  const fileName&,
226  const word& ext
227  );
228 
229  //- Select constructed from filename (implicit extension)
231 
232 
233  //- Destructor
234  virtual ~UnsortedMeshedSurface();
235 
236 
237  // Member Function Selectors
238 
240  (
241  void,
243  write,
244  fileExtension,
245  (
246  const fileName& name,
247  const UnsortedMeshedSurface<Face>& surf
248  ),
249  (name, surf)
250  );
251 
252  //- Write to file
253  static void write(const fileName&, const UnsortedMeshedSurface<Face>&);
254 
255 
256  // Member Functions
257 
258  // Access
259 
260  //- The surface size is the number of faces
261  label size() const
262  {
263  return ParentType::size();
264  }
265 
266  //- Reset size of face and zone list
267  void setSize(const label);
268 
269  //- Return const access to the zone ids
270  const List<label>& zoneIds() const
271  {
272  return zoneIds_;
273  }
274 
275  //- Return const access to the zone table-of-contents
276  const List<surfZoneIdentifier>& zoneToc() const
277  {
278  return zoneToc_;
279  }
280 
281  //- Sort faces according to zoneIds
282  // Returns a surfZoneList and sets faceMap to index within faces()
283  // (i.e. map from original,unsorted to sorted)
284  surfZoneList sortedZones(labelList& faceMap) const;
285 
286  //- Set zones to 0 and set a single zone
287  void setOneZone();
288 
289  //- Set zone ids and zones
290  void setZones(const surfZoneList&);
291 
292  //- Set zone ids and zones
293  void setZones(const labelUList& sizes, const UList<word>& names);
294 
295  //- Set zone ids and zones with default names
296  void setZones(const labelUList& sizes);
297 
298 
299  // Edit
300 
301  //- Clear all storage
302  virtual void clear();
303 
304  //- Return new surface.
305  // Returns return pointMap, faceMap from subsetMeshMap
307  (
308  const labelHashSet& include,
309  labelList& pointMap,
310  labelList& faceMap
311  ) const;
312 
313  //- Return new surface.
315  (
316  const labelHashSet& include
317  ) const;
318 
319  //- Inherit reset from MeshedSurface<Face>
321 
322  //- Transfer components (points, faces, zone ids).
323  virtual void reset
324  (
325  pointField&&,
326  List<Face>&&,
328  );
329 
330  //- Transfer components (points, faces, zone ids).
331  virtual void reset
332  (
333  List<point>&&,
334  List<Face>&&,
336  );
337 
338  //- Transfer the contents of the argument and annul the argument
340 
341  //- Transfer the contents of the argument and annul the argument
343 
344 
345  // Read
346 
347  //- Read from file. Chooses reader based on explicit extension
348  bool read(const fileName&, const word& ext);
349 
350  //- Read from file. Chooses reader based on detected extension
351  virtual bool read(const fileName&);
352 
353 
354  // Write
355 
356  //- Generic write routine. Chooses writer based on extension.
357  virtual void write(const fileName& name) const
358  {
359  write(name, *this);
360  }
361 
362  //- Write to database
363  void write(const Time&, const word& surfName="") const;
364 
365 
366  // Member Operators
367 
369 
370  //- Conversion operator to MeshedSurfaceProxy
371  operator MeshedSurfaceProxy<Face>() const;
372 };
373 
374 
375 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
376 
377 } // End namespace Foam
378 
379 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
380 
381 #ifdef NoRepository
382  #include "UnsortedMeshedSurface.C"
383 #endif
384 
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
386 
387 #endif
388 
389 // ************************************************************************* //
A surface geometry mesh, in which the surface zone information is conveyed by the &#39;zoneId&#39; associated...
Definition: MeshedSurface.H:74
declareMemberFunctionSelectionTable(void, UnsortedMeshedSurface, write, fileExtension,(const fileName &name, const UnsortedMeshedSurface< Face > &surf),(name, surf))
virtual void clear()
Clear all storage.
bool read(const fileName &, const word &ext)
Read from file. Chooses reader based on explicit extension.
A HashTable with keys but without contents.
Definition: HashSet.H:59
virtual void reset(pointField &&, List< Face > &&, List< label > &&zoneIds)
Transfer components (points, faces, zone ids).
A class for handling file names.
Definition: fileName.H:79
A surface geometry mesh with zone information, not to be confused with the similarly named surfaceMes...
Definition: MeshedSurface.H:72
const List< label > & zoneIds() const
Return const access to the zone ids.
void transfer(UnsortedMeshedSurface< Face > &)
Transfer the contents of the argument and annul the argument.
static bool canRead(const fileName &, const bool verbose=false)
Can we read this file format?
void operator=(const UnsortedMeshedSurface< Face > &)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
virtual ~UnsortedMeshedSurface()
Destructor.
List< label > & storedZoneIds()
Return non-const access to the zone Ids.
UList< label > labelUList
Definition: UList.H:65
label size() const
The surface size is the number of faces.
declareRunTimeSelectionTable(autoPtr, UnsortedMeshedSurface, fileExtension,(const fileName &name),(name))
points setSize(newPointi)
UnsortedMeshedSurface subsetMesh(const labelHashSet &include, labelList &pointMap, labelList &faceMap) const
Return new surface.
A class for handling words, derived from string.
Definition: word.H:59
triSurfaceToAgglom resize(surfacesMesh.size())
TypeName("UnsortedMeshedSurface")
Runtime type information.
virtual void remapFaces(const labelUList &faceMap)
Set new zones from faceMap.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
A surface mesh consisting of general polygon faces.
Definition: surfMesh.H:55
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats...
Definition: MeshedSurface.H:73
const List< surfZoneIdentifier > & zoneToc() const
Return const access to the zone table-of-contents.
surfZoneList sortedZones(labelList &faceMap) const
Sort faces according to zoneIds.
label size() const
The surface size is the number of faces.
static bool canReadType(const word &ext, const bool verbose=false)
Can we read this file format?
void setZones(const surfZoneList &)
Set zone ids and zones.
static void write(const fileName &, const UnsortedMeshedSurface< Face > &)
Write to file.
List< surfZoneIdentifier > & storedZoneToc()
Return non-const access to the zone table-of-contents.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Macros to ease declaration of run-time selection tables.
static bool canWriteType(const word &ext, const bool verbose=false)
Can we write this file format?
static autoPtr< UnsortedMeshedSurface > New(const fileName &, const word &ext)
Select constructed from filename (explicit extension)
Namespace for OpenFOAM.
void setOneZone()
Set zones to 0 and set a single zone.