wallPointsI.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) 2018-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "polyMesh.H"
29#include "transform.H"
30
31// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32
33template<class TrackingData>
35(
36 const point& pt,
37 const label index1,
38 const wallPoints& w2,
39 const label index2,
40
41 const scalar tol,
42 TrackingData& td
43)
44{
45 const scalar dist2 = magSqr(pt - w2.origin_[index2]);
46
47 if (!valid(td))
48 {
49 // currently not yet set so use any value
50 distSqr_[index1] = dist2;
51 origin_[index1] = w2.origin_[index2];
52 surface_[index1] = w2.surface_[index2];
53 //normal_[index1] = w2.normal_[index2];
54
55 return true;
56 }
57
58 const scalar diff = distSqr_[index1] - dist2;
59
60 if (diff < 0)
61 {
62 // already nearer to pt
63 return false;
64 }
65
66 if
67 (
68 (diff < SMALL)
69 || ((distSqr_[index1] > SMALL) && (diff/distSqr_[index1] < tol))
70 )
71 {
72 // don't propagate small changes
73 return false;
74 }
75 else
76 {
77 // update with new values
78 distSqr_[index1] = dist2;
79 origin_[index1] = w2.origin_[index2];
80 surface_[index1] = w2.surface_[index2];
81 //normal_[index1] = w2.normal_[index2];
82
83 return true;
84 }
85}
86
87
88// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
89
91:
92 origin_(0),
93 distSqr_(0),
94 surface_(0)
95 //normal_(0)
96{}
97
98
100(
101 const UList<point>& origin,
102 const UList<scalar>& distSqr,
103 const UList<FixedList<label, 3>>& surface
104 //const UList<vector>& normal
105)
106:
107 origin_(origin),
108 distSqr_(distSqr),
109 surface_(surface)
110 //normal_(normal)
111{}
112
113
114// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115
116template<class TrackingData>
117inline bool Foam::wallPoints::valid(TrackingData& td) const
118{
119 return origin_.size();
120}
121
122
123// No geometric data so never any problem on cyclics
124template<class TrackingData>
126(
127 const polyMesh&,
128 const wallPoints&,
129 const scalar,
130 TrackingData&
131) const
132{
133 return true;
134}
135
136
137// No geometric data.
138template<class TrackingData>
140(
141 const polyMesh&,
142 const polyPatch& patch,
143 const label patchFacei,
144 const point& faceCentre,
145 TrackingData&
146)
147{
148 for (auto& o : origin_)
149 {
150 o -= faceCentre;
151 }
152}
153
154
155// No geometric data.
156template<class TrackingData>
158(
159 const polyMesh&,
160 const tensor& rotTensor,
161 TrackingData&
162)
163{
164 for (auto& o : origin_)
165 {
166 o = Foam::transform(rotTensor, o);
167 }
168}
169
170
171// No geometric data.
172template<class TrackingData>
174(
175 const polyMesh&,
176 const polyPatch& patch,
177 const label patchFacei,
178 const point& faceCentre,
179 TrackingData&
180)
181{
182 // back to absolute form
183 for (auto& o : origin_)
184 {
185 o += faceCentre;
186 }
187}
188
189
190// Update cell with neighbouring face information
191template<class TrackingData>
193(
194 const polyMesh& mesh,
195 const label thisCelli,
196 const label neighbourFacei,
197 const wallPoints& neighbourInfo,
198 const scalar tol,
199 TrackingData& td
200)
201{
202 const point& cc = mesh.cellCentres()[thisCelli];
203
204 bool hasChanged = false;
205
206 forAll(neighbourInfo.surface_, i)
207 {
208 const FixedList<label, 3>& nbrSurface = neighbourInfo.surface_[i];
209
210 // Check distance from nbr origin to cc against max walking distance
211 const scalar blockSize =
212 td.regionToBlockSize_[nbrSurface[0]][nbrSurface[1]];
213
214 const scalar d2 = magSqr(cc-neighbourInfo.origin_[i]);
215
216 if (d2 < Foam::sqr(3*blockSize))
217 {
218 // Real distance less than max gap distance. Note that it should
219 // be at least 2 * blockSize (since gap is two cells across).
220 // Should be
221 // a little bit more to account for castellated path walk. Bit
222 // heuristic - try 3. Should be as low as possible to kill off
223 // unnecessary waves asap.
224
225 // Find in my surfaces
226 label index = surface_.find(nbrSurface);
227 if (index == -1)
228 {
229 // Append
230 origin_.append(neighbourInfo.origin_[i]);
231 distSqr_.append(d2);
232 surface_.append(nbrSurface);
233 //normal_.append(neighbourInfo.normal_[i]);
234 hasChanged = true;
235 }
236 else
237 {
238 hasChanged =
239 update(cc, index, neighbourInfo, i, tol, td)
240 || hasChanged;
241 }
242 }
243 else
244 {
245 // Real distance more than gap distance so ignore
246 //Pout<< "at cell:" << cc << " ignoring nbr info:"
247 // << neighbourInfo.origin_[i]
248 // << " from surface:" << nbrSurface[0]
249 // << " from region:" << nbrSurface[1]
250 // << " bloxkSize:" << blockSize
251 // << " distance:" << Foam::sqrt(d2)
252 // << endl;
253 }
254 }
255
256 return hasChanged;
257}
258
259
260// Update face with neighbouring cell information
261template<class TrackingData>
263(
264 const polyMesh& mesh,
265 const label thisFacei,
266 const label neighbourCelli,
267 const wallPoints& neighbourInfo,
268 const scalar tol,
269 TrackingData& td
270)
271{
272 // From cell to its faces.
273 bool hasChanged = false;
274
275 if (!td.isBlockedFace_[thisFacei])
276 {
277 const point& fc = mesh.faceCentres()[thisFacei];
278
279 forAll(neighbourInfo.surface_, i)
280 {
281 const FixedList<label, 3>& nbrSurface = neighbourInfo.surface_[i];
282
283 // Check distance from nbr origin to cc against max walking distance
284 const scalar blockSize =
285 td.regionToBlockSize_[nbrSurface[0]][nbrSurface[1]];
286
287 const scalar d2 = magSqr(fc-neighbourInfo.origin_[i]);
288
289 if (d2 < Foam::sqr(3*blockSize))
290 {
291 // Real distance less than max gap distance
292
293 // Find in my surfaces
294 label index = surface_.find(nbrSurface);
295 if (index == -1)
296 {
297 // Append
298 origin_.append(neighbourInfo.origin_[i]);
299 distSqr_.append(d2);
300 surface_.append(nbrSurface);
301 //normal_.append(neighbourInfo.normal_[i]);
302 hasChanged = true;
303 }
304 else
305 {
306 hasChanged =
307 update(fc, index, neighbourInfo, i, tol, td)
308 || hasChanged;
309 }
310 }
311 else
312 {
313 // Real distance more than gap distance so ignore
314 //Pout<< "at face:" << fc << " ignoring nbr info:"
315 // << neighbourInfo.origin_[i]
316 // << " from surface:" << nbrSurface[0]
317 // << " from region:" << nbrSurface[1]
318 // << " bloxkSize:" << blockSize
319 // << " distance:" << Foam::sqrt(d2)
320 // << endl;
321 }
322 }
323 }
324
325 return hasChanged;
326}
327
328
329// Update face with coupled face information
330template<class TrackingData>
332(
333 const polyMesh& mesh,
334 const label thisFacei,
335 const wallPoints& neighbourInfo,
336 const scalar tol,
337 TrackingData& td
338)
339{
340 // From face to face (e.g. coupled faces)
341 bool hasChanged = false;
342
343 if (!td.isBlockedFace_[thisFacei])
344 {
345 const point& fc = mesh.faceCentres()[thisFacei];
346
347 forAll(neighbourInfo.surface_, i)
348 {
349 const FixedList<label, 3>& nbrSurface = neighbourInfo.surface_[i];
350
351 // Check distance from nbr origin to cc against max walking distance
352 const scalar blockSize =
353 td.regionToBlockSize_[nbrSurface[0]][nbrSurface[1]];
354
355 const scalar d2 = magSqr(fc-neighbourInfo.origin_[i]);
356
357 if (d2 < Foam::sqr(3*blockSize))
358 {
359 // Real distance less than max gap distance
360
361 // Find in my surfaces
362 const label index = surface_.find(nbrSurface);
363 if (index == -1)
364 {
365 // Append
366 origin_.append(neighbourInfo.origin_[i]);
367 distSqr_.append(d2);
368 surface_.append(nbrSurface);
369 //normal_.append(neighbourInfo.normal_[i]);
370 hasChanged = true;
371 }
372 else
373 {
374 hasChanged =
375 update(fc, index, neighbourInfo, i, tol, td)
376 || hasChanged;
377 }
378 }
379 else
380 {
381 // Real distance more than gap distance so ignore
382 //Pout<< "at face:" << fc << " ignoring nbr info:"
383 // << neighbourInfo.origin_[i]
384 // << " from surface:" << nbrSurface[0]
385 // << " from region:" << nbrSurface[1]
386 // << " bloxkSize:" << blockSize
387 // << " distance:" << Foam::sqrt(d2)
388 // << endl;
389 }
390 }
391 }
392
393 return hasChanged;
394}
395
396
397template<class TrackingData>
399(
400 const wallPoints& rhs,
401 TrackingData& td
402) const
403{
404 return operator==(rhs);
405}
406
407
408// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
409
411(
412 const wallPoints& rhs
413) const
414{
415 return
416 surface_ == rhs.surface_
417 && distSqr_ == rhs.distSqr_
418 && origin_ == rhs.origin_;
419 //&& normal_ == rhs.normal_;
420}
421
422
424(
425 const wallPoints& rhs
426) const
427{
428 return !(*this == rhs);
429}
430
431
432// ************************************************************************* //
#define w2
Definition: blockCreate.C:35
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
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
For use with FaceCellWave. Determines topological distance to starting faces.
Definition: wallPoints.H:64
DynamicList< scalar > distSqr_
Distance (squared) from cellcenter to origin.
Definition: wallPoints.H:98
bool equal(const wallPoints &, TrackingData &) const
Test for equality, with TrackingData.
Definition: wallPointsI.H:399
bool updateCell(const polyMesh &, const label thisCelli, const label neighbourFacei, const wallPoints &neighbourInfo, const scalar tol, TrackingData &td)
Influence of neighbouring face.
Definition: wallPointsI.H:193
void enterDomain(const polyMesh &, const polyPatch &, const label patchFacei, const point &faceCentre, TrackingData &td)
Reverse of leaveDomain.
Definition: wallPointsI.H:174
wallPoints()
Default construct.
Definition: wallPointsI.H:90
bool sameGeometry(const polyMesh &, const wallPoints &, const scalar, TrackingData &td) const
Check for identical geometrical data (eg, cyclics checking)
Definition: wallPointsI.H:126
bool valid(TrackingData &td) const
Changed or contains original (invalid) value.
Definition: wallPointsI.H:117
bool updateFace(const polyMesh &, const label thisFacei, const label neighbourCelli, const wallPoints &neighbourInfo, const scalar tol, TrackingData &td)
Influence of neighbouring cell.
Definition: wallPointsI.H:263
DynamicList< FixedList< label, 3 > > surface_
Originating surface,region and topological region.
Definition: wallPoints.H:101
DynamicList< point > origin_
Starting points.
Definition: wallPoints.H:95
void leaveDomain(const polyMesh &, const polyPatch &, const label patchFacei, const point &faceCentre, TrackingData &td)
Convert any absolute coordinates into relative to (patch)face.
Definition: wallPointsI.H:140
mesh update()
dynamicFvMesh & mesh
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
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
3D tensor transformation operations.