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  );
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.
124  (
125  const indexedOctree<treeDataTriSurface>& octree,
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 
139 public:
140 
141  //- Runtime type information
142  TypeName("triSurfaceMesh");
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  //- Flip triangles, outsideVolumeType and all cached inside/outside.
220  virtual void flip();
221 
222  //- Get representative set of element coordinates
223  // Usually the element centres (should be of length size()).
224  virtual tmp<pointField> coordinates() const;
225 
226  //- Get bounding spheres (centre and radius squared). Any point
227  // on surface is guaranteed to be inside.
228  virtual void boundingSpheres
229  (
230  pointField& centres,
231  scalarField& radiusSqr
232  ) const;
234  //- Get the points that define the surface.
235  virtual tmp<pointField> points() const;
236 
237  // Does any part of the surface overlap the supplied bound box?
238  virtual bool overlaps(const boundBox& bb) const;
239 
240  virtual void findNearest
241  (
242  const pointField& sample,
243  const scalarField& nearestDistSqr,
245  ) const;
246 
247  virtual void findNearest
248  (
249  const pointField& sample,
250  const scalarField& nearestDistSqr,
251  const labelList& regionIndices,
253  ) const;
254 
255  virtual void findLine
256  (
257  const pointField& start,
258  const pointField& end,
260  ) const;
261 
262  virtual void findLineAny
263  (
264  const pointField& start,
265  const pointField& end,
267  ) const;
268 
269  //- Get all intersections in order from start to end.
270  virtual void findLineAll
271  (
272  const pointField& start,
273  const pointField& end,
275  ) const;
276 
277  //- From a set of points and indices get the region
278  virtual void getRegion
279  (
280  const List<pointIndexHit>&,
281  labelList& region
282  ) const;
283 
284  //- From a set of points and indices get the normal
285  virtual void getNormal
286  (
287  const List<pointIndexHit>&,
288  vectorField& normal
289  ) const;
290 
291  //- Determine type (inside/outside/mixed) for point.
292  // Unknown if cannot be determined (e.g. non-manifold surface)
293  virtual void getVolumeType
294  (
295  const pointField& points,
296  List<volumeType>& volType
297  ) const;
298 
299 
300  // Other
301 
302  //- WIP. Store element-wise field.
303  virtual void setField(const labelList& values);
304 
305  //- WIP. From a set of hits (points and
306  // indices) get the specified field. Misses do not get set.
307  virtual void getField(const List<pointIndexHit>&, labelList&) const;
308 
309 
310  // regIOobject implementation
311 
312  bool writeData(Ostream&) const
313  {
315  return false;
316  }
317 
318  //- Write using stream options
319  virtual bool writeObject
320  (
321  IOstreamOption streamOpt,
322  const bool writeOnProc
323  ) const;
324 
325  //- Is object global
326  virtual bool global() const
327  {
328  return true;
329  }
330 
331  //- Return complete path + object name if the file exists
332  // either in the case/processor or case otherwise null
333  virtual fileName filePath() const
334  {
336  }
337 };
338 
339 
340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
341 
342 //- Global file type for triSurfaceMesh
343 template<>
344 struct is_globalIOobject<triSurfaceMesh> : std::true_type {};
345 
346 
347 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
348 
349 } // End namespace Foam
350 
351 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
352 
353 #endif
354 
355 // ************************************************************************* //
bool writeData(Ostream &) const
The writeData function is required by regIOobject but not used.
virtual void findLine(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Find first intersection on segment from start to end.
dictionary dict
virtual tmp< pointField > coordinates() const
Get representative set of element coordinates.
void clearOut()
Clear storage.
fileName globalFilePath(const word &typeName, const bool search=true) const
Redirect to fileHandler filePath, searching up if in parallel.
Definition: IOobject.C:547
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared). Any point.
virtual fileName filePath() const
Return complete path + object name if the file exists.
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.
virtual tmp< pointField > points() const
Get the points that define the surface.
virtual ~triSurfaceMesh()
Destructor.
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const
virtual void setField(const labelList &values)
WIP. Store element-wise field.
static bool addFaceToEdge(const edge &, EdgeMap< label > &)
Helper function for isSurfaceClosed.
virtual bool overlaps(const boundBox &bb) const
Does any part of the surface overlap the supplied bound box?
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
A simple container for options an IOstream can normally have.
An enumeration wrapper for classification of a location as being inside/outside of a volume...
Definition: volumeType.H:55
bool isSurfaceClosed() const
Check whether surface is closed without calculating any permanent.
iterator end() noexcept
iterator to signal the end (for any HashTable)
static word meshSubDir
Return the mesh sub-directory name (usually "triSurface")
IOoject and searching on triSurface.
virtual bool hasVolumeType() const
Whether supports volume type (below) - i.e. whether is closed.
virtual bool global() const
Is object global.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
virtual void flip()
Flip triangles, outsideVolumeType and all cached inside/outside.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:801
volumeType outsideVolType_
If surface is closed, what is type of outside points.
virtual void getVolumeType(const pointField &points, List< volumeType > &volType) const
Determine type (inside/outside/mixed) for point.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
Definition: edge.H:59
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const
Get all intersections in order from start to end.
autoPtr< indexedOctree< treeDataEdge > > edgeTree_
Search tree for boundary edges.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
void operator=(const triSurfaceMesh &)=delete
No copy assignment.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
label size() const noexcept
The number of elements in the container.
Definition: UList.H:702
const indexedOctree< treeDataEdge > & edgeTree() const
Demand driven construction of octree for boundary edges.
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
scalar minQuality_
Optional min triangle quality. Triangles below this get.
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
TypeName("triSurfaceMesh")
Runtime type information.
List< word > wordList
List of word.
Definition: fileName.H:59
Non-pointer based hierarchical recursive searching.
virtual label size() const
Range of local indices that can be returned.
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options.
label surfaceClosed_
Is surface closed.
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
virtual void movePoints(const pointField &)
Move points.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
virtual volumeType outsideVolumeType() const
If surface is closed, what is type of points outside bounds.
triSurfaceMesh(const triSurfaceMesh &)=delete
No copy construct.
Triangulated surface description with patch information.
Definition: triSurface.H:71
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:688
fileName fName_
Supplied fileName override.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
virtual const wordList & regions() const
Names of regions.
wordList regions_
Names of regions.
Namespace for OpenFOAM.
virtual void getField(const List< pointIndexHit > &, labelList &) const
WIP. From a set of hits (points and.