OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

dataSchedule.H

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) 1991-2007 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 Class
00026     dataSchedule
00027 
00028 Description
00029     Gets for every data item the source processor and the send processor.
00030     Determines:
00031     - which processor do I need to send to / receive from
00032     - what are the indices into the data I need to send / I am receiving.
00033 
00034     Example:
00035     - we have global sampling points
00036     - for every sampling point we have the cell/processor containing the point
00037       (sampleCells, sampleCellProcs)
00038     - for every sampling point we also have the destination cell/processor
00039       (receiveCells, receiveCellProcs)
00040     - sampleCellProcs, receiveCellProcs have to be the same on all processors!
00041 
00042     then we construct dataSchedule:
00043 
00044         dataSchedule mySchedule(sampleCellProcs, receiveCellProcs);
00045 
00046         const labelListList& sendOrder = mySchedule.sendOrder();
00047         const labelListList& receiveOrder = mySchedule.receiveOrder();
00048 
00049         // Do all remote data
00050         // ~~~~~~~~~~~~~~~~~~
00051 
00052         forAll(mySchedule, commI)
00053         {
00054             const labelPair& twoProcs = mySchedule[i];
00055             label sendProc = twoProcs[0];
00056             label recvProc = twoProcs[1];
00057 
00058             if (Pstream::myProcNo() == sendProc)
00059             {
00060                 // I am sender. Send to recvProc.
00061 
00062                 // Labels of my cells to sample
00063                 labelList cellLabels
00064                 (
00065                     IndirectList<label>(sampleCells, sendOrder[recvProc])
00066                 );
00067 
00068                 OPstream toProc(recvProc);
00069                 toProc<< IndirectList<vector>(fld, cellLabels)();
00070             }
00071             else
00072             {
00073                 // I am receiver. Receive from sendProc.
00074                 IPstream fromProc(sendProc);
00075 
00076                 vectorField fromFld(fromProc);
00077 
00078                 // Destination cells
00079                 labelList cellLabels
00080                 (
00081                     IndirectList<label>(receiveCells, receiveOrder[sendProc])
00082                 );
00083 
00084                 forAll(fromFld, i)
00085                 {
00086                     fld[cellLabels[i]] = fromFld[i];
00087                 }
00088             }
00089         }
00090 
00091 
00092 
00093         // Do local data
00094         // ~~~~~~~~~~~~~
00095 
00096         labelList sendCells
00097         (
00098             IndirectList<label>(sampleCells, sendOrder[Pstream::myProcNo()])
00099         );
00100 
00101         vectorField toMyself(IndirectList<vector>(fld, sendCells)());
00102     
00103         // Destination cells
00104         labelList recvCells
00105         (
00106             IndirectList<label>
00107             (
00108                 patchFaces,
00109                 receiveOrder[Pstream::myProcNo()]
00110             )
00111         );
00112 
00113         forAll(toMyself, i)
00114         {
00115             recvCells[i] = toMySelf[i];
00116         }
00117 
00118 
00119 SourceFiles
00120     dataSchedule.C
00121 
00122 \*---------------------------------------------------------------------------*/
00123 
00124 #ifndef dataSchedule_H
00125 #define dataSchedule_H
00126 
00127 #include "commSchedule.H"
00128 
00129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00130 
00131 namespace Foam
00132 {
00133 
00134 /*---------------------------------------------------------------------------*\
00135                            Class dataSchedule Declaration
00136 \*---------------------------------------------------------------------------*/
00137 
00138 class dataSchedule
00139 :
00140     public List<labelPair>
00141 {
00142     // Private data
00143 
00144         //- Per processor to send to the order in which the data needs to
00145         //  be packed.
00146         labelListList sendOrder_;
00147 
00148         //- Per processor to receive from the order how to unpack the
00149         //  received data.
00150         labelListList receiveOrder_;
00151 
00152 
00153 public:
00154 
00155     ClassName("dataSchedule");
00156 
00157     // Constructors
00158 
00159         //- Construct from components
00160         dataSchedule(const labelList& sendProcs, const labelList& receiveProcs);
00161 
00162 
00163     // Member Functions
00164 
00165         //- Send order per processor
00166         const labelListList& sendOrder() const
00167         {
00168             return sendOrder_;
00169         }
00170 
00171         //- Receive order per processor
00172         const labelListList& receiveOrder() const
00173         {
00174             return receiveOrder_;
00175         }
00176 
00177 };
00178 
00179 
00180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00181 
00182 } // End namespace Foam
00183 
00184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00185 
00186 #endif
00187 
00188 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd