OpenFOAM logo
Open Source CFD Toolkit

PointEdgeWave.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     PointEdgeWave
00027 
00028 Description
00029     Wave propagation of information through grid. Every iteration
00030     information goes through one layer of edges. Templated on information
00031     that is transferred.
00032 
00033     Handles parallel and cyclics. Only parallel reasonably tested. Cyclics
00034     hardly tested.
00035 
00036     Note: whether to propagate depends on the return value of Type::update
00037     which returns true (i.e. propagate) if the value changes by more than a
00038     certain tolerance.
00039 
00040     Note: parallel is done in two steps:
00041     1. transfer patch points in offset notation, i.e. every patch point is
00042     denoted by a patchface label and an index in this face. Receiving end uses
00043     that fact that f[0] is shared and order is reversed.
00044     2. do all non-local shared points by means of reduce of data on them.
00045 
00046     Note: cyclics is with offset in patchface as well. Patch is divided into
00047     two sub patches and the point-point addressing is never explicitly
00048     calculated but instead use is made of the face-face correspondence.
00049     (it probably is more efficient to calculate a point-point
00050     correspondence at the start and then reuse this; task to be done)
00051 
00052 SourceFiles
00053     PointEdgeWave.C
00054 
00055 \*---------------------------------------------------------------------------*/
00056 
00057 #ifndef PointEdgeWave_H
00058 #define PointEdgeWave_H
00059 
00060 #include "label.H"
00061 #include "boolList.H"
00062 #include "labelList.H"
00063 #include "scalarField.H"
00064 #include "pointFields.H"
00065 #include "tensor.H"
00066 #include "primitivePatch.H"
00067 #include "PtrList.H"
00068 
00069 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00070 
00071 namespace Foam
00072 {
00073 
00074 // Class forward declarations
00075 class pointMesh;
00076 
00077 
00078 /*---------------------------------------------------------------------------*\
00079                         Class PointEdgeWaveName Declaration
00080 \*---------------------------------------------------------------------------*/
00081 
00082 TemplateName(PointEdgeWave);
00083 
00084 
00085 /*---------------------------------------------------------------------------*\
00086                            Class PointEdgeWave Declaration
00087 \*---------------------------------------------------------------------------*/
00088 
00089 template <class Type>
00090 class PointEdgeWave
00091 :
00092     public PointEdgeWaveName
00093 {
00094   // Private static data
00095 
00096         //- Relative tolerance. Stop propagation if relative changes
00097         //  less than this tolerance (responsability for checking this is
00098         //  up to Type implementation)
00099         static scalar propagationTol_;
00100 
00101 
00102     // Private data
00103 
00104         //- Reference to mesh
00105         const pointMesh& pMesh_;
00106 
00107         //- Wall information for all points
00108         List<Type>& allPointInfo_;
00109 
00110         //- Information on all mesh edges
00111         List<Type>& allEdgeInfo_;
00112 
00113         //- Has point changed
00114         boolList changedPoint_;
00115 
00116         //- List of changed points
00117         labelList changedPoints_;
00118 
00119         //- Number of changed points
00120         label nChangedPoints_;
00121 
00122         //- Edges that have changed
00123         boolList changedEdge_;
00124         labelList changedEdges_;
00125         label nChangedEdges_;
00126 
00127         //- Number of cyclic patches
00128         bool nCyclicPatches_;
00129 
00130         //- For every cyclic patch two primitivePatches
00131         PtrList<primitivePatch> cycHalves_;
00132 
00133         //- Contains processor patches
00134         bool hasProcPatches_;
00135 
00136         //- Number of evaluations
00137         label nEvals_;
00138 
00139         //- Number of unvisited edges/points
00140         label nUnvisitedPoints_;
00141         label nUnvisitedEdges_;
00142 
00143         //- Iteration counter
00144         label iter_;
00145 
00146 
00147     // Private Member Functions
00148 
00149         //- Add value to all elements of labelList
00150         static void offset(const label val, labelList& elems);
00151 
00152 
00153         //- Adapt pointInfo for leaving domain
00154         void leaveDomain
00155         (
00156             const polyPatch& meshPatch,
00157             const primitivePatch& patch,
00158             const List<label>& patchPointLabels,
00159             List<Type>& pointInfo
00160         ) const;
00161 
00162         //- Adapt pointInfo for entering domain
00163         void enterDomain
00164         (
00165             const polyPatch& meshPatch,
00166             const primitivePatch& patch,
00167             const List<label>& patchPointLabels,
00168             List<Type>& pointInfo
00169         ) const;
00170 
00171         //- Transform. Implementation referred to Type
00172         void transform
00173         (
00174             const tensorField& rotTensor,
00175             List<Type>& pointInfo
00176         ) const;
00177 
00178         //- Updates pointInfo with information from neighbour. Updates all
00179         //  statistics.
00180         bool updatePoint
00181         (
00182             const label pointI,
00183             const label neighbourEdgeI,
00184             const Type& neighbourInfo,
00185             const scalar tol,
00186             Type& pointInfo
00187         );
00188 
00189         //- Updates pointInfo with information from same point. Updates all
00190         //  statistics.
00191         bool updatePoint
00192         (
00193             const label pointI,
00194             const Type& neighbourInfo,
00195             const scalar tol,
00196             Type& pointInfo
00197         );
00198 
00199         //- Updates edgeInfo with information from neighbour. Updates all
00200         //  statistics.
00201         bool updateEdge
00202         (
00203             const label edgeI,
00204             const label neighbourPointI,
00205             const Type& neighbourInfo,
00206             const scalar tol,
00207             Type& edgeInfo
00208         );
00209 
00210         //- Copy initial data into allPointInfo_
00211         void setPointInfo
00212         (
00213             const labelList& changedPoints,
00214             const List<Type>& changedPointsInfo
00215         );
00216 
00217         // Parallel, cyclic
00218 
00219             //- Has patches of certain type?
00220             template <class PatchType>
00221             label countPatchType() const;
00222 
00223             //- Get info on patch points
00224             void getChangedPatchPoints
00225             (
00226                 const primitivePatch& patch,
00227                 DynamicList<Type>& patchInfo,
00228                 DynamicList<label>& patchPoints,
00229                 DynamicList<label>& owner,
00230                 DynamicList<label>& ownerIndex
00231             ) const;
00232 
00233             //- Merge data from patch into overall data
00234             void updateFromPatchInfo
00235             (
00236                 const polyPatch& meshPatch,
00237                 const primitivePatch& patch,
00238                 const labelList& owner,
00239                 const labelList& ownerIndex,
00240                 List<Type>& patchInfo
00241             );
00242 
00243             //- Merge data from across processor boundaries
00244             void handleProcPatches();
00245 
00246             //- Calculate cyclic halves addressing.
00247             void calcCyclicAddressing();
00248 
00249             //- Merge data from across cyclic boundaries
00250             void handleCyclicPatches();
00251 
00252 
00253         //- Disallow default bitwise copy construct
00254         PointEdgeWave(const PointEdgeWave&);
00255 
00256         //- Disallow default bitwise assignment
00257         void operator=(const PointEdgeWave&);
00258 
00259 public:
00260 
00261     // Static Functions
00262 
00263         //- Access to tolerance
00264         static scalar propagationTol()
00265         {
00266             return propagationTol_;
00267         }
00268 
00269         //- Change tolerance
00270         static void setPropagationTol(const scalar tol)
00271         {
00272             propagationTol_ = tol;
00273         }
00274 
00275 
00276 
00277     // Constructors
00278 
00279         //- Construct from mesh, list of changed points with the Type
00280         //  for these points. Gets work arrays to operate on, one of size
00281         //  number of mesh points, the other number of mesh edges.
00282         //  Iterates until nothing changes or maxIter reached.
00283         //  (maxIter can be 0)
00284         PointEdgeWave
00285         (
00286             const pointMesh& pMesh,
00287             const labelList& initialPoints,
00288             const List<Type>& initialPointsInfo,
00289             List<Type>& allPointInfo,
00290             List<Type>& allEdgeInfo,
00291             const label maxIter
00292         );
00293 
00294 
00295     // Destructor
00296 
00297         ~PointEdgeWave();
00298 
00299 
00300     // Member Functions
00301 
00302         //- Get allPointInfo
00303         const List<Type>& allPointInfo() const
00304         {
00305             return allPointInfo_;
00306         }
00307 
00308         //- Get allEdgeInfo
00309         const List<Type>& allEdgeInfo() const
00310         {
00311             return allEdgeInfo_;
00312         }
00313 
00314 
00315 
00316         //- Get number of unvisited edges, i.e. edges that were not (yet)
00317         //  reached from walking across mesh. This can happen from
00318         //  - not enough iterations done
00319         //  - a disconnected mesh
00320         //  - a mesh without walls in it
00321         label getUnsetEdges() const;
00322 
00323         label getUnsetPoints() const;
00324 
00325         //- Propagate from point to edge. Returns total number of edges
00326         //  (over all processors) changed.
00327         label pointToEdge();
00328 
00329         //- Propagate from edge to point. Returns total number of points
00330         //  (over all processors) changed.
00331         label edgeToPoint();
00332 
00333         //- Iterate until no changes or maxIter reached.
00334         label iterate(const label maxIter);
00335 };
00336 
00337 
00338 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00339 
00340 /*---------------------------------------------------------------------------*\
00341                         Class listUpdateOp Declaration
00342 \*---------------------------------------------------------------------------*/
00343 
00344 
00345 template <class Type>
00346 class listUpdateOp
00347 {
00348 
00349 public:
00350 
00351     void operator()(List<Type>& x, const List<Type>& y) const
00352     {
00353         forAll(x, i)
00354         {
00355             x[i].updatePoint(y[i], PointEdgeWave<Type>::propagationTol());
00356         }
00357     }
00358 };
00359 
00360 
00361 
00362 
00363 
00364 } // End namespace Foam
00365 
00366 
00367 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00368 
00369 #ifdef NoRepository
00370 #   include "PointEdgeWave.C"
00371 #endif
00372 
00373 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00374 
00375 #endif
00376 
00377 // ************************************************************************* //
For further information go to www.openfoam.org