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-2020 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 class Time;
67 class Istream;
68 class Ostream;
69 
70 template<class Face> class MeshedSurface;
71 template<class Face> class MeshedSurfaceProxy;
72 template<class Face> class UnsortedMeshedSurface;
73 
74 template<class Face>
75 Istream& operator>>(Istream&, UnsortedMeshedSurface<Face>&);
76 template<class Face>
77 Ostream& operator<<(Ostream&, const UnsortedMeshedSurface<Face>&);
78 
79 /*---------------------------------------------------------------------------*\
80  Class UnsortedMeshedSurface Declaration
81 \*---------------------------------------------------------------------------*/
82 
83 template<class Face>
84 class UnsortedMeshedSurface
85 :
86  public MeshedSurface<Face>
87 {
88  // Friends, regardless of face representations
89  template<class Face2> friend class MeshedSurface;
90  template<class Face2> friend class UnsortedMeshedSurface;
91 
92  // Friendship with surfMesh is needed for transferring
93  friend class surfMesh;
94 
95 private:
96 
97  // Private Typedefs (convenience)
98 
102 
103 
104  // Private Data
105 
106  //- The zone Id associated with each face
107  labelList zoneIds_;
108 
109  //- Zone information (face ordering nFaces/startFace only used
110  // during reading and writing)
111  List<surfZoneIdentifier> zoneToc_;
112 
113 
114  // Private Member Functions
115 
116  //- Disable resize with value
117  void resize(const label, const Face&) = delete;
118 
119  //- Disable setSize with value
120  void setSize(const label, const Face&) = delete;
121 
122  //- Read/construct from Istream
123  bool readIstream(Istream& is);
124 
125  //- Write to Ostream
126  void writeOstream(Ostream& os) const;
127 
128 
129  //- Return a new surface using specified pointMap and faceMap
130  //
131  // \param[in] pointMap from subsetMeshMap
132  // \param[in] faceMap from subsetMeshMap
133  UnsortedMeshedSurface subsetMeshImpl
134  (
135  const labelList& pointMap,
136  const labelList& faceMap
137  ) const;
138 
139 
140 protected:
141 
142  // Protected Member Functions
143 
144  //- Return non-const access to the zone Ids
146  {
147  return zoneIds_;
148  }
149 
150  //- Return non-const access to the zone table-of-contents
152  {
153  return zoneToc_;
154  }
155 
156  //- Set new zones from faceMap
157  virtual void remapFaces(const labelUList& faceMapNewToOld);
158 
159 
160 public:
161 
162  // Public Typedefs
163 
164  //- The face type (same as the underlying PrimitivePatch)
165  typedef Face face_type;
166 
167  //- The point type (same as the underlying PrimitivePatch)
168  typedef point point_type;
169 
170 
171  //- Declare type-name, virtual type (with debug switch)
172  TypeName("UnsortedMeshedSurface");
173 
174 
175  // Static Functions
176 
177  //- Known readable file-types, without friends or proxies
178  static wordHashSet readTypes();
179 
180  //- Known writable file-types, without friends or proxies
181  static wordHashSet writeTypes();
182 
183  //- Can we read this file format? Also checks friend types.
184  static bool canReadType(const word& fileType, bool verbose=false);
185 
186  //- Can we write this file format? Also checks friend types.
187  static bool canWriteType(const word& fileType, bool verbose=false);
188 
189  //- Can we read this file format?
190  static bool canRead(const fileName& name, bool verbose=false);
191 
192 
193  // Constructors
194 
195  //- Default construct
197 
198  //- Copy construct
200 
201  //- Construct from a MeshedSurface
203 
204  //- Move construct from a UnsortedMeshedSurface
206 
207  //- Move construct from MeshedSurface
209 
210  //- Move construct from components (points, faces, zone ids).
211  // Zone information is fairly lightweight and is copied.
213  (
214  pointField&& pointLst,
215  List<Face>&& faceLst,
218  );
219 
220  //- Construct from file name (uses extension to determine type)
221  explicit UnsortedMeshedSurface(const fileName& name);
222 
223  //- Construct from file name with given format type.
224  // If the format type is "", uses the file extension.
225  UnsortedMeshedSurface(const fileName& name, const word& fileType);
226 
227  //- Construct from Istream
228  explicit UnsortedMeshedSurface(Istream& is);
229 
230  //- Construct from database (as surfMesh) with default name
231  explicit UnsortedMeshedSurface(const Time& runTime);
232 
233  //- Construct from database (as surfMesh) with given surface name
234  UnsortedMeshedSurface(const Time& runTime, const word& surfName);
235 
236  //- Read construct using IO to find the file location.
237  // Dictionary may contain the following entries:
238  // - \c file = alternative file name (default is dictionary name)
239  // - \c fileType = file format (default is from file extension)
240  // - \c scale (eg, 0.001: mm to m)
241  // .
243  (
244  const IOobject& io,
245  const dictionary& dict,
246  const bool isGlobal = true
247  );
248 
249 
250  // Declare run-time constructor selection table
251 
253  (
254  autoPtr,
257  (
258  const fileName& name
259  ),
260  (name)
261  );
262 
263 
264  // Selectors
265 
266  //- Read construct from filename with given file type
267  //
268  // \note Use mandatory=false if support for the file type
269  // is optional (the file still needs to exist!).
271  (
272  const fileName& name,
273  const word& fileType,
274  bool mandatory = true
275  );
276 
277  //- Read construct from filename (implicit extension)
279 
280 
281  //- Destructor
282  virtual ~UnsortedMeshedSurface() = default;
283 
284 
285  // Member Function Selectors
286 
288  (
289  void,
291  write,
293  (
294  const fileName& name,
295  const UnsortedMeshedSurface<Face>& surf,
296  IOstreamOption streamOpt,
297  const dictionary& options
298  ),
299  (name, surf, streamOpt, options)
300  );
301 
302  //- Write to file, select based on its extension
303  static void write
304  (
305  const fileName& name,
306  const UnsortedMeshedSurface<Face>& surf,
307  IOstreamOption streamOpt = IOstreamOption(),
308  const dictionary& options = dictionary::null
309  );
310 
311  //- Write to file with given format type.
312  // If the format type is "", uses the file extension.
313  static void write
314  (
315  const fileName& name,
316  const word& fileType,
317  const UnsortedMeshedSurface<Face>& surf,
318  IOstreamOption streamOpt = IOstreamOption(),
319  const dictionary& options = dictionary::null
320  );
321 
322 
323  // Member Functions
324 
325  // Access
326 
327  //- The surface size is the number of faces
328  label size() const
329  {
330  return MeshReference::size();
331  }
332 
333  //- Reset size of face and zone list
334  void setSize(const label);
335 
336  //- Return const access to the zone ids
337  virtual const labelList& zoneIds() const
338  {
339  return zoneIds_;
340  }
341 
342  //- Return const access to the zone table-of-contents
343  const List<surfZoneIdentifier>& zoneToc() const
344  {
345  return zoneToc_;
346  }
347 
348  //- Sort faces according to zoneIds
349  // Returns a surfZoneList and sets faceMap to index within faces()
350  // (i.e. map from original,unsorted to sorted)
352 
353  //- Set zones to 0 and set a single zone
354  void setOneZone();
355 
356  //- Set zone ids and zones
357  void setZones(const surfZoneList& zoneLst);
358 
359  //- Set zone ids and zones
360  void setZones(const labelUList& sizes, const UList<word>& names);
361 
362  //- Set zone ids and zones with default names
363  void setZones(const labelUList& sizes);
364 
365 
366  // Edit
367 
368  //- Clear all storage
369  virtual void clear();
370 
371  //- Create mappings for a sub-surface
372  //
373  // \param[in] include the faces to select
374  // \param[out] pointMap from new to old localPoints
375  // \param[out] faceMap from new to old localFaces
376  template<class BoolListType>
378  (
379  const BoolListType& include,
380  labelList& pointMap,
382  ) const
383  {
384  PatchTools::subsetMap(*this, include, pointMap, faceMap);
385  }
386 
387  //- Return a new surface subsetted on the selected faces.
388  //
389  // \param[in] include the faces to select
390  // \param[out] pointMap from new to old localPoints
391  // \param[out] faceMap from new to old localFaces
393  (
394  const UList<bool>& include,
395  labelList& pointMap,
397  ) const;
398 
399  //- Return a new surface subsetted on the selected faces.
400  //
401  // \param[in] include the faces to select
402  // \param[out] pointMap from new to old localPoints
403  // \param[out] faceMap from new to old localFaces
405  (
406  const bitSet& include,
407  labelList& pointMap,
409  ) const;
410 
411  //- Return a new surface subsetted on the selected faces.
412  //
413  // \param[in] include the faces to select
414  UnsortedMeshedSurface subsetMesh(const UList<bool>& include) const;
415 
416  //- Return a new surface subsetted on the selected faces.
417  //
418  // \param[in] include the faces to select
419  UnsortedMeshedSurface subsetMesh(const bitSet& include) const;
420 
421 
422  //- Swap contents - disabled
423  void swap(MeshedSurface<Face>& surf) = delete;
424 
425  //- Swap contents
426  void swap(UnsortedMeshedSurface<Face>& surf);
427 
428  //- Transfer the contents of the argument and annul the argument
430 
431  //- Transfer the contents of the argument and annul the argument
432  void transfer(MeshedSurface<Face>& surf);
433 
434  //- Release (clear) stored zoneIds and return for reuse
436 
437 
438  // Read
439 
440  //- Read from file with given format type.
441  // If the format type is "", uses the file extension.
442  bool read(const fileName& name, const word& fileType);
443 
444  //- Read from file. Chooses reader based on detected extension
445  virtual bool read(const fileName& name);
446 
447 
448  // Write
449 
450  //- Write to file, choosing writer based on the file extension.
451  virtual void write
452  (
453  const fileName& name,
454  IOstreamOption streamOpt = IOstreamOption(),
455  const dictionary& options = dictionary::null
456  ) const
457  {
458  write(name, *this, streamOpt, options);
459  }
460 
461  //- Write to file with given format type.
462  // If the format type is "", uses the file extension.
463  virtual void write
464  (
465  const fileName& name,
466  const word& fileType,
467  IOstreamOption streamOpt = IOstreamOption(),
468  const dictionary& options = dictionary::null
469  ) const
470  {
471  write(name, fileType, *this, streamOpt, options);
472  }
473 
474  //- Write to database
475  void write
476  (
477  const Time& t,
478  const word& surfName = word::null
479  ) const;
480 
481 
482  // Member Operators
483 
484  //- Copy assignment
485  void operator=(const UnsortedMeshedSurface<Face>& surf);
486 
487  //- Move assignment
489 
490  //- Conversion operator to MeshedSurfaceProxy
491  operator MeshedSurfaceProxy<Face>() const;
492 
493 
494  // IOstream Operators
495 
496  //- Read UnsortedMeshedSurface from Istream.
497  // Avoid using to read/write file content (fragile).
498  friend Istream& operator>> <Face>
499  (
500  Istream& is,
502  );
503 
504  //- Write UnsortedMeshedSurface to Ostream.
505  // Avoid using to read/write file content (fragile).
506  friend Ostream& operator<< <Face>
507  (
508  Ostream& os,
509  const UnsortedMeshedSurface<Face>& surf
510  );
511 };
512 
513 
514 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
515 
516 } // End namespace Foam
517 
518 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
519 
520 #ifdef NoRepository
521  #include "UnsortedMeshedSurface.C"
522 #endif
523 
524 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
525 
526 #endif
527 
528 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
setSize
points setSize(newPointi)
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
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: blockMeshMergeTopological.C:94
Foam::UnsortedMeshedSurface::setZones
void setZones(const surfZoneList &zoneLst)
Set zone ids and zones.
Definition: UnsortedMeshedSurface.C:359
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::UnsortedMeshedSurface::releaseZoneIds
autoPtr< labelList > releaseZoneIds()
Release (clear) stored zoneIds and return for reuse.
Definition: UnsortedMeshedSurface.C:746
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::vtk::fileExtension
const Foam::Enum< fileTag > fileExtension
File extension (without ".") for some vtk XML file content types.
Foam::UnsortedMeshedSurface::declareMemberFunctionSelectionTable
declareMemberFunctionSelectionTable(void, UnsortedMeshedSurface, write, fileExtension,(const fileName &name, const UnsortedMeshedSurface< Face > &surf, IOstreamOption streamOpt, const dictionary &options),(name, surf, streamOpt, options))
Foam::surfMesh
A surface mesh consisting of general polygon faces that has IO capabilities and a registry for storin...
Definition: surfMesh.H:63
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::HashSet< word, Hash< word > >
Foam::MeshedSurfaceProxy
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
Definition: MeshedSurface.H:82
Foam::dictionary::null
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:392
Foam::UnsortedMeshedSurface::zoneIds
virtual const labelList & zoneIds() const
Return const access to the zone ids.
Definition: UnsortedMeshedSurface.H:336
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::UnsortedMeshedSurface::TypeName
TypeName("UnsortedMeshedSurface")
Declare type-name, virtual type (with debug switch)
Foam::UnsortedMeshedSurface::subsetMeshMap
void subsetMeshMap(const BoolListType &include, labelList &pointMap, labelList &faceMap) const
Create mappings for a sub-surface.
Definition: UnsortedMeshedSurface.H:377
Foam::UnsortedMeshedSurface::UnsortedMeshedSurface
UnsortedMeshedSurface()
Default construct.
Definition: UnsortedMeshedSurface.C:179
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:708
Foam::UnsortedMeshedSurface
A surface geometry mesh, in which the surface zone information is conveyed by the 'zoneId' associated...
Definition: MeshedSurface.H:83
Foam::UnsortedMeshedSurface::New
static autoPtr< UnsortedMeshedSurface > New(const fileName &name, const word &fileType, bool mandatory=true)
Read construct from filename with given file type.
Definition: UnsortedMeshedSurfaceNew.C:37
Foam::UnsortedMeshedSurface::subsetMesh
UnsortedMeshedSurface subsetMesh(const UList< bool > &include, labelList &pointMap, labelList &faceMap) const
Return a new surface subsetted on the selected faces.
Definition: UnsortedMeshedSurface.C:633
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::UnsortedMeshedSurface::canWriteType
static bool canWriteType(const word &fileType, bool verbose=false)
Can we write this file format? Also checks friend types.
Definition: UnsortedMeshedSurface.C:73
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:342
HashSet.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::UnsortedMeshedSurface::face_type
Face face_type
The face type (same as the underlying PrimitivePatch)
Definition: UnsortedMeshedSurface.H:164
Foam::UnsortedMeshedSurface::storedZoneToc
List< surfZoneIdentifier > & storedZoneToc()
Return non-const access to the zone table-of-contents.
Definition: UnsortedMeshedSurface.H:150
os
OBJstream os(runTime.globalPath()/outputName)
Foam::UnsortedMeshedSurface::size
label size() const
The surface size is the number of faces.
Definition: UnsortedMeshedSurface.H:327
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::UnsortedMeshedSurface::operator=
void operator=(const UnsortedMeshedSurface< Face > &surf)
Copy assignment.
Definition: UnsortedMeshedSurface.C:789
Foam::UnsortedMeshedSurface::readTypes
static wordHashSet readTypes()
Known readable file-types, without friends or proxies.
Definition: UnsortedMeshedSurface.C:41
Foam::UnsortedMeshedSurface::read
bool read(const fileName &name, const word &fileType)
Read from file with given format type.
Definition: UnsortedMeshedSurface.C:763
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:338
Foam::UnsortedMeshedSurface::storedZoneIds
labelList & storedZoneIds()
Return non-const access to the zone Ids.
Definition: UnsortedMeshedSurface.H:144
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::Vector< scalar >
Foam::UnsortedMeshedSurface::clear
virtual void clear()
Clear all storage.
Definition: UnsortedMeshedSurface.C:500
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::UnsortedMeshedSurface::point_type
point point_type
The point type (same as the underlying PrimitivePatch)
Definition: UnsortedMeshedSurface.H:167
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
surfZoneList.H
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::UnsortedMeshedSurface::remapFaces
virtual void remapFaces(const labelUList &faceMapNewToOld)
Set new zones from faceMap.
Definition: UnsortedMeshedSurface.C:434
memberFunctionSelectionTables.H
Macros to ease 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::PatchTools::subsetMap
static void subsetMap(const PrimitivePatch< FaceList, PointField > &p, const BoolListType &includeFaces, labelList &pointMap, labelList &faceMap)
Determine the mapping for a sub-patch.
Definition: PatchToolsSearch.C:142
Foam::UnsortedMeshedSurface::write
static void write(const fileName &name, const UnsortedMeshedSurface< Face > &surf, IOstreamOption streamOpt=IOstreamOption(), const dictionary &options=dictionary::null)
Write to file, select based on its extension.
Definition: UnsortedMeshedSurface.C:106
Foam::MeshedSurface
A surface geometry mesh with zone information, not to be confused with the similarly named surfaceMes...
Definition: triSurfaceTools.H:80
Foam::PtrListOps::names
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Foam::MeshedSurface::size
label size() const
The surface size is the number of faces.
Definition: MeshedSurface.H:407
Foam::UnsortedMeshedSurface::canReadType
static bool canReadType(const word &fileType, bool verbose=false)
Can we read this file format? Also checks friend types.
Definition: UnsortedMeshedSurface.C:56
Foam::UnsortedMeshedSurface::swap
void swap(MeshedSurface< Face > &surf)=delete
Swap contents - disabled.
surfaceFormatsCore.H
Foam::UnsortedMeshedSurface::writeTypes
static wordHashSet writeTypes()
Known writable file-types, without friends or proxies.
Definition: UnsortedMeshedSurface.C:48
Foam::UnsortedMeshedSurface::sortedZones
surfZoneList sortedZones(labelList &faceMap) const
Sort faces according to zoneIds.
Definition: UnsortedMeshedSurface.C:510
MeshedSurface.H
surfZoneIdentifierList.H