disk_searchableSurface.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2014-2025 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 "disk_searchableSurface.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  namespace searchableSurfaces
34  {
36 
38  (
40  disk,
42  );
43 
45  (
47  disk,
48  dictionary,
49  searchableDisk,
50  "searchableDisk"
51  );
52  }
53 }
54 
55 
56 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
57 
58 Foam::pointIndexHit Foam::searchableSurfaces::disk::findNearest
59 (
60  const point& sample,
61  const scalar nearestDistSqr
62 ) const
63 {
64  pointIndexHit info(false, sample, -1);
65 
66  vector v(sample - origin_);
67 
68  // Decompose sample-origin into normal and parallel component
69  scalar parallel = (v & normal_);
70 
71  // Remove the parallel component and normalise
72  v -= parallel*normal_;
73  scalar magV = mag(v);
74 
75  if (magV < rootVSmall)
76  {
77  v = Zero;
78  }
79  else
80  {
81  v /= magV;
82  }
83 
84  // Clip to radius.
85  info.setPoint(origin_ + min(magV, radius_)*v);
86 
87  if (magSqr(sample - info.rawPoint()) < nearestDistSqr)
88  {
89  info.setHit();
90  info.setIndex(0);
91  }
92 
93  return info;
94 }
95 
96 
97 void Foam::searchableSurfaces::disk::findLine
98 (
99  const point& start,
100  const point& end,
101  pointIndexHit& info
102 ) const
103 {
104  info = pointIndexHit(false, Zero, -1);
105 
106  vector v(start - origin_);
107 
108  // Decompose sample-origin into normal and parallel component
109  scalar parallel = (v & normal_);
110 
111  if (sign(parallel) == sign((end - origin_) & normal_))
112  {
113  return;
114  }
115 
116  // Remove the parallel component and normalise
117  v -= parallel*normal_;
118  scalar magV = mag(v);
119 
120  if (magV < rootVSmall)
121  {
122  v = Zero;
123  }
124  else
125  {
126  v /= magV;
127  }
128 
129  // Set (hit or miss) to intersection of ray and plane of disk
130  info.setPoint(origin_ + magV*v);
131 
132  if (magV <= radius_)
133  {
134  info.setHit();
135  info.setIndex(0);
136  }
137 }
138 
139 
140 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
141 
143 (
144  const IOobject& io,
145  const point& origin,
146  const point& normal,
147  const scalar radius
148 )
149 :
150  searchableSurface(io),
151  origin_(origin),
152  normal_(normal/mag(normal)),
153  radius_(radius)
154 {
155  // Rough approximation of bounding box
156  // vector span(radius_, radius_, radius_);
157 
158  // See cylinder
159  vector span
160  (
161  sqrt(sqr(normal_.y()) + sqr(normal_.z())),
162  sqrt(sqr(normal_.x()) + sqr(normal_.z())),
163  sqrt(sqr(normal_.x()) + sqr(normal_.y()))
164  );
165  span *= radius_;
166 
167  bounds().min() = origin_ - span;
168  bounds().max() = origin_ + span;
169 }
170 
171 
173 (
174  const IOobject& io,
175  const dictionary& dict
176 )
177 :
178  searchableSurface(io),
179  origin_(dict.lookup<point>("origin", dimLength)),
180  normal_(dict.lookup<vector>("normal", dimless)),
181  radius_(dict.lookup<scalar>("radius", dimLength))
182 {
183  normal_ /= mag(normal_);
184 
185  // Rough approximation of bounding box
186  // vector span(radius_, radius_, radius_);
187 
188  // See cylinder
189  vector span
190  (
191  sqrt(sqr(normal_.y()) + sqr(normal_.z())),
192  sqrt(sqr(normal_.x()) + sqr(normal_.z())),
193  sqrt(sqr(normal_.x()) + sqr(normal_.y()))
194  );
195  span *= radius_;
196 
197  bounds().min() = origin_ - span;
198  bounds().max() = origin_ + span;
199 }
200 
201 
202 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
203 
205 {}
206 
207 
208 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
209 
211 {
212  if (regions_.empty())
213  {
214  regions_.setSize(1);
215  regions_[0] = "region0";
216  }
217  return regions_;
218 }
219 
220 
222 (
223  pointField& centres,
224  scalarField& radiusSqr
225 ) const
226 {
227  centres.setSize(1);
228  centres[0] = origin_;
229 
230  radiusSqr.setSize(1);
231  radiusSqr[0] = sqr(radius_);
232 
233  // Add a bit to make sure all points are tested inside
234  radiusSqr += Foam::sqr(small);
235 }
236 
237 
238 void Foam::searchableSurfaces::disk::findNearest
239 (
240  const pointField& samples,
241  const scalarField& nearestDistSqr,
242  List<pointIndexHit>& info
243 ) const
244 {
245  info.setSize(samples.size());
246 
247  forAll(samples, i)
248  {
249  info[i] = findNearest(samples[i], nearestDistSqr[i]);
250  }
251 }
252 
253 
254 void Foam::searchableSurfaces::disk::findLine
255 (
256  const pointField& start,
257  const pointField& end,
258  List<pointIndexHit>& info
259 ) const
260 {
261  info.setSize(start.size());
262 
263  forAll(start, i)
264  {
265  findLine(start[i], end[i], info[i]);
266  }
267 }
268 
269 
271 (
272  const pointField& start,
273  const pointField& end,
274  List<pointIndexHit>& info
275 ) const
276 {
277  findLine(start, end, info);
278 }
279 
280 
282 (
283  const pointField& start,
284  const pointField& end,
286 ) const
287 {
288  info.setSize(start.size());
289 
290  forAll(start, i)
291  {
292  pointIndexHit inter;
293  findLine(start[i], end[i], inter);
294 
295  if (inter.hit())
296  {
297  info[i].setSize(1);
298  info[i][0] = inter;
299  }
300  else
301  {
302  info[i].clear();
303  }
304  }
305 }
306 
307 
309 (
310  const List<pointIndexHit>& info,
311  labelList& region
312 ) const
313 {
314  region.setSize(info.size());
315  region = 0;
316 }
317 
318 
320 (
321  const List<pointIndexHit>& info,
322  vectorField& normal
323 ) const
324 {
325  normal.setSize(info.size());
326  normal = normal_;
327 }
328 
329 
331 (
332  const pointField& points,
333  List<volumeType>& volType
334 ) const
335 {
337  << "Volume type not supported for disk."
338  << exit(FatalError);
339 }
340 
341 
342 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
Macros for easy insertion into run-time selection tables.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
InfoProxy< IOobject > info() const
Return info proxy.
Definition: IOobject.H:485
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void setSize(const label)
Reset size of List.
Definition: List.C:281
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:54
bool hit() const
Is there a hit.
const point & min() const
Minimum point defining the bounding box.
Definition: boundBoxI.H:60
const point & max() const
Maximum point defining the bounding box.
Definition: boundBoxI.H:66
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
const boundBox & bounds() const
Return const reference to boundBox.
Surface geometry with a circular disk shape, which can be used with snappyHexMesh.
virtual void getVolumeType(const pointField &, List< volumeType > &) const
Determine type (inside/outside/mixed) for point. unknown if.
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared), one per element.
disk(const IOobject &io, const point &origin, const point &normal, const scalar radius)
Construct from components.
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
virtual const wordList & regions() const
Names of regions.
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const
Get all intersections in order from start to end.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const pointField & points
addToRunTimeSelectionTable(searchableSurface, box, dictionary)
addBackwardCompatibleToRunTimeSelectionTable(searchableSurface, box, dictionary, searchableBox, "searchableBox")
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const zero Zero
Definition: zero.H:97
dimensionedScalar sign(const dimensionedScalar &ds)
PointIndexHit< point > pointIndexHit
Definition: pointIndexHit.H:42
const dimensionSet dimless
const dimensionSet dimLength
vector point
Point is a vector.
Definition: point.H:41
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
void sqr(LagrangianPatchField< typename outerProduct< Type, Type >::type > &f, const LagrangianPatchField< Type > &f1)
error FatalError
void magSqr(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
dictionary dict
scalarField samples(nIntervals, 0)