![]() |
|
00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2005 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 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: takes (elements of) sublists and appends them into one big 00033 list. 00034 combineOffset: 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 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 00080 SourceFiles 00081 ListListOps.C 00082 00083 \*---------------------------------------------------------------------------*/ 00084 00085 #ifndef ListListOps_H 00086 #define ListListOps_H 00087 00088 #include "labelList.H" 00089 00090 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00091 00092 namespace Foam 00093 { 00094 // 00095 //template <class T> class accessOp; 00096 //template <class T> class offsetOp; 00097 // Dummy access operator for combine() 00098 template <class T> 00099 class accessOp 00100 { 00101 public: 00102 00103 const T& operator()(const T& x) const 00104 { 00105 return x; 00106 } 00107 }; 00108 00109 00110 // Offset operator for combineOffset() 00111 template <class T> 00112 class offsetOp 00113 { 00114 public: 00115 00116 T operator()(const T& x, const label offset) const 00117 { 00118 return x + offset; 00119 } 00120 }; 00121 00122 /*---------------------------------------------------------------------------*\ 00123 Class ListListOps Declaration 00124 \*---------------------------------------------------------------------------*/ 00125 00126 namespace ListListOps 00127 { 00128 00129 //- Combines sublists into one big list 00130 template <class AccessType, class T, class AccessOp> 00131 AccessType combine(const List<T>&, AccessOp aop = accessOp<T>()); 00132 00133 //- Gets sizes of sublists 00134 template <class T, class AccessOp> 00135 labelList subSizes(const List<T>&, AccessOp aop = accessOp<T>()); 00136 00137 //- Like combine but also offsets sublists based on passed sizes 00138 template <class AccessType, class T, class AccessOp, class OffsetOp> 00139 AccessType combineOffset 00140 ( 00141 const List<T>&, 00142 const labelList& sizes, 00143 AccessOp aop, 00144 OffsetOp oop = offsetOp<T>() 00145 ); 00146 }; 00147 00148 00149 00150 00151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00152 00153 } // End namespace Foam 00154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00155 00156 #ifdef NoRepository 00157 # include "ListListOps.C" 00158 #endif 00159 00160 00161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00162 00163 #endif 00164 00165 // ************************************************************************* //