OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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