Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::UnsortedMeshedSurface
29
30Description
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
40See also
41 The Foam::MeshedSurface - which is organized as a surface mesh, but
42 with independent zone information.
43
44SourceFiles
45 UnsortedMeshedSurface.C
46
47\*---------------------------------------------------------------------------*/
48
49#ifndef Foam_UnsortedMeshedSurface_H
50#define Foam_UnsortedMeshedSurface_H
51
52#include "MeshedSurface.H"
54#include "surfZoneList.H"
55#include "surfaceFormatsCore.H"
56#include "HashSet.H"
59
60// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61
62namespace Foam
63{
64
65// Forward Declarations
66class Time;
67
68template<class Face> class MeshedSurface;
69template<class Face> class MeshedSurfaceProxy;
70template<class Face> class UnsortedMeshedSurface;
71
72template<class Face>
74template<class Face>
76
77/*---------------------------------------------------------------------------*\
78 Class UnsortedMeshedSurface Declaration
79\*---------------------------------------------------------------------------*/
80
81template<class Face>
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
93private:
94
95 // Private Typedefs (convenience)
96
97 typedef MeshedSurface<Face> MeshReference;
98 typedef MeshedSurface<Face> FriendType;
99 typedef MeshedSurfaceProxy<Face> ProxyType;
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)
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
138protected:
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
158public:
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
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
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.
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
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
251 (
252 autoPtr,
254 fileExtension,
255 (
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 );
275 //- Read construct from filename (implicit extension)
277
278
279 //- Destructor
280 virtual ~UnsortedMeshedSurface() = default;
281
282
283 // Member Function Selectors
286 (
287 void,
290 fileExtension,
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
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
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);
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;
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
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
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
448 //- Write to file, choosing writer based on the file extension.
449 virtual void write
450 (
451 const fileName& name,
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 }
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,
508 );
509};
510
511
512// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
513
514} // End namespace Foam
515
516// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
518#ifdef NoRepository
519 #include "UnsortedMeshedSurface.C"
520#endif
521
522// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
523
524#endif
526// ************************************************************************* //
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A simple container for options an IOstream can normally have.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
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...
label size() const
The surface size is the number of faces.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
static void subsetMap(const PrimitivePatch< FaceList, PointField > &p, const BoolListType &includeFaces, labelList &pointMap, labelList &faceMap)
Determine the mapping for a sub-patch.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
A surface geometry mesh, in which the surface zone information is conveyed by the 'zoneId' associated...
Face face_type
The face type (same as the underlying PrimitivePatch).
virtual void write(const fileName &name, IOstreamOption streamOpt=IOstreamOption(), const dictionary &options=dictionary::null) const
Write to file, choosing writer based on the file extension.
UnsortedMeshedSurface(Istream &is)
Construct from Istream.
UnsortedMeshedSurface(const MeshedSurface< Face > &surf)
Construct from a MeshedSurface.
static void write(const fileName &name, const UnsortedMeshedSurface< face > &surf, IOstreamOption streamOpt=IOstreamOption(), const dictionary &options=dictionary::null)
declareRunTimeSelectionTable(autoPtr, UnsortedMeshedSurface, fileExtension,(const fileName &name),(name))
void operator=(UnsortedMeshedSurface< Face > &&surf)
Move assignment.
void transfer(MeshedSurface< Face > &surf)
Transfer the contents of the argument and annul the argument.
static bool canWriteType(const word &fileType, bool verbose=false)
Can we write this file format? Also checks friend types.
autoPtr< labelList > releaseZoneIds()
Release (clear) stored zoneIds and return for reuse.
UnsortedMeshedSurface(UnsortedMeshedSurface< Face > &&surf)
Move construct from a UnsortedMeshedSurface.
void setZones(const labelUList &sizes, const UList< word > &names)
Set zone ids and zones.
UnsortedMeshedSurface subsetMesh(const bitSet &include) const
Return a new surface subsetted on the selected faces.
surfZoneList sortedZones(labelList &faceMap) const
Sort faces according to zoneIds.
UnsortedMeshedSurface(MeshedSurface< Face > &&surf)
Move construct from MeshedSurface.
static wordHashSet writeTypes()
Known writable file-types, without friends or proxies.
UnsortedMeshedSurface subsetMesh(const bitSet &include, labelList &pointMap, labelList &faceMap) const
Return a new surface subsetted on the selected faces.
static void write(const fileName &name, const word &fileType, const UnsortedMeshedSurface< Face > &surf, IOstreamOption streamOpt=IOstreamOption(), const dictionary &options=dictionary::null)
Write to file with given format type.
void setZones(const labelUList &sizes)
Set zone ids and zones with default names.
void write(const Time &t, const word &surfName=word::null) const
Write to database.
virtual bool read(const fileName &name)
Read from file. Chooses reader based on detected extension.
virtual void remapFaces(const labelUList &faceMapNewToOld)
Set new zones from faceMap.
virtual void write(const fileName &name, const word &fileType, IOstreamOption streamOpt=IOstreamOption(), const dictionary &options=dictionary::null) const
Write to file with given format type.
void setZones(const surfZoneList &zoneLst)
Set zone ids and zones.
static bool canReadType(const word &fileType, bool verbose=false)
Can we read this file format? Also checks friend types.
void transfer(UnsortedMeshedSurface< Face > &surf)
Transfer the contents of the argument and annul the argument.
bool read(const fileName &name, const word &fileType)
Read from file with given format type.
static autoPtr< UnsortedMeshedSurface > New(const fileName &name)
Read construct from filename (implicit extension).
virtual const labelList & zoneIds() const
labelList & storedZoneIds()
Return non-const access to the zone Ids.
static bool canRead(const fileName &name, bool verbose=false)
Can we read this file format?
UnsortedMeshedSurface(const UnsortedMeshedSurface< Face > &surf)
Copy construct.
label size() const
The surface size is the number of faces.
UnsortedMeshedSurface subsetMesh(const UList< bool > &include) const
Return a new surface subsetted on the selected faces.
UnsortedMeshedSurface(const IOobject &io, const dictionary &dict, const bool isGlobal=true)
Read construct using IO to find the file location.
UnsortedMeshedSurface()
Default construct.
virtual ~UnsortedMeshedSurface()=default
Destructor.
List< surfZoneIdentifier > & storedZoneToc()
Return non-const access to the zone table-of-contents.
void operator=(const UnsortedMeshedSurface< Face > &surf)
Copy assignment.
TypeName("UnsortedMeshedSurface")
Declare type-name, virtual type (with debug switch).
void subsetMeshMap(const BoolListType &include, labelList &pointMap, labelList &faceMap) const
Create mappings for a sub-surface.
declareMemberFunctionSelectionTable(void, UnsortedMeshedSurface, write, fileExtension,(const fileName &name, const UnsortedMeshedSurface< Face > &surf, IOstreamOption streamOpt, const dictionary &options),(name, surf, streamOpt, options))
UnsortedMeshedSurface(pointField &&pointLst, List< Face > &&faceLst, List< label > &&zoneIds, UList< surfZoneIdentifier > &tocInfo)
Move construct from components (points, faces, zone ids).
void setOneZone()
Set zones to 0 and set a single zone.
virtual void clear()
Clear all storage.
point point_type
The point type (same as the underlying PrimitivePatch).
static autoPtr< UnsortedMeshedSurface > New(const fileName &name, const word &fileType, bool mandatory=true)
Read construct from filename with given file type.
UnsortedMeshedSurface(const fileName &name)
Construct from file name (uses extension to determine type).
const List< surfZoneIdentifier > & zoneToc() const
Return const access to the zone table-of-contents.
UnsortedMeshedSurface(const Time &runTime, const word &surfName)
Construct from database (as surfMesh) with given surface name.
void setSize(const label)
Reset size of face and zone list.
UnsortedMeshedSurface(const Time &runTime)
Construct from database (as surfMesh) with default name.
void swap(UnsortedMeshedSurface< Face > &surf)
Swap contents.
UnsortedMeshedSurface(const fileName &name, const word &fileType)
Construct from file name with given format type.
void swap(MeshedSurface< Face > &surf)=delete
Swap contents - disabled.
UnsortedMeshedSurface subsetMesh(const UList< bool > &include, labelList &pointMap, labelList &faceMap) const
Return a new surface subsetted on the selected faces.
static wordHashSet readTypes()
Known readable file-types, without friends or proxies.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition dictionary.H:487
A class for handling file names.
Definition fileName.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
static const word null
An empty word.
Definition word.H:84
patchWriters resize(patchIds.size())
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
const auto & io
auto & names
Macros to ease declaration of member function selection tables.
#define declareMemberFunctionSelectionTable(returnType, baseType, funcName, argNames, argList, parListUnused)
Declare a run-time member-function selection (variables and adder classes).
Namespace for OpenFOAM.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition HashSet.H:80
List< label > labelList
A List of labels.
Definition List.H:62
List< surfZone > surfZoneList
List of surfZone.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Istream & operator>>(Istream &, directionInfo &)
vector point
Point is a vector.
Definition point.H:37
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
vectorField pointField
pointField is a vectorField.
UList< label > labelUList
A UList of labels.
Definition UList.H:75
runTime write()
points setSize(newPointi)
Macros to ease declaration of run-time selection tables.
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes).
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68