initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / polyMesh / globalMeshData / globalIndexI.H
blobd7c44107c665e29d0fd38900b2767e116b5e1b57
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 \*---------------------------------------------------------------------------*/
27 #include "ListOps.H"
29 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
31 //inline const Foam::labelList& Foam::globalIndex::offsets() const
32 //{
33 //    return offsets_;
34 //}
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
45     return
46     (
47         procI == 0
48       ? offsets_[procI]
49       : offsets_[procI] - offsets_[procI-1]
50     );
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
68     const label procI,
69     const label i
70 ) const
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
85     return
86         (i < offsets_[procI])
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)
98 const
100     label localI = (procI == 0 ? i : i - offsets_[procI-1]);
102     if (localI < 0 || i >= offsets_[procI])
103     {
104         FatalErrorIn("globalIndex::toLocal(const label, const label)")
105             << "Global " << i << " does not belong on processor "
106             << procI << endl << "Offsets:" << offsets_
107             << abort(FatalError);
108     }
109     return localI;
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)
124     {
125         FatalErrorIn("globalIndex::whichProcID(const label)")
126             << "Global " << i << " does not belong on any processor."
127             << " Offsets:" << offsets_
128             << abort(FatalError);
129     }
131     return index+1;
135 // ************************************************************************* //