mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: avoid raw dictionary lookup in functionObjects (issue #762)
Style changes:
- use lookupObjectRef instead of using const_cast
- use tmp::New factory
This commit is contained in:
@ -109,19 +109,16 @@ bool Foam::functionObjects::ensightWrite::read(const dictionary& dict)
|
||||
//
|
||||
writeOpts_.noPatches(dict.lookupOrDefault("noPatches", false));
|
||||
|
||||
if (dict.found("patches"))
|
||||
wordRes list;
|
||||
if (dict.readIfPresent("patches", list))
|
||||
{
|
||||
wordRes list(dict.lookup("patches"));
|
||||
list.uniq();
|
||||
|
||||
writeOpts_.patchSelection(list);
|
||||
}
|
||||
|
||||
if (dict.found("faceZones"))
|
||||
if (dict.readIfPresent("faceZones", list))
|
||||
{
|
||||
wordRes list(dict.lookup("faceZones"));
|
||||
list.uniq();
|
||||
|
||||
writeOpts_.faceZoneSelection(list);
|
||||
}
|
||||
|
||||
@ -147,7 +144,7 @@ bool Foam::functionObjects::ensightWrite::read(const dictionary& dict)
|
||||
//
|
||||
// output fields
|
||||
//
|
||||
dict.lookup("fields") >> selectFields_;
|
||||
dict.readEntry("fields", selectFields_);
|
||||
selectFields_.uniq();
|
||||
|
||||
return true;
|
||||
|
||||
@ -74,7 +74,7 @@ bool Foam::functionObjects::removeRegisteredObject::read(const dictionary& dict)
|
||||
{
|
||||
regionFunctionObject::read(dict);
|
||||
|
||||
dict.lookup("objects") >> objectNames_;
|
||||
dict.readEntry("objects", objectNames_);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -53,9 +53,9 @@ Foam::functionObjects::runTimeControls::averageCondition::averageCondition
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
functionObjectName_(dict.lookup("functionObject")),
|
||||
fieldNames_(dict.lookup("fields")),
|
||||
tolerance_(readScalar(dict.lookup("tolerance"))),
|
||||
functionObjectName_(dict.get<word>("functionObject")),
|
||||
fieldNames_(dict.get<wordList>("fields")),
|
||||
tolerance_(dict.get<scalar>("tolerance")),
|
||||
window_(dict.lookupOrDefault<scalar>("window", -1)),
|
||||
totalTime_(fieldNames_.size(), obr_.time().deltaTValue()),
|
||||
resetOnRestart_(false)
|
||||
@ -71,7 +71,7 @@ Foam::functionObjects::runTimeControls::averageCondition::averageCondition
|
||||
if (dict.found(fieldName))
|
||||
{
|
||||
const dictionary& valueDict = dict.subDict(fieldName);
|
||||
totalTime_[fieldi] = readScalar(valueDict.lookup("totalTime"));
|
||||
valueDict.readEntry("totalTime", totalTime_[fieldi]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,8 +76,8 @@ equationInitialResidualCondition
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
fieldNames_(dict.lookup("fields")),
|
||||
value_(readScalar(dict.lookup("value"))),
|
||||
fieldNames_(dict.get<wordList>("fields")),
|
||||
value_(dict.get<scalar>("value")),
|
||||
timeStart_(dict.lookupOrDefault("timeStart", -GREAT)),
|
||||
mode_(operatingModeNames.lookup("mode", dict))
|
||||
{
|
||||
|
||||
@ -60,8 +60,8 @@ equationMaxIterCondition
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
fieldNames_(dict.lookup("fields")),
|
||||
threshold_(readLabel(dict.lookup("threshold"))),
|
||||
fieldNames_(dict.get<wordList>("fields")),
|
||||
threshold_(dict.get<label>("threshold")),
|
||||
startIter_(dict.lookupOrDefault("startIter", 2))
|
||||
{
|
||||
if (!fieldNames_.size())
|
||||
|
||||
@ -83,10 +83,10 @@ Foam::functionObjects::runTimeControls::minMaxCondition::minMaxCondition
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
functionObjectName_(dict.lookup("functionObject")),
|
||||
functionObjectName_(dict.get<word>("functionObject")),
|
||||
mode_(modeTypeNames_.lookup("mode", dict)),
|
||||
fieldNames_(dict.lookup("fields")),
|
||||
value_(readScalar(dict.lookup("value")))
|
||||
fieldNames_(dict.get<wordList>("fields")),
|
||||
value_(dict.get<scalar>("value"))
|
||||
{}
|
||||
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@ minTimeStepCondition
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
minValue_(readScalar(dict.lookup("minValue")))
|
||||
minValue_(dict.get<scalar>("minValue"))
|
||||
{}
|
||||
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ Foam::functionObjects::runTimeControls::runTimeCondition::New
|
||||
stateFunctionObject& state
|
||||
)
|
||||
{
|
||||
const word conditionType(dict.lookup("type"));
|
||||
const word conditionType(dict.get<word>("type"));
|
||||
|
||||
Info<< "Selecting runTimeCondition " << conditionType << endl;
|
||||
|
||||
@ -52,7 +52,8 @@ Foam::functionObjects::runTimeControls::runTimeCondition::New
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return autoPtr<runTimeCondition>
|
||||
return
|
||||
autoPtr<runTimeCondition>
|
||||
(
|
||||
cstrIter()(conditionName, obr, dict, state)
|
||||
);
|
||||
|
||||
@ -56,7 +56,7 @@ Foam::functionObjects::thermoCoupleProbes::thermoCoupleProbes
|
||||
probes(name, runTime, dict, loadFromFiles, false),
|
||||
ODESystem(),
|
||||
UName_(dict.lookupOrDefault<word>("U", "U")),
|
||||
radiationFieldName_(dict.lookup("radiationField")),
|
||||
radiationFieldName_(dict.get<word>("radiationField")),
|
||||
thermo_(mesh_.lookupObject<fluidThermo>(basicThermo::dictName)),
|
||||
odeSolver_(nullptr),
|
||||
Ttc_()
|
||||
@ -71,7 +71,7 @@ Foam::functionObjects::thermoCoupleProbes::thermoCoupleProbes
|
||||
dictionary probeDict;
|
||||
if (getDict(typeName, probeDict))
|
||||
{
|
||||
probeDict.lookup("Tc") >> Ttc_;
|
||||
probeDict.readEntry("Tc", Ttc_);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -198,10 +198,10 @@ bool Foam::functionObjects::thermoCoupleProbes::read(const dictionary& dict)
|
||||
{
|
||||
if (probes::read(dict))
|
||||
{
|
||||
rho_ = readScalar(dict.lookup("rho"));
|
||||
Cp_ = readScalar(dict.lookup("Cp"));
|
||||
d_ = readScalar(dict.lookup("d"));
|
||||
epsilon_ = readScalar(dict.lookup("epsilon"));
|
||||
dict.readEntry("rho", rho_);
|
||||
dict.readEntry("Cp", Cp_);
|
||||
dict.readEntry("d", d_);
|
||||
dict.readEntry("epsilon", epsilon_);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -115,8 +115,8 @@ bool Foam::functionObjects::timeActivatedFileUpdate::read
|
||||
{
|
||||
functionObject::read(dict);
|
||||
|
||||
dict.lookup("fileToUpdate") >> fileToUpdate_;
|
||||
dict.lookup("timeVsFile") >> timeVsFile_;
|
||||
dict.readEntry("fileToUpdate", fileToUpdate_);
|
||||
dict.readEntry("timeVsFile", timeVsFile_);
|
||||
|
||||
lastIndex_ = -1;
|
||||
fileToUpdate_.expand();
|
||||
|
||||
@ -87,7 +87,7 @@ bool Foam::functionObjects::vtkWrite::read(const dictionary& dict)
|
||||
writeOpts_.ascii
|
||||
(
|
||||
dict.found("format")
|
||||
&& (IOstream::formatEnum(dict.lookup("format")) == IOstream::ASCII)
|
||||
&& (IOstream::formatEnum(dict.get<word>("format")) == IOstream::ASCII)
|
||||
);
|
||||
|
||||
// FUTURE?
|
||||
@ -115,7 +115,7 @@ bool Foam::functionObjects::vtkWrite::read(const dictionary& dict)
|
||||
//
|
||||
// output fields
|
||||
//
|
||||
dict.lookup("fields") >> selectFields_;
|
||||
dict.readEntry("fields", selectFields_);
|
||||
selectFields_.uniq();
|
||||
|
||||
return true;
|
||||
|
||||
@ -125,7 +125,7 @@ bool Foam::functionObjects::writeDictionary::read(const dictionary& dict)
|
||||
{
|
||||
regionFunctionObject::read(dict);
|
||||
|
||||
wordList dictNames(dict.lookup("dictNames"));
|
||||
wordList dictNames(dict.get<wordList>("dictNames"));
|
||||
wordHashSet uniqueNames(dictNames);
|
||||
dictNames_ = uniqueNames.toc();
|
||||
|
||||
@ -134,9 +134,9 @@ bool Foam::functionObjects::writeDictionary::read(const dictionary& dict)
|
||||
Info<< type() << " " << name() << ": monitoring dictionaries:" << nl;
|
||||
if (dictNames_.size())
|
||||
{
|
||||
forAll(dictNames_, i)
|
||||
for (const word & dictName : dictNames_)
|
||||
{
|
||||
Info<< " " << dictNames_[i] << endl;
|
||||
Info<< " " << dictName << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@ -90,15 +90,15 @@ bool Foam::functionObjects::writeObjects::read(const dictionary& dict)
|
||||
if (dict.found("field"))
|
||||
{
|
||||
objectNames_.setSize(1);
|
||||
dict.lookup("field") >> objectNames_[0];
|
||||
dict.readEntry("field", objectNames_[0]);
|
||||
}
|
||||
else if (dict.found("fields"))
|
||||
{
|
||||
dict.lookup("fields") >> objectNames_;
|
||||
dict.readEntry("fields", objectNames_);
|
||||
}
|
||||
else
|
||||
{
|
||||
dict.lookup("objects") >> objectNames_;
|
||||
dict.readEntry("objects", objectNames_);
|
||||
}
|
||||
|
||||
writeOption_ = writeOptionNames_.lookupOrDefault
|
||||
|
||||
Reference in New Issue
Block a user