searchablePlane.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) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 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 "searchablePlane.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(searchablePlane, 0);
38  (
39  searchableSurface,
40  searchablePlane,
41  dict
42  );
44  (
45  searchableSurface,
46  searchablePlane,
47  dict,
48  plane
49  );
50 }
51 
52 
53 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
54 
55 Foam::pointIndexHit Foam::searchablePlane::findLine
56 (
57  const point& start,
58  const point& end
59 ) const
60 {
61  pointIndexHit info(true, Zero, 0);
62 
63  linePointRef l(start, end);
64 
65  scalar t = lineIntersect(l);
66 
67  if (t < 0 || t > 1)
68  {
69  info.setMiss();
70  info.setIndex(-1);
71  }
72  else
73  {
74  info.setPoint(start+t*l.vec());
75  }
76 
77  return info;
78 }
79 
80 
81 Foam::boundBox Foam::searchablePlane::calcBounds() const
82 {
83  boundBox bb(boundBox::greatBox);
84 
85  for (direction dir = 0; dir < vector::nComponents; dir++)
86  {
87  if (mag(normal()[dir]) - 1 < SMALL)
88  {
89  bb.min()[dir] = 0;
90  bb.max()[dir] = 0;
91  break;
92  }
93  }
94 
95  return bb;
96 }
97 
98 
99 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
100 
101 Foam::searchablePlane::searchablePlane
102 (
103  const IOobject& io,
104  const point& basePoint,
105  const vector& normal
106 )
107 :
109  plane(basePoint, normal)
110 {
111  bounds() = calcBounds();
112 }
113 
114 
115 Foam::searchablePlane::searchablePlane
116 (
117  const IOobject& io,
118  const dictionary& dict
119 )
120 :
122  plane(dict)
123 {
124  bounds() = calcBounds();
125 }
126 
127 
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 
131 {
132  if (regions_.empty())
133  {
134  regions_.setSize(1);
135  regions_[0] = "region0";
136  }
137  return regions_;
138 }
139 
140 
142 (
143  pointField& centres,
144  scalarField& radiusSqr
145 ) const
146 {
147  centres.resize(1);
148  radiusSqr.resize(1);
150  centres[0] = origin();
151  radiusSqr[0] = Foam::sqr(GREAT);
152 }
153 
154 
156 (
157  const pointField& samples,
158  const scalarField& nearestDistSqr,
159  List<pointIndexHit>& info
160 ) const
161 {
162  info.setSize(samples.size());
163 
164  forAll(samples, i)
165  {
166  info[i].setPoint(nearestPoint(samples[i]));
167 
168  if (info[i].point().distSqr(samples[i]) > nearestDistSqr[i])
169  {
170  info[i].setIndex(-1);
171  info[i].setMiss();
172  }
173  else
174  {
175  info[i].setIndex(0);
176  info[i].setHit();
177  }
178  }
179 }
180 
181 
182 void Foam::searchablePlane::findLine
183 (
184  const pointField& start,
185  const pointField& end,
186  List<pointIndexHit>& info
187 ) const
188 {
189  info.setSize(start.size());
190 
191  forAll(start, i)
192  {
193  info[i] = findLine(start[i], end[i]);
194  }
195 }
196 
197 
199 (
200  const pointField& start,
201  const pointField& end,
202  List<pointIndexHit>& info
203 ) const
204 {
205  findLine(start, end, info);
206 }
207 
208 
210 (
211  const pointField& start,
212  const pointField& end,
214 ) const
215 {
216  List<pointIndexHit> nearestInfo;
217  findLine(start, end, nearestInfo);
218 
219  info.setSize(start.size());
220  forAll(info, pointi)
221  {
222  if (nearestInfo[pointi].hit())
223  {
224  info[pointi].setSize(1);
225  info[pointi][0] = nearestInfo[pointi];
226  }
227  else
228  {
229  info[pointi].clear();
230  }
231  }
232 }
233 
234 
236 (
237  const List<pointIndexHit>& info,
238  labelList& region
239 ) const
240 {
241  region.setSize(info.size());
242  region = 0;
243 }
244 
245 
247 (
248  const List<pointIndexHit>& info,
249  vectorField& n
250 ) const
251 {
252  n.setSize(info.size());
253  n = normal();
254 }
255 
256 
258 (
259  const pointField& points,
260  List<volumeType>& volType
261 ) const
262 {
264  << "Volume type not supported for plane."
265  << exit(FatalError);
266 }
267 
268 
269 // ************************************************************************* //
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
uint8_t direction
Definition: direction.H:46
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
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
dimensionedSymmTensor sqr(const dimensionedVector &dv)
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared), one per element.
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const
Get all intersections in order from start to end.
scalarField samples(nIntervals, Zero)
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
Definition: pointIndexHit.H:58
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
This class describes the interaction of an object (often a face) and a point. It carries the info of ...
Definition: pointIndexHit.H:44
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition: exprTraits.C:40
static const boundBox greatBox
A large boundBox: min/max == -/+ ROOTVGREAT.
Definition: boundBox.H:119
Base class of (analytical or triangulated) surface. Encapsulates all the search routines. WIP.
Geometric class that creates a 3D plane and can return the intersection point between a line and the ...
Definition: plane.H:90
Macros for easy insertion into run-time selection tables.
scalar lineIntersect(const line< PointType, PointRef > &l) const
Return the cutting point between the plane and a line passing through the supplied points...
Definition: plane.H:317
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
void setSize(const label n)
Alias for resize()
Definition: List.H:316
line< point, const point & > linePointRef
A line using referred points.
Definition: line.H:66
const pointField & points
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:137
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
InfoProxy< IOobject > info() const noexcept
Return info proxy, for printing information to a stream.
Definition: IOobject.H:955
virtual const wordList & regions() const
Names of regions.
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)
vector point
Point is a vector.
Definition: point.H:37
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
label n
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)
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
virtual void getVolumeType(const pointField &, List< volumeType > &) const
Determine type (inside/outside/mixed) for point.
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127