1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
7 -------------------------------------------------------------------------------
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Compressed row addressing class
32 Hrvoje Jasak, Wikki Ltd. All rights reserved
34 \*----------------------------------------------------------------------------*/
36 #include "crAddressing.H"
38 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 void Foam::crAddressing::setRowCount(const labelList& count)
42 if (count.size() != nRows_)
44 FatalErrorIn("void crAddressing::setRowCount(const labelList& count)")
45 << "Incorrect size of count: nRows =" << nRows_
46 << " count = " << count.size()
56 row_[i + 1] = row_[i] + count[i];
59 // Resize and clear column array
60 col_.setSize(row_[nRows_]);
65 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
67 // Construct from given size
68 Foam::crAddressing::crAddressing
72 const labelList& count
85 // Construct from components
86 Foam::crAddressing::crAddressing
103 Foam::crAddressing::crAddressing(const crAddressing& a)
113 // Construct from Istream
114 Foam::crAddressing::crAddressing(Istream& is)
117 nRows_(readLabel(is)),
118 nCols_(readLabel(is)),
124 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
126 Foam::tmp<Foam::crAddressing> Foam::crAddressing::T() const
128 const labelList& myRow = row();
129 const labelList& myCol = col();
131 labelList trCount(nCols(), 0);
133 // Count number of entries in a row
134 for (label i = 0; i < nRows(); i++)
136 for (label ip = myRow[i]; ip < myRow[i + 1]; ip++)
138 trCount[myCol[ip]]++;
142 // Create transpose addressing
143 tmp<crAddressing> ttranspose(new crAddressing(nCols(), nRows(), trCount));
144 crAddressing& transpose = ttranspose();
147 const labelList& trRow = transpose.row();
148 labelList& trCol = transpose.col();
151 // Reset count to use as counter
156 for (label i = 0; i < nRows(); i++)
158 for (label ip = myRow[i]; ip < myRow[i + 1]; ip++)
162 trCol[trRow[j] + trCount[j]] = i;
172 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
174 void Foam::crAddressing::operator=(const crAddressing& rhs)
176 // Check for assignment to self
179 FatalErrorIn("Foam::crAddressing::operator=(const Foam::crAddressing&)")
180 << "Attempted assignment to self"
181 << abort(FatalError);
191 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
193 Foam::Ostream& Foam::operator<<(Ostream& os, const crAddressing& a)
195 os << a.nRows_ << tab << a.nCols_ << nl
203 // ************************************************************************* //