Bug fix: addressing memory leak in Block AMG

This commit is contained in:
Hrvoje Jasak 2015-08-25 11:13:39 +01:00
parent d4a0916e17
commit 445b28d6a4
13 changed files with 95 additions and 94 deletions

View file

@ -34,11 +34,12 @@ Author
#include "BlockMatrixAgglomeration.H"
#include "boolList.H"
#include "tolerancesSwitch.H"
#include "coeffFields.H"
#include "addToRunTimeSelectionTable.H"
#include "BlockGAMGInterfaceField.H"
#include "processorLduInterfaceField.H"
#include "tolerancesSwitch.H"
#include "coarseBlockAmgLevel.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -397,14 +398,14 @@ Foam::BlockMatrixAgglomeration<Type>::~BlockMatrixAgglomeration()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Foam::autoPtr<Foam::BlockLduMatrix<Type> >
Foam::autoPtr<Foam::BlockAmgLevel<Type> >
Foam::BlockMatrixAgglomeration<Type>::restrictMatrix() const
{
if (!coarsen_)
{
FatalErrorIn
(
"autoPtr<amgMatrix> "
"autoPtr<BlockAmgLevel<Type> > "
"BlockMatrixAgglomeration<Type>::restrictMatrix() const"
) << "Requesting coarse matrix when it cannot be created"
<< abort(FatalError);
@ -434,8 +435,8 @@ Foam::BlockMatrixAgglomeration<Type>::restrictMatrix() const
{
FatalErrorIn
(
"autoPtr<BlockLduMatrix<Type> > BlockMatrixAgglomeration<Type>::"
"restrictMatrix() const"
"autoPtr<BlockLduMatrix<Type> >"
"BlockMatrixAgglomeration<Type>::restrictMatrix() const"
) << "agglomIndex array does not correspond to fine level. " << endl
<< " Size: " << agglomIndex_.size()
<< " number of equations: " << matrix_.lduAddr().size()
@ -609,23 +610,23 @@ Foam::BlockMatrixAgglomeration<Type>::restrictMatrix() const
const_cast<BlockLduMatrix<Type>&>(matrix_).interfaces();
// Set the coarse interfaces and coefficients
lduInterfacePtrsList* coarseInterfacesPtr =
new lduInterfacePtrsList(interfaceSize);
lduInterfacePtrsList& coarseInterfaces = *coarseInterfacesPtr;
lduInterfacePtrsList coarseInterfaces(interfaceSize);
labelListList coarseInterfaceAddr(interfaceSize);
// Add the coarse level
// Set the coarse ldu addressing onto the list
lduPrimitiveMesh* coarseAddrPtr =
autoPtr<lduPrimitiveMesh> coarseAddrPtr
(
new lduPrimitiveMesh
(
nCoarseEqns_,
coarseOwner,
coarseNeighbour,
true
);
)
);
// Initialise transfer of restrict addressing on the interface
forAll (interfaceFields, intI)
@ -679,7 +680,7 @@ Foam::BlockMatrixAgglomeration<Type>::restrictMatrix() const
intI,
GAMGInterface::New
(
*coarseAddrPtr,
coarseAddrPtr(),
fineInterface,
fineInterface.interfaceInternalField(agglomIndex_),
fineInterfaceAddr[intI]
@ -702,15 +703,17 @@ Foam::BlockMatrixAgglomeration<Type>::restrictMatrix() const
// Add interfaces
coarseAddrPtr->addInterfaces
(
*coarseInterfacesPtr,
coarseInterfaces,
coarseInterfaceAddr,
matrix_.patchSchedule()
);
// Set the coarse level matrix
BlockLduMatrix<Type>* coarseMatrixPtr =
new BlockLduMatrix<Type>(*coarseAddrPtr);
BlockLduMatrix<Type>& coarseMatrix = *coarseMatrixPtr;
autoPtr<BlockLduMatrix<Type> > coarseMatrixPtr
(
new BlockLduMatrix<Type>(coarseAddrPtr())
);
BlockLduMatrix<Type>& coarseMatrix = coarseMatrixPtr();
typename BlockLduInterfaceFieldPtrsList<Type>::Type&
coarseInterfaceFieldsTransfer =
@ -818,7 +821,7 @@ Foam::BlockMatrixAgglomeration<Type>::restrictMatrix() const
{
FatalErrorIn
(
"autoPtr<amgMatrix>"
"autoPtr<BlockAmgLevel<Type> >"
"BlockMatrixAgglomeration<Type>::restrictMatrix() const"
) << "Matrix diagonal of square type and upper of "
<< "linear type is not implemented"
@ -828,7 +831,7 @@ Foam::BlockMatrixAgglomeration<Type>::restrictMatrix() const
{
FatalErrorIn
(
"autoPtr<amgMatrix>"
"autoPtr<BlockAmgLevel<Type> >"
"BlockMatrixAgglomeration<Type>::restrictMatrix() const"
) << "Matrix diagonal of square type and upper of "
<< "scalar type is not implemented"
@ -839,7 +842,7 @@ Foam::BlockMatrixAgglomeration<Type>::restrictMatrix() const
{
FatalErrorIn
(
"autoPtr<amgMatrix>"
"autoPtr<BlockAmgLevel<Type> >"
"BlockMatrixAgglomeration<Type>::restrictMatrix() const"
) << "Matrix diagonal of linear type not implemented"
<< abort(FatalError);
@ -848,7 +851,7 @@ Foam::BlockMatrixAgglomeration<Type>::restrictMatrix() const
{
FatalErrorIn
(
"autoPtr<amgMatrix>"
"autoPtr<BlockAmgLevel<Type> >"
"BlockMatrixAgglomeration<Type>::restrictMatrix() const"
) << "Matrix diagonal of scalar type not implemented"
<< abort(FatalError);
@ -900,7 +903,7 @@ Foam::BlockMatrixAgglomeration<Type>::restrictMatrix() const
{
FatalErrorIn
(
"autoPtr<amgMatrix>"
"autoPtr<BlockAmgLevel<Type> >"
"BlockMatrixAgglomeration<Type>::restrictMatrix() const"
) << "Matrix diagonal of square type and upper of "
<< "linear type is not implemented"
@ -910,7 +913,7 @@ Foam::BlockMatrixAgglomeration<Type>::restrictMatrix() const
{
FatalErrorIn
(
"autoPtr<amgMatrix>"
"autoPtr<BlockAmgLevel<Type> >"
"BlockMatrixAgglomeration<Type>::restrictMatrix() const"
) << "Matrix diagonal of square type and upper of "
<< "scalar type is not implemented"
@ -922,8 +925,8 @@ Foam::BlockMatrixAgglomeration<Type>::restrictMatrix() const
{
FatalErrorIn
(
"autoPtr<amgMatrix> BlockMatrixAgglomeration<Type>::"
"restrictMatrix() const"
"autoPtr<BlockAmgLevel<Type> > "
"BlockMatrixAgglomeration<Type>::restrictMatrix() const"
) << "Matrix diagonal of linear type not implemented"
<< abort(FatalError);
}
@ -931,14 +934,25 @@ Foam::BlockMatrixAgglomeration<Type>::restrictMatrix() const
{
FatalErrorIn
(
"autoPtr<amgMatrix> BlockMatrixAgglomeration<Type>::"
"restrictMatrix() const"
"autoPtr<BlockAmgLevel<Type> > "
"BlockMatrixAgglomeration<Type>::restrictMatrix() const"
) << "Matrix diagonal of scalar type not implemented"
<< abort(FatalError);
}
}
return autoPtr<BlockLduMatrix<Type> >(coarseMatrixPtr);
return autoPtr<BlockAmgLevel<Type> >
(
new coarseBlockAmgLevel<Type>
(
coarseAddrPtr,
coarseMatrixPtr,
this->dict(),
this->type(),
this->groupSize(),
this->minCoarseEqns()
)
);
}

View file

@ -138,7 +138,7 @@ public:
}
//- Restrict matrix
virtual autoPtr<BlockLduMatrix<Type> > restrictMatrix() const;
virtual autoPtr<BlockAmgLevel<Type> > restrictMatrix() const;
//- Restrict residual
virtual void restrictResidual

View file

@ -31,7 +31,8 @@ Class
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
template<class Type>
Foam::autoPtr<Foam::BlockMatrixCoarsening<Type> > Foam::BlockMatrixCoarsening<Type>::New
Foam::autoPtr<Foam::BlockMatrixCoarsening<Type> >
Foam::BlockMatrixCoarsening<Type>::New
(
const word& coarseningType,
const BlockLduMatrix<Type>& matrix,
@ -47,7 +48,8 @@ Foam::autoPtr<Foam::BlockMatrixCoarsening<Type> > Foam::BlockMatrixCoarsening<Ty
{
FatalErrorIn
(
"autoPtr<BlockMatrixCoarsening<Type> > BlockMatrixCoarsening<Type>::New\n"
"autoPtr<BlockMatrixCoarsening<Type> > "
"BlockMatrixCoarsening<Type>::New\n"
"(\n"
" const word& coarseningType,\n"
" const lduMatrix& matrix,\n"

View file

@ -91,29 +91,25 @@ class BlockMatrixCoarsening
public:
//- Runtime type information
TypeName("BlockMatrixCoarsening");
// KRJ: 2012-12-15: Replaced by the above function
//- Runtime type information
//virtual const word& type() const = 0;
//- Runtime type information
TypeName("BlockMatrixCoarsening");
// Declare run-time constructor selection tables
// Declare run-time constructor selection tables
declareRunTimeSelectionTable
declareRunTimeSelectionTable
(
autoPtr,
BlockMatrixCoarsening,
matrix,
(
autoPtr,
BlockMatrixCoarsening,
matrix,
(
const BlockLduMatrix<Type>& matrix,
const dictionary& dict,
const label groupSize,
const label minCoarseEqns
),
(matrix, dict, groupSize, minCoarseEqns)
);
const BlockLduMatrix<Type>& matrix,
const dictionary& dict,
const label groupSize,
const label minCoarseEqns
),
(matrix, dict, groupSize, minCoarseEqns)
);
// Selectors
@ -154,6 +150,12 @@ public:
// Member Functions
//- Return access to dictionary
const dictionary& dict() const
{
return dict_;
}
//- Return group size
label groupSize() const
{
@ -170,7 +172,7 @@ public:
virtual bool coarsen() const = 0;
//- Restrict matrix
virtual autoPtr<BlockLduMatrix<Type> > restrictMatrix
virtual autoPtr<BlockAmgLevel<Type> > restrictMatrix
() const = 0;
//- Restrict residual

View file

@ -25,6 +25,7 @@ License
#include "blockMatrixAgglomerations.H"
#include "blockMatrixCoarsenings.H"
#include "coarseBlockAmgLevel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View file

@ -58,18 +58,18 @@ namespace Foam
//- Restrict matrix
template<>
inline autoPtr<BlockLduMatrix<scalar> >
inline autoPtr<BlockAmgLevel<scalar> >
BlockMatrixAgglomeration<scalar>::restrictMatrix() const
{
FatalErrorIn
(
"autoPtr<BlockLduMatrix<scalar> > "
"autoPtr<BlockAmgLevel<scalar> > "
"BlockMatrixAgglomeration<Type>::restrictMatrix() const"
) << "Function not implemented for Type=scalar. " << endl
<< abort(FatalError);
// Dummy return to keep compiler happy
return autoPtr<BlockLduMatrix<scalar> >(NULL);
return autoPtr<BlockAmgLevel<scalar> >(NULL);
}

View file

@ -52,18 +52,20 @@ namespace Foam
//- Restrict matrix
template<>
inline autoPtr<BlockLduMatrix<tensor> > BlockMatrixAgglomeration<tensor>::restrictMatrix
inline autoPtr<BlockAmgLevel<tensor> >
BlockMatrixAgglomeration<tensor>::restrictMatrix
() const
{
FatalErrorIn
(
"autoPtr<BlockLduMatrix<tensor> > BlockMatrixAgglomeration<Type>::"
"autoPtr<BlockAmgLevel<tensor> > "
"BlockMatrixAgglomeration<Type>::"
"restrictMatrix() const"
) << "Function not implemented for Type=tensor. " << endl
<< abort(FatalError);
// Dummy return to keep compiler happy
return autoPtr<BlockLduMatrix<tensor> >(NULL);
return autoPtr<BlockAmgLevel<tensor> >(NULL);
}

View file

@ -46,25 +46,25 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class BlockMatrixAgglomeration Declaration
Class BlockMatrixAgglomeration Declaration
\*---------------------------------------------------------------------------*/
//- Restrict matrix
template<>
inline autoPtr<BlockLduMatrix<vector> >
inline autoPtr<BlockAmgLevel<vector> >
BlockMatrixAgglomeration<vector>::restrictMatrix
() const
{
FatalErrorIn
(
"autoPtr<BlockLduMatrix<vector> > BlockMatrixAgglomeration<Type>::"
"autoPtr<BlockAmgLevel<vector> > BlockMatrixAgglomeration<Type>::"
"restrictMatrix() const"
) << "Function not implemented for Type=vector. " << endl
<< abort(FatalError);
// Dummy return to keep compiler happy
return autoPtr<BlockLduMatrix<vector> >(NULL);
return autoPtr<BlockAmgLevel<vector> >(NULL);
}

View file

@ -47,14 +47,15 @@ Author
template<class Type>
Foam::coarseBlockAmgLevel<Type>::coarseBlockAmgLevel
(
autoPtr<lduPrimitiveMesh> addrPtr,
autoPtr<BlockLduMatrix<Type> > matrixPtr,
const dictionary& dict,
const word& coarseningType,
const label groupSize,
const label minCoarseEqns,
const word& smootherType
const label minCoarseEqns
)
:
addrPtr_(addrPtr),
matrixPtr_(matrixPtr),
x_(matrixPtr_->diag().size(),pTraits<Type>::zero),
b_(matrixPtr_->diag().size(),pTraits<Type>::zero),
@ -388,23 +389,12 @@ Foam::coarseBlockAmgLevel<Type>::makeNextLevel() const
{
if (coarseningPtr_->coarsen())
{
return autoPtr<Foam::BlockAmgLevel<Type> >
(
new coarseBlockAmgLevel
(
coarseningPtr_->restrictMatrix(),
dict(),
coarseningPtr_->type(),
coarseningPtr_->groupSize(),
coarseningPtr_->minCoarseEqns(),
smootherPtr_->type()
)
);
return coarseningPtr_->restrictMatrix();
}
else
{
// Final level: cannot coarsen
return autoPtr<Foam::BlockAmgLevel<Type> >();
return autoPtr<BlockAmgLevel<Type> >();
}
}

View file

@ -41,6 +41,7 @@ SourceFiles
#include "BlockAmgLevel.H"
#include "BlockLduSmoother.H"
#include "BlockLduMatrix.H"
#include "lduPrimitiveMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -58,6 +59,9 @@ class coarseBlockAmgLevel
{
// Private data
//- Matrix addressing object. This also contains coupling interfaces
autoPtr<lduPrimitiveMesh> addrPtr_;
//- Matrix
autoPtr<BlockLduMatrix<Type> > matrixPtr_;
@ -100,12 +104,12 @@ public:
//- Construct from components
coarseBlockAmgLevel
(
autoPtr<lduPrimitiveMesh> addrPtr,
autoPtr<BlockLduMatrix<Type> > matrixPtr,
const dictionary& dict,
const word& coarseningType,
const label groupSize,
const label minCoarseEqns,
const word& smootherType
const label minCoarseEqns
);

View file

@ -50,8 +50,7 @@ Foam::fineBlockAmgLevel<Type>::fineBlockAmgLevel
const dictionary& dict,
const word& coarseningType,
const label groupSize,
const label minCoarseEqns,
const word& smootherType
const label minCoarseEqns
)
:
matrix_(matrix),
@ -314,18 +313,7 @@ Foam::fineBlockAmgLevel<Type>::makeNextLevel() const
{
if (coarseningPtr_->coarsen())
{
return autoPtr<Foam::BlockAmgLevel<Type> >
(
new coarseBlockAmgLevel<Type>
(
coarseningPtr_->restrictMatrix(),
dict(),
coarseningPtr_->type(),
coarseningPtr_->groupSize(),
coarseningPtr_->minCoarseEqns(),
smootherPtr_->type()
)
);
return coarseningPtr_->restrictMatrix();
}
else
{

View file

@ -108,8 +108,7 @@ public:
const dictionary& dict,
const word& coarseningType,
const label groupSize,
const label minCoarseEqns,
const word& smootherType
const label minCoarseEqns
);

View file

@ -70,8 +70,7 @@ Foam::BlockAmgPrecon<Type>::BlockAmgPrecon
dict,
dict.lookup("coarseningType"),
readLabel(dict.lookup("groupSize")),
readLabel(dict.lookup("minCoarseEqns")),
dict.lookup("smoother")
readLabel(dict.lookup("minCoarseEqns"))
)
)
)