UCompactListList.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "UCompactListList.H"
27 
28 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
29 
30 template<class T>
31 template<class ListType, class ListListType>
33 (
34  ListType& offsets,
35  ListType& m,
36  const ListListType& ll
37 )
38 {
39  offsets.setSize(ll.size() + 1);
40 
41  label sumSize = 0;
42  offsets[0] = 0;
43  forAll(ll, i)
44  {
45  sumSize += ll[i].size();
46  offsets[i+1] = sumSize;
47  }
48 
49  m.setSize(sumSize);
50 }
51 
52 
53 template<class T>
54 template<class ListType, class ListListType>
56 (
57  ListType& offsets,
58  ListType& m,
59  const ListListType& ll
60 )
61 {
62  setSizeToListList(offsets, m, ll);
63 
64  label k = 0;
65  forAll(ll, i)
66  {
67  forAll(ll[i], j)
68  {
69  m[k++] = ll[i][j];
70  }
71  }
72 }
73 
74 
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 
77 template<class T>
79 {
80  labelList rowSizes(size());
81 
82  if (rowSizes.size() > 0)
83  {
84  forAll(rowSizes, i)
85  {
86  rowSizes[i] = offsets_[i+1] - offsets_[i];
87  }
88  }
89  return rowSizes;
90 }
91 
92 
93 template<class T>
94 template<class Container>
96 {
97  List<Container> ll(size());
98 
99  forAll(ll, i)
100  {
101  ll[i] = Container(operator[](i));
102  }
103 
104  return ll;
105 }
106 
107 
108 // * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
109 
110 #include "UCompactListListIO.C"
111 
112 // ************************************************************************* //
label k
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
List< Container > list() const
Convert to List<Container>
static void setSizeToListList(ListType &offsets, ListType &m, const ListListType &ll)
Set the sizes to match that of the given list-list.
static void setSizeAndValuesToListList(ListType &offsets, ListType &m, const ListListType &ll)
Set the sizes and values to match that of the given list-list.
labelList sizes() const
Return sizes (to be used e.g. for construction)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59