initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / lagrangian / molecularDynamics / molecule / moleculeCloud / moleculeCloudBuildCellReferralLists.C
blob8bba81ee6dfaf7ff29db1827068e39de4ab0fabc
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 "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
41     forAll(refIntL, rIL)
42     {
43         const referredCell& rC(refIntL[rIL]);
45         if (findIndex(referralProcs, rC.sourceProc()) == -1)
46         {
47             referralProcs.append(rC.sourceProc());
48         }
49     }
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
62     forAll(refIntL, rIL)
63     {
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
80         // same time.
82         if (existingSource == -1)
83         {
84             sRL.append(rC.sourceCell());
86             rRL.append
87             (
88                 DynamicList<label> (labelList(1,rIL))
89             );
90         }
91         else
92         {
93             rRL[existingSource].append(rIL);
95             rRL[existingSource].shrink();
96         }
97     }
99     forAll(referralProcs, rPI)
100     {
101         DynamicList<DynamicList<label> >& rRL(cellReceivingReferralLists[rPI]);
103         DynamicList<label>& sRL(cellSendingReferralLists[rPI]);
105         sRL.shrink();
107         rRL.shrink();
108     }
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)
118     {
119         DynamicList<DynamicList<label> >& rRL(cellReceivingReferralLists[rPI]);
121         labelListList translLL(rRL.size());
123         forAll(rRL, rRLI)
124         {
125             translLL[rRLI] = rRL[rRLI];
126         }
128         cellReceivingReferralLists_[rPI] = receivingReferralList
129         (
130             referralProcs[rPI],
131             translLL
132         );
133     }
135     // Send sendingReferralLists to each interacting processor.
137     forAll(referralProcs, rPI)
138     {
140         DynamicList<label>& sRL(cellSendingReferralLists[rPI]);
142         if (referralProcs[rPI] != Pstream::myProcNo())
143         {
144             if (Pstream::parRun())
145             {
146                 OPstream toInteractingProc
147                 (
148                     Pstream::blocking,
149                     referralProcs[rPI]
150                 );
152                 toInteractingProc << sendingReferralList
153                 (
154                     Pstream::myProcNo(),
155                     sRL
156                 );
157             }
158         }
159     }
161     // Receive sendingReferralLists from each interacting processor.
163     forAll(referralProcs, rPI)
164     {
165         if (referralProcs[rPI] != Pstream::myProcNo())
166         {
167             if (Pstream::parRun())
168             {
169                 IPstream fromInteractingProc
170                 (
171                     Pstream::blocking,
172                     referralProcs[rPI]
173                 );
175                 fromInteractingProc >> cellSendingReferralLists_[rPI];
176             }
177         }
178         else
179         {
180             cellSendingReferralLists_[rPI] = sendingReferralList
181             (
182                 Pstream::myProcNo(),
183                 cellSendingReferralLists[rPI]
184             );
185         }
186     }
188 //     Pout << "receiving list: " << nl << cellReceivingReferralLists_ << endl;
190 //     Pout << "sending list: " << nl << cellSendingReferralLists_ << endl;
194 // ************************************************************************* //