ENH: fvMatrix, faMatrix: replace raw pointers with unique_ptr (#3107)

This commit is contained in:
Kutalmis Bercin
2024-02-27 13:40:36 +00:00
committed by Andrew Heather
parent 1cbbcf15d3
commit cd8bc891f0
10 changed files with 78 additions and 78 deletions

View File

@ -272,10 +272,7 @@ while (pimple.correct())
).ptr()
);
deleteDemandDrivenData
(
pEqnComps[phasei].faceFluxCorrectionPtr()
);
pEqnComps[phasei].faceFluxCorrectionPtr(nullptr);
pEqnComps[phasei].relax();
}

View File

@ -190,8 +190,7 @@ Foam::faMatrix<Type>::faMatrix
dimensions_(ds),
source_(psi.size(), Zero),
internalCoeffs_(psi.mesh().boundary().size()),
boundaryCoeffs_(psi.mesh().boundary().size()),
faceFluxCorrectionPtr_(nullptr)
boundaryCoeffs_(psi.mesh().boundary().size())
{
DebugInFunction
<< "constructing faMatrix<Type> for field " << psi_.name()
@ -231,16 +230,14 @@ Foam::faMatrix<Type>::faMatrix(const faMatrix<Type>& fam)
dimensions_(fam.dimensions_),
source_(fam.source_),
internalCoeffs_(fam.internalCoeffs_),
boundaryCoeffs_(fam.boundaryCoeffs_),
faceFluxCorrectionPtr_(nullptr)
boundaryCoeffs_(fam.boundaryCoeffs_)
{
DebugInFunction
<< "Copying faMatrix<Type> for field " << psi_.name() << endl;
if (fam.faceFluxCorrectionPtr_)
{
faceFluxCorrectionPtr_ =
new GeometricField<Type, faePatchField, edgeMesh>
faceFluxCorrectionPtr_ = std::make_unique<faceFluxFieldType>
(
*(fam.faceFluxCorrectionPtr_)
);
@ -256,8 +253,7 @@ Foam::faMatrix<Type>::faMatrix(const tmp<faMatrix<Type>>& tmat)
dimensions_(tmat().dimensions_),
source_(tmat.constCast().source_, tmat.movable()),
internalCoeffs_(tmat.constCast().internalCoeffs_, tmat.movable()),
boundaryCoeffs_(tmat.constCast().boundaryCoeffs_, tmat.movable()),
faceFluxCorrectionPtr_(nullptr)
boundaryCoeffs_(tmat.constCast().boundaryCoeffs_, tmat.movable())
{
DebugInFunction
<< "Copy/Move faMatrix<Type> for field " << psi_.name() << endl;
@ -265,14 +261,13 @@ Foam::faMatrix<Type>::faMatrix(const tmp<faMatrix<Type>>& tmat)
if (tmat().faceFluxCorrectionPtr_)
{
if (tmat.movable())
{
faceFluxCorrectionPtr_ = tmat().faceFluxCorrectionPtr_;
tmat().faceFluxCorrectionPtr_ = nullptr;
}
else
{
faceFluxCorrectionPtr_ =
new GeometricField<Type, faePatchField, edgeMesh>
std::move(tmat.constCast().faceFluxCorrectionPtr_);
}
else if (tmat().faceFluxCorrectionPtr_)
{
faceFluxCorrectionPtr_ = std::make_unique<faceFluxFieldType>
(
*(tmat().faceFluxCorrectionPtr_)
);
@ -290,8 +285,6 @@ Foam::faMatrix<Type>::~faMatrix()
{
DebugInFunction
<< "Destroying faMatrix<Type> for field " << psi_.name() << endl;
deleteDemandDrivenData(faceFluxCorrectionPtr_);
}
@ -788,9 +781,10 @@ void Foam::faMatrix<Type>::operator=(const faMatrix<Type>& famv)
}
else if (famv.faceFluxCorrectionPtr_)
{
faceFluxCorrectionPtr_ =
new GeometricField<Type, faePatchField, edgeMesh>
(*famv.faceFluxCorrectionPtr_);
faceFluxCorrectionPtr_ = std::make_unique<faceFluxFieldType>
(
*famv.faceFluxCorrectionPtr_
);
}
}
@ -835,8 +829,7 @@ void Foam::faMatrix<Type>::operator+=(const faMatrix<Type>& famv)
}
else if (famv.faceFluxCorrectionPtr_)
{
faceFluxCorrectionPtr_ = new
GeometricField<Type, faePatchField, edgeMesh>
faceFluxCorrectionPtr_ = std::make_unique<faceFluxFieldType>
(
*famv.faceFluxCorrectionPtr_
);
@ -869,9 +862,10 @@ void Foam::faMatrix<Type>::operator-=(const faMatrix<Type>& famv)
}
else if (famv.faceFluxCorrectionPtr_)
{
faceFluxCorrectionPtr_ =
new GeometricField<Type, faePatchField, edgeMesh>
(-*famv.faceFluxCorrectionPtr_);
faceFluxCorrectionPtr_ = std::make_unique<faceFluxFieldType>
(
-*famv.faceFluxCorrectionPtr_
);
}
}

View File

@ -151,7 +151,7 @@ private:
FieldField<Field, Type> boundaryCoeffs_;
//- Face flux field for non-orthogonal correction
mutable faceFluxFieldType* faceFluxCorrectionPtr_;
mutable std::unique_ptr<faceFluxFieldType> faceFluxCorrectionPtr_;
protected:
@ -353,8 +353,7 @@ public:
}
//- Declare return type of the faceFluxCorrectionPtr() function
typedef GeometricField<Type, faePatchField, edgeMesh>
*faceFluxFieldPtrType;
typedef std::unique_ptr<faceFluxFieldType> faceFluxFieldPtrType;
//- Return pointer to face-flux non-orthogonal correction field
faceFluxFieldPtrType& faceFluxCorrectionPtr()
@ -362,6 +361,12 @@ public:
return faceFluxCorrectionPtr_;
}
//- Set pointer to face-flux non-orthogonal correction field
void faceFluxCorrectionPtr(faceFluxFieldType* flux)
{
faceFluxCorrectionPtr_.reset(flux);
}
//- True if face-flux non-orthogonal correction field exists
bool hasFaceFluxCorrection() const noexcept
{

View File

@ -82,8 +82,10 @@ gaussLaplacianScheme<Type>::famLaplacian
{
if (this->mesh().fluxRequired(vf.name()))
{
fam.faceFluxCorrectionPtr() = new
fam.faceFluxCorrectionPtr() = std::make_unique
<
GeometricField<Type, faePatchField, edgeMesh>
>
(
gammaMagSf*this->tlnGradScheme_().correction(vf)
);

View File

@ -194,7 +194,7 @@ gaussLaplacianScheme<Type, GType>::fvmLaplacian
if (mesh.fluxRequired(vf.name()))
{
fvm.faceFluxCorrectionPtr() = tfaceFluxCorrection.ptr();
fvm.faceFluxCorrectionPtr(tfaceFluxCorrection.ptr());
}
return tfvm;

View File

@ -61,8 +61,10 @@ Foam::fv::gaussLaplacianScheme<Foam::Type, Foam::scalar>::fvmLaplacian \
{ \
if (mesh.fluxRequired(vf.name())) \
{ \
fvm.faceFluxCorrectionPtr() = new \
fvm.faceFluxCorrectionPtr() = std::make_unique \
< \
GeometricField<Type, fvsPatchField, surfaceMesh> \
> \
( \
gammaMagSf*this->tsnGradScheme_().correction(vf) \
); \

View File

@ -222,7 +222,7 @@ relaxedNonOrthoGaussLaplacianScheme<Type, GType>::fvmLaplacian
if (mesh.fluxRequired(vf.name()))
{
fvm.faceFluxCorrectionPtr() = trelaxedCorrection.ptr();
fvm.faceFluxCorrectionPtr(trelaxedCorrection.ptr());
}
return tfvm;

View File

@ -98,7 +98,7 @@ fvmLaplacian \
\
if (mesh.fluxRequired(vf.name())) \
{ \
fvm.faceFluxCorrectionPtr() = trelaxedCorrection.ptr(); \
fvm.faceFluxCorrectionPtr(trelaxedCorrection.ptr()); \
} \
} \
\

View File

@ -369,8 +369,7 @@ Foam::fvMatrix<Type>::fvMatrix
dimensions_(ds),
source_(psi.size(), Zero),
internalCoeffs_(psi.mesh().boundary().size()),
boundaryCoeffs_(psi.mesh().boundary().size()),
faceFluxCorrectionPtr_(nullptr)
boundaryCoeffs_(psi.mesh().boundary().size())
{
DebugInFunction
<< "Constructing fvMatrix<Type> for field " << psi_.name() << endl;
@ -410,16 +409,14 @@ Foam::fvMatrix<Type>::fvMatrix(const fvMatrix<Type>& fvm)
dimensions_(fvm.dimensions_),
source_(fvm.source_),
internalCoeffs_(fvm.internalCoeffs_),
boundaryCoeffs_(fvm.boundaryCoeffs_),
faceFluxCorrectionPtr_(nullptr)
boundaryCoeffs_(fvm.boundaryCoeffs_)
{
DebugInFunction
<< "Copying fvMatrix<Type> for field " << psi_.name() << endl;
if (fvm.faceFluxCorrectionPtr_)
{
faceFluxCorrectionPtr_ =
new GeometricField<Type, fvsPatchField, surfaceMesh>
faceFluxCorrectionPtr_ = std::make_unique<faceFluxFieldType>
(
*(fvm.faceFluxCorrectionPtr_)
);
@ -438,8 +435,7 @@ Foam::fvMatrix<Type>::fvMatrix(const tmp<fvMatrix<Type>>& tmat)
dimensions_(tmat().dimensions_),
source_(tmat.constCast().source_, tmat.movable()),
internalCoeffs_(tmat.constCast().internalCoeffs_, tmat.movable()),
boundaryCoeffs_(tmat.constCast().boundaryCoeffs_, tmat.movable()),
faceFluxCorrectionPtr_(nullptr)
boundaryCoeffs_(tmat.constCast().boundaryCoeffs_, tmat.movable())
{
DebugInFunction
<< "Copy/move fvMatrix<Type> for field " << psi_.name() << endl;
@ -447,14 +443,13 @@ Foam::fvMatrix<Type>::fvMatrix(const tmp<fvMatrix<Type>>& tmat)
if (tmat().faceFluxCorrectionPtr_)
{
if (tmat.movable())
{
faceFluxCorrectionPtr_ = tmat().faceFluxCorrectionPtr_;
tmat().faceFluxCorrectionPtr_ = nullptr;
}
else
{
faceFluxCorrectionPtr_ =
new GeometricField<Type, fvsPatchField, surfaceMesh>
std::move(tmat.constCast().faceFluxCorrectionPtr_);
}
else if (tmat().faceFluxCorrectionPtr_)
{
faceFluxCorrectionPtr_ = std::make_unique<faceFluxFieldType>
(
*(tmat().faceFluxCorrectionPtr_)
);
@ -473,7 +468,6 @@ Foam::fvMatrix<Type>::~fvMatrix()
DebugInFunction
<< "Destroying fvMatrix<Type> for field " << psi_.name() << endl;
deleteDemandDrivenData(faceFluxCorrectionPtr_);
subMatrices_.clear();
}
@ -1577,9 +1571,10 @@ void Foam::fvMatrix<Type>::operator=(const fvMatrix<Type>& fvmv)
}
else if (fvmv.faceFluxCorrectionPtr_)
{
faceFluxCorrectionPtr_ =
new GeometricField<Type, fvsPatchField, surfaceMesh>
(*fvmv.faceFluxCorrectionPtr_);
faceFluxCorrectionPtr_ = std::make_unique<faceFluxFieldType>
(
*fvmv.faceFluxCorrectionPtr_
);
}
useImplicit_ = fvmv.useImplicit_;
@ -1631,8 +1626,7 @@ void Foam::fvMatrix<Type>::operator+=(const fvMatrix<Type>& fvmv)
}
else if (fvmv.faceFluxCorrectionPtr_)
{
faceFluxCorrectionPtr_ = new
GeometricField<Type, fvsPatchField, surfaceMesh>
faceFluxCorrectionPtr_ = std::make_unique<faceFluxFieldType>
(
*fvmv.faceFluxCorrectionPtr_
);
@ -1669,9 +1663,10 @@ void Foam::fvMatrix<Type>::operator-=(const fvMatrix<Type>& fvmv)
}
else if (fvmv.faceFluxCorrectionPtr_)
{
faceFluxCorrectionPtr_ =
new GeometricField<Type, fvsPatchField, surfaceMesh>
(-*fvmv.faceFluxCorrectionPtr_);
faceFluxCorrectionPtr_ = std::make_unique<faceFluxFieldType>
(
-*fvmv.faceFluxCorrectionPtr_
);
}
}
@ -2002,7 +1997,7 @@ Foam::tmp<Foam::fvMatrix<Type>> Foam::correction
// Delete the faceFluxCorrection from the correction matrix
// as it does not have a clear meaning or purpose
deleteDemandDrivenData(tAcorr.ref().faceFluxCorrectionPtr());
tAcorr.ref().faceFluxCorrectionPtr(nullptr);
return tAcorr;
}
@ -2018,7 +2013,7 @@ Foam::tmp<Foam::fvMatrix<Type>> Foam::correction
// Delete the faceFluxCorrection from the correction matrix
// as it does not have a clear meaning or purpose
deleteDemandDrivenData(tAcorr.ref().faceFluxCorrectionPtr());
tAcorr.ref().faceFluxCorrectionPtr(nullptr);
return tAcorr;
}

View File

@ -172,7 +172,7 @@ private:
FieldField<Field, Type> boundaryCoeffs_;
//- Face flux field for non-orthogonal correction
mutable faceFluxFieldType* faceFluxCorrectionPtr_;
mutable std::unique_ptr<faceFluxFieldType> faceFluxCorrectionPtr_;
protected:
@ -494,8 +494,7 @@ public:
}
//- Declare return type of the faceFluxCorrectionPtr() function
typedef GeometricField<Type, fvsPatchField, surfaceMesh>
*faceFluxFieldPtrType;
typedef std::unique_ptr<faceFluxFieldType> faceFluxFieldPtrType;
//- Return pointer to face-flux non-orthogonal correction field
faceFluxFieldPtrType& faceFluxCorrectionPtr()
@ -503,6 +502,12 @@ public:
return faceFluxCorrectionPtr_;
}
//- Set pointer to face-flux non-orthogonal correction field
void faceFluxCorrectionPtr(faceFluxFieldType* flux)
{
faceFluxCorrectionPtr_.reset(flux);
}
//- True if face-flux non-orthogonal correction field exists
bool hasFaceFluxCorrection() const noexcept
{