searchableSurface.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::searchableSurface
26 
27 Description
28  Base class of (analytical or triangulated) surface.
29  Encapsulates all the search routines. WIP.
30 
31  Information returned is usually a pointIndexHit:
32  - bool : was intersection/nearest found?
33  - point : intersection point or nearest point
34  - index : unique index on surface (e.g. triangle for triSurfaceMesh)
35 
36 SourceFiles
37  searchableSurface.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef searchableSurface_H
42 #define searchableSurface_H
43 
44 #include "pointField.H"
45 #include "boundBox.H"
46 #include "typeInfo.H"
47 #include "runTimeSelectionTables.H"
48 #include "pointIndexHit.H"
49 #include "linePointRef.H"
50 #include "objectRegistry.H"
51 #include "volumeType.H"
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 namespace Foam
56 {
57 
58 // Forward declaration of classes
59 class objectRegistry;
60 class distributionMap;
61 class treeBoundBox;
62 
63 /*---------------------------------------------------------------------------*\
64  Class searchableSurface Declaration
65 \*---------------------------------------------------------------------------*/
66 
68 :
69  public regIOobject
70 {
71  // Private Data
72 
73  const word name_;
74 
75  boundBox bounds_;
76 
77 
78 public:
79 
80  //- Runtime type information
81  TypeName("searchableSurface");
82 
83 
84  // Static data
85 
86  //- Name of the directory for the geometry files
87  // Defaults to "geometry"
88  static word geometryDir_;
89 
90 
91  // Declare run-time constructor selection table
92 
93  // For the dictionary constructor
95  (
96  autoPtr,
98  dict,
99  (
100  const IOobject& io,
101  const dictionary& dict
102  ),
103  (io, dict)
104  );
105 
106 
107  //- Class used for the read-construction of
108  // PtrLists of searchableSurface.
109  class iNew
110  {
111  IOobject& io_;
112 
113  public:
115  iNew(IOobject& io)
116  :
117  io_(io)
118  {}
121  {
122  word surfaceType(is);
123  word readName(is);
124  dictionary dict(is);
125 
126  autoPtr<IOobject> namedIO(io_.clone());
127  namedIO().rename(readName);
128  return searchableSurface::New(surfaceType, namedIO(), dict);
129  }
130  };
131 
132 
133  // Constructors
134 
135  searchableSurface(const IOobject& io);
136 
137  //- Disallow default bitwise copy construction
138  searchableSurface(const searchableSurface&) = delete;
139 
140  //- Clone
141  virtual autoPtr<searchableSurface> clone() const
142  {
144  return autoPtr<searchableSurface>(nullptr);
145  }
146 
147 
148  // Selectors
149 
150  //- Return a reference to the selected searchableSurface
152  (
153  const word& surfaceType,
154  const IOobject& io,
155  const dictionary& dict
156  );
157 
158 
159  //- Destructor
160  virtual ~searchableSurface();
161 
162 
163  // Member Functions
164 
165  //- Return the geometry directory name
166  static const word& geometryDir();
167 
168  //- Check that the geometry directory exists and return
169  // if not return "triSurface" for backward compatibility
170  static const word& geometryDir(const Time& time);
171 
172  //- Return const reference to boundBox
173  const boundBox& bounds() const
174  {
175  return bounds_;
176  }
177 
178  //- Return non-const access to the boundBox to allow it to be set.
179  boundBox& bounds()
180  {
181  return bounds_;
182  }
183 
184  //- Names of regions
185  virtual const wordList& regions() const = 0;
186 
187  //- Whether supports volume type below
188  virtual bool hasVolumeType() const = 0;
189 
190  //- Range of local indices that can be returned
191  virtual label size() const = 0;
192 
193  //- Range of global indices that can be returned
194  virtual label globalSize() const
195  {
196  return size();
197  }
198 
199  //- Get representative set of element coordinates
200  // Usually the element centres (should be of length size()).
201  virtual tmp<pointField> coordinates() const = 0;
202 
203  //- Get bounding spheres (centre and radius squared), one per element.
204  // Any point on element is guaranteed to be inside.
205  virtual void boundingSpheres
206  (
207  pointField& centres,
208  scalarField& radiusSqr
209  ) const = 0;
210 
211  //- Get the points that define the surface.
212  virtual tmp<pointField> points() const = 0;
213 
214  //- Does any part of the surface overlap the supplied bound box?
215  virtual bool overlaps(const boundBox& bb) const = 0;
216 
217  // Single point queries.
218 
224  // virtual pointIndexHit findNearest
225  //(
226  // const point& sample,
227  // const scalar nearestDistSqr
228  //) const = 0;
229  //
235  // virtual pointIndexHit findNearestOnEdge
236  //(
237  // const point& sample,
238  // const scalar nearestDistSqr
239  //) const = 0;
240  //
249  // virtual pointIndexHit findNearest
250  //(
251  // const linePointRef& ln,
252  // treeBoundBox& tightest,
253  // point& linePoint
254  //) const = 0;
255  //
257  // virtual pointIndexHit findLine
258  //(
259  // const point& start,
260  // const point& end
261  //) const = 0;
262  //
264  // virtual pointIndexHit findLineAny
265  //(
266  // const point& start,
267  // const point& end
268  //) const = 0;
269 
270 
271  // Multiple point queries. When surface is distributed the index
272  // should be a global index. Not done yet.
273 
274  virtual void findNearest
275  (
276  const pointField& sample,
277  const scalarField& nearestDistSqr,
279  ) const = 0;
280 
281  //- Find the nearest locations for the supplied points to a
282  // particular region in the searchable surface.
283  virtual void findNearest
284  (
285  const pointField& samples,
286  const scalarField& nearestDistSqr,
287  const labelList& regionIndices,
289  ) const
290  {
291  findNearest(samples, nearestDistSqr, info);
292  }
293 
294  //- Find first intersection on segment from start to end.
295  // Note: searchableSurfacesQueries expects no
296  // intersection to be found if start==end. Is problem?
297  virtual void findLine
298  (
299  const pointField& start,
300  const pointField& end,
302  ) const = 0;
303 
304  //- Return any intersection on segment from start to end.
305  virtual void findLineAny
306  (
307  const pointField& start,
308  const pointField& end,
310  ) const = 0;
311 
312  //- Get all intersections in order from start to end.
313  virtual void findLineAll
314  (
315  const pointField& start,
316  const pointField& end,
318  ) const = 0;
319 
320  //- From a set of points and indices get the region
321  virtual void getRegion
322  (
323  const List<pointIndexHit>&,
324  labelList& region
325  ) const = 0;
326 
327  //- From a set of points and indices get the normal
328  virtual void getNormal
329  (
330  const List<pointIndexHit>&,
331  vectorField& normal
332  ) const = 0;
333 
334  //- Determine type (inside/outside) for point. unknown if
335  // cannot be determined (e.g. non-manifold surface)
336  virtual void getVolumeType
337  (
338  const pointField&,
340  ) const = 0;
341 
342  //- Find nearest, normal and region. Can be overridden with
343  // optimised implementation
344  virtual void findNearest
345  (
346  const pointField& sample,
347  const scalarField& nearestDistSqr,
349  vectorField& normal,
350  labelList& region
351  ) const;
352 
353 
354  // Other
355 
356  //- Set bounds of surface. Bounds currently set as list of
357  // bounding boxes. The bounds are hints to the surface as for
358  // the range of queries it can expect. faceMap/pointMap can be
359  // set if the surface has done any redistribution.
360  virtual void distribute
361  (
362  const List<treeBoundBox>&,
363  const bool keepNonLocal,
365  autoPtr<distributionMap>& pointMap
366  )
367  {}
368 
369  //- WIP. Store element-wise field.
370  virtual void setField(const labelList& values)
371  {}
372 
373  //- WIP. From a set of hits (points and
374  // indices) get the specified field. Misses do not get set. Return
375  // empty field if not supported.
376  virtual void getField(const List<pointIndexHit>&, labelList& values)
377  const
378  {
379  values.clear();
380  }
381 
382 
383  // Member Operators
384 
385  //- Disallow default bitwise assignment
386  void operator=(const searchableSurface&) = delete;
387 };
388 
389 
390 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391 
392 } // End namespace Foam
393 
394 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
395 
396 #endif
397 
398 // ************************************************************************* //
dictionary dict
autoPtr< IOobject > clone() const
Clone.
Definition: IOobject.H:288
virtual const wordList & regions() const =0
Names of regions.
virtual tmp< pointField > coordinates() const =0
Get representative set of element coordinates.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
TypeName("searchableSurface")
Runtime type information.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
declareRunTimeSelectionTable(autoPtr, searchableSurface, dict,(const IOobject &io, const dictionary &dict),(io, dict))
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:58
Base class of (analytical or triangulated) surface. Encapsulates all the search routines. WIP.
Class used for the read-construction of.
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const =0
Return any intersection on segment from start to end.
static word geometryDir_
Name of the directory for the geometry files.
virtual void getField(const List< pointIndexHit > &, labelList &values) const
WIP. From a set of hits (points and.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
scalarField samples(nIntervals, 0)
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const =0
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const =0
Get all intersections in order from start to end.
static const word & geometryDir()
Return the geometry directory name.
A class for handling words, derived from string.
Definition: word.H:59
virtual bool overlaps(const boundBox &bb) const =0
Does any part of the surface overlap the supplied bound box?
void operator=(const searchableSurface &)=delete
Disallow default bitwise assignment.
virtual label globalSize() const
Range of global indices that can be returned.
searchableSurface(const IOobject &io)
virtual autoPtr< searchableSurface > clone() const
Clone.
virtual tmp< pointField > points() const =0
Get the points that define the surface.
virtual ~searchableSurface()
Destructor.
virtual void distribute(const List< treeBoundBox > &, const bool keepNonLocal, autoPtr< distributionMap > &faceMap, autoPtr< distributionMap > &pointMap)
Set bounds of surface. Bounds currently set as list of.
static autoPtr< searchableSurface > New(const word &surfaceType, const IOobject &io, const dictionary &dict)
Return a reference to the selected searchableSurface.
virtual void getVolumeType(const pointField &, List< volumeType > &) const =0
Determine type (inside/outside) for point. unknown if.
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const =0
From a set of points and indices get the region.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:52
const boundBox & bounds() const
Return const reference to boundBox.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Macros to ease declaration of run-time selection tables.
virtual label size() const =0
Range of local indices that can be returned.
InfoProxy< IOobject > info() const
Return info proxy.
Definition: IOobject.H:495
A class for managing temporary objects.
Definition: PtrList.H:53
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:353
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
virtual void setField(const labelList &values)
WIP. Store element-wise field.
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const =0
From a set of points and indices get the normal.
autoPtr< searchableSurface > operator()(Istream &is) const
virtual void findLine(const pointField &start, const pointField &end, List< pointIndexHit > &) const =0
Find first intersection on segment from start to end.
virtual bool hasVolumeType() const =0
Whether supports volume type below.
Namespace for OpenFOAM.
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const =0
Get bounding spheres (centre and radius squared), one per element.