00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 00023 00024 \*---------------------------------------------------------------------------*/ 00025 00026 #include <OpenFOAM/ListOps.H> 00027 00028 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // 00029 00030 //inline const Foam::labelList& Foam::globalIndex::offsets() const 00031 //{ 00032 // return offsets_; 00033 //} 00034 00035 00036 inline Foam::label Foam::globalIndex::offset(const label procI) const 00037 { 00038 return (procI == 0 ? 0 : offsets_[procI-1]); 00039 } 00040 00041 00042 inline Foam::label Foam::globalIndex::localSize(const label procI) const 00043 { 00044 return 00045 ( 00046 procI == 0 00047 ? offsets_[procI] 00048 : offsets_[procI] - offsets_[procI-1] 00049 ); 00050 } 00051 00052 00053 inline Foam::label Foam::globalIndex::localSize() const 00054 { 00055 return localSize(Pstream::myProcNo()); 00056 } 00057 00058 00059 inline Foam::label Foam::globalIndex::size() const 00060 { 00061 return offsets_[Pstream::nProcs()-1]; 00062 } 00063 00064 00065 inline Foam::label Foam::globalIndex::toGlobal 00066 ( 00067 const label procI, 00068 const label i 00069 ) const 00070 { 00071 return(procI == 0 ? i : i + offsets_[procI-1]); 00072 } 00073 00074 00075 inline Foam::label Foam::globalIndex::toGlobal(const label i) const 00076 { 00077 return toGlobal(Pstream::myProcNo(), i); 00078 } 00079 00080 00081 //- Is on local processor 00082 inline bool Foam::globalIndex::isLocal(const label procI, const label i) const 00083 { 00084 return 00085 (i < offsets_[procI]) 00086 && (i >= (procI == 0 ? 0 : offsets_[procI-1])); 00087 } 00088 00089 00090 inline bool Foam::globalIndex::isLocal(const label i) const 00091 { 00092 return isLocal(Pstream::myProcNo(), i); 00093 } 00094 00095 00096 inline Foam::label Foam::globalIndex::toLocal(const label procI, const label i) 00097 const 00098 { 00099 label localI = (procI == 0 ? i : i - offsets_[procI-1]); 00100 00101 if (localI < 0 || i >= offsets_[procI]) 00102 { 00103 FatalErrorIn("globalIndex::toLocal(const label, const label)") 00104 << "Global " << i << " does not belong on processor " 00105 << procI << endl << "Offsets:" << offsets_ 00106 << abort(FatalError); 00107 } 00108 return localI; 00109 } 00110 00111 00112 inline Foam::label Foam::globalIndex::toLocal(const label i) const 00113 { 00114 return toLocal(Pstream::myProcNo(), i); 00115 } 00116 00117 00118 inline Foam::label Foam::globalIndex::whichProcID(const label i) const 00119 { 00120 label index = findLower(offsets_, i+1); 00121 00122 if (index == Pstream::nProcs()-1) 00123 { 00124 FatalErrorIn("globalIndex::whichProcID(const label)") 00125 << "Global " << i << " does not belong on any processor." 00126 << " Offsets:" << offsets_ 00127 << abort(FatalError); 00128 } 00129 00130 return index+1; 00131 } 00132 00133 00134 // ************************ vim: set sw=4 sts=4 et: ************************ //