FreeFOAM The Cross-Platform CFD Toolkit
globalIndex.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::globalIndex
26 
27 Description
28  Calculates a unique integer (label so might not have enough room - 2G max)
29  for processor + local index. E.g.
30 
31  globalIndex globalFaces(mesh.nFaces());
32  label globalFaceI = globalFaces.toGlobal(faceI);
33 
34 
35 SourceFiles
36  globalIndex.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef globalIndex_H
41 #define globalIndex_H
42 
43 #include <OpenFOAM/Pstream.H>
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward declaration of friend functions and operators
51 
52 class globalIndex;
53 
54 Istream& operator>>(Istream& is, globalIndex& gi);
55 Ostream& operator<<(Ostream& os, const globalIndex& gi);
56 
57 
58 /*---------------------------------------------------------------------------*\
59  Class globalIndex Declaration
60 \*---------------------------------------------------------------------------*/
61 
63 {
64  // Private data
65 
66  //- Start off procI+1. (so like CompactListList)
67  labelList offsets_;
68 
69 
70 public:
71 
72  // Constructors
73 
74  //- Construct from local max size
75  globalIndex(const label localSize);
76 
77  //- Construct from Istream
78  globalIndex(Istream& is);
79 
80 
81  // Member Functions
82 
84  //inline const labelList& offsets() const;
85 
86 
87  // Queries relating to my processor
88 
89  //- my local size
90  inline label localSize() const;
91 
92  //- From local to global
93  inline label toGlobal(const label i) const;
94 
95  //- Is on local processor
96  inline bool isLocal(const label i) const;
97 
98  //- From global to local on current processor.
99  // FatalError if not on local processor.
100  inline label toLocal(const label i) const;
101 
102 
103  // Global queries
104 
105  //- Global sum of localSizes
106  inline label size() const;
107 
108  //- Size of procI data
109  inline label localSize(const label procI) const;
110 
111  //- From local to global on procI
112  inline label toGlobal(const label procI, const label i) const;
113 
114  //- Is on processor procI
115  inline bool isLocal(const label procI, const label i) const;
116 
117  //- From global to local on procI
118  inline label toLocal(const label procI, const label i) const;
119 
120  //- Which processor does global come from? Binary search.
121  inline label whichProcID(const label i) const;
122 
123  //- Start of procI data
124  inline label offset(const label procI) const;
125 
126 
127 
128  // IOstream Operators
129 
130  friend Istream& operator>>(Istream& is, globalIndex& gi);
131  friend Ostream& operator<<(Ostream& os, const globalIndex& gi);
132 };
133 
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 } // End namespace Foam
138 
139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
140 
141 #include <OpenFOAM/globalIndexI.H>
142 
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144 
145 #endif
146 
147 // ************************ vim: set sw=4 sts=4 et: ************************ //