FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

mapDistribute.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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Class
00025     Foam::mapDistribute
00026 
00027 Description
00028     Class containing processor-to-processor mapping information.
00029 
00030     We store mapping from the bits-to-send to the complete starting list
00031     (subXXXMap) and from the received bits to their location in the new
00032     list (constructXXXMap).
00033 
00034 Note:
00035     Schedule is a list of processor pairs (one send, one receive. One of
00036     them will be myself) which forms a scheduled (i.e. non-buffered) exchange.
00037     See distribute on how to use it.
00038     Note2: number of items send on one processor have to equal the number
00039     of items received on the other processor.
00040 
00041 
00042 SourceFiles
00043     mapDistribute.C
00044 
00045 \*---------------------------------------------------------------------------*/
00046 
00047 #ifndef mapDistribute_H
00048 #define mapDistribute_H
00049 
00050 #include <OpenFOAM/labelList.H>
00051 #include <OpenFOAM/labelPair.H>
00052 #include <OpenFOAM/Pstream.H>
00053 #include <OpenFOAM/boolList.H>
00054 
00055 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00056 
00057 namespace Foam
00058 {
00059 
00060 class mapPolyMesh;
00061 
00062 /*---------------------------------------------------------------------------*\
00063                            Class mapDistribute Declaration
00064 \*---------------------------------------------------------------------------*/
00065 
00066 class mapDistribute
00067 {
00068     // Private data
00069 
00070         //- Size of reconstructed data
00071         label constructSize_;
00072 
00073         //- Maps from subsetted data back to original data
00074         labelListList subMap_;
00075 
00076         //- Maps from subsetted data to new reconstructed data
00077         labelListList constructMap_;
00078 
00079         //- Schedule
00080         mutable autoPtr<List<labelPair> > schedulePtr_;
00081 
00082 
00083 public:
00084 
00085     // Constructors
00086 
00087         //- Construct from components
00088         mapDistribute
00089         (
00090             const label constructSize,
00091             const labelListList& subMap,
00092             const labelListList& constructMap
00093         );
00094 
00095         //- (optionally destructively) construct from components
00096         mapDistribute
00097         (
00098             const label constructSize,
00099             labelListList& subMap,
00100             labelListList& constructMap,
00101             const bool reUse                // clone or reuse
00102         );
00103 
00104         //- Construct from reverse addressing: per data item the send
00105         //  processor and the receive processor. All processors get same data.
00106         mapDistribute
00107         (
00108             const labelList& sendProcs,
00109             const labelList& recvProcs
00110         );
00111 
00112         //- Construct copy
00113         mapDistribute(const mapDistribute&);
00114 
00115 
00116     // Member Functions
00117 
00118         // Access
00119 
00120             //- Constructed data size
00121             label constructSize() const
00122             {
00123                 return constructSize_;
00124             }
00125 
00126             //- Constructed data size
00127             label& constructSize()
00128             {
00129                 return constructSize_;
00130             }
00131 
00132             //- From subsetted data back to original data
00133             const labelListList& subMap() const
00134             {
00135                 return subMap_;
00136             }
00137 
00138             //- From subsetted data back to original data
00139             labelListList& subMap()
00140             {
00141                 return subMap_;
00142             }
00143 
00144             //- From subsetted data to new reconstructed data
00145             const labelListList& constructMap() const
00146             {
00147                 return constructMap_;
00148             }
00149 
00150             //- From subsetted data to new reconstructed data
00151             labelListList& constructMap()
00152             {
00153                 return constructMap_;
00154             }
00155 
00156             //- Calculate a schedule. See above.
00157             static List<labelPair> schedule
00158             (
00159                 const labelListList& subMap,
00160                 const labelListList& constructMap
00161             );
00162 
00163             //- Return a schedule. Demand driven. See above.
00164             const List<labelPair>& schedule() const;
00165 
00166 
00167         // Other
00168 
00169             //- Compact maps. Gets per field a bool whether it is used (locally)
00170             //  and works out itself what this side and sender side can remove
00171             //  from maps.
00172             void compact(const boolList& elemIsUsed);
00173 
00174 
00175             //- Distribute data. Note:schedule only used for Pstream::scheduled
00176             //  for now, all others just use send-to-all, receive-from-all.
00177             template<class T>
00178             static void distribute
00179             (
00180                 const Pstream::commsTypes commsType,
00181                 const List<labelPair>& schedule,
00182                 const label constructSize,
00183                 const labelListList& subMap,
00184                 const labelListList& constructMap,
00185                 List<T>&
00186             );
00187 
00188             //- Distribute data. If multiple processors writing to same
00189             //  position adds contributions using cop.
00190             template<class T, class CombineOp>
00191             static void distribute
00192             (
00193                 const Pstream::commsTypes commsType,
00194                 const List<labelPair>& schedule,
00195                 const label constructSize,
00196                 const labelListList& subMap,
00197                 const labelListList& constructMap,
00198                 List<T>&,
00199                 const CombineOp& cop,
00200                 const T& nullValue
00201             );
00202 
00203             //- Distribute data using default commsType.
00204             template<class T>
00205             void distribute(List<T>& fld) const
00206             {
00207                 if
00208                 (
00209                     Pstream::defaultCommsType == Pstream::nonBlocking
00210                  && contiguous<T>()
00211                 )
00212                 {
00213                     distribute
00214                     (
00215                         Pstream::nonBlocking,
00216                         List<labelPair>(),
00217                         constructSize_,
00218                         subMap_,
00219                         constructMap_,
00220                         fld
00221                     );
00222                 }
00223                 else if (Pstream::defaultCommsType == Pstream::scheduled)
00224                 {
00225                     distribute
00226                     (
00227                         Pstream::scheduled,
00228                         schedule(),
00229                         constructSize_,
00230                         subMap_,
00231                         constructMap_,
00232                         fld
00233                     );
00234                 }
00235                 else
00236                 {
00237                     distribute
00238                     (
00239                         Pstream::blocking,
00240                         List<labelPair>(),
00241                         constructSize_,
00242                         subMap_,
00243                         constructMap_,
00244                         fld
00245                     );
00246                 }
00247             }
00248 
00249             //- Correct for topo change.
00250             void updateMesh(const mapPolyMesh&)
00251             {
00252                 notImplemented
00253                 (
00254                     "mapDistribute::updateMesh(const mapPolyMesh&)"
00255                 );
00256             }
00257 
00258     // Member Operators
00259 
00260         void operator=(const mapDistribute&);
00261 
00262 };
00263 
00264 
00265 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00266 
00267 } // End namespace Foam
00268 
00269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00270 
00271 #ifdef NoRepository
00272 #   include "mapDistributeTemplates.C"
00273 #endif
00274 
00275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00276 
00277 #endif
00278 
00279 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines