FreeFOAM The Cross-Platform CFD Toolkit
pointEdgePointI.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) 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 <OpenFOAM/polyMesh.H>
27 #include <OpenFOAM/transform.H>
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 // Update this with w2 if w2 nearer to pt.
32 inline bool Foam::pointEdgePoint::update
33 (
34  const point& pt,
35  const pointEdgePoint& w2,
36  const scalar tol
37 )
38 {
39  scalar dist2 = magSqr(pt - w2.origin());
40 
41  if (!valid())
42  {
43  // current not yet set so use any value
44  distSqr_ = dist2;
45  origin_ = w2.origin();
46 
47  return true;
48  }
49 
50  scalar diff = distSqr_ - dist2;
51 
52  if (diff < 0)
53  {
54  // already nearer to pt
55  return false;
56  }
57 
58  if ((diff < SMALL) || ((distSqr_ > SMALL) && (diff/distSqr_ < tol)))
59  {
60  // don't propagate small changes
61  return false;
62  }
63  else
64  {
65  // update with new values
66  distSqr_ = dist2;
67  origin_ = w2.origin();
68 
69  return true;
70  }
71 }
72 
73 
74 // Update this with w2 (information on same point)
75 inline bool Foam::pointEdgePoint::update
76 (
77  const pointEdgePoint& w2,
78  const scalar tol
79 )
80 {
81  if (!valid())
82  {
83  // current not yet set so use any value
84  distSqr_ = w2.distSqr();
85  origin_ = w2.origin();
86 
87  return true;
88  }
89 
90  scalar diff = distSqr_ - w2.distSqr();
91 
92  if (diff < 0)
93  {
94  // already nearer to pt
95  return false;
96  }
97 
98  if ((diff < SMALL) || ((distSqr_ > SMALL) && (diff/distSqr_ < tol)))
99  {
100  // don't propagate small changes
101  return false;
102  }
103  else
104  {
105  // update with new values
106  distSqr_ = w2.distSqr();
107  origin_ = w2.origin();
108 
109  return true;
110  }
111 }
112 
113 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
114 
115 // Null constructor
117 :
118  origin_(greatPoint),
119  distSqr_(GREAT)
120 {}
121 
122 
123 // Construct from origin, distance
125 (
126  const point& origin,
127  const scalar distSqr
128 )
129 :
130  origin_(origin),
131  distSqr_(distSqr)
132 {}
133 
134 
135 // Construct as copy
137 :
138  origin_(wpt.origin()),
139  distSqr_(wpt.distSqr())
140 {}
141 
142 
143 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
144 
146 {
147  return origin_;
148 }
149 
150 
151 inline Foam::scalar Foam::pointEdgePoint::distSqr() const
152 {
153  return distSqr_;
154 }
155 
156 
157 inline bool Foam::pointEdgePoint::valid() const
158 {
159  return origin_ != greatPoint;
160 }
161 
162 
163 // Checks for cyclic points
165 (
166  const pointEdgePoint& w2,
167  const scalar tol
168 ) const
169 {
170  scalar diff = Foam::mag(distSqr() - w2.distSqr());
171 
172  if (diff < SMALL)
173  {
174  return true;
175  }
176  else
177  {
178  if ((distSqr() > SMALL) && ((diff/distSqr()) < tol))
179  {
180  return true;
181  }
182  else
183  {
184  return false;
185  }
186  }
187 }
188 
189 
191 (
192  const polyPatch& patch,
193  const label patchPointI,
194  const point& coord
195 )
196 {
197  origin_ -= coord;
198 }
199 
200 
201 inline void Foam::pointEdgePoint::transform(const tensor& rotTensor)
202 {
203  origin_ = Foam::transform(rotTensor, origin_);
204 }
205 
206 
207 // Update absolute geometric quantities. Note that distance (distSqr_)
208 // is not affected by leaving/entering domain.
210 (
211  const polyPatch& patch,
212  const label patchPointI,
213  const point& coord
214 )
215 {
216  // back to absolute form
217  origin_ += coord;
218 }
219 
220 
221 // Update this with information from connected edge
223 (
224  const polyMesh& mesh,
225  const label pointI,
226  const label edgeI,
227  const pointEdgePoint& edgeInfo,
228  const scalar tol
229 )
230 {
231  return
232  update
233  (
234  mesh.points()[pointI],
235  edgeInfo,
236  tol
237  );
238  }
239 
240 
241 // Update this with new information on same point
243 (
244  const polyMesh& mesh,
245  const label pointI,
246  const pointEdgePoint& newPointInfo,
247  const scalar tol
248 )
249 {
250  return
251  update
252  (
253  mesh.points()[pointI],
254  newPointInfo,
255  tol
256  );
257 }
258 
259 
260 // Update this with new information on same point. No extra information.
262 (
263  const pointEdgePoint& newPointInfo,
264  const scalar tol
265 )
266 {
267  return update(newPointInfo, tol);
268 }
269 
270 
271 // Update this with information from connected point
273 (
274  const polyMesh& mesh,
275  const label edgeI,
276  const label pointI,
277  const pointEdgePoint& pointInfo,
278  const scalar tol
279 )
280 {
281  const pointField& points = mesh.points();
282 
283  const edge& e = mesh.edges()[edgeI];
284 
285  const point edgeMid(0.5*(points[e[0]] + points[e[1]]));
286 
287  return
288  update
289  (
290  edgeMid,
291  pointInfo,
292  tol
293  );
294 }
295 
296 
297 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
298 
300  const
301 {
302  return origin() == rhs.origin();
303 }
304 
305 
307  const
308 {
309  return !(*this == rhs);
310 }
311 
312 
313 // ************************ vim: set sw=4 sts=4 et: ************************ //