From f6c0779fcbc7991f3635b59c2bbf2ffa5dd75c28 Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 8 Dec 2011 16:25:43 +0000 Subject: [PATCH] ENH: renumberMethods: new library to do renumbering --- .../CuthillMcKeeRenumber.H | 118 ++++++++++++ src/renumberMethods/Make/files | 7 + src/renumberMethods/Make/options | 7 + .../manualRenumber/manualRenumber.C | 137 ++++++++++++++ .../manualRenumber/manualRenumber.H | 125 +++++++++++++ .../randomRenumber/randomRenumber.C | 96 ++++++++++ .../randomRenumber/randomRenumber.H | 107 +++++++++++ .../renumberMethod/renumberMethod.C | 131 +++++++++++++ .../renumberMethod/renumberMethod.H | 161 ++++++++++++++++ .../springRenumber/springRenumber.C | 172 ++++++++++++++++++ .../springRenumber/springRenumber.H | 132 ++++++++++++++ 11 files changed, 1193 insertions(+) create mode 100644 src/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.H create mode 100644 src/renumberMethods/Make/files create mode 100644 src/renumberMethods/Make/options create mode 100644 src/renumberMethods/manualRenumber/manualRenumber.C create mode 100644 src/renumberMethods/manualRenumber/manualRenumber.H create mode 100644 src/renumberMethods/randomRenumber/randomRenumber.C create mode 100644 src/renumberMethods/randomRenumber/randomRenumber.H create mode 100644 src/renumberMethods/renumberMethod/renumberMethod.C create mode 100644 src/renumberMethods/renumberMethod/renumberMethod.H create mode 100644 src/renumberMethods/springRenumber/springRenumber.C create mode 100644 src/renumberMethods/springRenumber/springRenumber.H diff --git a/src/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.H b/src/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.H new file mode 100644 index 0000000000..90a81692e0 --- /dev/null +++ b/src/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 . + +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&) + { + 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 + ); + + //- 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 + ); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/renumberMethods/Make/files b/src/renumberMethods/Make/files new file mode 100644 index 0000000000..fb366f73c4 --- /dev/null +++ b/src/renumberMethods/Make/files @@ -0,0 +1,7 @@ +renumberMethod/renumberMethod.C +manualRenumber/manualRenumber.C +CuthillMcKeeRenumber/CuthillMcKeeRenumber.C +randomRenumber/randomRenumber.C +springRenumber/springRenumber.C + +LIB = $(FOAM_LIBBIN)/librenumberMethods diff --git a/src/renumberMethods/Make/options b/src/renumberMethods/Make/options new file mode 100644 index 0000000000..03cb68d946 --- /dev/null +++ b/src/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/renumberMethods/manualRenumber/manualRenumber.C b/src/renumberMethods/manualRenumber/manualRenumber.C new file mode 100644 index 0000000000..40989264b5 --- /dev/null +++ b/src/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 . + +\*---------------------------------------------------------------------------*/ + +#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 +) +{ + 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/renumberMethods/manualRenumber/manualRenumber.H b/src/renumberMethods/manualRenumber/manualRenumber.H new file mode 100644 index 0000000000..9aa0d76c06 --- /dev/null +++ b/src/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 . + +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&) + { + 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 + ); + + //- 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 + ) + { + notImplemented + ( + "manualRenumber::renumber" + "(const labelListList&, const pointField&)" + ); + return labelList(0); + } + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/renumberMethods/randomRenumber/randomRenumber.C b/src/renumberMethods/randomRenumber/randomRenumber.C new file mode 100644 index 0000000000..27ddc29c3f --- /dev/null +++ b/src/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 . + +\*---------------------------------------------------------------------------*/ + +#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 +) +{ + 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 +) +{ + return renumber(points); +} + + +Foam::labelList Foam::randomRenumber::renumber +( + const labelListList& cellCells, + const pointField& points +) +{ + return renumber(points); +} + + +// ************************************************************************* // diff --git a/src/renumberMethods/randomRenumber/randomRenumber.H b/src/renumberMethods/randomRenumber/randomRenumber.H new file mode 100644 index 0000000000..54d63d2835 --- /dev/null +++ b/src/renumberMethods/randomRenumber/randomRenumber.H @@ -0,0 +1,107 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 . + +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&); + + //- Return for every coordinate the wanted processor number. Use the + // mesh connectivity (if needed) + virtual labelList renumber + ( + const polyMesh& mesh, + const pointField& cc + ); + + //- 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 + ); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/renumberMethods/renumberMethod/renumberMethod.C b/src/renumberMethods/renumberMethod/renumberMethod.C new file mode 100644 index 0000000000..53138673b8 --- /dev/null +++ b/src/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 . + +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::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(cstrIter()(renumberDict)); +} + + +Foam::labelList Foam::renumberMethod::renumber +( + const polyMesh& mesh, + const pointField& points +) +{ + CompactListList