globalIndexI.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-2019 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 \*---------------------------------------------------------------------------*/
25 
26 #include "ListOps.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
31 {}
32 
33 
35 :
36  offsets_(move(offsets))
37 {}
38 
39 
40 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41 
43 {
44  return offsets_;
45 }
46 
47 
48 inline Foam::label Foam::globalIndex::offset(const label proci) const
49 {
50  return offsets_[proci];
51 }
52 
53 
55 {
56  return offsets_[proci+1] - offsets_[proci];
57 }
58 
59 
61 {
62  return localSize(Pstream::myProcNo());
63 }
64 
65 
67 {
68  return offsets_.last();
69 }
70 
71 
73 (
74  const label proci,
75  const label i
76 ) const
77 {
78  return i + offsets_[proci];
79 }
80 
81 
83 {
84  return toGlobal(Pstream::myProcNo(), i);
85 }
86 
87 
88 //- Is on local processor
89 inline bool Foam::globalIndex::isLocal(const label proci, const label i) const
90 {
91  return i >= offsets_[proci] && i < offsets_[proci+1];
92 }
93 
94 
95 inline bool Foam::globalIndex::isLocal(const label i) const
96 {
97  return isLocal(Pstream::myProcNo(), i);
98 }
99 
100 
101 inline Foam::label Foam::globalIndex::toLocal(const label proci, const label i)
102 const
103 {
104  label localI = i - offsets_[proci];
105 
106  if (localI < 0 || i >= offsets_[proci+1])
107  {
109  << "Global " << i << " does not belong on processor "
110  << proci << endl << "Offsets:" << offsets_
111  << abort(FatalError);
112  }
113  return localI;
114 }
115 
116 
118 {
119  return toLocal(Pstream::myProcNo(), i);
120 }
121 
122 
124 {
125  if (i < 0 || i >= size())
126  {
128  << "Global " << i << " does not belong on any processor."
129  << " Offsets:" << offsets_
130  << abort(FatalError);
131  }
132 
133  return findLower(offsets_, i+1);
134 }
135 
136 
137 // ************************************************************************* //
bool isLocal(const label i) const
Is on local processor.
Definition: globalIndexI.H:95
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:429
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Various functions to operate on Lists.
label offset(const label proci) const
Start of proci data.
Definition: globalIndexI.H:48
globalIndex()
Construct null.
Definition: globalIndexI.H:30
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
errorManip< error > abort(error &err)
Definition: errorManip.H:131
label toGlobal(const label i) const
From local to global.
Definition: globalIndexI.H:82
label findLower(const ListType &, typename ListType::const_reference, const label stary, const BinaryOp &bop)
Find last element < given value in sorted list and return index,.
T & last()
Return the last element of the list.
Definition: UListI.H:128
label localSize() const
My local size.
Definition: globalIndexI.H:60