FreeFOAM The Cross-Platform CFD Toolkit
refinementDistanceDataI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include <OpenFOAM/transform.H>
27 #include <OpenFOAM/polyMesh.H>
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 // Returns the wanted level
32 inline Foam::label Foam::refinementDistanceData::wantedLevel(const point& pt)
33  const
34 {
35  const scalar distSqr = magSqr(pt-origin_);
36 
37  // Get the size at the origin level
38  scalar levelSize = level0Size_/(1<<originLevel_);
39 
40  scalar r = 0;
41 
42  for (label level = originLevel_; level >= 0; --level)
43  {
44  // Current range
45  r += levelSize;
46 
47  // Check if our distance is within influence sphere
48  if (sqr(r) > distSqr)
49  {
50  return level;
51  }
52 
53  // Lower level will have double the size
54  levelSize *= 2;
55  }
56  return 0;
57 }
58 
59 
60 inline bool Foam::refinementDistanceData::update
61 (
62  const point& pos,
63  const refinementDistanceData& neighbourInfo,
64  const scalar tol
65 )
66 {
67  if (!valid())
68  {
69  if (!neighbourInfo.valid())
70  {
71  FatalErrorIn("refinementDistanceData::update(..)")
72  << "problem" << abort(FatalError);
73  }
74  operator=(neighbourInfo);
75  return true;
76  }
77 
78  // Determine wanted level at current position.
79  label cellLevel = wantedLevel(pos);
80 
81  // Determine wanted level coming through the neighbour
82  label nbrLevel = neighbourInfo.wantedLevel(pos);
83 
84  if (nbrLevel > cellLevel)
85  {
86  operator=(neighbourInfo);
87  return true;
88  }
89  else if (nbrLevel == cellLevel)
90  {
91  scalar myDistSqr = magSqr(pos-origin_);
92  scalar nbrDistSqr = magSqr(pos - neighbourInfo.origin());
93  scalar diff = myDistSqr - nbrDistSqr;
94 
95  if (diff < 0)
96  {
97  // already nearest
98  return false;
99  }
100 
101  if ((diff < SMALL) || ((myDistSqr > SMALL) && (diff/myDistSqr < tol)))
102  {
103  // don't propagate small changes
104  return false;
105  }
106  else
107  {
108  // update with new values
109  operator=(neighbourInfo);
110  return true;
111  }
112  }
113  else
114  {
115  return false;
116  }
117 }
118 
119 
120 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
121 
122 // Null constructor
124 :
125  level0Size_(-1)
126 {}
127 
128 
129 // Construct from components
131 (
132  const scalar level0Size,
133  const point& origin,
134  const label originLevel
135 )
136 :
137  level0Size_(level0Size),
138  origin_(origin),
139  originLevel_(originLevel)
140 {}
141 
142 
143 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
144 
146 {
147  return level0Size_ != -1;
148 }
149 
150 
151 // No geometric data so never any problem on cyclics
153 (
154  const polyMesh&,
155  const refinementDistanceData&,
156  const scalar
157 ) const
158 {
159  return true;
160 }
161 
162 
164 (
165  const polyMesh&,
166  const polyPatch& patch,
167  const label patchFaceI,
168  const point& faceCentre
169 )
170 {
171  origin_ -= faceCentre;
172 }
173 
174 
176 (
177  const polyMesh&,
178  const tensor& rotTensor
179 )
180 {
181  origin_ = Foam::transform(rotTensor, origin_);
182 }
183 
184 
185 // Update absolute geometric quantities.
187 (
188  const polyMesh&,
189  const polyPatch& patch,
190  const label patchFaceI,
191  const point& faceCentre
192 )
193 {
194  // back to absolute form
195  origin_ += faceCentre;
196 }
197 
198 
199 // Update cell with neighbouring face information
201 (
202  const polyMesh& mesh,
203  const label thisCellI,
204  const label neighbourFaceI,
205  const refinementDistanceData& neighbourInfo,
206  const scalar tol
207 )
208 {
209  const point& pos = mesh.cellCentres()[thisCellI];
210 
211  return update(pos, neighbourInfo, tol);
212 }
213 
214 
215 // Update face with neighbouring cell information
217 (
218  const polyMesh& mesh,
219  const label thisFaceI,
220  const label neighbourCellI,
221  const refinementDistanceData& neighbourInfo,
222  const scalar tol
223 )
224 {
225  const point& pos = mesh.faceCentres()[thisFaceI];
226 
227  return update(pos, neighbourInfo, tol);
228 }
229 
230 
231 // Update face with coupled face information
233 (
234  const polyMesh& mesh,
235  const label thisFaceI,
236  const refinementDistanceData& neighbourInfo,
237  const scalar tol
238 )
239 {
240  const point& pos = mesh.faceCentres()[thisFaceI];
241 
242  return update(pos, neighbourInfo, tol);
243 }
244 
245 
246 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
247 
248 inline bool Foam::refinementDistanceData::operator==
249 (
251 )
252  const
253 {
254  if (!valid())
255  {
256  if (!rhs.valid())
257  {
258  return true;
259  }
260  else
261  {
262  return false;
263  }
264  }
265  else
266  {
267  return
268  level0Size_ == rhs.level0Size_
269  && origin_ == rhs.origin_
270  && originLevel_ == rhs.originLevel_;
271  }
272 }
273 
274 
275 inline bool Foam::refinementDistanceData::operator!=
276 (
278 )
279  const
280 {
281  return !(*this == rhs);
282 }
283 
284 
285 // ************************ vim: set sw=4 sts=4 et: ************************ //