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-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 \*---------------------------------------------------------------------------*/
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  // Clip to inner/outer radius
76  info.setPoint(origin() + radialLimits_.clip(magV)*v);
77 
78  if (magSqr(sample - info.rawPoint()) < nearestDistSqr)
79  {
80  info.setHit();
81  info.setIndex(0);
82  }
83 
84  return info;
85 }
86 
87 
88 void Foam::searchableDisk::findLine
89 (
90  const point& start,
91  const point& end,
92  pointIndexHit& info
93 ) const
94 {
95  info = pointIndexHit(false, Zero, -1);
96 
97  vector v(start - origin());
98 
99  // Decompose sample-origin into normal and parallel component
100  const scalar parallel = (v & normal());
101 
102  if (Foam::sign(parallel) == Foam::sign(plane::signedDistance(end)))
103  {
104  return;
105  }
106 
107  // Remove the parallel component and normalise
108  v -= parallel * normal();
109 
110  const scalar magV = mag(v);
111 
112  v.normalise();
113 
114  // Set (hit or miss) to intersection of ray and plane of disk
115  info.setPoint(origin() + magV*v);
116 
117  if (radialLimits_.contains(magV))
118  {
119  info.setHit();
120  info.setIndex(0);
121  }
122 }
123 
124 
125 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
126 
127 Foam::searchableDisk::searchableDisk
128 (
129  const IOobject& io,
130  const point& originPoint,
131  const vector& normalVector,
132  const scalar outerRadius,
133  const scalar innerRadius
134 )
135 :
136  searchableSurface(io),
137  plane(originPoint, normalVector),
138  radialLimits_(innerRadius, outerRadius)
139 {
140  // Rough approximation of bounding box
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 *= outerRadius;
150 
151  bounds().min() = origin() - span;
152  bounds().max() = origin() + span;
153 }
154 
155 
156 Foam::searchableDisk::searchableDisk
157 (
158  const IOobject& io,
159  const dictionary& dict
160 )
161 :
163  (
164  io,
165  dict.get<point>("origin"),
166  dict.get<vector>("normal"),
167  dict.get<scalar>("radius"),
168  dict.getOrDefault<scalar>("innerRadius", 0)
169  )
170 {}
171 
172 
173 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
174 
176 {
177  if (regions_.empty())
178  {
179  regions_.resize(1);
180  regions_.first() = "region0";
181  }
182  return regions_;
183 }
184 
185 
187 (
188  pointField& centres,
189  scalarField& radiusSqr
190 ) const
191 {
192  centres.resize(1);
193  radiusSqr.resize(1);
194 
195  centres[0] = origin();
196  radiusSqr[0] = sqr(radialLimits_.max());
197 
198  // Add a bit to make sure all points are tested inside
199  radiusSqr += Foam::sqr(SMALL);
200 }
201 
202 
203 void Foam::searchableDisk::findNearest
204 (
205  const pointField& samples,
206  const scalarField& nearestDistSqr,
207  List<pointIndexHit>& info
208 ) const
209 {
210  info.resize(samples.size());
211 
212  forAll(samples, i)
213  {
214  info[i] = findNearest(samples[i], nearestDistSqr[i]);
215  }
216 }
217 
218 
219 void Foam::searchableDisk::findLine
220 (
221  const pointField& start,
222  const pointField& end,
223  List<pointIndexHit>& info
224 ) const
225 {
226  info.resize(start.size());
227 
228  forAll(start, i)
229  {
230  findLine(start[i], end[i], info[i]);
231  }
232 }
233 
234 
236 (
237  const pointField& start,
238  const pointField& end,
239  List<pointIndexHit>& info
240 ) const
241 {
242  findLine(start, end, info);
243 }
244 
245 
247 (
248  const pointField& start,
249  const pointField& end,
251 ) const
252 {
253  info.setSize(start.size());
254 
255  forAll(start, i)
256  {
257  pointIndexHit inter;
258  findLine(start[i], end[i], inter);
259 
260  if (inter.hit())
261  {
262  info[i].setSize(1);
263  info[i][0] = inter;
264  }
265  else
266  {
267  info[i].clear();
268  }
269  }
270 }
271 
272 
274 (
275  const List<pointIndexHit>& info,
276  labelList& region
277 ) const
278 {
279  region.resize(info.size());
280  region = 0;
281 }
282 
283 
285 (
286  const List<pointIndexHit>& info,
287  vectorField& normals
288 ) const
289 {
290  normals.resize(info.size());
291  normals = normal();
292 }
293 
294 
296 (
297  const pointField& points,
298  List<volumeType>& volType
299 ) const
300 {
302  << "Volume type not supported for disk."
303  << exit(FatalError);
304 }
305 
306 
307 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
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:296
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::searchableDisk::regions
virtual const wordList & regions() const
Names of regions.
Definition: searchableDisk.C:175
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
Foam::sign
dimensionedScalar sign(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:166
Foam::IOobject::info
InfoProxy< IOobject > info() const
Return info proxy.
Definition: IOobject.H:689
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
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. Optionally it can be...
Definition: searchableDisk.H:97
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:52
Foam::PointIndexHit::hit
bool hit() const noexcept
Is there a hit?
Definition: PointIndexHit.H:130
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
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
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::MinMax::clip
const T & clip(const T &val) const
Definition: MinMaxI.H:223
Foam::searchableDisk::boundingSpheres
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared), one per element.
Definition: searchableDisk.C:187
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:123
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:121
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:274
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::pointIndexHit
PointIndexHit< point > pointIndexHit
A PointIndexHit for 3D points.
Definition: pointIndexHit.H:46
Foam::searchableDisk::findLine
virtual void findLine(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Find first intersection on segment from start to end.
Definition: searchableDisk.C:220
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)
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:285
Foam::List::clear
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
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:236
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:247
Foam::point
vector point
Point is a vector.
Definition: point.H:43
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:148
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
y
scalar y
Definition: LISASMDCalcMethod1.H:14
sample
Minimal example by using system/controlDict.functions: