Commit 065db9a7 authored by Andrew Heather's avatar Andrew Heather

Merge branch 'enh-memory-cleanup' into 'develop'

autoPtr/tmp cleanup

See merge request !378
parents 53eda1c4 6d4928d5
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2014-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -129,12 +130,12 @@ Foam::BlendedInterfacialModel<modelType>::K() const
{
tmp<volScalarField> f1, f2;
if (model_.valid() || model1In2_.valid())
if (model_ || model1In2_)
{
f1 = blending_.f1(pair1In2_.dispersed(), pair2In1_.dispersed());
}
if (model_.valid() || model2In1_.valid())
if (model_ || model2In1_)
{
f2 = blending_.f2(pair1In2_.dispersed(), pair2In1_.dispersed());
}
......@@ -157,17 +158,17 @@ Foam::BlendedInterfacialModel<modelType>::K() const
)
);
if (model_.valid())
if (model_)
{
x.ref() += model_->K()*(f1() - f2());
}
if (model1In2_.valid())
if (model1In2_)
{
x.ref() += model1In2_->K()*(1 - f1);
}
if (model2In1_.valid())
if (model2In1_)
{
x.ref() += model2In1_->K()*f2;
}
......@@ -175,7 +176,7 @@ Foam::BlendedInterfacialModel<modelType>::K() const
if
(
correctFixedFluxBCs_
&& (model_.valid() || model1In2_.valid() || model2In1_.valid())
&& (model_ || model1In2_ || model2In1_)
)
{
correctFixedFluxBCs(x.ref());
......@@ -191,7 +192,7 @@ Foam::BlendedInterfacialModel<modelType>::Kf() const
{
tmp<surfaceScalarField> f1, f2;
if (model_.valid() || model1In2_.valid())
if (model_ || model1In2_)
{
f1 = fvc::interpolate
(
......@@ -199,7 +200,7 @@ Foam::BlendedInterfacialModel<modelType>::Kf() const
);
}
if (model_.valid() || model2In1_.valid())
if (model_ || model2In1_)
{
f2 = fvc::interpolate
(
......@@ -225,17 +226,17 @@ Foam::BlendedInterfacialModel<modelType>::Kf() const
)
);
if (model_.valid())
if (model_)
{
x.ref() += model_->Kf()*(f1() - f2());
}
if (model1In2_.valid())
if (model1In2_)
{
x.ref() += model1In2_->Kf()*(1 - f1);
}
if (model2In1_.valid())
if (model2In1_)
{
x.ref() += model2In1_->Kf()*f2;
}
......@@ -243,7 +244,7 @@ Foam::BlendedInterfacialModel<modelType>::Kf() const
if
(
correctFixedFluxBCs_
&& (model_.valid() || model1In2_.valid() || model2In1_.valid())
&& (model_ || model1In2_ || model2In1_)
)
{
correctFixedFluxBCs(x.ref());
......@@ -260,12 +261,12 @@ Foam::BlendedInterfacialModel<modelType>::F() const
{
tmp<volScalarField> f1, f2;
if (model_.valid() || model1In2_.valid())
if (model_ || model1In2_)
{
f1 = blending_.f1(pair1In2_.dispersed(), pair2In1_.dispersed());
}
if (model_.valid() || model2In1_.valid())
if (model_ || model2In1_)
{
f2 = blending_.f2(pair1In2_.dispersed(), pair2In1_.dispersed());
}
......@@ -285,17 +286,17 @@ Foam::BlendedInterfacialModel<modelType>::F() const
dimensioned<Type>(modelType::dimF, Zero)
);
if (model_.valid())
if (model_)
{
x.ref() += model_->F()*(f1() - f2());
}
if (model1In2_.valid())
if (model1In2_)
{
x.ref() += model1In2_->F()*(1 - f1);
}
if (model2In1_.valid())
if (model2In1_)
{
x.ref() -= model2In1_->F()*f2; // note : subtraction
}
......@@ -303,7 +304,7 @@ Foam::BlendedInterfacialModel<modelType>::F() const
if
(
correctFixedFluxBCs_
&& (model_.valid() || model1In2_.valid() || model2In1_.valid())
&& (model_ || model1In2_ || model2In1_)
)
{
correctFixedFluxBCs(x.ref());
......@@ -319,7 +320,7 @@ Foam::BlendedInterfacialModel<modelType>::Ff() const
{
tmp<surfaceScalarField> f1, f2;
if (model_.valid() || model1In2_.valid())
if (model_ || model1In2_)
{
f1 = fvc::interpolate
(
......@@ -327,7 +328,7 @@ Foam::BlendedInterfacialModel<modelType>::Ff() const
);
}
if (model_.valid() || model2In1_.valid())
if (model_ || model2In1_)
{
f2 = fvc::interpolate
(
......@@ -352,17 +353,17 @@ Foam::BlendedInterfacialModel<modelType>::Ff() const
x.ref().setOriented();
if (model_.valid())
if (model_)
{
x.ref() += model_->Ff()*(f1() - f2());
}
if (model1In2_.valid())
if (model1In2_)
{
x.ref() += model1In2_->Ff()*(1 - f1);
}
if (model2In1_.valid())
if (model2In1_)
{
x.ref() -= model2In1_->Ff()*f2; // note : subtraction
}
......@@ -370,7 +371,7 @@ Foam::BlendedInterfacialModel<modelType>::Ff() const
if
(
correctFixedFluxBCs_
&& (model_.valid() || model1In2_.valid() || model2In1_.valid())
&& (model_ || model1In2_ || model2In1_)
)
{
correctFixedFluxBCs(x.ref());
......@@ -386,12 +387,12 @@ Foam::BlendedInterfacialModel<modelType>::D() const
{
tmp<volScalarField> f1, f2;
if (model_.valid() || model1In2_.valid())
if (model_ || model1In2_)
{
f1 = blending_.f1(pair1In2_.dispersed(), pair2In1_.dispersed());
}
if (model_.valid() || model2In1_.valid())
if (model_ || model2In1_)
{
f2 = blending_.f2(pair1In2_.dispersed(), pair2In1_.dispersed());
}
......@@ -414,17 +415,17 @@ Foam::BlendedInterfacialModel<modelType>::D() const
)
);
if (model_.valid())
if (model_)
{
x.ref() += model_->D()*(f1() - f2());
}
if (model1In2_.valid())
if (model1In2_)
{
x.ref() += model1In2_->D()*(1 - f1);
}
if (model2In1_.valid())
if (model2In1_)
{
x.ref() += model2In1_->D()*f2;
}
......@@ -432,7 +433,7 @@ Foam::BlendedInterfacialModel<modelType>::D() const
if
(
correctFixedFluxBCs_
&& (model_.valid() || model1In2_.valid() || model2In1_.valid())
&& (model_ || model1In2_ || model2In1_)
)
{
correctFixedFluxBCs(x.ref());
......@@ -451,8 +452,8 @@ bool Foam::BlendedInterfacialModel<modelType>::hasModel
return
(
&phase == &(pair_.phase1())
? model1In2_.valid()
: model2In1_.valid()
? bool(model1In2_)
: bool(model2In1_)
);
}
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2014-2015 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -85,7 +86,7 @@ Foam::word Foam::orderedPhasePair::name() const
Foam::tmp<Foam::volScalarField> Foam::orderedPhasePair::E() const
{
if (!aspectRatio_.valid())
if (!aspectRatio_)
{
FatalErrorInFunction
<< "Aspect ratio model not specified for " << *this << "."
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2019 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -44,7 +44,7 @@ void testTransfer1(autoPtr<labelList> ap)
// Passed in copy, so automatically removes content
// Transfer would be nice, but not actually needed
Info<< "recv " << Switch::name(ap.valid()) << nl;
Info<< "recv " << Switch::name(bool(ap)) << nl;
}
......@@ -53,7 +53,7 @@ void testTransfer1(autoPtr<labelList> ap)
void testTransfer2(autoPtr<labelList>&& ap)
{
// As rvalue, so this time we actually get to manage content
Info<< "recv " << Switch::name(ap.valid()) << nl;
Info<< "recv " << Switch::name(bool(ap)) << nl;
}
......@@ -161,7 +161,7 @@ int main(int argc, char *argv[])
testTransfer2(std::move(list));
Info<<"now have valid=" << Switch::name(list.valid());
Info<<"now have valid=" << Switch::name(bool(list));
if (list)
{
......@@ -209,9 +209,9 @@ int main(int argc, char *argv[])
testTransfer2(std::move(list));
Info<<"now have valid=" << Switch::name(list.valid());
Info<<"now have valid=" << Switch::name(bool(list));
if (list.valid())
if (list)
{
Info<< nl
<< flatOutput(*list) << " @ " << name(list->cdata())
......@@ -229,7 +229,7 @@ int main(int argc, char *argv[])
auto ptr1 = autoPtr<labelList>::New();
auto ptr2 = autoPtr<labelList>::New();
Info<<"ptr valid: " << ptr1.valid() << nl;
Info<<"ptr valid: " << bool(ptr1) << nl;
// Refuses to compile (good!): ptr1 = new labelList(10);
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -53,8 +53,8 @@ Foam::token Foam::dictionaryTokens::keywordToken(const entry& e)
bool Foam::dictionaryTokens::setIterator() const
{
primIter_.clear();
dictIter_.clear();
primIter_.reset(nullptr);
dictIter_.reset(nullptr);
if (entryIter_ != dict_.cend())
{
......@@ -166,8 +166,8 @@ bool Foam::dictionaryTokens::good() const
entryIter_ != dict_.cend()
&&
(
(primIter_.valid() && primIter_().good())
|| (dictIter_.valid() && dictIter_().good())
(primIter_ && primIter_->good())
|| (dictIter_ && dictIter_->good())
)
);
}
......@@ -189,8 +189,8 @@ const Foam::token& Foam::dictionaryTokens::operator*() const
{
if (good())
{
if (primIter_.valid()) return *(primIter_());
if (dictIter_.valid()) return *(dictIter_());
if (primIter_) return *(*primIter_);
if (dictIter_) return *(*dictIter_);
}
return token::undefinedToken;
......@@ -251,8 +251,8 @@ bool Foam::dictionaryTokens::operator++()
if (ok)
{
if (primIter_.valid()) ok = ++(primIter_());
if (dictIter_.valid()) ok = ++(dictIter_());
if (primIter_) ok = ++(*primIter_);
if (dictIter_) ok = ++(*dictIter_);
if (!ok)
{
......
......@@ -137,9 +137,9 @@ label mergePatchFaces
// Faces in error.
labelHashSet errorFaces;
if (qualDictPtr.valid())
if (qualDictPtr)
{
motionSmoother::checkMesh(false, mesh, qualDictPtr(), errorFaces);
motionSmoother::checkMesh(false, mesh, *qualDictPtr, errorFaces);
}
else
{
......@@ -440,7 +440,7 @@ int main(int argc, char *argv[])
);
// Merge points on straight edges and remove unused points
if (qualDict.valid())
if (qualDict)
{
Info<< "Merging all 'loose' points on surface edges, "
<< "regardless of the angle they make." << endl;
......
......@@ -731,9 +731,9 @@ int main(int argc, char *argv[])
);
// Update
if (refDataPtr.valid())
if (refDataPtr)
{
refDataPtr().updateMesh(map());
refDataPtr->updateMesh(map());
}
// Store added cells
......@@ -815,9 +815,9 @@ int main(int argc, char *argv[])
polyMesh& mesh =
(
meshFromMesh.valid()
? meshFromMesh()
: meshFromSurface()
meshFromMesh
? *meshFromMesh
: *meshFromSurface
);
......@@ -896,9 +896,9 @@ int main(int argc, char *argv[])
updateFaceLabels(map(), backPatchFaces);
updateCellSet(map(), addedCellsSet);
if (refDataPtr.valid())
if (refDataPtr)
{
refDataPtr().updateMesh(map());
refDataPtr->updateMesh(map());
}
// Move mesh (if inflation used)
......@@ -1029,9 +1029,9 @@ int main(int argc, char *argv[])
// Update local data
updateCellSet(map(), addedCellsSet);
if (refDataPtr.valid())
if (refDataPtr)
{
refDataPtr().updateMesh(map());
refDataPtr->updateMesh(map());
}
// Move mesh (if inflation used)
......@@ -1067,9 +1067,9 @@ int main(int argc, char *argv[])
}
}
if (refDataPtr.valid())
if (refDataPtr)
{
refDataPtr().write();
refDataPtr->write();
}
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -625,7 +626,7 @@ void Foam::DistributedDelaunayMesh<Triangulation>::sync
return;
}
if (allBackgroundMeshBounds_.empty())
if (!allBackgroundMeshBounds_)
{
distributeBoundBoxes(bb);
}
......@@ -810,7 +811,7 @@ void Foam::DistributedDelaunayMesh<Triangulation>::sync(const boundBox& bb)
return;
}
if (allBackgroundMeshBounds_.empty())
if (!allBackgroundMeshBounds_)
{
distributeBoundBoxes(bb);
}
......
......@@ -539,7 +539,7 @@ Foam::label Foam::checkGeometry
<< nonAlignedPoints.name() << endl;
nonAlignedPoints.instance() = mesh.pointsInstance();
nonAlignedPoints.write();
if (setWriter.valid())
if (setWriter)
{
mergeAndWrite(*setWriter, nonAlignedPoints);
}
......@@ -573,7 +573,7 @@ Foam::label Foam::checkGeometry
<< " non closed cells to set " << cells.name() << endl;
cells.instance() = mesh.pointsInstance();
cells.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, cells);
}
......@@ -589,7 +589,7 @@ Foam::label Foam::checkGeometry
<< aspectCells.name() << endl;
aspectCells.instance() = mesh.pointsInstance();
aspectCells.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, aspectCells);
}
......@@ -610,7 +610,7 @@ Foam::label Foam::checkGeometry
<< " zero area faces to set " << faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, faces);
}
......@@ -632,7 +632,7 @@ Foam::label Foam::checkGeometry
<< " zero volume cells to set " << cells.name() << endl;
cells.instance() = mesh.pointsInstance();
cells.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, cells);
}
......@@ -655,7 +655,7 @@ Foam::label Foam::checkGeometry
<< " non-orthogonal faces to set " << faces.name() << endl;