FreeFOAM The Cross-Platform CFD Toolkit
globalIndexI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/ListOps.H>
27 
28 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
30 //inline const Foam::labelList& Foam::globalIndex::offsets() const
31 //{
32 // return offsets_;
33 //}
34 
35 
36 inline Foam::label Foam::globalIndex::offset(const label procI) const
37 {
38  return (procI == 0 ? 0 : offsets_[procI-1]);
39 }
40 
41 
42 inline Foam::label Foam::globalIndex::localSize(const label procI) const
43 {
44  return
45  (
46  procI == 0
47  ? offsets_[procI]
48  : offsets_[procI] - offsets_[procI-1]
49  );
50 }
51 
52 
53 inline Foam::label Foam::globalIndex::localSize() const
54 {
55  return localSize(Pstream::myProcNo());
56 }
57 
58 
59 inline Foam::label Foam::globalIndex::size() const
60 {
61  return offsets_[Pstream::nProcs()-1];
62 }
63 
64 
65 inline Foam::label Foam::globalIndex::toGlobal
66 (
67  const label procI,
68  const label i
69 ) const
70 {
71  return(procI == 0 ? i : i + offsets_[procI-1]);
72 }
73 
74 
75 inline Foam::label Foam::globalIndex::toGlobal(const label i) const
76 {
77  return toGlobal(Pstream::myProcNo(), i);
78 }
79 
80 
81 //- Is on local processor
82 inline bool Foam::globalIndex::isLocal(const label procI, const label i) const
83 {
84  return
85  (i < offsets_[procI])
86  && (i >= (procI == 0 ? 0 : offsets_[procI-1]));
87 }
88 
89 
90 inline bool Foam::globalIndex::isLocal(const label i) const
91 {
92  return isLocal(Pstream::myProcNo(), i);
93 }
94 
95 
96 inline Foam::label Foam::globalIndex::toLocal(const label procI, const label i)
97 const
98 {
99  label localI = (procI == 0 ? i : i - offsets_[procI-1]);
100 
101  if (localI < 0 || i >= offsets_[procI])
102  {
103  FatalErrorIn("globalIndex::toLocal(const label, const label)")
104  << "Global " << i << " does not belong on processor "
105  << procI << endl << "Offsets:" << offsets_
106  << abort(FatalError);
107  }
108  return localI;
109 }
110 
111 
112 inline Foam::label Foam::globalIndex::toLocal(const label i) const
113 {
114  return toLocal(Pstream::myProcNo(), i);
115 }
116 
117 
118 inline Foam::label Foam::globalIndex::whichProcID(const label i) const
119 {
120  label index = findLower(offsets_, i+1);
121 
122  if (index == Pstream::nProcs()-1)
123  {
124  FatalErrorIn("globalIndex::whichProcID(const label)")
125  << "Global " << i << " does not belong on any processor."
126  << " Offsets:" << offsets_
127  << abort(FatalError);
128  }
129 
130  return index+1;
131 }
132 
133 
134 // ************************ vim: set sw=4 sts=4 et: ************************ //