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-2026 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 
95 
98 
99 
100  // Private 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  //- Non-const access to the surface zones.
306  // If zones are defined, they must be contiguous and cover the
307  // entire surface
309  {
310  return zones_;
311  }
312 
313  //- Add surface zones
314  virtual void addZones
315  (
316  const UList<surfZone>&,
317  const bool cullEmpty=false
318  );
319 
320  //- Add surface zones
321  virtual void addZones
322  (
323  const labelUList& sizes,
324  const UList<word>& names,
325  const bool cullEmpty=false
326  );
327 
328  //- Add surface zones
329  virtual void addZones
330  (
331  const labelUList& sizes,
332  const bool cullEmpty=false
333  );
334 
335  //- Remove surface zones
336  virtual void removeZones();
337 
338 
339  // Edit
340 
341  //- Clear all storage
342  virtual void clear();
343 
344  //- Reset the points
345  virtual void setPoints(const pointField&);
346 
347  //- Scale points. A non-positive factor is ignored
348  virtual void scalePoints(const scalar);
349 
350  //- Reset primitive data (points, faces and zones)
351  // Note, optimised to avoid overwriting data (with null)
352  virtual void reset
353  (
354  pointField&& points,
355  List<Face>&& faces,
356  surfZoneList&& zones
357  );
358 
359  //- Reset primitive data (points, faces and zones)
360  // Note, optimised to avoid overwriting data (with null)
361  virtual void reset
362  (
364  List<Face>&& faces,
365  surfZoneList&& zones
366  );
367 
368  //- Remove invalid faces
369  virtual void cleanup(const bool verbose);
370 
371  virtual bool stitchFaces
372  (
373  const scalar tol=small,
374  const bool verbose=false
375  );
376 
377  virtual bool checkFaces
378  (
379  const bool verbose=false
380  );
381 
382  //- Triangulate in-place, returning the number of triangles added
383  virtual label triangulate();
384 
385  //- Triangulate in-place, returning the number of triangles added
386  // and setting a map of original face Ids.
387  // The faceMap is zero-sized when no triangulation was done.
389 
390 
391  //- Return new surface.
392  // Returns return pointMap, faceMap from subsetMeshMap
394  (
395  const labelHashSet& include,
396  labelList& pointMap,
398  ) const;
399 
400  //- Return new surface.
402  (
403  const labelHashSet& include
404  ) const;
405 
406  //- Transfer the contents of the argument and annul the argument
408 
409  //- Transfer the contents of the argument and annul the argument
411 
412 
413  // Read
414 
415  //- Read from file. Chooses reader based on explicit extension
416  bool read(const fileName&, const word& ext);
417 
418  //- Read from file. Chooses reader based on detected extension
419  virtual bool read(const fileName&);
420 
421 
422  // Write
423 
424  void writeStats(Ostream& os) const;
425 
426  //- Generic write routine. Chooses writer based on extension.
427  virtual void write(const fileName& name) const
428  {
429  write(name, *this);
430  }
431 
432  //- Write to database
433  void write(const Time&, const word& surfName="") const;
434 
435 
436  // Member Operators
437 
438  void operator=(const MeshedSurface<Face>&);
439 
440  //- Conversion operator to MeshedSurfaceProxy
441  operator MeshedSurfaceProxy<Face>() const;
442 };
443 
444 
445 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
446 
447 //- Specialisation for holding triangulated information
448 template<>
449 inline bool MeshedSurface<triFace>::isTri()
450 {
451  return true;
452 }
453 
454 
455 //- Specialisation for holding triangulated information
456 template<>
458 {
459  return 0;
460 }
461 
462 
463 //- Specialisation for holding triangulated information
464 template<>
466 {
467  if (notNull(faceMap))
468  {
469  faceMap.clear();
470  }
471 
472  return 0;
473 }
474 
475 
476 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
477 
478 } // End namespace Foam
479 
480 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
481 
482 #ifdef NoRepository
483  #include "MeshedSurface.C"
484 #endif
485 
486 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
487 
488 #endif
489 
490 // ************************************************************************* //
A HashTable with keys but without contents.
Definition: HashSet.H:62
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
A surface geometry mesh with zone information, not to be confused with the similarly named surfaceMes...
Definition: MeshedSurface.H:85
static bool isTri()
Face storage only handles triangulated faces.
Definition: MeshedSurface.C:42
virtual void scalePoints(const scalar)
Scale points. A non-positive factor is ignored.
const List< surfZone > & surfZones() const
Const access to the surface zones.
const List< Face > & faces() const
Return const access to the faces.
Face FaceType
Face type used.
void transcribe(MeshedSurface< face > &)
Transfer points/zones and transcribe face -> triFace.
void operator=(const MeshedSurface< Face > &)
virtual void addZones(const UList< surfZone > &, const bool cullEmpty=false)
Add surface zones.
static wordHashSet writeTypes()
Definition: MeshedSurface.C:56
pointField & storedPoints()
Non-const access to global points.
declareMemberFunctionSelectionTable(void, UnsortedMeshedSurface, write, fileExtension,(const fileName &name, const MeshedSurface< Face > &surf),(name, surf))
void sortFacesAndStore(List< Face > &&unsortedFaces, List< label > &&zoneIds, const bool sorted)
Sort faces by zones and store sorted faces.
ClassName("MeshedSurface")
Runtime type information.
virtual void cleanup(const bool verbose)
Remove invalid faces.
void transfer(MeshedSurface< Face > &)
Transfer the contents of the argument and annul the argument.
virtual ~MeshedSurface()
Destructor.
declareRunTimeSelectionTable(autoPtr, MeshedSurface, fileExtension,(const fileName &name),(name))
bool read(const fileName &, const word &ext)
Read from file. Chooses reader based on explicit extension.
virtual label triangulate()
Triangulate in-place, returning the number of triangles added.
static bool canWriteType(const word &ext, const bool verbose=false)
Can we write this file format?
Definition: MeshedSurface.C:83
label size() const
The surface size is the number of faces.
MeshedSurface subsetMesh(const labelHashSet &include, labelList &pointMap, labelList &faceMap) const
Return new surface.
surfZoneList & storedZones()
Non-const access to the zones.
static bool canRead(const fileName &, const bool verbose=false)
Can we read this file format?
static bool canReadType(const word &ext, const bool verbose=false)
Can we read this file format?
Definition: MeshedSurface.C:66
virtual bool stitchFaces(const scalar tol=small, const bool verbose=false)
static void write(const fileName &, const MeshedSurface< Face > &)
Write to file.
virtual void reset(pointField &&points, List< Face > &&faces, surfZoneList &&zones)
Reset primitive data (points, faces and zones)
List< Face > & storedFaces()
Non-const access to the faces.
void writeStats(Ostream &os) const
static autoPtr< MeshedSurface > New(const fileName &, const word &ext)
Select constructed from filename (explicit extension)
virtual void remapFaces(const labelUList &faceMap)
Set new zones from faceMap.
virtual void clear()
Clear all storage.
friend class MeshedSurface
Definition: MeshedSurface.H:87
virtual bool checkFaces(const bool verbose=false)
virtual void removeZones()
Remove surface zones.
virtual void setPoints(const pointField &)
Reset the points.
void checkZones()
Basic sanity check on zones.
static wordHashSet readTypes()
Definition: MeshedSurface.C:49
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of faces which address into the list of points.
const Field< PointType > & points() const
Return reference to global points.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A surface geometry mesh, in which the surface zone information is conveyed by the 'zoneId' associated...
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 collection of helper functions for reading/writing surface formats.
A class for handling file names.
Definition: fileName.H:82
Calculates points shared by more than two processor patches or cyclic patches.
Definition: globalPoints.H:101
Foam::polyBoundaryMesh.
A surface mesh consisting of general polygon faces.
Definition: surfMesh.H:60
A class for handling words, derived from string.
Definition: word.H:63
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
bool notNull(const T &t)
Return true if t is not a reference to the nullObject of type T.
Definition: nullObjectI.H:64
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
UList< label > labelUList
Definition: UList.H:65
Macros to ease declaration of run-time selection tables.