initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / lagrangian / molecularDynamics / molecule / referralLists / sendingReferralList.C
blob4e0d12cf723488fa83059f5b4b2c58920226ce47
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*----------------------------------------------------------------------------*/
27 #include "sendingReferralList.H"
29 namespace Foam
32 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
34 sendingReferralList::sendingReferralList()
36     labelList(),
37     destinationProc_(-1)
41 sendingReferralList::sendingReferralList
43     const label destinationProc,
44     const labelList& cellsToSend
47     labelList(cellsToSend),
48     destinationProc_(destinationProc)
52 sendingReferralList::sendingReferralList
54     const sendingReferralList& rL
57     labelList(rL),
58     destinationProc_(rL.destinationProc())
62 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
64 sendingReferralList::~sendingReferralList()
68 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
70 void sendingReferralList::operator=(const sendingReferralList& rhs)
72     // Check for assignment to self
73     if (this == &rhs)
74     {
75         FatalErrorIn
76         (
77             "Foam::distribution::operator=(const Foam::distribution&)"
78         )
79             << "Attempted assignment to self"
80             << abort(FatalError);
81     }
83     labelList::operator=(rhs);
85     destinationProc_ = rhs.destinationProc();
89 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
91 bool operator==
93     const sendingReferralList& a,
94     const sendingReferralList& b
97     // Trivial reject: lists are different size
98     if (a.size() != b.size())
99     {
100         return false;
101     }
103     // Or if source processors are not the same.
104     if (a.destinationProc() != b.destinationProc())
105     {
106         return false;
107     }
109     List<bool> fnd(a.size(), false);
111     forAll (b, bI)
112     {
113         label curLabel = b[bI];
115         bool found = false;
117         forAll (a, aI)
118         {
119             if (a[aI] == curLabel)
120             {
121                 found = true;
122                 fnd[aI] = true;
123                 break;
124             }
125         }
127         if (!found)
128         {
129             return false;
130         }
131     }
133     // check if all labels on a were marked
134     bool result = true;
136     forAll (fnd, aI)
137     {
138         result = (result && fnd[aI]);
139     }
141     return result;
145 Istream& operator>>
147     Istream& is,
148     sendingReferralList& sRL
151     is >> sRL.destinationProc_ >> static_cast<labelList&>(sRL);
153     is.check("Istream& operator<<(Istream& f, const sendingReferralList& sRL");
155     return is;
159 Ostream& operator<<
161     Ostream& os,
162     const sendingReferralList& rL
165     os << rL.destinationProc() << token::SPACE
166         << static_cast< const labelList& >(rL);
168     os.check("Ostream& operator<<(Ostream& f, const sendingReferralList& rL");
170     return os;
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 } // End namespace Foam
178 // ************************************************************************* //