FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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