diff --git a/src/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.H b/src/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.H new file mode 100644 index 0000000000000000000000000000000000000000..90a81692e02108cf90e4bb3484afd8d0c28e1b1d --- /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 <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&) + { + 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 0000000000000000000000000000000000000000..fb366f73c4d994bf2f23c7b452731b2599933ccb --- /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 0000000000000000000000000000000000000000..03cb68d94683cbf98c9e3f9a0426943c7365dd6b --- /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 0000000000000000000000000000000000000000..40989264b5032e3caef7202dafa747db6e773ab3 --- /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 <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 +) +{ + 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 0000000000000000000000000000000000000000..9aa0d76c065bb44cb4fb02eab3c666bf05c76cee --- /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 <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&) + { + 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 0000000000000000000000000000000000000000..27ddc29c3f2cdda7c90d157cc5a220ca65da4c98 --- /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 <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 +) +{ + 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 0000000000000000000000000000000000000000..54d63d2835e046cb3a7305d21d6872d47d95b2ff --- /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 <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&); + + //- 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 0000000000000000000000000000000000000000..53138673b834b98567b79141014bd20821ead9f7 --- /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 <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 +) +{ + 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 +) +{ + 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/renumberMethods/renumberMethod/renumberMethod.H b/src/renumberMethods/renumberMethod/renumberMethod.H new file mode 100644 index 0000000000000000000000000000000000000000..b4b6e89f220be61a890d156559feb49d7edd6d2a --- /dev/null +++ b/src/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&) + { + 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&); + + //- 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 + ); + + //- 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 + ) = 0; + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/renumberMethods/springRenumber/springRenumber.C b/src/renumberMethods/springRenumber/springRenumber.C new file mode 100644 index 0000000000000000000000000000000000000000..5c6fa49350b6b3e7e0fbe2ff1516df590910f933 --- /dev/null +++ b/src/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 +) +{ + 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 +) +{ + // 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/renumberMethods/springRenumber/springRenumber.H b/src/renumberMethods/springRenumber/springRenumber.H new file mode 100644 index 0000000000000000000000000000000000000000..d6ee7f00c1172a417095821915fd9d2c16c52248 --- /dev/null +++ b/src/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&) + { + 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 + ); + + //- 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 + +// ************************************************************************* //