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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "transform.H"
30 #include "polyMesh.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 // Returns the wanted level
36  const
37 {
38  const scalar distSqr = magSqr(pt-origin_);
39 
40  // Get the size at the origin level
41  scalar levelSize = level0Size_/(1<<originLevel_);
42 
43  scalar r = 0;
44 
45  for (label level = originLevel_; level >= 0; --level)
46  {
47  // Current range
48  r += levelSize;
49 
50  // Check if our distance is within influence sphere
51  if (sqr(r) > distSqr)
52  {
53  return level;
54  }
55 
56  // Lower level will have double the size
57  levelSize *= 2;
58  }
59  return 0;
60 }
61 
62 
63 template<class TrackingData>
64 inline bool Foam::refinementDistanceData::update
65 (
66  const point& pos,
67  const refinementDistanceData& neighbourInfo,
68  const scalar tol,
69  TrackingData& td
70 )
71 {
72  if (!valid(td))
73  {
74  if (!neighbourInfo.valid(td))
75  {
77  << "problem" << abort(FatalError);
78  }
79  operator=(neighbourInfo);
80  return true;
81  }
82 
83  // Determine wanted level at current position.
84  label cellLevel = wantedLevel(pos);
85 
86  // Determine wanted level coming through the neighbour
87  label nbrLevel = neighbourInfo.wantedLevel(pos);
88 
89  if (nbrLevel > cellLevel)
90  {
91  operator=(neighbourInfo);
92  return true;
93  }
94  else if (nbrLevel == cellLevel)
95  {
96  scalar myDistSqr = magSqr(pos-origin_);
97  scalar nbrDistSqr = magSqr(pos - neighbourInfo.origin());
98  scalar diff = myDistSqr - nbrDistSqr;
99 
100  if (diff < 0)
101  {
102  // already nearest
103  return false;
104  }
105 
106  if ((diff < SMALL) || ((myDistSqr > SMALL) && (diff/myDistSqr < tol)))
107  {
108  // don't propagate small changes
109  return false;
110  }
111  else
112  {
113  // update with new values
114  operator=(neighbourInfo);
115  return true;
116  }
117  }
118 
119  return false;
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 polyMesh&,
173  const polyPatch& patch,
174  const label patchFacei,
175  const point& faceCentre,
176  TrackingData& td
177 )
178 {
179  origin_ -= faceCentre;
180 }
181 
182 
183 template<class TrackingData>
185 (
186  const polyMesh&,
187  const tensor& rotTensor,
188  TrackingData& td
189 )
190 {
191  origin_ = Foam::transform(rotTensor, origin_);
192 }
193 
194 
195 // Update absolute geometric quantities.
196 template<class TrackingData>
198 (
199  const polyMesh&,
200  const polyPatch& patch,
201  const label patchFacei,
202  const point& faceCentre,
203  TrackingData& td
204 )
205 {
206  // back to absolute form
207  origin_ += faceCentre;
208 }
209 
210 
211 // Update cell with neighbouring face information
212 template<class TrackingData>
214 (
215  const polyMesh& mesh,
216  const label thisCelli,
217  const label neighbourFacei,
218  const refinementDistanceData& neighbourInfo,
219  const scalar tol,
220  TrackingData& td
221 )
222 {
223  const point& pos = mesh.cellCentres()[thisCelli];
224 
225  return update(pos, neighbourInfo, tol, td);
226 }
227 
228 
229 // Update face with neighbouring cell information
230 template<class TrackingData>
232 (
233  const polyMesh& mesh,
234  const label thisFacei,
235  const label neighbourCelli,
236  const refinementDistanceData& neighbourInfo,
237  const scalar tol,
238  TrackingData& td
239 )
240 {
241  const point& pos = mesh.faceCentres()[thisFacei];
242 
243  return update(pos, neighbourInfo, tol, td);
244 }
245 
246 
247 // Update face with coupled face information
248 template<class TrackingData>
250 (
251  const polyMesh& mesh,
252  const label thisFacei,
253  const refinementDistanceData& neighbourInfo,
254  const scalar tol,
255  TrackingData& td
256 )
257 {
258  const point& pos = mesh.faceCentres()[thisFacei];
259 
260  return update(pos, neighbourInfo, tol, td);
261 }
262 
263 
264 template<class TrackingData>
266 (
267  const refinementDistanceData& rhs,
268  TrackingData& td
269 ) const
270 {
271  if (!valid(td))
272  {
273  return (!rhs.valid(td));
274  }
275  else
276  {
277  return operator==(rhs);
278  }
279 }
280 
281 
282 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
283 
284 inline bool Foam::refinementDistanceData::operator==
285 (
287 ) const
288 {
289  return
290  level0Size_ == rhs.level0Size_
291  && origin_ == rhs.origin_
292  && originLevel_ == rhs.originLevel_;
293 }
294 
295 
296 inline bool Foam::refinementDistanceData::operator!=
297 (
299 ) const
300 {
301  return !(*this == rhs);
302 }
303 
304 
305 // ************************************************************************* //
Foam::Tensor< scalar >
Foam::refinementDistanceData::sameGeometry
bool sameGeometry(const polyMesh &, const refinementDistanceData &, const scalar, TrackingData &) const
Check for identical geometrical data. Used for cyclics checking.
Definition: refinementDistanceDataI.H:158
update
mesh update()
Foam::refinementDistanceData::updateCell
bool updateCell(const polyMesh &, const label thisCelli, const label neighbourFacei, const refinementDistanceData &neighbourInfo, const scalar tol, TrackingData &)
Influence of neighbouring face.
Definition: refinementDistanceDataI.H:214
Foam::refinementDistanceData::valid
bool valid(TrackingData &) const
Check whether origin has been changed at all or.
Definition: refinementDistanceDataI.H:149
Foam::refinementDistanceData::refinementDistanceData
refinementDistanceData()
Construct null.
Definition: refinementDistanceDataI.H:126
Foam::transform
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:519
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::refinementDistanceData
Transfers refinement levels such that slow transition between levels is maintained....
Definition: refinementDistanceData.H:63
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::diff
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
Definition: triad.C:378
Foam::label
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:62
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::refinementDistanceData::updateFace
bool updateFace(const polyMesh &, const label thisFacei, const label neighbourCelli, const refinementDistanceData &neighbourInfo, const scalar tol, TrackingData &)
Influence of neighbouring cell.
Definition: refinementDistanceDataI.H:232
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::refinementDistanceData::enterDomain
void enterDomain(const polyMesh &, const polyPatch &, const label patchFacei, const point &faceCentre, TrackingData &)
Reverse of leaveDomain.
Definition: refinementDistanceDataI.H:198
Foam::refinementDistanceData::transform
void transform(const polyMesh &, const tensor &, TrackingData &)
Apply rotation matrix to any coordinates.
Definition: refinementDistanceDataI.H:185
Foam::refinementDistanceData::equal
bool equal(const refinementDistanceData &, TrackingData &) const
Same (like operator==)
Definition: refinementDistanceDataI.H:266
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:176
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::Vector< scalar >
Foam::primitiveMesh::faceCentres
const vectorField & faceCentres() const
Definition: primitiveMeshFaceCentresAndAreas.C:145
Foam::refinementDistanceData::leaveDomain
void leaveDomain(const polyMesh &, const polyPatch &, const label patchFacei, const point &faceCentre, TrackingData &)
Convert any absolute coordinates into relative to (patch)face.
Definition: refinementDistanceDataI.H:171
transform.H
3D tensor transformation operations.
Foam::refinementDistanceData::origin
const point & origin() const
Definition: refinementDistanceData.H:117
Foam::refinementDistanceData::wantedLevel
label wantedLevel(const point &pt) const
Calculates the wanted level at a given point. Walks out from.
Definition: refinementDistanceDataI.H:35
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177