1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 "moleculeCloud.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 void Foam::moleculeCloud::buildCellReferralLists()
33 Info<< nl << "Determining molecule referring schedule" << endl;
35 const referredCellList& refIntL(referredInteractionList());
37 DynamicList<label> referralProcs;
39 // Run through all referredCells to build list of interacting processors
43 const referredCell& rC(refIntL[rIL]);
45 if (findIndex(referralProcs, rC.sourceProc()) == -1)
47 referralProcs.append(rC.sourceProc());
51 referralProcs.shrink();
53 // Pout << "referralProcs: " << nl << referralProcs << endl;
55 List<DynamicList<label> > cellSendingReferralLists(referralProcs.size());
57 List<DynamicList<DynamicList<label> > >
58 cellReceivingReferralLists(referralProcs.size());
60 // Run through all referredCells again building up send and receive info
64 const referredCell& rC(refIntL[rIL]);
66 label rPI = findIndex(referralProcs, rC.sourceProc());
68 DynamicList<DynamicList<label> >& rRL(cellReceivingReferralLists[rPI]);
70 DynamicList<label>& sRL(cellSendingReferralLists[rPI]);
72 label existingSource = findIndex(sRL, rC.sourceCell());
74 // Check to see if this source cell has already been allocated to
75 // come to this processor. If not, add the source cell to the sending
76 // list and add the current referred cell to the receiving list.
78 // It shouldn't be possible for the sending and receiving lists to be
79 // different lengths, because their append operations happen at the
82 if (existingSource == -1)
84 sRL.append(rC.sourceCell());
88 DynamicList<label> (labelList(1,rIL))
93 rRL[existingSource].append(rIL);
95 rRL[existingSource].shrink();
99 forAll(referralProcs, rPI)
101 DynamicList<DynamicList<label> >& rRL(cellReceivingReferralLists[rPI]);
103 DynamicList<label>& sRL(cellSendingReferralLists[rPI]);
110 // It is assumed that cell exchange is reciprocal, if proc A has cells to
111 // send to proc B, then proc B must have some to send to proc A.
113 cellReceivingReferralLists_.setSize(referralProcs.size());
115 cellSendingReferralLists_.setSize(referralProcs.size());
117 forAll(referralProcs, rPI)
119 DynamicList<DynamicList<label> >& rRL(cellReceivingReferralLists[rPI]);
121 labelListList translLL(rRL.size());
125 translLL[rRLI] = rRL[rRLI];
128 cellReceivingReferralLists_[rPI] = receivingReferralList
135 // Send sendingReferralLists to each interacting processor.
137 forAll(referralProcs, rPI)
140 DynamicList<label>& sRL(cellSendingReferralLists[rPI]);
142 if (referralProcs[rPI] != Pstream::myProcNo())
144 if (Pstream::parRun())
146 OPstream toInteractingProc
152 toInteractingProc << sendingReferralList
161 // Receive sendingReferralLists from each interacting processor.
163 forAll(referralProcs, rPI)
165 if (referralProcs[rPI] != Pstream::myProcNo())
167 if (Pstream::parRun())
169 IPstream fromInteractingProc
175 fromInteractingProc >> cellSendingReferralLists_[rPI];
180 cellSendingReferralLists_[rPI] = sendingReferralList
183 cellSendingReferralLists[rPI]
188 // Pout << "receiving list: " << nl << cellReceivingReferralLists_ << endl;
190 // Pout << "sending list: " << nl << cellSendingReferralLists_ << endl;
194 // ************************************************************************* //