FreeFOAM The Cross-Platform CFD Toolkit
bandCompression.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
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
28 
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "bandCompression.H"
33 #include <OpenFOAM/SLList.H>
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 // Constructor from components
39 {
40  labelList newOrder(cellCellAddressing.size());
41 
42  // the business bit of the renumbering
43  SLList<label> nextCell;
44 
45  labelList visited(cellCellAddressing.size());
46 
47  label currentCell;
48  label cellInOrder = 0;
49 
50  // reset the visited cells list
51  forAll (visited, cellI)
52  {
53  visited[cellI] = 0;
54  }
55 
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;
63 
64  // use this cell as a start
65  nextCell.append(currentCell);
66 
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
71 
72  while (nextCell.size())
73  {
74  currentCell = nextCell.removeHead();
75 
76  if (visited[currentCell] == 0)
77  {
78  visited[currentCell] = 1;
79 
80  // add into cellOrder
81  newOrder[cellInOrder] = currentCell;
82  cellInOrder++;
83 
84  // find if the neighbours have been visited
85  const labelList& neighbours =
86  cellCellAddressing[currentCell];
87 
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  }
100 
101  return newOrder;
102 }
103 
104 
105 // ************************ vim: set sw=4 sts=4 et: ************************ //