Transferred copyright to the OpenFOAM Foundation
[OpenFOAM-2.0.x.git] / src / OpenFOAM / meshes / bandCompression / bandCompression.C
blob5c31a2121d6128cadff0512f4c4a2cb05b0353db
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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 Description
25     The function renumbers the addressing such that the band of the
26     matrix is reduced. The algorithm uses a simple search through the
27     neighbour list
30 \*---------------------------------------------------------------------------*/
32 #include "bandCompression.H"
33 #include "SLList.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());
47     label currentCell;
48     label cellInOrder = 0;
50     // reset the visited cells list
51     forAll(visited, cellI)
52     {
53         visited[cellI] = 0;
54     }
56     // loop over the cells
57     forAll(visited, cellI)
58     {
59         // find the first cell that has not been visited yet
60         if (visited[cellI] == 0)
61         {
62             currentCell = cellI;
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())
73             {
74                 currentCell = nextCell.removeHead();
76                 if (visited[currentCell] == 0)
77                 {
78                     visited[currentCell] = 1;
80                     // add into cellOrder
81                     newOrder[cellInOrder] = currentCell;
82                     cellInOrder++;
84                     // find if the neighbours have been visited
85                     const labelList& neighbours =
86                         cellCellAddressing[currentCell];
88                     forAll(neighbours, nI)
89                     {
90                         if (visited[neighbours[nI]] == 0)
91                         {
92                             // not visited, add to the list
93                             nextCell.append(neighbours[nI]);
94                         }
95                     }
96                 }
97             }
98         }
99     }
101     return newOrder;
105 // ************************************************************************* //