1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 \*---------------------------------------------------------------------------*/
27 #include "transform.H"
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 // Returns the wanted level
33 inline Foam::label Foam::refinementDistanceData::wantedLevel(const point& pt)
36 const scalar distSqr = magSqr(pt-origin_);
38 // Get the size at the origin level
39 scalar levelSize = level0Size_/(1<<originLevel_);
43 for (label level = originLevel_; level >= 0; --level)
48 // Check if our distance is within influence sphere
54 // Lower level will have double the size
61 inline bool Foam::refinementDistanceData::update
64 const refinementDistanceData& neighbourInfo,
70 if (!neighbourInfo.valid())
72 FatalErrorIn("refinementDistanceData::update(..)")
73 << "problem" << abort(FatalError);
75 operator=(neighbourInfo);
79 // Determine wanted level at current position.
80 label cellLevel = wantedLevel(pos);
82 // Determine wanted level coming through the neighbour
83 label nbrLevel = neighbourInfo.wantedLevel(pos);
85 if (nbrLevel > cellLevel)
87 operator=(neighbourInfo);
90 else if (nbrLevel == cellLevel)
92 scalar myDistSqr = magSqr(pos-origin_);
93 scalar nbrDistSqr = magSqr(pos - neighbourInfo.origin());
94 scalar diff = myDistSqr - nbrDistSqr;
102 if ((diff < SMALL) || ((myDistSqr > SMALL) && (diff/myDistSqr < tol)))
104 // don't propagate small changes
109 // update with new values
110 operator=(neighbourInfo);
121 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
124 inline Foam::refinementDistanceData::refinementDistanceData()
130 // Construct from components
131 inline Foam::refinementDistanceData::refinementDistanceData
133 const scalar level0Size,
135 const label originLevel
138 level0Size_(level0Size),
140 originLevel_(originLevel)
144 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
146 inline bool Foam::refinementDistanceData::valid() const
148 return level0Size_ != -1;
152 // No geometric data so never any problem on cyclics
153 inline bool Foam::refinementDistanceData::sameGeometry
156 const refinementDistanceData&,
164 inline void Foam::refinementDistanceData::leaveDomain
167 const polyPatch& patch,
168 const label patchFaceI,
169 const point& faceCentre
172 origin_ -= faceCentre;
176 inline void Foam::refinementDistanceData::transform
179 const tensor& rotTensor
182 origin_ = Foam::transform(rotTensor, origin_);
186 // Update absolute geometric quantities.
187 inline void Foam::refinementDistanceData::enterDomain
190 const polyPatch& patch,
191 const label patchFaceI,
192 const point& faceCentre
195 // back to absolute form
196 origin_ += faceCentre;
200 // Update cell with neighbouring face information
201 inline bool Foam::refinementDistanceData::updateCell
203 const polyMesh& mesh,
204 const label thisCellI,
205 const label neighbourFaceI,
206 const refinementDistanceData& neighbourInfo,
210 const point& pos = mesh.cellCentres()[thisCellI];
212 return update(pos, neighbourInfo, tol);
216 // Update face with neighbouring cell information
217 inline bool Foam::refinementDistanceData::updateFace
219 const polyMesh& mesh,
220 const label thisFaceI,
221 const label neighbourCellI,
222 const refinementDistanceData& neighbourInfo,
226 const point& pos = mesh.faceCentres()[thisFaceI];
228 return update(pos, neighbourInfo, tol);
232 // Update face with coupled face information
233 inline bool Foam::refinementDistanceData::updateFace
235 const polyMesh& mesh,
236 const label thisFaceI,
237 const refinementDistanceData& neighbourInfo,
241 const point& pos = mesh.faceCentres()[thisFaceI];
243 return update(pos, neighbourInfo, tol);
247 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
249 inline bool Foam::refinementDistanceData::operator==
251 const Foam::refinementDistanceData& rhs
269 level0Size_ == rhs.level0Size_
270 && origin_ == rhs.origin_
271 && originLevel_ == rhs.originLevel_;
276 inline bool Foam::refinementDistanceData::operator!=
278 const Foam::refinementDistanceData& rhs
282 return !(*this == rhs);
286 // ************************************************************************* //