FIX: Update foamPackSource for new SF upload scheme
[freefoam.git] / src / dynamicMesh / fvMeshDistribute / CompactListList_dev.C
blob48275dccba79fa1cc04d1e09faaa156795c2edef
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "CompactListList_dev.H"
28 // * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * * //
30 template<class T, class Container>
31 Foam::CompactListList_dev<T, Container>::CompactListList_dev(const List<Container>& ll)
33     size_(ll.size()),
34     offsets_(ll.size()+1)
36     label sumSize = 0;
37     offsets_[0] = 0;
38     forAll(ll, i)
39     {
40         sumSize += ll[i].size();
41         offsets_[i+1] = sumSize;
42     }
44     m_.setSize(sumSize);
46     label k = 0;
47     forAll(ll, i)
48     {
49         const Container& lli = ll[i];
51         forAll(lli, j)
52         {
53             m_[k++] = lli[j];
54         }
55     }
59 template<class T, class Container>
60 Foam::CompactListList_dev<T, Container>::CompactListList_dev
62     const UList<label>& rowSizes
65     size_(rowSizes.size()),
66     offsets_(rowSizes.size()+1)
68     label sumSize = 0;
69     offsets_[0] = 0;
70     forAll(rowSizes, i)
71     {
72         sumSize += rowSizes[i];
73         offsets_[i+1] = sumSize;
74     }
76     m_.setSize(sumSize);
80 template<class T, class Container>
81 Foam::CompactListList_dev<T, Container>::CompactListList_dev
83     const UList<label>& rowSizes,
84     const T& t
87     size_(rowSizes.size()),
88     offsets_(rowSizes.size()+1)
90     label sumSize = 0;
91     offsets_[0] = 0;
92     forAll(rowSizes, i)
93     {
94         sumSize += rowSizes[i];
95         offsets_[i+1] = sumSize;
96     }
98     m_.setSize(sumSize, t);
102 template<class T, class Container>
103 Foam::CompactListList_dev<T, Container>::CompactListList_dev
105     const Xfer<CompactListList_dev<T, Container> >& lst
108     transfer(lst());
112 template<class T, class Container>
113 Foam::CompactListList_dev<T, Container>::CompactListList_dev
115     CompactListList_dev<T, Container>& lst,
116     bool reUse
119     size_(lst.size()),
120     offsets_(lst.offsets_, reUse),
121     m_(lst.m_, reUse)
125 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
127 template<class T, class Container>
128 void Foam::CompactListList_dev<T, Container>::setSize(const label nRows)
130     if (nRows == 0)
131     {
132         clear();
133     }
134     if (nRows < size())
135     {
136         size_ = nRows;
137         offsets_.setSize(nRows+1);
138         m_.setSize(offsets_[nRows]);
139     }
140     else if (nRows > size())
141     {
142         FatalErrorIn
143         (
144             "CompactListList_dev<T, Container>::setSize(const label nRows)"
145         )   << "Cannot be used to extend the list from " << offsets_.size()
146             << " to " << nRows << nl
147             << "    Please use one of the other setSize member functions"
148             << abort(FatalError);
149     }
153 template<class T, class Container>
154 void Foam::CompactListList_dev<T, Container>::setSize
156     const label nRows,
157     const label nData
160     size_ = nRows;
161     offsets_.setSize(nRows+1);
162     m_.setSize(nData);
166 template<class T, class Container>
167 void Foam::CompactListList_dev<T, Container>::setSize
169     const label nRows,
170     const label nData,
171     const T& t
174     size_ = nRows;
175     offsets_.setSize(nRows+1);
176     m_.setSize(nData, t);
180 template<class T, class Container>
181 void Foam::CompactListList_dev<T, Container>::setSize(const UList<label>& rowSizes)
183     size_ = rowSizes.size();
184     offsets_.setSize(rowSizes.size()+1);
186     label sumSize = 0;
187     offsets_[0] = 0;
188     forAll(rowSizes, i)
189     {
190         sumSize += rowSizes[i];
191         offsets_[i+1] = sumSize;
192     }
194     m_.setSize(sumSize);
198 template<class T, class Container>
199 Foam::labelList Foam::CompactListList_dev<T, Container>::sizes() const
201     labelList rowSizes(size());
203     if (rowSizes.size() > 0)
204     {
205         forAll(rowSizes, i)
206         {
207             rowSizes[i] = offsets_[i+1] - offsets_[i];
208         }
209     }
210     return rowSizes;
214 template<class T, class Container>
215 void Foam::CompactListList_dev<T, Container>::clear()
217     size_ = 0;
218     offsets_.clear();
219     m_.clear();
223 template<class T, class Container>
224 void Foam::CompactListList_dev<T, Container>::transfer
226     CompactListList_dev<T, Container>& a
229     size_ = a.size_;
230     offsets_.transfer(a.offsets_);
231     m_.transfer(a.m_);
235 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
237 template<class T, class Container>
238 Foam::List<Container> Foam::CompactListList_dev<T, Container>::operator()()
239 const
241     List<Container> ll(size());
243     forAll(ll, i)
244     {
245         ll[i] = Container(operator[](i));
246     }
248     return ll;
252 // * * * * * * * * * * * * * * * *  IOStream operators * * * * * * * * * * * //
254 #include "CompactListList_devIO.C"
256 // ************************ vim: set sw=4 sts=4 et: ************************ //