plane_searchableSurface.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-2025 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 
27 #include "SortableList.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  namespace searchableSurfaces
35  {
37 
39  (
41  plane,
43  );
44 
46  (
48  plane,
49  dictionary,
50  searchablePlane,
51  "searchablePlane"
52  );
53  }
54 }
55 
56 
57 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
58 
59 Foam::pointIndexHit Foam::searchableSurfaces::plane::findLine
60 (
61  const point& start,
62  const point& end
63 ) const
64 {
65  pointIndexHit info(true, Zero, 0);
66 
67  linePointRef l(start, end);
68 
69  scalar t = lineIntersect(l);
70 
71  if (t < 0 || t > 1)
72  {
73  info.setMiss();
74  info.setIndex(-1);
75  }
76  else
77  {
78  info.setPoint(start+t*l.vec());
79  }
80 
81  return info;
82 }
83 
84 
85 Foam::boundBox Foam::searchableSurfaces::plane::calcBounds() const
86 {
87  point max(vGreat, vGreat, vGreat);
88 
89  for (direction dir = 0; dir < vector::nComponents; dir++)
90  {
91  if (mag(normal()[dir]) - 1 < small)
92  {
93  max[dir] = 0;
94 
95  break;
96  }
97  }
98 
99  point min = -max;
100 
101  return boundBox(min, max);
102 }
103 
104 
105 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
106 
108 (
109  const IOobject& io,
110  const point& basePoint,
111  const vector& normal
112 )
113 :
114  searchableSurface(io),
115  Foam::plane(basePoint, normal)
116 {
117  bounds() = calcBounds();
118 }
119 
120 
122 (
123  const IOobject& io,
124  const dictionary& dict
125 )
126 :
127  searchableSurface(io),
128  Foam::plane(dict)
129 {
130  bounds() = calcBounds();
131 }
132 
133 
134 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
135 
137 {}
138 
139 
140 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
141 
143 {
144  if (regions_.empty())
145  {
146  regions_.setSize(1);
147  regions_[0] = "region0";
148  }
149  return regions_;
150 }
151 
152 
154 (
155  pointField& centres,
156  scalarField& radiusSqr
157 ) const
158 {
159  centres.setSize(1);
160  centres[0] = refPoint();
161 
162  radiusSqr.setSize(1);
163  radiusSqr[0] = Foam::sqr(great);
164 }
165 
166 
168 (
169  const pointField& samples,
170  const scalarField& nearestDistSqr,
171  List<pointIndexHit>& info
172 ) const
173 {
174  info.setSize(samples.size());
175 
176  forAll(samples, i)
177  {
178  info[i].setPoint(nearestPoint(samples[i]));
179 
180  if (magSqr(samples[i]-info[i].rawPoint()) > nearestDistSqr[i])
181  {
182  info[i].setIndex(-1);
183  info[i].setMiss();
184  }
185  else
186  {
187  info[i].setIndex(0);
188  info[i].setHit();
189  }
190  }
191 }
192 
193 
194 void Foam::searchableSurfaces::plane::findLine
195 (
196  const pointField& start,
197  const pointField& end,
198  List<pointIndexHit>& info
199 ) const
200 {
201  info.setSize(start.size());
202 
203  forAll(start, i)
204  {
205  info[i] = findLine(start[i], end[i]);
206  }
207 }
208 
209 
211 (
212  const pointField& start,
213  const pointField& end,
214  List<pointIndexHit>& info
215 ) const
216 {
217  findLine(start, end, info);
218 }
219 
220 
222 (
223  const pointField& start,
224  const pointField& end,
226 ) const
227 {
228  List<pointIndexHit> nearestInfo;
229  findLine(start, end, nearestInfo);
230 
231  info.setSize(start.size());
232  forAll(info, pointi)
233  {
234  if (nearestInfo[pointi].hit())
235  {
236  info[pointi].setSize(1);
237  info[pointi][0] = nearestInfo[pointi];
238  }
239  else
240  {
241  info[pointi].clear();
242  }
243  }
244 }
245 
246 
248 (
249  const List<pointIndexHit>& info,
250  labelList& region
251 ) const
252 {
253  region.setSize(info.size());
254  region = 0;
255 }
256 
257 
259 (
260  const List<pointIndexHit>& info,
261  vectorField& n
262 ) const
263 {
264  n.setSize(info.size());
265  n = normal();
266 }
267 
268 
270 (
271  const pointField& points,
272  List<volumeType>& volType
273 ) const
274 {
276  << "Volume type not supported for plane."
277  << exit(FatalError);
278 }
279 
280 
281 // ************************************************************************* //
label n
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
Macros for easy insertion into run-time selection tables.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
InfoProxy< IOobject > info() const
Return info proxy.
Definition: IOobject.H:485
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
void setSize(const label)
Reset size of List.
Definition: List.C:281
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:54
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:105
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:59
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
scalar lineIntersect(const line< Point, PointRef > &l) const
Return the cutting point between the plane and.
Definition: plane.H:212
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
const boundBox & bounds() const
Return const reference to boundBox.
Surface geometry of an infinite plane, which can be used with snappyHexMesh.
virtual void getVolumeType(const pointField &, List< volumeType > &) const
Determine type (inside/outside/mixed) for point. unknown if.
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
virtual void boundingSpheres(pointField &centres, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared), one per element.
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
virtual void getRegion(const List< pointIndexHit > &, labelList &region) const
From a set of points and indices get the region.
virtual const wordList & regions() const
Names of regions.
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const
virtual void findLineAll(const pointField &start, const pointField &end, List< List< pointIndexHit >> &) const
Get all intersections in order from start to end.
plane(const IOobject &io, const point &basePoint, const vector &normal)
Construct from components.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const pointField & points
addToRunTimeSelectionTable(searchableSurface, box, dictionary)
addBackwardCompatibleToRunTimeSelectionTable(searchableSurface, box, dictionary, searchableBox, "searchableBox")
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const zero Zero
Definition: zero.H:97
PointIndexHit< point > pointIndexHit
Definition: pointIndexHit.H:42
line< point, const point & > linePointRef
Line using referred points.
Definition: linePointRef.H:45
vector point
Point is a vector.
Definition: point.H:41
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
void sqr(LagrangianPatchField< typename outerProduct< Type, Type >::type > &f, const LagrangianPatchField< Type > &f1)
error FatalError
void magSqr(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
uint8_t direction
Definition: direction.H:45
dictionary dict
scalarField samples(nIntervals, 0)