triSurface.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-2021 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::triSurface
29
30Description
31 Triangulated surface description with patch information.
32
33SourceFiles
34 triSurface.C
35 triSurfaceAddressing.C
36 triSurfaceIO.C
37 triSurfaceStitch.C
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef triSurface_H
42#define triSurface_H
43
44#include "PrimitivePatch.H"
45#include "PatchTools.H"
46#include "pointField.H"
47#include "labelledTri.H"
48#include "boolList.H"
49#include "bitSet.H"
50#include "HashSet.H"
52#include "surfacePatchList.H"
53#include "triFaceList.H"
54
55// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56
57namespace Foam
58{
59
60// Forward Declarations
61class Time;
62class IOobject;
63class IFstream;
64class surfZone;
65class triSurface;
66
67template<class Face> class MeshedSurface;
68
69Istream& operator>>(Istream&, triSurface&);
70Ostream& operator<<(Ostream&, const triSurface&);
71
72
73/*---------------------------------------------------------------------------*\
74 Class triSurface Declaration
75\*---------------------------------------------------------------------------*/
77class triSurface
78:
79 public PrimitivePatch<::Foam::List<labelledTri>, pointField>
80{
81 // Private Typedefs
82
83 //- Internal mesh storage type
86
87
88 // Private Data
89
90 //- Patch information
91 // (face ordering nFaces/startFace only used during reading, writing)
93
94
95 // Demand Driven
96
97 //- Edge-face addressing (sorted)
98 mutable unique_ptr<labelListList> sortedEdgeFacesPtr_;
99
100 //- Label of face that 'owns' edge
101 //- i.e. e.vec() is righthanded walk along face
102 mutable unique_ptr<labelList> edgeOwnerPtr_;
103
104
105 // Private Member Functions
106
107 //- Calculate sorted edgeFaces
108 void calcSortedEdgeFaces() const;
109
110 //- Calculate owner
111 void calcEdgeOwner() const;
112
113 //- Sort faces according to region.
114 // Returns patch list and sets faceMap to index of labelledTri
115 // inside *this.
116 surfacePatchList calcPatches(labelList& faceMap) const;
117
118 //- Sets default values for patches
119 void setDefaultPatches();
120
121 //- Function to stitch the triangles by removing duplicate points.
122 // Returns true if any points merged
123 bool stitchTriangles
124 (
125 const scalar tol = SMALL,
126 const bool verbose = false
127 );
128
129 //- Read in OpenFOAM format
130 bool readNative(Istream& is);
131
132 //- Write in OpenFOAM format
133 void writeNative(Ostream& os) const;
134
135 //- Read in STL format
136 bool readSTL(const fileName& filename, bool forceBinary=false);
137
138 //- Generic read routine for given format type.
139 // If the format type is "", uses the file extension.
140 bool read
141 (
142 const fileName& filename,
143 const word& fileType,
144 const bool check = true
145 );
146
147 //- Write STL ASCII format.
148 // Each region becomes a 'solid' 'endsolid' block.
149 void writeSTLASCII(const fileName& filename, const bool sort) const;
150
151 //- Write STL BINARY format
152 void writeSTLBINARY(const fileName& filename) const;
153
154 //- Write GTS (Gnu Tri Surface library) format.
155 void writeGTS(const fileName& filename, const bool sort) const;
156
157
158 // Static Private Functions
159
160 //- Convert faces to labelledTri. All get same region.
161 static List<labelledTri> convertToTri
162 (
163 const faceList& faces,
164 const label defaultRegion = 0
165 );
166
167 //- Convert triFaces to labelledTri. All get same region.
168 static List<labelledTri> convertToTri
169 (
170 const triFaceList& faces,
171 const label defaultRegion = 0
172 );
173
174 //- Return a new surface using specified pointMap and faceMap
175 //
176 // \param[in] pointMap from subsetMeshMap
177 // \param[in] faceMap from subsetMeshMap
178 triSurface subsetMeshImpl
179 (
180 const labelList& pointMap,
181 const labelList& faceMap
182 ) const;
183
184
185protected:
186
187 // Protected Member Functions
188
189 //- Non-const access to global points
191 {
192 return const_cast<pointField&>(MeshReference::points());
193 }
194
195 //- Non-const access to the faces
197 {
198 return static_cast<List<labelledTri>&>(*this);
199 }
200
201
202public:
203
204 // Public Typedefs
205
206 //- Placeholder only, but do not remove - it is needed for GeoMesh
207 typedef bool BoundaryMesh;
208
209 //- The face type (same as the underlying PrimitivePatch)
210 typedef labelledTri face_type;
211
212 //- The point type (same as the underlying PrimitivePatch)
213 typedef point point_type;
214
215
216 //- Runtime type information
217 ClassName("triSurface");
218
219
220 // Static
221
222 //- Name of triSurface directory to use.
223 static fileName triSurfInstance(const Time&);
224
225 //- Known readable file-types, including via friends or proxies
226 static wordHashSet readTypes();
227
228 //- Known writable file-types, including via friends or proxies
229 static wordHashSet writeTypes();
230
231 //- Can we read this file format?
232 static bool canReadType(const word& fileType, bool verbose=false);
233
234 //- Can we write this file format?
235 static bool canWriteType(const word& fileType, bool verbose=false);
236
237 //- Can we read this file format?
238 static bool canRead(const fileName& name, bool verbose=false);
239
240
241 // IO helpers
242
243 //- Return fileName.
244 // If fileName is relative gets treated as local to IOobject.
246 (
247 const IOobject& io,
248 const fileName& f,
249 const bool isGlobal = true
250 );
251
252 //- Return fileName to load IOobject from.
253 // Fatal if the file does not exist
254 static fileName checkFile
255 (
256 const IOobject& io,
257 const bool isGlobal = true
258 );
259
260 //- Return fileName to load IOobject from.
261 // Supports optional override of fileName with "file" entry
262 // Fatal if the file does not exist
263 static fileName checkFile
264 (
265 const IOobject& io,
266 const dictionary& dict,
267 const bool isGlobal = true
268 );
269
270 //- Use IOobject information to resolve file to load from,
271 //- or empty if the file does not exist.
272 static fileName findFile
273 (
274 const IOobject& io,
275 const bool isGlobal = true
276 );
277
278 //- Use IOobject information to resolve file to load from,
279 //- or empty if the file does not exist.
280 // Supports optional override of fileName with "file" entry
281 static fileName findFile
282 (
283 const IOobject& io,
284 const dictionary& dict,
285 const bool isGlobal = true
286 );
287
288
289 // Constructors
290
291 //- Default construct
292 triSurface();
293
294 //- Copy construct
295 triSurface(const triSurface& surf);
296
297 //- Move construct
298 triSurface(triSurface&& surf);
299
300 //- Construct from triangles, patches, points.
302 (
303 const List<labelledTri>& triangles,
305 const pointField& pts
306 );
307
308 //- Construct from triangles, patches, points. Reuse storage.
310 (
311 List<labelledTri>& triangles,
313 pointField& pts,
314 const bool reuse
315 );
316
317 //- Construct from triangles, points.
318 //- Set patch names to default.
320 (
321 const List<labelledTri>& triangles,
322 const pointField& pts
323 );
324
325 //- Construct from triangles, points.
326 //- Set region to 0 and default patchName.
328 (
329 const triFaceList& triangles,
330 const pointField& pts
331 );
332
333 //- Construct from file name (uses extension to determine type).
334 // Optional (positive, non-zero) point scaling is possible.
335 explicit triSurface
336 (
337 const fileName& name,
338 const scalar scaleFactor = -1
339 );
340
341 //- Construct from file name with given format type.
342 // If the format type is "", uses the file extension.
344 (
345 const fileName& name,
346 const word& fileType,
347 const scalar scaleFactor = -1
348 );
349
350 //- Construct from Istream
351 explicit triSurface(Istream& is);
352
353 //- Construct from objectRegistry by reading an ".ftr" file
354 explicit triSurface(const Time& d);
355
356 //- Read construct using IO to find the file location.
357 // Dictionary may contain the following entries:
358 // - \c file = alternative file name (default is dictionary name)
359 // - \c fileType = file format (default is from file extension)
360 // - \c scale (eg, 0.001: mm to m)
361 // .
363 (
364 const IOobject& io,
365 const dictionary& dict,
366 const bool isGlobal = true
367 );
368
369
370 // Selectors
371
372 //- Read construct from filename with given file type
374 (
375 const fileName& name,
376 const word& fileType
377 );
378
379 //- Read construct from filename (file type implicit from extension)
380 static autoPtr<triSurface> New(const fileName& name);
381
382
383 //- Destructor
384 virtual ~triSurface();
385
386
387 // Member Functions
388
389 void clearOut();
390
391 void clearTopology();
392
393 void clearPatchMeshAddr();
394
395 void swap(triSurface& surf);
396
397
398 // Access
401 {
402 return patches_;
403 }
406 {
407 return patches_;
408 }
409
410 //- Return const access to the faces
412 {
413 return static_cast<const List<labelledTri>&>(*this);
414 }
415
416 //- Return edge-face addressing sorted (for edges with more than
417 // 2 faces) according to the angle around the edge.
418 // Orientation is anticlockwise looking from
419 // edge.vec(localPoints())
420 const labelListList& sortedEdgeFaces() const;
421
422 //- If 2 face neighbours: label of face where ordering of edge
423 // is consistent with righthand walk.
424 // If 1 neighbour: label of only face.
425 // If >2 neighbours: undetermined.
426 const labelList& edgeOwner() const;
427
428
429 //- Face area vectors (normals)
430 const vectorField& Sf() const
431 {
433 }
434
435 //- Face area magnitudes
436 const scalarField& magSf() const
437 {
439 }
440
441 //- Face centres
442 const vectorField& Cf() const
443 {
445 }
446
447
448 // Interoperability with other surface mesh classes
449
450 //- Sort faces according to zoneIds
451 // Returns a surfZoneList and sets faceMap to index within faces()
452 // (i.e. map from original,unsorted to sorted)
454
455 //- Create a list of faces from the triFaces
456 void triFaceFaces(List<face>& plainFaceList) const;
457
458
459 // Edit
460
461 //- Move points
462 virtual void movePoints(const pointField& pts);
463
464 //- Swap points. Similar to movePoints, but returns the old points
465 virtual void swapPoints(pointField& pts);
466
467 //- Scale points. A non-positive factor is ignored.
468 virtual void scalePoints(const scalar scaleFactor);
469
470 //- Check/remove duplicate/degenerate triangles
471 void checkTriangles(const bool verbose);
472
473 //- Check triply (or more) connected edges.
474 void checkEdges(const bool verbose);
475
476 //- Remove non-valid triangles
477 void cleanup(const bool verbose);
478
479 //- Remove unused points and renumber faces in local visit order
480 //
481 // \param[out] pointMap from new to old points (optional)
482 void compactPoints
483 (
484 labelList& pointMap = const_cast<labelList&>(labelList::null())
485 );
486
487 //- Fill faceZone with currentZone for every face reachable
488 // from facei without crossing edge marked in borderEdge.
489 // Note: faceZone has to be sized nFaces before calling this fun.
490 void markZone
491 (
492 const boolList& borderEdge,
493 const label facei,
494 const label currentZone,
496 ) const;
497
498 //- (size and) fills faceZone with zone of face. Zone is area
499 // reachable by edge crossing without crossing borderEdge
500 // (bool for every edge in surface). Returns number of zones.
501 label markZones
502 (
503 const boolList& borderEdge,
505 ) const;
506
507 //- Create mappings for a sub-surface
508 //
509 // \param[in] include the faces to select
510 // \param[out] pointMap from new to old localPoints
511 // \param[out] faceMap from new to old localFaces
512 template<class BoolListType>
513 void subsetMeshMap
514 (
515 const BoolListType& include,
516 labelList& pointMap,
518 ) const
519 {
520 PatchTools::subsetMap(*this, include, pointMap, faceMap);
521 }
522
523 //- Return a new surface subsetted on the selected faces.
524 //
525 // \param[in] include the faces to select
526 // \param[out] pointMap from new to old localPoints
527 // \param[out] faceMap from new to old localFaces
529 (
530 const UList<bool>& include,
531 labelList& pointMap,
533 ) const;
534
535 //- Return a new surface subsetted on the selected faces.
536 //
537 // \param[in] include the faces to select
538 // \param[out] pointMap from subsetMeshMap
539 // \param[out] faceMap from subsetMeshMap
541 (
542 const bitSet& include,
543 labelList& pointMap,
545 ) const;
546
547 //- Return a new surface subsetted on the selected faces.
548 //
549 // \param[in] include the faces to select
550 triSurface subsetMesh(const UList<bool>& include) const;
551
552 //- Return a new surface subsetted on the selected faces.
553 //
554 // \param[in] include the faces to select
555 triSurface subsetMesh(const bitSet& include) const;
556
557 //- Return a new surface subsetted on the selected patch names
558 //
559 // \param[in] includeNames surface patch names to include
560 // \param[in] excludeNames surface patch names to exclude
561 //
562 // \see Foam::stringListOps::findMatching for details about matching
564 (
565 const wordRes& includeNames,
566 const wordRes& excludeNames = wordRes()
567 ) const;
568
569 //- Swap the list of faces being addressed
570 void swapFaces(List<labelledTri>& faceLst);
571
572 //- Alter contents by transferring (triangles, points) components.
573 // Patch information is small and therefore just copied.
574 void transfer(triSurface& surf);
575
576 //- Alter contents by transferring (triangles, points) components.
577 // Patch information is small and therefore just copied.
579
580
581 // Write
582
583 //- Write to Ostream in simple OpenFOAM format
584 void write(Ostream& os) const;
585
586 //- Generic write routine (uses extension to determine type).
587 // The sort option may not have an effect.
588 void write(const fileName&, const bool sortByRegion = false) const;
589
590 //- Generic write routine for given format type.
591 // If the format type is "", uses the file extension.
592 // The sort option may not have an effect.
593 void write
594 (
595 const fileName& filename,
596 const word& fileType,
597 const bool sortByRegion = false
598 ) const;
599
600 //- Write to database
601 void write(const Time& d) const;
602
603 //- Write some statistics
604 void writeStats(Ostream& os) const;
605
606
607 // Member Operators
608
609 //- Copy assignment
610 void operator=(const triSurface& surf);
611
612 //- Move assignment
613 void operator=(triSurface&& surf);
614
615 //- Move assignment
617
618
619 // IOstream Operators
622 friend Ostream& operator<<(Ostream& os, const triSurface& s);
623};
624
625
626// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
627
628} // End namespace Foam
629
630// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
631
632#endif
633
634// ************************************************************************* //
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A surface geometry mesh with zone information, not to be confused with the similarly named surfaceMes...
Definition: MeshedSurface.H:99
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.
A list of faces which address into the list of points.
const Field< point_type > & points() const noexcept
Return reference to global points.
const Field< point_type > & faceAreas() const
Return face area vectors for patch.
const Field< point_type > & faceCentres() const
Return face centres for patch.
const Field< scalar > & magFaceAreas() const
Return face area magnitudes for patch.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
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:94
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 subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:67
A class for handling file names.
Definition: fileName.H:76
A triFace with additional (region) index.
Definition: labelledTri.H:60
Triangulated surface description with patch information.
Definition: triSurface.H:79
geometricSurfacePatchList & patches() noexcept
Definition: triSurface.H:404
static fileName triSurfInstance(const Time &)
Name of triSurface directory to use.
Definition: triSurface.C:73
static fileName checkFile(const IOobject &io, const bool isGlobal=true)
Return fileName to load IOobject from.
Definition: triSurfaceIO.C:122
triSurface()
Default construct.
Definition: triSurface.C:432
static bool canWriteType(const word &fileType, bool verbose=false)
Can we write this file format?
Definition: triSurfaceIO.C:87
const vectorField & Sf() const
Face area vectors (normals)
Definition: triSurface.H:429
List< surfZone > sortedZones(labelList &faceMap) const
Sort faces according to zoneIds.
Definition: triSurface.C:709
pointField & storedPoints()
Non-const access to global points.
Definition: triSurface.H:189
void transfer(triSurface &surf)
Alter contents by transferring (triangles, points) components.
Definition: triSurface.C:961
static wordHashSet writeTypes()
Known writable file-types, including via friends or proxies.
Definition: triSurfaceIO.C:58
static fileName findFile(const IOobject &io, const bool isGlobal=true)
Definition: triSurfaceIO.C:143
label markZones(const boolList &borderEdge, labelList &faceZone) const
(size and) fills faceZone with zone of face. Zone is area
Definition: triSurface.C:796
friend Istream & operator>>(Istream &is, triSurface &s)
const scalarField & magSf() const
Face area magnitudes.
Definition: triSurface.H:435
void swap(triSurface &surf)
Definition: triSurface.C:574
static autoPtr< triSurface > New(const fileName &name, const word &fileType)
Read construct from filename with given file type.
Definition: triSurfaceNew.C:37
labelledTri face_type
The face type (same as the underlying PrimitivePatch)
Definition: triSurface.H:209
void triFaceFaces(List< face > &plainFaceList) const
Create a list of faces from the triFaces.
Definition: triSurface.C:723
triSurface subsetMesh(const UList< bool > &include, labelList &pointMap, labelList &faceMap) const
Return a new surface subsetted on the selected faces.
Definition: triSurface.C:879
static bool canReadType(const word &fileType, bool verbose=false)
Can we read this file format?
Definition: triSurfaceIO.C:75
void cleanup(const bool verbose)
Remove non-valid triangles.
Definition: triSurface.C:655
void clearTopology()
Definition: triSurface.C:552
const geometricSurfacePatchList & patches() const noexcept
Definition: triSurface.H:399
void checkTriangles(const bool verbose)
Check/remove duplicate/degenerate triangles.
Definition: triSurface.C:182
virtual void swapPoints(pointField &pts)
Swap points. Similar to movePoints, but returns the old points.
Definition: triSurface.C:625
void checkEdges(const bool verbose)
Check triply (or more) connected edges.
Definition: triSurface.C:301
List< labelledTri > & storedFaces()
Non-const access to the faces.
Definition: triSurface.H:195
void compactPoints(labelList &pointMap=const_cast< labelList & >(labelList::null()))
Remove unused points and renumber faces in local visit order.
Definition: triSurface.C:669
const vectorField & Cf() const
Face centres.
Definition: triSurface.H:441
void markZone(const boolList &borderEdge, const label facei, const label currentZone, labelList &faceZone) const
Fill faceZone with currentZone for every face reachable.
Definition: triSurface.C:737
static bool canRead(const fileName &name, bool verbose=false)
Can we read this file format?
Definition: triSurfaceIO.C:99
static fileName relativeFilePath(const IOobject &io, const fileName &f, const bool isGlobal=true)
Return fileName.
Definition: triSurfaceIO.C:111
friend Ostream & operator<<(Ostream &os, const triSurface &s)
const labelList & edgeOwner() const
If 2 face neighbours: label of face where ordering of edge.
Definition: triSurface.C:601
void subsetMeshMap(const BoolListType &include, labelList &pointMap, labelList &faceMap) const
Create mappings for a sub-surface.
Definition: triSurface.H:513
void writeStats(Ostream &os) const
Write some statistics.
Definition: triSurfaceIO.C:353
virtual void movePoints(const pointField &pts)
Move points.
Definition: triSurface.C:612
point point_type
The point type (same as the underlying PrimitivePatch)
Definition: triSurface.H:212
void clearPatchMeshAddr()
Definition: triSurface.C:560
virtual void scalePoints(const scalar scaleFactor)
Scale points. A non-positive factor is ignored.
Definition: triSurface.C:638
const labelListList & sortedEdgeFaces() const
Return edge-face addressing sorted (for edges with more than.
Definition: triSurface.C:590
const List< labelledTri > & surfFaces() const noexcept
Return const access to the faces.
Definition: triSurface.H:410
void swapFaces(List< labelledTri > &faceLst)
Swap the list of faces being addressed.
Definition: triSurface.C:953
void operator=(const triSurface &surf)
Copy assignment.
Definition: triSurface.C:999
ClassName("triSurface")
Runtime type information.
bool BoundaryMesh
Placeholder only, but do not remove - it is needed for GeoMesh.
Definition: triSurface.H:206
virtual ~triSurface()
Destructor.
Definition: triSurface.C:544
static wordHashSet readTypes()
Known readable file-types, including via friends or proxies.
Definition: triSurfaceIO.C:40
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition: className.H:67
OBJstream os(runTime.globalPath()/outputName)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
static void check(const int retVal, const char *what)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:342
const direction noexcept
Definition: Scalar.H:223
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
runTime write()
labelList f(nPoints)
dictionary dict