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 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>
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 }
119
120 return false;
121}
122
123
124// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
125
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
149{
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
176)
177{
178 origin_ -= faceCentre;
179}
180
181
182template<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.
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];
223
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];
241
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(
266 const refinementDistanceData& rhs,
267 TrackingData& td
268) const
269{
270 if (!valid(td))
271 {
272 return (!rhs.valid(td));
273 }
274 else
275 {
276 return operator==(rhs);
277 }
278}
279
280
281// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
282
284(
285 const refinementDistanceData& rhs
286) const
287{
288 return
289 level0Size_ == rhs.level0Size_
290 && origin_ == rhs.origin_
291 && originLevel_ == rhs.originLevel_;
292}
293
294
296(
297 const refinementDistanceData& rhs
298) const
299{
300 return !(*this == rhs);
301}
302
303
304// ************************************************************************* //
bool valid() const
True if all internal ids are non-negative.
friend Ostream & operator(Ostream &, const faMatrix< Type > &)
virtual bool update()
Update the mesh for both mesh motion and topology change.
Default transformation behaviour.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
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.
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.
refinementDistanceData()
Default construct.
void enterDomain(const polyMesh &, const polyPatch &, const label patchFacei, const point &faceCentre, TrackingData &)
Reverse of leaveDomain.
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:453
dimensionedScalar pos(const dimensionedScalar &ds)
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:536
dimensionedSymmTensor sqr(const dimensionedVector &dv)
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:378
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
3D tensor transformation operations.