BUG: PointEdgeWave : n cyclics bool instead of label
[OpenFOAM-1.6.x.git] / src / meshTools / PointEdgeWave / PointEdgeWave.H
blob33b291a6162b99c787a020e5c4a3bef38de228cb
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::PointEdgeWave
28 Description
29     Wave propagation of information through grid. Every iteration
30     information goes through one layer of edges. Templated on information
31     that is transferred.
33     Templated on information that is transferred.
34     Handles parallel and cyclics. Only parallel reasonably tested. Cyclics
35     hardly tested.
37     Note: whether to propagate depends on the return value of Type::update
38     which returns true (i.e. propagate) if the value changes by more than a
39     certain tolerance.
41     Note: parallel is done in two steps:
42       -# transfer patch points in offset notation, i.e. every patch
43          point is denoted by a patchface label and an index in this face.
44          Receiving end uses that fact that f[0] is shared and order is
45          reversed.
46       -# do all non-local shared points by means of reduce of data on them.
48     Note: cyclics is with offset in patchface as well. Patch is divided into
49     two sub patches and the point-point addressing is never explicitly
50     calculated but instead use is made of the face-face correspondence.
51     (it probably is more efficient to calculate a point-point
52     correspondence at the start and then reuse this; task to be done)
54 SourceFiles
55     PointEdgeWave.C
57 \*---------------------------------------------------------------------------*/
59 #ifndef PointEdgeWave_H
60 #define PointEdgeWave_H
62 #include "label.H"
63 #include "boolList.H"
64 #include "scalarField.H"
65 #include "pointFields.H"
66 #include "tensor.H"
67 #include "primitivePatch.H"
68 #include "PtrList.H"
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 namespace Foam
75 // Forward declaration of classes
76 class polyMesh;
79 /*---------------------------------------------------------------------------*\
80                         Class PointEdgeWaveName Declaration
81 \*---------------------------------------------------------------------------*/
83 TemplateName(PointEdgeWave);
86 /*---------------------------------------------------------------------------*\
87                            Class PointEdgeWave Declaration
88 \*---------------------------------------------------------------------------*/
90 template <class Type>
91 class PointEdgeWave
93     public PointEdgeWaveName
95   // Private static data
97         //- Relative tolerance. Stop propagation if relative changes
98         //  less than this tolerance (responsability for checking this is
99         //  up to Type implementation)
100         static scalar propagationTol_;
103     // Private data
105         //- Reference to mesh
106         const polyMesh& mesh_;
108         //- Wall information for all points
109         List<Type>& allPointInfo_;
111         //- Information on all mesh edges
112         List<Type>& allEdgeInfo_;
114         //- Has point changed
115         boolList changedPoint_;
117         //- List of changed points
118         labelList changedPoints_;
120         //- Number of changed points
121         label nChangedPoints_;
123         //- Edges that have changed
124         boolList changedEdge_;
125         labelList changedEdges_;
126         label nChangedEdges_;
128         //- Number of cyclic patches
129         label nCyclicPatches_;
131         //- For every cyclic patch two primitivePatches
132         PtrList<primitivePatch> cycHalves_;
134         //- Number of evaluations
135         label nEvals_;
137         //- Number of unvisited edges/points
138         label nUnvisitedPoints_;
139         label nUnvisitedEdges_;
142     // Private Member Functions
144         //- Add value to all elements of labelList
145         static void offset(const label val, labelList& elems);
148         //- Adapt pointInfo for leaving domain
149         void leaveDomain
150         (
151             const polyPatch& meshPatch,
152             const primitivePatch& patch,
153             const List<label>& patchPointLabels,
154             List<Type>& pointInfo
155         ) const;
157         //- Adapt pointInfo for entering domain
158         void enterDomain
159         (
160             const polyPatch& meshPatch,
161             const primitivePatch& patch,
162             const List<label>& patchPointLabels,
163             List<Type>& pointInfo
164         ) const;
166         //- Transform. Implementation referred to Type
167         void transform
168         (
169             const tensorField& rotTensor,
170             List<Type>& pointInfo
171         ) const;
173         //- Updates pointInfo with information from neighbour. Updates all
174         //  statistics.
175         bool updatePoint
176         (
177             const label pointI,
178             const label neighbourEdgeI,
179             const Type& neighbourInfo,
180             const scalar tol,
181             Type& pointInfo
182         );
184         //- Updates pointInfo with information from same point. Updates all
185         //  statistics.
186         bool updatePoint
187         (
188             const label pointI,
189             const Type& neighbourInfo,
190             const scalar tol,
191             Type& pointInfo
192         );
194         //- Updates edgeInfo with information from neighbour. Updates all
195         //  statistics.
196         bool updateEdge
197         (
198             const label edgeI,
199             const label neighbourPointI,
200             const Type& neighbourInfo,
201             const scalar tol,
202             Type& edgeInfo
203         );
205         // Parallel, cyclic
207             //- Has patches of certain type?
208             template <class PatchType>
209             label countPatchType() const;
211             //- Get info on patch points
212             void getChangedPatchPoints
213             (
214                 const primitivePatch& patch,
215                 DynamicList<Type>& patchInfo,
216                 DynamicList<label>& patchPoints,
217                 DynamicList<label>& owner,
218                 DynamicList<label>& ownerIndex
219             ) const;
221             //- Merge data from patch into overall data
222             void updateFromPatchInfo
223             (
224                 const polyPatch& meshPatch,
225                 const primitivePatch& patch,
226                 const labelList& owner,
227                 const labelList& ownerIndex,
228                 List<Type>& patchInfo
229             );
231             //- Merge data from across processor boundaries
232             void handleProcPatches();
234             //- Calculate cyclic halves addressing.
235             void calcCyclicAddressing();
237             //- Merge data from across cyclic boundaries
238             void handleCyclicPatches();
241         //- Disallow default bitwise copy construct
242         PointEdgeWave(const PointEdgeWave&);
244         //- Disallow default bitwise assignment
245         void operator=(const PointEdgeWave&);
247 public:
249     // Static Functions
251         //- Access to tolerance
252         static scalar propagationTol()
253         {
254             return propagationTol_;
255         }
257         //- Change tolerance
258         static void setPropagationTol(const scalar tol)
259         {
260             propagationTol_ = tol;
261         }
265     // Constructors
267         //- Construct from mesh, list of changed points with the Type
268         //  for these points. Gets work arrays to operate on, one of size
269         //  number of mesh points, the other number of mesh edges.
270         //  Iterates until nothing changes or maxIter reached.
271         //  (maxIter can be 0)
272         PointEdgeWave
273         (
274             const polyMesh& mesh,
275             const labelList& initialPoints,
276             const List<Type>& initialPointsInfo,
277             List<Type>& allPointInfo,
278             List<Type>& allEdgeInfo,
279             const label maxIter
280         );
283     // Destructor
285         ~PointEdgeWave();
288     // Member Functions
290         //- Get allPointInfo
291         const List<Type>& allPointInfo() const
292         {
293             return allPointInfo_;
294         }
296         //- Get allEdgeInfo
297         const List<Type>& allEdgeInfo() const
298         {
299             return allEdgeInfo_;
300         }
302         //- Get number of unvisited edges, i.e. edges that were not (yet)
303         //  reached from walking across mesh. This can happen from
304         //  - not enough iterations done
305         //  - a disconnected mesh
306         //  - a mesh without walls in it
307         label getUnsetEdges() const;
309         label getUnsetPoints() const;
311         //- Copy initial data into allPointInfo_
312         void setPointInfo
313         (
314             const labelList& changedPoints,
315             const List<Type>& changedPointsInfo
316         );
318         //- Propagate from point to edge. Returns total number of edges
319         //  (over all processors) changed.
320         label pointToEdge();
322         //- Propagate from edge to point. Returns total number of points
323         //  (over all processors) changed.
324         label edgeToPoint();
326         //- Iterate until no changes or maxIter reached. Returns actual
327         //  number of iterations.
328         label iterate(const label maxIter);
332 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
334 /*---------------------------------------------------------------------------*\
335                         Class listUpdateOp Declaration
336 \*---------------------------------------------------------------------------*/
338 //- List update operation
339 template <class Type>
340 class listUpdateOp
343 public:
345     void operator()(List<Type>& x, const List<Type>& y) const
346     {
347         forAll(x, i)
348         {
349             x[i].updatePoint(y[i], PointEdgeWave<Type>::propagationTol());
350         }
351     }
354 } // End namespace Foam
357 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
359 #ifdef NoRepository
360 #   include "PointEdgeWave.C"
361 #endif
363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
365 #endif
367 // ************************************************************************* //