MeshedSurface.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::MeshedSurface
26 
27 Description
28  A surface geometry mesh with zone information, not to be confused with
29  the similarly named surfaceMesh, which actually refers to the cell faces
30  of a volume mesh.
31 
32  A MeshedSurface can have zero or more surface zones (roughly equivalent
33  to faceZones for a polyMesh). If surface zones are defined, they must
34  be contiguous and cover all of the faces.
35 
36  The MeshedSurface is intended for surfaces from a variety of sources.
37  - A set of points and faces without any surface zone information.
38  - A set of points and faces with randomly ordered zone information.
39  This could arise, for example, from reading external file formats
40  such as STL, etc.
41 
42 SourceFiles
43  MeshedSurface.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef MeshedSurface_H
48 #define MeshedSurface_H
49 
50 #include "PrimitivePatch.H"
51 #include "PatchTools.H"
52 #include "pointField.H"
53 #include "face.H"
54 #include "triFace.H"
55 
56 #include "surfZoneList.H"
57 #include "surfaceFormatsCore.H"
58 #include "runTimeSelectionTables.H"
60 #include "HashSet.H"
61 
62 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
63 
64 namespace Foam
65 {
66 
67 // Forward declaration of friend functions and operators
68 
69 class Time;
70 class surfMesh;
71 class polyBoundaryMesh;
72 
73 template<class Face> class MeshedSurface;
74 template<class Face> class MeshedSurfaceProxy;
75 template<class Face> class UnsortedMeshedSurface;
76 
77 /*---------------------------------------------------------------------------*\
78  Class MeshedSurface Declaration
79 \*---------------------------------------------------------------------------*/
80 
81 template<class Face>
82 class MeshedSurface
83 :
84  public PrimitivePatch<::Foam::List<Face>, pointField>,
86 {
87  // friends - despite different face representationsx
88  template<class Face2> friend class MeshedSurface;
89  template<class Face2> friend class UnsortedMeshedSurface;
90  friend class surfMesh;
91 
92  // Private Typedefs for convenience
93 
94  typedef PrimitivePatch<::Foam::List<Face>, pointField> ParentType;
95 
96  typedef UnsortedMeshedSurface<Face> FriendType;
97  typedef MeshedSurfaceProxy<Face> ProxyType;
98 
99 
100  // Private Member Data
101 
102  //- Zone information
103  // (face ordering nFaces/startFace only used during reading/writing)
104  List<surfZone> zones_;
105 
106 
107 protected:
108 
109  // Protected Member functions
110 
111  //- Transfer points/zones and transcribe face -> triFace
113 
114  //- Basic sanity check on zones
115  void checkZones();
116 
117  //- Non-const access to global points
119  {
120  return const_cast<pointField&>(ParentType::points());
121  }
122 
123  //- Non-const access to the faces
125  {
126  return static_cast<List<Face> &>(*this);
127  }
128 
129  //- Non-const access to the zones
131  {
132  return zones_;
133  }
134 
135  //- Sort faces by zones and store sorted faces
136  void sortFacesAndStore
137  (
138  List<Face>&& unsortedFaces,
139  List<label>&& zoneIds,
140  const bool sorted
141  );
142 
143  //- Set new zones from faceMap
144  virtual void remapFaces(const labelUList& faceMap);
145 
146 
147 public:
148 
149  // Public Typedefs
150 
151  //- Face type used
152  typedef Face FaceType;
153 
154  //- Runtime type information
155  ClassName("MeshedSurface");
156 
157 
158  // Static
159 
160  //- Face storage only handles triangulated faces
161  inline static bool isTri();
162 
163  //- Can we read this file format?
164  static bool canRead(const fileName&, const bool verbose=false);
165 
166  //- Can we read this file format?
167  static bool canReadType(const word& ext, const bool verbose=false);
168 
169  //- Can we write this file format?
170  static bool canWriteType(const word& ext, const bool verbose=false);
171 
172  static wordHashSet readTypes();
173  static wordHashSet writeTypes();
174 
175 
176  // Constructors
177 
178  //- Construct null
179  MeshedSurface();
180 
181  //- Construct by transferring components (points, faces, zones).
183  (
184  pointField&&,
185  List<Face>&&,
186  surfZoneList&&
187  );
188 
189  //- Construct by transferring components (points, faces).
190  // Use zone information if available
192  (
193  pointField&&,
194  List<Face>&&,
195  const labelUList& zoneSizes = labelUList(),
196  const UList<word>& zoneNames = UList<word>()
197  );
198 
199  //- Copy constructor
201 
202  //- Construct from a UnsortedMeshedSurface
204 
205  //- Construct from a boundary mesh with local points/faces
207  (
208  const polyBoundaryMesh&,
209  const bool globalPoints=false
210  );
211 
212  //- Construct from a surfMesh
213  MeshedSurface(const surfMesh&);
214 
215  //- Construct by transferring the contents from a UnsortedMeshedSurface
217 
218  //- Construct by transferring the contents from a MeshedSurface
220 
221  //- Construct from file name (uses extension to determine type)
222  MeshedSurface(const fileName&);
223 
224  //- Construct from file name (uses extension to determine type)
225  MeshedSurface(const fileName&, const word& ext);
226 
227  //- Construct from database
228  MeshedSurface(const Time&, const word& surfName="");
229 
230 
231  // Declare run-time constructor selection table
232 
234  (
235  autoPtr,
237  fileExtension,
238  (
239  const fileName& name
240  ),
241  (name)
242  );
243 
244 
245  // Selectors
246 
247  //- Select constructed from filename (explicit extension)
249  (
250  const fileName&,
251  const word& ext
252  );
253 
254  //- Select constructed from filename (implicit extension)
255  static autoPtr<MeshedSurface> New(const fileName&);
256 
257 
258  //- Destructor
259  virtual ~MeshedSurface();
260 
261 
262  // Member Function Selectors
263 
265  (
266  void,
268  write,
269  fileExtension,
270  (
271  const fileName& name,
272  const MeshedSurface<Face>& surf
273  ),
274  (name, surf)
275  );
276 
277  //- Write to file
278  static void write(const fileName&, const MeshedSurface<Face>&);
279 
280 
281  // Member Functions
282 
283  // Access
284 
285  //- The surface size is the number of faces
286  label size() const
287  {
288  return ParentType::size();
289  }
290 
291  //- Return const access to the faces
292  inline const List<Face>& faces() const
293  {
294  return static_cast<const List<Face> &>(*this);
295  }
296 
297  //- Const access to the surface zones.
298  // If zones are defined, they must be contiguous and cover the
299  // entire surface
300  const List<surfZone>& surfZones() const
301  {
302  return zones_;
303  }
304 
305  //- Add surface zones
306  virtual void addZones
307  (
308  const UList<surfZone>&,
309  const bool cullEmpty=false
310  );
311 
312  //- Add surface zones
313  virtual void addZones
314  (
315  const labelUList& sizes,
316  const UList<word>& names,
317  const bool cullEmpty=false
318  );
319 
320  //- Add surface zones
321  virtual void addZones
322  (
323  const labelUList& sizes,
324  const bool cullEmpty=false
325  );
326 
327  //- Remove surface zones
328  virtual void removeZones();
329 
330 
331  // Edit
332 
333  //- Clear all storage
334  virtual void clear();
335 
336  //- Move points
337  virtual void movePoints(const pointField&);
338 
339  //- Scale points. A non-positive factor is ignored
340  virtual void scalePoints(const scalar);
341 
342  //- Reset primitive data (points, faces and zones)
343  // Note, optimised to avoid overwriting data (with null)
344  virtual void reset
345  (
346  pointField&& points,
347  List<Face>&& faces,
348  surfZoneList&& zones
349  );
350 
351  //- Reset primitive data (points, faces and zones)
352  // Note, optimised to avoid overwriting data (with null)
353  virtual void reset
354  (
356  List<Face>&& faces,
357  surfZoneList&& zones
358  );
359 
360  //- Remove invalid faces
361  virtual void cleanup(const bool verbose);
362 
363  virtual bool stitchFaces
364  (
365  const scalar tol=small,
366  const bool verbose=false
367  );
368 
369  virtual bool checkFaces
370  (
371  const bool verbose=false
372  );
373 
374  //- Triangulate in-place, returning the number of triangles added
375  virtual label triangulate();
376 
377  //- Triangulate in-place, returning the number of triangles added
378  // and setting a map of original face Ids.
379  // The faceMap is zero-sized when no triangulation was done.
380  virtual label triangulate(List<label>& faceMap);
381 
382 
383  //- Return new surface.
384  // Returns return pointMap, faceMap from subsetMeshMap
386  (
387  const labelHashSet& include,
388  labelList& pointMap,
389  labelList& faceMap
390  ) const;
391 
392  //- Return new surface.
394  (
395  const labelHashSet& include
396  ) const;
397 
398  //- Transfer the contents of the argument and annul the argument
400 
401  //- Transfer the contents of the argument and annul the argument
403 
404 
405  // Read
406 
407  //- Read from file. Chooses reader based on explicit extension
408  bool read(const fileName&, const word& ext);
409 
410  //- Read from file. Chooses reader based on detected extension
411  virtual bool read(const fileName&);
412 
413 
414  // Write
415 
416  void writeStats(Ostream& os) const;
417 
418  //- Generic write routine. Chooses writer based on extension.
419  virtual void write(const fileName& name) const
420  {
421  write(name, *this);
422  }
423 
424  //- Write to database
425  void write(const Time&, const word& surfName="") const;
426 
427 
428  // Member Operators
429 
430  void operator=(const MeshedSurface<Face>&);
431 
432  //- Conversion operator to MeshedSurfaceProxy
433  operator MeshedSurfaceProxy<Face>() const;
434 };
435 
436 
437 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
438 
439 //- Specialisation for holding triangulated information
440 template<>
441 inline bool MeshedSurface<triFace>::isTri()
442 {
443  return true;
444 }
445 
446 
447 //- Specialisation for holding triangulated information
448 template<>
450 {
451  return 0;
452 }
453 
454 
455 //- Specialisation for holding triangulated information
456 template<>
458 {
459  if (notNull(faceMap))
460  {
461  faceMap.clear();
462  }
463 
464  return 0;
465 }
466 
467 
468 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
469 
470 } // End namespace Foam
471 
472 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
473 
474 #ifdef NoRepository
475  #include "MeshedSurface.C"
476 #endif
477 
478 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
479 
480 #endif
481 
482 // ************************************************************************* //
bool read(const fileName &, const word &ext)
Read from file. Chooses reader based on explicit extension.
A surface geometry mesh, in which the surface zone information is conveyed by the &#39;zoneId&#39; associated...
Definition: MeshedSurface.H:74
A HashTable with keys but without contents.
Definition: HashSet.H:59
void sortFacesAndStore(List< Face > &&unsortedFaces, List< label > &&zoneIds, const bool sorted)
Sort faces by zones and store sorted faces.
A class for handling file names.
Definition: fileName.H:79
declareMemberFunctionSelectionTable(void, UnsortedMeshedSurface, write, fileExtension,(const fileName &name, const MeshedSurface< Face > &surf),(name, surf))
virtual ~MeshedSurface()
Destructor.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
A surface geometry mesh with zone information, not to be confused with the similarly named surfaceMes...
Definition: MeshedSurface.H:72
void writeStats(Ostream &os) const
static wordHashSet writeTypes()
Definition: MeshedSurface.C:56
virtual void clear()
Clear all storage.
void transfer(MeshedSurface< Face > &)
Transfer the contents of the argument and annul the argument.
MeshedSurface subsetMesh(const labelHashSet &include, labelList &pointMap, labelList &faceMap) const
Return new surface.
virtual void removeZones()
Remove surface zones.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
surfZoneList & storedZones()
Non-const access to the zones.
ClassName("MeshedSurface")
Runtime type information.
static autoPtr< MeshedSurface > New(const fileName &, const word &ext)
Select constructed from filename (explicit extension)
UList< label > labelUList
Definition: UList.H:65
declareRunTimeSelectionTable(autoPtr, MeshedSurface, fileExtension,(const fileName &name),(name))
A list of faces which address into the list of points.
void operator=(const MeshedSurface< Face > &)
static wordHashSet readTypes()
Definition: MeshedSurface.C:49
List< Face > & storedFaces()
Non-const access to the faces.
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
A class for handling words, derived from string.
Definition: word.H:59
Face FaceType
Face type used.
pointField & storedPoints()
Non-const access to global points.
virtual void cleanup(const bool verbose)
Remove invalid faces.
virtual label triangulate()
Triangulate in-place, returning the number of triangles added.
const Field< PointType > & points() const
Return reference to global points.
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
static bool isTri()
Face storage only handles triangulated faces.
Definition: MeshedSurface.C:42
static void write(const fileName &, const MeshedSurface< Face > &)
Write to file.
static bool canWriteType(const word &ext, const bool verbose=false)
Can we write this file format?
Definition: MeshedSurface.C:83
Foam::polyBoundaryMesh.
A surface mesh consisting of general polygon faces.
Definition: surfMesh.H:55
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual void reset(pointField &&points, List< Face > &&faces, surfZoneList &&zones)
Reset primitive data (points, faces and zones)
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats...
Definition: MeshedSurface.H:73
void checkZones()
Basic sanity check on zones.
const List< Face > & faces() const
Return const access to the faces.
virtual void scalePoints(const scalar)
Scale points. A non-positive factor is ignored.
bool notNull(const T &t)
Return true if t is not a reference to the nullObject of type T.
Definition: nullObjectI.H:52
Calculates points shared by more than two processor patches or cyclic patches.
Definition: globalPoints.H:100
virtual void remapFaces(const labelUList &faceMap)
Set new zones from faceMap.
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?
Definition: MeshedSurface.C:66
virtual bool checkFaces(const bool verbose=false)
static bool canRead(const fileName &, const bool verbose=false)
Can we read this file format?
virtual bool stitchFaces(const scalar tol=small, const bool verbose=false)
virtual void addZones(const UList< surfZone > &, const bool cullEmpty=false)
Add surface zones.
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.
void transcribe(MeshedSurface< face > &)
Transfer points/zones and transcribe face -> triFace.
A collection of helper functions for reading/writing surface formats.
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
virtual void movePoints(const pointField &)
Move points.
Namespace for OpenFOAM.
const List< surfZone > & surfZones() const
Const access to the surface zones.
MeshedSurface()
Construct null.