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 UnsortedMeshedSurface_H
50#define 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;
67class Istream;
68class Ostream;
69
70template<class Face> class MeshedSurface;
71template<class Face> class MeshedSurfaceProxy;
72template<class Face> class UnsortedMeshedSurface;
73
74template<class Face>
76template<class Face>
78
79/*---------------------------------------------------------------------------*\
80 Class UnsortedMeshedSurface Declaration
81\*---------------------------------------------------------------------------*/
82
83template<class Face>
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
95private:
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)
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
140protected:
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
160public:
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
253 (
254 autoPtr,
256 fileExtension,
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
288 (
289 void,
291 write,
292 fileExtension,
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>
377 void subsetMeshMap
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
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,
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// ************************************************************************* //
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
The IOstreamOption is 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:64
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:99
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:62
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:80
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.
declareRunTimeSelectionTable(autoPtr, UnsortedMeshedSurface, fileExtension,(const fileName &name),(name))
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.
surfZoneList sortedZones(labelList &faceMap) const
Sort faces according to zoneIds.
static wordHashSet writeTypes()
Known writable file-types, without friends or proxies.
virtual void remapFaces(const labelUList &faceMapNewToOld)
Set new zones from faceMap.
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.
virtual const labelList & zoneIds() const
Return const access to the zone ids.
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?
label size() const
The surface size is the number of faces.
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))
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.
const List< surfZoneIdentifier > & zoneToc() const
Return const access to the zone table-of-contents.
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:66
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
A surface mesh consisting of general polygon faces that has IO capabilities and a registry for storin...
Definition: surfMesh.H:68
A class for handling words, derived from Foam::string.
Definition: word.H:68
static const word null
An empty word.
Definition: word.H:80
patchWriters resize(patchIds.size())
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
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)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
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:73