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

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