initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / dynamicMesh / polyTopoChange / polyTopoChange / refinementDistanceDataI.H
blobafe234a80f42f9d1dc7326c6843af95f6909fe5d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
28 #include "polyMesh.H"
30 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
32 // Returns the wanted level
33 inline Foam::label Foam::refinementDistanceData::wantedLevel(const point& pt)
34  const
36     const scalar distSqr = magSqr(pt-origin_);
38     // Get the size at the origin level
39     scalar levelSize = level0Size_/(1<<originLevel_);
41     scalar r = 0;
43     for (label level = originLevel_; level >= 0; --level)
44     {
45         // Current range
46         r += levelSize;
48         // Check if our distance is within influence sphere
49         if (sqr(r) > distSqr)
50         {
51             return level;
52         }
54         // Lower level will have double the size
55         levelSize *= 2;
56     }
57     return 0;
61 inline bool Foam::refinementDistanceData::update
63     const point& pos,
64     const refinementDistanceData& neighbourInfo,
65     const scalar tol
68     if (!valid())
69     {
70         if (!neighbourInfo.valid())
71         {
72             FatalErrorIn("refinementDistanceData::update(..)")
73                 << "problem" << abort(FatalError);
74         }
75         operator=(neighbourInfo);
76         return true;
77     }
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)
86     {
87         operator=(neighbourInfo);
88         return true;
89     }
90     else if (nbrLevel == cellLevel)
91     {
92         scalar myDistSqr = magSqr(pos-origin_);
93         scalar nbrDistSqr = magSqr(pos - neighbourInfo.origin());
94         scalar diff = myDistSqr - nbrDistSqr;
96         if (diff < 0)
97         {
98             // already nearest
99             return false;
100         }
102         if ((diff < SMALL) || ((myDistSqr > SMALL) && (diff/myDistSqr < tol)))
103         {
104             // don't propagate small changes
105             return false;
106         }
107         else
108         {
109             // update with new values
110             operator=(neighbourInfo);
111             return true;
112         }
113     }
114     else
115     {
116         return false;
117     }
121 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
123 // Null constructor
124 inline Foam::refinementDistanceData::refinementDistanceData()
126     level0Size_(-1)
130 // Construct from components
131 inline Foam::refinementDistanceData::refinementDistanceData
133     const scalar level0Size,
134     const point& origin,
135     const label originLevel
138     level0Size_(level0Size),
139     origin_(origin),
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
155     const polyMesh&,
156     const refinementDistanceData&,
157     const scalar
158 ) const
160     return true;
164 inline void Foam::refinementDistanceData::leaveDomain
166     const polyMesh&,
167     const polyPatch& patch,
168     const label patchFaceI,
169     const point& faceCentre
172     origin_ -= faceCentre;
176 inline void Foam::refinementDistanceData::transform
178     const polyMesh&,
179     const tensor& rotTensor
182     origin_ = Foam::transform(rotTensor, origin_);
186 // Update absolute geometric quantities.
187 inline void Foam::refinementDistanceData::enterDomain
189     const polyMesh&,
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,
207     const scalar tol
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,
223     const scalar tol
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,
238     const scalar tol
241     const point& pos = mesh.faceCentres()[thisFaceI];
243     return update(pos, neighbourInfo, tol);
244 }    
247 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
249 inline bool Foam::refinementDistanceData::operator==
251     const Foam::refinementDistanceData& rhs
253  const
255     if (!valid())
256     {
257         if (!rhs.valid())
258         {
259             return true;
260         }
261         else
262         {
263             return false;
264         }
265     }
266     else
267     {
268         return
269             level0Size_ == rhs.level0Size_
270          && origin_ == rhs.origin_
271          && originLevel_ == rhs.originLevel_;
272     }
276 inline bool Foam::refinementDistanceData::operator!=
278     const Foam::refinementDistanceData& rhs
280  const
282     return !(*this == rhs);
286 // ************************************************************************* //