Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
38 (
41 dict
42 );
44 (
47 dict,
48 disk
49 );
50}
51
52
53// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
54
55Foam::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
88void 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
127Foam::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
156Foam::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
203void Foam::searchableDisk::findNearest
204(
205 const pointField& samples,
206 const scalarField& nearestDistSqr,
208) const
209{
210 info.resize(samples.size());
211
213 {
214 info[i] = findNearest(samples[i], nearestDistSqr[i]);
215 }
216}
217
218
219void 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,
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
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// ************************************************************************* //
scalar y
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Minimal example by using system/controlDict.functions:
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
InfoProxy< IOobject > info() const noexcept
Return info proxy, for printing information to a stream.
Definition IOobject.H:1041
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
T clamp(const T &val) const
Return value clamped component-wise.
Definition MinMaxI.H:227
bool hit() const noexcept
Is there a hit?
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
const point & max() const noexcept
Maximum describing the bounding box.
Definition boundBoxI.H:168
const point & min() const noexcept
Minimum describing the bounding box.
Definition boundBoxI.H:162
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
plane()
Construct zero-initialised.
Definition planeI.H:23
const point & origin() const noexcept
The plane base point.
Definition planeI.H:38
const vector & normal() const noexcept
The plane unit normal.
Definition planeI.H:32
scalar signedDistance(const point &p) const
Return distance from the given point to the plane.
Definition planeI.H:68
Searching on circular disk given as origin, normal (gets normalised) and radius. Optionally it can be...
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit > > &) const
Get all intersections in order from start to end.
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.
virtual void getVolumeType(const pointField &points, List< volumeType > &volType) const
Determine type (inside/outside/mixed) for point.
virtual tmp< pointField > points() const
Get the points that define the surface.
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 getNormal(const List< pointIndexHit > &, vectorField &normals) const
From a set of points and indices get the normal.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
virtual const boundBox & bounds() const
Return const reference to boundBox.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
const auto & io
const pointField & points
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
dimensionedScalar sign(const dimensionedScalar &ds)
List< label > labelList
A List of labels.
Definition List.H:62
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Field< vector > vectorField
Specialisation of Field<T> for vector.
vector point
Point is a vector.
Definition point.H:37
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
vectorField pointField
pointField is a vectorField.
Vector< scalar > vector
Definition vector.H:57
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299
scalarField samples(nIntervals, Zero)