1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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
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/>.
24 \*---------------------------------------------------------------------------*/
28 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 inline Foam::label Foam::globalIndex::offset(const label procI) const
32 return offsets_[procI];
36 inline Foam::label Foam::globalIndex::localSize(const label procI) const
38 return offsets_[procI+1] - offsets_[procI];
42 inline Foam::label Foam::globalIndex::localSize() const
44 return localSize(Pstream::myProcNo());
48 inline Foam::label Foam::globalIndex::size() const
50 return offsets_[Pstream::nProcs()];
54 inline Foam::label Foam::globalIndex::toGlobal
60 return i + offsets_[procI];
64 inline Foam::label Foam::globalIndex::toGlobal(const label i) const
66 return toGlobal(Pstream::myProcNo(), i);
70 //- Is on local processor
71 inline bool Foam::globalIndex::isLocal(const label procI, const label i) const
73 return i >= offsets_[procI] && i < offsets_[procI+1];
77 inline bool Foam::globalIndex::isLocal(const label i) const
79 return isLocal(Pstream::myProcNo(), i);
83 inline Foam::label Foam::globalIndex::toLocal(const label procI, const label i)
86 label localI = i - offsets_[procI];
88 if (localI < 0 || i >= offsets_[procI+1])
90 FatalErrorIn("globalIndex::toLocal(const label, const label)")
91 << "Global " << i << " does not belong on processor "
92 << procI << endl << "Offsets:" << offsets_
99 inline Foam::label Foam::globalIndex::toLocal(const label i) const
101 return toLocal(Pstream::myProcNo(), i);
105 inline Foam::label Foam::globalIndex::whichProcID(const label i) const
107 if (i < 0 || i >= offsets_[Pstream::nProcs()])
109 FatalErrorIn("globalIndex::whichProcID(const label)")
110 << "Global " << i << " does not belong on any processor."
111 << " Offsets:" << offsets_
112 << abort(FatalError);
115 return findLower(offsets_, i+1);
119 // ************************************************************************* //