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

refinementDistanceDataI.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/transform.H>
00027 #include <OpenFOAM/polyMesh.H>
00028 
00029 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00030 
00031 // Returns the wanted level
00032 inline Foam::label Foam::refinementDistanceData::wantedLevel(const point& pt)
00033  const
00034 {
00035     const scalar distSqr = magSqr(pt-origin_);
00036 
00037     // Get the size at the origin level
00038     scalar levelSize = level0Size_/(1<<originLevel_);
00039 
00040     scalar r = 0;
00041 
00042     for (label level = originLevel_; level >= 0; --level)
00043     {
00044         // Current range
00045         r += levelSize;
00046 
00047         // Check if our distance is within influence sphere
00048         if (sqr(r) > distSqr)
00049         {
00050             return level;
00051         }
00052 
00053         // Lower level will have double the size
00054         levelSize *= 2;
00055     }
00056     return 0;
00057 }
00058 
00059 
00060 inline bool Foam::refinementDistanceData::update
00061 (
00062     const point& pos,
00063     const refinementDistanceData& neighbourInfo,
00064     const scalar tol
00065 )
00066 {
00067     if (!valid())
00068     {
00069         if (!neighbourInfo.valid())
00070         {
00071             FatalErrorIn("refinementDistanceData::update(..)")
00072                 << "problem" << abort(FatalError);
00073         }
00074         operator=(neighbourInfo);
00075         return true;
00076     }
00077 
00078     // Determine wanted level at current position.
00079     label cellLevel = wantedLevel(pos);
00080 
00081     // Determine wanted level coming through the neighbour
00082     label nbrLevel = neighbourInfo.wantedLevel(pos);
00083 
00084     if (nbrLevel > cellLevel)
00085     {
00086         operator=(neighbourInfo);
00087         return true;
00088     }
00089     else if (nbrLevel == cellLevel)
00090     {
00091         scalar myDistSqr = magSqr(pos-origin_);
00092         scalar nbrDistSqr = magSqr(pos - neighbourInfo.origin());
00093         scalar diff = myDistSqr - nbrDistSqr;
00094 
00095         if (diff < 0)
00096         {
00097             // already nearest
00098             return false;
00099         }
00100 
00101         if ((diff < SMALL) || ((myDistSqr > SMALL) && (diff/myDistSqr < tol)))
00102         {
00103             // don't propagate small changes
00104             return false;
00105         }
00106         else
00107         {
00108             // update with new values
00109             operator=(neighbourInfo);
00110             return true;
00111         }
00112     }
00113     else
00114     {
00115         return false;
00116     }
00117 }
00118 
00119 
00120 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00121 
00122 // Null constructor
00123 inline Foam::refinementDistanceData::refinementDistanceData()
00124 :
00125     level0Size_(-1)
00126 {}
00127 
00128 
00129 // Construct from components
00130 inline Foam::refinementDistanceData::refinementDistanceData
00131 (
00132     const scalar level0Size,
00133     const point& origin,
00134     const label originLevel
00135 )
00136 :
00137     level0Size_(level0Size),
00138     origin_(origin),
00139     originLevel_(originLevel)
00140 {}
00141 
00142 
00143 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00144 
00145 inline bool Foam::refinementDistanceData::valid() const
00146 {
00147     return level0Size_ != -1;
00148 }
00149 
00150 
00151 // No geometric data so never any problem on cyclics
00152 inline bool Foam::refinementDistanceData::sameGeometry
00153 (
00154     const polyMesh&,
00155     const refinementDistanceData&,
00156     const scalar
00157 ) const
00158 {
00159     return true;
00160 }
00161 
00162 
00163 inline void Foam::refinementDistanceData::leaveDomain
00164 (
00165     const polyMesh&,
00166     const polyPatch& patch,
00167     const label patchFaceI,
00168     const point& faceCentre
00169 )
00170 {
00171     origin_ -= faceCentre;
00172 }
00173 
00174 
00175 inline void Foam::refinementDistanceData::transform
00176 (
00177     const polyMesh&,
00178     const tensor& rotTensor
00179 )
00180 {
00181     origin_ = Foam::transform(rotTensor, origin_);
00182 }
00183 
00184 
00185 // Update absolute geometric quantities.
00186 inline void Foam::refinementDistanceData::enterDomain
00187 (
00188     const polyMesh&,
00189     const polyPatch& patch,
00190     const label patchFaceI,
00191     const point& faceCentre
00192 )
00193 {
00194     // back to absolute form
00195     origin_ += faceCentre;
00196 }
00197 
00198 
00199 // Update cell with neighbouring face information
00200 inline bool Foam::refinementDistanceData::updateCell
00201 (
00202     const polyMesh& mesh,
00203     const label thisCellI,
00204     const label neighbourFaceI,
00205     const refinementDistanceData& neighbourInfo,
00206     const scalar tol
00207 )
00208 {
00209     const point& pos = mesh.cellCentres()[thisCellI];
00210 
00211     return update(pos, neighbourInfo, tol);
00212 }
00213 
00214 
00215 // Update face with neighbouring cell information
00216 inline bool Foam::refinementDistanceData::updateFace
00217 (
00218     const polyMesh& mesh,
00219     const label thisFaceI,
00220     const label neighbourCellI,
00221     const refinementDistanceData& neighbourInfo,
00222     const scalar tol
00223 )
00224 {
00225     const point& pos = mesh.faceCentres()[thisFaceI];
00226 
00227     return update(pos, neighbourInfo, tol);
00228 }
00229 
00230 
00231 // Update face with coupled face information
00232 inline bool Foam::refinementDistanceData::updateFace
00233 (
00234     const polyMesh& mesh,
00235     const label thisFaceI,
00236     const refinementDistanceData& neighbourInfo,
00237     const scalar tol
00238 )
00239 {
00240     const point& pos = mesh.faceCentres()[thisFaceI];
00241 
00242     return update(pos, neighbourInfo, tol);
00243 }    
00244 
00245 
00246 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00247 
00248 inline bool Foam::refinementDistanceData::operator==
00249 (
00250     const Foam::refinementDistanceData& rhs
00251 )
00252  const
00253 {
00254     if (!valid())
00255     {
00256         if (!rhs.valid())
00257         {
00258             return true;
00259         }
00260         else
00261         {
00262             return false;
00263         }
00264     }
00265     else
00266     {
00267         return
00268             level0Size_ == rhs.level0Size_
00269          && origin_ == rhs.origin_
00270          && originLevel_ == rhs.originLevel_;
00271     }
00272 }
00273 
00274 
00275 inline bool Foam::refinementDistanceData::operator!=
00276 (
00277     const Foam::refinementDistanceData& rhs
00278 )
00279  const
00280 {
00281     return !(*this == rhs);
00282 }
00283 
00284 
00285 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines