FreeFOAM The Cross-Platform CFD Toolkit
sendingReferralList.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) 2008-2010 OpenCFD Ltd.
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 
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
31 :
32  labelList(),
33  destinationProc_(-1)
34 {}
35 
36 
38 (
39  const label destinationProc,
40  const labelList& cellsToSend
41 )
42 :
43  labelList(cellsToSend),
44  destinationProc_(destinationProc)
45 {}
46 
47 
49 (
50  const sendingReferralList& rL
51 )
52 :
53  labelList(rL),
54  destinationProc_(rL.destinationProc())
55 {}
56 
57 
58 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
59 
61 {}
62 
63 
64 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
65 
67 {
68  // Check for assignment to self
69  if (this == &rhs)
70  {
72  (
73  "Foam::distribution::operator=(const Foam::distribution&)"
74  )
75  << "Attempted assignment to self"
76  << abort(FatalError);
77  }
78 
80 
81  destinationProc_ = rhs.destinationProc();
82 }
83 
84 
85 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
86 
87 bool operator==
88 (
91 )
92 {
93  // Trivial reject: lists are different size
94  if (a.size() != b.size())
95  {
96  return false;
97  }
98 
99  // Or if source processors are not the same.
100  if (a.destinationProc() != b.destinationProc())
101  {
102  return false;
103  }
104 
105  Foam::List<bool> fnd(a.size(), false);
106 
107  forAll (b, bI)
108  {
109  Foam::label curLabel = b[bI];
110 
111  bool found = false;
112 
113  forAll (a, aI)
114  {
115  if (a[aI] == curLabel)
116  {
117  found = true;
118  fnd[aI] = true;
119  break;
120  }
121  }
122 
123  if (!found)
124  {
125  return false;
126  }
127  }
128 
129  // check if all labels on a were marked
130  bool result = true;
131 
132  forAll (fnd, aI)
133  {
134  result = (result && fnd[aI]);
135  }
136 
137  return result;
138 }
139 
140 
141 Foam::Istream& Foam::operator>>
142 (
143  Istream& is,
144  sendingReferralList& sRL
145 )
146 {
147  is >> sRL.destinationProc_ >> static_cast<labelList&>(sRL);
148 
149  is.check("Istream& operator<<(Istream& f, const sendingReferralList& sRL");
150 
151  return is;
152 }
153 
154 
155 Foam::Ostream& Foam::operator<<
156 (
157  Ostream& os,
158  const sendingReferralList& rL
159 )
160 {
161  os << rL.destinationProc() << token::SPACE
162  << static_cast< const labelList& >(rL);
163 
164  os.check("Ostream& operator<<(Ostream& f, const sendingReferralList& rL");
165 
166  return os;
167 }
168 
169 
170 // ************************ vim: set sw=4 sts=4 et: ************************ //