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