searchableSurface.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) 2018 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::searchableSurface
29 
30 Description
31  Base class of (analytical or triangulated) surface.
32  Encapsulates all the search routines. WIP.
33 
34  Information returned is usually a pointIndexHit:
35  - bool : was intersection/nearest found?
36  - point : intersection point or nearest point
37  - index : unique index on surface (e.g. triangle for triSurfaceMesh)
38 
39 SourceFiles
40  searchableSurface.C
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef searchableSurface_H
45 #define searchableSurface_H
46 
47 #include "pointField.H"
48 #include "boundBox.H"
49 #include "typeInfo.H"
50 #include "runTimeSelectionTables.H"
51 #include "pointIndexHit.H"
52 #include "linePointRef.H"
53 #include "objectRegistry.H"
54 #include "volumeType.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 // Forward declarations
62 class objectRegistry;
63 class mapDistribute;
64 class treeBoundBox;
65 
66 /*---------------------------------------------------------------------------*\
67  Class searchableSurface Declaration
68 \*---------------------------------------------------------------------------*/
69 
71 :
72  public regIOobject
73 {
74  // Private data
75 
76  const word name_;
77 
78  boundBox bounds_;
79 
80 
81  // Private Member Functions
82 
83  //- No copy construct
84  searchableSurface(const searchableSurface&) = delete;
85 
86  //- No copy assignment
87  void operator=(const searchableSurface&) = delete;
88 
89 
90 public:
91 
92  //- Runtime type information
93  TypeName("searchableSurface");
94 
95  // Declare run-time constructor selection table
96 
97  // For the dictionary constructor
99  (
100  autoPtr,
102  dict,
103  (
104  const IOobject& io,
105  const dictionary& dict
106  ),
107  (io, dict)
108  );
109 
110 
111  //- Class used for the read-construction of
112  // PtrLists of searchableSurface.
113  class iNew
114  {
115  IOobject& io_;
116 
117  public:
118 
119  iNew(IOobject& io)
120  :
121  io_(io)
122  {}
123 
125  {
126  word surfaceType(is);
127  word readName(is);
128  dictionary dict(is);
129 
130  autoPtr<IOobject> namedIO(io_.clone());
131  namedIO().rename(readName);
132  return searchableSurface::New(surfaceType, namedIO(), dict);
133  }
134  };
135 
136 
137  // Constructors
138 
139  searchableSurface(const IOobject& io);
140 
141  //- Clone
142  virtual autoPtr<searchableSurface> clone() const
143  {
145  return nullptr;
146  }
147 
148 
149  // Selectors
150 
151  //- Return a reference to the selected searchableSurface
153  (
154  const word& surfaceType,
155  const IOobject& io,
156  const dictionary& dict
157  );
158 
159 
160  //- Destructor
161  virtual ~searchableSurface() = default;
162 
163 
164  // Member Functions
165 
166  //- Is object global
167  virtual bool global() const
168  {
169  return true;
170  }
171 
172  //- Return complete path + object name if the file exists
173  // either in the case/processor or case otherwise null
174  virtual fileName filePath() const
175  {
176  return globalFilePath(type());
177  }
178 
179  //- Return const reference to boundBox
180  virtual const boundBox& bounds() const
181  {
182  return bounds_;
183  }
184 
185  //- Return non-const access to the boundBox to allow it to be set.
186  virtual boundBox& bounds()
187  {
188  return bounds_;
189  }
190 
191  //- Names of regions
192  virtual const wordList& regions() const = 0;
193 
194  //- Whether supports volume type (below).
195  // This is false for the base class.
196  virtual bool hasVolumeType() const;
197 
198  //- If surface supports volume queries, what is type of points outside
199  // bounds
200  virtual volumeType outsideVolumeType() const = 0;
201 
202  //- Range of local indices that can be returned
203  virtual label size() const = 0;
204 
205  //- Range of global indices that can be returned
206  virtual label globalSize() const
207  {
208  return size();
209  }
210 
211  //- Get representative set of element coordinates
212  // Usually the element centres (should be of length size()).
213  virtual tmp<pointField> coordinates() const = 0;
214 
215  //- Get bounding spheres (centre and radius squared), one per element.
216  // Any point on element is guaranteed to be inside.
217  virtual void boundingSpheres
218  (
219  pointField& centres,
220  scalarField& radiusSqr
221  ) const = 0;
222 
223  //- Get the points that define the surface.
224  virtual tmp<pointField> points() const = 0;
225 
226  //- Does any part of the surface overlap the supplied bound box?
227  virtual bool overlaps(const boundBox& bb) const = 0;
228 
229  // Single point queries.
230 
236  //virtual pointIndexHit findNearest
237  //(
238  // const point& sample,
239  // const scalar nearestDistSqr
240  //) const = 0;
241  //
247  //virtual pointIndexHit findNearestOnEdge
248  //(
249  // const point& sample,
250  // const scalar nearestDistSqr
251  //) const = 0;
252  //
261  //virtual pointIndexHit findNearest
262  //(
263  // const linePointRef& ln,
264  // treeBoundBox& tightest,
265  // point& linePoint
266  //) const = 0;
267  //
269  //virtual pointIndexHit findLine
270  //(
271  // const point& start,
272  // const point& end
273  //) const = 0;
274  //
276  //virtual pointIndexHit findLineAny
277  //(
278  // const point& start,
279  // const point& end
280  //) const = 0;
281 
282 
283  // Multiple point queries. When surface is distributed the index
284  // should be a global index. Not done yet.
285 
286  virtual void findNearest
287  (
288  const pointField& sample,
289  const scalarField& nearestDistSqr,
291  ) const = 0;
292 
293  //- Find the nearest locations for the supplied points to a
294  // particular region in the searchable surface.
295  virtual void findNearest
296  (
297  const pointField& samples,
298  const scalarField& nearestDistSqr,
299  const labelList& regionIndices,
301  ) const
302  {
303  findNearest(samples, nearestDistSqr, info);
304  }
305 
306  //- Find first intersection on segment from start to end.
307  // Note: searchableSurfacesQueries expects no
308  // intersection to be found if start==end. Is problem?
309  virtual void findLine
310  (
311  const pointField& start,
312  const pointField& end,
314  ) const = 0;
315 
316  //- Return any intersection on segment from start to end.
317  virtual void findLineAny
318  (
319  const pointField& start,
320  const pointField& end,
322  ) const = 0;
323 
324  //- Get all intersections in order from start to end.
325  virtual void findLineAll
326  (
327  const pointField& start,
328  const pointField& end,
330  ) const = 0;
331 
332  //- From a set of points and indices get the region
333  virtual void getRegion
334  (
335  const List<pointIndexHit>&,
336  labelList& region
337  ) const = 0;
338 
339  //- From a set of points and indices get the normal
340  virtual void getNormal
341  (
342  const List<pointIndexHit>&,
343  vectorField& normal
344  ) const = 0;
345 
346  //- Determine type (inside/outside) for point.
347  // Unknown if cannot be determined (e.g. non-manifold surface)
348  virtual void getVolumeType
349  (
350  const pointField&,
352  ) const = 0;
353 
354  //- Find nearest, normal and region. Can be overridden with
355  // optimised implementation
356  virtual void findNearest
357  (
358  const pointField& sample,
359  const scalarField& nearestDistSqr,
361  vectorField& normal,
362  labelList& region
363  ) const;
364 
365 
366  // Other
367 
368  //- Set bounds of surface. Bounds currently set as list of
369  // bounding boxes. The bounds are hints to the surface as for
370  // the range of queries it can expect. faceMap/pointMap can be
371  // set if the surface has done any redistribution.
372  virtual void distribute
373  (
374  const List<treeBoundBox>&,
375  const bool keepNonLocal,
377  autoPtr<mapDistribute>& pointMap
378  )
379  {}
380 
381  //- WIP. Store element-wise field.
382  virtual void setField(const labelList& values)
383  {}
384 
385  //- WIP. From a set of hits (points and
386  // indices) get the specified field. Misses do not get set. Return
387  // empty field if not supported.
388  virtual void getField(const List<pointIndexHit>&, labelList& values)
389  const
390  {
391  values.clear();
392  }
393 };
394 
395 
396 //- Template function for obtaining global status
397 template<>
398 inline bool typeGlobal<searchableSurface>()
399 {
400  return true;
401 }
402 
403 
404 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
405 
406 } // End namespace Foam
407 
408 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
409 
410 #endif
411 
412 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::searchableSurface::iNew
Class used for the read-construction of.
Definition: searchableSurface.H:112
Foam::searchableSurface::findLineAll
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const =0
Get all intersections in order from start to end.
pointIndexHit.H
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeTopological.C:94
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
typeInfo.H
Foam::searchableSurface::getNormal
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const =0
From a set of points and indices get the normal.
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::searchableSurface::coordinates
virtual tmp< pointField > coordinates() const =0
Get representative set of element coordinates.
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::searchableSurface::globalSize
virtual label globalSize() const
Range of global indices that can be returned.
Definition: searchableSurface.H:205
objectRegistry.H
Foam::searchableSurface::clone
virtual autoPtr< searchableSurface > clone() const
Clone.
Definition: searchableSurface.H:141
Foam::searchableSurface::size
virtual label size() const =0
Range of local indices that can be returned.
Foam::searchableSurface::global
virtual bool global() const
Is object global.
Definition: searchableSurface.H:166
Foam::searchableSurface::filePath
virtual fileName filePath() const
Return complete path + object name if the file exists.
Definition: searchableSurface.H:173
Foam::IOobject::info
InfoProxy< IOobject > info() const
Return info proxy.
Definition: IOobject.H:689
Foam::searchableSurface::getRegion
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const =0
From a set of points and indices get the region.
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
volumeType.H
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::searchableSurface::regions
virtual const wordList & regions() const =0
Names of regions.
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::searchableSurface::points
virtual tmp< pointField > points() const =0
Get the points that define the surface.
Foam::searchableSurface::overlaps
virtual bool overlaps(const boundBox &bb) const =0
Does any part of the surface overlap the supplied bound box?
Foam::searchableSurface::findLineAny
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const =0
Return any intersection on segment from start to end.
Foam::searchableSurface::iNew::iNew
iNew(IOobject &io)
Definition: searchableSurface.H:118
Foam::searchableSurface
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
Definition: searchableSurface.H:69
Foam::typeGlobal< searchableSurface >
bool typeGlobal< searchableSurface >()
Template function for obtaining global status.
Definition: searchableSurface.H:397
samples
scalarField samples(nIntervals, Zero)
Foam::IOobject::clone
autoPtr< IOobject > clone() const
Clone.
Definition: IOobject.H:468
Foam::searchableSurface::iNew::operator()
autoPtr< searchableSurface > operator()(Istream &is) const
Definition: searchableSurface.H:123
Foam::searchableSurface::TypeName
TypeName("searchableSurface")
Runtime type information.
dict
dictionary dict
Definition: searchingEngine.H:14
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
Foam::searchableSurface::hasVolumeType
virtual bool hasVolumeType() const
Whether supports volume type (below).
Definition: searchableSurface.C:76
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam::searchableSurface::outsideVolumeType
virtual volumeType outsideVolumeType() const =0
If surface supports volume queries, what is type of points outside.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::searchableSurface::findNearest
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const =0
Foam::searchableSurface::New
static autoPtr< searchableSurface > New(const word &surfaceType, const IOobject &io, const dictionary &dict)
Return a reference to the selected searchableSurface.
Definition: searchableSurface.C:43
pointField.H
boundBox.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::searchableSurface::setField
virtual void setField(const labelList &values)
WIP. Store element-wise field.
Definition: searchableSurface.H:381
Foam::searchableSurface::~searchableSurface
virtual ~searchableSurface()=default
Destructor.
Foam::List< word >
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::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::searchableSurface::boundingSpheres
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const =0
Get bounding spheres (centre and radius squared), one per element.
Foam::searchableSurface::bounds
virtual boundBox & bounds()
Return non-const access to the boundBox to allow it to be set.
Definition: searchableSurface.H:185
Foam::searchableSurface::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, searchableSurface, dict,(const IOobject &io, const dictionary &dict),(io, dict))
Foam::searchableSurface::bounds
virtual const boundBox & bounds() const
Return const reference to boundBox.
Definition: searchableSurface.H:179
Foam::searchableSurface::findLine
virtual void findLine(const pointField &start, const pointField &end, List< pointIndexHit > &) const =0
Find first intersection on segment from start to end.
Foam::searchableSurface::distribute
virtual void distribute(const List< treeBoundBox > &, const bool keepNonLocal, autoPtr< mapDistribute > &faceMap, autoPtr< mapDistribute > &pointMap)
Set bounds of surface. Bounds currently set as list of.
Definition: searchableSurface.H:372
Foam::searchableSurface::getField
virtual void getField(const List< pointIndexHit > &, labelList &values) const
WIP. From a set of hits (points and.
Definition: searchableSurface.H:387
Foam::searchableSurface::getVolumeType
virtual void getVolumeType(const pointField &, List< volumeType > &) const =0
Determine type (inside/outside) for point.
sample
Minimal example by using system/controlDict.functions:
linePointRef.H