1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 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
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 \*---------------------------------------------------------------------------*/
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 //inline const Foam::labelList& Foam::globalIndex::offsets() const
37 inline Foam::label Foam::globalIndex::offset(const label procI) const
39 return (procI == 0 ? 0 : offsets_[procI-1]);
43 inline Foam::label Foam::globalIndex::localSize(const label procI) const
49 : offsets_[procI] - offsets_[procI-1]
54 inline Foam::label Foam::globalIndex::localSize() const
56 return localSize(Pstream::myProcNo());
60 inline Foam::label Foam::globalIndex::size() const
62 return offsets_[Pstream::nProcs()-1];
66 inline Foam::label Foam::globalIndex::toGlobal
72 return(procI == 0 ? i : i + offsets_[procI-1]);
76 inline Foam::label Foam::globalIndex::toGlobal(const label i) const
78 return toGlobal(Pstream::myProcNo(), i);
82 //- Is on local processor
83 inline bool Foam::globalIndex::isLocal(const label procI, const label i) const
87 && (i >= (procI == 0 ? 0 : offsets_[procI-1]));
91 inline bool Foam::globalIndex::isLocal(const label i) const
93 return isLocal(Pstream::myProcNo(), i);
97 inline Foam::label Foam::globalIndex::toLocal(const label procI, const label i)
100 label localI = (procI == 0 ? i : i - offsets_[procI-1]);
102 if (localI < 0 || i >= offsets_[procI])
104 FatalErrorIn("globalIndex::toLocal(const label, const label)")
105 << "Global " << i << " does not belong on processor "
106 << procI << endl << "Offsets:" << offsets_
107 << abort(FatalError);
113 inline Foam::label Foam::globalIndex::toLocal(const label i) const
115 return toLocal(Pstream::myProcNo(), i);
119 inline Foam::label Foam::globalIndex::whichProcID(const label i) const
121 label index = findLower(offsets_, i+1);
123 if (index == Pstream::nProcs()-1)
125 FatalErrorIn("globalIndex::whichProcID(const label)")
126 << "Global " << i << " does not belong on any processor."
127 << " Offsets:" << offsets_
128 << abort(FatalError);
135 // ************************************************************************* //