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() ).ptr()
); );
deleteDemandDrivenData pEqnComps[phasei].faceFluxCorrectionPtr(nullptr);
(
pEqnComps[phasei].faceFluxCorrectionPtr()
);
pEqnComps[phasei].relax(); pEqnComps[phasei].relax();
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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