CompactListList.C
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) 2019-2021 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 \*---------------------------------------------------------------------------*/
28 
29 #include "CompactListList.H"
30 
31 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
32 
33 template<class T, class Container>
35 :
36  size_(ll.size()),
37  offsets_(ll.size()+1)
38 {
39  label sumSize = 0;
40  offsets_[0] = 0;
41  forAll(ll, i)
42  {
43  sumSize += ll[i].size();
44  offsets_[i+1] = sumSize;
45  }
46 
47  m_.setSize(sumSize);
48 
49  label k = 0;
50  forAll(ll, i)
51  {
52  const Container& lli = ll[i];
53 
54  forAll(lli, j)
55  {
56  m_[k++] = lli[j];
57  }
58  }
59 }
60 
61 
62 template<class T, class Container>
64 (
65  const labelUList& rowSizes
66 )
67 :
68  size_(rowSizes.size()),
69  offsets_(rowSizes.size()+1)
70 {
71  label sumSize = 0;
72  offsets_[0] = 0;
73  forAll(rowSizes, i)
74  {
75  sumSize += rowSizes[i];
76  offsets_[i+1] = sumSize;
77  }
78 
79  m_.setSize(sumSize);
80 }
81 
82 
83 template<class T, class Container>
85 (
86  const labelUList& rowSizes,
87  const T& val
88 )
89 :
90  size_(rowSizes.size()),
91  offsets_(rowSizes.size()+1)
92 {
93  label sumSize = 0;
94  offsets_[0] = 0;
95  forAll(rowSizes, i)
96  {
97  sumSize += rowSizes[i];
98  offsets_[i+1] = sumSize;
99  }
100 
101  m_.setSize(sumSize, val);
102 }
103 
104 
105 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
106 
107 template<class T, class Container>
109 {
110  if (mRows == 0)
111  {
112  clear();
113  }
114  if (mRows < size())
115  {
116  size_ = mRows;
117  offsets_.setSize(mRows+1);
118  m_.setSize(offsets_[mRows]);
119  }
120  else if (mRows > size())
121  {
123  << "Cannot be used to extend the list from " << offsets_.size()
124  << " to " << mRows << nl
125  << " Please use one of the other setSize member functions"
126  << abort(FatalError);
127  }
128 }
129 
130 
131 template<class T, class Container>
133 (
134  const label mRows,
135  const label nData
136 )
137 {
138  size_ = mRows;
139  offsets_.setSize(mRows+1);
140  m_.setSize(nData);
141 }
142 
143 
144 template<class T, class Container>
146 (
147  const label mRows,
148  const label nData,
149  const T& t
150 )
151 {
152  size_ = mRows;
153  offsets_.setSize(mRows+1);
154  m_.setSize(nData, t);
155 }
156 
157 
158 template<class T, class Container>
160 {
161  size_ = rowSizes.size();
162  offsets_.setSize(rowSizes.size()+1);
163 
164  label sumSize = 0;
165  offsets_[0] = 0;
166  forAll(rowSizes, i)
167  {
168  sumSize += rowSizes[i];
169  offsets_[i+1] = sumSize;
170  }
171 
172  m_.setSize(sumSize);
173 }
174 
175 
176 template<class T, class Container>
178 {
179  labelList rowSizes(size());
180 
181  if (rowSizes.size() > 0)
182  {
183  forAll(rowSizes, i)
184  {
185  rowSizes[i] = offsets_[i+1] - offsets_[i];
186  }
187  }
188  return rowSizes;
189 }
190 
191 
192 template<class T, class Container>
194 {
195  size_ = 0;
196  offsets_.clear();
197  m_.clear();
198 }
199 
200 
201 template<class T, class Container>
203 (
205 )
206 {
207  if (this == &other)
208  {
209  return; // Self-swap is a no-op
210  }
211 
212  std::swap(size_, other.size_);
213  offsets_.swap(other.offsets_);
214  m_.swap(other.m_);
215 }
216 
217 
218 template<class T, class Container>
220 (
222 )
223 {
224  if (this == &list)
225  {
226  return; // Self-assignment is a no-op
227  }
228 
229  this->clear();
230  this->swap(list);
231 }
232 
233 
234 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
235 
236 template<class T, class Container>
238 const
239 {
240  List<Container> ll(size());
241 
242  forAll(ll, i)
243  {
244  ll[i] = Container(operator[](i));
245  }
246 
247  return ll;
248 }
249 
250 
251 // ************************************************************************* //
Foam::CompactListList::operator()
List< Container > operator()() const
Return as List<Container>
Definition: CompactListList.C:237
Foam::CompactListList::transfer
void transfer(CompactListList< T, Container > &list)
Transfer contents into this and annul the argument.
Definition: CompactListList.C:220
Foam::CompactListList
A packed storage unstructured matrix of objects of type <T> using an offset table for access.
Definition: CompactListList.H:63
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::CompactListList::setSize
void setSize(const label mRows)
Reset size of CompactListList.
Definition: CompactListList.C:108
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::CompactListList::clear
void clear()
Clear the CompactListList, i.e. set sizes to zero.
Definition: CompactListList.C:193
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
clear
patchWriters clear()
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::CompactListList::sizes
labelList sizes() const
Return sizes (to be used e.g. for construction)
Definition: CompactListList.C:177
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::UList< label >
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::CompactListList::CompactListList
CompactListList()
Default construct.
Definition: CompactListListI.H:35
Foam::CompactListList::swap
void swap(CompactListList< T, Container > &other)
Swap contents.
Definition: CompactListList.C:203
CompactListList.H
Foam::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114