PointEdgeWave.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 | Copyright (C) 2011-2013 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 (responsability 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 tensorField& 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  //- Disallow default bitwise copy construct
214 
215  //- Disallow default bitwise assignment
216  void operator=(const PointEdgeWave&);
217 
218 
219 public:
220 
221  // Static Functions
222 
223  //- Access to tolerance
224  static scalar propagationTol()
225  {
226  return propagationTol_;
227  }
228 
229  //- Change tolerance
230  static void setPropagationTol(const scalar tol)
231  {
232  propagationTol_ = tol;
233  }
234 
235 
236  // Constructors
237 
238  //- Construct from mesh, list of changed points with the Type
239  // for these points. Gets work arrays to operate on, one of size
240  // number of mesh points, the other number of mesh edges.
241  // Iterates until nothing changes or maxIter reached.
242  // (maxIter can be 0)
244  (
245  const polyMesh& mesh,
246  const labelList& initialPoints,
247  const List<Type>& initialPointsInfo,
250  const label maxIter,
251  TrackingData& td = dummyTrackData_
252  );
253 
254  //- Construct from mesh. Use setPointInfo and iterate() to do
255  // actual calculation
257  (
258  const polyMesh& mesh,
259  UList<Type>& allPointInfo,
260  UList<Type>& allEdgeInfo,
261  TrackingData& td = dummyTrackData_
262  );
263 
264 
265  //- Destructor
266  ~PointEdgeWave();
267 
268 
269  // Member Functions
270 
271  //- Access allPointInfo
272  UList<Type>& allPointInfo() const
273  {
274  return allPointInfo_;
275  }
276 
277  //- Access allEdgeInfo
278  UList<Type>& allEdgeInfo() const
279  {
280  return allEdgeInfo_;
281  }
282 
283  //- Additional data to be passed into container
284  const TrackingData& data() const
285  {
286  return td_;
287  }
288 
289  //- Get number of unvisited edges, i.e. edges that were not (yet)
290  // reached from walking across mesh. This can happen from
291  // - not enough iterations done
292  // - a disconnected mesh
293  // - a mesh without walls in it
294  label getUnsetEdges() const;
295 
296  label getUnsetPoints() const;
297 
298  //- Copy initial data into allPointInfo_
299  void setPointInfo
300  (
301  const labelList& changedPoints,
302  const List<Type>& changedPointsInfo
303  );
304 
305  //- Propagate from point to edge. Returns total number of edges
306  // (over all processors) changed.
307  label pointToEdge();
308 
309  //- Propagate from edge to point. Returns total number of points
310  // (over all processors) changed.
311  label edgeToPoint();
312 
313  //- Iterate until no changes or maxIter reached. Returns actual
314  // number of iterations.
315  label iterate(const label maxIter);
316 };
317 
318 
319 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
320 
321 /*---------------------------------------------------------------------------*\
322  Class listUpdateOp Declaration
323 \*---------------------------------------------------------------------------*/
324 
325 //- List update operation
326 template<class Type, class TrackingData = int>
327 class listUpdateOp
328 {
329  //- Additional data to be passed into container
330 
331  const scalar tol_;
332 
333  TrackingData& td_;
334 
335 public:
336  listUpdateOp(const scalar tol, TrackingData& td)
337  :
338  tol_(tol),
339  td_(td)
340  {}
342  void operator()(List<Type>& x, const List<Type>& y) const
343  {
344  forAll(x, i)
345  {
346  if (y[i].valid(td_))
347  {
348  x[i].updatePoint(y[i], tol_, td_);
349  }
350  }
351  }
352 };
353 
354 } // End namespace Foam
355 
356 
357 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
358 
359 #ifdef NoRepository
360 # include "PointEdgeWave.C"
361 #endif
362 
363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
364 
365 #endif
366 
367 // ************************************************************************* //
static void setPropagationTol(const scalar tol)
Change tolerance.
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
UList< Type > & allPointInfo() const
Access allPointInfo.
label pointToEdge()
Propagate from point to edge. Returns total number of edges.
label getUnsetEdges() const
Get number of unvisited edges, i.e. edges that were not (yet)
dynamicFvMesh & mesh
const TrackingData & data() const
Additional data to be passed into container.
Namespace for OpenFOAM.
void setPointInfo(const labelList &changedPoints, const List< Type > &changedPointsInfo)
Copy initial data into allPointInfo_.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
label getUnsetPoints() const
UList< Type > & allEdgeInfo() const
Access allEdgeInfo.
#define forAll(list, i)
Definition: UList.H:421
List update operation.
label edgeToPoint()
Propagate from edge to point. Returns total number of points.
label iterate(const label maxIter)
Iterate until no changes or maxIter reached. Returns actual.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
scalar y
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.
TemplateName(blendedSchemeBase)
~PointEdgeWave()
Destructor.