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) 2011-2013 OpenFOAM Foundation
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 "transform.H"
27 #include "polyMesh.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 // Returns the wanted level
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 template<class TrackingData>
61 inline bool Foam::refinementDistanceData::update
62 (
63  const point& pos,
64  const refinementDistanceData& neighbourInfo,
65  const scalar tol,
66  TrackingData& td
67 )
68 {
69  if (!valid(td))
70  {
71  if (!neighbourInfo.valid(td))
72  {
73  FatalErrorIn("refinementDistanceData::update(..)")
74  << "problem" << abort(FatalError);
75  }
76  operator=(neighbourInfo);
77  return true;
78  }
79 
80  // Determine wanted level at current position.
81  label cellLevel = wantedLevel(pos);
82 
83  // Determine wanted level coming through the neighbour
84  label nbrLevel = neighbourInfo.wantedLevel(pos);
85 
86  if (nbrLevel > cellLevel)
87  {
88  operator=(neighbourInfo);
89  return true;
90  }
91  else if (nbrLevel == cellLevel)
92  {
93  scalar myDistSqr = magSqr(pos-origin_);
94  scalar nbrDistSqr = magSqr(pos - neighbourInfo.origin());
95  scalar diff = myDistSqr - nbrDistSqr;
96 
97  if (diff < 0)
98  {
99  // already nearest
100  return false;
101  }
102 
103  if ((diff < SMALL) || ((myDistSqr > SMALL) && (diff/myDistSqr < tol)))
104  {
105  // don't propagate small changes
106  return false;
107  }
108  else
109  {
110  // update with new values
111  operator=(neighbourInfo);
112  return true;
113  }
114  }
115  else
116  {
117  return false;
118  }
119 }
120 
121 
122 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
123 
124 // Null constructor
126 :
127  level0Size_(-1)
128 {}
129 
130 
131 // Construct from components
133 (
134  const scalar level0Size,
135  const point& origin,
136  const label originLevel
137 )
138 :
139  level0Size_(level0Size),
140  origin_(origin),
141  originLevel_(originLevel)
142 {}
143 
144 
145 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
146 
147 template<class TrackingData>
148 inline bool Foam::refinementDistanceData::valid(TrackingData& td) const
149 {
150  return level0Size_ != -1;
151 }
152 
153 
154 // No geometric data so never any problem on cyclics
155 template<class TrackingData>
157 (
158  const polyMesh&,
159  const refinementDistanceData&,
160  const scalar,
161  TrackingData& td
162 ) const
163 {
164  return true;
165 }
166 
167 
168 template<class TrackingData>
170 (
171  const polyMesh&,
172  const polyPatch& patch,
173  const label patchFaceI,
174  const point& faceCentre,
175  TrackingData& td
176 )
177 {
178  origin_ -= faceCentre;
179 }
180 
181 
182 template<class TrackingData>
184 (
185  const polyMesh&,
186  const tensor& rotTensor,
187  TrackingData& td
188 )
189 {
190  origin_ = Foam::transform(rotTensor, origin_);
191 }
192 
193 
194 // Update absolute geometric quantities.
195 template<class TrackingData>
197 (
198  const polyMesh&,
199  const polyPatch& patch,
200  const label patchFaceI,
201  const point& faceCentre,
202  TrackingData& td
203 )
204 {
205  // back to absolute form
206  origin_ += faceCentre;
207 }
208 
209 
210 // Update cell with neighbouring face information
211 template<class TrackingData>
213 (
214  const polyMesh& mesh,
215  const label thisCellI,
216  const label neighbourFaceI,
217  const refinementDistanceData& neighbourInfo,
218  const scalar tol,
219  TrackingData& td
220 )
221 {
222  const point& pos = mesh.cellCentres()[thisCellI];
223 
224  return update(pos, neighbourInfo, tol, td);
225 }
226 
227 
228 // Update face with neighbouring cell information
229 template<class TrackingData>
231 (
232  const polyMesh& mesh,
233  const label thisFaceI,
234  const label neighbourCellI,
235  const refinementDistanceData& neighbourInfo,
236  const scalar tol,
237  TrackingData& td
238 )
239 {
240  const point& pos = mesh.faceCentres()[thisFaceI];
241 
242  return update(pos, neighbourInfo, tol, td);
243 }
244 
245 
246 // Update face with coupled face information
247 template<class TrackingData>
249 (
250  const polyMesh& mesh,
251  const label thisFaceI,
252  const refinementDistanceData& neighbourInfo,
253  const scalar tol,
254  TrackingData& td
255 )
256 {
257  const point& pos = mesh.faceCentres()[thisFaceI];
258 
259  return update(pos, neighbourInfo, tol, td);
260 }
261 
262 
263 template<class TrackingData>
265 (
266  const refinementDistanceData& rhs,
267  TrackingData& td
268 ) const
269 {
270  if (!valid(td))
271  {
272  if (!rhs.valid(td))
273  {
274  return true;
275  }
276  else
277  {
278  return false;
279  }
280  }
281  else
282  {
283  return operator==(rhs);
284  }
285 }
286 
287 
288 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
289 
290 inline bool Foam::refinementDistanceData::operator==
291 (
293 )
294  const
295 {
296  return
297  level0Size_ == rhs.level0Size_
298  && origin_ == rhs.origin_
299  && originLevel_ == rhs.originLevel_;
300 }
301 
302 
303 inline bool Foam::refinementDistanceData::operator!=
304 (
306 )
307  const
308 {
309  return !(*this == rhs);
310 }
311 
312 
313 // ************************************************************************* //
bool equal(const refinementDistanceData &, TrackingData &) const
Same (like operator==)
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
Definition: triad.C:407
dimensioned< scalar > magSqr(const dimensioned< Type > &)
bool updateFace(const polyMesh &, const label thisFaceI, const label neighbourCellI, const refinementDistanceData &neighbourInfo, const scalar tol, TrackingData &)
Influence of neighbouring cell.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
bool valid(TrackingData &) const
Check whether origin has been changed at all or.
void leaveDomain(const polyMesh &, const polyPatch &, const label patchFaceI, const point &faceCentre, TrackingData &)
Convert any absolute coordinates into relative to (patch)face.
const vectorField & cellCentres() const
bool operator==(const refinementDistanceData &) const
void transform(const polyMesh &, const tensor &, TrackingData &)
Apply rotation matrix to any coordinates.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Transfers refinement levels such that slow transition between levels is maintained. Used in FaceCellWave.
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:465
void enterDomain(const polyMesh &, const polyPatch &, const label patchFaceI, const point &faceCentre, TrackingData &)
Reverse of leaveDomain.
bool updateCell(const polyMesh &, const label thisCellI, const label neighbourFaceI, const refinementDistanceData &neighbourInfo, const scalar tol, TrackingData &)
Influence of neighbouring face.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
bool sameGeometry(const polyMesh &, const refinementDistanceData &, const scalar, TrackingData &) const
Check for identical geometrical data. Used for cyclics checking.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
error FatalError
label wantedLevel(const point &pt) const
Calculates the wanted level at a given point. Walks out from.
3D tensor transformation operations.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
const vectorField & faceCentres() const