Loading...
Searching...
No Matches
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-2020,2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
35(
36 const point& pt
37) const
38{
39 const scalar distSqr = magSqr(pt-origin_);
40
41 // Get the size at the origin level
42 scalar levelSize = level0Size_/(1<<originLevel_);
43
44 scalar r = 0;
45
46 for (label level = originLevel_; level >= 0; --level)
47 {
48 // Current range
49 r += levelSize;
50
51 // Check if our distance is within influence sphere
52 if (sqr(r) > distSqr)
53 {
54 return level;
55 }
56
57 // Lower level will have double the size
58 levelSize *= 2;
59 }
60 return 0;
61}
62
63
64template<class TrackingData>
65inline bool Foam::refinementDistanceData::update
66(
67 const point& pos,
68 const refinementDistanceData& neighbourInfo,
69 const scalar tol,
70 TrackingData& td
71)
72{
73 if (!valid(td))
74 {
75 if (!neighbourInfo.valid(td))
76 {
78 << "problem" << abort(FatalError);
79 }
80 operator=(neighbourInfo);
81 return true;
82 }
83
84 // Determine wanted level at current position.
85 label cellLevel = wantedLevel(pos);
86
87 // Determine wanted level coming through the neighbour
88 label nbrLevel = neighbourInfo.wantedLevel(pos);
89
90 if (nbrLevel > cellLevel)
91 {
92 operator=(neighbourInfo);
93 return true;
94 }
95 else if (nbrLevel == cellLevel)
96 {
97 scalar myDistSqr = magSqr(pos-origin_);
98 scalar nbrDistSqr = magSqr(pos - neighbourInfo.origin());
99 scalar diff = myDistSqr - nbrDistSqr;
100
101 if (diff < 0)
102 {
103 // already nearest
104 return false;
105 }
106
107 if ((diff < SMALL) || ((myDistSqr > SMALL) && (diff/myDistSqr < tol)))
108 {
109 // don't propagate small changes
110 return false;
111 }
112 else
113 {
114 // update with new values
115 operator=(neighbourInfo);
116 return true;
117 }
118 }
120 return false;
121}
122
123
124// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
127:
128 level0Size_(-1)
129{}
130
131
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
147template<class TrackingData>
148inline bool Foam::refinementDistanceData::valid(TrackingData& td) const
150 return level0Size_ != -1;
151}
152
153
154// No geometric data so never any problem on cyclics
155template<class TrackingData>
157(
158 const polyMesh&,
160 const scalar,
161 TrackingData& td
162) const
163{
164 return true;
165}
166
167
168template<class TrackingData>
170(
171 const polyMesh&,
172 const polyPatch& patch,
173 const label patchFacei,
174 const point& faceCentre,
175 TrackingData& td
177{
178 origin_ -= faceCentre;
179}
180
181
182template<class TrackingData>
184(
185 const polyMesh&,
186 const tensor& rotTensor,
187 TrackingData& td
188)
190 origin_ = Foam::transform(rotTensor, origin_);
191}
192
193
194// Update absolute geometric quantities.
195template<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
211template<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];
224 return update(pos, neighbourInfo, tol, td);
225}
226
227
228// Update face with neighbouring cell information
229template<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];
242 return update(pos, neighbourInfo, tol, td);
243}
244
245
246// Update face with coupled face information
247template<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
263template<class TrackingData>
265(
267 TrackingData& td
268) const
269{
270 if (!valid(td))
271 {
272 return (!rhs.valid(td));
273 }
274 else
276 return operator==(rhs);
277 }
278}
279
280
281template<class TrackingData>
283(
284 const polyMesh&,
285 const point& pt,
286 const label i0,
287 const refinementDistanceData& f0,
288 const label i1,
289 const refinementDistanceData& f1,
290 const scalar weight,
291 const scalar tol,
292 TrackingData& td
293)
294{
295 if (f0.valid(td))
296 {
297 return update(pt, f0, tol, td);
298 }
299 if (f1.valid(td))
300 {
301 return update(pt, f1, tol, td);
302 }
303 else
304 {
305 return false;
306 }
307}
308
309
310// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
311
312inline bool Foam::refinementDistanceData::operator==
313(
314 const refinementDistanceData& rhs
315) const
316{
317 return
318 level0Size_ == rhs.level0Size_
319 && origin_ == rhs.origin_
320 && originLevel_ == rhs.originLevel_;
321}
322
323
324inline bool Foam::refinementDistanceData::operator!=
325(
327) const
328{
329 return !(*this == rhs);
330}
331
332
333// ************************************************************************* //
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
Transfers refinement levels such that slow transition between levels is maintained....
bool interpolate(const polyMesh &, const point &pt, const label i0, const refinementDistanceData &f0, const label i1, const refinementDistanceData &f1, const scalar weight, const scalar tol, TrackingData &td)
Interpolate between two values (lerp). Returns true if causes changes. Not sure if needs to be specia...
bool updateCell(const polyMesh &, const label thisCelli, const label neighbourFacei, const refinementDistanceData &neighbourInfo, const scalar tol, TrackingData &)
Influence of neighbouring face.
void leaveDomain(const polyMesh &, const polyPatch &, const label patchFacei, const point &faceCentre, TrackingData &)
Convert any absolute coordinates into relative to (patch)face.
bool sameGeometry(const polyMesh &, const refinementDistanceData &, const scalar, TrackingData &) const
Check for identical geometrical data (eg, 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.
bool valid(TrackingData &) const
Changed or contains original (invalid) value.
void enterDomain(const polyMesh &, const polyPatch &, const label patchFacei, const point &faceCentre, TrackingData &)
Reverse of leaveDomain.
void transform(const polyMesh &, const tensor &, TrackingData &)
Apply rotation matrix to any coordinates.
bool equal(const refinementDistanceData &, TrackingData &) const
Test for equality, with TrackingData.
mesh update()
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
wallPoints::trackData td(isBlockedFace, regionToBlockSize)
dimensionedScalar pos(const dimensionedScalar &ds)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
refinementData transform(const tensor &, const refinementData val)
No-op rotational transform for base types.
Tensor< scalar > tensor
Definition symmTensor.H:57
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
Definition triad.C:373
errorManip< error > abort(error &err)
Definition errorManip.H:139
vector point
Point is a vector.
Definition point.H:37
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
3D tensor transformation operations.