1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
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
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/>.
25 The function renumbers the addressing such that the band of the
26 matrix is reduced. The algorithm uses a simple search through the
30 \*---------------------------------------------------------------------------*/
32 #include "bandCompression.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // Constructor from components
38 Foam::labelList Foam::bandCompression(const labelListList& cellCellAddressing)
40 labelList newOrder(cellCellAddressing.size());
42 // the business bit of the renumbering
43 SLList<label> nextCell;
45 labelList visited(cellCellAddressing.size());
48 label cellInOrder = 0;
50 // reset the visited cells list
51 forAll(visited, cellI)
56 // loop over the cells
57 forAll(visited, cellI)
59 // find the first cell that has not been visited yet
60 if (visited[cellI] == 0)
64 // use this cell as a start
65 nextCell.append(currentCell);
67 // loop through the nextCell list. Add the first cell into the
68 // cell order if it has not already been visited and ask for its
69 // neighbours. If the neighbour in question has not been visited,
70 // add it to the end of the nextCell list
72 while (nextCell.size())
74 currentCell = nextCell.removeHead();
76 if (visited[currentCell] == 0)
78 visited[currentCell] = 1;
81 newOrder[cellInOrder] = currentCell;
84 // find if the neighbours have been visited
85 const labelList& neighbours =
86 cellCellAddressing[currentCell];
88 forAll(neighbours, nI)
90 if (visited[neighbours[nI]] == 0)
92 // not visited, add to the list
93 nextCell.append(neighbours[nI]);
105 // ************************************************************************* //