1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Various utility functions to work on Lists of Lists (usually resulting
29 from 'gather'ing and combining information from individual processors)
32 takes (elements of) sublists and appends them into one big list.
34 similar and also adds offset.
36 The access of data is through an AccessOp so that data can be 'gather'ed
37 in one go, minimizing communication, and then picked apart and recombined.
41 // Assuming myContainer defined which holds all the data I want to
42 // transfer (say a pointField and a faceList). myContainer also defines
43 // access operators to
44 // access the individual elements, say myContainerPoints::operator(),
45 // and myContainerFaces::operator()
47 List<myContainer> gatheredData(Pstream::nProcs());
48 gatheredData[Pstream::myProcNo()] = myContainer(points, faces);
50 // Gather data onto master
51 Pstream::gatherList(gatheredData);
54 pointField combinedPoints
56 ListListOps::combine<pointField>
63 // Combine and renumber (so combinedFaces indexes combinedPoints)
65 // Extract sizes of individual lists
68 ListListOps::subSizes(gatheredData, myContainerPoints())
71 // Renumber using user-defined operator offsetOp<face>()
72 faceList combinedFaces
74 ListListOps::combineOffset<faceList>
76 gatheredData, sizes, myContainerFaces(), offsetOp<face>()
84 \*---------------------------------------------------------------------------*/
89 #include "labelList.H"
91 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
96 //template <class T> class accessOp;
97 //template <class T> class offsetOp;
98 // Dummy access operator for combine()
104 const T& operator()(const T& x) const
111 // Offset operator for combineOffset()
117 T operator()(const T& x, const label offset) const
123 /*---------------------------------------------------------------------------*\
124 Class ListListOps Declaration
125 \*---------------------------------------------------------------------------*/
127 namespace ListListOps
130 //- Combines sublists into one big list
131 template <class AccessType, class T, class AccessOp>
132 AccessType combine(const List<T>&, AccessOp aop = accessOp<T>());
134 //- Gets sizes of sublists
135 template <class T, class AccessOp>
136 labelList subSizes(const List<T>&, AccessOp aop = accessOp<T>());
138 //- Like combine but also offsets sublists based on passed sizes
139 template <class AccessType, class T, class AccessOp, class OffsetOp>
140 AccessType combineOffset
143 const labelList& sizes,
145 OffsetOp oop = offsetOp<T>()
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 } // End namespace Foam
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 # include "ListListOps.C"
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 // ************************************************************************* //