|
|
|
bandCompression.CGo to the documentation of this file.00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software; you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by the 00013 Free Software Foundation; either version 2 of the License, or (at your 00014 option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM; if not, write to the Free Software Foundation, 00023 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 00025 Description 00026 The function renumbers the addressing such that the band of the 00027 matrix is reduced. The algorithm uses a simple search through the 00028 neighbour list 00029 00030 00031 \*---------------------------------------------------------------------------*/ 00032 00033 #include "bandCompression.H" 00034 #include "SLList.H" 00035 00036 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00037 00038 // Constructor from components 00039 Foam::labelList Foam::bandCompression(const labelListList& cellCellAddressing) 00040 { 00041 labelList newOrder(cellCellAddressing.size()); 00042 00043 // the business bit of the renumbering 00044 SLList<label> nextCell; 00045 00046 labelList visited(cellCellAddressing.size()); 00047 00048 label currentCell; 00049 label cellInOrder = 0; 00050 00051 // reset the visited cells list 00052 forAll (visited, cellI) 00053 { 00054 visited[cellI] = 0; 00055 } 00056 00057 // loop over the cells 00058 forAll (visited, cellI) 00059 { 00060 // find the first cell that has not been visited yet 00061 if (visited[cellI] == 0) 00062 { 00063 currentCell = cellI; 00064 00065 // use this cell as a start 00066 nextCell.append(currentCell); 00067 00068 // loop through the nextCell list. Add the first cell into the 00069 // cell order if it has not already been visited and ask for its 00070 // neighbours. If the neighbour in question has not been visited, 00071 // add it to the end of the nextCell list 00072 00073 while (nextCell.size()) 00074 { 00075 currentCell = nextCell.removeHead(); 00076 00077 if (visited[currentCell] == 0) 00078 { 00079 visited[currentCell] = 1; 00080 00081 // add into cellOrder 00082 newOrder[cellInOrder] = currentCell; 00083 cellInOrder++; 00084 00085 // find if the neighbours have been visited 00086 const labelList& neighbours = 00087 cellCellAddressing[currentCell]; 00088 00089 forAll (neighbours, nI) 00090 { 00091 if (visited[neighbours[nI]] == 0) 00092 { 00093 // not visited, add to the list 00094 nextCell.append(neighbours[nI]); 00095 } 00096 } 00097 } 00098 } 00099 } 00100 } 00101 00102 return newOrder; 00103 } 00104 00105 00106 // ************************************************************************* // |