Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / OpenFOAM / db / IOstreams / Pstreams / UPstreamCommsStruct.C
blobcfe7f761c360038fd454aa19c8010749c0c3da16
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "UPstream.H"
27 #include "boolList.H"
29 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
31 Foam::UPstream::commsStruct::commsStruct()
33     above_(-1),
34     below_(0),
35     allBelow_(0),
36     allNotBelow_(0)
40 Foam::UPstream::commsStruct::commsStruct
42     const label above,
43     const labelList& below,
44     const labelList& allBelow,
45     const labelList& allNotBelow
48     above_(above),
49     below_(below),
50     allBelow_(allBelow),
51     allNotBelow_(allNotBelow)
55 Foam::UPstream::commsStruct::commsStruct
57     const label nProcs,
58     const label myProcID,
59     const label above,
60     const labelList& below,
61     const labelList& allBelow
64     above_(above),
65     below_(below),
66     allBelow_(allBelow),
67     allNotBelow_(nProcs - allBelow.size() - 1)
69     boolList inBelow(nProcs, false);
71     forAll(allBelow, belowI)
72     {
73         inBelow[allBelow[belowI]] = true;
74     }
76     label notI = 0;
77     forAll(inBelow, procI)
78     {
79         if ((procI != myProcID) && !inBelow[procI])
80         {
81             allNotBelow_[notI++] = procI;
82         }
83     }
84     if (notI != allNotBelow_.size())
85     {
86         FatalErrorIn("commsStruct") << "problem!" << Foam::abort(FatalError);
87     }
91 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
93 bool Foam::UPstream::commsStruct::operator==(const commsStruct& comm) const
95     return
96     (
97         (above_ == comm.above())
98      && (below_ == comm.below())
99      && (allBelow_ == allBelow())
100      && (allNotBelow_ == allNotBelow())
101     );
105 bool Foam::UPstream::commsStruct::operator!=(const commsStruct& comm) const
107     return !operator==(comm);
111 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
113 Foam::Ostream& Foam::operator<<(Ostream& os, const UPstream::commsStruct& comm)
115     os  << comm.above_ << token::SPACE
116         << comm.below_ << token::SPACE
117         << comm.allBelow_ << token::SPACE
118         << comm.allNotBelow_;
120     os.check
121     (
122         "Ostream& operator<<(Ostream&, const commsStruct&)"
123     );
125     return os;
129 // ************************************************************************* //