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-2022 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_.clamp(magV)*v);
77 
78  if (info.point().distSqr(sample) < 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;
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());
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 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
dimensionedScalar sign(const dimensionedScalar &ds)
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared), one per element.
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
scalar signedDistance(const point &p) const
Return distance from the given point to the plane.
Definition: planeI.H:68
dimensionedSymmTensor sqr(const dimensionedVector &dv)
scalarField samples(nIntervals, Zero)
dimensionedScalar sqrt(const dimensionedScalar &ds)
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
Definition: pointIndexHit.H:58
virtual void getNormal(const List< pointIndexHit > &, vectorField &normals) const
From a set of points and indices get the normal.
This class describes the interaction of an object (often a face) and a point. It carries the info of ...
Definition: pointIndexHit.H:44
const point & min() const noexcept
Minimum describing the bounding box.
Definition: boundBoxI.H:162
virtual const boundBox & bounds() const
Return const reference to boundBox.
Macros for easy insertion into run-time selection tables.
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
scalar y
const point & max() const noexcept
Maximum describing the bounding box.
Definition: boundBoxI.H:168
const point & origin() const noexcept
The plane base point.
Definition: planeI.H:38
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
T clamp(const T &val) const
Return value clamped component-wise.
Definition: MinMaxI.H:238
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const
Get all intersections in order from start to end.
const pointField & points
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
Vector< scalar > vector
Definition: vector.H:57
InfoProxy< IOobject > info() const noexcept
Return info proxy, for printing information to a stream.
Definition: IOobject.H:955
virtual void getVolumeType(const pointField &points, List< volumeType > &volType) const
Determine type (inside/outside/mixed) for point.
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
defineTypeNameAndDebug(combustionModel, 0)
virtual const wordList & regions() const
Names of regions.
bool hit() const noexcept
Is there a hit?
vector point
Point is a vector.
Definition: point.H:37
Searching on circular disk given as origin, normal (gets normalised) and radius. Optionally it can be...
List< label > labelList
A List of labels.
Definition: List.H:62
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
const vector & normal() const noexcept
The plane unit normal.
Definition: planeI.H:32
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127