FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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. Templated on information
30  that is transferred.
31 
32  Templated on information that is transferred.
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 <OpenFOAM/label.H>
62 #include <OpenFOAM/boolList.H>
63 #include <OpenFOAM/scalarField.H>
64 #include <OpenFOAM/pointFields.H>
65 #include <OpenFOAM/tensor.H>
67 #include <OpenFOAM/PtrList.H>
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 namespace Foam
72 {
73 
74 // Forward declaration of classes
75 class polyMesh;
76 
77 
78 /*---------------------------------------------------------------------------*\
79  Class PointEdgeWaveName Declaration
80 \*---------------------------------------------------------------------------*/
81 
82 TemplateName(PointEdgeWave);
83 
84 
85 /*---------------------------------------------------------------------------*\
86  Class PointEdgeWave Declaration
87 \*---------------------------------------------------------------------------*/
88 
89 template <class Type>
91 :
92  public PointEdgeWaveName
93 {
94  // Private static data
95 
96  //- Relative tolerance. Stop propagation if relative changes
97  // less than this tolerance (responsability for checking this is
98  // up to Type implementation)
99  static scalar propagationTol_;
100 
101 
102  // Private data
103 
104  //- Reference to mesh
105  const polyMesh& mesh_;
106 
107  //- Wall information for all points
108  List<Type>& allPointInfo_;
109 
110  //- Information on all mesh edges
111  List<Type>& allEdgeInfo_;
112 
113  //- Has point changed
114  boolList changedPoint_;
115 
116  //- List of changed points
117  labelList changedPoints_;
118 
119  //- Number of changed points
120  label nChangedPoints_;
121 
122  //- Edges that have changed
123  boolList changedEdge_;
124  labelList changedEdges_;
125  label nChangedEdges_;
126 
127  //- Number of cyclic patches
128  label nCyclicPatches_;
129 
130  //- For every cyclic patch two primitivePatches
131  PtrList<primitivePatch> cycHalves_;
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  //- Add value to all elements of labelList
144  static void offset(const label val, labelList& elems);
145 
146 
147  //- Adapt pointInfo for leaving domain
148  void leaveDomain
149  (
150  const polyPatch& meshPatch,
151  const primitivePatch& patch,
152  const List<label>& patchPointLabels,
153  List<Type>& pointInfo
154  ) const;
155 
156  //- Adapt pointInfo for entering domain
157  void enterDomain
158  (
159  const polyPatch& meshPatch,
160  const primitivePatch& patch,
161  const List<label>& patchPointLabels,
162  List<Type>& pointInfo
163  ) const;
164 
165  //- Transform. Implementation referred to Type
166  void transform
167  (
168  const tensorField& rotTensor,
169  List<Type>& pointInfo
170  ) const;
171 
172  //- Updates pointInfo with information from neighbour. Updates all
173  // statistics.
174  bool updatePoint
175  (
176  const label pointI,
177  const label neighbourEdgeI,
178  const Type& neighbourInfo,
179  const scalar tol,
180  Type& pointInfo
181  );
182 
183  //- Updates pointInfo with information from same point. Updates all
184  // statistics.
185  bool updatePoint
186  (
187  const label pointI,
188  const Type& neighbourInfo,
189  const scalar tol,
190  Type& pointInfo
191  );
192 
193  //- Updates edgeInfo with information from neighbour. Updates all
194  // statistics.
195  bool updateEdge
196  (
197  const label edgeI,
198  const label neighbourPointI,
199  const Type& neighbourInfo,
200  const scalar tol,
201  Type& edgeInfo
202  );
203 
204  // Parallel, cyclic
205 
206  //- Has patches of certain type?
207  template <class PatchType>
208  label countPatchType() const;
209 
210  //- Get info on patch points
211  void getChangedPatchPoints
212  (
213  const primitivePatch& patch,
214  DynamicList<Type>& patchInfo,
215  DynamicList<label>& patchPoints,
216  DynamicList<label>& owner,
217  DynamicList<label>& ownerIndex
218  ) const;
219 
220  //- Merge data from patch into overall data
221  void updateFromPatchInfo
222  (
223  const polyPatch& meshPatch,
224  const primitivePatch& patch,
225  const labelList& owner,
226  const labelList& ownerIndex,
227  List<Type>& patchInfo
228  );
229 
230  //- Merge data from across processor boundaries
231  void handleProcPatches();
232 
233  //- Calculate cyclic halves addressing.
234  void calcCyclicAddressing();
235 
236  //- Merge data from across cyclic boundaries
237  void handleCyclicPatches();
238 
239 
240  //- Disallow default bitwise copy construct
242 
243  //- Disallow default bitwise assignment
244  void operator=(const PointEdgeWave&);
245 
246 public:
247 
248  // Static Functions
249 
250  //- Access to tolerance
251  static scalar propagationTol()
252  {
253  return propagationTol_;
254  }
255 
256  //- Change tolerance
257  static void setPropagationTol(const scalar tol)
258  {
259  propagationTol_ = tol;
260  }
261 
262 
263 
264  // Constructors
265 
266  //- Construct from mesh, list of changed points with the Type
267  // for these points. Gets work arrays to operate on, one of size
268  // number of mesh points, the other number of mesh edges.
269  // Iterates until nothing changes or maxIter reached.
270  // (maxIter can be 0)
272  (
273  const polyMesh& mesh,
274  const labelList& initialPoints,
275  const List<Type>& initialPointsInfo,
278  const label maxIter
279  );
280 
281 
282  // Destructor
283 
284  ~PointEdgeWave();
285 
286 
287  // Member Functions
288 
289  //- Get allPointInfo
290  const List<Type>& allPointInfo() const
291  {
292  return allPointInfo_;
293  }
294 
295  //- Get allEdgeInfo
296  const List<Type>& allEdgeInfo() const
297  {
298  return allEdgeInfo_;
299  }
300 
301  //- Get number of unvisited edges, i.e. edges that were not (yet)
302  // reached from walking across mesh. This can happen from
303  // - not enough iterations done
304  // - a disconnected mesh
305  // - a mesh without walls in it
306  label getUnsetEdges() const;
307 
308  label getUnsetPoints() const;
309 
310  //- Copy initial data into allPointInfo_
311  void setPointInfo
312  (
313  const labelList& changedPoints,
314  const List<Type>& changedPointsInfo
315  );
316 
317  //- Propagate from point to edge. Returns total number of edges
318  // (over all processors) changed.
319  label pointToEdge();
320 
321  //- Propagate from edge to point. Returns total number of points
322  // (over all processors) changed.
323  label edgeToPoint();
324 
325  //- Iterate until no changes or maxIter reached. Returns actual
326  // number of iterations.
327  label iterate(const label maxIter);
328 };
329 
330 
331 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
332 
333 /*---------------------------------------------------------------------------*\
334  Class listUpdateOp Declaration
335 \*---------------------------------------------------------------------------*/
336 
337 //- List update operation
338 template <class Type>
340 {
341 
342 public:
343 
344  void operator()(List<Type>& x, const List<Type>& y) const
345  {
346  forAll(x, i)
347  {
348  x[i].updatePoint(y[i], PointEdgeWave<Type>::propagationTol());
349  }
350  }
351 };
352 
353 } // End namespace Foam
354 
355 
356 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
357 
358 #ifdef NoRepository
359 # include "PointEdgeWave.C"
360 #endif
361 
362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
363 
364 #endif
365 
366 // ************************ vim: set sw=4 sts=4 et: ************************ //