searchableSphere.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) 2018-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::searchableSphere
29 
30 Description
31  Searching on general spheroid.
32 
33  \heading Dictionary parameters
34  \table
35  Property | Description | Required | Default
36  type | sphere | selector |
37  origin | The origin (centre) of the sphere | yes |
38  radius | The (outside) radius/radiii of sphere | yes |
39  centre | Alternative name for 'origin' | no |
40  \endtable
41 
42 Note
43  The \c radius can be specified as a single \em scalar (for a sphere)
44  or a \em vector of three values (for a general spheroid).
45 
46  Longer type name : \c searchableSphere
47 
48 SourceFiles
49  searchableSphere.C
50 
51 \*---------------------------------------------------------------------------*/
52 
53 #ifndef searchableSphere_H
54 #define searchableSphere_H
55 
56 #include "treeBoundBox.H"
57 #include "searchableSurface.H"
58 
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 
61 namespace Foam
62 {
63 
64 /*---------------------------------------------------------------------------*\
65  Class searchableSphere Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 class searchableSphere
69 :
70  public searchableSurface
71 {
72 public:
73 
74  // Public Types
75 
76  //- The type of shape
77  enum shapeType : uint8_t
78  {
79  SPHERE = 0,
80  OBLATE = 1,
81  PROLATE = 2,
82  GENERAL = 3
83  };
84 
85 
86 private:
87 
88  // Private Types
89 
90  //- Component order (largest to smallest)
91  struct componentOrder
92  {
93  uint8_t major;
94  uint8_t mezzo;
95  uint8_t minor;
97  };
98 
99 
100  // Private Data
102  //- Centre point of the sphere
103  const point origin_;
105  //- The outer radii of the spheroid
106  const vector radii_;
107 
108  //- The canonical (sorted) order and shape
109  const struct componentOrder order_;
110 
111  //- Names of regions
112  mutable wordList regions_;
113 
114 
115  // Private Member Functions
116 
117  //- Determine sorted order and classify the shape
118  inline static componentOrder getOrdering(const vector& radii);
119 
120  //- Shift point relative to origin
121  //- and scale relative to spheroid dimensions
122  inline point scalePoint(const point& p) const
123  {
124  return point
125  (
126  (p.x() - origin_.x()) / radii_.x(),
127  (p.y() - origin_.y()) / radii_.y(),
128  (p.z() - origin_.z()) / radii_.z()
129  );
130  }
131 
132  //- Undo scalePoint(): unscale point and unshift relative to origin
133  inline point unscalePoint(const point& p) const
134  {
135  return point
136  (
137  p.x() * radii_.x() + origin_.x(),
138  p.y() * radii_.y() + origin_.y(),
139  p.z() * radii_.z() + origin_.z()
140  );
141  }
142 
143 
144  //- Inherit findNearest from searchableSurface
146 
147  //- Find nearest point on general spheroid.
148  // With some optimization for special shapes
149  pointIndexHit findNearest
150  (
151  const point& sample,
152  const scalar nearestDistSqr
153  ) const;
154 
155  //- Find intersection with general spheroid
156  void findLineAll
157  (
158  const point& start,
159  const point& end,
160  pointIndexHit& near,
161  pointIndexHit& far
162  ) const;
163 
164 
165  //- No copy construct
166  searchableSphere(const searchableSphere&) = delete;
167 
168  //- No copy assignment
169  void operator=(const searchableSphere&) = delete;
170 
171 
172 public:
173 
174  //- Runtime type information
175  TypeName("searchableSphere");
176 
177 
178  // Constructors
179 
180  //- Construct a sphere from components
181  searchableSphere
182  (
183  const IOobject& io,
184  const point& origin,
185  const scalar radius
186  );
187 
188  //- Construct a spheroid from components
189  searchableSphere
190  (
191  const IOobject& io,
192  const point& centre,
193  const vector& radii
194  );
195 
196  //- Construct from dictionary (used by searchableSurface)
197  searchableSphere
198  (
199  const IOobject& io,
200  const dictionary& dict
201  );
202 
203 
204  //- Destructor
205  virtual ~searchableSphere() = default;
206 
207 
208  // Member Functions
209 
210  // Geometric
211 
212  //- The centre (origin) of the sphere
213  const point& centre() const noexcept
214  {
215  return origin_;
216  }
217 
218  //- The radius of the sphere, or major radius of the spheroid
219  scalar radius() const noexcept
220  {
221  return radii_[order_.major];
222  }
223 
224  //- The radii of the spheroid
225  const vector& radii() const noexcept
226  {
227  return radii_;
228  }
229 
230  //- The type of shape
231  enum shapeType shape() const noexcept
232  {
233  return order_.shape;
234  }
235 
236  //- A point on the sphere at given location
237  // theta [-pi,pi], phi [0,pi]
238  point surfacePoint(const scalar theta, const scalar phi) const;
239 
240  //- Surface normal on the sphere at given location
241  // theta [-pi,pi], phi [0,pi]
242  vector surfaceNormal(const scalar theta, const scalar phi) const;
243 
244 
245 
246  // Searching
247 
248  //- Names of regions
249  virtual const wordList& regions() const;
250 
251  //- Whether supports volume type (below)
252  virtual bool hasVolumeType() const
253  {
254  return true;
255  }
256 
257  //- What is type of points outside bounds
258  virtual volumeType outsideVolumeType() const
259  {
260  return volumeType::OUTSIDE;
261  }
262 
263  //- Range of local indices that can be returned.
264  virtual label size() const
265  {
266  return 1;
267  }
268 
269  //- Get representative set of element coordinates
270  // Usually the element centres (should be of length size()).
271  virtual tmp<pointField> coordinates() const
272  {
273  return tmp<pointField>::New(1, origin_);
274  }
275 
276  //- Get bounding spheres (centre and radius squared), one per element.
277  // Any point on element is guaranteed to be inside.
278  virtual void boundingSpheres
279  (
280  pointField& centres,
281  scalarField& radiusSqr
282  ) const;
283 
284  //- Get the points that define the surface.
285  virtual tmp<pointField> points() const
286  {
287  return coordinates();
288  }
289 
290  //- Does any part of the surface overlap the supplied bound box?
291  virtual bool overlaps(const boundBox& bb) const;
292 
293 
294  // Multiple point queries.
295 
296  virtual void findNearest
297  (
298  const pointField& sample,
299  const scalarField& nearestDistSqr,
301  ) const;
302 
303  virtual void findLine
304  (
305  const pointField& start,
306  const pointField& end,
308  ) const;
309 
310  virtual void findLineAny
311  (
312  const pointField& start,
313  const pointField& end,
315  ) const;
316 
317  //- Get all intersections in order from start to end.
318  virtual void findLineAll
319  (
320  const pointField& start,
321  const pointField& end,
323  ) const;
324 
325  //- From a set of points and indices get the region
326  virtual void getRegion
327  (
328  const List<pointIndexHit>&,
329  labelList& region
330  ) const;
331 
332  //- From a set of points and indices get the normal
333  virtual void getNormal
334  (
335  const List<pointIndexHit>&,
336  vectorField& normal
337  ) const;
338 
339  //- Determine type (inside/outside/mixed) for point.
340  virtual void getVolumeType
341  (
342  const pointField& points,
343  List<volumeType>& volType
344  ) const;
346 
347  // Output
348 
349  // Implementation for regIOobject. NotImplemented
350  bool writeData(Ostream&) const
351  {
353  return false;
354  }
355 };
356 
357 
358 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
359 
360 } // End namespace Foam
361 
362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
363 
364 #endif
365 
366 // ************************************************************************* //
virtual volumeType outsideVolumeType() const
What is type of points outside bounds.
dictionary dict
virtual tmp< pointField > coordinates() const
Get representative set of element coordinates.
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
virtual tmp< pointField > points() const
Get the points that define the surface.
vector surfaceNormal(const scalar theta, const scalar phi) const
Surface normal on the sphere at given location.
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
Definition: pointIndexHit.H:58
virtual ~searchableSphere()=default
Destructor.
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
const vector & radii() const noexcept
The radii of the spheroid.
virtual void findLine(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Find first intersection on segment from start to end.
Oblate (major = mezzo > minor)
const point & centre() const noexcept
The centre (origin) of the sphere.
virtual bool overlaps(const boundBox &bb) const
Does any part of the surface overlap the supplied bound box?
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const =0
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
virtual void getVolumeType(const pointField &points, List< volumeType > &volType) const
Determine type (inside/outside/mixed) for point.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:206
point surfacePoint(const scalar theta, const scalar phi) const
A point on the sphere at given location.
Sphere (all components equal)
enum shapeType shape() const noexcept
The type of shape.
Vector< scalar > vector
Definition: vector.H:57
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
A location outside the volume.
Definition: volumeType.H:66
shapeType
The type of shape.
bool writeData(Ostream &) const
Pure virtual writeData function.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
scalar radius() const noexcept
The radius of the sphere, or major radius of the spheroid.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:201
TypeName("searchableSphere")
Runtime type information.
List< word > wordList
List of word.
Definition: fileName.H:59
virtual bool hasVolumeType() const
Whether supports volume type (below)
vector point
Point is a vector.
Definition: point.H:37
virtual const wordList & regions() const
Names of regions.
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared), one per element.
virtual label size() const
Range of local indices that can be returned.
volScalarField & p
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
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:686
Prolate (major > mezzo = minor)
Namespace for OpenFOAM.