Correction to the compilation of mesquite-2.1.2. Bug fix contributed by Philippose...
[OpenFOAM-1.6-ext.git] / src / lduSolvers / crMatrix / crAddressing.C
blob73f1060abdb0d5f6e1d27e0ad640204f9731e6f2
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-6 H. Jasak All rights reserved
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 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
19     for more details.
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
25 Class
26     crAddressing
28 Description
29     Compressed row addressing class
31 Author
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_)
43     {
44         FatalErrorIn("void crAddressing::setRowCount(const labelList& count)")
45             << "Incorrect size of count: nRows =" << nRows_
46             << " count = " << count.size()
47             << abort(FatalError);
49     }
51     // Accumulate count
52     row_[0] = 0;
54     forAll (count, i)
55     {
56         row_[i + 1] = row_[i] + count[i];
57     }
59     // Resize and clear column array
60     col_.setSize(row_[nRows_]);
61     col_ = 0;
65 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
67 // Construct from given size
68 Foam::crAddressing::crAddressing
70     const label nRows,
71     const label nCols,
72     const labelList& count
75     refCount(),
76     nRows_(nRows),
77     nCols_(nCols),
78     row_(nRows + 1),
79     col_(0)
81     setRowCount(count);
85 // Construct from components
86 Foam::crAddressing::crAddressing
88     const label nRows,
89     const label nCols,
90     const labelList& row,
91     const labelList& col
94     refCount(),
95     nRows_(nRows),
96     nCols_(nCols),
97     row_(row),
98     col_(col)
102 // Construct as copy
103 Foam::crAddressing::crAddressing(const crAddressing& a)
105     refCount(),
106     nRows_(a.nRows_),
107     nCols_(a.nCols_),
108     row_(a.row_),
109     col_(a.col_)
113 // Construct from Istream
114 Foam::crAddressing::crAddressing(Istream& is)
116     refCount(),
117     nRows_(readLabel(is)),
118     nCols_(readLabel(is)),
119     row_(is),
120     col_(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++)
135     {
136         for (label ip = myRow[i]; ip < myRow[i + 1]; ip++)
137         {
138             trCount[myCol[ip]]++;
139         }
140     }
142     // Create transpose addressing
143     tmp<crAddressing> ttranspose(new crAddressing(nCols(), nRows(), trCount));
144     crAddressing& transpose = ttranspose();
146     // Set coefficients
147     const labelList& trRow = transpose.row();
148     labelList& trCol = transpose.col();
149     trCol = 0;
151     // Reset count to use as counter
152     trCount = 0;
154     label j;
156     for (label i = 0; i < nRows(); i++)
157     {
158         for (label ip = myRow[i]; ip < myRow[i + 1]; ip++)
159         {
160             j = myCol[ip];
162             trCol[trRow[j] + trCount[j]] = i;
164             trCount[j]++;
165         }
166     }
168     return ttranspose;
172 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
174 void Foam::crAddressing::operator=(const crAddressing& rhs)
176     // Check for assignment to self
177     if (this == &rhs)
178     {
179         FatalErrorIn("Foam::crAddressing::operator=(const Foam::crAddressing&)")
180             << "Attempted assignment to self"
181             << abort(FatalError);
182     }
184     nRows_ = rhs.nRows_;
185     nCols_ = rhs.nCols_;
186     row_ = rhs.row_;
187     col_ = rhs.col_;
191 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
193 Foam::Ostream& Foam::operator<<(Ostream& os, const crAddressing& a)
195     os  << a.nRows_ << tab << a.nCols_ << nl
196         << a.row_ << nl
197         << a.col_ << endl;
199     return os;
203 // ************************************************************************* //