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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2014-2017 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 \*---------------------------------------------------------------------------*/
28 
29 #include "searchableDisk.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(searchableDisk, 0);
38  (
39  searchableSurface,
40  searchableDisk,
41  dict
42  );
44  (
45  searchableSurface,
46  searchableDisk,
47  dict,
48  disk
49  );
50 }
51 
52 
53 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
54 
55 Foam::pointIndexHit Foam::searchableDisk::findNearest
56 (
57  const point& sample,
58  const scalar nearestDistSqr
59 ) const
60 {
61  pointIndexHit info(false, sample, -1);
62 
63  vector v(sample - origin());
64 
65  // Decompose sample-origin into normal and parallel component
66  const scalar parallel = (v & normal());
67 
68  // Remove the parallel component and normalise
69  v -= parallel * normal();
70 
71  const scalar magV = mag(v);
72 
73  v.normalise();
74 
75 
76  // Clip to radius.
77  info.setPoint(origin() + min(magV, radius_)*v);
78 
79  if (magSqr(sample - info.rawPoint()) < nearestDistSqr)
80  {
81  info.setHit();
82  info.setIndex(0);
83  }
84 
85  return info;
86 }
87 
88 
89 void Foam::searchableDisk::findLine
90 (
91  const point& start,
92  const point& end,
93  pointIndexHit& info
94 ) const
95 {
96  info = pointIndexHit(false, Zero, -1);
97 
98  vector v(start - origin());
99 
100  // Decompose sample-origin into normal and parallel component
101  const scalar parallel = (v & normal());
102 
103  if (Foam::sign(parallel) == Foam::sign(plane::signedDistance(end)))
104  {
105  return;
106  }
107 
108  // Remove the parallel component and normalise
109  v -= parallel * normal();
110 
111  const scalar magV = mag(v);
112 
113  v.normalise();
114 
115 
116  // Set (hit or miss) to intersection of ray and plane of disk
117  info.setPoint(origin() + magV*v);
118 
119  if (magV <= radius_)
120  {
121  info.setHit();
122  info.setIndex(0);
123  }
124 }
125 
126 
127 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
128 
129 Foam::searchableDisk::searchableDisk
130 (
131  const IOobject& io,
132  const point& originPoint,
133  const vector& normalVector,
134  const scalar radius
135 )
136 :
137  searchableSurface(io),
138  plane(originPoint, normalVector),
139  radius_(radius)
140 {
141  // Rough approximation of bounding box
142  // vector span(radius_, radius_, radius_);
143 
144  // See searchableCylinder
145  vector span
146  (
147  sqrt(sqr(normal().y()) + sqr(normal().z())),
148  sqrt(sqr(normal().x()) + sqr(normal().z())),
149  sqrt(sqr(normal().x()) + sqr(normal().y()))
150  );
151  span *= radius_;
152 
153  bounds().min() = origin() - span;
154  bounds().max() = origin() + span;
155 }
156 
157 
158 Foam::searchableDisk::searchableDisk
159 (
160  const IOobject& io,
161  const dictionary& dict
162 )
163 :
165  (
166  io,
167  dict.get<point>("origin"),
168  dict.get<vector>("normal"),
169  dict.get<scalar>("radius")
170  )
171 {}
172 
173 
174 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
175 
177 {
178  if (regions_.empty())
179  {
180  regions_.setSize(1);
181  regions_[0] = "region0";
182  }
183  return regions_;
184 }
185 
186 
188 (
189  pointField& centres,
190  scalarField& radiusSqr
191 ) const
192 {
193  centres.setSize(1);
194  centres[0] = origin();
195 
196  radiusSqr.setSize(1);
197  radiusSqr[0] = sqr(radius_);
198 
199  // Add a bit to make sure all points are tested inside
200  radiusSqr += Foam::sqr(SMALL);
201 }
202 
203 
204 void Foam::searchableDisk::findNearest
205 (
206  const pointField& samples,
207  const scalarField& nearestDistSqr,
208  List<pointIndexHit>& info
209 ) const
210 {
211  info.setSize(samples.size());
212 
213  forAll(samples, i)
214  {
215  info[i] = findNearest(samples[i], nearestDistSqr[i]);
216  }
217 }
218 
219 
220 void Foam::searchableDisk::findLine
221 (
222  const pointField& start,
223  const pointField& end,
224  List<pointIndexHit>& info
225 ) const
226 {
227  info.setSize(start.size());
228 
229  forAll(start, i)
230  {
231  findLine(start[i], end[i], info[i]);
232  }
233 }
234 
235 
237 (
238  const pointField& start,
239  const pointField& end,
240  List<pointIndexHit>& info
241 ) const
242 {
243  findLine(start, end, info);
244 }
245 
246 
248 (
249  const pointField& start,
250  const pointField& end,
252 ) const
253 {
254  info.setSize(start.size());
255 
256  forAll(start, i)
257  {
258  pointIndexHit inter;
259  findLine(start[i], end[i], inter);
260 
261  if (inter.hit())
262  {
263  info[i].setSize(1);
264  info[i][0] = inter;
265  }
266  else
267  {
268  info[i].clear();
269  }
270  }
271 }
272 
273 
275 (
276  const List<pointIndexHit>& info,
277  labelList& region
278 ) const
279 {
280  region.resize(info.size());
281  region = 0;
282 }
283 
284 
286 (
287  const List<pointIndexHit>& info,
288  vectorField& normals
289 ) const
290 {
291  normals.resize(info.size());
292  normals = normal();
293 }
294 
295 
297 (
298  const pointField& points,
299  List<volumeType>& volType
300 ) const
301 {
303  << "Volume type not supported for disk."
304  << exit(FatalError);
305 }
306 
307 
308 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::plane::normal
const vector & normal() const
The plane unit normal.
Definition: planeI.H:39
Foam::searchableDisk::getVolumeType
virtual void getVolumeType(const pointField &points, List< volumeType > &volType) const
Determine type (inside/outside/mixed) for point.
Definition: searchableDisk.C:297
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::PointIndexHit::hit
bool hit() const
Is there a hit.
Definition: PointIndexHit.H:107
Foam::searchableDisk::regions
virtual const wordList & regions() const
Names of regions.
Definition: searchableDisk.C:176
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:81
Foam::sign
dimensionedScalar sign(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:166
Foam::IOobject::info
InfoProxy< IOobject > info() const
Return info proxy.
Definition: IOobject.H:519
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::plane
Geometric class that creates a 3D plane and can return the intersection point between a line and the ...
Definition: plane.H:89
Foam::searchableDisk
Searching on circular disk given as origin, normal (gets normalised) and radius.
Definition: searchableDisk.H:87
Foam::VectorSpace::min
static const Form min
Definition: VectorSpace.H:118
Foam::PointIndexHit
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:55
Foam::Field< vector >
Foam::plane::signedDistance
scalar signedDistance(const point &p) const
Return distance from the given point to the plane.
Definition: planeI.H:81
searchableDisk.H
Foam::searchableSurface
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
Definition: searchableSurface.H:69
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
samples
scalarField samples(nIntervals, Zero)
Foam::List::resize
void resize(const label newSize)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::searchableDisk::boundingSpheres
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared), one per element.
Definition: searchableDisk.C:188
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:115
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::plane::origin
const point & origin() const
The plane base point.
Definition: planeI.H:45
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:275
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::pointIndexHit
PointIndexHit< point > pointIndexHit
Definition: pointIndexHit.H:45
Foam::VectorSpace::max
static const Form max
Definition: VectorSpace.H:117
Foam::Vector< scalar >
Foam::List< word >
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::start
label ListType::const_reference const label start
Definition: ListOps.H:408
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::searchableDisk::getNormal
virtual void getNormal(const List< pointIndexHit > &, vectorField &normals) const
From a set of points and indices get the normal.
Definition: searchableDisk.C:286
Foam::List::clear
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:115
x
x
Definition: LISASMDCalcMethod2.H:52
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:237
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:248
Foam::point
vector point
Point is a vector.
Definition: point.H:43
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
y
scalar y
Definition: LISASMDCalcMethod1.H:14