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

globalMeshData.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::globalMeshData
00026 
00027 Description
00028     Various mesh related information for a parallel run. Upon construction
00029     constructs all info by using parallel communication. 
00030 
00031     Requires: 
00032     - all processor patches to have correct ordering.
00033     - all processorPatches to have their transforms set ('makeTransforms')
00034 
00035     The shared point addressing is quite interesting. It gives on each processor
00036     the vertices that cannot be set using a normal swap on processor patches.
00037     These are the vertices that are shared between more than 2 processors.
00038 
00039     There is an issue with these shared vertices if they originate from
00040     cyclics (i.e. are now separated processor patches). They will all be
00041     mapped to the same global point (so even though the processor points are
00042     not on the same location) since topologically they are one and the same.
00043 
00044     So if you ask for sharedPoints() you get only one of the coordinates of
00045     the topologically shared points.
00046 
00047     All the hard work of these shared points is done by the globalPoints class.
00048 
00049     Shared edges: similar to shared points gives on all processors the edges
00050     that are shared between more than two patches (i.e. the edges on which
00051     data cannot be synchronized by a straightforward edge data swap). Note
00052     that shared edges will use shared points but not all edges between shared
00053     points need to be shared edges (e.g. there might be an edge connecting
00054     two disconnected regions of shared points).
00055 
00056     Currently an edge is considered shared
00057     if it uses two shared points and is used more than once. This is not
00058     correct on processor patches but it only slightly overestimates the number
00059     of shared edges. Doing full analysis of how many patches use the edge
00060     would be too complicated.
00061 
00062     Shared edge calculation is demand driven so always make sure to have
00063     your first call to one of the access functions synchronous amongst all
00064     processors!
00065 
00066 
00067 SourceFiles
00068     globalMeshData.C
00069     globalMeshDataMorph.C
00070 
00071 \*---------------------------------------------------------------------------*/
00072 
00073 #ifndef globalMeshData_H
00074 #define globalMeshData_H
00075 
00076 #include <OpenFOAM/polyMesh.H>
00077 #include <OpenFOAM/Switch.H>
00078 #include "processorTopology.H"
00079 #include <OpenFOAM/labelPair.H>
00080 
00081 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00082 
00083 namespace Foam
00084 {
00085 
00086 // Forward declaration of friend functions and operators
00087 
00088 class globalMeshData;
00089 Ostream& operator<<(Ostream&, const globalMeshData&);
00090 
00091 
00092 /*---------------------------------------------------------------------------*\
00093                            Class globalMeshData Declaration
00094 \*---------------------------------------------------------------------------*/
00095 
00096 class globalMeshData
00097 :
00098     public processorTopology
00099 {
00100 
00101     // Private class
00102 
00103         // To combineReduce a pointField. Just appends all lists.
00104         template <class T>
00105         class plusEqOp
00106         {
00107 
00108         public:
00109 
00110             void operator()(T& x, const T& y) const
00111             {
00112                 label n = x.size();
00113 
00114                 x.setSize(x.size() + y.size());
00115 
00116                 forAll(y, i)
00117                 {
00118                     x[n++] = y[i];
00119                 }
00120             }
00121         };
00122 
00123 
00124         typedef List<labelPair> labelPairList;
00125 
00126 
00127     // Private data
00128 
00129         //- Reference to mesh
00130         const polyMesh& mesh_;
00131 
00132 
00133         // Data related to the complete mesh
00134 
00135             //- Bounding box of complete mesh
00136             boundBox bb_;
00137 
00138             //- Total number of points in the complete mesh
00139             label nTotalPoints_;
00140 
00141             //- Total number of faces in the complete mesh
00142             label nTotalFaces_;
00143 
00144             //- Total number of cells in the complete mesh
00145             label nTotalCells_;
00146 
00147 
00148         // Processor patch addressing (be careful if not running in parallel!)
00149 
00150             //- List of processor patch labels 
00151             //  (size of list = number of processor patches)
00152             labelList processorPatches_;
00153 
00154             //- List of indices into processorPatches_ for each patch.
00155             //  Index = -1 for non-processor patches.
00156             //  (size of list = number of patches)
00157             labelList processorPatchIndices_;
00158 
00159             //- processorPatchIndices_ of the neighbours processor patches
00160             labelList processorPatchNeighbours_;
00161 
00162 
00163         // Globally shared point addressing
00164 
00165             //- Total number of global points
00166             label nGlobalPoints_;
00167 
00168             //- Indices of local points that are globally shared
00169             labelList sharedPointLabels_;
00170 
00171             //- Indices of globally shared points in the master list
00172             //  This list contains all the shared points in the mesh
00173             labelList sharedPointAddr_;
00174 
00175             //- Shared point global labels.
00176             //  Global point index for every local shared point.
00177             //  Only valid if constructed with this information or if
00178             //  pointProcAddressing read.
00179             mutable labelList* sharedPointGlobalLabelsPtr_;
00180 
00181 
00182         // Globally shared edge addressing. Derived from shared points.
00183         // All demand driven since don't want to construct edges always.
00184 
00185             //- Total number of global edges
00186             mutable label nGlobalEdges_;
00187 
00188             //- Indices of local edges that are globally shared
00189             mutable labelList* sharedEdgeLabelsPtr_;
00190 
00191             //- Indices of globally shared edge in the master list
00192             //  This list contains all the shared edges in the mesh
00193             mutable labelList* sharedEdgeAddrPtr_;
00194 
00195 
00196     // Private Member Functions
00197 
00198         //- Set up processor patch addressing
00199         void initProcAddr();
00200 
00201         //- Helper function for shared edge addressing
00202         static void countSharedEdges
00203         (
00204             const HashTable<labelList, edge, Hash<edge> >& procSharedEdges,
00205             HashTable<label, edge, Hash<edge> >&,
00206             label&
00207         );
00208 
00209         //- Calculate shared edge addressing
00210         void calcSharedEdges() const;
00211 
00212         //- Count coincident faces.
00213         static label countCoincidentFaces
00214         (
00215             const scalar tolDim,
00216             const vectorField& separationDist
00217         );
00218 
00219         //- Disallow default bitwise copy construct
00220         globalMeshData(const globalMeshData&);
00221 
00222         //- Disallow default bitwise assignment
00223         void operator=(const globalMeshData&);
00224 
00225 
00226 public:
00227 
00228     //- Runtime type information
00229     ClassName("globalMeshData");
00230 
00231 
00232     // Static data members
00233 
00234         //- Geomtric tolerance (fraction of bounding box)
00235         static const Foam::scalar matchTol_;
00236 
00237 
00238     // Constructors
00239 
00240         //- Construct from mesh, derive rest (does parallel communication!)
00241         globalMeshData(const polyMesh& mesh);
00242 
00243         //- Old behaviour: read constructor given IOobject and a polyMesh
00244         //  reference. Only use this for testing!
00245         globalMeshData(const IOobject& io, const polyMesh& mesh);
00246 
00247 
00248     // Destructor
00249 
00250         ~globalMeshData();
00251 
00252         //- Remove all demand driven data
00253         void clearOut();
00254 
00255 
00256     // Member Functions
00257 
00258         // Access
00259 
00260             //- Return the mesh reference
00261             const polyMesh& mesh() const
00262             {
00263                 return mesh_;
00264             }
00265 
00266             //- Does the mesh contain processor patches? (also valid when
00267             //  not running parallel)
00268             bool parallel() const
00269             {
00270                 return processorPatches_.size() > 0;
00271             }
00272 
00273             const boundBox& bb() const
00274             {
00275                 return bb_;
00276             }
00277 
00278             //- Return total number of points in decomposed mesh
00279             label nTotalPoints() const
00280             {
00281                 return nTotalPoints_;
00282             }
00283 
00284             //- Return total number of faces in decomposed mesh
00285             label nTotalFaces() const
00286             {
00287                 return nTotalFaces_;
00288             }
00289 
00290             //- Return total number of cells in decomposed mesh
00291             label nTotalCells() const
00292             {
00293                 return nTotalCells_;
00294             }
00295 
00296 
00297         // Processor patch addressing (be careful when not running in parallel)
00298 
00299             //- Return list of processor patch labels 
00300             //  (size of list = number of processor patches)
00301             const labelList& processorPatches() const
00302             {
00303                 return processorPatches_;
00304             }
00305 
00306             //- Return list of indices into processorPatches_ for each patch.
00307             //  Index = -1 for non-processor parches.
00308             //  (size of list = number of patches)
00309             const labelList& processorPatchIndices() const
00310             {
00311                 return processorPatchIndices_;
00312             }
00313 
00314             //- Return processorPatchIndices of the neighbours
00315             //  processor patches. -1 if not running parallel.
00316             const labelList& processorPatchNeighbours() const
00317             {
00318                 return processorPatchNeighbours_;
00319             }
00320 
00321 
00322         // Globally shared point addressing
00323 
00324             //- Return number of globally shared points
00325             label nGlobalPoints() const
00326             {
00327                 return nGlobalPoints_;
00328             }
00329 
00330             //- Return indices of local points that are globally shared
00331             const labelList& sharedPointLabels() const
00332             {
00333                 return sharedPointLabels_;
00334             }
00335 
00336             //- Return addressing into the complete globally shared points
00337             //  list
00338             //  Note: It is assumed that a (never constructed) complete
00339             //  list of globally shared points exists.  The set of shared
00340             //  points on the current processor is a subset of all shared
00341             //  points. Shared point addressing gives the index in the
00342             //  list of all globally shared points for each of the locally
00343             //  shared points.
00344             const labelList& sharedPointAddr() const
00345             {
00346                 return sharedPointAddr_;
00347             }
00348 
00349             //- Return shared point global labels. Tries to read
00350             //  'pointProcAddressing' and returns list or -1 if none
00351             //  available.
00352             const labelList& sharedPointGlobalLabels() const;
00353 
00354             //- Collect coordinates of shared points on all processors.
00355             //  (does parallel communication!)
00356             //  Note: not valid for cyclicParallel since shared cyclic points
00357             //  are merged into single global point. (use geometricSharedPoints
00358             //  instead)
00359             pointField sharedPoints() const;
00360 
00361             //- Like sharedPoints but keeps cyclic points separate.
00362             //  (does geometric merging; uses matchTol_*bb as merging tolerance)
00363             //  Use sharedPoints() instead.
00364             pointField geometricSharedPoints() const;
00365 
00366 
00367 
00368         // Globally shared edge addressing
00369 
00370             //- Return number of globally shared edges. Demand-driven
00371             //  calculation so call needs to be synchronous among processors!
00372             label nGlobalEdges() const;
00373 
00374             //- Return indices of local edges that are globally shared.
00375             //  Demand-driven
00376             //  calculation so call needs to be synchronous among processors!
00377             const labelList& sharedEdgeLabels() const;
00378 
00379             //- Return addressing into the complete globally shared edge
00380             //  list. The set of shared
00381             //  edges on the current processor is a subset of all shared
00382             //  edges. Shared edge addressing gives the index in the
00383             //  list of all globally shared edges for each of the locally
00384             //  shared edges.
00385             //  Demand-driven
00386             //  calculation so call needs to be synchronous among processors!
00387             const labelList& sharedEdgeAddr() const;
00388 
00389 
00390         // Edit
00391 
00392             //- Update for moving points.
00393             void movePoints(const pointField& newPoints);
00394 
00395             //- Change global mesh data given a topological change. Does a
00396             //  full parallel analysis to determine shared points and
00397             //  boundaries.
00398             void updateMesh();
00399 
00400 
00401         // Write
00402 
00403             bool write() const;
00404 
00405 
00406     // Ostream Operator
00407 
00408         friend Ostream& operator<<(Ostream&, const globalMeshData&);
00409 };
00410 
00411 
00412 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00413 
00414 } // End namespace Foam
00415 
00416 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00417 
00418 #endif
00419 
00420 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines