OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

FaceCellWave.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     FaceCellWave
00027 
00028 Description
00029     Wave propagation of information through grid. Every iteration
00030     information goes through one layer of cells. Templated on information
00031     that is transferred.
00032 
00033     Handles parallel and cyclics and non-parallel cyclics.
00034 
00035     Note: whether to propagate depends on the return value of Type::update
00036     which returns true (i.e. propagate) if the value changes by more than a
00037     certain tolerance.
00038     This tolerance can be very strict for normal face-cell and parallel
00039     cyclics (we use a value of 0.01 just to limit propagation of small changes)
00040     but for non-parallel cyclics this tolerance can be critical and if chosen
00041     too small can lead to non-convergence.
00042 
00043 SourceFiles
00044     FaceCellWave.C
00045 
00046 \*---------------------------------------------------------------------------*/
00047 
00048 #ifndef FaceCellWave_H
00049 #define FaceCellWave_H
00050 
00051 #include "boolList.H"
00052 #include "labelList.H"
00053 #include "primitiveFieldsFwd.H"
00054 
00055 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00056 
00057 namespace Foam
00058 {
00059 
00060 // Class forward declarations
00061 class polyMesh;
00062 class polyPatch;
00063 
00064 /*---------------------------------------------------------------------------*\
00065                         Class FaceCellWaveName Declaration
00066 \*---------------------------------------------------------------------------*/
00067 
00068 TemplateName(FaceCellWave);
00069 
00070 
00071 /*---------------------------------------------------------------------------*\
00072                            Class FaceCellWave Declaration
00073 \*---------------------------------------------------------------------------*/
00074 
00075 template <class Type>
00076 class FaceCellWave
00077 :
00078     public FaceCellWaveName
00079 {
00080     // Private data
00081 
00082         //- Reference to mesh
00083         const polyMesh& mesh_;
00084 
00085         //- Information for all faces
00086         UList<Type>& allFaceInfo_;
00087 
00088         //- Information for all cells
00089         UList<Type>& allCellInfo_;
00090 
00091         //- Has face changed
00092         boolList changedFace_;
00093 
00094         //- List of changed faces
00095         labelList changedFaces_;
00096 
00097         //- Number of changed faces
00098         label nChangedFaces_;
00099 
00100         // Cells that have changed
00101         boolList changedCell_;
00102         labelList changedCells_;
00103         label nChangedCells_;
00104 
00105         //- Contains cyclics
00106         bool hasCyclicPatches_;
00107 
00108         //- Contains processor patches
00109         bool hasProcPatches_;
00110 
00111         //- Number of evaluations
00112         label nEvals_;
00113 
00114         //- Number of unvisited cells/faces
00115         label nUnvisitedCells_;
00116         label nUnvisitedFaces_;
00117 
00118         //- Iteration counter
00119         label iter_;
00120 
00121 
00122     // Static Functions
00123 
00124         //- Write faces info
00125         static Ostream& writeFaces
00126         (
00127             const label nFaces,
00128             const labelList& faceLabels,
00129             const List<Type>& faceInfo,
00130             Ostream& os
00131         );
00132 
00133         //- Read faces info
00134         static Istream& readFaces
00135         (
00136             label& nFaces,
00137             labelList& faceLabels,
00138             List<Type>& faceInfo,
00139             Istream& is
00140         );
00141 
00142 
00143     // Private Member Functions
00144 
00145         //- Disallow default bitwise copy construct
00146         FaceCellWave(const FaceCellWave&);
00147 
00148         //- Disallow default bitwise assignment
00149         void operator=(const FaceCellWave&);
00150 
00151 
00152         //- Updates cellInfo with information from neighbour. Updates all
00153         //  statistics.
00154         bool updateCell
00155         (
00156             const label cellI,
00157             const label neighbourFaceI,
00158             const Type& neighbourInfo,
00159             const scalar tol,
00160             Type& cellInfo
00161         );
00162 
00163         //- Updates faceInfo with information from neighbour. Updates all
00164         //  statistics.
00165         bool updateFace
00166         (
00167             const label faceI,
00168             const label neighbourCellI,
00169             const Type& neighbourInfo,
00170             const scalar tol,
00171             Type& faceInfo
00172         );
00173 
00174         //- Updates faceInfo with information from same face. Updates all
00175         //  statistics.
00176         bool updateFace
00177         (
00178             const label faceI,
00179             const Type& neighbourInfo,
00180             const scalar tol,
00181             Type& faceInfo
00182         );
00183 
00184 
00185         // Parallel, cyclic
00186 
00187             //- Debugging: check info on both sides of cyclic
00188             void checkCyclic(const polyPatch& pPatch) const;
00189 
00190             //- Has patches of certain type?
00191             bool hasPatchType(const word& nameOfType);
00192 
00193             //- Merge received patch data into global data
00194             void mergeFaceInfo
00195             (
00196                 const polyPatch& patch,
00197                 const label nFaces,
00198                 const labelList&,
00199                 const List<Type>&,
00200                 const bool isParallel
00201             );
00202 
00203             //- Extract info for single patch only
00204             label getChangedPatchFaces
00205             (
00206                 const polyPatch& patch,
00207                 const label startFaceI,
00208                 const label nFaces,
00209                 labelList& changedPatchFaces,
00210                 List<Type>& changedPatchFacesInfo
00211             ) const;
00212 
00213             //- Handle leaving domain. Implementation referred to Type
00214             void leaveDomain
00215             (
00216                 const polyPatch& patch,
00217                 const label nFaces,
00218                 const labelList& faceLabels,
00219                 List<Type>& faceInfo
00220             ) const;
00221 
00222             //- Handle leaving domain. Implementation referred to Type
00223             void enterDomain
00224             (
00225                 const polyPatch& patch,
00226                 const label nFaces,
00227                 const labelList& faceLabels,
00228                 List<Type>& faceInfo
00229             ) const;
00230 
00231             //- Send info to neighbour
00232             void sendPatchInfo
00233             (
00234                 const label neighbour,
00235                 const label nFaces,
00236                 const labelList&,
00237                 const List<Type>&
00238             ) const;
00239 
00240             //- Receive info from neighbour. Returns number of faces received.
00241             label receivePatchInfo
00242             (
00243                 const label neighbour,
00244                 labelList&,
00245                 List<Type>&
00246             ) const;
00247 
00248             //- Offset face labels by constant value
00249             static void offset
00250             (
00251                 const polyPatch& patch,
00252                 const label off,
00253                 const label nFaces,
00254                 labelList& faces
00255             );
00256 
00257             //- Apply transformation to Type
00258             void transform
00259             (
00260                 const tensorField& rotTensor,
00261                 const label nFaces,
00262                 List<Type>& faceInfo
00263             );
00264 
00265             //- Merge data from across processor boundaries
00266             void handleProcPatches();
00267 
00268             //- Merge data from across cyclics
00269             void handleCyclicPatches();
00270 
00271 
00272       // Private static data
00273 
00274             static const scalar geomTol_;
00275             static const scalar propagationTol_;
00276 
00277 public:
00278 
00279     // Static Functions
00280 
00281         //- Access to tolerance
00282         static scalar propagationTol()
00283         {
00284             return propagationTol_;
00285         }
00286 
00287         //- Change tolerance
00288         static void setPropagationTol(const scalar tol)
00289         {
00290             propagationTol_ = tol;
00291         }
00292 
00293 
00294     // Constructors
00295 
00296         // Construct from mesh. Use setFaceInfo and iterate() to do actual
00297         // calculation.
00298         FaceCellWave
00299         (
00300             const polyMesh&,
00301             UList<Type>& allFaceInfo,
00302             UList<Type>& allCellInfo
00303         );
00304 
00305         //- Construct from mesh and list of changed faces with the Type
00306         //  for these faces. Iterates until nothing changes or maxIter reached.
00307         //  (maxIter can be 0)
00308         FaceCellWave
00309         (
00310             const polyMesh&,
00311             const labelList& initialChangedFaces,
00312             const List<Type>& changedFacesInfo,
00313             UList<Type>& allFaceInfo,
00314             UList<Type>& allCellInfo,
00315             const label maxIter
00316         );
00317 
00318 
00319     // Member Functions
00320 
00321         // Access
00322 
00323             //- Access allFaceInfo
00324             UList<Type>& allFaceInfo()
00325             {
00326                 return allFaceInfo_;
00327             }
00328 
00329             //- Access allCellInfo
00330             UList<Type>& allCellInfo()
00331             {
00332                 return allCellInfo_;
00333             }
00334 
00335             //- Access mesh
00336             const polyMesh& mesh() const
00337             {   
00338                 return mesh_;
00339             }
00340 
00341             //- Get number of unvisited cells, i.e. cells that were not (yet)
00342             //  reached from walking across mesh. This can happen from
00343             //  - not enough iterations done
00344             //  - a disconnected mesh
00345             //  - a mesh without walls in it
00346             label getUnsetCells() const;
00347 
00348             //- Get number of unvisited faces
00349             label getUnsetFaces() const;
00350 
00351 
00352         // Edit
00353 
00354             //- Set initial changed faces
00355             void setFaceInfo
00356             (
00357                 const labelList& changedFaces,
00358                 const List<Type>& changedFacesInfo
00359             );
00360 
00361             //- Propagate from face to cell. Returns total number of cells
00362             //  (over all processors) changed.
00363             label faceToCell();
00364 
00365             //- Propagate from cell to face. Returns total number of faces
00366             //  (over all processors) changed. (Faces on processorpatches are
00367             //  counted double)
00368             label cellToFace();
00369 
00370             //- Iterate until no changes or maxIter reached. Returns number of
00371             //  unset cells (see getUnsetCells)
00372             label iterate(const label maxIter);
00373 };
00374 
00375 
00376 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00377 
00378 } // End namespace Foam
00379 
00380 
00381 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00382 
00383 #ifdef NoRepository
00384 #   include "FaceCellWave.C"
00385 #endif
00386 
00387 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00388 
00389 #endif
00390 
00391 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd