searchableSurfacesQueries.H
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-2016 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 Class
25  Foam::searchableSurfacesQueries
26 
27 Description
28  A collection of tools for searchableSurfaces.
29 
30 SourceFiles
31  searchableSurfacesQueries.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef searchableSurfacesQueries_H
36 #define searchableSurfacesQueries_H
37 
38 #include "searchableSurface.H"
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 // Forward declaration of classes
46 class plane;
47 
48 /*---------------------------------------------------------------------------*\
49  Class searchableSurfacesQueries Declaration
50 \*---------------------------------------------------------------------------*/
51 
53 {
54  // Private data
55 
56  // Private Member Functions
57 
58  //- Temporary wrapper around findNearest. Used in facesIntersection only
59  static pointIndexHit tempFindNearest
60  (
61  const searchableSurface&,
62  const point& pt,
63  const scalar initDistSqr
64  );
65 
66  //- Calculate sum of distances to nearest point on surfaces. Is used
67  // in minimisation to find intersection. Returns sum of (square of)
68  // distances to the surfaces.
69  static scalar sumDistSqr
70  (
72  const labelList& surfacesToTest,
73  const scalar initialDistSqr, // search box
74  const point& pt
75  );
76 
77  //- Takes the tet (points p) and reflects the point with the
78  // highest value around the centre (pSum). Checks if it gets closer
79  // and updates p, y if so.
80  static scalar tryMorphTet
81  (
83  const labelList& surfacesToTest,
84  const scalar initialDistSqr,
85  List<vector>& p,
86  List<scalar>& y,
87  vector& pSum,
88  const label ihi,
89  const scalar fac
90  );
91 
92  //- Downhill simplex method: find the point with min cumulative
93  // distance to all surfaces. Does so by morphing a tet (points p).
94  // Returns the point on the 0th surface or hit if not reached within
95  // maxIters iterations.
96  static bool morphTet
97  (
99  const labelList& surfacesToTest,
100  const scalar initialDistSqr,
101  const scalar convergenceDistSqr,
102  const label maxIter,
103  List<vector>& p,
104  List<scalar>& y
105  );
106 
107  //static void findAllIntersections
108  //(
109  // const searchableSurface& s,
110  // const pointField& start,
111  // const pointField& end,
112  // const vectorField& smallVec,
113  // List<List<pointIndexHit>>&
114  //);
115 
116  static void mergeHits
117  (
118  const point& start,
119 
120  const label surfI,
121  const List<pointIndexHit>& surfHits,
122 
123  labelList& allSurfaces,
124  List<pointIndexHit>& allInfo,
125  scalarList& allDistSqr
126  );
127 
128 public:
129 
130  // Declare name of the class and its debug switch
131  ClassName("searchableSurfacesQueries");
132 
133 
134  // Multiple point queries.
135 
136  //- Find any intersection. Return hit point information and
137  // index in surfacesToTest. If multiple surfaces hit the first
138  // surface is returned, not necessarily the nearest (to start).
139  static void findAnyIntersection
140  (
142  const labelList& surfacesToTest,
143  const pointField& start,
144  const pointField& end,
145  labelList& surfaces,
147  );
148 
149  //- Find all intersections in order from start to end. Returns for
150  // every hit the index in surfacesToTest and the hit info.
151  static void findAllIntersections
152  (
154  const labelList& surfacesToTest,
155  const pointField& start,
156  const pointField& end,
157  labelListList& surfaces,
158  List<List<pointIndexHit>>& surfaceHits
159  );
160 
161  //Find intersections of edge nearest to both endpoints.
162  static void findNearestIntersection
163  (
164  const PtrList<searchableSurface>& allSurfaces,
165  const labelList& surfacesToTest,
166  const pointField& start,
167  const pointField& end,
168  labelList& surface1,
169  List<pointIndexHit>& hit1,
170  labelList& surface2,
171  List<pointIndexHit>& hit2
172  );
173 
174  //- Find nearest. Return -1 (and a miss()) or surface and nearest
175  // point.
176  static void findNearest
177  (
179  const labelList& surfacesToTest,
180  const pointField&,
181  const scalarField& nearestDistSqr,
182  labelList& surfaces,
184  );
185 
186  //- Find nearest points to a specific region of the surface
187  static void findNearest
188  (
189  const PtrList<searchableSurface>& allSurfaces,
190  const labelList& surfacesToTest,
191  const pointField& samples,
192  const scalarField& nearestDistSqr,
193  const labelList& regionIndices,
194  labelList& nearestSurfaces,
195  List<pointIndexHit>& nearestInfo
196  );
197 
198  //- Find signed distance to nearest surface. Outside is positive.
199  // illegalHandling: how to handle non-inside or outside
200  // OUTSIDE : treat as outside
201  // INSIDE : treat as inside
202  // UNKNOWN : throw fatal error
203  static void signedDistance
204  (
205  const PtrList<searchableSurface>& allSurfaces,
206  const labelList& surfacesToTest,
207  const pointField& samples,
208  const scalarField& nearestDistSqr,
209  const volumeType illegalHandling,
210  labelList& nearestSurfaces,
212  );
213 
214  //- Find the boundBox of the selected surfaces
215  static boundBox bounds
216  (
217  const PtrList<searchableSurface>& allSurfaces,
218  const labelList& surfacesToTest
219  );
220 
221  // Single point queries
222 
223  //- Calculate point which is on a set of surfaces. WIP.
225  (
226  const PtrList<searchableSurface>& allSurfaces,
227  const labelList& surfacesToTest,
228  const scalar initDistSqr,
229  const scalar convergenceDistSqr,
230  const point& start
231  );
232 };
233 
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 } // End namespace Foam
238 
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240 
241 #endif
242 
243 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
static void findNearest(const PtrList< searchableSurface > &, const labelList &surfacesToTest, const pointField &, const scalarField &nearestDistSqr, labelList &surfaces, List< pointIndexHit > &)
Find nearest. Return -1 (and a miss()) or surface and nearest.
A collection of tools for searchableSurfaces.
scalar distance(const vector &p1, const vector &p2)
Definition: curveTools.C:12
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
Base class of (analytical or triangulated) surface. Encapsulates all the search routines. WIP.
static void findAllIntersections(const PtrList< searchableSurface > &, const labelList &surfacesToTest, const pointField &start, const pointField &end, labelListList &surfaces, List< List< pointIndexHit >> &surfaceHits)
Find all intersections in order from start to end. Returns for.
static void signedDistance(const PtrList< searchableSurface > &allSurfaces, const labelList &surfacesToTest, const pointField &samples, const scalarField &nearestDistSqr, const volumeType illegalHandling, labelList &nearestSurfaces, scalarField &distance)
Find signed distance to nearest surface. Outside is positive.
scalarField samples(nIntervals, 0)
scalar y
static void findNearestIntersection(const PtrList< searchableSurface > &allSurfaces, const labelList &surfacesToTest, const pointField &start, const pointField &end, labelList &surface1, List< pointIndexHit > &hit1, labelList &surface2, List< pointIndexHit > &hit2)
ClassName("searchableSurfacesQueries")
static void findAnyIntersection(const PtrList< searchableSurface > &, const labelList &surfacesToTest, const pointField &start, const pointField &end, labelList &surfaces, List< pointIndexHit > &)
Find any intersection. Return hit point information and.
static pointIndexHit facesIntersection(const PtrList< searchableSurface > &allSurfaces, const labelList &surfacesToTest, const scalar initDistSqr, const scalar convergenceDistSqr, const point &start)
Calculate point which is on a set of surfaces. WIP.
volScalarField & p
static boundBox bounds(const PtrList< searchableSurface > &allSurfaces, const labelList &surfacesToTest)
Find the boundBox of the selected surfaces.
Namespace for OpenFOAM.