MeshedSurface.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 | Copyright (C) 2011-2015 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<Face, ::Foam::List, pointField, point>,
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 
93 private:
94 
95  // Private typedefs for convenience
96 
97  typedef PrimitivePatch
98  <
99  Face,
100  ::Foam::List,
101  pointField,
102  point
103  >
104  ParentType;
105 
106  typedef UnsortedMeshedSurface<Face> FriendType;
107  typedef MeshedSurfaceProxy<Face> ProxyType;
108 
109 
110  // Private Member Data
111 
112  //- Zone information
113  // (face ordering nFaces/startFace only used during reading/writing)
114  List<surfZone> zones_;
115 
116 
117 protected:
118 
119  // Protected Member functions
120 
121  //- Transfer points/zones and transcribe face -> triFace
123 
124  //- Basic sanity check on zones
125  void checkZones();
126 
127  //- Non-const access to global points
128  pointField& storedPoints()
129  {
130  return const_cast<pointField&>(ParentType::points());
131  }
132 
133  //- Non-const access to the faces
135  {
136  return static_cast<List<Face> &>(*this);
137  }
138 
139  //- Non-const access to the zones
141  {
142  return zones_;
143  }
144 
145  //- Sort faces by zones and store sorted faces
146  void sortFacesAndStore
147  (
148  const Xfer<List<Face> >& unsortedFaces,
149  const Xfer<List<label> >& zoneIds,
150  const bool sorted
151  );
152 
153  //- Set new zones from faceMap
154  virtual void remapFaces(const labelUList& faceMap);
155 
156 
157 public:
158 
159  // Public typedefs
160 
161  //- Face type used
162  typedef Face FaceType;
163 
164  //- Runtime type information
165  ClassName("MeshedSurface");
166 
167 
168  // Static
169 
170  //- Face storage only handles triangulated faces
171  inline static bool isTri();
172 
173  //- Can we read this file format?
174  static bool canRead(const fileName&, const bool verbose=false);
175 
176  //- Can we read this file format?
177  static bool canReadType(const word& ext, const bool verbose=false);
178 
179  //- Can we write this file format?
180  static bool canWriteType(const word& ext, const bool verbose=false);
181 
182  static wordHashSet readTypes();
183  static wordHashSet writeTypes();
184 
185 
186  // Constructors
187 
188  //- Construct null
189  MeshedSurface();
190 
191  //- Construct by transferring components (points, faces, zones).
193  (
194  const Xfer<pointField>&,
195  const Xfer<List<Face> >&,
196  const Xfer<surfZoneList>&
197  );
198 
199  //- Construct by transferring components (points, faces).
200  // Use zone information if available
202  (
203  const Xfer<pointField>&,
204  const Xfer<List<Face> >&,
205  const labelUList& zoneSizes = labelUList(),
206  const UList<word>& zoneNames = UList<word>()
207  );
208 
209  //- Construct as copy
211 
212  //- Construct from a UnsortedMeshedSurface
214 
215  //- Construct from a boundary mesh with local points/faces
217  (
218  const polyBoundaryMesh&,
219  const bool globalPoints=false
220  );
221 
222  //- Construct from a surfMesh
223  MeshedSurface(const surfMesh&);
224 
225  //- Construct by transferring the contents from a UnsortedMeshedSurface
227 
228  //- Construct by transferring the contents from a MeshedSurface
230 
231  //- Construct from file name (uses extension to determine type)
232  MeshedSurface(const fileName&);
233 
234  //- Construct from file name (uses extension to determine type)
235  MeshedSurface(const fileName&, const word& ext);
236 
237  //- Construct from database
238  MeshedSurface(const Time&, const word& surfName="");
239 
240 
241  // Declare run-time constructor selection table
242 
244  (
245  autoPtr,
247  fileExtension,
248  (
249  const fileName& name
250  ),
251  (name)
252  );
253 
254 
255  // Selectors
256 
257  //- Select constructed from filename (explicit extension)
259  (
260  const fileName&,
261  const word& ext
262  );
263 
264  //- Select constructed from filename (implicit extension)
265  static autoPtr<MeshedSurface> New(const fileName&);
266 
267 
268  //- Destructor
269  virtual ~MeshedSurface();
270 
271 
272  // Member Function Selectors
273 
275  (
276  void,
278  write,
279  fileExtension,
280  (
281  const fileName& name,
282  const MeshedSurface<Face>& surf
283  ),
284  (name, surf)
285  );
286 
287  //- Write to file
288  static void write(const fileName&, const MeshedSurface<Face>&);
289 
290 
291  // Member Functions
292 
293  // Access
294 
295  //- The surface size is the number of faces
296  label size() const
297  {
298  return ParentType::size();
299  }
300 
301  //- Return const access to the faces
302  inline const List<Face>& faces() const
303  {
304  return static_cast<const List<Face> &>(*this);
305  }
306 
307  //- Const access to the surface zones.
308  // If zones are defined, they must be contiguous and cover the
309  // entire surface
310  const List<surfZone>& surfZones() const
311  {
312  return zones_;
313  }
314 
315  //- Add surface zones
316  virtual void addZones
317  (
318  const UList<surfZone>&,
319  const bool cullEmpty=false
320  );
321 
322  //- Add surface zones
323  virtual void addZones
324  (
325  const labelUList& sizes,
326  const UList<word>& names,
327  const bool cullEmpty=false
328  );
329 
330  //- Add surface zones
331  virtual void addZones
332  (
333  const labelUList& sizes,
334  const bool cullEmpty=false
335  );
336 
337  //- Remove surface zones
338  virtual void removeZones();
339 
340 
341  // Edit
342 
343  //- Clear all storage
344  virtual void clear();
345 
346  //- Move points
347  virtual void movePoints(const pointField&);
348 
349  //- Scale points. A non-positive factor is ignored
350  virtual void scalePoints(const scalar);
351 
352  //- Reset primitive data (points, faces and zones)
353  // Note, optimized to avoid overwriting data (with Xfer::null)
354  virtual void reset
355  (
356  const Xfer<pointField >& points,
357  const Xfer<List<Face> >& faces,
358  const Xfer<surfZoneList>& zones
359  );
360 
361  //- Reset primitive data (points, faces and zones)
362  // Note, optimized to avoid overwriting data (with Xfer::null)
363  virtual void reset
364  (
365  const Xfer<List<point> >& points,
366  const Xfer<List<Face> >& faces,
367  const Xfer<surfZoneList >& zones
368  );
369 
370  //- Remove invalid faces
371  virtual void cleanup(const bool verbose);
372 
373  virtual bool stitchFaces
374  (
375  const scalar tol=SMALL,
376  const bool verbose=false
377  );
378 
379  virtual bool checkFaces
380  (
381  const bool verbose=false
382  );
383 
384  //- Triangulate in-place, returning the number of triangles added
385  virtual label triangulate();
386 
387  //- Triangulate in-place, returning the number of triangles added
388  // and setting a map of original face Ids.
389  // The faceMap is zero-sized when no triangulation was done.
390  virtual label triangulate(List<label>& faceMap);
391 
392 
393  //- Return new surface.
394  // Returns return pointMap, faceMap from subsetMeshMap
396  (
397  const labelHashSet& include,
398  labelList& pointMap,
399  labelList& faceMap
400  ) const;
401 
402  //- Return new surface.
404  (
405  const labelHashSet& include
406  ) const;
407 
408  //- Transfer the contents of the argument and annul the argument
410 
411  //- Transfer the contents of the argument and annul the argument
413 
414  //- Transfer contents to the Xfer container
416 
417 
418  // Read
419 
420  //- Read from file. Chooses reader based on explicit extension
421  bool read(const fileName&, const word& ext);
422 
423  //- Read from file. Chooses reader based on detected extension
424  virtual bool read(const fileName&);
425 
426 
427  // Write
428 
429  void writeStats(Ostream& os) const;
430 
431  //- Generic write routine. Chooses writer based on extension.
432  virtual void write(const fileName& name) const
433  {
434  write(name, *this);
435  }
436 
437  //- Write to database
438  void write(const Time&, const word& surfName="") const;
439 
440 
441  // Member operators
442 
443  void operator=(const MeshedSurface<Face>&);
444 
445  //- Conversion operator to MeshedSurfaceProxy
446  operator MeshedSurfaceProxy<Face>() const;
447 };
448 
449 
450 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
451 
452 //- Specialization for holding triangulated information
453 template<>
454 inline bool MeshedSurface<triFace>::isTri()
455 {
456  return true;
457 }
458 
459 
460 //- Specialization for holding triangulated information
461 template<>
463 {
464  return 0;
465 }
466 
467 
468 //- Specialization for holding triangulated information
469 template<>
471 {
472  if (notNull(faceMap))
473  {
474  faceMap.clear();
475  }
476 
477  return 0;
478 }
479 
480 
481 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
482 
483 } // End namespace Foam
484 
485 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
486 
487 #ifdef NoRepository
488 # include "MeshedSurface.C"
489 #endif
490 
491 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
492 
493 #endif
494 
495 // ************************************************************************* //
void transcribe(MeshedSurface< face > &)
Transfer points/zones and transcribe face -> triFace.
virtual void removeZones()
Remove surface zones.
A surface mesh consisting of general polygon faces.
Definition: surfMesh.H:55
UList< label > labelUList
Definition: UList.H:63
Face FaceType
Face type used.
virtual void cleanup(const bool verbose)
Remove invalid faces.
const List< surfZone > & surfZones() const
Const access to the surface zones.
virtual void remapFaces(const labelUList &faceMap)
Set new zones from faceMap.
Xfer< MeshedSurface< Face > > xfer()
Transfer contents to the Xfer container.
static bool canReadType(const word &ext, const bool verbose=false)
Can we read this file format?
Definition: MeshedSurface.C:65
static wordHashSet readTypes()
Definition: MeshedSurface.C:48
declareRunTimeSelectionTable(autoPtr, MeshedSurface, fileExtension,( const fileName &name ),(name))
Macros to ease declaration of run-time selection tables.
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats...
Definition: MeshedSurface.H:73
void sortFacesAndStore(const Xfer< List< Face > > &unsortedFaces, const Xfer< List< label > > &zoneIds, const bool sorted)
Sort faces by zones and store sorted faces.
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
A class for handling words, derived from string.
Definition: word.H:59
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
label size() const
The surface size is the number of faces.
declareMemberFunctionSelectionTable(void, UnsortedMeshedSurface, write, fileExtension,( const fileName &name, const MeshedSurface< Face > &surf ),(name, surf))
bool notNull(const T &t)
Return true if t is not a reference to the nullObject of type T.
Definition: nullObjectI.H:46
MeshedSurface()
Construct null.
ClassName("MeshedSurface")
Runtime type information.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
static wordHashSet writeTypes()
Definition: MeshedSurface.C:55
Namespace for OpenFOAM.
pointField & storedPoints()
Non-const access to global points.
static void write(const fileName &, const MeshedSurface< Face > &)
Write to file.
virtual void clear()
Clear all storage.
static autoPtr< MeshedSurface > New(const fileName &, const word &ext)
Select constructed from filename (explicit extension)
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 collection of helper functions for reading/writing surface formats.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
void clear()
Clear the list, i.e. set size to zero.
Definition: List.C:379
Calculates points shared by more than two processor patches or cyclic patches.
Definition: globalPoints.H:100
const List< Face > & faces() const
Return const access to the faces.
Foam::polyBoundaryMesh.
virtual void reset(const Xfer< pointField > &points, const Xfer< List< Face > > &faces, const Xfer< surfZoneList > &zones)
Reset primitive data (points, faces and zones)
surfZoneList & storedZones()
Non-const access to the zones.
virtual ~MeshedSurface()
Destructor.
A list of faces which address into the list of points.
virtual void addZones(const UList< surfZone > &, const bool cullEmpty=false)
Add surface zones.
void operator=(const MeshedSurface< Face > &)
A surface geometry mesh, in which the surface zone information is conveyed by the &#39;zoneId&#39; associated...
Definition: MeshedSurface.H:74
void checkZones()
Basic sanity check on zones.
static bool isTri()
Face storage only handles triangulated faces.
Definition: MeshedSurface.C:41
A class for handling file names.
Definition: fileName.H:69
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 HashTable with keys but without contents.
Definition: HashSet.H:59
label size() const
Return the number of elements in the UList.
A surface geometry mesh with zone information, not to be confused with the similarly named surfaceMes...
Definition: MeshedSurface.H:72
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual void movePoints(const pointField &)
Move points.
List< Face > & storedFaces()
Non-const access to the faces.
void transfer(MeshedSurface< Face > &)
Transfer the contents of the argument and annul the argument.
static bool canWriteType(const word &ext, const bool verbose=false)
Can we write this file format?
Definition: MeshedSurface.C:82
virtual label triangulate()
Triangulate in-place, returning the number of triangles added.
MeshedSurface subsetMesh(const labelHashSet &include, labelList &pointMap, labelList &faceMap) const
Return new surface.
virtual void scalePoints(const scalar)
Scale points. A non-positive factor is ignored.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
const Field< point > & points() const
Return reference to global points.
void writeStats(Ostream &os) const
virtual bool checkFaces(const bool verbose=false)
virtual bool stitchFaces(const scalar tol=SMALL, const bool verbose=false)
bool read(const fileName &, const word &ext)
Read from file. Chooses reader based on explicit extension.
static bool canRead(const fileName &, const bool verbose=false)
Can we read this file format?
Definition: MeshedSurface.C:99