initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / meshes / polyMesh / globalMeshData / globalMeshData.H
blobdfa90fcb6675e35f5376dea6a0beaf7834b154c8
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::globalMeshData
28 Description
29     Various mesh related information for a parallel run. Upon construction
30     constructs all info by using parallel communication. 
32     Requires: 
33     - all processor patches to have correct ordering.
34     - all processorPatches to have their transforms set ('makeTransforms')
36     The shared point addressing is quite interesting. It gives on each processor
37     the vertices that cannot be set using a normal swap on processor patches.
38     These are the vertices that are shared between more than 2 processors.
40     There is an issue with these shared vertices if they originate from
41     cyclics (i.e. are now separated processor patches). They will all be
42     mapped to the same global point (so even though the processor points are
43     not on the same location) since topologically they are one and the same.
45     So if you ask for sharedPoints() you get only one of the coordinates of
46     the topologically shared points.
48     All the hard work of these shared points is done by the globalPoints class.
50     Shared edges: similar to shared points gives on all processors the edges
51     that are shared between more than two patches (i.e. the edges on which
52     data cannot be synchronized by a straightforward edge data swap). Note
53     that shared edges will use shared points but not all edges between shared
54     points need to be shared edges (e.g. there might be an edge connecting
55     two disconnected regions of shared points).
57     Currently an edge is considered shared
58     if it uses two shared points and is used more than once. This is not
59     correct on processor patches but it only slightly overestimates the number
60     of shared edges. Doing full analysis of how many patches use the edge
61     would be too complicated.
63     Shared edge calculation is demand driven so always make sure to have
64     your first call to one of the access functions synchronous amongst all
65     processors!
68 SourceFiles
69     globalMeshData.C
70     globalMeshDataMorph.C
72 \*---------------------------------------------------------------------------*/
74 #ifndef globalMeshData_H
75 #define globalMeshData_H
77 #include "polyMesh.H"
78 #include "Switch.H"
79 #include "processorTopology.H"
80 #include "labelPair.H"
82 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
84 namespace Foam
87 // Forward declaration of friend functions and operators
89 class globalMeshData;
90 Ostream& operator<<(Ostream&, const globalMeshData&);
93 /*---------------------------------------------------------------------------*\
94                            Class globalMeshData Declaration
95 \*---------------------------------------------------------------------------*/
97 class globalMeshData
99     public processorTopology
102     // Private class
104         // To combineReduce a pointField. Just appends all lists.
105         template <class T>
106         class plusEqOp
107         {
109         public:
111             void operator()(T& x, const T& y) const
112             {
113                 label n = x.size();
115                 x.setSize(x.size() + y.size());
117                 forAll(y, i)
118                 {
119                     x[n++] = y[i];
120                 }
121             }
122         };
125         typedef List<labelPair> labelPairList;
128     // Private data
130         //- Reference to mesh
131         const polyMesh& mesh_;
134         // Data related to the complete mesh
136             //- Bounding box of complete mesh
137             boundBox bb_;
139             //- Total number of points in the complete mesh
140             label nTotalPoints_;
142             //- Total number of faces in the complete mesh
143             label nTotalFaces_;
145             //- Total number of cells in the complete mesh
146             label nTotalCells_;
149         // Processor patch addressing (be careful if not running in parallel!)
151             //- List of processor patch labels 
152             //  (size of list = number of processor patches)
153             labelList processorPatches_;
155             //- List of indices into processorPatches_ for each patch.
156             //  Index = -1 for non-processor patches.
157             //  (size of list = number of patches)
158             labelList processorPatchIndices_;
160             //- processorPatchIndices_ of the neighbours processor patches
161             labelList processorPatchNeighbours_;
164         // Globally shared point addressing
166             //- Total number of global points
167             label nGlobalPoints_;
169             //- Indices of local points that are globally shared
170             labelList sharedPointLabels_;
172             //- Indices of globally shared points in the master list
173             //  This list contains all the shared points in the mesh
174             labelList sharedPointAddr_;
176             //- Shared point global labels.
177             //  Global point index for every local shared point.
178             //  Only valid if constructed with this information or if
179             //  pointProcAddressing read.
180             mutable labelList* sharedPointGlobalLabelsPtr_;
183         // Globally shared edge addressing. Derived from shared points.
184         // All demand driven since don't want to construct edges always.
186             //- Total number of global edges
187             mutable label nGlobalEdges_;
189             //- Indices of local edges that are globally shared
190             mutable labelList* sharedEdgeLabelsPtr_;
192             //- Indices of globally shared edge in the master list
193             //  This list contains all the shared edges in the mesh
194             mutable labelList* sharedEdgeAddrPtr_;
197     // Private Member Functions
199         //- Set up processor patch addressing
200         void initProcAddr();
202         //- Helper function for shared edge addressing
203         static void countSharedEdges
204         (
205             const HashTable<labelList, edge, Hash<edge> >& procSharedEdges,
206             HashTable<label, edge, Hash<edge> >&,
207             label&
208         );
210         //- Calculate shared edge addressing
211         void calcSharedEdges() const;
213         //- Count coincident faces.
214         static label countCoincidentFaces
215         (
216             const scalar tolDim,
217             const vectorField& separationDist
218         );
220         //- Disallow default bitwise copy construct
221         globalMeshData(const globalMeshData&);
223         //- Disallow default bitwise assignment
224         void operator=(const globalMeshData&);
227 public:
229     //- Runtime type information
230     ClassName("globalMeshData");
233     // Static data members
235         //- Geomtric tolerance (fraction of bounding box)
236         static const Foam::scalar matchTol_;
239     // Constructors
241         //- Construct from mesh, derive rest (does parallel communication!)
242         globalMeshData(const polyMesh& mesh);
244         //- Old behaviour: read constructor given IOobject and a polyMesh
245         //  reference. Only use this for testing!
246         globalMeshData(const IOobject& io, const polyMesh& mesh);
249     // Destructor
251         ~globalMeshData();
253         //- Remove all demand driven data
254         void clearOut();
257     // Member Functions
259         // Access
261             //- Return the mesh reference
262             const polyMesh& mesh() const
263             {
264                 return mesh_;
265             }
267             //- Does the mesh contain processor patches? (also valid when
268             //  not running parallel)
269             bool parallel() const
270             {
271                 return processorPatches_.size() > 0;
272             }
274             const boundBox& bb() const
275             {
276                 return bb_;
277             }
279             //- Return total number of points in decomposed mesh
280             label nTotalPoints() const
281             {
282                 return nTotalPoints_;
283             }
285             //- Return total number of faces in decomposed mesh
286             label nTotalFaces() const
287             {
288                 return nTotalFaces_;
289             }
291             //- Return total number of cells in decomposed mesh
292             label nTotalCells() const
293             {
294                 return nTotalCells_;
295             }
298         // Processor patch addressing (be careful when not running in parallel)
300             //- Return list of processor patch labels 
301             //  (size of list = number of processor patches)
302             const labelList& processorPatches() const
303             {
304                 return processorPatches_;
305             }
307             //- Return list of indices into processorPatches_ for each patch.
308             //  Index = -1 for non-processor parches.
309             //  (size of list = number of patches)
310             const labelList& processorPatchIndices() const
311             {
312                 return processorPatchIndices_;
313             }
315             //- Return processorPatchIndices of the neighbours
316             //  processor patches. -1 if not running parallel.
317             const labelList& processorPatchNeighbours() const
318             {
319                 return processorPatchNeighbours_;
320             }
323         // Globally shared point addressing
325             //- Return number of globally shared points
326             label nGlobalPoints() const
327             {
328                 return nGlobalPoints_;
329             }
331             //- Return indices of local points that are globally shared
332             const labelList& sharedPointLabels() const
333             {
334                 return sharedPointLabels_;
335             }
337             //- Return addressing into the complete globally shared points
338             //  list
339             //  Note: It is assumed that a (never constructed) complete
340             //  list of globally shared points exists.  The set of shared
341             //  points on the current processor is a subset of all shared
342             //  points. Shared point addressing gives the index in the
343             //  list of all globally shared points for each of the locally
344             //  shared points.
345             const labelList& sharedPointAddr() const
346             {
347                 return sharedPointAddr_;
348             }
350             //- Return shared point global labels. Tries to read
351             //  'pointProcAddressing' and returns list or -1 if none
352             //  available.
353             const labelList& sharedPointGlobalLabels() const;
355             //- Collect coordinates of shared points on all processors.
356             //  (does parallel communication!)
357             //  Note: not valid for cyclicParallel since shared cyclic points
358             //  are merged into single global point. (use geometricSharedPoints
359             //  instead)
360             pointField sharedPoints() const;
362             //- Like sharedPoints but keeps cyclic points separate.
363             //  (does geometric merging; uses matchTol_*bb as merging tolerance)
364             //  Use sharedPoints() instead.
365             pointField geometricSharedPoints() const;
369         // Globally shared edge addressing
371             //- Return number of globally shared edges. Demand-driven
372             //  calculation so call needs to be synchronous among processors!
373             label nGlobalEdges() const;
375             //- Return indices of local edges that are globally shared.
376             //  Demand-driven
377             //  calculation so call needs to be synchronous among processors!
378             const labelList& sharedEdgeLabels() const;
380             //- Return addressing into the complete globally shared edge
381             //  list. The set of shared
382             //  edges on the current processor is a subset of all shared
383             //  edges. Shared edge addressing gives the index in the
384             //  list of all globally shared edges for each of the locally
385             //  shared edges.
386             //  Demand-driven
387             //  calculation so call needs to be synchronous among processors!
388             const labelList& sharedEdgeAddr() const;
391         // Edit
393             //- Update for moving points.
394             void movePoints(const pointField& newPoints);
396             //- Change global mesh data given a topological change. Does a
397             //  full parallel analysis to determine shared points and
398             //  boundaries.
399             void updateMesh();
402         // Write
404             bool write() const;
407     // Ostream Operator
409         friend Ostream& operator<<(Ostream&, const globalMeshData&);
413 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
415 } // End namespace Foam
417 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
419 #endif
421 // ************************************************************************* //