Commit 6cb2be20 authored by mattijs's avatar mattijs
Browse files

ENH: GAMGProcAgglomeration methods

parent 786221c6
......@@ -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
......
......@@ -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,20 +260,58 @@ const Foam::GAMGAgglomeration& Foam::GAMGAgglomeration::New
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::GAMGAgglomeration::~GAMGAgglomeration()
Foam::autoPtr<Foam::GAMGAgglomeration> Foam::GAMGAgglomeration::New
(
const lduMesh& mesh,
const scalarField& cellVolumes,
const vectorField& faceAreas,
const dictionary& controlDict
)
{
forAllReverse(procCommunicator_, i)
const word agglomeratorType(controlDict.lookup("agglomerator"));
const_cast<Time&>(mesh.thisDb().time()).libs().open
(
controlDict,
"geometricGAMGAgglomerationLibs",
geometryConstructorTablePtr_
);
geometryConstructorTable::iterator cstrIter =
geometryConstructorTablePtr_->find(agglomeratorType);
if (cstrIter == geometryConstructorTablePtr_->end())
{
if (procCommunicator_[i] != -1)
{
UPstream::freeCommunicator(procCommunicator_[i]);
}
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<GAMGAgglomeration>
(
cstrIter()
(
mesh,
cellVolumes,
faceAreas,
controlDict
)
);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::GAMGAgglomeration::~GAMGAgglomeration()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::lduMesh& Foam::GAMGAgglomeration::meshLevel
......
......@@ -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<GAMGAgglomeration> New
(
const lduMesh& mesh,
const scalarField& cellVolumes,
const vectorField& faceAreas,
const dictionary& controlDict
);
//- Destructor
~GAMGAgglomeration();
......
......@@ -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
......
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#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<int> 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;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
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<Tuple2<label, labelList> > procAgglomMaps_;
//- Any allocated communicators
DynamicList<label> comms_;
// Private Member Functions
//- Disallow default bitwise copy construct
manualGAMGProcAgglomeration
(
const manualGAMGProcAgglomeration&
);
//- Disallow default bitwise assignment
void operator=(const manualGAMGProcAgglomeration&);
public:
//- Runtime type information
TypeName("manual");
// Constructors
//- Construct given agglomerator and controls
manualGAMGProcAgglomeration
(
GAMGAgglomeration& agglom,
const dictionary& controlDict
);
//- Destructor
virtual ~manualGAMGProcAgglomeration();
// Member Functions
//- Modify agglomeration. Return true if modified
virtual bool agglomerate();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -23,7 +23,7 @@ License
\*---------------------------------------------------------------------------*/
#include "masterCoarsest.H"
#include "masterCoarsestGAMGProcAgglomeration.H"
#include "addToRunTimeSelectionTable.H"
#include "GAMGAgglomeration.H"
......@@ -31,12 +31,12 @@ License
namespace Foam
{
defineTypeNameAndDebug(masterCoarsest, 0);
defineTypeNameAndDebug(masterCoarsestGAMGProcAgglomeration, 0);
addToRunTimeSelectionTable
(
GAMGProcAgglomeration,
masterCoarsest,
masterCoarsestGAMGProcAgglomeration,
GAMGAgglomeration
);
}
......@@ -47,7 +47,7 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::masterCoarsest::masterCoarsest
Foam::masterCoarsestGAMGProcAgglomeration::masterCoarsestGAMGProcAgglomeration
(
GAMGAgglomeration& agglom,
const dictionary& controlDict
......@@ -59,10 +59,22 @@ Foam::masterCoarsest::masterCoarsest
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::masterCoarsestGAMGProcAgglomeration::
~masterCoarsestGAMGProcAgglomeration()
{
forAllReverse(comms_, i)
{
if (comms_[i] != -1)
{
UPstream::freeCommunicator(comms_[i]);
}
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::masterCoarsest::agglomerate()
bool Foam::masterCoarsestGAMGProcAgglomeration::agglomerate()
{
if (debug)
{
......@@ -76,60 +88,50 @@ bool Foam::masterCoarsest::agglomerate()
// restrictAddressing)
label fineLevelIndex = agglom_.size()-1;
// Get the coarse mesh
const lduMesh& levelMesh = agglom_.meshLevel(fineLevelIndex-1);
label levelComm = levelMesh.comm();
// Processor restriction map: per processor the coarse processor
labelList procAgglomMap(UPstream::nProcs(levelComm));
//{
// label half = (procAgglomMap.size()+1)/2;
// for (label i = 0; i < half; i++)
// {
// procAgglomMap[i] = 0;
// }
// for (label i = half; i < procAgglomMap.size(); i++)
// {
// procAgglomMap[i] = 1;
// }
//}
procAgglomMap = 0;
// Master processor
labelList masterProcs;
// Local processors that agglomerate. agglomProcIDs[0] is in
// masterProc.
List<int> agglomProcIDs;