initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / autoMesh / autoHexMesh / autoHexMeshDriver / pointData / pointDataI.H
blob68a46489a340be3c7b9bfc45d7c0b50053751322
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
27 \*---------------------------------------------------------------------------*/
29 #include "polyMesh.H"
30 #include "transform.H"
31 #include "wallPoint.H"
33 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
35 // Update this with w2 if w2 nearer to pt.
36 inline bool Foam::pointData::update
38     const point& pt,
39     const pointData& w2,
40     const scalar tol
43     scalar dist2 = magSqr(pt - w2.origin());
45     if (!valid())
46     {
47         distSqr_ = dist2;
48         origin_ = w2.origin();
49         s_ = w2.s();
50         v_ = w2.v();
52         return true;
53     }       
56 //    if (v_ != w2.v())
57 //    {
58 //        return false;
59 //    }
62     scalar diff = distSqr_ - dist2;
64     if (diff < 0)
65     {
66         // already nearer to pt
67         return false;
68     }
70     if ((diff < SMALL) || ((distSqr_ > SMALL) && (diff/distSqr_ < tol)))
71     {
72         // don't propagate small changes
73         return false;
74     }
75     else
76     {
77         // update with new values
78         distSqr_ = dist2;
79         origin_ = w2.origin();
80         s_ = w2.s();
81         v_ = w2.v();
83         return true;
84     }
87     
88 // Update this with w2 (information on same point)
89 inline bool Foam::pointData::update
91     const pointData& w2,
92     const scalar tol
95     if (!valid())
96     {
97         // current not yet set so use any value
98         distSqr_ = w2.distSqr();
99         origin_ = w2.origin();
100         s_ = w2.s();
101         v_ = w2.v();
102         return true;
103     }        
106 //    if (v_ != w2.v())
107 //    {
108 //        return false;
109 //    }
112     scalar diff = distSqr_ - w2.distSqr();
114     if (diff < 0)
115     {
116         // already nearer to pt
117         return false;
118     }
120     if ((diff < SMALL) || ((distSqr_ > SMALL) && (diff/distSqr_ < tol)))
121     {
122         // don't propagate small changes
123         return false;
124     }
125     else
126     {
127         // update with new values
128         distSqr_ =  w2.distSqr();
129         origin_ = w2.origin();
130         s_ = w2.s();
131         v_ = w2.v();
133         return true;
134     }
138 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
140 // Null constructor
141 inline Foam::pointData::pointData()
143     origin_(wallPoint::greatPoint),
144     distSqr_(GREAT),
145     s_(GREAT),
146     v_(wallPoint::greatPoint)
150 // Construct from origin, distance
151 inline Foam::pointData::pointData
153     const point& origin, 
154     const scalar distSqr,
155     const scalar s,
156     const vector& v
159     origin_(origin),
160     distSqr_(distSqr),
161     s_(s),
162     v_(v)
166 // Construct as copy
167 inline Foam::pointData::pointData(const pointData& wpt)
169     origin_(wpt.origin()),
170     distSqr_(wpt.distSqr()),
171     s_(wpt.s()),
172     v_(wpt.v())
176 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
178 inline const Foam::point& Foam::pointData::origin() const
180     return origin_;
184 inline Foam::scalar Foam::pointData::distSqr() const
186     return distSqr_;
190 inline Foam::scalar Foam::pointData::s() const
192     return s_;
196 inline const Foam::vector& Foam::pointData::v() const
198     return v_;
202 inline bool Foam::pointData::valid() const
204     return origin_ != wallPoint::greatPoint;
208 // Checks for cyclic points
209 inline bool Foam::pointData::sameGeometry
211     const pointData& w2,
212     const scalar tol
213 ) const
215     scalar diff = Foam::mag(distSqr() - w2.distSqr());
217     if (diff < SMALL)
218     {
219         return true;
220     }
221     else
222     {
223         if ((distSqr() > SMALL) && ((diff/distSqr()) < tol))
224         {
225             return true;
226         }
227         else
228         {
229             return false;
230         }
231     }
235 inline void Foam::pointData::leaveDomain
237     const polyPatch& patch,
238     const label patchPointI,
239     const point& coord
242     origin_ -= coord;
246 inline void Foam::pointData::transform(const tensor& rotTensor)
248     origin_ = Foam::transform(rotTensor, origin_);
252 // Update absolute geometric quantities. Note that distance (distSqr_)
253 // is not affected by leaving/entering domain.
254 inline void Foam::pointData::enterDomain
256     const polyPatch& patch,
257     const label patchPointI,
258     const point& coord
261     // back to absolute form
262     origin_ += coord;
266 // Update this with information from connected edge
267 inline bool Foam::pointData::updatePoint
269     const polyMesh& mesh,
270     const label pointI,
271     const label edgeI,
272     const pointData& edgeInfo,
273     const scalar tol
276     return 
277         update
278         (
279             mesh.points()[pointI],
280             edgeInfo,
281             tol
282         );
283     }    
286 // Update this with new information on same point
287 inline bool Foam::pointData::updatePoint
289     const polyMesh& mesh,
290     const label pointI,
291     const pointData& newPointInfo,
292     const scalar tol
295     return
296         update
297         (
298             mesh.points()[pointI],
299             newPointInfo,
300             tol
301         );
302 }    
305 // Update this with new information on same point. No extra information.
306 inline bool Foam::pointData::updatePoint
308     const pointData& newPointInfo,
309     const scalar tol
312     return update(newPointInfo, tol);
313 }    
316 // Update this with information from connected point
317 inline bool Foam::pointData::updateEdge
319     const polyMesh& mesh,
320     const label edgeI,
321     const label pointI,
322     const pointData& pointInfo,
323     const scalar tol
326     const pointField& points = mesh.points();
328     const edge& e = mesh.edges()[edgeI];
330     const point edgeMid(0.5*(points[e[0]] + points[e[1]]));
332     return
333         update
334         (
335             edgeMid,
336             pointInfo,
337             tol
338         );
339 }    
342 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
344 inline bool Foam::pointData::operator==(const pointData& rhs) const
346     return origin() == rhs.origin();
350 inline bool Foam::pointData::operator!=(const pointData& rhs) const
352     return !(*this == rhs);
356 // ************************************************************************* //