OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide 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-2009 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     Foam::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 // Forward declaration of classes
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         //- Number of evaluations
00109         label nEvals_;
00110 
00111         //- Number of unvisited cells/faces
00112         label nUnvisitedCells_;
00113         label nUnvisitedFaces_;
00114 
00115         //- Iteration counter
00116         label iter_;
00117 
00118 
00119     // Static Functions
00120 
00121         //- Write faces info
00122         static Ostream& writeFaces
00123         (
00124             const label nFaces,
00125             const labelList& faceLabels,
00126             const List<Type>& faceInfo,
00127             Ostream& os
00128         );
00129 
00130         //- Read faces info
00131         static Istream& readFaces
00132         (
00133             label& nFaces,
00134             labelList& faceLabels,
00135             List<Type>& faceInfo,
00136             Istream& is
00137         );
00138 
00139 
00140     // Private Member Functions
00141 
00142         //- Disallow default bitwise copy construct
00143         FaceCellWave(const FaceCellWave&);
00144 
00145         //- Disallow default bitwise assignment
00146         void operator=(const FaceCellWave&);
00147 
00148 
00149         //- Updates cellInfo with information from neighbour. Updates all
00150         //  statistics.
00151         bool updateCell
00152         (
00153             const label cellI,
00154             const label neighbourFaceI,
00155             const Type& neighbourInfo,
00156             const scalar tol,
00157             Type& cellInfo
00158         );
00159 
00160         //- Updates faceInfo with information from neighbour. Updates all
00161         //  statistics.
00162         bool updateFace
00163         (
00164             const label faceI,
00165             const label neighbourCellI,
00166             const Type& neighbourInfo,
00167             const scalar tol,
00168             Type& faceInfo
00169         );
00170 
00171         //- Updates faceInfo with information from same face. Updates all
00172         //  statistics.
00173         bool updateFace
00174         (
00175             const label faceI,
00176             const Type& neighbourInfo,
00177             const scalar tol,
00178             Type& faceInfo
00179         );
00180 
00181 
00182         // Parallel, cyclic
00183 
00184             //- Debugging: check info on both sides of cyclic
00185             void checkCyclic(const polyPatch& pPatch) const;
00186 
00187             //- Has patches of certain type?
00188             bool hasPatchType(const word& nameOfType);
00189 
00190             //- Merge received patch data into global data
00191             void mergeFaceInfo
00192             (
00193                 const polyPatch& patch,
00194                 const label nFaces,
00195                 const labelList&,
00196                 const List<Type>&,
00197                 const bool isParallel
00198             );
00199 
00200             //- Extract info for single patch only
00201             label getChangedPatchFaces
00202             (
00203                 const polyPatch& patch,
00204                 const label startFaceI,
00205                 const label nFaces,
00206                 labelList& changedPatchFaces,
00207                 List<Type>& changedPatchFacesInfo
00208             ) const;
00209 
00210             //- Handle leaving domain. Implementation referred to Type
00211             void leaveDomain
00212             (
00213                 const polyPatch& patch,
00214                 const label nFaces,
00215                 const labelList& faceLabels,
00216                 List<Type>& faceInfo
00217             ) const;
00218 
00219             //- Handle leaving domain. Implementation referred to Type
00220             void enterDomain
00221             (
00222                 const polyPatch& patch,
00223                 const label nFaces,
00224                 const labelList& faceLabels,
00225                 List<Type>& faceInfo
00226             ) const;
00227 
00228             //- Send info to neighbour
00229             void sendPatchInfo
00230             (
00231                 const label neighbour,
00232                 const label nFaces,
00233                 const labelList&,
00234                 const List<Type>&
00235             ) const;
00236 
00237             //- Receive info from neighbour. Returns number of faces received.
00238             label receivePatchInfo
00239             (
00240                 const label neighbour,
00241                 labelList&,
00242                 List<Type>&
00243             ) const;
00244 
00245             //- Offset face labels by constant value
00246             static void offset
00247             (
00248                 const polyPatch& patch,
00249                 const label off,
00250                 const label nFaces,
00251                 labelList& faces
00252             );
00253 
00254             //- Apply transformation to Type
00255             void transform
00256             (
00257                 const tensorField& rotTensor,
00258                 const label nFaces,
00259                 List<Type>& faceInfo
00260             );
00261 
00262             //- Merge data from across processor boundaries
00263             void handleProcPatches();
00264 
00265             //- Merge data from across cyclics
00266             void handleCyclicPatches();
00267 
00268 
00269       // Private static data
00270 
00271             static const scalar geomTol_;
00272             static const scalar propagationTol_;
00273 
00274 public:
00275 
00276     // Static Functions
00277 
00278         //- Access to tolerance
00279         static scalar propagationTol()
00280         {
00281             return propagationTol_;
00282         }
00283 
00284         //- Change tolerance
00285         static void setPropagationTol(const scalar tol)
00286         {
00287             propagationTol_ = tol;
00288         }
00289 
00290 
00291     // Constructors
00292 
00293         // Construct from mesh. Use setFaceInfo and iterate() to do actual
00294         // calculation.
00295         FaceCellWave
00296         (
00297             const polyMesh&,
00298             UList<Type>& allFaceInfo,
00299             UList<Type>& allCellInfo
00300         );
00301 
00302         //- Construct from mesh and list of changed faces with the Type
00303         //  for these faces. Iterates until nothing changes or maxIter reached.
00304         //  (maxIter can be 0)
00305         FaceCellWave
00306         (
00307             const polyMesh&,
00308             const labelList& initialChangedFaces,
00309             const List<Type>& changedFacesInfo,
00310             UList<Type>& allFaceInfo,
00311             UList<Type>& allCellInfo,
00312             const label maxIter
00313         );
00314 
00315 
00316     // Member Functions
00317 
00318         // Access
00319 
00320             //- Access allFaceInfo
00321             UList<Type>& allFaceInfo()
00322             {
00323                 return allFaceInfo_;
00324             }
00325 
00326             //- Access allCellInfo
00327             UList<Type>& allCellInfo()
00328             {
00329                 return allCellInfo_;
00330             }
00331 
00332             //- Access mesh
00333             const polyMesh& mesh() const
00334             {   
00335                 return mesh_;
00336             }
00337 
00338             //- Get number of unvisited cells, i.e. cells that were not (yet)
00339             //  reached from walking across mesh. This can happen from
00340             //  - not enough iterations done
00341             //  - a disconnected mesh
00342             //  - a mesh without walls in it
00343             label getUnsetCells() const;
00344 
00345             //- Get number of unvisited faces
00346             label getUnsetFaces() const;
00347 
00348 
00349         // Edit
00350 
00351             //- Set initial changed faces
00352             void setFaceInfo
00353             (
00354                 const labelList& changedFaces,
00355                 const List<Type>& changedFacesInfo
00356             );
00357 
00358             //- Propagate from face to cell. Returns total number of cells
00359             //  (over all processors) changed.
00360             label faceToCell();
00361 
00362             //- Propagate from cell to face. Returns total number of faces
00363             //  (over all processors) changed. (Faces on processorpatches are
00364             //  counted double)
00365             label cellToFace();
00366 
00367             //- Iterate until no changes or maxIter reached. Returns number of
00368             //  unset cells (see getUnsetCells)
00369             label iterate(const label maxIter);
00370 
00371 };
00372 
00373 
00374 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00375 
00376 } // End namespace Foam
00377 
00378 
00379 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00380 
00381 #ifdef NoRepository
00382 #   include "FaceCellWave.C"
00383 #endif
00384 
00385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00386 
00387 #endif
00388 
00389 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd