OpenFOAM logo
Open Source CFD Toolkit

meshWave.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-2005 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     meshWave
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     meshWave.C
00045 
00046 \*---------------------------------------------------------------------------*/
00047 
00048 #ifndef meshWave_H
00049 #define meshWave_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 meshWaveName Declaration
00066 \*---------------------------------------------------------------------------*/
00067 
00068 TemplateName(meshWave);
00069 
00070 
00071 /*---------------------------------------------------------------------------*\
00072                            Class meshWave Declaration
00073 \*---------------------------------------------------------------------------*/
00074 
00075 template <class Type>
00076 class meshWave
00077 :
00078     public meshWaveName
00079 {
00080     // Private data
00081 
00082         //- Reference to mesh
00083         const polyMesh& mesh_;
00084 
00085         //- Wall information for all cells
00086         List<Type> allCellInfo_;
00087 
00088         //- Wall information for all faces
00089         List<Type> allFaceInfo_;
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         //- For debugging: string containing processor number
00122         const string procLabel_;
00123 
00124     // Static Functions
00125 
00126         //- Write faces info
00127         static Ostream& writeFaces
00128         (
00129             const label nFaces,
00130             const labelList& faceLabels,
00131             const List<Type>& faceInfo,
00132             Ostream& os
00133         );
00134 
00135         //- Read faces info
00136         static Istream& readFaces
00137         (
00138             label& nFaces,
00139             labelList& faceLabels,
00140             List<Type>& faceInfo,
00141             Istream& is
00142         );
00143 
00144 
00145     // Private Member Functions
00146 
00147         //- Disallow default bitwise copy construct
00148         meshWave(const meshWave&);
00149 
00150         //- Disallow default bitwise assignment
00151         void operator=(const meshWave&);
00152 
00153 
00154         //- Updates cellInfo with information from neighbour. Updates all
00155         //  statistics.
00156         bool updateCell
00157         (
00158             const label cellI,
00159             const label neighbourFaceI,
00160             const Type& neighbourInfo,
00161             const scalar tol,
00162             Type& cellInfo
00163         );
00164 
00165         //- Updates faceInfo with information from neighbour. Updates all
00166         //  statistics.
00167         bool updateFace
00168         (
00169             const label faceI,
00170             const label neighbourCellI,
00171             const Type& neighbourInfo,
00172             const scalar tol,
00173             Type& faceInfo
00174         );
00175 
00176         //- Updates faceInfo with information from same face. Updates all
00177         //  statistics.
00178         bool updateFace
00179         (
00180             const label faceI,
00181             const Type& neighbourInfo,
00182             const scalar tol,
00183             Type& faceInfo
00184         );
00185 
00186         //- Copy face info into member data
00187         void setFaceInfo
00188         (
00189             const labelList& changedFaces,
00190             const List<Type>& changedFacesInfo
00191         );
00192 
00193 
00194         // Parallel, cyclic
00195 
00196             //- Debugging: check info on both sides of cyclic
00197             void checkCyclic(const polyPatch& pPatch) const;
00198 
00199             //- Has patches of certain type?
00200             bool hasPatchType(const word& nameOfType);
00201 
00202             //- Merge received patch data into global data
00203             void mergeFaceInfo
00204             (
00205                 const polyPatch& patch,
00206                 const label nFaces,
00207                 const labelList&,
00208                 const List<Type>&,
00209                 const bool isParallel
00210             );
00211 
00212             //- Extract info for single patch only
00213             label getChangedPatchFaces
00214             (
00215                 const polyPatch& patch,
00216                 const label startFaceI,
00217                 const label nFaces,
00218                 labelList& changedPatchFaces,
00219                 List<Type>& changedPatchFacesInfo
00220             ) const;
00221 
00222             //- Handle leaving domain. Implementation referred to Type
00223             void leaveDomain
00224             (
00225                 const polyPatch& patch,
00226                 const label nFaces,
00227                 const labelList& faceLabels,
00228                 List<Type>& faceInfo
00229             ) const;
00230 
00231             //- Handle leaving domain. Implementation referred to Type
00232             void enterDomain
00233             (
00234                 const polyPatch& patch,
00235                 const label nFaces,
00236                 const labelList& faceLabels,
00237                 List<Type>& faceInfo
00238             ) const;
00239 
00240             //- Send info to neighbour
00241             void sendPatchInfo
00242             (
00243                 const label neighbour,
00244                 const label nFaces,
00245                 const labelList&,
00246                 const List<Type>&
00247             ) const;
00248 
00249             //- Receive info from neighbour. Returns number of faces received.
00250             label receivePatchInfo
00251             (
00252                 const label neighbour,
00253                 labelList&,
00254                 List<Type>&
00255             ) const;
00256 
00257             //- Offset face labels by constant value
00258             static void offset
00259             (
00260                 const polyPatch& patch,
00261                 const label off,
00262                 const label nFaces,
00263                 labelList& faces
00264             );
00265 
00266             //- Apply transformation to Type
00267             static void transform
00268             (
00269                 const tensorField& rotTensor,
00270                 const label nFaces,
00271                 List<Type>& faceInfo
00272             );
00273 
00274             //- Merge data from across processor boundaries
00275             void handleProcPatches();
00276 
00277             //- Merge data from across cyclics
00278             void handleCyclicPatches();
00279 
00280 
00281       // Private static data
00282 
00283             static const scalar geomTol_;
00284             static const scalar propagationTol_;
00285 
00286 public:
00287 
00288     // Constructors
00289 
00290         //- Construct from mesh and list of changed faces with the Type
00291         //  for these faces. Iterates until nothing changes or maxIter reached.
00292         //  (maxIter can be 0)
00293         meshWave
00294         (
00295             const polyMesh& mesh,
00296             const labelList& initialChangedFaces,
00297             const List<Type>& changedFacesInfo,
00298             const label maxIter
00299         );
00300 
00301         //- Construct from mesh, list of changed faces with the Type
00302         //  for these faces and initial field.
00303         //  Iterates until nothing changes or maxIter reached.
00304         //  (maxIter can be 0)
00305         meshWave
00306         (
00307             const polyMesh& mesh,
00308             const labelList& initialChangedFaces,
00309             const List<Type>& changedFacesInfo,
00310             const List<Type>& allCellInfo,
00311             const label maxIter
00312         );
00313 
00314 
00315     // Destructor
00316 
00317         ~meshWave();
00318 
00319 
00320     // Member Functions
00321 
00322         //- Get allFaceInfo
00323         const List<Type>& allFaceInfo() const
00324         {
00325             return allFaceInfo_;
00326         }
00327 
00328         //- Get allCellInfo
00329         const List<Type>& allCellInfo() const
00330         {
00331             return allCellInfo_;
00332         }
00333 
00334         //- Get number of unvisited cells, i.e. cells that were not (yet)
00335         //  reached from walking across mesh. This can happen from
00336         //  - not enough iterations done
00337         //  - a disconnected mesh
00338         //  - a mesh without walls in it
00339         label getUnsetCells() const;
00340 
00341         label getUnsetFaces() const;
00342 
00343         //- Propagate from face to cell. Returns total number of cells
00344         //  (over all processors) changed.
00345         label faceToCell();
00346 
00347         //- Propagate from cell to face. Returns total number of faces
00348         //  (over all processors) changed. (Faces on processorpatches are
00349         //  counted double)
00350         label cellToFace();
00351 
00352         //- Iterate until no changes or maxIter reached.
00353         label iterate(const label maxIter);
00354 };
00355 
00356 
00357 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00358 
00359 } // End namespace Foam
00360 
00361 
00362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00363 
00364 #ifdef NoRepository
00365 #   include "meshWave.C"
00366 #endif
00367 
00368 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00369 
00370 #endif
00371 
00372 // ************************************************************************* //
For further information go to www.openfoam.org