CompactListList.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-2022 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 "CompactListList.H"
27 
28 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
29 
30 template<class T>
31 template<class Container>
33 :
35  offsets_(ll.size() + 1),
36  m_()
37 {
38  label sumSize = 0;
39  offsets_[0] = 0;
40  forAll(ll, i)
41  {
42  sumSize += ll[i].size();
43  offsets_[i+1] = sumSize;
44  }
45 
46  m_.setSize(sumSize);
47 
48  label k = 0;
49  forAll(ll, i)
50  {
51  forAll(ll[i], j)
52  {
53  m_[k++] = ll[i][j];
54  }
55  }
56 
58 }
59 
60 
61 template<class T>
63 (
64  const labelUList& rowSizes,
65  const T& t
66 )
67 :
69  offsets_(rowSizes.size() + 1),
70  m_()
71 {
72  label sumSize = 0;
73  offsets_[0] = 0;
74  forAll(rowSizes, i)
75  {
76  sumSize += rowSizes[i];
77  offsets_[i+1] = sumSize;
78  }
79 
80  m_.setSize(sumSize, t);
81 
83 }
84 
85 
86 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
87 
88 template<class T>
90 {
91  if (mRows == 0)
92  {
93  clear();
94  }
95  if (mRows < this->size())
96  {
97  offsets_.setSize(mRows + 1);
98  m_.setSize(offsets_[mRows]);
99 
101  }
102  else if (mRows > this->size())
103  {
105  << "Cannot be used to extend the list from " << offsets_.size()
106  << " to " << mRows << nl
107  << " Please use one of the other setSize member functions"
108  << abort(FatalError);
109  }
110 }
111 
112 
113 template<class T>
115 (
116  const label mRows,
117  const label nData
118 )
119 {
120  offsets_.setSize(mRows + 1);
121  m_.setSize(nData);
122 
124 }
125 
126 
127 template<class T>
129 (
130  const label mRows,
131  const label nData,
132  const T& t
133 )
134 {
135  offsets_.setSize(mRows + 1);
136  m_.setSize(nData, t);
137 
139 }
140 
141 
142 template<class T>
144 {
145  offsets_.setSize(rowSizes.size() + 1);
146 
147  label sumSize = 0;
148  offsets_[0] = 0;
149  forAll(rowSizes, i)
150  {
151  sumSize += rowSizes[i];
152  offsets_[i+1] = sumSize;
153  }
154 
155  m_.setSize(sumSize);
156 
158 }
159 
160 
161 template<class T>
163 {
164  offsets_ = List<label>(label(1), label(0));
165  m_.clear();
166 
168 }
169 
170 
171 template<class T>
173 {
174  offsets_.transfer(a.offsets_);
175  m_.transfer(a.m_);
176 
178 
179  a.clear();
180 }
181 
182 
183 // * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
184 
185 #include "CompactListListIO.C"
186 
187 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
label size() const
Return the primary size, i.e. the number of rows.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void shallowCopy(const UCompactListList< T > &)
Copy the ULists, but not the underlying data.
label k
Boltzmann constant.
void clear()
Clear the CompactListList, i.e. set sizes to zero.
void transfer(CompactListList< T > &)
Transfer the contents of the argument CompactListList.
CompactListList()
Null constructor.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
A packed storage unstructured matrix of objects of type <T> using an offset table for access...
void setSize(const label mRows)
Reset size of CompactListList.
static const char nl
Definition: Ostream.H:260
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void setSize(const label)
Reset size of List.
Definition: List.C:281
const volScalarField & T
Unallocated base class of CompactListList.
Definition: fvMesh.H:83
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342