1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Various utility functions to work on Lists of Lists (usually resulting
30 from 'gather'ing and combining information from individual processors)
33 takes (elements of) sublists and appends them into one big list.
35 similar and also adds offset.
37 The access of data is through an AccessOp so that data can be 'gather'ed
38 in one go, minimizing communication, and then picked apart and recombined.
42 // Assuming myContainer defined which holds all the data I want to
43 // transfer (say a pointField and a faceList). myContainer also defines
44 // access operators to
45 // access the individual elements, say myContainerPoints::operator(),
46 // and myContainerFaces::operator()
48 List<myContainer> gatheredData(Pstream::nProcs());
49 gatheredData[Pstream::myProcNo()] = myContainer(points, faces);
51 // Gather data onto master
52 Pstream::gatherList(gatheredData);
55 pointField combinedPoints
57 ListListOps::combine<pointField>
64 // Combine and renumber (so combinedFaces indexes combinedPoints)
66 // Extract sizes of individual lists
69 ListListOps::subSizes(gatheredData, myContainerPoints())
72 // Renumber using user-defined operator offsetOp<face>()
73 faceList combinedFaces
75 ListListOps::combineOffset<faceList>
77 gatheredData, sizes, myContainerFaces(), offsetOp<face>()
85 \*---------------------------------------------------------------------------*/
90 #include "labelList.H"
92 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
97 //template <class T> class accessOp;
98 //template <class T> class offsetOp;
99 // Dummy access operator for combine()
105 const T& operator()(const T& x) const
112 // Offset operator for combineOffset()
118 T operator()(const T& x, const label offset) const
124 /*---------------------------------------------------------------------------*\
125 Class ListListOps Declaration
126 \*---------------------------------------------------------------------------*/
128 namespace ListListOps
131 //- Combines sublists into one big list
132 template <class AccessType, class T, class AccessOp>
133 AccessType combine(const List<T>&, AccessOp aop = accessOp<T>());
135 //- Gets sizes of sublists
136 template <class T, class AccessOp>
137 labelList subSizes(const List<T>&, AccessOp aop = accessOp<T>());
139 //- Like combine but also offsets sublists based on passed sizes
140 template <class AccessType, class T, class AccessOp, class OffsetOp>
141 AccessType combineOffset
144 const labelList& sizes,
146 OffsetOp oop = offsetOp<T>()
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 } // End namespace Foam
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 # include "ListListOps.C"
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 // ************************************************************************* //