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 | Copyright (C) 2011-2015 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 
44 (
45  const point& start,
46  const point& end
47 ) const
48 {
49  pointIndexHit info(true, vector::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 
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 
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,
209  List<List<pointIndexHit> >& info
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 // ************************************************************************* //
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::plane::normal
const vector & normal() const
Return plane normal.
Definition: plane.C:248
Foam::searchablePlane::getVolumeType
virtual void getVolumeType(const pointField &, List< volumeType > &) const
Determine type (inside/outside/mixed) for point. unknown if.
Definition: searchablePlane.C:254
Foam::PointIndexHit::setIndex
void setIndex(const label index)
Definition: PointIndexHit.H:168
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::searchablePlane::findLineAll
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit > > &) const
Get all intersections in order from start to end.
Definition: searchablePlane.C:206
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::nComponents
@ nComponents
Number of components in this vector space.
Definition: VectorSpace.H:88
Foam::PointIndexHit::setMiss
void setMiss()
Definition: PointIndexHit.H:158
Foam::searchablePlane::calcBounds
boundBox calcBounds() const
Return the boundBox of the plane.
Definition: searchablePlane.C:69
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::searchablePlane::boundingSpheres
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared), one per element.
Definition: searchablePlane.C:138
Foam::plane
Geometric class that creates a 2D plane and can return the intersection point between a line and the ...
Definition: plane.H:60
samples
scalarField samples(nIntervals, 0)
n
label n
Definition: TABSMDCalcMethod2.H:31
SortableList.H
Foam::searchablePlane::searchablePlane
searchablePlane(const searchablePlane &)
Disallow default bitwise copy construct.
Foam::PointIndexHit
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:53
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::searchableSurface
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
Definition: searchableSurface.H:66
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::PointIndexHit::setPoint
void setPoint(const Point &p)
Definition: PointIndexHit.H:163
Foam::searchablePlane::findNearest
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const
Definition: searchablePlane.C:152
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::List::setSize
void setSize(const label)
Reset size of List.
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::searchablePlane::findLine
pointIndexHit findLine(const point &start, const point &end) const
Definition: searchablePlane.C:44
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::searchablePlane::regions
virtual const wordList & regions() const
Names of regions.
Definition: searchablePlane.C:126
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::List::clear
void clear()
Clear the list, i.e. set size to zero.
Definition: List.C:379
Foam::searchablePlane::~searchablePlane
virtual ~searchablePlane()
Destructor.
Definition: searchablePlane.C:120
Foam::searchablePlane::getRegion
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
Definition: searchablePlane.C:232
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::line
A line primitive.
Definition: line.H:56
searchablePlane.H
Foam::boundBox
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::line::vec
Point vec() const
Return start-end vector.
Definition: lineI.H:87
Foam::searchablePlane::findLineAny
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
Definition: searchablePlane.C:195
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Foam::searchablePlane::getNormal
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
Definition: searchablePlane.C:243
normal
A normal distribution model.