globalIndex.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
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  globalIndexI.H
37  globalIndex.C
38  globalIndexTemplates.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef globalIndex_H
43 #define globalIndex_H
44 
45 #include "Pstream.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward declaration of friend functions and operators
53 
54 class globalIndex;
55 
56 Istream& operator>>(Istream& is, globalIndex& gi);
57 Ostream& operator<<(Ostream& os, const globalIndex& gi);
58 
59 
60 /*---------------------------------------------------------------------------*\
61  Class globalIndex Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 class globalIndex
65 {
66  // Private Data
67 
68  //- Start of proci. Size is nProcs()+1. (so like CompactListList)
69  labelList offsets_;
70 
71 
72 public:
73 
74  // Constructors
75 
76  //- Construct null
77  inline globalIndex();
78 
79  //- Construct from local max size. Does communication with default
80  // communicator and message tag.
81  globalIndex(const label localSize);
82 
83  //- Construct from local max size. Does communication with given
84  // communicator and message tag
86  (
87  const label localSize,
88  const int tag,
89  const label comm,
90  const bool parallel // use parallel comms
91  );
92 
93  //- Construct from components
94  globalIndex(const labelList& offsets);
95 
96  //- Move constructor from components
97  inline globalIndex(labelList&& offsets);
98 
99  //- Construct from Istream
100  globalIndex(Istream& is);
101 
102 
103  // Member Functions
104 
105  // Edit
106 
107  //- Change after construction
108  inline labelList& offsets();
109 
110 
111  // Queries relating to my processor (using world communicator)
112 
113  //- My local size
114  inline label localSize() const;
115 
116  //- From local to global
117  inline label toGlobal(const label i) const;
118 
119  //- Is on local processor
120  inline bool isLocal(const label i) const;
121 
122  //- From global to local on current processor.
123  // FatalError if not on local processor.
124  inline label toLocal(const label i) const;
125 
126 
127  // Global queries
128 
129  //- Global sum of localSizes
130  inline label size() const;
131 
132  //- Size of proci data
133  inline label localSize(const label proci) const;
134 
135  //- From local to global on proci
136  inline label toGlobal(const label proci, const label i) const;
137 
138  //- Is on processor proci
139  inline bool isLocal(const label proci, const label i) const;
140 
141  //- From global to local on proci
142  inline label toLocal(const label proci, const label i) const;
143 
144  //- Which processor does global come from? Binary search.
145  inline label whichProcID(const label i) const;
146 
147  //- Start of proci data
148  inline label offset(const label proci) const;
149 
150 
151  // Other
152 
153  //- Collect data in processor order on master (== procIDs[0]).
154  // Needs offsets only on master.
155  template<class Type>
156  static void gather
157  (
158  const labelUList& offsets,
159  const label comm,
160  const labelList& procIDs,
161  const UList<Type>& fld,
162  List<Type>& allFld,
163  const int tag = UPstream::msgType(),
164  const Pstream::commsTypes commsType =
166  );
167 
168  //- Collect data in processor order on master (== procIDs[0]).
169  // Needs offsets only on master.
170  template<class Type>
171  void gather
172  (
173  const label comm,
174  const labelList& procIDs,
175  const UList<Type>& fld,
176  List<Type>& allFld,
177  const int tag = UPstream::msgType(),
178  const Pstream::commsTypes commsType =
180  ) const
181  {
182  gather(offsets_, comm, procIDs, fld, allFld, tag, commsType);
183  }
184 
185  //- Inplace collect data in processor order on master
186  // (== procIDs[0]). Needs offsets only on master.
187  template<class Type>
188  static void gather
189  (
190  const labelUList& offsets,
191  const label comm,
192  const labelList& procIDs,
193  List<Type>& fld,
194  const int tag = UPstream::msgType(),
195  const Pstream::commsTypes commsType =
197  );
198 
199  //- Inplace collect data in processor order on master
200  // (== procIDs[0]). Needs offsets only on master.
201  template<class Type>
202  void gather
203  (
204  const label comm,
205  const labelList& procIDs,
206  List<Type>& fld,
207  const int tag = UPstream::msgType(),
208  const Pstream::commsTypes commsType =
210  ) const
211  {
212  gather(offsets_, comm, procIDs, fld, tag, commsType);
213  }
214 
215  //- Distribute data in processor order. Requires fld to be sized!
216  template<class Type>
217  static void scatter
218  (
219  const labelUList& offsets,
220  const label comm,
221  const labelList& procIDs,
222  const UList<Type>& allFld,
223  UList<Type>& fld,
224  const int tag = UPstream::msgType(),
225  const Pstream::commsTypes commsType =
227  );
228 
229  //- Distribute data in processor order. Requires fld to be sized!
230  template<class Type>
231  void scatter
232  (
233  const label comm,
234  const labelList& procIDs,
235  const UList<Type>& allFld,
236  UList<Type>& fld,
237  const int tag = UPstream::msgType(),
238  const Pstream::commsTypes commsType =
240  ) const
241  {
242  scatter(offsets_, comm, procIDs, allFld, fld, tag, commsType);
243  }
244 
245 
246  // IOstream Operators
247 
248  friend Istream& operator>>(Istream& is, globalIndex& gi);
249  friend Ostream& operator<<(Ostream& os, const globalIndex& gi);
250 };
251 
252 
253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 
255 } // End namespace Foam
256 
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 
259 #ifdef NoRepository
260  #include "globalIndexTemplates.C"
261 #endif
262 
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
264 
265 #include "globalIndexI.H"
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
269 #endif
270 
271 // ************************************************************************* //
bool isLocal(const label i) const
Is on local processor.
Definition: globalIndexI.H:95
static void gather(const labelUList &offsets, const label comm, const labelList &procIDs, const UList< Type > &fld, List< Type > &allFld, const int tag=UPstream::msgType(), const Pstream::commsTypes commsType=Pstream::commsTypes::nonBlocking)
Collect data in processor order on master (== procIDs[0]).
commsTypes
Types of communications.
Definition: UPstream.H:64
static void scatter(const labelUList &offsets, const label comm, const labelList &procIDs, const UList< Type > &allFld, UList< Type > &fld, const int tag=UPstream::msgType(), const Pstream::commsTypes commsType=Pstream::commsTypes::nonBlocking)
Distribute data in processor order. Requires fld to be sized!
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
friend Ostream & operator<<(Ostream &os, const globalIndex &gi)
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:476
friend Istream & operator>>(Istream &is, globalIndex &gi)
label offset(const label proci) const
Start of proci data.
Definition: globalIndexI.H:48
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
globalIndex()
Construct null.
Definition: globalIndexI.H:30
Istream & operator>>(Istream &, directionInfo &)
label size() const
Global sum of localSizes.
Definition: globalIndexI.H:66
label toLocal(const label i) const
From global to local on current processor.
Definition: globalIndexI.H:117
labelList & offsets()
Change after construction.
Definition: globalIndexI.H:42
label whichProcID(const label i) const
Which processor does global come from? Binary search.
Definition: globalIndexI.H:123
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
label toGlobal(const label i) const
From local to global.
Definition: globalIndexI.H:82
Ostream & operator<<(Ostream &, const ensightPart &)
Namespace for OpenFOAM.
label localSize() const
My local size.
Definition: globalIndexI.H:60