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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "searchablePlane.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(searchablePlane, 0);
37  (
38  searchableSurface,
39  searchablePlane,
40  dict
41  );
43  (
44  searchableSurface,
45  searchablePlane,
46  dict,
47  plane
48  );
49 }
50 
51 
52 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
53 
54 Foam::pointIndexHit Foam::searchablePlane::findLine
55 (
56  const point& start,
57  const point& end
58 ) const
59 {
60  pointIndexHit info(true, Zero, 0);
61 
62  linePointRef l(start, end);
63 
64  scalar t = lineIntersect(l);
65 
66  if (t < 0 || t > 1)
67  {
68  info.setMiss();
69  info.setIndex(-1);
70  }
71  else
72  {
73  info.setPoint(start+t*l.vec());
74  }
75 
76  return info;
77 }
78 
79 
80 Foam::boundBox Foam::searchablePlane::calcBounds() const
81 {
82  boundBox bb(boundBox::greatBox);
83 
84  for (direction dir = 0; dir < vector::nComponents; dir++)
85  {
86  if (mag(normal()[dir]) - 1 < SMALL)
87  {
88  bb.min()[dir] = 0;
89  bb.max()[dir] = 0;
90  break;
91  }
92  }
93 
94  return bb;
95 }
96 
97 
98 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
99 
100 Foam::searchablePlane::searchablePlane
101 (
102  const IOobject& io,
103  const point& basePoint,
104  const vector& normal
105 )
106 :
107  searchableSurface(io),
108  plane(basePoint, normal)
109 {
110  bounds() = calcBounds();
111 }
112 
113 
114 Foam::searchablePlane::searchablePlane
115 (
116  const IOobject& io,
117  const dictionary& dict
118 )
119 :
120  searchableSurface(io),
121  plane(dict)
122 {
123  bounds() = calcBounds();
124 }
125 
126 
127 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
128 
130 {
131  if (regions_.empty())
132  {
133  regions_.setSize(1);
134  regions_[0] = "region0";
135  }
136  return regions_;
137 }
138 
139 
141 (
142  pointField& centres,
143  scalarField& radiusSqr
144 ) const
145 {
146  centres.resize(1);
147  radiusSqr.resize(1);
148 
149  centres[0] = origin();
150  radiusSqr[0] = Foam::sqr(GREAT);
151 }
152 
153 
155 (
156  const pointField& samples,
157  const scalarField& nearestDistSqr,
158  List<pointIndexHit>& info
159 ) const
160 {
161  info.setSize(samples.size());
162 
163  forAll(samples, i)
164  {
165  info[i].setPoint(nearestPoint(samples[i]));
166 
167  if (magSqr(samples[i]-info[i].rawPoint()) > nearestDistSqr[i])
168  {
169  info[i].setIndex(-1);
170  info[i].setMiss();
171  }
172  else
173  {
174  info[i].setIndex(0);
175  info[i].setHit();
176  }
177  }
178 }
179 
180 
181 void Foam::searchablePlane::findLine
182 (
183  const pointField& start,
184  const pointField& end,
185  List<pointIndexHit>& info
186 ) const
187 {
188  info.setSize(start.size());
189 
190  forAll(start, i)
191  {
192  info[i] = findLine(start[i], end[i]);
193  }
194 }
195 
196 
198 (
199  const pointField& start,
200  const pointField& end,
201  List<pointIndexHit>& info
202 ) const
203 {
204  findLine(start, end, info);
205 }
206 
207 
209 (
210  const pointField& start,
211  const pointField& end,
213 ) const
214 {
215  List<pointIndexHit> nearestInfo;
216  findLine(start, end, nearestInfo);
217 
218  info.setSize(start.size());
219  forAll(info, pointi)
220  {
221  if (nearestInfo[pointi].hit())
222  {
223  info[pointi].setSize(1);
224  info[pointi][0] = nearestInfo[pointi];
225  }
226  else
227  {
228  info[pointi].clear();
229  }
230  }
231 }
232 
233 
235 (
236  const List<pointIndexHit>& info,
237  labelList& region
238 ) const
239 {
240  region.setSize(info.size());
241  region = 0;
242 }
243 
244 
246 (
247  const List<pointIndexHit>& info,
248  vectorField& n
249 ) const
250 {
251  n.setSize(info.size());
252  n = normal();
253 }
254 
255 
257 (
258  const pointField& points,
259  List<volumeType>& volType
260 ) const
261 {
263  << "Volume type not supported for plane."
264  << exit(FatalError);
265 }
266 
267 
268 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::searchablePlane::getVolumeType
virtual void getVolumeType(const pointField &, List< volumeType > &) const
Determine type (inside/outside/mixed) for point.
Definition: searchablePlane.C:257
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::IOobject::info
InfoProxy< IOobject > info() const
Return info proxy.
Definition: IOobject.H:689
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::searchablePlane::boundingSpheres
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared), one per element.
Definition: searchablePlane.C:141
Foam::plane
Geometric class that creates a 3D plane and can return the intersection point between a line and the ...
Definition: plane.H:89
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::PointIndexHit
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:52
Foam::Field< vector >
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::searchableSurface
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
Definition: searchableSurface.H:69
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
samples
scalarField samples(nIntervals, Zero)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::plane::lineIntersect
scalar lineIntersect(const line< Point, PointRef > &l) const
Return the cutting point between the plane and.
Definition: plane.H:257
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::searchablePlane::findNearest
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const
Definition: searchablePlane.C:155
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::linePointRef
line< point, const point & > linePointRef
A line using referred points.
Definition: linePointRef.H:47
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::pointIndexHit
PointIndexHit< point > pointIndexHit
A PointIndexHit for 3D points.
Definition: pointIndexHit.H:46
Foam::boundBox::greatBox
static const boundBox greatBox
A large boundBox: min/max == -/+ ROOTVGREAT.
Definition: boundBox.H:83
Foam::Vector< scalar >
Foam::List< word >
Foam::searchablePlane::regions
virtual const wordList & regions() const
Names of regions.
Definition: searchablePlane.C:129
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::List::clear
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
Foam::direction
uint8_t direction
Definition: direction.H:52
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:235
searchablePlane.H
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::point
vector point
Point is a vector.
Definition: point.H:43
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
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:198
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:246
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:209
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::nComponents
static constexpr direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:101