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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2021-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "UPstream.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 :
35  above_(-1),
36  below_(),
37  allBelow_(),
38  allNotBelow_()
39 {}
40 
41 
43 (
44  const label above,
45  const labelUList& below,
46  const labelUList& allBelow,
47  const labelUList& allNotBelow
48 )
49 :
50  above_(above),
51  below_(below),
52  allBelow_(allBelow),
53  allNotBelow_(allNotBelow)
54 {}
55 
56 
58 (
59  const label nProcs,
60  const label myProcID,
61  const label above,
62  const labelUList& below,
63  const labelUList& allBelow
64 )
65 :
66  above_(above),
67  below_(below),
68  allBelow_(allBelow),
69  allNotBelow_(nProcs - allBelow.size() - 1)
70 {
71  boolList inBelow(nProcs, false);
72 
73  forAll(allBelow, belowI)
74  {
75  inBelow[allBelow[belowI]] = true;
76  }
77 
78  label notI = 0;
79  forAll(inBelow, proci)
80  {
81  if ((proci != myProcID) && !inBelow[proci])
82  {
83  allNotBelow_[notI++] = proci;
84  }
85  }
86  if (notI != allNotBelow_.size())
87  {
89  }
90 }
91 
92 
93 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94 
96 {
97  above_ = -1;
98  below_.clear();
99  allBelow_.clear();
100  allNotBelow_.clear();
101 }
102 
103 
104 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
105 
107 {
108  return
109  (
110  (above_ == comm.above())
111  && (below_ == comm.below())
112  && (allBelow_ == allBelow())
113  && (allNotBelow_ == allNotBelow())
114  );
115 }
116 
117 
119 {
120  return !operator==(comm);
121 }
122 
123 
124 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
125 
126 Foam::Ostream& Foam::operator<<(Ostream& os, const UPstream::commsStruct& comm)
127 {
128  os << comm.above_ << token::SPACE
129  << comm.below_ << token::SPACE
130  << comm.allBelow_ << token::SPACE
131  << comm.allNotBelow_;
132 
133  os.check(FUNCTION_NAME);
134  return os;
135 }
136 
137 
138 // ************************************************************************* //
const labelList & below() const noexcept
The procIDs of all processors directly below.
Definition: UPstream.H:162
commsStruct() noexcept
Default construct. Above == -1.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:118
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
void clear()
Reset to default constructed state.
label above() const noexcept
The procID of the processor directly above.
Definition: UPstream.H:154
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator) is 1 for serial run.
Definition: UPstream.H:656
Space [isspace].
Definition: token.H:128
errorManip< error > abort(error &err)
Definition: errorManip.H:139
Structure for communicating between processors.
Definition: UPstream.H:84
const labelList & allBelow() const noexcept
The procIDs of all processors below (so not just directly below)
Definition: UPstream.H:171
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
const direction noexcept
Definition: Scalar.H:258
bool operator==(const commsStruct &) const
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
bool operator!=(const commsStruct &) const
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:76
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)