ListListOps.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Namespace
28  Foam::ListListOps
29 
30 Description
31  Various utility functions to work on Lists of Lists (usually resulting
32  from 'gather'ing and combining information from individual processors)
33 
34  - combine : \n
35  takes (elements of) sublists and appends them into one big list.
36  - combineOffset : \n
37  similar and also adds offset.
38 
39  The access of data is through an AccessOp so that data can be 'gather'ed
40  in one go, minimizing communication, and then picked apart and recombined.
41 
42  Example:
43  \code
44  // Assuming myContainer defined which holds all the data I want to
45  // transfer (say a pointField and a faceList). myContainer also defines
46  // access operators to
47  // access the individual elements, say myContainerPoints::operator(),
48  // and myContainerFaces::operator()
49 
50  List<myContainer> gatheredData(Pstream::nProcs());
51  gatheredData[Pstream::myProcNo()] = myContainer(points, faces);
52 
53  // Gather data onto master
54  Pstream::gatherList(gatheredData);
55 
56  // Combine
57  pointField combinedPoints
58  (
59  ListListOps::combine<pointField>
60  (
61  gatheredData,
62  myContainerPoints()
63  )
64  );
65 
66  // Combine and renumber (so combinedFaces indexes combinedPoints)
67 
68  // Extract sizes of individual lists
69  labelList sizes
70  (
71  ListListOps::subSizes(gatheredData, myContainerPoints())
72  );
73 
74  // Renumber using user-defined operator offsetOp<face>()
75  faceList combinedFaces
76  (
77  ListListOps::combineOffset<faceList>
78  (
79  gatheredData, sizes, myContainerFaces(), offsetOp<face>()
80  )
81  );
82  \endcode
83 
84 SourceFiles
85  ListListOps.C
86 
87 \*---------------------------------------------------------------------------*/
88 
89 #ifndef ListListOps_H
90 #define ListListOps_H
91 
92 #include "labelList.H"
93 
94 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
95 
96 namespace Foam
97 {
98 
99 //- Offset operator for ListListOps::combineOffset()
100 template<class T>
101 struct offsetOp
102 {
103  T operator()(const T& x, const label offset) const
104  {
105  return x + offset;
106  }
107 };
108 
109 
110 /*---------------------------------------------------------------------------*\
111  Namespace ListListOps Declaration
112 \*---------------------------------------------------------------------------*/
113 
114 namespace ListListOps
115 {
116  //- Return the sizes of the sub-lists
117  template<class T, class AccessOp>
118  labelList subSizes(const UList<T>& lists, AccessOp aop = accessOp<T>());
119 
120  //- The total size of all sub-lists
121  template<class T, class AccessOp>
122  label sumSizes(const UList<T>& lists, AccessOp aop = accessOp<T>());
123 
124  //- Combines sub-lists into a single list
125  template<class AccessType, class T, class AccessOp>
126  AccessType combine(const UList<T>& lists, AccessOp aop = accessOp<T>());
127 
128  //- Like combine but also offsets sublists based on passed sizes
129  template<class AccessType, class T, class AccessOp, class OffsetOp>
130  AccessType combineOffset
131  (
132  const UList<T>& lists,
133  const labelUList& offsets,
134  AccessOp aop,
135  OffsetOp oop = offsetOp<T>()
136  );
137 
138 } // End namespace ListListOps
139 
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 
142 } // End namespace Foam
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 #ifdef NoRepository
147  #include "ListListOps.C"
148 #endif
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 #endif
153 
154 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::ListListOps::combineOffset
AccessType combineOffset(const UList< T > &lists, const labelUList &offsets, AccessOp aop, OffsetOp oop=offsetOp< T >())
Like combine but also offsets sublists based on passed sizes.
Definition: ListListOps.C:99
Foam::ListListOps::subSizes
labelList subSizes(const IndirectListBase< T, Addr > &lists, AccessOp aop)
Return the sizes of the sub-lists.
Definition: ensightOutput.H:67
labelList.H
Foam::offsetOp::operator()
T operator()(const T &x, const label offset) const
Definition: ListListOps.H:103
Foam::ListListOps::combine
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:69
Foam::ListListOps::sumSizes
label sumSizes(const UList< T > &lists, AccessOp aop=accessOp< T >())
The total size of all sub-lists.
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::offsetOp
Offset operator for ListListOps::combineOffset()
Definition: ListListOps.H:101
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
ListListOps.C
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:85