diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 2c01641321..321855de69 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -324,8 +324,14 @@ GAMGProcAgglomerations = $(GAMG)/GAMGProcAgglomerations GAMGProcAgglomeration = $(GAMGProcAgglomerations)/GAMGProcAgglomeration $(GAMGProcAgglomeration)/GAMGProcAgglomeration.C -masterCoarsest = $(GAMGProcAgglomerations)/masterCoarsest -$(masterCoarsest)/masterCoarsest.C +masterCoarsestGAMGProcAgglomeration = $(GAMGProcAgglomerations)/masterCoarsestGAMGProcAgglomeration +$(masterCoarsestGAMGProcAgglomeration)/masterCoarsestGAMGProcAgglomeration.C +manualGAMGProcAgglomeration = $(GAMGProcAgglomerations)/manualGAMGProcAgglomeration +$(manualGAMGProcAgglomeration)/manualGAMGProcAgglomeration.C +/* +cellFaceRatioGAMGProcAgglomeration = $(GAMGProcAgglomerations)/cellFaceRatioGAMGProcAgglomeration +$(cellFaceRatioGAMGProcAgglomeration)/cellFaceRatioGAMGProcAgglomeration.C +*/ meshes/lduMesh/lduMesh.C diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomeration.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomeration.C index 8832fb81a7..324ace4c91 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomeration.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomeration.C @@ -38,6 +38,7 @@ namespace Foam defineTypeNameAndDebug(GAMGAgglomeration, 0); defineRunTimeSelectionTable(GAMGAgglomeration, lduMesh); defineRunTimeSelectionTable(GAMGAgglomeration, lduMatrix); + defineRunTimeSelectionTable(GAMGAgglomeration, geometry); } @@ -69,6 +70,24 @@ void Foam::GAMGAgglomeration::compactLevels(const label nCreatedLevels) procAgglomeratorPtr_().agglomerate(); } + + if (debug) + { + for (label levelI = 0; levelI <= size(); levelI++) + { + if (hasMeshLevel(levelI)) + { + const lduMesh& fineMesh = meshLevel(levelI); + Pout<< "Level " << levelI << " fine mesh:"<< nl; + Pout<< fineMesh.info() << endl; + } + else + { + Pout<< "Level " << levelI << " has no fine mesh:" << nl + << endl; + } + } + } } @@ -241,18 +260,56 @@ const Foam::GAMGAgglomeration& Foam::GAMGAgglomeration::New } +Foam::autoPtr Foam::GAMGAgglomeration::New +( + const lduMesh& mesh, + const scalarField& cellVolumes, + const vectorField& faceAreas, + const dictionary& controlDict +) +{ + const word agglomeratorType(controlDict.lookup("agglomerator")); + + const_cast(mesh.thisDb().time()).libs().open + ( + controlDict, + "geometricGAMGAgglomerationLibs", + geometryConstructorTablePtr_ + ); + + geometryConstructorTable::iterator cstrIter = + geometryConstructorTablePtr_->find(agglomeratorType); + + if (cstrIter == geometryConstructorTablePtr_->end()) + { + FatalErrorIn + ( + "GAMGAgglomeration::New" + "(const lduMesh& mesh, const dictionary& controlDict)" + ) << "Unknown GAMGAgglomeration type " + << agglomeratorType << ".\n" + << "Valid geometric GAMGAgglomeration types are :" + << geometryConstructorTablePtr_->sortedToc() + << exit(FatalError); + } + + return autoPtr + ( + cstrIter() + ( + mesh, + cellVolumes, + faceAreas, + controlDict + ) + ); +} + + // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::GAMGAgglomeration::~GAMGAgglomeration() -{ - forAllReverse(procCommunicator_, i) - { - if (procCommunicator_[i] != -1) - { - UPstream::freeCommunicator(procCommunicator_[i]); - } - } -} +{} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomeration.H b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomeration.H index faaf62bbc1..b3617965c7 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomeration.H +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomeration.H @@ -253,6 +253,27 @@ public: ) ); + //- Runtime selection table for matrix or mixed geometric/matrix + // agglomerators + declareRunTimeSelectionTable + ( + autoPtr, + GAMGAgglomeration, + geometry, + ( + const lduMesh& mesh, + const scalarField& cellVolumes, + const vectorField& faceAreas, + const dictionary& controlDict + ), + ( + mesh, + cellVolumes, + faceAreas, + controlDict + ) + ); + // Constructors @@ -280,6 +301,15 @@ public: const dictionary& controlDict ); + //- Return the selected geometric agglomerator + static autoPtr New + ( + const lduMesh& mesh, + const scalarField& cellVolumes, + const vectorField& faceAreas, + const dictionary& controlDict + ); + //- Destructor ~GAMGAgglomeration(); diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/GAMGProcAgglomeration/GAMGProcAgglomeration.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/GAMGProcAgglomeration/GAMGProcAgglomeration.C index b8a1e59a74..f825ca769d 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/GAMGProcAgglomeration/GAMGProcAgglomeration.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/GAMGProcAgglomeration/GAMGProcAgglomeration.C @@ -47,36 +47,11 @@ void Foam::GAMGProcAgglomeration::printStats { if (agglom.hasMeshLevel(levelI)) { - const lduMesh& fineMesh = agglom.meshLevel(levelI); - const lduInterfacePtrsList& interfaces = - agglom.interfaceLevel(levelI); - - os << "Level " << levelI << " fine mesh:"<< nl - << " nCells:" - << fineMesh.lduAddr().size() << nl - << " nFaces:" - << fineMesh.lduAddr().lowerAddr().size() << nl - << " nInterfaces:" << interfaces.size() - << endl; - - forAll(interfaces, i) - { - if (interfaces.set(i)) - { - os << " " << i - << "\tsize:" << interfaces[i].faceCells().size() - << endl; - } - } - - os << fineMesh.info() << endl; - - os << endl; + os << agglom.meshLevel(levelI).info() << endl; } else { - os << "Level " << levelI << " has no fine mesh:" << nl - << endl; + os << "Level " << levelI << " has no fine mesh:" << endl; } if diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/manualGAMGProcAgglomeration/manualGAMGProcAgglomeration.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/manualGAMGProcAgglomeration/manualGAMGProcAgglomeration.C new file mode 100644 index 0000000000..9e0439c578 --- /dev/null +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/manualGAMGProcAgglomeration/manualGAMGProcAgglomeration.C @@ -0,0 +1,170 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 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 "manualGAMGProcAgglomeration.H" +#include "addToRunTimeSelectionTable.H" +#include "GAMGAgglomeration.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(manualGAMGProcAgglomeration, 0); + + addToRunTimeSelectionTable + ( + GAMGProcAgglomeration, + manualGAMGProcAgglomeration, + GAMGAgglomeration + ); +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::manualGAMGProcAgglomeration::manualGAMGProcAgglomeration +( + GAMGAgglomeration& agglom, + const dictionary& controlDict +) +: + GAMGProcAgglomeration(agglom, controlDict), + procAgglomMaps_(controlDict.lookup("processorAgglomeration")) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::manualGAMGProcAgglomeration:: +~manualGAMGProcAgglomeration() +{ + forAllReverse(comms_, i) + { + if (comms_[i] != -1) + { + UPstream::freeCommunicator(comms_[i]); + } + } +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::manualGAMGProcAgglomeration::agglomerate() +{ + if (debug) + { + Pout<< nl << "Starting mesh overview" << endl; + printStats(Pout, agglom_); + } + + if (agglom_.size() >= 1) + { + forAll(procAgglomMaps_, i) + { + const label fineLevelIndex = procAgglomMaps_[i].first(); + + if (fineLevelIndex >= agglom_.size()) + { + WarningIn("manualGAMGProcAgglomeration::agglomerate()") + << "Ignoring specification for level " << fineLevelIndex + << " since outside agglomeration." << endl; + + continue; + } + + + if (agglom_.hasMeshLevel(fineLevelIndex)) + { + const labelList& procAgglomMap = procAgglomMaps_[i].second(); + // Get the fine mesh + const lduMesh& levelMesh = agglom_.meshLevel(fineLevelIndex); + + + if (procAgglomMap.size() != Pstream::nProcs(levelMesh.comm())) + { + FatalErrorIn("manualGAMGProcAgglomeration::agglomerate()") + << "At level " << fineLevelIndex + << "The fine-to-coarse agglomeration map size " + << procAgglomMap.size() << " differs from the" + << " number of processors " + << Pstream::nProcs(levelMesh.comm()) + << exit(FatalError); + } + + // Master processor + labelList masterProcs; + // Local processors that agglomerate. agglomProcIDs[0] is in + // masterProc. + List agglomProcIDs; + GAMGAgglomeration::calculateRegionMaster + ( + levelMesh.comm(), + procAgglomMap, + masterProcs, + agglomProcIDs + ); + + // Allocate a communicator for the processor-agglomerated matrix + comms_.append + ( + UPstream::allocateCommunicator + ( + levelMesh.comm(), + masterProcs + ) + ); + + // Use procesor agglomeration maps to do the actual collecting. + if (Pstream::myProcNo(levelMesh.comm()) != -1) + { + GAMGProcAgglomeration::agglomerate + ( + fineLevelIndex, + procAgglomMap, + masterProcs, + agglomProcIDs, + comms_.last() + ); + } + } + } + + // Print a bit + if (debug) + { + Pout<< nl << "Agglomerated mesh overview" << endl; + printStats(Pout, agglom_); + } + } + + return true; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/manualGAMGProcAgglomeration/manualGAMGProcAgglomeration.H b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/manualGAMGProcAgglomeration/manualGAMGProcAgglomeration.H new file mode 100644 index 0000000000..914518f3bd --- /dev/null +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/manualGAMGProcAgglomeration/manualGAMGProcAgglomeration.H @@ -0,0 +1,114 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 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::manualGAMGProcAgglomeration + +Description + Manual processor agglomeration of GAMGAgglomerations. + +SourceFiles + manualGAMGProcAgglomeration.C + +\*---------------------------------------------------------------------------*/ + +#ifndef manualGAMGProcAgglomeration_H +#define manualGAMGProcAgglomeration_H + +#include "GAMGProcAgglomeration.H" +#include "DynamicList.H" +#include "Tuple2.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class GAMGAgglomeration; + +/*---------------------------------------------------------------------------*\ + Class manualGAMGProcAgglomeration Declaration +\*---------------------------------------------------------------------------*/ + +class manualGAMGProcAgglomeration +: + public GAMGProcAgglomeration +{ + // Private data + + //- Per level the agglomeration map + const List > procAgglomMaps_; + + //- Any allocated communicators + DynamicList