diff --git a/src/Allwmake b/src/Allwmake index a0622b30f7b53f26a621b327681d3256168dcbe0..97023aa7005de06be5c9a630a4bb33e6c4656a1d 100755 --- a/src/Allwmake +++ b/src/Allwmake @@ -46,7 +46,7 @@ wmake $makeType genericPatchFields # Build the proper scotchDecomp, metisDecomp etc. parallel/Allwmake $* -wmake $makeType renumberMethods +renumber/Allwmake $* wmake $makeType conversion diff --git a/src/renumber/Allwmake b/src/renumber/Allwmake new file mode 100755 index 0000000000000000000000000000000000000000..36c057dafefbf6be9b1cce34f33ecca85fef88a1 --- /dev/null +++ b/src/renumber/Allwmake @@ -0,0 +1,30 @@ +#!/bin/sh +cd ${0%/*} || exit 1 # run from this directory +makeType=${1:-libso} + +## get ZOLTAN_ARCH_PATH +#if settings=`$WM_PROJECT_DIR/bin/foamEtcFile config/zoltan.sh` +#then +# . $settings +# echo "using ZOLTAN_ARCH_PATH=$ZOLTAN_ARCH_PATH" +#else +# echo +# echo "Error: no config/zoltan.sh settings" +# echo +#fi + + +set -x + +wmake $makeType renumberMethods + +#if [ -n "$ZOLTAN_ARCH_PATH" ] +#then +# wmake $makeType zoltanRenumber +#else +# echo +# echo "Skipping zoltanRenumber" +# echo +#fi + +# ----------------------------------------------------------------- end-of-file diff --git a/src/renumber/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.C b/src/renumber/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.C new file mode 100644 index 0000000000000000000000000000000000000000..2732484b36ddcdd7f3c474e21df4e97024be1b88 --- /dev/null +++ b/src/renumber/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.C @@ -0,0 +1,106 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "CuthillMcKeeRenumber.H" +#include "addToRunTimeSelectionTable.H" +#include "bandCompression.H" +#include "decompositionMethod.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(CuthillMcKeeRenumber, 0); + + addToRunTimeSelectionTable + ( + renumberMethod, + CuthillMcKeeRenumber, + dictionary + ); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::CuthillMcKeeRenumber::CuthillMcKeeRenumber(const dictionary& renumberDict) +: + renumberMethod(renumberDict), + reverse_ + ( + renumberDict.found(typeName + "Coeffs") + ? Switch(renumberDict.subDict(typeName + "Coeffs").lookup("reverse")) + : Switch(false) + ) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::labelList Foam::CuthillMcKeeRenumber::renumber +( + const polyMesh& mesh, + const pointField& points +) const +{ + CompactListList<label> cellCells; + decompositionMethod::calcCellCells + ( + mesh, + identity(mesh.nCells()), + mesh.nCells(), + false, // local only + cellCells + ); + + labelList orderedToOld = bandCompression(cellCells()); + + if (reverse_) + { + reverse(orderedToOld); + } + + return invert(orderedToOld.size(), orderedToOld); +} + + +Foam::labelList Foam::CuthillMcKeeRenumber::renumber +( + const labelListList& cellCells, + const pointField& points +) const +{ + labelList orderedToOld = bandCompression(cellCells); + + if (reverse_) + { + reverse(orderedToOld); + } + + return invert(orderedToOld.size(), orderedToOld); +} + + +// ************************************************************************* // diff --git a/src/renumber/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.H b/src/renumber/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.H new file mode 100644 index 0000000000000000000000000000000000000000..a4ec011b4074f07246d30fe7fdbb9d685cbb0e73 --- /dev/null +++ b/src/renumber/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.H @@ -0,0 +1,118 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::CuthillMcKeeRenumber + +Description + Cuthill-McKee renumbering + +SourceFiles + CuthillMcKeeRenumber.C + +\*---------------------------------------------------------------------------*/ + +#ifndef CuthillMcKeeRenumber_H +#define CuthillMcKeeRenumber_H + +#include "renumberMethod.H" +#include "Switch.H" + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class CuthillMcKeeRenumber Declaration +\*---------------------------------------------------------------------------*/ + +class CuthillMcKeeRenumber +: + public renumberMethod +{ + // Private data + + const Switch reverse_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct and assignment + void operator=(const CuthillMcKeeRenumber&); + CuthillMcKeeRenumber(const CuthillMcKeeRenumber&); + + +public: + + //- Runtime type information + TypeName("CuthillMcKee"); + + + // Constructors + + //- Construct given the renumber dictionary + CuthillMcKeeRenumber(const dictionary& renumberDict); + + + //- Destructor + virtual ~CuthillMcKeeRenumber() + {} + + + // Member Functions + + //- Return for every coordinate the wanted processor number. + // We need a polyMesh (to be able to load the file) + virtual labelList renumber(const pointField&) const + { + notImplemented("CuthillMcKeeRenumber::renumber(const pointField&)"); + return labelList(0); + } + + //- Return for every coordinate the wanted processor number. Use the + // mesh connectivity (if needed) + virtual labelList renumber + ( + const polyMesh& mesh, + const pointField& cc + ) const; + + //- Return for every cell the new cell label. + // The connectivity is equal to mesh.cellCells() except + // - the connections are across coupled patches + virtual labelList renumber + ( + const labelListList& cellCells, + const pointField& cc + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/renumber/renumberMethods/Make/files b/src/renumber/renumberMethods/Make/files new file mode 100644 index 0000000000000000000000000000000000000000..c19f1e6b6d6ad9cf9e720e1abcdf0316e2bb1438 --- /dev/null +++ b/src/renumber/renumberMethods/Make/files @@ -0,0 +1,8 @@ +renumberMethod/renumberMethod.C +manualRenumber/manualRenumber.C +CuthillMcKeeRenumber/CuthillMcKeeRenumber.C +randomRenumber/randomRenumber.C +springRenumber/springRenumber.C +boundaryFirstRenumber/boundaryFirstRenumber.C + +LIB = $(FOAM_LIBBIN)/librenumberMethods diff --git a/src/renumber/renumberMethods/Make/options b/src/renumber/renumberMethods/Make/options new file mode 100644 index 0000000000000000000000000000000000000000..03cb68d94683cbf98c9e3f9a0426943c7365dd6b --- /dev/null +++ b/src/renumber/renumberMethods/Make/options @@ -0,0 +1,7 @@ +EXE_INC = \ + -I$(LIB_SRC)/parallel/decompose/decompositionMethods/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude + +LIB_LIBS = \ + -ldecompositionMethods \ + -lmeshTools diff --git a/src/renumber/renumberMethods/boundaryFirstRenumber/boundaryFirstRenumber.C b/src/renumber/renumberMethods/boundaryFirstRenumber/boundaryFirstRenumber.C new file mode 100644 index 0000000000000000000000000000000000000000..293e5ba19b940628ee67aec82087de852ae116fa --- /dev/null +++ b/src/renumber/renumberMethods/boundaryFirstRenumber/boundaryFirstRenumber.C @@ -0,0 +1,201 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "boundaryFirstRenumber.H" +#include "addToRunTimeSelectionTable.H" +#include "bandCompression.H" +#include "decompositionMethod.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(boundaryFirstRenumber, 0); + + addToRunTimeSelectionTable + ( + renumberMethod, + boundaryFirstRenumber, + dictionary + ); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::boundaryFirstRenumber::boundaryFirstRenumber +( + const dictionary& renumberDict +) +: + renumberMethod(renumberDict), + reverse_ + ( + renumberDict.found(typeName + "Coeffs") + ? Switch(renumberDict.subDict(typeName + "Coeffs").lookup("reverse")) + : Switch(true) + ) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::labelList Foam::boundaryFirstRenumber::renumber +( + const polyMesh& mesh, + const pointField& points +) const +{ + const labelList& own = mesh.faceOwner(); + const labelList& nei = mesh.faceNeighbour(); + + // Distance to boundary. Minimum of neighbours. + labelList distance(mesh.nCells(), -1); + + // New order + labelList newOrder(mesh.nCells()); + label cellInOrder = 0; + + + // Starting faces for walk. These are the zero distance faces. + DynamicList<label> frontFaces(mesh.nFaces()-mesh.nInternalFaces()); + + const polyBoundaryMesh& patches = mesh.boundaryMesh(); + + forAll(patches, patchI) + { + const polyPatch& pp = patches[patchI]; + + //- Note: cannot check for empty since these are introduced by + // fvMeshSubset. Also most loops don't care about patch type. + //if (!isA<emptyPolyPatch>(pp)) + { + forAll(pp, i) + { + frontFaces.append(pp.start()+i); + } + } + } + + // Loop over all frontFaces + label currentDistance = 0; + while (frontFaces.size() > 0) + { + DynamicList<label> frontCells(frontFaces.size()); + + // Set all of frontFaces' neighbours to current distance + + forAll(frontFaces, i) + { + label faceI = frontFaces[i]; + + if (mesh.isInternalFace(faceI)) + { + label ownCellI = own[faceI]; + if (distance[ownCellI] == -1) + { + distance[ownCellI] = currentDistance; + frontCells.append(ownCellI); + } + label neiCellI = nei[faceI]; + if (distance[neiCellI] == -1) + { + distance[neiCellI] = currentDistance; + frontCells.append(neiCellI); + } + } + else + { + label ownCellI = own[faceI]; + if (distance[ownCellI] == -1) + { + distance[ownCellI] = currentDistance; + frontCells.append(ownCellI); + } + } + } + + //Pout<< "For distance:" << currentDistance + // << " from " << frontFaces.size() << " faces to " + // << frontCells.size() << " cells." << endl; + + + // TBD. Determine order within current shell (frontCells). For now + // just add them. + forAll(frontCells, i) + { + newOrder[cellInOrder] = frontCells[i]; + cellInOrder++; + } + + // From cells to faces + frontFaces.clear(); + forAll(frontCells, i) + { + label cellI = frontCells[i]; + const cell& cFaces = mesh.cells()[cellI]; + + forAll(cFaces, i) + { + label faceI = cFaces[i]; + if (mesh.isInternalFace(faceI)) + { + label nbrCellI = + ( + mesh.faceOwner()[faceI] == cellI + ? mesh.faceNeighbour()[faceI] + : mesh.faceOwner()[faceI] + ); + if (distance[nbrCellI] == -1) + { + frontFaces.append(faceI); + } + } + } + } + + currentDistance++; + } + + // Return furthest away cell first + if (reverse_) + { + reverse(newOrder); + } + + //forAll(newOrder, i) + //{ + // label cellI = newOrder[i]; + // + // Pout<< "cell:" << cellI << endl; + // Pout<< " at distance:" << distance[cellI] + // << endl; + //} + + return invert(newOrder.size(), newOrder); +} + + +// ************************************************************************* // diff --git a/src/renumber/renumberMethods/boundaryFirstRenumber/boundaryFirstRenumber.H b/src/renumber/renumberMethods/boundaryFirstRenumber/boundaryFirstRenumber.H new file mode 100644 index 0000000000000000000000000000000000000000..690af21455a6689ce47cda252cb9d9857c66c82f --- /dev/null +++ b/src/renumber/renumberMethods/boundaryFirstRenumber/boundaryFirstRenumber.H @@ -0,0 +1,129 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::boundaryFirstRenumber + +Description + Cuthill-McKee renumbering + +SourceFiles + boundaryFirstRenumber.C + +\*---------------------------------------------------------------------------*/ + +#ifndef boundaryFirstRenumber_H +#define boundaryFirstRenumber_H + +#include "renumberMethod.H" +#include "Switch.H" + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class boundaryFirstRenumber Declaration +\*---------------------------------------------------------------------------*/ + +class boundaryFirstRenumber +: + public renumberMethod +{ + // Private data + + const Switch reverse_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct and assignment + void operator=(const boundaryFirstRenumber&); + boundaryFirstRenumber(const boundaryFirstRenumber&); + + +public: + + //- Runtime type information + TypeName("boundaryFirst"); + + + // Constructors + + //- Construct given the renumber dictionary + boundaryFirstRenumber(const dictionary& renumberDict); + + + //- Destructor + virtual ~boundaryFirstRenumber() + {} + + + // Member Functions + + //- Return for every coordinate the wanted processor number. + // We need a polyMesh (to be able to load the file) + virtual labelList renumber(const pointField&) const + { + notImplemented + ( + "boundaryFirstRenumber::renumber(const pointField&)" + ); + return labelList(0); + } + + //- Return for every coordinate the wanted processor number. Use the + // mesh connectivity (if needed) + virtual labelList renumber + ( + const polyMesh& mesh, + const pointField& cc + ) const; + + //- Return for every cell the new cell label. + // The connectivity is equal to mesh.cellCells() except + // - the connections are across coupled patches + virtual labelList renumber + ( + const labelListList& cellCells, + const pointField& cc + ) const + { + notImplemented + ( + "boundaryFirstRenumber::renumber" + "(const labelListList&, const pointField&)" + ); + return labelList(0); + } +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/renumber/renumberMethods/manualRenumber/manualRenumber.C b/src/renumber/renumberMethods/manualRenumber/manualRenumber.C new file mode 100644 index 0000000000000000000000000000000000000000..92b5c8e00cb5782e09d62eb10a25100ef82a9dac --- /dev/null +++ b/src/renumber/renumberMethods/manualRenumber/manualRenumber.C @@ -0,0 +1,137 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "manualRenumber.H" +#include "addToRunTimeSelectionTable.H" +#include "IFstream.H" +#include "labelIOList.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(manualRenumber, 0); + + addToRunTimeSelectionTable + ( + renumberMethod, + manualRenumber, + dictionary + ); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::manualRenumber::manualRenumber(const dictionary& renumberDict) +: + renumberMethod(renumberDict), + dataFile_ + ( + renumberDict.subDict(typeName+"Coeffs").lookup("dataFile") + ) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::labelList Foam::manualRenumber::renumber +( + const polyMesh& mesh, + const pointField& points +) const +{ + labelIOList oldToNew + ( + IOobject + ( + dataFile_, + mesh.facesInstance(), + mesh, + IOobject::MUST_READ, + IOobject::AUTO_WRITE, + false + ) + ); + + // check if the final renumbering is OK + + if (oldToNew.size() != points.size()) + { + FatalErrorIn + ( + "manualRenumber::renumber(const pointField&, const scalarField&)" + ) << "Size of renumber list does not correspond " + << "to the number of points. Size: " + << oldToNew.size() << " Number of points: " + << points.size() + << ".\n" << "Manual renumbering data read from file " + << dataFile_ << "." << endl + << exit(FatalError); + } + + // Invert to see if one to one + labelList newToOld(points.size(), -1); + forAll(oldToNew, i) + { + label newI = oldToNew[i]; + + if (newI < 0 || newI >= oldToNew.size()) + { + FatalErrorIn + ( + "manualRenumber::renumber(const pointField&" + ", const scalarField&)" + ) << "Renumbering is not one-to-one. Index " + << i << " maps onto " << newI + << ".\n" << "Manual renumbering data read from file " + << dataFile_ << "." << endl + << exit(FatalError); + } + + if (newToOld[newI] == -1) + { + newToOld[newI] = i; + } + else + { + FatalErrorIn + ( + "manualRenumber::renumber(const pointField&" + ", const scalarField&)" + ) << "Renumbering is not one-to-one. Both index " + << newToOld[newI] + << " and " << i << " map onto " << newI + << ".\n" << "Manual renumbering data read from file " + << dataFile_ << "." << endl + << exit(FatalError); + } + } + + return oldToNew; +} + + +// ************************************************************************* // diff --git a/src/renumber/renumberMethods/manualRenumber/manualRenumber.H b/src/renumber/renumberMethods/manualRenumber/manualRenumber.H new file mode 100644 index 0000000000000000000000000000000000000000..a4d4b2f46f28fa74d94c9b3b33f5b1e27910d023 --- /dev/null +++ b/src/renumber/renumberMethods/manualRenumber/manualRenumber.H @@ -0,0 +1,125 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::manualRenumber + +Description + Renumber given a cell-to-new cell association in a file + +SourceFiles + manualRenumber.C + +\*---------------------------------------------------------------------------*/ + +#ifndef manualRenumber_H +#define manualRenumber_H + +#include "renumberMethod.H" + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class manualRenumber Declaration +\*---------------------------------------------------------------------------*/ + +class manualRenumber +: + public renumberMethod +{ + // Private data + + const fileName dataFile_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct and assignment + void operator=(const manualRenumber&); + manualRenumber(const manualRenumber&); + + +public: + + //- Runtime type information + TypeName("manual"); + + + // Constructors + + //- Construct given the renumber dictionary + manualRenumber(const dictionary& renumberDict); + + + //- Destructor + virtual ~manualRenumber() + {} + + + // Member Functions + + //- Return for every coordinate the wanted processor number. + // We need a polyMesh (to be able to load the file) + virtual labelList renumber(const pointField&) const + { + notImplemented("manualRenumber::renumber(const pointField&)"); + return labelList(0); + } + + //- Return for every coordinate the wanted processor number. Use the + // mesh connectivity (if needed) + virtual labelList renumber + ( + const polyMesh& mesh, + const pointField& cc + ) const; + + //- Return for every cell the new cell label. + // The connectivity is equal to mesh.cellCells() except + // - the connections are across coupled patches + virtual labelList renumber + ( + const labelListList& cellCells, + const pointField& cc + ) const + { + notImplemented + ( + "manualRenumber::renumber" + "(const labelListList&, const pointField&)" + ); + return labelList(0); + } +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/renumber/renumberMethods/randomRenumber/randomRenumber.C b/src/renumber/renumberMethods/randomRenumber/randomRenumber.C new file mode 100644 index 0000000000000000000000000000000000000000..2dae28e4381c325442b0707cea5abe30f3256965 --- /dev/null +++ b/src/renumber/renumberMethods/randomRenumber/randomRenumber.C @@ -0,0 +1,96 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "randomRenumber.H" +#include "addToRunTimeSelectionTable.H" +#include "Random.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(randomRenumber, 0); + + addToRunTimeSelectionTable + ( + renumberMethod, + randomRenumber, + dictionary + ); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::randomRenumber::randomRenumber(const dictionary& renumberDict) +: + renumberMethod(renumberDict) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::labelList Foam::randomRenumber::renumber +( + const pointField& points +) const +{ + Random rndGen(0); + + labelList oldToNew(identity(points.size())); + + for (label iter = 0; iter < 10; iter++) + { + forAll(oldToNew, i) + { + label j = rndGen.integer(0, oldToNew.size()-1); + Swap(oldToNew[i], oldToNew[j]); + } + } + return oldToNew; +} + + +Foam::labelList Foam::randomRenumber::renumber +( + const polyMesh& mesh, + const pointField& points +) const +{ + return renumber(points); +} + + +Foam::labelList Foam::randomRenumber::renumber +( + const labelListList& cellCells, + const pointField& points +) const +{ + return renumber(points); +} + + +// ************************************************************************* // diff --git a/src/renumber/renumberMethods/randomRenumber/randomRenumber.H b/src/renumber/renumberMethods/randomRenumber/randomRenumber.H new file mode 100644 index 0000000000000000000000000000000000000000..0665d5159b318e89c5e40802d81f592d2a4e5497 --- /dev/null +++ b/src/renumber/renumberMethods/randomRenumber/randomRenumber.H @@ -0,0 +1,108 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::randomRenumber + +Description + Random renumber. Just to see effect of renumbering. + +SourceFiles + randomRenumber.C + +\*---------------------------------------------------------------------------*/ + +#ifndef randomRenumber_H +#define randomRenumber_H + +#include "renumberMethod.H" + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class randomRenumber Declaration +\*---------------------------------------------------------------------------*/ + +class randomRenumber +: + public renumberMethod +{ + // Private Member Functions + + //- Disallow default bitwise copy construct and assignment + void operator=(const randomRenumber&); + randomRenumber(const randomRenumber&); + + +public: + + //- Runtime type information + TypeName("random"); + + + // Constructors + + //- Construct given the renumber dictionary + randomRenumber(const dictionary& renumberDict); + + + //- Destructor + virtual ~randomRenumber() + {} + + + // Member Functions + + //- Return for every coordinate the wanted processor number. + // We need a polyMesh (to be able to load the file) + virtual labelList renumber(const pointField&) const; + + //- Return for every coordinate the wanted processor number. Use the + // mesh connectivity (if needed) + virtual labelList renumber + ( + const polyMesh& mesh, + const pointField& cc + ) const; + + //- Return for every cell the new cell label. + // The connectivity is equal to mesh.cellCells() except + // - the connections are across coupled patches + virtual labelList renumber + ( + const labelListList& cellCells, + const pointField& cc + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/renumber/renumberMethods/renumberMethod/renumberMethod.C b/src/renumber/renumberMethods/renumberMethod/renumberMethod.C new file mode 100644 index 0000000000000000000000000000000000000000..76ba1911e2a00a7dfb417f63bfac0f774fe7fbea --- /dev/null +++ b/src/renumber/renumberMethods/renumberMethod/renumberMethod.C @@ -0,0 +1,131 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +InClass + renumberMethod + +\*---------------------------------------------------------------------------*/ + +#include "renumberMethod.H" +#include "decompositionMethod.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(renumberMethod, 0); + defineRunTimeSelectionTable(renumberMethod, dictionary); +} + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::autoPtr<Foam::renumberMethod> Foam::renumberMethod::New +( + const dictionary& renumberDict +) +{ + const word methodType(renumberDict.lookup("method")); + + //Info<< "Selecting renumberMethod " << methodType << endl; + + dictionaryConstructorTable::iterator cstrIter = + dictionaryConstructorTablePtr_->find(methodType); + + if (cstrIter == dictionaryConstructorTablePtr_->end()) + { + FatalErrorIn + ( + "renumberMethod::New" + "(const dictionary& renumberDict)" + ) << "Unknown renumberMethod " + << methodType << nl << nl + << "Valid renumberMethods are : " << endl + << dictionaryConstructorTablePtr_->sortedToc() + << exit(FatalError); + } + + return autoPtr<renumberMethod>(cstrIter()(renumberDict)); +} + + +Foam::labelList Foam::renumberMethod::renumber +( + const polyMesh& mesh, + const pointField& points +) const +{ + CompactListList<label> cellCells; + decompositionMethod::calcCellCells + ( + mesh, + identity(mesh.nCells()), + mesh.nCells(), + false, // local only + cellCells + ); + + // Renumber based on agglomerated points + return renumber(cellCells(), points); +} + + +Foam::labelList Foam::renumberMethod::renumber +( + const polyMesh& mesh, + const labelList& fineToCoarse, + const pointField& coarsePoints +) const +{ + CompactListList<label> coarseCellCells; + decompositionMethod::calcCellCells + ( + mesh, + fineToCoarse, + coarsePoints.size(), + false, // local only + coarseCellCells + ); + + // Renumber based on agglomerated points + labelList coarseDistribution + ( + renumber + ( + coarseCellCells(), + coarsePoints + ) + ); + + // Rework back into renumbering for original mesh_ + labelList fineDistribution(fineToCoarse.size()); + + forAll(fineDistribution, i) + { + fineDistribution[i] = coarseDistribution[fineToCoarse[i]]; + } + + return fineDistribution; +} + + +// ************************************************************************* // diff --git a/src/renumber/renumberMethods/renumberMethod/renumberMethod.H b/src/renumber/renumberMethods/renumberMethod/renumberMethod.H new file mode 100644 index 0000000000000000000000000000000000000000..ead92b1e4152bd68692b27693bd190110dbe63cb --- /dev/null +++ b/src/renumber/renumberMethods/renumberMethod/renumberMethod.H @@ -0,0 +1,161 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::renumberMethod + +Description + Abstract base class for renumbering + +SourceFiles + renumberMethod.C + +\*---------------------------------------------------------------------------*/ + +#ifndef renumberMethod_H +#define renumberMethod_H + +#include "polyMesh.H" +#include "pointField.H" +#include "CompactListList.H" + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class renumberMethod Declaration +\*---------------------------------------------------------------------------*/ + +class renumberMethod +{ + +protected: + + // Protected data + + const dictionary& renumberDict_; + +private: + + // Private Member Functions + + //- Disallow default bitwise copy construct and assignment + renumberMethod(const renumberMethod&); + void operator=(const renumberMethod&); + + +public: + + //- Runtime type information + TypeName("renumberMethod"); + + + // Declare run-time constructor selection tables + + declareRunTimeSelectionTable + ( + autoPtr, + renumberMethod, + dictionary, + ( + const dictionary& renumberDict + ), + (renumberDict) + ); + + + // Selectors + + //- Return a reference to the selected renumbering method + static autoPtr<renumberMethod> New + ( + const dictionary& renumberDict + ); + + + // Constructors + + //- Construct given the renumber dictionary + renumberMethod(const dictionary& renumberDict) + : + renumberDict_(renumberDict) + {} + + + //- Destructor + virtual ~renumberMethod() + {} + + + // Member Functions + + //- Return for every cell the new cell label. + // This is only defined for geometric renumberMethods. + virtual labelList renumber(const pointField&) const + { + notImplemented + ( + "renumberMethod:renumber(const pointField&)" + ); + return labelList(0); + } + + //- Return for every cell the new cell label. Use the + // mesh connectivity (if needed) + virtual labelList renumber(const polyMesh&, const pointField&) const; + + //- Return for every cell the new cell label. Gets + // passed agglomeration map (from fine to coarse cells) and coarse + // cell + // location. Can be overridden by renumberMethods that provide this + // functionality natively. Coarse cells are local to the processor + // (if in parallel). If you want to have coarse cells spanning + // processors use the globalCellCells instead. + virtual labelList renumber + ( + const polyMesh& mesh, + const labelList& cellToRegion, + const pointField& regionPoints + ) const; + + //- Return for every cell the new cell label. + // The connectivity is equal to mesh.cellCells() except + // - the connections are across coupled patches + virtual labelList renumber + ( + const labelListList& cellCells, + const pointField& cc + ) const = 0; + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/renumber/renumberMethods/springRenumber/springRenumber.C b/src/renumber/renumberMethods/springRenumber/springRenumber.C new file mode 100644 index 0000000000000000000000000000000000000000..64a15145ce4d200da625d0eee9ed808a0ddf2605 --- /dev/null +++ b/src/renumber/renumberMethods/springRenumber/springRenumber.C @@ -0,0 +1,172 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "springRenumber.H" +#include "addToRunTimeSelectionTable.H" +#include "decompositionMethod.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(springRenumber, 0); + + addToRunTimeSelectionTable + ( + renumberMethod, + springRenumber, + dictionary + ); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::springRenumber::springRenumber(const dictionary& renumberDict) +: + renumberMethod(renumberDict), + dict_(renumberDict.subDict(typeName+"Coeffs")), + maxCo_(readScalar(dict_.lookup("maxCo"))), + maxIter_(readLabel(dict_.lookup("maxIter"))), + freezeFraction_(readScalar(dict_.lookup("freezeFraction"))) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::labelList Foam::springRenumber::renumber +( + const polyMesh& mesh, + const pointField& points +) const +{ + CompactListList<label> cellCells; + decompositionMethod::calcCellCells + ( + mesh, + identity(mesh.nCells()), + mesh.nCells(), + false, // local only + cellCells + ); + + return renumber(cellCells(), points); +} + + +Foam::labelList Foam::springRenumber::renumber +( + const labelListList& cellCells, + const pointField& points +) const +{ + // Look at cell index as a 1D position parameter. + // Move cells to the average 'position' of their neighbour. + + scalarField position(cellCells.size()); + forAll(position, cellI) + { + position[cellI] = cellI; + } + + labelList oldToNew(identity(cellCells.size())); + + scalar maxCo = maxCo_ * cellCells.size(); + + for (label iter = 0; iter < maxIter_; iter++) + { + //Pout<< "Iteration : " << iter << nl + // << "------------" + // << endl; + + //Pout<< "Position :" << nl + // << " min : " << min(position) << nl + // << " max : " << max(position) << nl + // << " avg : " << average(position) << nl + // << endl; + + // Sum force per cell. + scalarField sumForce(cellCells.size(), 0.0); + forAll(cellCells, oldCellI) + { + const labelList& cCells = cellCells[oldCellI]; + label cellI = oldToNew[oldCellI]; + + forAll(cCells, i) + { + label nbrCellI = oldToNew[cCells[i]]; + + sumForce[cellI] += (position[nbrCellI]-position[cellI]); + } + } + + //Pout<< "Force :" << nl + // << " min : " << min(sumForce) << nl + // << " max : " << max(sumForce) << nl + // << " avgMag : " << average(mag(sumForce)) << nl + // << "DeltaT : " << deltaT << nl + // << endl; + + // Limit displacement + scalar deltaT = maxCo / max(mag(sumForce)); + + Info<< "Iter:" << iter + << " maxCo:" << maxCo + << " deltaT:" << deltaT + << " average force:" << average(mag(sumForce)) << endl; + + // Determine displacement. + scalarField displacement = deltaT*sumForce; + + //Pout<< "Displacement :" << nl + // << " min : " << min(displacement) << nl + // << " max : " << max(displacement) << nl + // << " avgMag : " << average(mag(displacement)) << nl + // << endl; + + // Calculate new position and scale to be within original range + // (0..nCells-1) for ease of postprocessing. + position += displacement; + position -= min(position); + position *= (position.size()-1)/max(position); + + // Slowly freeze. + maxCo *= freezeFraction_; + } + + //writeOBJ("endPosition.obj", cellCells, position); + + // Move cells to new position + labelList shuffle; + sortedOrder(position, shuffle); + + // Reorder oldToNew + inplaceReorder(shuffle, oldToNew); + + return oldToNew; +} + + +// ************************************************************************* // diff --git a/src/renumber/renumberMethods/springRenumber/springRenumber.H b/src/renumber/renumberMethods/springRenumber/springRenumber.H new file mode 100644 index 0000000000000000000000000000000000000000..30f7a3d8381487f5f32b139f809b5c01cea5b46d --- /dev/null +++ b/src/renumber/renumberMethods/springRenumber/springRenumber.H @@ -0,0 +1,132 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::springRenumber + +Description + Use spring analogy - attract neighbouring cells according to the distance + of their cell indices. + + // Maximum jump of cell indices. Is fraction of number of cells + maxCo 0.1; + + // Limit the amount of movement; the fraction maxCo gets decreased + // with every iteration. + freezeFraction 0.9; + + // Maximum number of iterations + maxIter 1000; + +SourceFiles + springRenumber.C + +\*---------------------------------------------------------------------------*/ + +#ifndef springRenumber_H +#define springRenumber_H + +#include "renumberMethod.H" + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class springRenumber Declaration +\*---------------------------------------------------------------------------*/ + +class springRenumber +: + public renumberMethod +{ + // Private data + + const dictionary& dict_; + + const scalar maxCo_; + + const label maxIter_; + + const scalar freezeFraction_; + + // Private Member Functions + + //- Disallow default bitwise copy construct and assignment + void operator=(const springRenumber&); + springRenumber(const springRenumber&); + + +public: + + //- Runtime type information + TypeName("spring"); + + + // Constructors + + //- Construct given the renumber dictionary + springRenumber(const dictionary& renumberDict); + + + //- Destructor + virtual ~springRenumber() + {} + + + // Member Functions + + //- Return for every coordinate the wanted processor number. + virtual labelList renumber(const pointField&) const + { + notImplemented("springRenumber::renumber(const pointField&)"); + return labelList(0); + } + + //- Return for every coordinate the wanted processor number. Use the + // mesh connectivity (if needed) + virtual labelList renumber + ( + const polyMesh& mesh, + const pointField& cc + ) const; + + //- Return for every cell the new cell label. + // The connectivity is equal to mesh.cellCells() except + // - the connections are across coupled patches + virtual labelList renumber + ( + const labelListList& cellCells, + const pointField& cc + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //