searchablePlane.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) 2011-2018 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 "searchablePlane.H"
28 #include "SortableList.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 defineTypeNameAndDebug(searchablePlane, 0);
36 addToRunTimeSelectionTable(searchableSurface, searchablePlane, dict);
37 
38 }
39 
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
43 Foam::pointIndexHit Foam::searchablePlane::findLine
44 (
45  const point& start,
46  const point& end
47 ) const
48 {
49  pointIndexHit info(true, Zero, 0);
50 
51  linePointRef l(start, end);
52 
53  scalar t = lineIntersect(l);
54 
55  if (t < 0 || t > 1)
56  {
57  info.setMiss();
58  info.setIndex(-1);
59  }
60  else
61  {
62  info.setPoint(start+t*l.vec());
63  }
64 
65  return info;
66 }
67 
68 
69 Foam::boundBox Foam::searchablePlane::calcBounds() const
70 {
71  point max(vGreat, vGreat, vGreat);
72 
73  for (direction dir = 0; dir < vector::nComponents; dir++)
74  {
75  if (mag(normal()[dir]) - 1 < small)
76  {
77  max[dir] = 0;
78 
79  break;
80  }
81  }
82 
83  point min = -max;
84 
85  return boundBox(min, max);
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
90 
92 (
93  const IOobject& io,
94  const point& basePoint,
95  const vector& normal
96 )
97 :
99  plane(basePoint, normal)
100 {
101  bounds() = calcBounds();
102 }
103 
104 
106 (
107  const IOobject& io,
108  const dictionary& dict
109 )
110 :
111  searchableSurface(io),
112  plane(dict)
113 {
114  bounds() = calcBounds();
115 }
116 
117 
118 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
119 
121 {}
122 
123 
124 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125 
127 {
128  if (regions_.empty())
129  {
130  regions_.setSize(1);
131  regions_[0] = "region0";
132  }
133  return regions_;
134 }
135 
136 
138 (
139  pointField& centres,
140  scalarField& radiusSqr
141 ) const
142 {
143  centres.setSize(1);
144  centres[0] = refPoint();
145 
146  radiusSqr.setSize(1);
147  radiusSqr[0] = Foam::sqr(great);
148 }
149 
150 
152 (
153  const pointField& samples,
154  const scalarField& nearestDistSqr,
155  List<pointIndexHit>& info
156 ) const
157 {
158  info.setSize(samples.size());
159 
160  forAll(samples, i)
161  {
162  info[i].setPoint(nearestPoint(samples[i]));
163 
164  if (magSqr(samples[i]-info[i].rawPoint()) > nearestDistSqr[i])
165  {
166  info[i].setIndex(-1);
167  info[i].setMiss();
168  }
169  else
170  {
171  info[i].setIndex(0);
172  info[i].setHit();
173  }
174  }
175 }
176 
177 
178 void Foam::searchablePlane::findLine
179 (
180  const pointField& start,
181  const pointField& end,
182  List<pointIndexHit>& info
183 ) const
184 {
185  info.setSize(start.size());
186 
187  forAll(start, i)
188  {
189  info[i] = findLine(start[i], end[i]);
190  }
191 }
192 
193 
195 (
196  const pointField& start,
197  const pointField& end,
198  List<pointIndexHit>& info
199 ) const
200 {
201  findLine(start, end, info);
202 }
203 
204 
206 (
207  const pointField& start,
208  const pointField& end,
210 ) const
211 {
212  List<pointIndexHit> nearestInfo;
213  findLine(start, end, nearestInfo);
214 
215  info.setSize(start.size());
216  forAll(info, pointi)
217  {
218  if (nearestInfo[pointi].hit())
219  {
220  info[pointi].setSize(1);
221  info[pointi][0] = nearestInfo[pointi];
222  }
223  else
224  {
225  info[pointi].clear();
226  }
227  }
228 }
229 
230 
232 (
233  const List<pointIndexHit>& info,
234  labelList& region
235 ) const
236 {
237  region.setSize(info.size());
238  region = 0;
239 }
240 
241 
243 (
244  const List<pointIndexHit>& info,
245  vectorField& n
246 ) const
247 {
248  n.setSize(info.size());
249  n = normal();
250 }
251 
252 
254 (
255  const pointField& points,
256  List<volumeType>& volType
257 ) const
258 {
260  << "Volume type not supported for plane."
261  << exit(FatalError);
262 }
263 
264 
265 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
dimensionedSymmTensor sqr(const dimensionedVector &dv)
uint8_t direction
Definition: direction.H:45
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
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.
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:58
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:53
PointIndexHit< point > pointIndexHit
Definition: pointIndexHit.H:42
Base class of (analytical or triangulated) surface. Encapsulates all the search routines. WIP.
Geometric class that creates a 2D plane and can return the intersection point between a line and the ...
Definition: plane.H:60
Macros for easy insertion into run-time selection tables.
searchablePlane(const IOobject &io, const point &basePoint, const vector &normal)
Construct from components.
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:99
line< point, const point & > linePointRef
Line using referred points.
Definition: linePointRef.H:45
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
static const zero Zero
Definition: zero.H:97
virtual ~searchablePlane()
Destructor.
dimensioned< scalar > magSqr(const dimensioned< Type > &)
virtual const wordList & regions() const
Names of regions.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
void setSize(const label)
Reset size of List.
Definition: List.C:281
vector point
Point is a vector.
Definition: point.H:41
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.
dimensioned< scalar > mag(const dimensioned< Type > &)
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
virtual void getVolumeType(const pointField &, List< volumeType > &) const
Determine type (inside/outside/mixed) for point. unknown if.
Namespace for OpenFOAM.