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-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 
33 template<class TrackingData>
34 inline bool Foam::wallPoints::update
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 
116 template<class TrackingData>
117 inline 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
124 template<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.
138 template<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.
156 template<class TrackingData>
157 inline void Foam::wallPoints::transform
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.
172 template<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
191 template<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  forAll(neighbourInfo.surface_, i)
206  {
207  const FixedList<label, 3>& nbrSurface = neighbourInfo.surface_[i];
208 
209  // Find in my surfaces
210  label index = surface_.find(nbrSurface);
211  if (index == -1)
212  {
213  // Append
214  origin_.append(neighbourInfo.origin_[i]);
215  distSqr_.append(magSqr(cc-neighbourInfo.origin_[i]));
216  surface_.append(nbrSurface);
217  //normal_.append(neighbourInfo.normal_[i]);
218  hasChanged = true;
219  }
220  else
221  {
222  hasChanged =
223  update(cc, index, neighbourInfo, i, tol, td)
224  || hasChanged;
225  }
226  }
227 
228  return hasChanged;
229 }
230 
231 
232 // Update face with neighbouring cell information
233 template<class TrackingData>
235 (
236  const polyMesh& mesh,
237  const label thisFacei,
238  const label neighbourCelli,
239  const wallPoints& neighbourInfo,
240  const scalar tol,
241  TrackingData& td
242 )
243 {
244  // From cell to its faces.
245  bool hasChanged = false;
246 
247  if (!td.isBlockedFace_[thisFacei])
248  {
249  const point& fc = mesh.faceCentres()[thisFacei];
250 
251  forAll(neighbourInfo.surface_, i)
252  {
253  const FixedList<label, 3>& nbrSurface = neighbourInfo.surface_[i];
254 
255  // Find in my surfaces
256  label index = surface_.find(nbrSurface);
257  if (index == -1)
258  {
259  // Append
260  origin_.append(neighbourInfo.origin_[i]);
261  distSqr_.append(magSqr(fc-neighbourInfo.origin_[i]));
262  surface_.append(nbrSurface);
263  //normal_.append(neighbourInfo.normal_[i]);
264  hasChanged = true;
265  }
266  else
267  {
268  hasChanged =
269  update(fc, index, neighbourInfo, i, tol, td)
270  || hasChanged;
271  }
272  }
273  }
274 
275  return hasChanged;
276 }
277 
278 
279 // Update face with coupled face information
280 template<class TrackingData>
282 (
283  const polyMesh& mesh,
284  const label thisFacei,
285  const wallPoints& neighbourInfo,
286  const scalar tol,
287  TrackingData& td
288 )
289 {
290  // From face to face (e.g. coupled faces)
291  bool hasChanged = false;
292 
293  if (!td.isBlockedFace_[thisFacei])
294  {
295  const point& fc = mesh.faceCentres()[thisFacei];
296 
297  forAll(neighbourInfo.surface_, i)
298  {
299  const FixedList<label, 3>& nbrSurface = neighbourInfo.surface_[i];
300 
301  // Find in my surfaces
302  const label index = surface_.find(nbrSurface);
303  if (index == -1)
304  {
305  // Append
306  origin_.append(neighbourInfo.origin_[i]);
307  distSqr_.append(magSqr(fc-neighbourInfo.origin_[i]));
308  surface_.append(nbrSurface);
309  //normal_.append(neighbourInfo.normal_[i]);
310  hasChanged = true;
311  }
312  else
313  {
314  hasChanged =
315  update(fc, index, neighbourInfo, i, tol, td)
316  || hasChanged;
317  }
318  }
319  }
320 
321  return hasChanged;
322 }
323 
324 
325 template<class TrackingData>
326 inline bool Foam::wallPoints::equal
327 (
328  const wallPoints& rhs,
329  TrackingData& td
330 ) const
331 {
332  return operator==(rhs);
333 }
334 
335 
336 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
337 
338 inline bool Foam::wallPoints::operator==
339 (
340  const wallPoints& rhs
341 ) const
342 {
343  return
344  surface_ == rhs.surface_
345  && distSqr_ == rhs.distSqr_
346  && origin_ == rhs.origin_;
347  //&& normal_ == rhs.normal_;
348 }
349 
350 
351 inline bool Foam::wallPoints::operator!=
352 (
353  const wallPoints& rhs
354 ) const
355 {
356  return !(*this == rhs);
357 }
358 
359 
360 // ************************************************************************* //
Foam::wallPoints::distSqr_
DynamicList< scalar > distSqr_
Distance (squared) from cellcenter to origin.
Definition: wallPoints.H:89
Foam::Tensor< scalar >
Foam::wallPoints::valid
bool valid(TrackingData &td) const
Changed or contains original (invalid) value.
Definition: wallPointsI.H:117
Foam::wallPoints::transform
void transform(const polyMesh &, const tensor &, TrackingData &td)
Apply rotation matrix to any coordinates.
Definition: wallPointsI.H:158
update
mesh update()
Foam::wallPoints::origin_
DynamicList< point > origin_
Starting points.
Definition: wallPoints.H:86
Foam::wallPoints::surface_
DynamicList< FixedList< label, 3 > > surface_
Originating surface,region and topological region.
Definition: wallPoints.H:92
Foam::transform
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:521
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::wallPoints::updateCell
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
Foam::diff
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
Definition: triad.C:378
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::wallPoints::update
bool update(const point &pt, const label index1, const wallPoints &w2, const label index2, const scalar tol, TrackingData &td)
Originating normal.
Definition: wallPointsI.H:35
Foam::wallPoints::wallPoints
wallPoints()
Default construct.
Definition: wallPointsI.H:90
w2
#define w2
Definition: blockCreate.C:35
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::wallPoints::sameGeometry
bool sameGeometry(const polyMesh &, const wallPoints &, const scalar, TrackingData &td) const
Check for identical geometrical data (eg, cyclics checking)
Definition: wallPointsI.H:126
Foam::wallPoints::enterDomain
void enterDomain(const polyMesh &, const polyPatch &, const label patchFacei, const point &faceCentre, TrackingData &td)
Reverse of leaveDomain.
Definition: wallPointsI.H:174
Foam::wallPoints::leaveDomain
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
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:84
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:77
Foam::FixedList< label, 3 >
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::wallPoints::updateFace
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:235
transform.H
3D tensor transformation operations.
Foam::wallPoints
For use with FaceCellWave. Determines topological distance to starting faces.
Definition: wallPoints.H:62
Foam::wallPoints::equal
bool equal(const wallPoints &, TrackingData &) const
Test for equality, with TrackingData.
Definition: wallPointsI.H:327