1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Compressed row addressing class
31 Hrvoje Jasak, Wikki Ltd. All rights reserved
33 \*---------------------------------------------------------------------------*/
35 #include "crAddressing.H"
37 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 void Foam::crAddressing::setRowCount(const labelList& count)
41 if (count.size() != nRows_)
43 FatalErrorIn("void crAddressing::setRowCount(const labelList& count)")
44 << "Incorrect size of count: nRows =" << nRows_
45 << " count = " << count.size()
55 row_[i + 1] = row_[i] + count[i];
58 // Resize and clear column array
59 col_.setSize(row_[nRows_]);
64 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
66 // Construct from given size
67 Foam::crAddressing::crAddressing
71 const labelList& count
84 // Construct from components
85 Foam::crAddressing::crAddressing
102 Foam::crAddressing::crAddressing(const crAddressing& a)
112 // Construct from Istream
113 Foam::crAddressing::crAddressing(Istream& is)
116 nRows_(readLabel(is)),
117 nCols_(readLabel(is)),
123 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125 Foam::tmp<Foam::crAddressing> Foam::crAddressing::T() const
127 const labelList& myRow = row();
128 const labelList& myCol = col();
130 labelList trCount(nCols(), 0);
132 // Count number of entries in a row
133 for (label i = 0; i < nRows(); i++)
135 for (label ip = myRow[i]; ip < myRow[i + 1]; ip++)
137 trCount[myCol[ip]]++;
141 // Create transpose addressing
142 tmp<crAddressing> ttranspose(new crAddressing(nCols(), nRows(), trCount));
143 crAddressing& transpose = ttranspose();
146 const labelList& trRow = transpose.row();
147 labelList& trCol = transpose.col();
150 // Reset count to use as counter
155 for (label i = 0; i < nRows(); i++)
157 for (label ip = myRow[i]; ip < myRow[i + 1]; ip++)
161 trCol[trRow[j] + trCount[j]] = i;
171 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
173 void Foam::crAddressing::operator=(const crAddressing& rhs)
175 // Check for assignment to self
180 "Foam::crAddressing::operator=(const Foam::crAddressing&)"
181 ) << "Attempted assignment to self"
182 << abort(FatalError);
192 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
194 Foam::Ostream& Foam::operator<<(Ostream& os, const crAddressing& a)
196 os << a.nRows_ << tab << a.nCols_ << nl
204 // ************************************************************************* //