OpenFOAM logo
Open Source CFD Toolkit

wallPointI.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-2005 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "polyMesh.H"
00028 #include "transform.H"
00029 
00030 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00031 
00032 // Update this with w2 if w2 nearer to pt.
00033 inline bool Foam::wallPoint::update
00034 (
00035     const point& pt,
00036     const wallPoint& w2,
00037     const scalar tol
00038 )
00039 {
00040     //Already done in calling algorithm
00041     //if (w2.origin() == origin_)
00042     //{
00043     //    // Shortcut. Same input so same distance.
00044     //    return false;
00045     //}
00046 
00047     scalar dist2 = magSqr(pt - w2.origin());
00048 
00049     if (!valid())
00050     {
00051         // current not yet set so use any value
00052         distSqr_ = dist2;
00053         origin_ = w2.origin();
00054 
00055         return true;
00056     }        
00057 
00058     scalar diff = distSqr_ - dist2;
00059 
00060     if (diff < 0)
00061     {
00062         // already nearer to pt
00063         return false;
00064     }
00065 
00066     if ((diff < SMALL) || ((distSqr_ > SMALL) && (diff/distSqr_ < tol)))
00067     {
00068         // don't propagate small changes
00069         return false;
00070     }
00071     else
00072     {
00073         // update with new values
00074         distSqr_ = dist2;
00075         origin_ = w2.origin();
00076 
00077         return true;
00078     }
00079 }
00080     
00081 
00082 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00083 
00084 // Null constructor
00085 inline Foam::wallPoint::wallPoint()
00086 :
00087     origin_(greatPoint),
00088     distSqr_(GREAT)
00089 {}
00090 
00091 
00092 // Construct from origin, distance
00093 inline Foam::wallPoint::wallPoint(const point& origin, const scalar distSqr)
00094 :
00095     origin_(origin), distSqr_(distSqr)
00096 {}
00097 
00098 
00099 // Construct as copy
00100 inline Foam::wallPoint::wallPoint(const wallPoint& wpt)
00101 :
00102     origin_(wpt.origin()), distSqr_(wpt.distSqr())
00103 {}
00104 
00105 
00106 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00107 
00108 inline const Foam::point& Foam::wallPoint::origin() const
00109 {
00110     return origin_;
00111 }
00112 
00113 
00114 inline Foam::point& Foam::wallPoint::origin()
00115 {
00116     return origin_;
00117 }
00118 
00119 
00120 inline Foam::scalar Foam::wallPoint::distSqr() const
00121 {
00122     return distSqr_;
00123 }
00124 
00125 
00126 inline Foam::scalar& Foam::wallPoint::distSqr()
00127 {
00128     return distSqr_;
00129 }
00130 
00131 
00132 inline bool Foam::wallPoint::valid() const
00133 {
00134     return origin_ != greatPoint;
00135 }
00136 
00137 
00138 // Checks for cyclic faces
00139 inline bool Foam::wallPoint::sameGeometry(const wallPoint& w2, const scalar tol)
00140  const
00141 {
00142     scalar diff = mag(distSqr() - w2.distSqr());
00143 
00144     if (diff < SMALL)
00145     {
00146         return true;
00147     }
00148     else
00149     {
00150         if ((distSqr() > SMALL) && ((diff/distSqr()) < tol))
00151         {
00152             return true;
00153         }
00154         else
00155         {
00156             return false;
00157         }
00158     }
00159 }
00160 
00161 
00162 inline void Foam::wallPoint::leaveDomain
00163 (
00164     const polyPatch&,
00165     const label,
00166     const point& faceCentre
00167 )
00168 {
00169     origin_ -= faceCentre;
00170 }
00171 
00172 
00173 inline void Foam::wallPoint::transform
00174 (
00175     const tensor& rotTensor
00176 )
00177 {
00178     origin_ = Foam::transform(rotTensor, origin_);
00179 }
00180 
00181 
00182 // Update absolute geometric quantities. Note that distance (distSqr_)
00183 // is not affected by leaving/entering domain.
00184 inline void Foam::wallPoint::enterDomain
00185 (
00186     const polyPatch&,
00187     const label,
00188     const point& faceCentre
00189 )
00190 {
00191     // back to absolute form
00192     origin_ += faceCentre;
00193 }
00194 
00195 
00196 // Update this with w2 if w2 nearer to pt.
00197 inline bool Foam::wallPoint::updateCell
00198 (
00199     const polyMesh& mesh,
00200     const label thisCellI,
00201     const label neighbourFaceI,
00202     const wallPoint& neighbourWallInfo,
00203     const scalar tol
00204 )
00205 {
00206     const vectorField& cellCentres = mesh.primitiveMesh::cellCentres();
00207 
00208     return 
00209         update
00210         (
00211             cellCentres[thisCellI],
00212             neighbourWallInfo,
00213             tol
00214         );
00215     }    
00216 
00217 
00218 // Update this with w2 if w2 nearer to pt.
00219 inline bool Foam::wallPoint::updateFace
00220 (
00221     const polyMesh& mesh,
00222     const label thisFaceI,
00223     const label neighbourCellI,
00224     const wallPoint& neighbourWallInfo,
00225     const scalar tol
00226 )
00227 {
00228     const vectorField& faceCentres = mesh.faceCentres();
00229 
00230     return
00231         update
00232         (
00233             faceCentres[thisFaceI],
00234             neighbourWallInfo,
00235             tol
00236         );
00237 }    
00238 
00239 // Update this with w2 if w2 nearer to pt.
00240 inline bool Foam::wallPoint::updateFace
00241 (
00242     const polyMesh& mesh,
00243     const label thisFaceI,
00244     const wallPoint& neighbourWallInfo,
00245     const scalar tol
00246 )
00247 {
00248     const vectorField& faceCentres = mesh.faceCentres();
00249 
00250     return
00251         update
00252         (
00253             faceCentres[thisFaceI],
00254             neighbourWallInfo,
00255             tol
00256         );
00257 }    
00258 
00259 
00260 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00261 
00262 inline bool Foam::wallPoint::operator==(const Foam::wallPoint& rhs) const
00263 {
00264     return origin() == rhs.origin();
00265 }
00266 
00267 
00268 inline bool Foam::wallPoint::operator!=(const Foam::wallPoint& rhs) const
00269 {
00270     return !(*this == rhs);
00271 }
00272 
00273 
00274 // ************************************************************************* //
For further information go to www.openfoam.org