initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / containers / Lists / ListListOps / ListListOps.H
blob130d4493db5d18f2e902d02081b0920da66e889a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Namespace
26     Foam::ListListOps
28 Description
29     Various utility functions to work on Lists of Lists (usually resulting
30     from 'gather'ing and combining information from individual processors)
32     - combine : \n
33         takes (elements of) sublists and appends them into one big list.
34     - combineOffset : \n
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.
40     Example:
41     @code
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);
54         // Combine
55         pointField combinedPoints
56         (
57             ListListOps::combine<pointField>
58             (
59                 gatheredData,
60                 myContainerPoints()
61             )
62         );
64         // Combine and renumber (so combinedFaces indexes combinedPoints)
66         // Extract sizes of individual lists
67         labelList sizes
68         (
69             ListListOps::subSizes(gatheredData, myContainerPoints())
70         );
72         // Renumber using user-defined operator offsetOp<face>()
73         faceList combinedFaces
74         (
75             ListListOps::combineOffset<faceList>
76             (
77                 gatheredData, sizes, myContainerFaces(), offsetOp<face>()
78             )
79         );
80     @endcode
82 SourceFiles
83     ListListOps.C
85 \*---------------------------------------------------------------------------*/
87 #ifndef ListListOps_H
88 #define ListListOps_H
90 #include "labelList.H"
92 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
94 namespace Foam
97 //template <class T> class accessOp;
98 //template <class T> class offsetOp;
99 // Dummy access operator for combine()
100 template <class T>
101 class accessOp
103 public:
105     const T& operator()(const T& x) const
106     {
107         return x;
108     }
112 // Offset operator for combineOffset()
113 template <class T>
114 class offsetOp
116 public:
118     T operator()(const T& x, const label offset) const
119     {
120         return x + offset;
121     }
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
142     (
143         const List<T>&,
144         const labelList& sizes,
145         AccessOp aop,
146         OffsetOp oop = offsetOp<T>()
147     );
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 } // End namespace Foam
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 #ifdef NoRepository
156 #   include "ListListOps.C"
157 #endif
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 #endif
164 // ************************************************************************* //