initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / algorithms / MeshWave / FaceCellWave.H
blobfa4ee657eaeb5aa28825d09e8b643178676b5c00
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::FaceCellWave
28 Description
29     Wave propagation of information through grid. Every iteration
30     information goes through one layer of cells. Templated on information
31     that is transferred.
33     Handles parallel and cyclics and non-parallel cyclics.
35     Note: whether to propagate depends on the return value of Type::update
36     which returns true (i.e. propagate) if the value changes by more than a
37     certain tolerance.
38     This tolerance can be very strict for normal face-cell and parallel
39     cyclics (we use a value of 0.01 just to limit propagation of small changes)
40     but for non-parallel cyclics this tolerance can be critical and if chosen
41     too small can lead to non-convergence.
43 SourceFiles
44     FaceCellWave.C
46 \*---------------------------------------------------------------------------*/
48 #ifndef FaceCellWave_H
49 #define FaceCellWave_H
51 #include "boolList.H"
52 #include "labelList.H"
53 #include "primitiveFieldsFwd.H"
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 namespace Foam
60 // Forward declaration of classes
61 class polyMesh;
62 class polyPatch;
64 /*---------------------------------------------------------------------------*\
65                         Class FaceCellWaveName Declaration
66 \*---------------------------------------------------------------------------*/
68 TemplateName(FaceCellWave);
71 /*---------------------------------------------------------------------------*\
72                            Class FaceCellWave Declaration
73 \*---------------------------------------------------------------------------*/
75 template <class Type>
76 class FaceCellWave
78     public FaceCellWaveName
80     // Private data
82         //- Reference to mesh
83         const polyMesh& mesh_;
85         //- Information for all faces
86         UList<Type>& allFaceInfo_;
88         //- Information for all cells
89         UList<Type>& allCellInfo_;
91         //- Has face changed
92         boolList changedFace_;
94         //- List of changed faces
95         labelList changedFaces_;
97         //- Number of changed faces
98         label nChangedFaces_;
100         // Cells that have changed
101         boolList changedCell_;
102         labelList changedCells_;
103         label nChangedCells_;
105         //- Contains cyclics
106         bool hasCyclicPatches_;
108         //- Number of evaluations
109         label nEvals_;
111         //- Number of unvisited cells/faces
112         label nUnvisitedCells_;
113         label nUnvisitedFaces_;
115         //- Iteration counter
116         label iter_;
119     // Static Functions
121         //- Write faces info
122         static Ostream& writeFaces
123         (
124             const label nFaces,
125             const labelList& faceLabels,
126             const List<Type>& faceInfo,
127             Ostream& os
128         );
130         //- Read faces info
131         static Istream& readFaces
132         (
133             label& nFaces,
134             labelList& faceLabels,
135             List<Type>& faceInfo,
136             Istream& is
137         );
140     // Private Member Functions
142         //- Disallow default bitwise copy construct
143         FaceCellWave(const FaceCellWave&);
145         //- Disallow default bitwise assignment
146         void operator=(const FaceCellWave&);
149         //- Updates cellInfo with information from neighbour. Updates all
150         //  statistics.
151         bool updateCell
152         (
153             const label cellI,
154             const label neighbourFaceI,
155             const Type& neighbourInfo,
156             const scalar tol,
157             Type& cellInfo
158         );
160         //- Updates faceInfo with information from neighbour. Updates all
161         //  statistics.
162         bool updateFace
163         (
164             const label faceI,
165             const label neighbourCellI,
166             const Type& neighbourInfo,
167             const scalar tol,
168             Type& faceInfo
169         );
171         //- Updates faceInfo with information from same face. Updates all
172         //  statistics.
173         bool updateFace
174         (
175             const label faceI,
176             const Type& neighbourInfo,
177             const scalar tol,
178             Type& faceInfo
179         );
182         // Parallel, cyclic
184             //- Debugging: check info on both sides of cyclic
185             void checkCyclic(const polyPatch& pPatch) const;
187             //- Has patches of certain type?
188             bool hasPatchType(const word& nameOfType);
190             //- Merge received patch data into global data
191             void mergeFaceInfo
192             (
193                 const polyPatch& patch,
194                 const label nFaces,
195                 const labelList&,
196                 const List<Type>&,
197                 const bool isParallel
198             );
200             //- Extract info for single patch only
201             label getChangedPatchFaces
202             (
203                 const polyPatch& patch,
204                 const label startFaceI,
205                 const label nFaces,
206                 labelList& changedPatchFaces,
207                 List<Type>& changedPatchFacesInfo
208             ) const;
210             //- Handle leaving domain. Implementation referred to Type
211             void leaveDomain
212             (
213                 const polyPatch& patch,
214                 const label nFaces,
215                 const labelList& faceLabels,
216                 List<Type>& faceInfo
217             ) const;
219             //- Handle leaving domain. Implementation referred to Type
220             void enterDomain
221             (
222                 const polyPatch& patch,
223                 const label nFaces,
224                 const labelList& faceLabels,
225                 List<Type>& faceInfo
226             ) const;
228             //- Send info to neighbour
229             void sendPatchInfo
230             (
231                 const label neighbour,
232                 const label nFaces,
233                 const labelList&,
234                 const List<Type>&
235             ) const;
237             //- Receive info from neighbour. Returns number of faces received.
238             label receivePatchInfo
239             (
240                 const label neighbour,
241                 labelList&,
242                 List<Type>&
243             ) const;
245             //- Offset face labels by constant value
246             static void offset
247             (
248                 const polyPatch& patch,
249                 const label off,
250                 const label nFaces,
251                 labelList& faces
252             );
254             //- Apply transformation to Type
255             void transform
256             (
257                 const tensorField& rotTensor,
258                 const label nFaces,
259                 List<Type>& faceInfo
260             );
262             //- Merge data from across processor boundaries
263             void handleProcPatches();
265             //- Merge data from across cyclics
266             void handleCyclicPatches();
269       // Private static data
271             static const scalar geomTol_;
272             static const scalar propagationTol_;
274 public:
276     // Static Functions
278         //- Access to tolerance
279         static scalar propagationTol()
280         {
281             return propagationTol_;
282         }
284         //- Change tolerance
285         static void setPropagationTol(const scalar tol)
286         {
287             propagationTol_ = tol;
288         }
291     // Constructors
293         // Construct from mesh. Use setFaceInfo and iterate() to do actual
294         // calculation.
295         FaceCellWave
296         (
297             const polyMesh&,
298             UList<Type>& allFaceInfo,
299             UList<Type>& allCellInfo
300         );
302         //- Construct from mesh and list of changed faces with the Type
303         //  for these faces. Iterates until nothing changes or maxIter reached.
304         //  (maxIter can be 0)
305         FaceCellWave
306         (
307             const polyMesh&,
308             const labelList& initialChangedFaces,
309             const List<Type>& changedFacesInfo,
310             UList<Type>& allFaceInfo,
311             UList<Type>& allCellInfo,
312             const label maxIter
313         );
316     // Member Functions
318         // Access
320             //- Access allFaceInfo
321             UList<Type>& allFaceInfo()
322             {
323                 return allFaceInfo_;
324             }
326             //- Access allCellInfo
327             UList<Type>& allCellInfo()
328             {
329                 return allCellInfo_;
330             }
332             //- Access mesh
333             const polyMesh& mesh() const
334             {   
335                 return mesh_;
336             }
338             //- Get number of unvisited cells, i.e. cells that were not (yet)
339             //  reached from walking across mesh. This can happen from
340             //  - not enough iterations done
341             //  - a disconnected mesh
342             //  - a mesh without walls in it
343             label getUnsetCells() const;
345             //- Get number of unvisited faces
346             label getUnsetFaces() const;
349         // Edit
351             //- Set initial changed faces
352             void setFaceInfo
353             (
354                 const labelList& changedFaces,
355                 const List<Type>& changedFacesInfo
356             );
358             //- Propagate from face to cell. Returns total number of cells
359             //  (over all processors) changed.
360             label faceToCell();
362             //- Propagate from cell to face. Returns total number of faces
363             //  (over all processors) changed. (Faces on processorpatches are
364             //  counted double)
365             label cellToFace();
367             //- Iterate until no changes or maxIter reached. Returns number of
368             //  unset cells (see getUnsetCells)
369             label iterate(const label maxIter);
374 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
376 } // End namespace Foam
379 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
381 #ifdef NoRepository
382 #   include "FaceCellWave.C"
383 #endif
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 #endif
389 // ************************************************************************* //