FreeFOAM The Cross-Platform CFD Toolkit
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 | 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 "searchablePlane.H"
28 #include <OpenFOAM/SortableList.H>
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 defineTypeNameAndDebug(searchablePlane, 0);
36 addToRunTimeSelectionTable(searchableSurface, searchablePlane, dict);
37 
38 }
39 
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
43 Foam::pointIndexHit Foam::searchablePlane::findLine
44 (
45  const point& start,
46  const point& end
47 ) const
48 {
50 
51  linePointRef l(start, end);
52 
53  scalar t = lineIntersect(l);
54 
55  if (t < 0 || t > 1)
56  {
57  info.setMiss();
58  info.setIndex(-1);
59  }
60  else
61  {
62  info.setPoint(start+t*l.vec());
63  }
64 
65  return info;
66 }
67 
68 
69 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
70 
71 Foam::searchablePlane::searchablePlane
72 (
73  const IOobject& io,
74  const point& basePoint,
75  const vector& normal
76 )
77 :
79  plane(basePoint, normal)
80 {}
81 
82 
83 Foam::searchablePlane::searchablePlane
84 (
85  const IOobject& io,
86  const dictionary& dict
87 )
88 :
90  plane(dict)
91 {}
92 
93 
94 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
95 
97 {}
98 
99 
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101 
103 {
104  if (regions_.empty())
105  {
106  regions_.setSize(1);
107  regions_[0] = "region0";
108  }
109  return regions_;
110 }
111 
112 
114 (
115  const pointField& samples,
116  const scalarField& nearestDistSqr,
117  List<pointIndexHit>& info
118 ) const
119 {
120  info.setSize(samples.size());
121 
122  forAll(samples, i)
123  {
124  info[i].setPoint(nearestPoint(samples[i]));
125 
126  if (magSqr(samples[i]-info[i].rawPoint()) > nearestDistSqr[i])
127  {
128  info[i].setIndex(-1);
129  info[i].setMiss();
130  }
131  else
132  {
133  info[i].setIndex(0);
134  info[i].setHit();
135  }
136  }
137 }
138 
139 
140 void Foam::searchablePlane::findLine
141 (
142  const pointField& start,
143  const pointField& end,
144  List<pointIndexHit>& info
145 ) const
146 {
147  info.setSize(start.size());
148 
149  forAll(start, i)
150  {
151  info[i] = findLine(start[i], end[i]);
152  }
153 }
154 
155 
157 (
158  const pointField& start,
159  const pointField& end,
160  List<pointIndexHit>& info
161 ) const
162 {
163  findLine(start, end, info);
164 }
165 
166 
168 (
169  const pointField& start,
170  const pointField& end,
171  List<List<pointIndexHit> >& info
172 ) const
173 {
174  List<pointIndexHit> nearestInfo;
175  findLine(start, end, nearestInfo);
176 
177  info.setSize(start.size());
178  forAll(info, pointI)
179  {
180  if (nearestInfo[pointI].hit())
181  {
182  info[pointI].setSize(1);
183  info[pointI][0] = nearestInfo[pointI];
184  }
185  else
186  {
187  info[pointI].clear();
188  }
189  }
190 }
191 
192 
194 (
195  const List<pointIndexHit>& info,
196  labelList& region
197 ) const
198 {
199  region.setSize(info.size());
200  region = 0;
201 }
202 
203 
205 (
206  const List<pointIndexHit>& info,
207  vectorField& n
208 ) const
209 {
210  n.setSize(info.size());
211  n = normal();
212 }
213 
214 
216 (
217  const pointField& points,
218  List<volumeType>& volType
219 ) const
220 {
222  (
223  "searchableCollection::getVolumeType(const pointField&"
224  ", List<volumeType>&) const"
225  ) << "Volume type not supported for plane."
226  << exit(FatalError);
227 }
228 
229 
230 // ************************ vim: set sw=4 sts=4 et: ************************ //