diff --git a/src/OpenFOAM/meshes/bandCompression/bandCompression.C b/src/OpenFOAM/meshes/bandCompression/bandCompression.C index 96da4db0dcbdf4512e64a0d806c49a13bf2e2efd..6a74fdf58a45b367fc0f5c73fae8e48bdde55d28 100644 --- a/src/OpenFOAM/meshes/bandCompression/bandCompression.C +++ b/src/OpenFOAM/meshes/bandCompression/bandCompression.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -146,4 +146,129 @@ Foam::labelList Foam::bandCompression(const labelListList& cellCellAddressing) } +Foam::labelList Foam::bandCompression +( + const labelList& cellCells, + const labelList& offsets +) +{ + // Count number of neighbours + labelList numNbrs(offsets.size()-1, 0); + forAll(numNbrs, cellI) + { + label start = offsets[cellI]; + label end = offsets[cellI+1]; + + for (label faceI = start; faceI < end; faceI++) + { + numNbrs[cellI]++; + numNbrs[cellCells[faceI]]++; + } + } + + + labelList newOrder(offsets.size()-1); + + // the business bit of the renumbering + SLList<label> nextCell; + + PackedBoolList visited(offsets.size()-1); + + label cellInOrder = 0; + + + // Work arrays. Kept outside of loop to minimise allocations. + // - neighbour cells + DynamicList<label> nbrs; + // - corresponding weights + DynamicList<label> weights; + + // - ordering + labelList order; + + + while (true) + { + // For a disconnected region find the lowest connected cell. + + label currentCell = -1; + label minWeight = labelMax; + + forAll(visited, cellI) + { + // find the lowest connected cell that has not been visited yet + if (!visited[cellI]) + { + if (numNbrs[cellI] < minWeight) + { + minWeight = numNbrs[cellI]; + currentCell = cellI; + } + } + } + + + if (currentCell == -1) + { + break; + } + + + // Starting from currentCell walk breadth-first + + + // use this cell as a start + nextCell.append(currentCell); + + // loop through the nextCell list. Add the first cell into the + // cell order if it has not already been visited and ask for its + // neighbours. If the neighbour in question has not been visited, + // add it to the end of the nextCell list + + while (nextCell.size()) + { + currentCell = nextCell.removeHead(); + + if (!visited[currentCell]) + { + visited[currentCell] = 1; + + // add into cellOrder + newOrder[cellInOrder] = currentCell; + cellInOrder++; + + // Add in increasing order of connectivity + + // 1. Count neighbours of unvisited neighbours + nbrs.clear(); + weights.clear(); + + label start = offsets[currentCell]; + label end = offsets[currentCell+1]; + + for (label faceI = start; faceI < end; faceI++) + { + label nbr = cellCells[faceI]; + if (!visited[nbr]) + { + // not visited, add to the list + nbrs.append(nbr); + weights.append(numNbrs[nbr]); + } + } + // 2. Sort in ascending order + sortedOrder(weights, order); + // 3. Add in sorted order + forAll(order, i) + { + nextCell.append(nbrs[i]); + } + } + } + } + + return newOrder; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/meshes/bandCompression/bandCompression.H b/src/OpenFOAM/meshes/bandCompression/bandCompression.H index f1506e5dbcdd2a07ef9967722fa952d5657290c9..54e51efd3950e1c207b714b882386c65b5050e72 100644 --- a/src/OpenFOAM/meshes/bandCompression/bandCompression.H +++ b/src/OpenFOAM/meshes/bandCompression/bandCompression.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -51,6 +51,9 @@ namespace Foam // original) labelList bandCompression(const labelListList& addressing); +//- Renumber with addressing in losort form (neighbour + start in neighbour) +labelList bandCompression(const labelList& cellCells, const labelList& offsets); + } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //