OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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