searchableDisk.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2014-2015 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 \*---------------------------------------------------------------------------*/
25 
26 #include "searchableDisk.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 defineTypeNameAndDebug(searchableDisk, 0);
35 addToRunTimeSelectionTable(searchableSurface, searchableDisk, dict);
36 
37 }
38 
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
43 (
44  const point& sample,
45  const scalar nearestDistSqr
46 ) const
47 {
48  pointIndexHit info(false, sample, -1);
49 
50  vector v(sample - origin_);
51 
52  // Decompose sample-origin into normal and parallel component
53  scalar parallel = (v & normal_);
54 
55  // Remove the parallel component and normalise
56  v -= parallel*normal_;
57  scalar magV = mag(v);
58 
59  if (magV < ROOTVSMALL)
60  {
61  v = vector::zero;
62  }
63  else
64  {
65  v /= magV;
66  }
67 
68  // Clip to radius.
69  info.setPoint(origin_ + min(magV, radius_)*v);
70 
71  if (magSqr(sample - info.rawPoint()) < nearestDistSqr)
72  {
73  info.setHit();
74  info.setIndex(0);
75  }
76 
77  return info;
78 }
79 
80 
82 (
83  const point& start,
84  const point& end,
85  pointIndexHit& info
86 ) const
87 {
88  info = pointIndexHit(false, vector::zero, -1);
89 
90  vector v(start - origin_);
91 
92  // Decompose sample-origin into normal and parallel component
93  scalar parallel = (v & normal_);
94 
95  if (sign(parallel) == sign((end - origin_) & normal_))
96  {
97  return;
98  }
99 
100  // Remove the parallel component and normalise
101  v -= parallel*normal_;
102  scalar magV = mag(v);
103 
104  if (magV < ROOTVSMALL)
105  {
106  v = vector::zero;
107  }
108  else
109  {
110  v /= magV;
111  }
112 
113  // Set (hit or miss) to intersection of ray and plane of disk
114  info.setPoint(origin_ + magV*v);
115 
116  if (magV <= radius_)
117  {
118  info.setHit();
119  info.setIndex(0);
120  }
121 }
122 
123 
124 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
125 
127 (
128  const IOobject& io,
129  const point& origin,
130  const point& normal,
131  const scalar radius
132 )
133 :
134  searchableSurface(io),
135  origin_(origin),
136  normal_(normal/mag(normal)),
137  radius_(radius)
138 {
139  // Rough approximation of bounding box
140  //vector span(radius_, radius_, radius_);
141 
142  // See searchableCylinder
143  vector span
144  (
145  sqrt(sqr(normal_.y()) + sqr(normal_.z())),
146  sqrt(sqr(normal_.x()) + sqr(normal_.z())),
147  sqrt(sqr(normal_.x()) + sqr(normal_.y()))
148  );
149  span *= radius_;
150 
151  bounds().min() = origin_ - span;
152  bounds().max() = origin_ + span;
153 }
154 
155 
157 (
158  const IOobject& io,
159  const dictionary& dict
160 )
161 :
162  searchableSurface(io),
163  origin_(dict.lookup("origin")),
164  normal_(dict.lookup("normal")),
165  radius_(readScalar(dict.lookup("radius")))
166 {
167  normal_ /= mag(normal_);
168 
169  // Rough approximation of bounding box
170  //vector span(radius_, radius_, radius_);
171 
172  // See searchableCylinder
173  vector span
174  (
175  sqrt(sqr(normal_.y()) + sqr(normal_.z())),
176  sqrt(sqr(normal_.x()) + sqr(normal_.z())),
177  sqrt(sqr(normal_.x()) + sqr(normal_.y()))
178  );
179  span *= radius_;
180 
181  bounds().min() = origin_ - span;
182  bounds().max() = origin_ + span;
183 }
184 
185 
186 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
187 
189 {}
190 
191 
192 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
193 
195 {
196  if (regions_.empty())
197  {
198  regions_.setSize(1);
199  regions_[0] = "region0";
200  }
201  return regions_;
202 }
203 
204 
206 (
207  pointField& centres,
208  scalarField& radiusSqr
209 ) const
210 {
211  centres.setSize(1);
212  centres[0] = origin_;
213 
214  radiusSqr.setSize(1);
215  radiusSqr[0] = sqr(radius_);
216 
217  // Add a bit to make sure all points are tested inside
218  radiusSqr += Foam::sqr(SMALL);
219 }
220 
221 
223 (
224  const pointField& samples,
225  const scalarField& nearestDistSqr,
226  List<pointIndexHit>& info
227 ) const
228 {
229  info.setSize(samples.size());
230 
231  forAll(samples, i)
232  {
233  info[i] = findNearest(samples[i], nearestDistSqr[i]);
234  }
235 }
236 
237 
239 (
240  const pointField& start,
241  const pointField& end,
242  List<pointIndexHit>& info
243 ) const
244 {
245  info.setSize(start.size());
246 
247  forAll(start, i)
248  {
249  findLine(start[i], end[i], info[i]);
250  }
251 }
252 
253 
255 (
256  const pointField& start,
257  const pointField& end,
258  List<pointIndexHit>& info
259 ) const
260 {
261  findLine(start, end, info);
262 }
263 
264 
266 (
267  const pointField& start,
268  const pointField& end,
269  List<List<pointIndexHit> >& info
270 ) const
271 {
272  info.setSize(start.size());
273 
274  forAll(start, i)
275  {
276  pointIndexHit inter;
277  findLine(start[i], end[i], inter);
278 
279  if (inter.hit())
280  {
281  info[i].setSize(1);
282  info[i][0] = inter;
283  }
284  else
285  {
286  info[i].clear();
287  }
288  }
289 }
290 
291 
293 (
294  const List<pointIndexHit>& info,
295  labelList& region
296 ) const
297 {
298  region.setSize(info.size());
299  region = 0;
300 }
301 
302 
304 (
305  const List<pointIndexHit>& info,
307 ) const
308 {
309  normal.setSize(info.size());
310  normal = normal_;
311 }
312 
313 
315 (
316  const pointField& points,
317  List<volumeType>& volType
318 ) const
319 {
321  << "Volume type not supported for disk."
322  << exit(FatalError);
323 }
324 
325 
326 // ************************************************************************* //
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::Vector::min
static const Vector min
Definition: Vector.H:83
Foam::PointIndexHit::setIndex
void setIndex(const label index)
Definition: PointIndexHit.H:168
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::searchableDisk::searchableDisk
searchableDisk(const searchableDisk &)
Disallow default bitwise copy construct.
Foam::Vector::max
static const Vector max
Definition: Vector.H:82
Foam::searchableDisk::~searchableDisk
virtual ~searchableDisk()
Destructor.
Definition: searchableDisk.C:188
Foam::PointIndexHit::hit
bool hit() const
Is there a hit.
Definition: PointIndexHit.H:105
Foam::searchableDisk::regions
virtual const wordList & regions() const
Names of regions.
Definition: searchableDisk.C:194
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::sign
dimensionedScalar sign(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:179
samples
scalarField samples(nIntervals, 0)
Foam::searchableDisk::findNearest
pointIndexHit findNearest(const point &sample, const scalar nearestDistSqr) const
Find nearest point on disk.
Definition: searchableDisk.C:43
Foam::PointIndexHit
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:53
Foam::PointIndexHit::rawPoint
const Point & rawPoint() const
Return point with no checking.
Definition: PointIndexHit.H:143
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::searchableDisk::getVolumeType
virtual void getVolumeType(const pointField &, List< volumeType > &) const
Determine type (inside/outside/mixed) for point. unknown if.
Definition: searchableDisk.C:315
searchableDisk.H
Foam::searchableSurface
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
Definition: searchableSurface.H:66
Foam::PointIndexHit::setHit
void setHit()
Definition: PointIndexHit.H:153
Foam::searchableDisk::boundingSpheres
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared), one per element.
Definition: searchableDisk.C:206
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::searchableDisk::getNormal
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
Definition: searchableDisk.C:304
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::PointIndexHit::setPoint
void setPoint(const Point &p)
Definition: PointIndexHit.H:163
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
readScalar
#define readScalar
Definition: doubleScalar.C:38
Foam::searchableDisk::findLineAll
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit > > &) const
Get all intersections in order from start to end.
Definition: searchableDisk.C:266
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::searchableDisk::getRegion
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
Definition: searchableDisk.C:293
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::pointIndexHit
PointIndexHit< point > pointIndexHit
Definition: pointIndexHit.H:42
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:142
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::List::clear
void clear()
Clear the list, i.e. set size to zero.
Definition: List.C:379
Foam::searchableDisk::findLine
void findLine(const point &start, const point &end, pointIndexHit &) const
Find intersection with disk.
Definition: searchableDisk.C:82
Foam::searchableDisk::findLineAny
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
Definition: searchableDisk.C:255
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
normal
A normal distribution model.