ENH: unify use of dictionary method names

- previously introduced `getOrDefault` as a dictionary _get_ method,
  now complete the transition and use it everywhere instead of
  `lookupOrDefault`. This avoids mixed usage of the two methods that
  are identical in behaviour, makes for shorter names, and promotes
  the distinction between "lookup" access (ie, return a token stream,
  locate and return an entry) and "get" access (ie, the above with
  conversion to concrete types such as scalar, label etc).
This commit is contained in:
Mark Olesen
2020-06-02 16:38:55 +02:00
parent f721b5344f
commit 3e43edf056
624 changed files with 2109 additions and 1954 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -184,7 +184,7 @@ bool Foam::functionObjects::abort::read(const dictionary& dict)
triggered_ = false;
defaultAction_ = Time::stopAtControlNames.lookupOrDefault
defaultAction_ = Time::stopAtControlNames.getOrDefault
(
"action",
dict,

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -139,7 +139,7 @@ bool Foam::areaWrite::read(const dictionary& dict)
)
);
verbose_ = dict.lookupOrDefault("verbose", false);
verbose_ = dict.getOrDefault("verbose", false);
// All possible area meshes for the given fvMesh region
meshes_ = obr().lookupClass<faMesh>();

View File

@ -116,17 +116,17 @@ bool Foam::functionObjects::ensightWrite::read(const dictionary& dict)
// Writer options
consecutive_ = dict.lookupOrDefault("consecutive", false);
consecutive_ = dict.getOrDefault("consecutive", false);
writeOpts_.useBoundaryMesh(dict.lookupOrDefault("boundary", true));
writeOpts_.useInternalMesh(dict.lookupOrDefault("internal", true));
writeOpts_.useBoundaryMesh(dict.getOrDefault("boundary", true));
writeOpts_.useInternalMesh(dict.getOrDefault("internal", true));
// Warn if noPatches keyword (1806) exists and contradicts our settings
// Cannot readily use Compat since the boolean has the opposite value.
if
(
dict.lookupOrDefault("noPatches", false)
dict.getOrDefault("noPatches", false)
&& writeOpts_.useBoundaryMesh()
)
{
@ -151,9 +151,9 @@ bool Foam::functionObjects::ensightWrite::read(const dictionary& dict)
// Case options
caseOpts_.nodeValues(dict.lookupOrDefault("nodeValues", false));
caseOpts_.width(dict.lookupOrDefault<label>("width", 8));
caseOpts_.overwrite(dict.lookupOrDefault("overwrite", false));
caseOpts_.nodeValues(dict.getOrDefault("nodeValues", false));
caseOpts_.width(dict.getOrDefault<label>("width", 8));
caseOpts_.overwrite(dict.getOrDefault("overwrite", false));
// Output directory

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -70,7 +70,7 @@ Foam::functionObjects::runTimeControls::averageCondition::averageCondition
functionObjectName_(dict.get<word>("functionObject")),
fieldNames_(dict.get<wordList>("fields")),
tolerance_(dict.get<scalar>("tolerance")),
window_(dict.lookupOrDefault<scalar>("window", -1)),
window_(dict.getOrDefault<scalar>("window", -1)),
windowType_
(
window_ > 0
@ -78,8 +78,8 @@ Foam::functionObjects::runTimeControls::averageCondition::averageCondition
: windowType::NONE
),
totalTime_(fieldNames_.size(), scalar(0)),
resetOnRestart_(dict.lookupOrDefault<bool>("resetOnRestart", false)),
nIterStartUp_(dict.lookupOrDefault<label>("nIterStartUp", 10)),
resetOnRestart_(dict.getOrDefault("resetOnRestart", false)),
nIterStartUp_(dict.getOrDefault<label>("nIterStartUp", 10)),
iter_(-1)
{
dictionary& conditionDict = this->conditionDict();

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -85,7 +85,7 @@ equationInitialResidualCondition::equationInitialResidualCondition
runTimeCondition(name, obr, dict, state),
fieldSelection_(obr, true),
value_(dict.get<scalar>("value")),
timeStart_(dict.lookupOrDefault("timeStart", -GREAT)),
timeStart_(dict.getOrDefault("timeStart", -GREAT)),
mode_(operatingModeNames.get("mode", dict))
{
fieldSelection_.read(dict);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2015-2016 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -65,7 +65,7 @@ equationMaxIterCondition
runTimeCondition(name, obr, dict, state),
fieldNames_(dict.get<wordList>("fields")),
threshold_(dict.get<label>("threshold")),
startIter_(dict.lookupOrDefault("startIter", 2))
startIter_(dict.getOrDefault("startIter", 2))
{
if (!fieldNames_.size())
{

View File

@ -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.
@ -64,7 +64,7 @@ maxDurationCondition
duration_(dict.get<scalar>("duration")),
startTime_(-1),
initialised_(false),
resetOnRestart_(dict.lookupOrDefault("resetOnRestart", false))
resetOnRestart_(dict.getOrDefault("resetOnRestart", false))
{
if
(

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -85,10 +85,10 @@ Foam::functionObjects::runTimeControls::runTimeCondition::runTimeCondition
name_(name),
obr_(obr),
state_(state),
active_(dict.lookupOrDefault("active", true)),
active_(dict.getOrDefault("active", true)),
conditionDict_(setConditionDict()),
groupID_(dict.lookupOrDefault("groupID", -1)),
log(dict.lookupOrDefault("log", true))
groupID_(dict.getOrDefault("groupID", -1)),
log(dict.getOrDefault("log", true))
{}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2015-2018 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -155,7 +155,7 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::read
// Set the action to perform when all conditions are satisfied
// - set to end for backwards compatibility with v1806
satisfiedAction_ =
satisfiedActionNames.lookupOrDefault
satisfiedActionNames.getOrDefault
(
"satisfiedAction",
dict,

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -95,7 +95,7 @@ bool Foam::functionObjects::setTimeStepFunctionObject::read
timeStepPtr_ = Function1<scalar>::New("deltaT", dict);
// Ensure that adjustTimeStep is active
if (!time_.controlDict().lookupOrDefault<bool>("adjustTimeStep", false))
if (!time_.controlDict().getOrDefault("adjustTimeStep", false))
{
FatalIOErrorInFunction(dict)
<< "Need to set 'adjustTimeStep' true to allow timestep control"

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2016 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -148,7 +148,7 @@ bool Foam::functionObjects::solverInfo::read(const dictionary& dict)
fieldSet_.read(dict);
writeResidualFields_ =
dict.lookupOrDefault("writeResidualFields", false);
dict.getOrDefault("writeResidualFields", false);
residualFieldNames_.clear();

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -112,7 +112,7 @@ bool Foam::functionObjects::systemCall::read(const dictionary& dict)
dict.readIfPresent("executeCalls", executeCalls_);
dict.readIfPresent("writeCalls", writeCalls_);
dict.readIfPresent("endCalls", endCalls_);
masterOnly_ = dict.lookupOrDefault("master", false);
masterOnly_ = dict.getOrDefault("master", false);
if (executeCalls_.empty() && endCalls_.empty() && writeCalls_.empty())
{

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -57,7 +57,7 @@ Foam::functionObjects::thermoCoupleProbes::thermoCoupleProbes
:
probes(name, runTime, dict, loadFromFiles, false),
ODESystem(),
UName_(dict.lookupOrDefault<word>("U", "U")),
UName_(dict.getOrDefault<word>("U", "U")),
radiationFieldName_(dict.get<word>("radiationField")),
thermo_(mesh_.lookupObject<fluidThermo>(basicThermo::dictName)),
odeSolver_(nullptr),

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -88,7 +88,7 @@ bool Foam::functionObjects::timeInfo::read(const dictionary& dict)
timeFunctionObject::read(dict);
writeFile::read(dict);
perTimeStep_ = dict.lookupOrDefault("perTimeStep", false);
perTimeStep_ = dict.getOrDefault("perTimeStep", false);
return true;
}

View File

@ -170,11 +170,11 @@ bool Foam::functionObjects::vtkWrite::read(const dictionary& dict)
// We probably cannot trust old information after a reread
series_.clear();
// verbose_ = dict.lookupOrDefault<bool>("verbose", true);
doInternal_ = dict.lookupOrDefault<bool>("internal", true);
doBoundary_ = dict.lookupOrDefault<bool>("boundary", true);
oneBoundary_ = dict.lookupOrDefault<bool>("single", false);
interpolate_ = dict.lookupOrDefault<bool>("interpolate", false);
// verbose_ = dict.getOrDefault("verbose", true);
doInternal_ = dict.getOrDefault("internal", true);
doBoundary_ = dict.getOrDefault("boundary", true);
oneBoundary_ = dict.getOrDefault("single", false);
interpolate_ = dict.getOrDefault("interpolate", false);
//
// Writer options - default is xml base64
@ -197,7 +197,7 @@ bool Foam::functionObjects::vtkWrite::read(const dictionary& dict)
// Info<< type() << " " << name() << " output-format: "
// << writeOpts_.description() << nl;
const int padWidth = dict.lookupOrDefault<int>("width", 8);
const int padWidth = dict.getOrDefault<int>("width", 8);
// Appropriate printf format - Enforce min/max sanity limits
if (padWidth < 1 || padWidth > 31)
@ -213,8 +213,8 @@ bool Foam::functionObjects::vtkWrite::read(const dictionary& dict)
// Other options
//
decompose_ = dict.lookupOrDefault("decompose", false);
writeIds_ = dict.lookupOrDefault("writeIds", false);
decompose_ = dict.getOrDefault("decompose", false);
writeIds_ = dict.getOrDefault("writeIds", false);
// Output directory

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -241,7 +241,7 @@ bool Foam::functionObjects::vtkWrite::readSelection(const dictionary& dict)
{
selectRegions_.resize(1);
selectRegions_.first() =
dict.lookupOrDefault<word>("region", polyMesh::defaultRegion);
dict.getOrDefault<word>("region", polyMesh::defaultRegion);
}
// Restrict to specified meshes

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -75,7 +75,7 @@ Foam::functionObjects::writeObjects::writeObjects
(
runTime.lookupObject<objectRegistry>
(
dict.lookupOrDefault("region", polyMesh::defaultRegion)
dict.getOrDefault("region", polyMesh::defaultRegion)
)
),
writeOption_(ANY_WRITE),
@ -105,7 +105,7 @@ bool Foam::functionObjects::writeObjects::read(const dictionary& dict)
dict.readEntry("objects", objectNames_);
}
writeOption_ = writeOptionNames_.lookupOrDefault
writeOption_ = writeOptionNames_.getOrDefault
(
"writeOption",
dict,