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

ListListOps.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 Namespace
00025     Foam::ListListOps
00026 
00027 Description
00028     Various utility functions to work on Lists of Lists (usually resulting
00029     from 'gather'ing and combining information from individual processors)
00030 
00031     - combine : \n
00032         takes (elements of) sublists and appends them into one big list.
00033     - combineOffset : \n
00034         similar and also adds offset.
00035 
00036     The access of data is through an AccessOp so that data can be 'gather'ed
00037     in one go, minimizing communication, and then picked apart and recombined.
00038 
00039     Example:
00040     @code
00041         // Assuming myContainer defined which holds all the data I want to
00042         // transfer (say a pointField and a faceList). myContainer also defines
00043         // access operators to
00044         // access the individual elements, say myContainerPoints::operator(),
00045         // and myContainerFaces::operator()
00046 
00047         List<myContainer> gatheredData(Pstream::nProcs());
00048         gatheredData[Pstream::myProcNo()] = myContainer(points, faces);
00049 
00050         // Gather data onto master
00051         Pstream::gatherList(gatheredData);
00052 
00053         // Combine
00054         pointField combinedPoints
00055         (
00056             ListListOps::combine<pointField>
00057             (
00058                 gatheredData,
00059                 myContainerPoints()
00060             )
00061         );
00062 
00063         // Combine and renumber (so combinedFaces indexes combinedPoints)
00064 
00065         // Extract sizes of individual lists
00066         labelList sizes
00067         (
00068             ListListOps::subSizes(gatheredData, myContainerPoints())
00069         );
00070 
00071         // Renumber using user-defined operator offsetOp<face>()
00072         faceList combinedFaces
00073         (
00074             ListListOps::combineOffset<faceList>
00075             (
00076                 gatheredData, sizes, myContainerFaces(), offsetOp<face>()
00077             )
00078         );
00079     @endcode
00080 
00081 SourceFiles
00082     ListListOps.C
00083 
00084 \*---------------------------------------------------------------------------*/
00085 
00086 #ifndef ListListOps_H
00087 #define ListListOps_H
00088 
00089 #include <OpenFOAM/labelList.H>
00090 
00091 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00092 
00093 namespace Foam
00094 {
00095 //
00096 //template <class T> class accessOp;
00097 //template <class T> class offsetOp;
00098 // Dummy access operator for combine()
00099 template <class T>
00100 class accessOp
00101 {
00102 public:
00103 
00104     const T& operator()(const T& x) const
00105     {
00106         return x;
00107     }
00108 };
00109 
00110 
00111 // Offset operator for combineOffset()
00112 template <class T>
00113 class offsetOp
00114 {
00115 public:
00116 
00117     T operator()(const T& x, const label offset) const
00118     {
00119         return x + offset;
00120     }
00121 };
00122 
00123 /*---------------------------------------------------------------------------*\
00124                            Class ListListOps Declaration
00125 \*---------------------------------------------------------------------------*/
00126 
00127 namespace ListListOps
00128 {
00129 
00130     //- Combines sublists into one big list
00131     template <class AccessType, class T, class AccessOp>
00132     AccessType combine(const List<T>&, AccessOp aop = accessOp<T>());
00133 
00134     //- Gets sizes of sublists
00135     template <class T, class AccessOp>
00136     labelList subSizes(const List<T>&, AccessOp aop = accessOp<T>());
00137 
00138     //- Like combine but also offsets sublists based on passed sizes
00139     template <class AccessType, class T, class AccessOp, class OffsetOp>
00140     AccessType combineOffset
00141     (
00142         const List<T>&,
00143         const labelList& sizes,
00144         AccessOp aop,
00145         OffsetOp oop = offsetOp<T>()
00146     );
00147 };
00148 
00149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00150 
00151 } // End namespace Foam
00152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00153 
00154 #ifdef NoRepository
00155 #   include <OpenFOAM/ListListOps.C>
00156 #endif
00157 
00158 
00159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00160 
00161 #endif
00162 
00163 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines