Commit 3baebcb1 authored by Mark Olesen's avatar Mark Olesen

STYLE: replace uses of autoPtr::empty() with bool check (#1775)

- less clutter using plain tests with the bool operator:

      (!ptr)  vs  (ptr.empty())
      (ptr)   vs  (!ptr.empty())
parent 53eda1c4
......@@ -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);
}
......
......@@ -176,7 +176,7 @@ Foam::List<Foam::labelPair> Foam::mapDistributeBase::schedule
const Foam::List<Foam::labelPair>& Foam::mapDistributeBase::schedule() const
{
if (schedulePtr_.empty())
if (!schedulePtr_)
{
schedulePtr_.reset
(
......
......@@ -860,7 +860,7 @@ Foam::label Foam::polyMesh::nSolutionD() const
const Foam::labelIOList& Foam::polyMesh::tetBasePtIs() const
{
if (tetBasePtIsPtr_.empty())
if (!tetBasePtIsPtr_)
{
if (debug)
{
......@@ -894,7 +894,7 @@ const Foam::labelIOList& Foam::polyMesh::tetBasePtIs() const
const Foam::indexedOctree<Foam::treeDataCell>&
Foam::polyMesh::cellTree() const
{
if (cellTreePtr_.empty())
if (!cellTreePtr_)
{
treeBoundBox overallBb(points());
......@@ -1087,7 +1087,7 @@ const Foam::labelList& Foam::polyMesh::faceNeighbour() const
const Foam::pointField& Foam::polyMesh::oldPoints() const
{
if (oldPointsPtr_.empty())
if (!oldPointsPtr_)
{
if (debug)
{
......@@ -1233,7 +1233,7 @@ void Foam::polyMesh::resetMotion() const
const Foam::globalMeshData& Foam::polyMesh::globalData() const
{
if (globalMeshDataPtr_.empty())
if (!globalMeshDataPtr_)
{
if (debug)
{
......
......@@ -206,7 +206,7 @@ const solidType& thermalBaffle1DFvPatchScalarField<solidType>::solid() const
{
if (this->owner())
{
if (solidPtr_.empty())
if (!solidPtr_)
{
solidPtr_.reset(new solidType(solidDict_));
}
......
......@@ -91,7 +91,7 @@ Foam::pointHistory::pointHistory
refHistoryPoint_(dict.lookup("refHistoryPoint")),
processor_(-1),
fileName_(dict.get<word>("fileName")),
historyFilePtr_()
historyFilePtr_(nullptr)
{
Info<< "Creating " << this->name() << " function object." << endl;
......@@ -144,7 +144,7 @@ Foam::pointHistory::pointHistory
}
// Create history file if not already created
if (historyFilePtr_.empty())
if (!historyFilePtr_)
{
// File update
if (Pstream::master())
......@@ -180,13 +180,11 @@ Foam::pointHistory::pointHistory
);
// Add headers to output data
if (historyFilePtr_.valid())
if (historyFilePtr_)
{
historyFilePtr_()
<< "# Time" << tab << "X" << tab
<< "Y" << tab << "Z";
historyFilePtr_() << endl;
<< "# Time" << tab << "X" << tab << "Y" << tab << "Z"
<< endl;
}
}
}
......
......@@ -190,7 +190,7 @@ const Foam::pointToPointPlanarInterpolation&
Foam::turbulentDFSEMInletFvPatchVectorField::patchMapper() const
{
// Initialise interpolation (2D planar interpolation by triangulation)
if (mapperPtr_.empty())
if (!mapperPtr_)
{
const fileName samplePointsFile
(
......
......@@ -36,7 +36,7 @@ const Foam::pointToPointPlanarInterpolation&
Foam::turbulentDigitalFilterInletFvPatchVectorField::patchMapper() const
{
// Initialise interpolation (2D planar interpolation by triangulation)
if (mapperPtr_.empty())
if (!mapperPtr_)
{
// Reread values and interpolate
const fileName samplePointsFile
......
......@@ -65,7 +65,7 @@ Foam::functionObjects::streamLineBase::trackDirTypeNames
const Foam::word&
Foam::functionObjects::streamLineBase::sampledSetAxis() const
{
if (sampledSetPtr_.empty())
if (!sampledSetPtr_)
{
sampledSetPoints();
}
......@@ -77,7 +77,7 @@ Foam::functionObjects::streamLineBase::sampledSetAxis() const
const Foam::sampledSet&
Foam::functionObjects::streamLineBase::sampledSetPoints() const
{
if (sampledSetPtr_.empty())
if (!sampledSetPtr_)
{
sampledSetPtr_ = sampledSet::New
(
......
......@@ -394,7 +394,7 @@ surfaceDisplacementPointPatchVectorField
const Foam::searchableSurfaces&
Foam::surfaceDisplacementPointPatchVectorField::surfaces() const
{
if (surfacesPtr_.empty())
if (!surfacesPtr_)
{
surfacesPtr_.reset
(
......
......@@ -380,7 +380,7 @@ surfaceSlipDisplacementPointPatchVectorField
const Foam::searchableSurfaces&
Foam::surfaceSlipDisplacementPointPatchVectorField::surfaces() const
{
if (surfacesPtr_.empty())
if (!surfacesPtr_)
{
surfacesPtr_.reset
(
......
......@@ -501,7 +501,7 @@ void Foam::fv::directionalPressureGradientExplicitSource::constrain
const label
)
{
if (invAPtr_.empty())
if (!invAPtr_)
{
invAPtr_.reset
(
......
......@@ -237,7 +237,7 @@ void Foam::fv::meanVelocityForce::constrain
const label
)
{
if (rAPtr_.empty())
if (!rAPtr_)
{
rAPtr_.reset
(
......
......@@ -139,7 +139,7 @@ void Foam::KinematicCloud<CloudType>::solve
template<class CloudType>
void Foam::KinematicCloud<CloudType>::buildCellOccupancy()
{
if (cellOccupancyPtr_.empty())
if (!cellOccupancyPtr_)
{
cellOccupancyPtr_.reset
(
......@@ -174,7 +174,7 @@ void Foam::KinematicCloud<CloudType>::updateCellOccupancy()
// Only build the cellOccupancy if the pointer is set, i.e. it has
// been requested before.
if (cellOccupancyPtr_.valid())
if (cellOccupancyPtr_)
{
buildCellOccupancy();
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -370,7 +370,7 @@ template<class CloudType>
inline Foam::List<Foam::DynamicList<typename CloudType::particleType*>>&
Foam::KinematicCloud<CloudType>::cellOccupancy()
{
if (cellOccupancyPtr_.empty())
if (!cellOccupancyPtr_)
{
buildCellOccupancy();
}
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -150,10 +151,10 @@ inline const Foam::mapDistribute& Foam::mappedPatchBase::map() const
if (topoChange)
{
mapPtr_.clear();
mapPtr_.reset(nullptr);
}
if (mapPtr_.empty())
if (!mapPtr_)
{
calcMapping();
}
......
......@@ -644,7 +644,7 @@ void Foam::triSurfaceMesh::movePoints(const pointField& newPoints)
const Foam::indexedOctree<Foam::treeDataEdge>&
Foam::triSurfaceMesh::edgeTree() const
{
if (edgeTree_.empty())
if (!edgeTree_)
{
if (debug)
{
......
......@@ -205,7 +205,7 @@ void Foam::triSurfaceSearch::clearOut()
const Foam::indexedOctree<Foam::treeDataTriSurface>&
Foam::triSurfaceSearch::tree() const
{
if (treePtr_.empty())
if (!treePtr_)
{
// Calculate bb without constructing local point numbering.
treeBoundBox bb(Zero, Zero);
......
......@@ -7,7 +7,7 @@
-------------------------------------------------------------------------------
Copyright (C) 2007-2020 PCOpt/NTUA
Copyright (C) 2013-2020 FOSS GP
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -143,7 +143,7 @@ adjointBoundaryCondition<Type>::computePatchGrad(word name)
template<class Type>
bool adjointBoundaryCondition<Type>::addATCUaGradUTerm()
{
if (addATCUaGradUTerm_.empty())
if (!addATCUaGradUTerm_)
{
addATCUaGradUTerm_.reset(new bool(isA<ATCUaGradU>(getATC())));
}
......
......@@ -83,7 +83,7 @@ bool objectiveForceTarget::write(const bool valid) const
// in order to avoid various instantiations of the same objective
// opening the same file
unsigned int width = IOstream::defaultPrecision() + 5;
if (objFunctionFilePtr_.empty())
if (!objFunctionFilePtr_)
{
setObjectiveFilePtr();
objFunctionFilePtr_()
......
......@@ -130,7 +130,7 @@ autoPtr<objectiveIncompressible> objectiveIncompressible::New
void objectiveIncompressible::doNormalization()
{
if (normalize_ && normFactor_.valid())
if (normalize_ && normFactor_)
{
const scalar oneOverNorm(1./normFactor_());
......@@ -191,7 +191,7 @@ void objectiveIncompressible::doNormalization()
const volVectorField& objectiveIncompressible::dJdv()
{
if (dJdvPtr_.empty())
if (!dJdvPtr_)
{
// If pointer is not set, set it to a zero field
dJdvPtr_.reset
......@@ -210,7 +210,7 @@ const volVectorField& objectiveIncompressible::dJdv()
const volScalarField& objectiveIncompressible::dJdp()
{
if (dJdpPtr_.empty())
if (!dJdpPtr_)
{
// If pointer is not set, set it to a zero field
dJdpPtr_.reset
......@@ -229,7 +229,7 @@ const volScalarField& objectiveIncompressible::dJdp()
const volScalarField& objectiveIncompressible::dJdT()
{
if (dJdTPtr_.empty())
if (!dJdTPtr_)
{
// If pointer is not set, set it to a zero field
dJdTPtr_.reset
......@@ -248,7 +248,7 @@ const volScalarField& objectiveIncompressible::dJdT()
const volScalarField& objectiveIncompressible::dJdTMvar1()
{
if (dJdTMvar1Ptr_.empty())
if (!dJdTMvar1Ptr_)
{
// If pointer is not set, set it to a zero field
dJdTMvar1Ptr_.reset
......@@ -267,7 +267,7 @@ const volScalarField& objectiveIncompressible::dJdTMvar1()
const volScalarField& objectiveIncompressible::dJdTMvar2()
{
if (dJdTMvar2Ptr_.empty())
if (!dJdTMvar2Ptr_)
{
// If pointer is not set, set it to a zero field
dJdTMvar2Ptr_.reset
......@@ -289,7 +289,7 @@ const fvPatchVectorField& objectiveIncompressible::boundarydJdv
const label patchI
)
{
if (bdJdvPtr_.empty())
if (!bdJdvPtr_)
{
bdJdvPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
}
......@@ -302,7 +302,7 @@ const fvPatchScalarField& objectiveIncompressible::boundarydJdvn
const label patchI
)
{
if (bdJdvnPtr_.empty())
if (!bdJdvnPtr_)
{
bdJdvnPtr_.reset(createZeroBoundaryPtr<scalar>(mesh_));
}
......@@ -315,7 +315,7 @@ const fvPatchVectorField& objectiveIncompressible::boundarydJdvt
const label patchI
)
{
if (bdJdvtPtr_.empty())
if (!bdJdvtPtr_)
{
bdJdvtPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
}
......@@ -328,7 +328,7 @@ const fvPatchVectorField& objectiveIncompressible::boundarydJdp
const label patchI
)
{
if (bdJdpPtr_.empty())
if (!bdJdpPtr_)
{
bdJdpPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
}
......@@ -341,7 +341,7 @@ const fvPatchScalarField& objectiveIncompressible::boundarydJdT
const label patchI
)
{
if (bdJdTPtr_.empty())
if (!bdJdTPtr_)
{
bdJdTPtr_.reset(createZeroBoundaryPtr<scalar>(mesh_));
}
......@@ -354,7 +354,7 @@ const fvPatchScalarField& objectiveIncompressible::boundarydJdTMvar1
const label patchI
)
{
if (bdJdTMvar1Ptr_.empty())
if (!bdJdTMvar1Ptr_)
{
bdJdTMvar1Ptr_.reset(createZeroBoundaryPtr<scalar>(mesh_));
}
......@@ -367,7 +367,7 @@ const fvPatchScalarField& objectiveIncompressible::boundarydJdTMvar2
const label patchI
)
{
if (bdJdTMvar2Ptr_.empty())
if (!bdJdTMvar2Ptr_)
{
bdJdTMvar2Ptr_.reset(createZeroBoundaryPtr<scalar>(mesh_));
}
......@@ -377,7 +377,7 @@ const fvPatchScalarField& objectiveIncompressible::boundarydJdTMvar2
const boundaryVectorField& objectiveIncompressible::boundarydJdv()
{
if (bdJdvPtr_.empty())
if (!bdJdvPtr_)
{
bdJdvPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
}
......@@ -387,7 +387,7 @@ const boundaryVectorField& objectiveIncompressible::boundarydJdv()
const boundaryScalarField& objectiveIncompressible::boundarydJdvn()
{
if (bdJdvnPtr_.empty())
if (!bdJdvnPtr_)
{
bdJdvnPtr_.reset(createZeroBoundaryPtr<scalar>(mesh_));
}
......@@ -397,7 +397,7 @@ const boundaryScalarField& objectiveIncompressible::boundarydJdvn()
const boundaryVectorField& objectiveIncompressible::boundarydJdvt()
{
if (bdJdvtPtr_.empty())
if (!bdJdvtPtr_)
{
bdJdvtPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
}
......@@ -407,7 +407,7 @@ const boundaryVectorField& objectiveIncompressible::boundarydJdvt()
const boundaryVectorField& objectiveIncompressible::boundarydJdp()
{
if (bdJdpPtr_.empty())
if (!bdJdpPtr_)
{
bdJdpPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
}
......@@ -417,7 +417,7 @@ const boundaryVectorField& objectiveIncompressible::boundarydJdp()
const boundaryScalarField& objectiveIncompressible::boundarydJdT()
{
if (bdJdTPtr_.empty())
if (!bdJdTPtr_)
{
bdJdTPtr_.reset(createZeroBoundaryPtr<scalar>(mesh_));
}
......@@ -427,7 +427,7 @@ const boundaryScalarField& objectiveIncompressible::boundarydJdT()
const boundaryScalarField& objectiveIncompressible::boundarydJdTMvar1()
{
if (bdJdTMvar1Ptr_.empty())
if (!bdJdTMvar1Ptr_)
{
bdJdTMvar1Ptr_.reset(createZeroBoundaryPtr<scalar>(mesh_));
}
......@@ -437,7 +437,7 @@ const boundaryScalarField& objectiveIncompressible::boundarydJdTMvar1()
const boundaryScalarField& objectiveIncompressible::boundarydJdTMvar2()
{
if (bdJdTMvar2Ptr_.empty())
if (!bdJdTMvar2Ptr_)
{
bdJdTMvar2Ptr_.reset(createZeroBoundaryPtr<scalar>(mesh_));
}
......
......@@ -137,7 +137,7 @@ bool objectivePartialVolume::write(const bool valid) const
// in order to avoid various instantiations of the same objective
// opening the same file
unsigned int width = IOstream::defaultPrecision() + 6;
if (objFunctionFilePtr_.empty())
if (!objFunctionFilePtr_)
{
setObjectiveFilePtr();
objFunctionFilePtr_() << setw(4) << "#" << " ";
......
......@@ -242,7 +242,7 @@ bool objectivePtLosses::write(const bool valid) const
// in order to avoid various instantiations of the same objective
// opening the same file
unsigned int width = IOstream::defaultPrecision() + 5;
if (objFunctionFilePtr_.empty())
if (!objFunctionFilePtr_)
{
setObjectiveFilePtr();
objFunctionFilePtr_() << setw(4) << "#" << " ";
......
......@@ -256,7 +256,7 @@ scalar objective::JCycle() const
J -= target_;
// Normalize here, in order to get the correct value for line search
if (normalize_ && normFactor_.valid())
if (normalize_ && normFactor_)
{
J /= normFactor_();
}
......@@ -267,7 +267,7 @@ scalar objective::JCycle() const
void objective::updateNormalizationFactor()
{
if (normalize_ && normFactor_.empty())
if (normalize_ && !normFactor_)
{
normFactor_.reset(new scalar(JCycle()));
}
......@@ -327,7 +327,7 @@ bool objective::normalize() const
void objective::doNormalization()
{
if (normalize_ && normFactor_.valid())
if (normalize_ && normFactor_)
{
const scalar oneOverNorm(1./normFactor_());
......@@ -414,7 +414,7 @@ void objective::incrementIntegrationTimes(const scalar timeSpan)
const volScalarField& objective::dJdb()
{
if (dJdbPtr_.empty())
if (!dJdbPtr_)
{
// If pointer is not set, set it to a zero field
dJdbPtr_.reset
......@@ -434,7 +434,7 @@ const volScalarField& objective::dJdb()
const fvPatchVectorField& objective::boundarydJdb(const label patchI)
{
if (bdJdbPtr_.empty())
if (!bdJdbPtr_)
{
bdJdbPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
}
......@@ -444,7 +444,7 @@ const fvPatchVectorField& objective::boundarydJdb(const label patchI)
const fvPatchVectorField& objective::dSdbMultiplier(const label patchI)
{
if (bdSdbMultPtr_.empty())
if (!bdSdbMultPtr_)
{
bdSdbMultPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
}
......@@ -454,7 +454,7 @@ const fvPatchVectorField& objective::dSdbMultiplier(const label patchI)
const fvPatchVectorField& objective::dndbMultiplier(const label patchI)
{
if (bdndbMultPtr_.empty())
if (!bdndbMultPtr_)
{
bdndbMultPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
}
......@@ -464,7 +464,7 @@ const fvPatchVectorField& objective::dndbMultiplier(const label patchI)
const fvPatchVectorField& objective::dxdbMultiplier(const label patchI)
{
if (bdxdbMultPtr_.empty())
if (!bdxdbMultPtr_)
{
bdxdbMultPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
}
......@@ -474,7 +474,7 @@ const fvPatchVectorField& objective::dxdbMultiplier(const label patchI)
const fvPatchVectorField& objective::dxdbDirectMultiplier(const label patchI)
{
if (bdxdbDirectMultPtr_.empty())
if (!bdxdbDirectMultPtr_)
{
bdxdbDirectMultPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
}
......@@ -488,7 +488,7 @@ const vectorField& objective::boundaryEdgeMultiplier
const label edgeI
)
{
if (bdxdbDirectMultPtr_.empty())
if (!bdxdbDirectMultPtr_)
{
FatalErrorInFunction
<< "Unallocated boundaryEdgeMultiplier field"
......@@ -500,7 +500,7 @@ const vectorField& objective::boundaryEdgeMultiplier
const fvPatchTensorField& objective::boundarydJdStress(const label patchI)
{
if (bdJdStressPtr_.empty())
if (!bdJdStressPtr_)
{
bdJdStressPtr_.reset(createZeroBoundaryPtr<tensor>(mesh_));
}
......@@ -510,7 +510,7 @@ const fvPatchTensorField& objective::boundarydJdStress(const label patchI)
const boundaryVectorField& objective::boundarydJdb()
{
if (bdJdbPtr_.empty())
if (!bdJdbPtr_)
{
bdJdbPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
}
......@@ -520,7 +520,7 @@ const boundaryVectorField& objective::boundarydJdb()
const boundaryVectorField& objective::dSdbMultiplier<