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-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 "CompactListList.H"
27 
28 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
29 
30 template<class T>
31 template<class T2>
33 :
35  offsets_(),
36  m_()
37 {
39 
41 }
42 
43 
44 template<class T>
45 template<class T2>
47 :
49  offsets_(),
50  m_()
51 {
53 
55 }
56 
57 
58 template<class T>
60 (
61  const labelUList& rowSizes,
62  const T& t
63 )
64 :
66  offsets_(rowSizes.size() + 1),
67  m_()
68 {
69  label sumSize = 0;
70  offsets_[0] = 0;
71  forAll(rowSizes, i)
72  {
73  sumSize += rowSizes[i];
74  offsets_[i+1] = sumSize;
75  }
76 
77  m_.setSize(sumSize, t);
78 
80 }
81 
82 
83 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
84 
85 template<class T>
87 {
88  if (mRows == 0)
89  {
90  clear();
91  }
92  if (mRows < this->size())
93  {
94  offsets_.setSize(mRows + 1);
95  m_.setSize(offsets_[mRows]);
96 
98  }
99  else if (mRows > this->size())
100  {
102  << "Cannot be used to extend the list from " << offsets_.size()
103  << " to " << mRows << nl
104  << " Please use one of the other setSize member functions"
105  << abort(FatalError);
106  }
107 }
108 
109 
110 template<class T>
112 (
113  const label mRows,
114  const label nData
115 )
116 {
117  offsets_.setSize(mRows + 1);
118  m_.setSize(nData);
119 
121 }
122 
123 
124 template<class T>
126 (
127  const label mRows,
128  const label nData,
129  const T& t
130 )
131 {
132  offsets_.setSize(mRows + 1);
133  m_.setSize(nData, t);
134 
136 }
137 
138 
139 template<class T>
141 {
142  offsets_.setSize(rowSizes.size() + 1);
143 
144  label sumSize = 0;
145  offsets_[0] = 0;
146  forAll(rowSizes, i)
147  {
148  sumSize += rowSizes[i];
149  offsets_[i+1] = sumSize;
150  }
151 
152  m_.setSize(sumSize);
153 
155 }
156 
157 
158 template<class T>
159 template<class T2>
161 {
162  UCompactListList<T>::setSizeToListList(offsets_, m_, ll);
163 
165 }
166 
167 
168 template<class T>
169 template<class T2>
171 {
172  UCompactListList<T>::setSizeToListList(offsets_, m_, ll);
173 
175 }
176 
177 
178 template<class T>
180 {
181  offsets_ = List<label>(label(1), label(0));
182  m_.clear();
183 
185 }
186 
187 
188 template<class T>
190 {
191  offsets_.transfer(a.offsets_);
192  m_.transfer(a.m_);
193 
195 
196  a.clear();
197 }
198 
199 
200 // * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
201 
202 #include "CompactListListIO.C"
203 
204 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A packed storage unstructured matrix of objects of type <T> using an offset table for access.
CompactListList()
Null constructor.
void transfer(CompactListList< T > &)
Transfer the contents of the argument CompactListList.
void clear()
Clear the CompactListList, i.e. set sizes to zero.
void setSize(const label mRows)
Reset size of CompactListList.
Unallocated base class of CompactListList.
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.
void shallowCopy(const UCompactListList< T > &)
Copy the ULists, but not the underlying data.
A List with indirect addressing.
Definition: UIndirectList.H:60
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
tUEqn clear()
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
errorManip< error > abort(error &err)
Definition: errorManip.H:131
error FatalError
static const char nl
Definition: Ostream.H:260
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)