PointEdgeWave.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::PointEdgeWave
26 
27 Description
28  Wave propagation of information through grid. Every iteration
29  information goes through one layer of edges.
30 
31  Templated on information that is transferred.
32 
33  Handles parallel and cyclics. Only parallel reasonably tested. Cyclics
34  hardly tested.
35 
36  Note: whether to propagate depends on the return value of Type::update
37  which returns true (i.e. propagate) if the value changes by more than a
38  certain tolerance.
39 
40  Note: parallel is done in two steps:
41  -# transfer patch points in offset notation, i.e. every patch
42  point is denoted by a patchface label and an index in this face.
43  Receiving end uses that fact that f[0] is shared and order is
44  reversed.
45  -# do all non-local shared points by means of reduce of data on them.
46 
47  Note: cyclics is with offset in patchface as well. Patch is divided into
48  two sub patches and the point-point addressing is never explicitly
49  calculated but instead use is made of the face-face correspondence.
50  (it probably is more efficient to calculate a point-point
51  correspondence at the start and then reuse this; task to be done)
52 
53 SourceFiles
54  PointEdgeWave.C
55 
56 \*---------------------------------------------------------------------------*/
57 
58 #ifndef PointEdgeWave_H
59 #define PointEdgeWave_H
60 
61 #include "boolList.H"
62 #include "scalarField.H"
63 #include "tensorField.H"
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
67 namespace Foam
68 {
69 
70 // Forward declaration of classes
71 class polyMesh;
72 class polyPatch;
73 
74 /*---------------------------------------------------------------------------*\
75  Class PointEdgeWaveName Declaration
76 \*---------------------------------------------------------------------------*/
77 
78 TemplateName(PointEdgeWave);
79 
80 
81 /*---------------------------------------------------------------------------*\
82  Class PointEdgeWave Declaration
83 \*---------------------------------------------------------------------------*/
84 
85 template<class Type, class TrackingData = int>
86 class PointEdgeWave
87 :
88  public PointEdgeWaveName
89 {
90  // Private static data
91 
92  //- Relative tolerance. Stop propagation if relative changes
93  // less than this tolerance (responsibility for checking this is
94  // up to Type implementation)
95  static scalar propagationTol_;
96 
97  //- Used as default trackdata value to satisfy default template
98  // argument.
99  static int dummyTrackData_;
100 
101 
102  // Private Data
103 
104  //- Reference to mesh
105  const polyMesh& mesh_;
106 
107  //- Wall information for all points
108  UList<Type>& allPointInfo_;
109 
110  //- Information on all mesh edges
111  UList<Type>& allEdgeInfo_;
112 
113  //- Additional data to be passed into container
114  TrackingData& td_;
115 
116  //- Has point changed
117  boolList changedPoint_;
118 
119  //- List of changed points
120  labelList changedPoints_;
121 
122  //- Number of changed points
123  label nChangedPoints_;
124 
125  //- Edges that have changed
126  boolList changedEdge_;
127  labelList changedEdges_;
128  label nChangedEdges_;
129 
130  //- Number of cyclic patches
131  label nCyclicPatches_;
132 
133  //- Number of evaluations
134  label nEvals_;
135 
136  //- Number of unvisited edges/points
137  label nUnvisitedPoints_;
138  label nUnvisitedEdges_;
139 
140 
141  // Private Member Functions
142 
143  //- Adapt pointInfo for leaving domain
144  void leaveDomain
145  (
146  const polyPatch&,
147  const List<label>& patchPointLabels,
148  List<Type>& pointInfo
149  ) const;
150 
151  //- Adapt pointInfo for entering domain
152  void enterDomain
153  (
154  const polyPatch&,
155  const List<label>& patchPointLabels,
156  List<Type>& pointInfo
157  ) const;
158 
159  //- Transform. Implementation referred to Type
160  void transform
161  (
162  const polyPatch& patch,
163  const tensor& rotTensor,
164  List<Type>& pointInfo
165  ) const;
166 
167  //- Updates pointInfo with information from neighbour. Updates all
168  // statistics.
169  bool updatePoint
170  (
171  const label pointi,
172  const label neighbourEdgeI,
173  const Type& neighbourInfo,
174  Type& pointInfo
175  );
176 
177  //- Updates pointInfo with information from same point. Updates all
178  // statistics.
179  bool updatePoint
180  (
181  const label pointi,
182  const Type& neighbourInfo,
183  Type& pointInfo
184  );
185 
186  //- Updates edgeInfo with information from neighbour. Updates all
187  // statistics.
188  bool updateEdge
189  (
190  const label edgeI,
191  const label neighbourPointi,
192  const Type& neighbourInfo,
193  Type& edgeInfo
194  );
195 
196  // Parallel, cyclic
197 
198  //- Has patches of certain type?
199  template<class PatchType>
200  label countPatchType() const;
201 
202  //- Merge data from across processor boundaries
203  void handleProcPatches();
204 
205  //- Merge data from across cyclic boundaries
206  void handleCyclicPatches();
207 
208  //- Explicitly sync all collocated points
209  label handleCollocatedPoints();
210 
211 
212 public:
213 
214  // Static Functions
215 
216  //- Access to tolerance
217  static scalar propagationTol()
218  {
219  return propagationTol_;
220  }
221 
222  //- Change tolerance
223  static void setPropagationTol(const scalar tol)
224  {
225  propagationTol_ = tol;
226  }
227 
228 
229  // Constructors
230 
231  //- Construct from mesh, list of changed points with the Type
232  // for these points. Gets work arrays to operate on, one of size
233  // number of mesh points, the other number of mesh edges.
234  // Iterates until nothing changes or maxIter reached.
235  // (maxIter can be 0)
237  (
238  const polyMesh& mesh,
239  const labelList& initialPoints,
240  const List<Type>& initialPointsInfo,
243  const label maxIter,
244  TrackingData& td = dummyTrackData_
245  );
246 
247  //- Construct from mesh. Use setPointInfo and iterate() to do
248  // actual calculation
250  (
251  const polyMesh& mesh,
252  UList<Type>& allPointInfo,
253  UList<Type>& allEdgeInfo,
254  TrackingData& td = dummyTrackData_
255  );
256 
257  //- Disallow default bitwise copy construction
258  PointEdgeWave(const PointEdgeWave&) = delete;
259 
260 
261  //- Destructor
262  ~PointEdgeWave();
263 
264 
265  // Member Functions
266 
267  //- Access allPointInfo
268  UList<Type>& allPointInfo() const
269  {
270  return allPointInfo_;
271  }
272 
273  //- Access allEdgeInfo
274  UList<Type>& allEdgeInfo() const
275  {
276  return allEdgeInfo_;
277  }
278 
279  //- Additional data to be passed into container
280  const TrackingData& data() const
281  {
282  return td_;
283  }
284 
285  //- Get number of unvisited edges, i.e. edges that were not (yet)
286  // reached from walking across mesh. This can happen from
287  // - not enough iterations done
288  // - a disconnected mesh
289  // - a mesh without walls in it
290  label getUnsetEdges() const;
291 
292  label getUnsetPoints() const;
293 
294  //- Copy initial data into allPointInfo_
295  void setPointInfo
296  (
297  const labelList& changedPoints,
298  const List<Type>& changedPointsInfo
299  );
300 
301  //- Propagate from point to edge. Returns total number of edges
302  // (over all processors) changed.
303  label pointToEdge();
304 
305  //- Propagate from edge to point. Returns total number of points
306  // (over all processors) changed.
307  label edgeToPoint();
308 
309  //- Iterate until no changes or maxIter reached. Returns actual
310  // number of iterations.
311  label iterate(const label maxIter);
312 
313 
314  // Member Operators
315 
316  //- Disallow default bitwise assignment
317  void operator=(const PointEdgeWave&) = delete;
318 };
319 
320 
321 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
322 
323 /*---------------------------------------------------------------------------*\
324  Class listUpdateOp Declaration
325 \*---------------------------------------------------------------------------*/
326 
327 //- List update operation
328 template<class Type, class TrackingData = int>
329 class listUpdateOp
330 {
331  //- Additional data to be passed into container
332 
333  const scalar tol_;
334 
335  TrackingData& td_;
336 
337 public:
338  listUpdateOp(const scalar tol, TrackingData& td)
339  :
340  tol_(tol),
341  td_(td)
342  {}
344  void operator()(List<Type>& x, const List<Type>& y) const
345  {
346  forAll(x, i)
347  {
348  if (y[i].valid(td_))
349  {
350  x[i].updatePoint(y[i], tol_, td_);
351  }
352  }
353  }
354 };
355 
356 } // End namespace Foam
357 
358 
359 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
360 
361 #ifdef NoRepository
362  #include "PointEdgeWave.C"
363 #endif
364 
365 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
366 
367 #endif
368 
369 // ************************************************************************* //
TemplateName(blendedSchemeBase)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:59
label pointToEdge()
Propagate from point to edge. Returns total number of edges.
UList< Type > & allEdgeInfo() const
Access allEdgeInfo.
label iterate(const label maxIter)
Iterate until no changes or maxIter reached. Returns actual.
PointEdgeWave(const polyMesh &mesh, const labelList &initialPoints, const List< Type > &initialPointsInfo, UList< Type > &allPointInfo, UList< Type > &allEdgeInfo, const label maxIter, TrackingData &td=dummyTrackData_)
Construct from mesh, list of changed points with the Type.
label edgeToPoint()
Propagate from edge to point. Returns total number of points.
UList< Type > & allPointInfo() const
Access allPointInfo.
~PointEdgeWave()
Destructor.
void setPointInfo(const labelList &changedPoints, const List< Type > &changedPointsInfo)
Copy initial data into allPointInfo_.
void operator=(const PointEdgeWave &)=delete
Disallow default bitwise assignment.
scalar y
static void setPropagationTol(const scalar tol)
Change tolerance.
dynamicFvMesh & mesh
const TrackingData & data() const
Additional data to be passed into container.
List update operation.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
label getUnsetPoints() const
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Wave propagation of information through grid. Every iteration information goes through one layer of e...
Definition: PointEdgeWave.H:85
static scalar propagationTol()
Access to tolerance.
label getUnsetEdges() const
Get number of unvisited edges, i.e. edges that were not (yet)
Namespace for OpenFOAM.