triSurfaceMesh.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-2017 OpenFOAM Foundation
9  Copyright (C) 2015-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::triSurfaceMesh
29 
30 Description
31  IOoject and searching on triSurface
32 
33  Note: when constructing from dictionary has the following parameters:
34  - scale : scaling factor.
35  - tolerance : relative tolerance for doing intersections
36  (see triangle::intersection)
37  - minQuality: discard triangles with low quality when getting normal
38 
39  \heading Dictionary parameters
40  \table
41  Property | Description | Required | Default
42  type | triSurfaceMesh | selector |
43  file | File name to locate the surface | no |
44  fileType | The surface format (Eg, nastran) | no |
45  scale | Scaling factor | no | 0
46  minQuality | Quality criterion | no | -1
47  \endtable
48 
49 SourceFiles
50  triSurfaceMesh.C
51 
52 \*---------------------------------------------------------------------------*/
53 
54 #ifndef triSurfaceMesh_H
55 #define triSurfaceMesh_H
56 
57 #include "searchableSurface.H"
58 #include "treeBoundBox.H"
59 #include "objectRegistry.H"
60 #include "indexedOctree.H"
61 #include "treeDataTriSurface.H"
62 #include "treeDataPrimitivePatch.H"
63 #include "treeDataEdge.H"
64 #include "edgeHashes.H"
65 #include "triSurface.H"
66 #include "triSurfaceRegionSearch.H"
67 
68 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
69 
70 namespace Foam
71 {
72 
73 /*---------------------------------------------------------------------------*\
74  Class triSurfaceMesh Declaration
75 \*---------------------------------------------------------------------------*/
76 
77 class triSurfaceMesh
78 :
79  public searchableSurface,
80  public objectRegistry, // so we can store fields
81  public triSurface,
82  public triSurfaceRegionSearch
83 {
84 protected:
85 
86  // Private member data
87 
88  //- Supplied fileName override
89  fileName fName_;
90 
91  //- Optional min triangle quality. Triangles below this get
92  // ignored for normal calculation
93  scalar minQuality_;
94 
95  //- Search tree for boundary edges.
96  mutable autoPtr<indexedOctree<treeDataEdge>> edgeTree_;
97 
98  //- Names of regions
99  mutable wordList regions_;
100 
101  //- Is surface closed
102  mutable label surfaceClosed_;
103 
104  //- If surface is closed, what is type of outside points
105  mutable volumeType outsideVolType_;
106 
107 
108  // Private Member Functions
109 
110  //- Helper function for isSurfaceClosed
111  static bool addFaceToEdge
112  (
113  const edge&,
115  );
116 
117  //- Check whether surface is closed without calculating any permanent
118  // addressing.
119  bool isSurfaceClosed() const;
120 
121  //- Steps to next intersection. Adds smallVec and starts tracking
122  // from there.
123  static void getNextIntersections
124  (
126  const point& start,
127  const point& end,
128  const vector& smallVec,
130  );
131 
132  //- No copy construct
133  triSurfaceMesh(const triSurfaceMesh&) = delete;
134 
135  //- No copy assignment
136  void operator=(const triSurfaceMesh&) = delete;
137 
138 
139 public:
140 
141  //- Runtime type information
142  TypeName("triSurfaceMesh");
143 
144  //- Return the mesh sub-directory name (usually "triSurface")
145  static word meshSubDir;
146 
147 
148  // Constructors
149 
150  //- Construct from triSurface
151  triSurfaceMesh(const IOobject&, const triSurface&);
152 
153  //- Construct read
154  triSurfaceMesh(const IOobject& io);
155 
156  //- Construct from IO and dictionary (used by searchableSurface).
157  // Dictionary may contain a 'scale' entry (eg, 0.001: mm -> m)
159  (
160  const IOobject& io,
161  const dictionary& dict
162  );
163 
164 
165  // Special constructors for use by distributedTriSurface. File search
166  // method supplied:
167 
168  enum readAction
169  {
170  localOnly, // load from (processor-)local file only
171  localOrGlobal, // load from (processor-)local or global file
172  masterOnly // as localOrGlobal but only load on master
173  };
174 
175  triSurfaceMesh(const IOobject& io, const readAction r);
176 
178  (
179  const IOobject& io,
180  const dictionary& dict,
181  const readAction r
182  );
183 
184 
185  //- Destructor
186  virtual ~triSurfaceMesh();
187 
188 
189  //- Clear storage
190  void clearOut();
191 
192 
193  // Member Functions
194 
195  //- Move points
196  virtual void movePoints(const pointField&);
197 
198  //- Demand driven construction of octree for boundary edges
200 
201 
202  // searchableSurface implementation
203 
204  //- Names of regions
205  virtual const wordList& regions() const;
206 
207  //- Whether supports volume type (below) - i.e. whether is closed.
208  virtual bool hasVolumeType() const;
209 
210  //- If surface is closed, what is type of points outside bounds
211  virtual volumeType outsideVolumeType() const;
212 
213  //- Range of local indices that can be returned.
214  virtual label size() const
215  {
216  return triSurface::size();
217  }
218 
219  //- Get representative set of element coordinates
220  // Usually the element centres (should be of length size()).
221  virtual tmp<pointField> coordinates() const;
222 
223  //- Get bounding spheres (centre and radius squared). Any point
224  // on surface is guaranteed to be inside.
225  virtual void boundingSpheres
226  (
227  pointField& centres,
228  scalarField& radiusSqr
229  ) const;
230 
231  //- Get the points that define the surface.
232  virtual tmp<pointField> points() const;
233 
234  // Does any part of the surface overlap the supplied bound box?
235  virtual bool overlaps(const boundBox& bb) const;
236 
237  virtual void findNearest
238  (
239  const pointField& sample,
240  const scalarField& nearestDistSqr,
242  ) const;
243 
244  virtual void findNearest
245  (
246  const pointField& sample,
247  const scalarField& nearestDistSqr,
248  const labelList& regionIndices,
250  ) const;
251 
252  virtual void findLine
253  (
254  const pointField& start,
255  const pointField& end,
257  ) const;
258 
259  virtual void findLineAny
260  (
261  const pointField& start,
262  const pointField& end,
264  ) const;
265 
266  //- Get all intersections in order from start to end.
267  virtual void findLineAll
268  (
269  const pointField& start,
270  const pointField& end,
272  ) const;
273 
274  //- From a set of points and indices get the region
275  virtual void getRegion
276  (
277  const List<pointIndexHit>&,
278  labelList& region
279  ) const;
280 
281  //- From a set of points and indices get the normal
282  virtual void getNormal
283  (
284  const List<pointIndexHit>&,
285  vectorField& normal
286  ) const;
287 
288  //- Determine type (inside/outside/mixed) for point.
289  // Unknown if cannot be determined (e.g. non-manifold surface)
290  virtual void getVolumeType
291  (
292  const pointField& points,
293  List<volumeType>& volType
294  ) const;
295 
296 
297  // Other
298 
299  //- WIP. Store element-wise field.
300  virtual void setField(const labelList& values);
301 
302  //- WIP. From a set of hits (points and
303  // indices) get the specified field. Misses do not get set.
304  virtual void getField(const List<pointIndexHit>&, labelList&) const;
305 
306 
307  // regIOobject implementation
308 
309  bool writeData(Ostream&) const
310  {
312  return false;
313  }
314 
315  //- Write using stream options
316  virtual bool writeObject
317  (
318  IOstreamOption streamOpt,
319  const bool valid
320  ) const;
321 
322  //- Is object global
323  virtual bool global() const
324  {
325  return true;
326  }
327 
328  //- Return complete path + object name if the file exists
329  // either in the case/processor or case otherwise null
330  virtual fileName filePath() const
331  {
333  }
334 };
335 
336 
337 //- Template function for obtaining global status
338 template<>
339 inline bool typeGlobal<triSurfaceMesh>()
340 {
341  return true;
342 }
343 
344 
345 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
346 
347 } // End namespace Foam
348 
349 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
350 
351 #endif
352 
353 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::triSurfaceMesh::operator=
void operator=(const triSurfaceMesh &)=delete
No copy assignment.
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
searchableSurface.H
Foam::triSurfaceMesh::localOnly
Definition: triSurfaceMesh.H:199
Foam::triSurfaceMesh::localOrGlobal
Definition: triSurfaceMesh.H:200
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::triSurfaceMesh::minQuality_
scalar minQuality_
Optional min triangle quality. Triangles below this get.
Definition: triSurfaceMesh.H:122
Foam::triSurfaceMesh::edgeTree_
autoPtr< indexedOctree< treeDataEdge > > edgeTree_
Search tree for boundary edges.
Definition: triSurfaceMesh.H:125
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::triSurfaceMesh::getNormal
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
Definition: triSurfaceMesh.C:954
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::triSurfaceMesh::getRegion
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
Definition: triSurfaceMesh.C:921
Foam::HashTable< regIOobject * >::end
iterator end() noexcept
iterator to signal the end (for any HashTable)
Definition: HashTableIterI.H:256
Foam::triSurfaceMesh::edgeTree
const indexedOctree< treeDataEdge > & edgeTree() const
Demand driven construction of octree for boundary edges.
Definition: triSurfaceMesh.C:645
Foam::triSurfaceMesh::TypeName
TypeName("triSurfaceMesh")
Runtime type information.
indexedOctree.H
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:63
objectRegistry.H
Foam::typeGlobal< triSurfaceMesh >
bool typeGlobal< triSurfaceMesh >()
Template function for obtaining global status.
Definition: triSurfaceMesh.H:368
Foam::triSurfaceMesh
IOoject and searching on triSurface.
Definition: triSurfaceMesh.H:106
Foam::triSurfaceRegionSearch
Helper class to search on triSurface. Creates an octree for each region of the surface and only searc...
Definition: triSurfaceRegionSearch.H:58
triSurface.H
Foam::triSurfaceMesh::readAction
readAction
Definition: triSurfaceMesh.H:197
Foam::triSurfaceMesh::size
virtual label size() const
Range of local indices that can be returned.
Definition: triSurfaceMesh.H:243
Foam::triSurfaceMesh::surfaceClosed_
label surfaceClosed_
Is surface closed.
Definition: triSurfaceMesh.H:131
Foam::triSurfaceMesh::outsideVolumeType
virtual volumeType outsideVolumeType() const
If surface is closed, what is type of points outside bounds.
Definition: triSurfaceMesh.C:760
Foam::triSurfaceMesh::findLineAny
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
Definition: triSurfaceMesh.C:875
Foam::triSurfaceMesh::triSurfaceMesh
triSurfaceMesh(const triSurfaceMesh &)=delete
No copy construct.
Foam::triSurfaceMesh::movePoints
virtual void movePoints(const pointField &)
Move points.
Definition: triSurfaceMesh.C:612
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
Foam::volumeType
An enumeration wrapper for classification of a location as being inside/outside of a volume.
Definition: volumeType.H:60
Foam::Field< vector >
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:76
treeBoundBox.H
Foam::triSurfaceMesh::fName_
fileName fName_
Supplied fileName override.
Definition: triSurfaceMesh.H:118
Foam::searchableSurface
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
Definition: searchableSurface.H:69
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::triSurfaceMesh::findLine
virtual void findLine(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Find first intersection on segment from start to end.
Definition: triSurfaceMesh.C:852
Foam::indexedOctree
Non-pointer based hierarchical recursive searching.
Definition: treeDataEdge.H:50
treeDataPrimitivePatch.H
Foam::triSurfaceMesh::getField
virtual void getField(const List< pointIndexHit > &, labelList &) const
WIP. From a set of hits (points and.
Definition: triSurfaceMesh.C:1076
Foam::triSurfaceMesh::regions
virtual const wordList & regions() const
Names of regions.
Definition: triSurfaceMesh.C:728
Foam::triSurfaceMesh::regions_
wordList regions_
Names of regions.
Definition: triSurfaceMesh.H:128
Foam::triSurfaceMesh::writeData
bool writeData(Ostream &) const
writeData function required by regIOobject but not used.
Definition: triSurfaceMesh.H:338
Foam::triSurfaceMesh::boundingSpheres
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared). Any point.
Definition: triSurfaceMesh.C:569
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::triSurfaceMesh::clearOut
void clearOut()
Clear storage.
Definition: triSurfaceMesh.C:530
Foam::triSurfaceMesh::filePath
virtual fileName filePath() const
Return complete path + object name if the file exists.
Definition: triSurfaceMesh.H:359
Foam::IOobject::globalFilePath
fileName globalFilePath(const word &typeName, const bool search=true) const
Helper for filePath that searches up if in parallel.
Definition: IOobject.C:580
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
treeDataEdge.H
Foam::triSurfaceMesh::points
virtual tmp< pointField > points() const
Get the points that define the surface.
Definition: triSurfaceMesh.C:596
Foam::triSurfaceMesh::coordinates
virtual tmp< pointField > coordinates() const
Get representative set of element coordinates.
Definition: triSurfaceMesh.C:541
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::triSurfaceMesh::writeObject
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write using stream options.
Definition: triSurfaceMesh.C:1160
Foam::triSurfaceMesh::getNextIntersections
static void getNextIntersections(const indexedOctree< treeDataTriSurface > &octree, const point &start, const point &end, const vector &smallVec, DynamicList< pointIndexHit > &hits)
Steps to next intersection. Adds smallVec and starts tracking.
Foam::triSurfaceMesh::setField
virtual void setField(const labelList &values)
WIP. Store element-wise field.
Definition: triSurfaceMesh.C:1037
treeDataTriSurface.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::EdgeMap< label >
edgeHashes.H
Foam::triSurfaceMesh::~triSurfaceMesh
virtual ~triSurfaceMesh()
Destructor.
Definition: triSurfaceMesh.C:524
Foam::triSurfaceMesh::findNearest
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const
Definition: triSurfaceMesh.C:795
Foam::Vector< scalar >
Foam::List< word >
Foam::triSurfaceMesh::addFaceToEdge
static bool addFaceToEdge(const edge &, EdgeMap< label > &)
Helper function for isSurfaceClosed.
Definition: triSurfaceMesh.C:51
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::triSurfaceMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "triSurface")
Definition: triSurfaceMesh.H:174
Foam::triSurfaceMesh::overlaps
virtual bool overlaps(const boundBox &bb) const
Does any part of the surface overlap the supplied bound box?
Definition: triSurfaceMesh.C:602
Foam::triSurfaceMesh::isSurfaceClosed
bool isSurfaceClosed() const
Check whether surface is closed without calculating any permanent.
Definition: triSurfaceMesh.C:67
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::triSurfaceMesh::getVolumeType
virtual void getVolumeType(const pointField &points, List< volumeType > &volType) const
Determine type (inside/outside/mixed) for point.
Definition: triSurfaceMesh.C:1107
Foam::triSurfaceMesh::masterOnly
Definition: triSurfaceMesh.H:201
triSurfaceRegionSearch.H
Foam::triSurfaceMesh::hasVolumeType
virtual bool hasVolumeType() const
Whether supports volume type (below) - i.e. whether is closed.
Definition: triSurfaceMesh.C:742
Foam::triSurfaceMesh::global
virtual bool global() const
Is object global.
Definition: triSurfaceMesh.H:352
Foam::triSurfaceMesh::findLineAll
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const
Get all intersections in order from start to end.
Definition: triSurfaceMesh.C:898
Foam::triSurfaceMesh::outsideVolType_
volumeType outsideVolType_
If surface is closed, what is type of outside points.
Definition: triSurfaceMesh.H:134
sample
Minimal example by using system/controlDict.functions: