UPstreamCommsStruct.C
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) 2011-2016 OpenFOAM Foundation
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 "UPstream.H"
27 #include "boolList.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 :
33  above_(-1),
34  below_(0),
35  allBelow_(0),
36  allNotBelow_(0)
37 {}
38 
39 
41 (
42  const label above,
43  const labelList& below,
44  const labelList& allBelow,
45  const labelList& allNotBelow
46 )
47 :
48  above_(above),
49  below_(below),
50  allBelow_(allBelow),
51  allNotBelow_(allNotBelow)
52 {}
53 
54 
56 (
57  const label nProcs,
58  const label myProcID,
59  const label above,
60  const labelList& below,
61  const labelList& allBelow
62 )
63 :
64  above_(above),
65  below_(below),
66  allBelow_(allBelow),
67  allNotBelow_(nProcs - allBelow.size() - 1)
68 {
69  boolList inBelow(nProcs, false);
70 
71  forAll(allBelow, belowI)
72  {
73  inBelow[allBelow[belowI]] = true;
74  }
75 
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  {
87  }
88 }
89 
90 
91 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
92 
94 {
95  return
96  (
97  (above_ == comm.above())
98  && (below_ == comm.below())
99  && (allBelow_ == allBelow())
100  && (allNotBelow_ == allNotBelow())
101  );
102 }
103 
104 
106 {
107  return !operator==(comm);
108 }
109 
110 
111 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
112 
114 {
115  os << comm.above_ << token::SPACE
116  << comm.below_ << token::SPACE
117  << comm.allBelow_ << token::SPACE
118  << comm.allNotBelow_;
119 
120  os.check
121  (
122  "Ostream& operator<<(Ostream&, const commsStruct&)"
123  );
124 
125  return os;
126 }
127 
128 
129 // ************************************************************************* //
const labelList & below() const
Definition: UPstream.H:130
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Structure for communicating between processors.
Definition: UPstream.H:76
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
bool operator==(const commsStruct &) const
const labelList & allBelow() const
Definition: UPstream.H:135
bool operator!=(const commsStruct &) const
Ostream & operator<<(Ostream &, const ensightPart &)
const labelList & allNotBelow() const
Definition: UPstream.H:140