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

PstreamCommsStruct.C

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 "Pstream.H"
00028 #include "boolList.H"
00029 
00030 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00031 
00032 Foam::Pstream::commsStruct::commsStruct()
00033 :
00034     above_(-1),
00035     below_(0),
00036     allBelow_(0),
00037     allNotBelow_(0)
00038 {}
00039 
00040 
00041 Foam::Pstream::commsStruct::commsStruct
00042 (
00043     const label above,
00044     const labelList& below,
00045     const labelList& allBelow,
00046     const labelList& allNotBelow
00047 )
00048 :
00049     above_(above),
00050     below_(below),
00051     allBelow_(allBelow),
00052     allNotBelow_(allNotBelow)
00053 {}
00054 
00055 
00056 Foam::Pstream::commsStruct::commsStruct
00057 (
00058     const label nProcs,
00059     const label myProcID,
00060     const label above,
00061     const labelList& below,
00062     const labelList& allBelow
00063 )
00064 :
00065     above_(above),
00066     below_(below),
00067     allBelow_(allBelow),
00068     allNotBelow_(nProcs - allBelow.size() - 1)
00069 {
00070     boolList inBelow(nProcs, false);
00071 
00072     forAll(allBelow, belowI)
00073     {
00074         inBelow[allBelow[belowI]] = true;
00075     }
00076 
00077     label notI = 0;
00078     forAll(inBelow, procI)
00079     {
00080         if ((procI != myProcID) && !inBelow[procI])
00081         {
00082             allNotBelow_[notI++] = procI;
00083         }
00084     }
00085     if (notI != allNotBelow_.size())
00086     {
00087         FatalErrorIn("commsStruct") << "problem!" << Foam::abort(FatalError);
00088     }
00089 }
00090 
00091 
00092 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00093 
00094 bool Foam::Pstream::commsStruct::operator==(const commsStruct& comm) const
00095 {
00096     return
00097     (
00098         (above_ == comm.above())
00099      && (below_ == comm.below())
00100      && (allBelow_ == allBelow())
00101      && (allNotBelow_ == allNotBelow())
00102     );
00103 }
00104 
00105 
00106 bool Foam::Pstream::commsStruct::operator!=(const commsStruct& comm) const
00107 {
00108     return !operator==(comm);
00109 }
00110 
00111 
00112 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
00113 
00114 Foam::Ostream& Foam::operator<<(Ostream& os, const Pstream::commsStruct& comm)
00115 {
00116     os  << comm.above_ << token::SPACE
00117         << comm.below_ << token::SPACE
00118         << comm.allBelow_ << token::SPACE
00119         << comm.allNotBelow_;
00120 
00121     os.check
00122     (
00123         "Ostream& operator<<(Ostream&, const commsStruct&)"
00124     );
00125 
00126     return os;
00127 }
00128 
00129 
00130 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd