OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen 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-2007 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     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 /*---------------------------------------------------------------------------*\
00088                            Class globalMeshData Declaration
00089 \*---------------------------------------------------------------------------*/
00090 
00091 class globalMeshData
00092 :
00093     public processorTopology
00094 {
00095 
00096     // Private class
00097 
00098         // To combineReduce a pointField. Just appends all lists.
00099         template <class T>
00100         class plusEqOp
00101         {
00102 
00103         public:
00104 
00105             void operator()(T& x, const T& y) const
00106             {
00107                 label n = x.size();
00108 
00109                 x.setSize(x.size() + y.size());
00110 
00111                 forAll(y, i)
00112                 {
00113                     x[n++] = y[i];
00114                 }
00115             }
00116         };
00117 
00118 
00119         typedef List<labelPair> labelPairList;
00120 
00121 
00122     // Private data
00123 
00124         //- Reference to mesh
00125         const polyMesh& mesh_;
00126 
00127 
00128         // Data related to the complete mesh
00129 
00130             //- Bounding box of complete mesh
00131             boundBox bb_;
00132 
00133             //- Total number of points in the complete mesh
00134             label nTotalPoints_;
00135 
00136             //- Total number of faces in the complete mesh
00137             label nTotalFaces_;
00138 
00139             //- Total number of cells in the complete mesh
00140             label nTotalCells_;
00141 
00142 
00143         // Processor patch addressing (be careful if not running in parallel!)
00144 
00145             //- List of processor patch labels 
00146             //  (size of list = number of processor patches)
00147             labelList processorPatches_;
00148 
00149             //- List of indices into processorPatches_ for each patch.
00150             //  Index = -1 for non-processor patches.
00151             //  (size of list = number of patches)
00152             labelList processorPatchIndices_;
00153 
00154             //- processorPatchIndices_ of the neighbours processor patches
00155             labelList processorPatchNeighbours_;
00156 
00157 
00158         // Globally shared point addressing
00159 
00160             //- Total number of global points
00161             label nGlobalPoints_;
00162 
00163             //- Indices of local points that are globally shared
00164             labelList sharedPointLabels_;
00165 
00166             //- Indices of globally shared points in the master list
00167             //  This list contains all the shared points in the mesh
00168             labelList sharedPointAddr_;
00169 
00170             //- Shared point global labels.
00171             //  Global point index for every local shared point.
00172             //  Only valid if constructed with this information or if
00173             //  pointProcAddressing read.
00174             mutable labelList* sharedPointGlobalLabelsPtr_;
00175 
00176 
00177         // Globally shared edge addressing. Derived from shared points.
00178         // All demand driven since don't want to construct edges always.
00179 
00180             //- Total number of global edges
00181             mutable label nGlobalEdges_;
00182 
00183             //- Indices of local edges that are globally shared
00184             mutable labelList* sharedEdgeLabelsPtr_;
00185 
00186             //- Indices of globally shared edge in the master list
00187             //  This list contains all the shared edges in the mesh
00188             mutable labelList* sharedEdgeAddrPtr_;
00189 
00190 
00191     // Private Member Functions
00192 
00193         //- Set up processor patch addressing
00194         void initProcAddr();
00195 
00196         //- Helper function for shared edge addressing
00197         static void countSharedEdges
00198         (
00199             const HashTable<labelList, edge, Hash<edge> >& procSharedEdges,
00200             HashTable<label, edge, Hash<edge> >&,
00201             label&
00202         );
00203 
00204         //- Calculate shared edge addressing
00205         void calcSharedEdges() const;
00206 
00207         //- Count coincident faces.
00208         static label countCoincidentFaces
00209         (
00210             const scalar tolDim,
00211             const vectorField& separationDist
00212         );
00213 
00214         //- Disallow default bitwise copy construct
00215         globalMeshData(const globalMeshData&);
00216 
00217         //- Disallow default bitwise assignment
00218         void operator=(const globalMeshData&);
00219 
00220 
00221 public:
00222 
00223     //- Runtime type information
00224     ClassName("globalMeshData");
00225 
00226 
00227     // Static data members
00228 
00229         //- Geomtric tolerance (fraction of bounding box)
00230         static const Foam::scalar matchTol_;
00231 
00232 
00233     // Constructors
00234 
00235         //- Construct from mesh, derive rest (does parallel communication!)
00236         globalMeshData(const polyMesh& mesh);
00237 
00238         //- Old behaviour: read constructor given IOobject and a polyMesh
00239         //  reference. Only use this for testing!
00240         globalMeshData(const IOobject& io, const polyMesh& mesh);
00241 
00242 
00243     // Destructor
00244 
00245         ~globalMeshData();
00246 
00247         //- Remove all demand driven data
00248         void clearOut();
00249 
00250 
00251     // Member Functions
00252 
00253         // Access
00254 
00255             //- Return the mesh reference
00256             const polyMesh& mesh() const
00257             {
00258                 return mesh_;
00259             }
00260 
00261             //- Does the mesh contain processor patches? (also valid when
00262             //  not running parallel)
00263             bool parallel() const
00264             {
00265                 return processorPatches_.size() > 0;
00266             }
00267 
00268             const boundBox& bb() const
00269             {
00270                 return bb_;
00271             }
00272 
00273             //- Return total number of points in decomposed mesh
00274             label nTotalPoints() const
00275             {
00276                 return nTotalPoints_;
00277             }
00278 
00279             //- Return total number of faces in decomposed mesh
00280             label nTotalFaces() const
00281             {
00282                 return nTotalFaces_;
00283             }
00284 
00285             //- Return total number of cells in decomposed mesh
00286             label nTotalCells() const
00287             {
00288                 return nTotalCells_;
00289             }
00290 
00291 
00292         // Processor patch addressing (be careful when not running in parallel)
00293 
00294             //- Return list of processor patch labels 
00295             //  (size of list = number of processor patches)
00296             const labelList& processorPatches() const
00297             {
00298                 return processorPatches_;
00299             }
00300 
00301             //- Return list of indices into processorPatches_ for each patch.
00302             //  Index = -1 for non-processor parches.
00303             //  (size of list = number of patches)
00304             const labelList& processorPatchIndices() const
00305             {
00306                 return processorPatchIndices_;
00307             }
00308 
00309             //- Return processorPatchIndices of the neighbours
00310             //  processor patches. -1 if not running parallel.
00311             const labelList& processorPatchNeighbours() const
00312             {
00313                 return processorPatchNeighbours_;
00314             }
00315 
00316 
00317         // Globally shared point addressing
00318 
00319             //- Return number of globally shared points
00320             label nGlobalPoints() const
00321             {
00322                 return nGlobalPoints_;
00323             }
00324 
00325             //- Return indices of local points that are globally shared
00326             const labelList& sharedPointLabels() const
00327             {
00328                 return sharedPointLabels_;
00329             }
00330 
00331             //- Return addressing into the complete globally shared points
00332             //  list
00333             //  Note: It is assumed that a (never constructed) complete
00334             //  list of globally shared points exists.  The set of shared
00335             //  points on the current processor is a subset of all shared
00336             //  points. Shared point addressing gives the index in the
00337             //  list of all globally shared points for each of the locally
00338             //  shared points.
00339             const labelList& sharedPointAddr() const
00340             {
00341                 return sharedPointAddr_;
00342             }
00343 
00344             //- Return shared point global labels. Tries to read
00345             //  'pointProcAddressing' and returns list or -1 if none
00346             //  available.
00347             const labelList& sharedPointGlobalLabels() const;
00348 
00349             //- Collect coordinates of shared points on all processors.
00350             //  (does parallel communication!)
00351             //  Note: not valid for cyclicParallel since shared cyclic points
00352             //  are merged into single global point. (use geometricSharedPoints
00353             //  instead)
00354             pointField sharedPoints() const;
00355 
00356             //- Like sharedPoints but keeps cyclic points separate.
00357             //  (does geometric merging; uses matchTol_*bb as merging tolerance)
00358             //  Use sharedPoints() instead.
00359             pointField geometricSharedPoints() const;
00360 
00361 
00362 
00363         // Globally shared edge addressing
00364 
00365             //- Return number of globally shared edges. Demand-driven
00366             //  calculation so call needs to be synchronous among processors!
00367             label nGlobalEdges() const;
00368 
00369             //- Return indices of local edges that are globally shared.
00370             //  Demand-driven
00371             //  calculation so call needs to be synchronous among processors!
00372             const labelList& sharedEdgeLabels() const;
00373 
00374             //- Return addressing into the complete globally shared edge
00375             //  list. The set of shared
00376             //  edges on the current processor is a subset of all shared
00377             //  edges. Shared edge addressing gives the index in the
00378             //  list of all globally shared edges for each of the locally
00379             //  shared edges.
00380             //  Demand-driven
00381             //  calculation so call needs to be synchronous among processors!
00382             const labelList& sharedEdgeAddr() const;
00383 
00384 
00385         // Edit
00386 
00387             //- Update for moving points.
00388             void movePoints(const pointField& newPoints);
00389 
00390             //- Change global mesh data given a topological change. Does a
00391             //  full parallel analysis to determine shared points and
00392             //  boundaries.
00393             void updateMesh();
00394 
00395 
00396         // Write
00397 
00398             bool write() const;
00399 
00400 
00401     // Ostream Operator
00402 
00403         friend Ostream& operator<<(Ostream&, const globalMeshData&);
00404 };
00405 
00406 
00407 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00408 
00409 } // End namespace Foam
00410 
00411 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00412 
00413 #endif
00414 
00415 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd