STYLE: use guards for dictionary lookup()

This commit is contained in:
Mark Olesen
2020-01-27 13:38:26 +01:00
parent 500a3b62ca
commit ae40bd9f9b
10 changed files with 48 additions and 35 deletions

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -28,6 +29,7 @@ License
#include "general.H" #include "general.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "Tuple2.H" #include "Tuple2.H"
#include "Switch.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -135,12 +137,15 @@ Foam::tabulatedWallFunctions::general::general
: :
tabulatedWallFunction(dict, mesh, typeName), tabulatedWallFunction(dict, mesh, typeName),
interpType_(interpolationTypeNames_.get("interpType", coeffDict_)), interpType_(interpolationTypeNames_.get("interpType", coeffDict_)),
log10YPlus_(coeffDict_.get<bool>("log10YPlus")),
log10UPlus_(coeffDict_.get<bool>("log10UPlus")),
yPlus_(), yPlus_(),
uPlus_(), uPlus_()
log10YPlus_(coeffDict_.lookup("log10YPlus")),
log10UPlus_(coeffDict_.lookup("log10UPlus"))
{ {
List<Tuple2<scalar, scalar>> inputTable = coeffDict_.lookup("inputTable"); List<Tuple2<scalar, scalar>> inputTable;
coeffDict_.readEntry("inputTable", inputTable);
if (inputTable.size() < 2) if (inputTable.size() < 2)
{ {
FatalErrorInFunction FatalErrorInFunction

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -32,6 +33,7 @@ Description
Example dictionary specification: Example dictionary specification:
\verbatim
tabulatedWallFunction general; tabulatedWallFunction general;
// Output table info // Output table info
@ -52,9 +54,8 @@ Description
... ...
(yPlusValueN uPlusValueN) (yPlusValueN uPlusValueN)
); );
} }
\endverbatim
SourceFiles SourceFiles
general.C general.C
@ -66,7 +67,6 @@ SourceFiles
#include "tabulatedWallFunction.H" #include "tabulatedWallFunction.H"
#include "Enum.H" #include "Enum.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -103,18 +103,18 @@ protected:
//- Type of interpolation to apply when inverting the data set //- Type of interpolation to apply when inverting the data set
interpolationType interpType_; interpolationType interpType_;
//- Are y+ values entered as log10(y+)?
bool log10YPlus_;
//- Are U+ values entered as log10(U+)?
bool log10UPlus_;
//- Input y+ values //- Input y+ values
List<scalar> yPlus_; List<scalar> yPlus_;
//- Input U+ values //- Input U+ values
List<scalar> uPlus_; List<scalar> uPlus_;
//- Are y+ values entered as log10(y+)?
Switch log10YPlus_;
//- Are U+ values entered as log10(U+)?
Switch log10UPlus_;
// Protected Member Functions // Protected Member Functions

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.
@ -69,7 +69,7 @@ void Foam::ConeNozzleInjection<CloudType>::setInjectionMethod()
case injectionMethod::imPoint: case injectionMethod::imPoint:
case injectionMethod::imDisc: case injectionMethod::imDisc:
{ {
position_ = this->coeffDict().lookup("position"); this->coeffDict().readEntry("position", position_);
break; break;
} }
case injectionMethod::imMovingPoint: case injectionMethod::imMovingPoint:

View File

@ -67,7 +67,10 @@ void Foam::moleculeCloud::buildConstProps()
const word& id = idList[i]; const word& id = idList[i];
const dictionary& molDict = moleculePropertiesDict.subDict(id); const dictionary& molDict = moleculePropertiesDict.subDict(id);
List<word> siteIdNames = molDict.lookup("siteIds"); List<word> siteIdNames
(
molDict.lookup("siteIds")
);
List<label> siteIds(siteIdNames.size()); List<label> siteIds(siteIdNames.size());

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -47,7 +48,10 @@ void Foam::potential::setSiteIdList(const dictionary& moleculePropertiesDict)
const dictionary& molDict(moleculePropertiesDict.subDict(id)); const dictionary& molDict(moleculePropertiesDict.subDict(id));
List<word> siteIdNames = molDict.lookup("siteIds"); List<word> siteIdNames
(
molDict.lookup("siteIds")
);
forAll(siteIdNames, sI) forAll(siteIdNames, sI)
{ {
@ -59,7 +63,10 @@ void Foam::potential::setSiteIdList(const dictionary& moleculePropertiesDict)
} }
} }
List<word> pairPotSiteIds = molDict.lookup("pairPotentialSiteIds"); List<word> pairPotSiteIds
(
molDict.lookup("pairPotentialSiteIds")
);
forAll(pairPotSiteIds, sI) forAll(pairPotSiteIds, sI)
{ {
@ -111,7 +118,7 @@ void Foam::potential::potential::readPotentialDict()
) )
); );
idList_ = List<word>(idListDict.lookup("idList")); idListDict.readEntry("idList", idList_);
setSiteIdList setSiteIdList
( (
@ -156,10 +163,10 @@ void Foam::potential::potential::readPotentialDict()
potentialDict.readEntry("potentialEnergyLimit", potentialEnergyLimit_); potentialDict.readEntry("potentialEnergyLimit", potentialEnergyLimit_);
if (potentialDict.found("removalOrder")) List<word> remOrd;
{
List<word> remOrd = potentialDict.lookup("removalOrder");
if (potentialDict.readIfPresent("removalOrder", remOrd))
{
removalOrder_.setSize(remOrd.size()); removalOrder_.setSize(remOrd.size());
forAll(removalOrder_, rO) forAll(removalOrder_, rO)

View File

@ -1057,7 +1057,6 @@ Foam::mappedPatchBase::mappedPatchBase
case NONUNIFORM: case NONUNIFORM:
{ {
//offsets_ = pointField(dict.lookup("offsets"));
offsets_ = readListOrField("offsets", dict, patch_.size()); offsets_ = readListOrField("offsets", dict, patch_.size());
} }
break; break;
@ -1076,7 +1075,6 @@ Foam::mappedPatchBase::mappedPatchBase
else if (dict.found("offsets")) else if (dict.found("offsets"))
{ {
offsetMode_ = NONUNIFORM; offsetMode_ = NONUNIFORM;
//offsets_ = pointField(dict.lookup("offsets"));
offsets_ = readListOrField("offsets", dict, patch_.size()); offsets_ = readListOrField("offsets", dict, patch_.size());
} }
else if (mode_ != NEARESTPATCHFACE && mode_ != NEARESTPATCHFACEAMI) else if (mode_ != NEARESTPATCHFACE && mode_ != NEARESTPATCHFACEAMI)

View File

@ -731,10 +731,10 @@ Foam::surfaceFeatures::surfaceFeatures
dictionary featInfoDict(str); dictionary featInfoDict(str);
featureEdges_ = labelList(featInfoDict.lookup("featureEdges")); featInfoDict.readEntry("featureEdges", featureEdges_);
featurePoints_ = labelList(featInfoDict.lookup("featurePoints")); featInfoDict.readEntry("featurePoints", featurePoints_);
externalStart_ = featInfoDict.get<label>("externalStart"); featInfoDict.readEntry("externalStart", externalStart_);
internalStart_ = featInfoDict.get<label>("internalStart"); featInfoDict.readEntry("internalStart", internalStart_);
} }

View File

@ -159,9 +159,9 @@ bool Foam::RBD::restraints::linearAxialAngularSpring::read
<< exit(FatalError); << exit(FatalError);
} }
axis_ = coeffs_.lookup("axis"); coeffs_.readEntry("axis", axis_);
scalar magAxis(mag(axis_)); const scalar magAxis(mag(axis_));
if (magAxis > VSMALL) if (magAxis > VSMALL)
{ {

View File

@ -176,9 +176,9 @@ bool Foam::RBD::restraints::prescribedRotation::read
<< exit(FatalError); << exit(FatalError);
} }
axis_ = coeffs_.lookup("axis"); coeffs_.readEntry("axis", axis_);
scalar magAxis(mag(axis_)); const scalar magAxis(mag(axis_));
if (magAxis > VSMALL) if (magAxis > VSMALL)
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
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.
@ -162,9 +162,9 @@ bool Foam::sixDoFRigidBodyMotionRestraints::linearAxialAngularSpring::read
<< exit(FatalError); << exit(FatalError);
} }
axis_ = sDoFRBMRCoeffs_.lookup("axis"); sDoFRBMRCoeffs_.readEntry("axis", axis_);
scalar magAxis(mag(axis_)); const scalar magAxis(mag(axis_));
if (magAxis > VSMALL) if (magAxis > VSMALL)
{ {