UnsortedMeshedSurface.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::UnsortedMeshedSurface
29 
30 Description
31  A surface geometry mesh, in which the surface zone information is
32  conveyed by the 'zoneId' associated with each face.
33 
34  This form of surface description is particularly useful for reading in
35  surface meshes from third-party formats (eg, obj, stl, gts, etc.). It
36  can also be particularly useful for situations in which the surface
37  many be adjusted in an arbitrary manner without worrying about needed
38  to adjust the zone information (eg, surface refinement).
39 
40 See also
41  The Foam::MeshedSurface - which is organized as a surface mesh, but
42  with independent zone information.
43 
44 SourceFiles
45  UnsortedMeshedSurface.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef UnsortedMeshedSurface_H
50 #define UnsortedMeshedSurface_H
51 
52 #include "MeshedSurface.H"
53 #include "surfZoneIdentifierList.H"
54 #include "surfZoneList.H"
55 #include "surfaceFormatsCore.H"
56 #include "HashSet.H"
57 #include "runTimeSelectionTables.H"
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
62 namespace Foam
63 {
64 
65 // Forward declarations
66 //
67 class Time;
68 class Istream;
69 class Ostream;
70 
71 template<class Face> class MeshedSurface;
72 template<class Face> class MeshedSurfaceProxy;
73 template<class Face> class UnsortedMeshedSurface;
74 
75 template<class Face>
76 Istream& operator>>(Istream&, UnsortedMeshedSurface<Face>&);
77 template<class Face>
78 Ostream& operator<<(Ostream&, const UnsortedMeshedSurface<Face>&);
79 
80 /*---------------------------------------------------------------------------*\
81  Class UnsortedMeshedSurface Declaration
82 \*---------------------------------------------------------------------------*/
83 
84 template<class Face>
85 class UnsortedMeshedSurface
86 :
87  public MeshedSurface<Face>
88 {
89  // Friends, regardless of face representations
90  template<class Face2> friend class MeshedSurface;
91  template<class Face2> friend class UnsortedMeshedSurface;
92 
93  // Friendship with surfMesh is needed for transferring
94  friend class surfMesh;
95 
96 private:
97 
98  // Private typedefs for convenience
99 
103 
104 
105  // Private Member Data
106 
107  //- The zone Id associated with each face
108  labelList zoneIds_;
109 
110  //- Zone information (face ordering nFaces/startFace only used
111  // during reading and writing)
112  List<surfZoneIdentifier> zoneToc_;
113 
114 
115  // Private Member Functions
116 
117  //- Disable resize with value
118  void resize(const label, const Face&) = delete;
119 
120  //- Disable setSize with value
121  void setSize(const label, const Face&) = delete;
122 
123  //- Read/construct from Istream
124  Istream& read(Istream&);
125 
126  //- Write to Ostream
127  Ostream& write(Ostream&) const;
128 
129 protected:
130 
131  // Protected Member functions
132 
133  //- Return non-const access to the zone Ids
135  {
136  return zoneIds_;
137  }
138 
139  //- Return non-const access to the zone table-of-contents
141  {
142  return zoneToc_;
143  }
144 
145  //- Set new zones from faceMap
146  virtual void remapFaces(const labelUList& faceMap);
147 
148 
149 public:
150 
151  // Public typedefs
152 
153  //- Face type used
154  typedef Face FaceType;
155 
156  //- Runtime type information
157  TypeName("UnsortedMeshedSurface");
158 
159 
160  // Static
161 
162  //- Can we read this file format type?
163  static bool canReadType(const word& ext, bool verbose=false);
164 
165  //- Can we read this file format?
166  static bool canRead(const fileName& name, bool verbose=false);
167 
168  //- Can we write this file format type?
169  static bool canWriteType(const word& ext, bool verbose=false);
170 
171  //- Known readable file-types
172  static wordHashSet readTypes();
173 
174  //- Known writable file-types
175  static wordHashSet writeTypes();
176 
177 
178  // Constructors
179 
180  //- Construct null
182 
183  //- Construct as copy
185 
186  //- Construct from a MeshedSurface
188 
189  //- Move construct from a UnsortedMeshedSurface
191 
192  //- Move construct from MeshedSurface
194 
195  //- Move construct from components (points, faces, zone ids).
196  // Zone information is fairly lightweight and is copied.
198  (
199  pointField&& pointLst,
200  List<Face>&& faceLst,
203  );
204 
205  //- Construct from file name (uses extension to determine type)
207 
208  //- Construct from file name (uses extension to determine type)
209  UnsortedMeshedSurface(const fileName& name, const word& ext);
210 
211  //- Construct from Istream
213 
214  //- Construct from objectRegistry and a named surface
216  (
217  const Time& t,
218  const word& surfName = word::null
219  );
220 
221 
222  // Declare run-time constructor selection table
223 
225  (
226  autoPtr,
229  (
230  const fileName& name
231  ),
232  (name)
233  );
234 
235 
236  // Selectors
237 
238  //- Select constructed from filename (explicit extension)
240  (
241  const fileName& name,
242  const word& ext
243  );
244 
245  //- Select constructed from filename (implicit extension)
247 
248 
249  //- Destructor
250  virtual ~UnsortedMeshedSurface() = default;
251 
252 
253  // Member Function Selectors
254 
256  (
257  void,
259  write,
261  (
262  const fileName& name,
263  const UnsortedMeshedSurface<Face>& surf,
264  const dictionary& options
265  ),
266  (name, surf, options)
267  );
268 
269  //- Write to file, select based on its extension
270  static void write
271  (
272  const fileName& name,
273  const UnsortedMeshedSurface<Face>& surf,
274  const dictionary& options = dictionary::null
275  );
276 
277  //- Write to file, selected based on given extension
278  static void write
279  (
280  const fileName& name,
281  const word& ext,
282  const UnsortedMeshedSurface<Face>& surf,
283  const dictionary& options
284  );
285 
286 
287  // Member Functions
288 
289  // Access
290 
291  //- The surface size is the number of faces
292  label size() const
293  {
294  return ParentType::size();
295  }
296 
297  //- Reset size of face and zone list
298  void setSize(const label);
299 
300  //- Return const access to the zone ids
301  virtual const labelList& zoneIds() const
302  {
303  return zoneIds_;
304  }
305 
306  //- Return const access to the zone table-of-contents
307  const List<surfZoneIdentifier>& zoneToc() const
308  {
309  return zoneToc_;
310  }
311 
312  //- Sort faces according to zoneIds
313  // Returns a surfZoneList and sets faceMap to index within faces()
314  // (i.e. map from original,unsorted to sorted)
316 
317  //- Set zones to 0 and set a single zone
318  void setOneZone();
319 
320  //- Set zone ids and zones
321  void setZones(const surfZoneList& zoneLst);
322 
323  //- Set zone ids and zones
324  void setZones(const labelUList& sizes, const UList<word>& names);
325 
326  //- Set zone ids and zones with default names
327  void setZones(const labelUList& sizes);
328 
329 
330  // Edit
331 
332  //- Clear all storage
333  virtual void clear();
334 
335  //- Return new surface.
336  // \param[in] include the faces to select
337  // \param[out] pointMap from subsetMeshMap
338  // \param[out] faceMap from subsetMeshMap
339  template<class BoolListType>
341  (
342  const BoolListType& include,
343  labelList& pointMap,
345  ) const;
346 
347  //- Return new surface
348  UnsortedMeshedSurface subsetMesh(const bitSet& include) const;
349 
350  //- Return new surface
351  UnsortedMeshedSurface subsetMesh(const labelHashSet& include) const;
352 
353 
354  //- Swap contents - disabled
355  void swap(MeshedSurface<Face>& surf) = delete;
356 
357  //- Swap contents
358  void swap(UnsortedMeshedSurface<Face>& surf);
359 
360  //- Transfer the contents of the argument and annul the argument
362 
363  //- Transfer the contents of the argument and annul the argument
364  void transfer(MeshedSurface<Face>& surf);
365 
366  //- Release (clear) stored zoneIds and return for reuse
368 
369 
370  // Read
371 
372  //- Read from file. Chooses reader based on explicit extension
373  bool read(const fileName& name, const word& ext);
374 
375  //- Read from file. Chooses reader based on detected extension
376  virtual bool read(const fileName& name);
377 
378 
379  // Write
380 
381  //- Generic write routine. Chooses writer based on its extension.
382  virtual void write
383  (
384  const fileName& name,
385  const dictionary& options = dictionary::null
386  ) const
387  {
388  write(name, *this, options);
389  }
390 
391  //- Write to database
392  void write
393  (
394  const Time& t,
395  const word& surfName = word::null
396  ) const;
397 
398 
399  // Member Operators
400 
401  //- Copy assignment
402  void operator=(const UnsortedMeshedSurface<Face>& surf);
403 
404  //- Move assignment
406 
407  //- Conversion operator to MeshedSurfaceProxy
408  operator MeshedSurfaceProxy<Face>() const;
409 
410 
411  // IOstream Operators
412 
413  //- Read UnsortedMeshedSurface from Istream.
414  // Avoid using to read/write file content (fragile).
415  friend Istream& operator>> <Face>
416  (
417  Istream& is,
419  );
420 
421  //- Write UnsortedMeshedSurface to Ostream.
422  // Avoid using to read/write file content (fragile).
423  friend Ostream& operator<< <Face>
424  (
425  Ostream& os,
426  const UnsortedMeshedSurface<Face>& surf
427  );
428 };
429 
430 
431 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
432 
433 } // End namespace Foam
434 
435 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
436 
437 #ifdef NoRepository
438  #include "UnsortedMeshedSurface.C"
439 #endif
440 
441 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
442 
443 #endif
444 
445 // ************************************************************************* //
setSize
points setSize(newPointi)
Foam::UnsortedMeshedSurface::FaceType
Face FaceType
Face type used.
Definition: UnsortedMeshedSurface.H:153
Foam::UnsortedMeshedSurface::canReadType
static bool canReadType(const word &ext, bool verbose=false)
Can we read this file format type?
Definition: UnsortedMeshedSurface.C:56
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:94
Foam::UnsortedMeshedSurface::setZones
void setZones(const surfZoneList &zoneLst)
Set zone ids and zones.
Definition: UnsortedMeshedSurface.C:310
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::UnsortedMeshedSurface::releaseZoneIds
autoPtr< labelList > releaseZoneIds()
Release (clear) stored zoneIds and return for reuse.
Definition: UnsortedMeshedSurface.C:661
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
Foam::vtk::fileExtension
const Foam::Enum< fileTag > fileExtension
File extension (without ".") for some vtk XML file content types.
Foam::surfMesh
A surface mesh consisting of general polygon faces.
Definition: surfMesh.H:64
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:228
Foam::UnsortedMeshedSurface::canWriteType
static bool canWriteType(const word &ext, bool verbose=false)
Can we write this file format type?
Definition: UnsortedMeshedSurface.C:73
Foam::UnsortedMeshedSurface::New
static autoPtr< UnsortedMeshedSurface > New(const fileName &name, const word &ext)
Select constructed from filename (explicit extension)
Definition: UnsortedMeshedSurfaceNew.C:37
Foam::UnsortedMeshedSurface::remapFaces
virtual void remapFaces(const labelUList &faceMap)
Set new zones from faceMap.
Definition: UnsortedMeshedSurface.C:385
Foam::HashSet< word >
Foam::MeshedSurfaceProxy
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
Definition: MeshedSurface.H:78
Foam::dictionary::null
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:385
Foam::UnsortedMeshedSurface::zoneIds
virtual const labelList & zoneIds() const
Return const access to the zone ids.
Definition: UnsortedMeshedSurface.H:300
Foam::UnsortedMeshedSurface::TypeName
TypeName("UnsortedMeshedSurface")
Runtime type information.
Foam::UnsortedMeshedSurface::UnsortedMeshedSurface
UnsortedMeshedSurface()
Construct null.
Definition: UnsortedMeshedSurface.C:160
Foam::label
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:62
resize
patchWriters resize(patchIds.size())
Foam::Field< vector >
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::UnsortedMeshedSurface::transfer
void transfer(UnsortedMeshedSurface< Face > &surf)
Transfer the contents of the argument and annul the argument.
Definition: UnsortedMeshedSurface.C:626
Foam::UnsortedMeshedSurface
A surface geometry mesh, in which the surface zone information is conveyed by the 'zoneId' associated...
Definition: MeshedSurface.H:79
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::UnsortedMeshedSurface::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, UnsortedMeshedSurface, fileExtension,(const fileName &name),(name))
Foam::UnsortedMeshedSurface::zoneToc
const List< surfZoneIdentifier > & zoneToc() const
Return const access to the zone table-of-contents.
Definition: UnsortedMeshedSurface.H:306
Foam::blockMeshTools::read
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:33
HashSet.H
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::UnsortedMeshedSurface::storedZoneToc
List< surfZoneIdentifier > & storedZoneToc()
Return non-const access to the zone table-of-contents.
Definition: UnsortedMeshedSurface.H:139
Foam::UnsortedMeshedSurface::size
label size() const
The surface size is the number of faces.
Definition: UnsortedMeshedSurface.H:291
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::UnsortedMeshedSurface::operator=
void operator=(const UnsortedMeshedSurface< Face > &surf)
Copy assignment.
Definition: UnsortedMeshedSurface.C:713
Foam::UnsortedMeshedSurface::readTypes
static wordHashSet readTypes()
Known readable file-types.
Definition: UnsortedMeshedSurface.C:41
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
UnsortedMeshedSurface.C
Foam::UnsortedMeshedSurface::~UnsortedMeshedSurface
virtual ~UnsortedMeshedSurface()=default
Destructor.
Foam::UnsortedMeshedSurface::setOneZone
void setOneZone()
Set zones to 0 and set a single zone.
Definition: UnsortedMeshedSurface.C:285
Foam::UnsortedMeshedSurface::storedZoneIds
labelList & storedZoneIds()
Return non-const access to the zone Ids.
Definition: UnsortedMeshedSurface.H:133
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::UnsortedMeshedSurface::clear
virtual void clear()
Clear all storage.
Definition: UnsortedMeshedSurface.C:452
Foam::List< label >
Foam::UnsortedMeshedSurface::canRead
static bool canRead(const fileName &name, bool verbose=false)
Can we read this file format?
Definition: UnsortedMeshedSurface.C:90
Foam::UList< label >
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:35
surfZoneList.H
memberFunctionSelectionTables.H
Macros to enable the easy declaration of member function selection tables.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::UnsortedMeshedSurface::declareMemberFunctionSelectionTable
declareMemberFunctionSelectionTable(void, UnsortedMeshedSurface, write, fileExtension,(const fileName &name, const UnsortedMeshedSurface< Face > &surf, const dictionary &options),(name, surf, options))
Foam::UnsortedMeshedSurface::subsetMesh
UnsortedMeshedSurface subsetMesh(const BoolListType &include, labelList &pointMap, labelList &faceMap) const
Return new surface.
Foam::MeshedSurface
A surface geometry mesh with zone information, not to be confused with the similarly named surfaceMes...
Definition: triSurfaceTools.H:80
Foam::MeshedSurface::size
label size() const
The surface size is the number of faces.
Definition: MeshedSurface.H:356
Foam::UnsortedMeshedSurface::swap
void swap(MeshedSurface< Face > &surf)=delete
Swap contents - disabled.
surfaceFormatsCore.H
Foam::UnsortedMeshedSurface::writeTypes
static wordHashSet writeTypes()
Known writable file-types.
Definition: UnsortedMeshedSurface.C:48
Foam::UnsortedMeshedSurface::sortedZones
surfZoneList sortedZones(labelList &faceMap) const
Sort faces according to zoneIds.
Definition: UnsortedMeshedSurface.C:462
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102
MeshedSurface.H
surfZoneIdentifierList.H