FreeFOAM The Cross-Platform CFD Toolkit
triSurfaceSearch.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) 1991-2010 OpenCFD Ltd.
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 "triSurfaceSearch.H"
28 #include <OpenFOAM/boolList.H>
30 #include <triSurface/triSurface.H>
31 #include <OpenFOAM/line.H>
32 #include <OSspecific/cpuTime.H>
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 
41 const point triSurfaceSearch::greatPoint(GREAT, GREAT, GREAT);
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
46 // Construct from surface. Holds reference!
47 triSurfaceSearch::triSurfaceSearch(const triSurface& surface)
48 :
49  surface_(surface),
50  treePtr_(NULL)
51 {
52  // Random number generator. Bit dodgy since not exactly random ;-)
53  Random rndGen(65431);
54 
55  // Slightly extended bb. Slightly off-centred just so on symmetric
56  // geometry there are less face/edge aligned items.
57  treeBoundBox treeBb
58  (
59  treeBoundBox(surface_.points(), surface_.meshPoints()).extend
60  (
61  rndGen,
62  1E-4
63  )
64  );
65  treeBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
66  treeBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
67 
68  treePtr_.reset
69  (
71  (
72  treeDataTriSurface(surface_),
73  treeBb,
74  8, // maxLevel
75  10, // leafsize
76  3.0 // duplicity
77  )
78  );
79 }
80 
81 
82 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
83 
84 // Determine inside/outside for samples
86 {
87  boolList inside(samples.size());
88 
89  forAll(samples, sampleI)
90  {
91  const point& sample = samples[sampleI];
92 
93  if (!tree().bb().contains(sample))
94  {
95  inside[sampleI] = false;
96  }
97  else if
98  (
99  tree().getVolumeType(sample)
101  )
102  {
103  inside[sampleI] = true;
104  }
105  else
106  {
107  inside[sampleI] = false;
108  }
109  }
110  return inside;
111 }
112 
113 
115 (
116  const pointField& samples,
117  const vector& span
118 ) const
119 {
120  labelList nearest(samples.size());
121 
122  const scalar nearestDistSqr = 0.25*magSqr(span);
123 
124  pointIndexHit hitInfo;
125 
126  forAll(samples, sampleI)
127  {
128  hitInfo = tree().findNearest(samples[sampleI], nearestDistSqr);
129 
130  if (hitInfo.hit())
131  {
132  nearest[sampleI] = hitInfo.index();
133  }
134  else
135  {
136  nearest[sampleI] = -1;
137  }
138  }
139 
140  return nearest;
141 }
142 
143 
144 // Nearest point on surface
146 (
147  const pointField& samples,
148  const vector& span
149 ) const
150 {
151  const scalar nearestDistSqr = 0.25*magSqr(span);
152 
153  tmp<pointField> tnearest(new pointField(samples.size()));
154  pointField& nearest = tnearest();
155 
156  pointIndexHit hitInfo;
157 
158  forAll(samples, sampleI)
159  {
160  hitInfo = tree().findNearest(samples[sampleI], nearestDistSqr);
161 
162  if (hitInfo.hit())
163  {
164  nearest[sampleI] = hitInfo.hitPoint();
165  }
166  else
167  {
168  nearest[sampleI] = greatPoint;
169  }
170  }
171 
172  return tnearest;
173 }
174 
175 
177  const
178 {
179  const scalar nearestDistSqr = 0.25*magSqr(span);
180 
181  return tree().findNearest(pt, nearestDistSqr);
182 }
183 
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 } // End namespace Foam
188 
189 // ************************ vim: set sw=4 sts=4 et: ************************ //