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 #include "SortableList.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 
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  point max(VGREAT, VGREAT, VGREAT);
84 
85  for (direction dir = 0; dir < vector::nComponents; dir++)
86  {
87  if (mag(normal()[dir]) - 1 < SMALL)
88  {
89  max[dir] = 0;
90 
91  break;
92  }
93  }
94 
95  point min = -max;
96 
97  return boundBox(min, max);
98 }
99 
100 
101 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
102 
103 Foam::searchablePlane::searchablePlane
104 (
105  const IOobject& io,
106  const point& basePoint,
107  const vector& normal
108 )
109 :
110  searchableSurface(io),
111  plane(basePoint, normal)
112 {
113  bounds() = calcBounds();
114 }
115 
116 
117 Foam::searchablePlane::searchablePlane
118 (
119  const IOobject& io,
120  const dictionary& dict
121 )
122 :
123  searchableSurface(io),
124  plane(dict)
125 {
126  bounds() = calcBounds();
127 }
128 
129 
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
131 
133 {
134  if (regions_.empty())
135  {
136  regions_.setSize(1);
137  regions_[0] = "region0";
138  }
139  return regions_;
140 }
141 
142 
144 (
145  pointField& centres,
146  scalarField& radiusSqr
147 ) const
148 {
149  centres.setSize(1);
150  centres[0] = origin();
151 
152  radiusSqr.setSize(1);
153  radiusSqr[0] = Foam::sqr(GREAT);
154 }
155 
156 
158 (
159  const pointField& samples,
160  const scalarField& nearestDistSqr,
161  List<pointIndexHit>& info
162 ) const
163 {
164  info.setSize(samples.size());
165 
166  forAll(samples, i)
167  {
168  info[i].setPoint(nearestPoint(samples[i]));
169 
170  if (magSqr(samples[i]-info[i].rawPoint()) > nearestDistSqr[i])
171  {
172  info[i].setIndex(-1);
173  info[i].setMiss();
174  }
175  else
176  {
177  info[i].setIndex(0);
178  info[i].setHit();
179  }
180  }
181 }
182 
183 
184 void Foam::searchablePlane::findLine
185 (
186  const pointField& start,
187  const pointField& end,
188  List<pointIndexHit>& info
189 ) const
190 {
191  info.setSize(start.size());
192 
193  forAll(start, i)
194  {
195  info[i] = findLine(start[i], end[i]);
196  }
197 }
198 
199 
201 (
202  const pointField& start,
203  const pointField& end,
204  List<pointIndexHit>& info
205 ) const
206 {
207  findLine(start, end, info);
208 }
209 
210 
212 (
213  const pointField& start,
214  const pointField& end,
216 ) const
217 {
218  List<pointIndexHit> nearestInfo;
219  findLine(start, end, nearestInfo);
220 
221  info.setSize(start.size());
222  forAll(info, pointi)
223  {
224  if (nearestInfo[pointi].hit())
225  {
226  info[pointi].setSize(1);
227  info[pointi][0] = nearestInfo[pointi];
228  }
229  else
230  {
231  info[pointi].clear();
232  }
233  }
234 }
235 
236 
238 (
239  const List<pointIndexHit>& info,
240  labelList& region
241 ) const
242 {
243  region.setSize(info.size());
244  region = 0;
245 }
246 
247 
249 (
250  const List<pointIndexHit>& info,
251  vectorField& n
252 ) const
253 {
254  n.setSize(info.size());
255  n = normal();
256 }
257 
258 
260 (
261  const pointField& points,
262  List<volumeType>& volType
263 ) const
264 {
266  << "Volume type not supported for plane."
267  << exit(FatalError);
268 }
269 
270 
271 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::searchablePlane::getVolumeType
virtual void getVolumeType(const pointField &, List< volumeType > &) const
Determine type (inside/outside/mixed) for point.
Definition: searchablePlane.C:260
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::IOobject::info
InfoProxy< IOobject > info() const
Return info proxy.
Definition: IOobject.H:519
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
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:144
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
SortableList.H
Foam::PointIndexHit
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:55
Foam::Field< vector >
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)
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
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:121
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:115
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:158
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::linePointRef
line< point, const point & > linePointRef
Line using referred points.
Definition: linePointRef.H:47
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::pointIndexHit
PointIndexHit< point > pointIndexHit
Definition: pointIndexHit.H:45
Foam::Vector< scalar >
Foam::List< word >
Foam::searchablePlane::regions
virtual const wordList & regions() const
Names of regions.
Definition: searchablePlane.C:132
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::start
label ListType::const_reference const label start
Definition: ListOps.H:408
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:115
Foam::direction
uint8_t direction
Definition: direction.H:47
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:238
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::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
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:201
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:249
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:212
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::nComponents
static constexpr direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:101