initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / polyMesh / globalMeshData / globalPoints.H
blobd39903e406bba536713732855c57812c9558fe77
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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::globalPoints
28 Description
29     Calculates points shared by more than two processor patches or cyclic
30     patches.
32     Is used in globalMeshData. (this info is needed for point-edge
33     communication where you do all but these shared points with patch to
34     patch communication but need to do a reduce on these shared points)
36     Works purely topological and using local communication only. 
37     Needs:
38       - domain to be one single domain (i.e. all faces can be reached through
39         face-cell walk).
40       - patch face ordering to be ok
41       - f[0] ordering on patch faces to be ok.
43     Works by constructing equivalence lists for all the points on processor
44     patches. These list are procPointList and give processor and meshPoint
45     label on that processor.
46     E.g.
47     @verbatim
48           ((7 93)(4 731)(3 114))
49     @endverbatim
51     means point 93 on proc7 is connected to point 731 on proc4 and 114 on proc3.
52     It then gets the lowest numbered processor (the 'master') to request a
53     sharedPoint label from processor0 and it redistributes this label back to
54     the other processors in the equivalence list.
56     Algorithm:
57         - get meshPoints of all my points on processor patches and initialize
58           equivalence lists to this.
59      loop
60         - send to all neighbours in relative form:
61             - patchFace
62             - index in face
63         - receive and convert into meshPoints. Add to to my equivalence lists.
64         - mark meshPoints for which information changed.
65         - send data for these meshPoints again
66      endloop until nothing changes
68     At this point one will have complete point-point connectivity for all
69     points on processor patches. Now
71         - remove point equivalences of size 2. These are just normal points
72           shared between two neighbouring procPatches.
73         - collect on each processor points for which it is the master
74         - request number of sharedPointLabels from the Pstream::master.
76     This information gets redistributed to all processors in a similar way
77     as that in which the equivalence lists were collected:
79         - initialize the indices of shared points I am the master for
80      loop
81         - send my known sharedPoints + meshPoints to all neighbours
82         - receive from all neighbour. Find which meshPoint on my processor
83           the sharedpoint is connected to
84         - mark indices for which information has changed
85      endloop until nothing changes.
88 SourceFiles
89     globalPoints.C
91 \*---------------------------------------------------------------------------*/
93 #ifndef globalPoints_H
94 #define globalPoints_H
96 #include "DynamicList.H"
97 #include "Map.H"
98 #include "labelList.H"
99 #include "FixedList.H"
100 #include "primitivePatch.H"
101 #include "className.H"
102 #include "edgeList.H"
104 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
106 namespace Foam
109 // Forward declaration of classes
110 class polyMesh;
111 class polyBoundaryMesh;
112 class cyclicPolyPatch;
114 /*---------------------------------------------------------------------------*\
115                            Class globalPoints Declaration
116 \*---------------------------------------------------------------------------*/
118 class globalPoints
120     // Private classes
122         //- Define procPointList as holding a list of meshPoint/processor labels
123         typedef FixedList<label, 2> procPoint;
124         typedef List<procPoint> procPointList;
126     // Private data
128         //- Mesh reference
129         const polyMesh& mesh_;
131         //- Sum of points on processor patches (unfiltered, point on 2 patches
132         //  counts as 2)
133         const label nPatchPoints_;
135         //- All points on boundaries and their corresponding connected points
136         //  on other processors.
137         DynamicList<procPointList> procPoints_;
139         //- Map from mesh point to index in procPoints
140         Map<label> meshToProcPoint_;
142         //- Shared points used by this processor (= global point number)
143         labelList sharedPointAddr_;
145         //- My meshpoints corresponding to the shared points
146         labelList sharedPointLabels_;
148         //- Total number of shared points.
149         label nGlobalPoints_;
152     // Private Member Functions
154         //- Count all points on processorPatches. Is all points for which
155         //  information is collected.
156         static label countPatchPoints(const polyBoundaryMesh&);
158         //- Add information about patchPointI in relative indices to send
159         //  buffers (patchFaces, indexInFace etc.)
160         static void addToSend
161         (
162             const primitivePatch&,
163             const label patchPointI,
164             const procPointList&,
165             DynamicList<label>& patchFaces,
166             DynamicList<label>& indexInFace,
167             DynamicList<procPointList>& allInfo
168         );
170         //- Merge info from neighbour into my data
171         static bool mergeInfo
172         (
173             const procPointList& nbrInfo,
174             procPointList& myInfo
175         );
177         //- Store (and merge) info for meshPointI
178         bool storeInfo(const procPointList& nbrInfo, const label meshPointI);
180         //- Initialize procPoints_ to my patch points. allPoints = true:
181         //  seed with all patch points, = false: only boundaryPoints().
182         void initOwnPoints(const bool allPoints, labelHashSet& changedPoints);
184         //- Send subset of procPoints to neighbours
185         void sendPatchPoints(const labelHashSet& changedPoints) const;
187         //- Receive neighbour points and merge into my procPoints.
188         void receivePatchPoints(labelHashSet& changedPoints);
190         //- Remove entries of size 2 where meshPoint is in provided Map.
191         //  Used to remove normal face-face connected points.
192         void remove(const Map<label>&);
194         //- Get indices of point for which I am master (lowest numbered proc)
195         labelList getMasterPoints() const;
197         //- Send subset of shared points to neighbours
198         void sendSharedPoints(const labelList& changedIndices) const;
200         //- Receive shared points and update subset.
201         void receiveSharedPoints(labelList& changedIndices);
204         //- Should move into cyclicPolyPatch but some ordering problem
205         //  keeps on giving problems.
206         static edgeList coupledPoints(const cyclicPolyPatch&);
208         //- Disallow default bitwise copy construct
209         globalPoints(const globalPoints&);
211         //- Disallow default bitwise assignment
212         void operator=(const globalPoints&);
215 public:
217         //- Declare name of the class and its debug switch
218         ClassName("globalPoints");
221     // Constructors
223         //- Construct from mesh
224         globalPoints(const polyMesh& mesh);
227     // Member Functions
229         // Access
231             label nPatchPoints() const
232             {
233                 return nPatchPoints_;
234             }
236             const Map<label>& meshToProcPoint() const
237             {
238                 return meshToProcPoint_;
239             }
241             //- shared points used by this processor (= global point number)
242             const labelList& sharedPointAddr() const
243             {
244                 return sharedPointAddr_;
245             }
247             //- my meshpoints corresponding to the shared points
248             const labelList& sharedPointLabels() const
249             {
250                 return sharedPointLabels_;
251             }
253             label nGlobalPoints() const
254             {
255                 return nGlobalPoints_;
256             }
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 } // End namespace Foam
265 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 #endif
269 // ************************************************************************* //