/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration |
\\ / A nd | For copyright notice see file Copyright
\\/ M anispulation |
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see .
Application
renumberMesh
Description
Renumbers the cell list in order to reduce the bandwidth, reading and
renumbering all fields from all the time directories.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "IOobjectList.H"
#include "fvMesh.H"
#include "directTopoChange.H"
#include "ReadFields.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "bandCompression.H"
#include "faceSet.H"
#include "SortableList.H"
#include "decompositionMethod.H"
#include "fvMeshSubset.H"
#include "zeroGradientFvPatchFields.H"
using namespace Foam;
// Calculate band of matrix
label getBand(const labelList& owner, const labelList& neighbour)
{
label band = 0;
forAll(neighbour, faceI)
{
label diff = neighbour[faceI] - owner[faceI];
if (diff > band)
{
band = diff;
}
}
return band;
}
// Return new to old cell numbering
labelList regionBandCompression
(
const fvMesh& mesh,
const labelList& cellToRegion
)
{
Pout<< "Determining cell order:" << endl;
labelList cellOrder(cellToRegion.size());
label nRegions = max(cellToRegion)+1;
labelListList regionToCells(invertOneToMany(nRegions, cellToRegion));
label cellI = 0;
forAll(regionToCells, regionI)
{
Pout<< " region " << regionI << " starts at " << cellI << endl;
// Per region do a reordering.
fvMeshSubset meshSubset
(
IOobject
(
"set",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh
);
meshSubset.setLargeCellSubset(cellToRegion, regionI);
const fvMesh& subMesh = meshSubset.subMesh();
labelList subCellOrder(bandCompression(subMesh.cellCells()));
const labelList& cellMap = meshSubset.cellMap();
forAll(subCellOrder, i)
{
cellOrder[cellI++] = cellMap[subCellOrder[i]];
}
}
Pout<< endl;
return cellOrder;
}
// Determine face order such that inside region faces are sorted
// upper-triangular but inbetween region faces are handled like boundary faces.
labelList regionFaceOrder
(
const primitiveMesh& mesh,
const labelList& cellOrder, // new to old cell
const labelList& cellToRegion // old cell to region
)
{
Pout<< "Determining face order:" << endl;
labelList reverseCellOrder(invert(cellOrder.size(), cellOrder));
labelList oldToNewFace(mesh.nFaces(), -1);
label newFaceI = 0;
label prevRegion = -1;
forAll (cellOrder, newCellI)
{
label oldCellI = cellOrder[newCellI];
if (cellToRegion[oldCellI] != prevRegion)
{
prevRegion = cellToRegion[oldCellI];
Pout<< " region " << prevRegion << " internal faces start at "
<< newFaceI << endl;
}
const cell& cFaces = mesh.cells()[oldCellI];
SortableList