OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

sendingReferralList.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 2008-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*----------------------------------------------------------------------------*/
00026 
00027 #include "sendingReferralList.H"
00028 
00029 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00030 
00031 Foam::sendingReferralList::sendingReferralList()
00032 :
00033     labelList(),
00034     destinationProc_(-1)
00035 {}
00036 
00037 
00038 Foam::sendingReferralList::sendingReferralList
00039 (
00040     const label destinationProc,
00041     const labelList& cellsToSend
00042 )
00043 :
00044     labelList(cellsToSend),
00045     destinationProc_(destinationProc)
00046 {}
00047 
00048 
00049 Foam::sendingReferralList::sendingReferralList
00050 (
00051     const sendingReferralList& rL
00052 )
00053 :
00054     labelList(rL),
00055     destinationProc_(rL.destinationProc())
00056 {}
00057 
00058 
00059 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00060 
00061 Foam::sendingReferralList::~sendingReferralList()
00062 {}
00063 
00064 
00065 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00066 
00067 void Foam::sendingReferralList::operator=(const sendingReferralList& rhs)
00068 {
00069     // Check for assignment to self
00070     if (this == &rhs)
00071     {
00072         FatalErrorIn
00073         (
00074             "Foam::distribution::operator=(const Foam::distribution&)"
00075         )
00076             << "Attempted assignment to self"
00077             << abort(FatalError);
00078     }
00079 
00080     labelList::operator=(rhs);
00081 
00082     destinationProc_ = rhs.destinationProc();
00083 }
00084 
00085 
00086 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00087 
00088 bool operator==
00089 (
00090     const Foam::sendingReferralList& a,
00091     const Foam::sendingReferralList& b
00092 )
00093 {
00094     // Trivial reject: lists are different size
00095     if (a.size() != b.size())
00096     {
00097         return false;
00098     }
00099 
00100     // Or if source processors are not the same.
00101     if (a.destinationProc() != b.destinationProc())
00102     {
00103         return false;
00104     }
00105 
00106     Foam::List<bool> fnd(a.size(), false);
00107 
00108     forAll (b, bI)
00109     {
00110         Foam::label curLabel = b[bI];
00111 
00112         bool found = false;
00113 
00114         forAll (a, aI)
00115         {
00116             if (a[aI] == curLabel)
00117             {
00118                 found = true;
00119                 fnd[aI] = true;
00120                 break;
00121             }
00122         }
00123 
00124         if (!found)
00125         {
00126             return false;
00127         }
00128     }
00129 
00130     // check if all labels on a were marked
00131     bool result = true;
00132 
00133     forAll (fnd, aI)
00134     {
00135         result = (result && fnd[aI]);
00136     }
00137 
00138     return result;
00139 }
00140 
00141 
00142 Foam::Istream& Foam::operator>>
00143 (
00144     Istream& is,
00145     sendingReferralList& sRL
00146 )
00147 {
00148     is  >> sRL.destinationProc_ >> static_cast<labelList&>(sRL);
00149 
00150     is.check("Istream& operator<<(Istream& f, const sendingReferralList& sRL");
00151 
00152     return is;
00153 }
00154 
00155 
00156 Foam::Ostream& Foam::operator<<
00157 (
00158     Ostream& os,
00159     const sendingReferralList& rL
00160 )
00161 {
00162     os  << rL.destinationProc() << token::SPACE
00163         << static_cast< const labelList& >(rL);
00164 
00165     os.check("Ostream& operator<<(Ostream& f, const sendingReferralList& rL");
00166 
00167     return os;
00168 }
00169 
00170 
00171 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd