FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

pointEdgePointI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <OpenFOAM/polyMesh.H>
00027 #include <OpenFOAM/transform.H>
00028 
00029 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00030 
00031 // Update this with w2 if w2 nearer to pt.
00032 inline bool Foam::pointEdgePoint::update
00033 (
00034     const point& pt,
00035     const pointEdgePoint& w2,
00036     const scalar tol
00037 )
00038 {
00039     scalar dist2 = magSqr(pt - w2.origin());
00040 
00041     if (!valid())
00042     {
00043         // current not yet set so use any value
00044         distSqr_ = dist2;
00045         origin_ = w2.origin();
00046 
00047         return true;
00048     }        
00049 
00050     scalar diff = distSqr_ - dist2;
00051 
00052     if (diff < 0)
00053     {
00054         // already nearer to pt
00055         return false;
00056     }
00057 
00058     if ((diff < SMALL) || ((distSqr_ > SMALL) && (diff/distSqr_ < tol)))
00059     {
00060         // don't propagate small changes
00061         return false;
00062     }
00063     else
00064     {
00065         // update with new values
00066         distSqr_ = dist2;
00067         origin_ = w2.origin();
00068 
00069         return true;
00070     }
00071 }
00072 
00073     
00074 // Update this with w2 (information on same point)
00075 inline bool Foam::pointEdgePoint::update
00076 (
00077     const pointEdgePoint& w2,
00078     const scalar tol
00079 )
00080 {
00081     if (!valid())
00082     {
00083         // current not yet set so use any value
00084         distSqr_ = w2.distSqr();
00085         origin_ = w2.origin();
00086 
00087         return true;
00088     }        
00089 
00090     scalar diff = distSqr_ - w2.distSqr();
00091 
00092     if (diff < 0)
00093     {
00094         // already nearer to pt
00095         return false;
00096     }
00097 
00098     if ((diff < SMALL) || ((distSqr_ > SMALL) && (diff/distSqr_ < tol)))
00099     {
00100         // don't propagate small changes
00101         return false;
00102     }
00103     else
00104     {
00105         // update with new values
00106         distSqr_ =  w2.distSqr();
00107         origin_ = w2.origin();
00108 
00109         return true;
00110     }
00111 }
00112 
00113 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00114 
00115 // Null constructor
00116 inline Foam::pointEdgePoint::pointEdgePoint()
00117 :
00118     origin_(greatPoint),
00119     distSqr_(GREAT)
00120 {}
00121 
00122 
00123 // Construct from origin, distance
00124 inline Foam::pointEdgePoint::pointEdgePoint
00125 (
00126     const point& origin, 
00127     const scalar distSqr
00128 )
00129 :
00130     origin_(origin),
00131     distSqr_(distSqr)
00132 {}
00133 
00134 
00135 // Construct as copy
00136 inline Foam::pointEdgePoint::pointEdgePoint(const pointEdgePoint& wpt)
00137 :
00138     origin_(wpt.origin()),
00139     distSqr_(wpt.distSqr())
00140 {}
00141 
00142 
00143 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00144 
00145 inline const Foam::point& Foam::pointEdgePoint::origin() const
00146 {
00147     return origin_;
00148 }
00149 
00150 
00151 inline Foam::scalar Foam::pointEdgePoint::distSqr() const
00152 {
00153     return distSqr_;
00154 }
00155 
00156 
00157 inline bool Foam::pointEdgePoint::valid() const
00158 {
00159     return origin_ != greatPoint;
00160 }
00161 
00162 
00163 // Checks for cyclic points
00164 inline bool Foam::pointEdgePoint::sameGeometry
00165 (
00166     const pointEdgePoint& w2,
00167     const scalar tol
00168 ) const
00169 {
00170     scalar diff = Foam::mag(distSqr() - w2.distSqr());
00171 
00172     if (diff < SMALL)
00173     {
00174         return true;
00175     }
00176     else
00177     {
00178         if ((distSqr() > SMALL) && ((diff/distSqr()) < tol))
00179         {
00180             return true;
00181         }
00182         else
00183         {
00184             return false;
00185         }
00186     }
00187 }
00188 
00189 
00190 inline void Foam::pointEdgePoint::leaveDomain
00191 (
00192     const polyPatch& patch,
00193     const label patchPointI,
00194     const point& coord
00195 )
00196 {
00197     origin_ -= coord;
00198 }
00199 
00200 
00201 inline void Foam::pointEdgePoint::transform(const tensor& rotTensor)
00202 {
00203     origin_ = Foam::transform(rotTensor, origin_);
00204 }
00205 
00206 
00207 // Update absolute geometric quantities. Note that distance (distSqr_)
00208 // is not affected by leaving/entering domain.
00209 inline void Foam::pointEdgePoint::enterDomain
00210 (
00211     const polyPatch& patch,
00212     const label patchPointI,
00213     const point& coord
00214 )
00215 {
00216     // back to absolute form
00217     origin_ += coord;
00218 }
00219 
00220 
00221 // Update this with information from connected edge
00222 inline bool Foam::pointEdgePoint::updatePoint
00223 (
00224     const polyMesh& mesh,
00225     const label pointI,
00226     const label edgeI,
00227     const pointEdgePoint& edgeInfo,
00228     const scalar tol
00229 )
00230 {
00231     return 
00232         update
00233         (
00234             mesh.points()[pointI],
00235             edgeInfo,
00236             tol
00237         );
00238     }    
00239 
00240 
00241 // Update this with new information on same point
00242 inline bool Foam::pointEdgePoint::updatePoint
00243 (
00244     const polyMesh& mesh,
00245     const label pointI,
00246     const pointEdgePoint& newPointInfo,
00247     const scalar tol
00248 )
00249 {
00250     return
00251         update
00252         (
00253             mesh.points()[pointI],
00254             newPointInfo,
00255             tol
00256         );
00257 }    
00258 
00259 
00260 // Update this with new information on same point. No extra information.
00261 inline bool Foam::pointEdgePoint::updatePoint
00262 (
00263     const pointEdgePoint& newPointInfo,
00264     const scalar tol
00265 )
00266 {
00267     return update(newPointInfo, tol);
00268 }    
00269 
00270 
00271 // Update this with information from connected point
00272 inline bool Foam::pointEdgePoint::updateEdge
00273 (
00274     const polyMesh& mesh,
00275     const label edgeI,
00276     const label pointI,
00277     const pointEdgePoint& pointInfo,
00278     const scalar tol
00279 )
00280 {
00281     const pointField& points = mesh.points();
00282 
00283     const edge& e = mesh.edges()[edgeI];
00284 
00285     const point edgeMid(0.5*(points[e[0]] + points[e[1]]));
00286 
00287     return
00288         update
00289         (
00290             edgeMid,
00291             pointInfo,
00292             tol
00293         );
00294 }    
00295 
00296 
00297 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00298 
00299 inline bool Foam::pointEdgePoint::operator==(const Foam::pointEdgePoint& rhs)
00300  const
00301 {
00302     return origin() == rhs.origin();
00303 }
00304 
00305 
00306 inline bool Foam::pointEdgePoint::operator!=(const Foam::pointEdgePoint& rhs)
00307  const
00308 {
00309     return !(*this == rhs);
00310 }
00311 
00312 
00313 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines