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