OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

globalIndexI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "ListOps.H"
00028 
00029 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00030 
00031 //inline const Foam::labelList& Foam::globalIndex::offsets() const
00032 //{
00033 //    return offsets_;
00034 //}
00035 
00036 
00037 inline Foam::label Foam::globalIndex::offset(const label procI) const
00038 {
00039     return (procI == 0 ? 0 : offsets_[procI-1]);
00040 }
00041 
00042 
00043 inline Foam::label Foam::globalIndex::localSize(const label procI) const
00044 {
00045     return
00046     (
00047         procI == 0
00048       ? offsets_[procI]
00049       : offsets_[procI] - offsets_[procI-1]
00050     );
00051 }
00052 
00053 
00054 inline Foam::label Foam::globalIndex::localSize() const
00055 {
00056     return localSize(Pstream::myProcNo());
00057 }
00058 
00059 
00060 inline Foam::label Foam::globalIndex::size() const
00061 {
00062     return offsets_[Pstream::nProcs()-1];
00063 }
00064 
00065 
00066 inline Foam::label Foam::globalIndex::toGlobal
00067 (
00068     const label procI,
00069     const label i
00070 ) const
00071 {
00072     return(procI == 0 ? i : i + offsets_[procI-1]);
00073 }
00074 
00075 
00076 inline Foam::label Foam::globalIndex::toGlobal(const label i) const
00077 {
00078     return toGlobal(Pstream::myProcNo(), i);
00079 }
00080 
00081 
00082 //- Is on local processor
00083 inline bool Foam::globalIndex::isLocal(const label procI, const label i) const
00084 {
00085     return
00086         (i < offsets_[procI])
00087      && (i >= (procI == 0 ? 0 : offsets_[procI-1]));
00088 }
00089 
00090 
00091 inline bool Foam::globalIndex::isLocal(const label i) const
00092 {
00093     return isLocal(Pstream::myProcNo(), i);
00094 }
00095 
00096 
00097 inline Foam::label Foam::globalIndex::toLocal(const label procI, const label i)
00098 const
00099 {
00100     label localI = (procI == 0 ? i : i - offsets_[procI-1]);
00101 
00102     if (localI < 0 || i >= offsets_[procI])
00103     {
00104         FatalErrorIn("globalIndex::toLocal(const label, const label)")
00105             << "Global " << i << " does not belong on processor "
00106             << procI << endl << "Offsets:" << offsets_
00107             << abort(FatalError);
00108     }
00109     return localI;
00110 }
00111 
00112 
00113 inline Foam::label Foam::globalIndex::toLocal(const label i) const
00114 {
00115     return toLocal(Pstream::myProcNo(), i);
00116 }
00117 
00118 
00119 inline Foam::label Foam::globalIndex::whichProcID(const label i) const
00120 {
00121     label index = findLower(offsets_, i+1);
00122 
00123     if (index == Pstream::nProcs()-1)
00124     {
00125         FatalErrorIn("globalIndex::whichProcID(const label)")
00126             << "Global " << i << " does not belong on any processor."
00127             << " Offsets:" << offsets_
00128             << abort(FatalError);
00129     }
00130 
00131     return index+1;
00132 }
00133 
00134 
00135 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd