refinementDistanceDataI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 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 "transformer.H"
27 #include "polyMesh.H"
28 #include "SubField.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 // Returns the wanted level
34  const
35 {
36  const scalar distSqr = magSqr(pt-origin_);
37 
38  // Get the size at the origin level
39  scalar levelSize = level0Size_/(1<<originLevel_);
40 
41  scalar r = 0;
42 
43  for (label level = originLevel_; level >= 0; --level)
44  {
45  // Current range
46  r += levelSize;
47 
48  // Check if our distance is within influence sphere
49  if (sqr(r) > distSqr)
50  {
51  return level;
52  }
53 
54  // Lower level will have double the size
55  levelSize *= 2;
56  }
57  return 0;
58 }
59 
60 
61 template<class TrackingData>
62 inline bool Foam::refinementDistanceData::update
63 (
64  const point& pos,
65  const refinementDistanceData& neighbourInfo,
66  const scalar tol,
67  TrackingData& td
68 )
69 {
70  if (!valid(td))
71  {
72  if (!neighbourInfo.valid(td))
73  {
75  << "problem" << abort(FatalError);
76  }
77  operator=(neighbourInfo);
78  return true;
79  }
80 
81  // Determine wanted level at current position.
82  label cellLevel = wantedLevel(pos);
83 
84  // Determine wanted level coming through the neighbour
85  label nbrLevel = neighbourInfo.wantedLevel(pos);
86 
87  if (nbrLevel > cellLevel)
88  {
89  operator=(neighbourInfo);
90  return true;
91  }
92  else if (nbrLevel == cellLevel)
93  {
94  scalar myDistSqr = magSqr(pos-origin_);
95  scalar nbrDistSqr = magSqr(pos - neighbourInfo.origin());
96  scalar diff = myDistSqr - nbrDistSqr;
97 
98  if (diff < 0)
99  {
100  // already nearest
101  return false;
102  }
103 
104  if ((diff < small) || ((myDistSqr > small) && (diff/myDistSqr < tol)))
105  {
106  // don't propagate small changes
107  return false;
108  }
109  else
110  {
111  // update with new values
112  operator=(neighbourInfo);
113  return true;
114  }
115  }
116  else
117  {
118  return false;
119  }
120 }
121 
122 
123 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
124 
125 // Null constructor
127 :
128  level0Size_(-1)
129 {}
130 
131 
132 // Construct from components
134 (
135  const scalar level0Size,
136  const point& origin,
137  const label originLevel
138 )
139 :
140  level0Size_(level0Size),
141  origin_(origin),
142  originLevel_(originLevel)
143 {}
144 
145 
146 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
147 
148 template<class TrackingData>
149 inline bool Foam::refinementDistanceData::valid(TrackingData& td) const
150 {
151  return level0Size_ != -1;
152 }
153 
154 
155 // No geometric data so never any problem on cyclics
156 template<class TrackingData>
158 (
159  const polyMesh&,
160  const refinementDistanceData&,
161  const scalar,
162  TrackingData& td
163 ) const
164 {
165  return true;
166 }
167 
168 
169 template<class TrackingData>
171 (
172  const polyPatch& patch,
173  const label patchFacei,
174  const transformer& transform,
175  TrackingData& td
176 )
177 {
178  origin_ = transform.transformPosition(origin_);
179 }
180 
181 
182 template<class TrackingData>
184 (
185  const polyMesh& mesh,
186  const label thisCelli,
187  const label neighbourFacei,
188  const refinementDistanceData& neighbourInfo,
189  const scalar tol,
190  TrackingData& td
191 )
192 {
193  const point& pos = mesh.cellCentres()[thisCelli];
194 
195  return update(pos, neighbourInfo, tol, td);
196 }
197 
198 
199 // Update face with neighbouring cell information
200 template<class TrackingData>
202 (
203  const polyMesh& mesh,
204  const label thisFacei,
205  const label neighbourCelli,
206  const refinementDistanceData& neighbourInfo,
207  const scalar tol,
208  TrackingData& td
209 )
210 {
211  const point& pos = mesh.faceCentres()[thisFacei];
212 
213  return update(pos, neighbourInfo, tol, td);
214 }
215 
216 
217 // Update face with coupled face information
218 template<class TrackingData>
220 (
221  const polyMesh& mesh,
222  const label thisFacei,
223  const refinementDistanceData& neighbourInfo,
224  const scalar tol,
225  TrackingData& td
226 )
227 {
228  const point& pos = mesh.faceCentres()[thisFacei];
229 
230  return update(pos, neighbourInfo, tol, td);
231 }
232 
233 
234 template<class TrackingData>
236 (
237  const refinementDistanceData& rhs,
238  TrackingData& td
239 ) const
240 {
241  if (!valid(td))
242  {
243  if (!rhs.valid(td))
244  {
245  return true;
246  }
247  else
248  {
249  return false;
250  }
251  }
252  else
253  {
254  return operator==(rhs);
255  }
256 }
257 
258 
259 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
260 
261 inline bool Foam::refinementDistanceData::operator==
262 (
264 )
265  const
266 {
267  return
268  level0Size_ == rhs.level0Size_
269  && origin_ == rhs.origin_
270  && originLevel_ == rhs.originLevel_;
271 }
272 
273 
274 inline bool Foam::refinementDistanceData::operator!=
275 (
277 )
278  const
279 {
280  return !(*this == rhs);
281 }
282 
283 
284 // ************************************************************************* //
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
const vectorField & faceCentres() const
const vectorField & cellCentres() const
Transfers refinement levels such that slow transition between levels is maintained....
bool updateCell(const polyMesh &, const label thisCelli, const label neighbourFacei, const refinementDistanceData &neighbourInfo, const scalar tol, TrackingData &)
Influence of neighbouring face.
bool sameGeometry(const polyMesh &, const refinementDistanceData &, const scalar, TrackingData &) const
Check for identical geometrical data. Used for cyclics checking.
bool updateFace(const polyMesh &, const label thisFacei, const label neighbourCelli, const refinementDistanceData &neighbourInfo, const scalar tol, TrackingData &)
Influence of neighbouring cell.
label wantedLevel(const point &pt) const
Calculates the wanted level at a given point. Walks out from.
bool valid(TrackingData &) const
Check whether origin has been changed at all or.
void transform(const polyPatch &patch, const label patchFacei, const transformer &transform, TrackingData &td)
Transform across an interface.
bool equal(const refinementDistanceData &, TrackingData &) const
Same (like operator==)
Vector-tensor class used to perform translations, rotations and scaling operations in 3D space.
Definition: transformer.H:84
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
bool valid(const PtrList< ModelType > &l)
dimensionedScalar pos(const dimensionedScalar &ds)
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
dimensionedSymmTensor sqr(const dimensionedVector &dv)
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
errorManip< error > abort(error &err)
Definition: errorManip.H:131
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
Definition: triad.C:409
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:504
error FatalError
dimensioned< scalar > magSqr(const dimensioned< Type > &)