STYLE: simplify short-circuit involving autoPtr (#1775)

- with '&&' conditions, often better to check for non-null autoPtr
  first (it is cheap)

- check as bool instead of valid() method for cleaner code, especially
  when the wrapped item itself has a valid/empty or good.
  Also when handling multiple checks.

  Now
      if (ptr && ptr->valid())
      if (ptr1 || ptr2)

  instead
      if (ptr.valid() && ptr->valid())
      if (ptr1.valid() || ptr2.valid())
This commit is contained in:
Mark Olesen
2020-07-15 08:50:57 +02:00
parent 3baebcb101
commit 9af3f85cf9
35 changed files with 118 additions and 123 deletions

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2014-2016 OpenFOAM Foundation Copyright (C) 2014-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -129,12 +130,12 @@ Foam::BlendedInterfacialModel<modelType>::K() const
{ {
tmp<volScalarField> f1, f2; tmp<volScalarField> f1, f2;
if (model_.valid() || model1In2_.valid()) if (model_ || model1In2_)
{ {
f1 = blending_.f1(pair1In2_.dispersed(), pair2In1_.dispersed()); f1 = blending_.f1(pair1In2_.dispersed(), pair2In1_.dispersed());
} }
if (model_.valid() || model2In1_.valid()) if (model_ || model2In1_)
{ {
f2 = blending_.f2(pair1In2_.dispersed(), pair2In1_.dispersed()); 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()); x.ref() += model_->K()*(f1() - f2());
} }
if (model1In2_.valid()) if (model1In2_)
{ {
x.ref() += model1In2_->K()*(1 - f1); x.ref() += model1In2_->K()*(1 - f1);
} }
if (model2In1_.valid()) if (model2In1_)
{ {
x.ref() += model2In1_->K()*f2; x.ref() += model2In1_->K()*f2;
} }
@ -175,7 +176,7 @@ Foam::BlendedInterfacialModel<modelType>::K() const
if if
( (
correctFixedFluxBCs_ correctFixedFluxBCs_
&& (model_.valid() || model1In2_.valid() || model2In1_.valid()) && (model_ || model1In2_ || model2In1_)
) )
{ {
correctFixedFluxBCs(x.ref()); correctFixedFluxBCs(x.ref());
@ -191,7 +192,7 @@ Foam::BlendedInterfacialModel<modelType>::Kf() const
{ {
tmp<surfaceScalarField> f1, f2; tmp<surfaceScalarField> f1, f2;
if (model_.valid() || model1In2_.valid()) if (model_ || model1In2_)
{ {
f1 = fvc::interpolate f1 = fvc::interpolate
( (
@ -199,7 +200,7 @@ Foam::BlendedInterfacialModel<modelType>::Kf() const
); );
} }
if (model_.valid() || model2In1_.valid()) if (model_ || model2In1_)
{ {
f2 = fvc::interpolate f2 = fvc::interpolate
( (
@ -225,17 +226,17 @@ Foam::BlendedInterfacialModel<modelType>::Kf() const
) )
); );
if (model_.valid()) if (model_)
{ {
x.ref() += model_->Kf()*(f1() - f2()); x.ref() += model_->Kf()*(f1() - f2());
} }
if (model1In2_.valid()) if (model1In2_)
{ {
x.ref() += model1In2_->Kf()*(1 - f1); x.ref() += model1In2_->Kf()*(1 - f1);
} }
if (model2In1_.valid()) if (model2In1_)
{ {
x.ref() += model2In1_->Kf()*f2; x.ref() += model2In1_->Kf()*f2;
} }
@ -243,7 +244,7 @@ Foam::BlendedInterfacialModel<modelType>::Kf() const
if if
( (
correctFixedFluxBCs_ correctFixedFluxBCs_
&& (model_.valid() || model1In2_.valid() || model2In1_.valid()) && (model_ || model1In2_ || model2In1_)
) )
{ {
correctFixedFluxBCs(x.ref()); correctFixedFluxBCs(x.ref());
@ -260,12 +261,12 @@ Foam::BlendedInterfacialModel<modelType>::F() const
{ {
tmp<volScalarField> f1, f2; tmp<volScalarField> f1, f2;
if (model_.valid() || model1In2_.valid()) if (model_ || model1In2_)
{ {
f1 = blending_.f1(pair1In2_.dispersed(), pair2In1_.dispersed()); f1 = blending_.f1(pair1In2_.dispersed(), pair2In1_.dispersed());
} }
if (model_.valid() || model2In1_.valid()) if (model_ || model2In1_)
{ {
f2 = blending_.f2(pair1In2_.dispersed(), pair2In1_.dispersed()); f2 = blending_.f2(pair1In2_.dispersed(), pair2In1_.dispersed());
} }
@ -285,17 +286,17 @@ Foam::BlendedInterfacialModel<modelType>::F() const
dimensioned<Type>(modelType::dimF, Zero) dimensioned<Type>(modelType::dimF, Zero)
); );
if (model_.valid()) if (model_)
{ {
x.ref() += model_->F()*(f1() - f2()); x.ref() += model_->F()*(f1() - f2());
} }
if (model1In2_.valid()) if (model1In2_)
{ {
x.ref() += model1In2_->F()*(1 - f1); x.ref() += model1In2_->F()*(1 - f1);
} }
if (model2In1_.valid()) if (model2In1_)
{ {
x.ref() -= model2In1_->F()*f2; // note : subtraction x.ref() -= model2In1_->F()*f2; // note : subtraction
} }
@ -303,7 +304,7 @@ Foam::BlendedInterfacialModel<modelType>::F() const
if if
( (
correctFixedFluxBCs_ correctFixedFluxBCs_
&& (model_.valid() || model1In2_.valid() || model2In1_.valid()) && (model_ || model1In2_ || model2In1_)
) )
{ {
correctFixedFluxBCs(x.ref()); correctFixedFluxBCs(x.ref());
@ -319,7 +320,7 @@ Foam::BlendedInterfacialModel<modelType>::Ff() const
{ {
tmp<surfaceScalarField> f1, f2; tmp<surfaceScalarField> f1, f2;
if (model_.valid() || model1In2_.valid()) if (model_ || model1In2_)
{ {
f1 = fvc::interpolate f1 = fvc::interpolate
( (
@ -327,7 +328,7 @@ Foam::BlendedInterfacialModel<modelType>::Ff() const
); );
} }
if (model_.valid() || model2In1_.valid()) if (model_ || model2In1_)
{ {
f2 = fvc::interpolate f2 = fvc::interpolate
( (
@ -352,17 +353,17 @@ Foam::BlendedInterfacialModel<modelType>::Ff() const
x.ref().setOriented(); x.ref().setOriented();
if (model_.valid()) if (model_)
{ {
x.ref() += model_->Ff()*(f1() - f2()); x.ref() += model_->Ff()*(f1() - f2());
} }
if (model1In2_.valid()) if (model1In2_)
{ {
x.ref() += model1In2_->Ff()*(1 - f1); x.ref() += model1In2_->Ff()*(1 - f1);
} }
if (model2In1_.valid()) if (model2In1_)
{ {
x.ref() -= model2In1_->Ff()*f2; // note : subtraction x.ref() -= model2In1_->Ff()*f2; // note : subtraction
} }
@ -370,7 +371,7 @@ Foam::BlendedInterfacialModel<modelType>::Ff() const
if if
( (
correctFixedFluxBCs_ correctFixedFluxBCs_
&& (model_.valid() || model1In2_.valid() || model2In1_.valid()) && (model_ || model1In2_ || model2In1_)
) )
{ {
correctFixedFluxBCs(x.ref()); correctFixedFluxBCs(x.ref());
@ -386,12 +387,12 @@ Foam::BlendedInterfacialModel<modelType>::D() const
{ {
tmp<volScalarField> f1, f2; tmp<volScalarField> f1, f2;
if (model_.valid() || model1In2_.valid()) if (model_ || model1In2_)
{ {
f1 = blending_.f1(pair1In2_.dispersed(), pair2In1_.dispersed()); f1 = blending_.f1(pair1In2_.dispersed(), pair2In1_.dispersed());
} }
if (model_.valid() || model2In1_.valid()) if (model_ || model2In1_)
{ {
f2 = blending_.f2(pair1In2_.dispersed(), pair2In1_.dispersed()); 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()); x.ref() += model_->D()*(f1() - f2());
} }
if (model1In2_.valid()) if (model1In2_)
{ {
x.ref() += model1In2_->D()*(1 - f1); x.ref() += model1In2_->D()*(1 - f1);
} }
if (model2In1_.valid()) if (model2In1_)
{ {
x.ref() += model2In1_->D()*f2; x.ref() += model2In1_->D()*f2;
} }
@ -432,7 +433,7 @@ Foam::BlendedInterfacialModel<modelType>::D() const
if if
( (
correctFixedFluxBCs_ correctFixedFluxBCs_
&& (model_.valid() || model1In2_.valid() || model2In1_.valid()) && (model_ || model1In2_ || model2In1_)
) )
{ {
correctFixedFluxBCs(x.ref()); correctFixedFluxBCs(x.ref());
@ -451,8 +452,8 @@ bool Foam::BlendedInterfacialModel<modelType>::hasModel
return return
( (
&phase == &(pair_.phase1()) &phase == &(pair_.phase1())
? model1In2_.valid() ? bool(model1In2_)
: model2In1_.valid() : bool(model2In1_)
); );
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017 OpenCFD Ltd. Copyright (C) 2017-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -53,8 +53,8 @@ Foam::token Foam::dictionaryTokens::keywordToken(const entry& e)
bool Foam::dictionaryTokens::setIterator() const bool Foam::dictionaryTokens::setIterator() const
{ {
primIter_.clear(); primIter_.reset(nullptr);
dictIter_.clear(); dictIter_.reset(nullptr);
if (entryIter_ != dict_.cend()) if (entryIter_ != dict_.cend())
{ {
@ -166,8 +166,8 @@ bool Foam::dictionaryTokens::good() const
entryIter_ != dict_.cend() entryIter_ != dict_.cend()
&& &&
( (
(primIter_.valid() && primIter_().good()) (primIter_ && primIter_->good())
|| (dictIter_.valid() && dictIter_().good()) || (dictIter_ && dictIter_->good())
) )
); );
} }
@ -189,8 +189,8 @@ const Foam::token& Foam::dictionaryTokens::operator*() const
{ {
if (good()) if (good())
{ {
if (primIter_.valid()) return *(primIter_()); if (primIter_) return *(*primIter_);
if (dictIter_.valid()) return *(dictIter_()); if (dictIter_) return *(*dictIter_);
} }
return token::undefinedToken; return token::undefinedToken;
@ -251,8 +251,8 @@ bool Foam::dictionaryTokens::operator++()
if (ok) if (ok)
{ {
if (primIter_.valid()) ok = ++(primIter_()); if (primIter_) ok = ++(*primIter_);
if (dictIter_.valid()) ok = ++(dictIter_()); if (dictIter_) ok = ++(*dictIter_);
if (!ok) if (!ok)
{ {

View File

@ -815,9 +815,9 @@ int main(int argc, char *argv[])
polyMesh& mesh = polyMesh& mesh =
( (
meshFromMesh.valid() meshFromMesh
? meshFromMesh() ? *meshFromMesh
: meshFromSurface() : *meshFromSurface
); );

View File

@ -954,7 +954,7 @@ Foam::label Foam::checkGeometry
patchWriter.reset(new surfaceWriters::vtkWriter()); patchWriter.reset(new surfaceWriters::vtkWriter());
} }
surfaceWriter& wr = (surfWriter.valid() ? *surfWriter : *patchWriter); surfaceWriter& wr = (surfWriter ? *surfWriter : *patchWriter);
// Currently only do AMI checks // Currently only do AMI checks

View File

@ -1415,9 +1415,9 @@ autoPtr<mapDistributePolyMesh> createReconstructMap
autoPtr<mapDistributePolyMesh> mapPtr; autoPtr<mapDistributePolyMesh> mapPtr;
if (baseMeshPtr.valid() && baseMeshPtr().nCells()) if (baseMeshPtr && baseMeshPtr->nCells())
{ {
const fvMesh& baseMesh = baseMeshPtr(); const fvMesh& baseMesh = *baseMeshPtr;
labelListList cellSubMap(Pstream::nProcs()); labelListList cellSubMap(Pstream::nProcs());
cellSubMap[Pstream::masterNo()] = identity(mesh.nCells()); cellSubMap[Pstream::masterNo()] = identity(mesh.nCells());

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -56,7 +56,7 @@ if (doFiniteArea)
FatalError.throwExceptions(throwing); FatalError.throwExceptions(throwing);
} }
if (faMeshPtr.valid() && nAreaFields) if (faMeshPtr && nAreaFields)
{ {
reportFields::area(Info, objects); reportFields::area(Info, objects);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -85,7 +85,7 @@ bool writeDimField
const auto& field = tfield(); const auto& field = tfield();
if (internalWriter.valid() && pInterp.valid()) if (internalWriter && pInterp)
{ {
internalWriter->write(field, *pInterp); internalWriter->write(field, *pInterp);
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -99,7 +99,7 @@ bool writeVolField
const auto& field = tfield(); const auto& field = tfield();
// Internal // Internal
if (internalWriter.valid() && pInterp.valid()) if (internalWriter && pInterp)
{ {
internalWriter->write(field, *pInterp); internalWriter->write(field, *pInterp);
} }

View File

@ -723,7 +723,7 @@ int main(int argc, char *argv[])
mesh.readUpdate(); mesh.readUpdate();
if (args.found("dummy-phi") && !dummyPhi.valid()) if (args.found("dummy-phi") && !dummyPhi)
{ {
Info<< "Adding a dummy phi" << endl; Info<< "Adding a dummy phi" << endl;
dummyPhi.reset dummyPhi.reset

View File

@ -1043,7 +1043,7 @@ int main(int argc, char *argv[])
// ) // )
// ); // );
// //
// if (hitInfo.hit() && intStreamPtr.valid()) // if (hitInfo.hit() && intStreamPtr)
// { // {
// intStreamPtr().write(hitInfo.hitPoint()); // intStreamPtr().write(hitInfo.hitPoint());
// //

View File

@ -346,14 +346,14 @@ int main(int argc, char *argv[])
// Load a single file, or load and combine multiple selected files // Load a single file, or load and combine multiple selected files
autoPtr<triSurface> surfPtr = loader.load(loadingOption, scaleFactor); autoPtr<triSurface> surfPtr = loader.load(loadingOption, scaleFactor);
if (!surfPtr.valid() || surfPtr().empty()) if (!surfPtr || surfPtr->empty())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Problem loading surface(s) for entry: " << "Problem loading surface(s) for entry: "
<< dictName << exit(FatalError); << dictName << exit(FatalError);
} }
triSurface surf = surfPtr(); triSurface surf = *surfPtr;
Info<< nl Info<< nl
<< "Statistics:" << nl; << "Statistics:" << nl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2018 OpenFOAM Foundation Copyright (C) 2011-2018 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd. Copyright (C) 2015-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -185,7 +185,7 @@ void Foam::regIOobject::close()
{ {
Pout<< "regIOobject::close() : " Pout<< "regIOobject::close() : "
<< "finished reading " << "finished reading "
<< (isPtr_.valid() ? isPtr_().name() : "dummy") << (isPtr_ ? isPtr_->name() : "dummy")
<< endl; << endl;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd. Copyright (C) 2015-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -128,8 +128,8 @@ void Foam::globalMeshData::calcSharedPoints() const
if if
( (
nGlobalPoints_ != -1 nGlobalPoints_ != -1
|| sharedPointLabelsPtr_.valid() || sharedPointLabelsPtr_
|| sharedPointAddrPtr_.valid() || sharedPointAddrPtr_
) )
{ {
FatalErrorInFunction FatalErrorInFunction
@ -295,8 +295,8 @@ void Foam::globalMeshData::calcSharedEdges() const
if if
( (
nGlobalEdges_ != -1 nGlobalEdges_ != -1
|| sharedEdgeLabelsPtr_.valid() || sharedEdgeLabelsPtr_
|| sharedEdgeAddrPtr_.valid() || sharedEdgeAddrPtr_
) )
{ {
FatalErrorInFunction FatalErrorInFunction

View File

@ -190,7 +190,7 @@ bool Foam::expressions::fvExprDriver::readDict
{ {
ITstream& is = eptr->stream(); ITstream& is = eptr->stream();
if (writer_.valid() && storedVariables_.size()) if (writer_ && !storedVariables_.empty())
{ {
WarningInFunction WarningInFunction
// << "Context: " << driverContext_ << nl // << "Context: " << driverContext_ << nl
@ -216,7 +216,7 @@ bool Foam::expressions::fvExprDriver::readDict
{ {
ITstream& is = eptr->stream(); ITstream& is = eptr->stream();
if (writer_.valid() && delayedVariables_.size()) if (writer_ && !delayedVariables_.empty())
{ {
WarningInFunction WarningInFunction
// << "Context: " << driverContext_ << nl // << "Context: " << driverContext_ << nl

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2010-2018 Bernhard Gschaider <bgschaid@hfd-research.com> Copyright (C) 2010-2018 Bernhard Gschaider <bgschaid@hfd-research.com>
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -261,16 +261,16 @@ Foam::Ostream& Foam::expressions::fvExprDriver::writeCommon
void Foam::expressions::fvExprDriver::createWriterAndRead(const word& name) void Foam::expressions::fvExprDriver::createWriterAndRead(const word& name)
{ {
if (hasDataToWrite() && !writer_.valid()) if (!writer_ && hasDataToWrite())
{ {
writer_.set(new exprDriverWriter(name + "_" + this->type(), *this)); writer_.reset(new exprDriverWriter(name + "_" + this->type(), *this));
} }
} }
void Foam::expressions::fvExprDriver::tryWrite() const void Foam::expressions::fvExprDriver::tryWrite() const
{ {
if (writer_.valid() && mesh().time().outputTime()) if (writer_ && mesh().time().outputTime())
{ {
writer_->write(); writer_->write();
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd. Copyright (C) 2017-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -38,7 +38,7 @@ withSurfaceFields() const
( (
stFaceZone == regionType_ stFaceZone == regionType_
|| stPatch == regionType_ || stPatch == regionType_
|| (sampledPtr_.valid() && sampledPtr_->withSurfaceFields()) || (sampledPtr_ && sampledPtr_->withSurfaceFields())
); );
} }

View File

@ -370,7 +370,7 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::writeValues
Field<Type> values(getFieldValues<Type>(fieldName, true)); Field<Type> values(getFieldValues<Type>(fieldName, true));
// Write raw values on surface if specified // Write raw values on surface if specified
if (surfaceWriterPtr_.valid() && surfaceWriterPtr_->enabled()) if (surfaceWriterPtr_ && surfaceWriterPtr_->enabled())
{ {
Field<Type> allValues(values); Field<Type> allValues(values);
combineFields(allValues); combineFields(allValues);

View File

@ -34,7 +34,7 @@ template<class chemistryType>
void Foam::functionObjects::reactionsSensitivityAnalysis<chemistryType>:: void Foam::functionObjects::reactionsSensitivityAnalysis<chemistryType>::
createFileNames() createFileNames()
{ {
if (writeToFile() && !prodFilePtr_.valid()) if (writeToFile() && !prodFilePtr_)
{ {
prodFilePtr_ = createFile("production"); prodFilePtr_ = createFile("production");
writeHeader(prodFilePtr_(), "production"); writeHeader(prodFilePtr_(), "production");

View File

@ -413,8 +413,8 @@ bool Foam::functionObjects::regionSizeDistribution::write()
const volScalarField& alpha = const volScalarField& alpha =
( (
alphaPtr.valid() alphaPtr
? alphaPtr() ? *alphaPtr
: obr_.lookupObject<volScalarField>(alphaName_) : obr_.lookupObject<volScalarField>(alphaName_)
); );

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd. Copyright (C) 2015-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -54,7 +54,7 @@ void Foam::functionObjects::forceCoeffs::createFiles()
{ {
// Note: Only possible to create bin files after bins have been initialised // Note: Only possible to create bin files after bins have been initialised
if (writeToFile() && !coeffFilePtr_.valid()) if (writeToFile() && !coeffFilePtr_)
{ {
coeffFilePtr_ = createFile("coefficient"); coeffFilePtr_ = createFile("coefficient");
writeIntegratedHeader("Coefficients", coeffFilePtr_()); writeIntegratedHeader("Coefficients", coeffFilePtr_());

View File

@ -58,7 +58,7 @@ void Foam::functionObjects::forces::createFiles()
{ {
// Note: Only possible to create bin files after bins have been initialised // Note: Only possible to create bin files after bins have been initialised
if (writeToFile() && !forceFilePtr_.valid()) if (writeToFile() && !forceFilePtr_)
{ {
forceFilePtr_ = createFile("force"); forceFilePtr_ = createFile("force");
writeIntegratedHeader("Force", forceFilePtr_()); writeIntegratedHeader("Force", forceFilePtr_());

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -126,7 +126,7 @@ Foam::label Foam::functionObjects::vtkWrite::writeVolFields
const auto& field = tfield(); const auto& field = tfield();
// Internal // Internal
if (internalWriter.valid() && pInterp.valid()) if (internalWriter && pInterp)
{ {
ok = true; ok = true;
internalWriter->write(field, *pInterp); internalWriter->write(field, *pInterp);

View File

@ -1253,11 +1253,11 @@ void Foam::snappySnapDriver::featureAttractionUsingReconstruction
const point& pt = pp.localPoints()[pointi]; const point& pt = pp.localPoints()[pointi];
if (patchConstraints[pointi].first() == 2 && feStr.valid()) if (feStr && patchConstraints[pointi].first() == 2)
{ {
feStr().write(linePointRef(pt, pt+patchAttraction[pointi])); feStr().write(linePointRef(pt, pt+patchAttraction[pointi]));
} }
else if (patchConstraints[pointi].first() == 3 && fpStr.valid()) else if (fpStr && patchConstraints[pointi].first() == 3)
{ {
fpStr().write(linePointRef(pt, pt+patchAttraction[pointi])); fpStr().write(linePointRef(pt, pt+patchAttraction[pointi]));
} }
@ -2580,11 +2580,7 @@ void Foam::snappySnapDriver::determineFeatures
hasSnapped = true; hasSnapped = true;
// Debug: dump missed feature point // Debug: dump missed feature point
if if (missedMP0Str && !nearInfo.second().hit())
(
missedMP0Str.valid()
&& !nearInfo.second().hit()
)
{ {
missedMP0Str().write missedMP0Str().write
( (
@ -2649,11 +2645,7 @@ void Foam::snappySnapDriver::determineFeatures
} }
// Debug: dump missed feature point // Debug: dump missed feature point
if if (missedMP1Str && !nearInfo.second().hit())
(
missedMP1Str.valid()
&& !nearInfo.second().hit()
)
{ {
missedMP1Str().write missedMP1Str().write
( (
@ -2693,8 +2685,8 @@ void Foam::snappySnapDriver::determineFeatures
{ {
if if
( (
patchConstraints[pointi].first() == 3 featurePointStr
&& featurePointStr.valid() && patchConstraints[pointi].first() == 3
) )
{ {
featurePointStr().write featurePointStr().write
@ -2704,8 +2696,8 @@ void Foam::snappySnapDriver::determineFeatures
} }
else if else if
( (
patchConstraints[pointi].first() == 2 featureEdgeStr
&& featureEdgeStr.valid() && patchConstraints[pointi].first() == 2
) )
{ {
featureEdgeStr().write featureEdgeStr().write
@ -2812,7 +2804,7 @@ void Foam::snappySnapDriver::determineFeatures
} }
const pointIndexHit& info = nearInfo.second(); const pointIndexHit& info = nearInfo.second();
if (info.hit() && featurePointStr.valid()) if (featurePointStr && info.hit())
{ {
featurePointStr().write featurePointStr().write
( (

View File

@ -763,7 +763,7 @@ const
{ {
const word surfType(surfDict_.getOrDefault<word>("type", "none")); const word surfType(surfDict_.getOrDefault<word>("type", "none"));
if (!surfPtr_.valid() && surfType != "none") if (!surfPtr_ && surfType != "none")
{ {
word surfName(surfDict_.getOrDefault("name", patch_.name())); word surfName(surfDict_.getOrDefault("name", patch_.name()));

View File

@ -63,7 +63,7 @@ Foam::label Foam::NURBS3DVolume::getCPID
void Foam::NURBS3DVolume::findPointsInBox(const vectorField& meshPoints) void Foam::NURBS3DVolume::findPointsInBox(const vectorField& meshPoints)
{ {
// It is considered an error to recompute points in the control boxes // It is considered an error to recompute points in the control boxes
if (mapPtr_.valid() || reverseMapPtr_.valid()) if (mapPtr_ || reverseMapPtr_)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Attempting to recompute points residing within control boxes" << "Attempting to recompute points residing within control boxes"

View File

@ -7,7 +7,7 @@
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2007-2019 PCOpt/NTUA Copyright (C) 2007-2019 PCOpt/NTUA
Copyright (C) 2013-2019 FOSS GP Copyright (C) 2013-2019 FOSS GP
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -153,7 +153,7 @@ RASModelVariables::autoTmp
RASModelVariables::cloneAutoTmp(const autoTmp& source) const RASModelVariables::cloneAutoTmp(const autoTmp& source) const
{ {
autoTmp returnField(nullptr); autoTmp returnField(nullptr);
if (source.valid() && source().valid()) if (source && source->valid())
{ {
const volScalarField& sf = source()(); const volScalarField& sf = source()();
DebugInfo DebugInfo

View File

@ -646,12 +646,12 @@ void alphatWallBoilingWallFunctionFvPatchScalarField::updateCoeffs()
if if
( (
CHFModel_.valid() CHFModel_
&& CHFSoobModel_.valid() && CHFSoobModel_
&& TDNBModel_.valid() && TDNBModel_
&& MHFModel_.valid() && MHFModel_
&& LeidenfrostModel_.valid() && LeidenfrostModel_
&& filmBoilingModel_.valid() && filmBoilingModel_
) )
{ {

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2014-2018 OpenFOAM Foundation Copyright (C) 2014-2018 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -106,7 +107,7 @@ Foam::BlendedInterfacialModel<ModelType>::evaluate
tmp<scalarGeoField> f1, f2; tmp<scalarGeoField> f1, f2;
if (model_.valid() || model1In2_.valid()) if (model_ || model1In2_)
{ {
f1 = f1 =
blendedInterfacialModel::interpolate<scalarGeoField> blendedInterfacialModel::interpolate<scalarGeoField>
@ -115,7 +116,7 @@ Foam::BlendedInterfacialModel<ModelType>::evaluate
); );
} }
if (model_.valid() || model2In1_.valid()) if (model_ || model2In1_)
{ {
f2 = f2 =
blendedInterfacialModel::interpolate<scalarGeoField> blendedInterfacialModel::interpolate<scalarGeoField>
@ -177,7 +178,7 @@ Foam::BlendedInterfacialModel<ModelType>::evaluate
if if
( (
correctFixedFluxBCs_ correctFixedFluxBCs_
&& (model_.valid() || model1In2_.valid() || model2In1_.valid()) && (model_ || model1In2_ || model2In1_)
) )
{ {
correctFixedFluxBCs(x.ref()); correctFixedFluxBCs(x.ref());
@ -300,8 +301,8 @@ bool Foam::BlendedInterfacialModel<ModelType>::hasModel
{ {
return return
&phase == &(phase1_) &phase == &(phase1_)
? model1In2_.valid() ? bool(model1In2_)
: model2In1_.valid(); : bool(model2In1_);
} }

View File

@ -969,7 +969,7 @@ void Foam::shortestPathSet::genSamples
markLeakPath, markLeakPath,
iter, iter,
mesh, mesh,
(isBlockedFace.valid() ? isBlockedFace() : isBoundaryFace), (isBlockedFace ? *isBlockedFace : isBoundaryFace),
insidePoint, insidePoint,
insideCelli, insideCelli,
outsidePoint, outsidePoint,

View File

@ -107,7 +107,7 @@ bool Foam::sampledIsoSurfaceCell::updateGeometry() const
} }
const volScalarField& cellFld = const volScalarField& cellFld =
(fieldReadPtr.valid() ? *fieldReadPtr : *cellFldPtr); (fieldReadPtr ? *fieldReadPtr : *cellFldPtr);
auto tpointFld = volPointInterpolation::New(fvm).interpolate(cellFld); auto tpointFld = volPointInterpolation::New(fvm).interpolate(cellFld);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018 OpenFOAM Foundation Copyright (C) 2018 OpenFOAM Foundation
Copyright (C) 2018-2019 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -107,7 +107,7 @@ bool Foam::sampledIsoSurfaceTopo::updateGeometry() const
} }
const volScalarField& cellFld = const volScalarField& cellFld =
(fieldReadPtr.valid() ? *fieldReadPtr : *cellFldPtr); (fieldReadPtr ? *fieldReadPtr : *cellFldPtr);
auto tpointFld = volPointInterpolation::New(fvm).interpolate(cellFld); auto tpointFld = volPointInterpolation::New(fvm).interpolate(cellFld);

View File

@ -164,8 +164,8 @@ void Foam::sampledCuttingPlane::createGeometry()
// Select either the submesh or the underlying mesh // Select either the submesh or the underlying mesh
const fvMesh& mesh = const fvMesh& mesh =
( (
subMeshPtr_.valid() subMeshPtr_
? subMeshPtr_().subMesh() ? subMeshPtr_->subMesh()
: fvm : fvm
); );

View File

@ -326,7 +326,7 @@ bool Foam::sampledSurfaces::read(const dictionary& dict)
surfDict surfDict
); );
if (!surf.valid() || !surf->enabled()) if (!surf || !surf->enabled())
{ {
continue; continue;
} }
@ -392,7 +392,7 @@ bool Foam::sampledSurfaces::read(const dictionary& dict)
autoPtr<sampledSurface> surf = input.release(inputi); autoPtr<sampledSurface> surf = input.release(inputi);
if (!surf.valid() || !surf->enabled()) if (!surf || !surf->enabled())
{ {
continue; continue;
} }

View File

@ -102,8 +102,9 @@ bool Foam::sampledThresholdCellFaces::updateGeometry() const
fvm fvm
); );
} }
const volScalarField& cellFld = const volScalarField& cellFld =
(fieldReadPtr.valid() ? *fieldReadPtr : *cellFldPtr); (fieldReadPtr ? *fieldReadPtr : *cellFldPtr);
thresholdCellFaces surf thresholdCellFaces surf

View File

@ -439,7 +439,7 @@ void Foam::radiation::solarLoad::calculateQdiff
); );
if (finalAgglom_.size() > 0 && coarseMesh_.empty()) if (!coarseMesh_ && !finalAgglom_.empty())
{ {
coarseMesh_.reset coarseMesh_.reset
( (