Commit efe02691 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: avoid readScalar, readLabel etc from dictionary (#762, #1033)

- use the dictionary 'get' methods instead of readScalar for
  additional checking

     Unchecked:  readScalar(dict.lookup("key"));
     Checked:    dict.get<scalar>("key");

- In templated classes that also inherit from a dictionary, an additional
  'template' keyword will be required. Eg,

     this->coeffsDict().template get<scalar>("key");

  For this common use case, the predefined getXXX shortcuts may be
  useful. Eg,

     this->coeffsDict().getScalar("key");
parent e37a1a2d
......@@ -49,7 +49,7 @@ Foam::XiGModels::basicSubGrid::basicSubGrid
)
:
XiGModel(XiGProperties, thermo, turbulence, Su),
k1(readScalar(XiGModelCoeffs_.lookup("k1"))),
k1(XiGModelCoeffs_.get<scalar>("k1")),
XiGModel_(XiGModel::New(XiGModelCoeffs_, thermo, turbulence, Su))
{}
......
......@@ -49,13 +49,10 @@ Foam::XiEqModels::Gulder::Gulder
)
:
XiEqModel(XiEqProperties, thermo, turbulence, Su),
XiEqCoef_(readScalar(XiEqModelCoeffs_.lookup("XiEqCoef"))),
XiEqCoef_(XiEqModelCoeffs_.get<scalar>("XiEqCoef")),
SuMin_(0.01*Su.average()),
uPrimeCoef_(readScalar(XiEqModelCoeffs_.lookup("uPrimeCoef"))),
subGridSchelkin_
(
readBool(XiEqModelCoeffs_.lookup("subGridSchelkin"))
)
uPrimeCoef_(XiEqModelCoeffs_.get<scalar>("uPrimeCoef")),
subGridSchelkin_(XiEqModelCoeffs_.get<bool>("subGridSchelkin"))
{}
......
......@@ -49,15 +49,12 @@ Foam::XiEqModels::SCOPEXiEq::SCOPEXiEq
)
:
XiEqModel(XiEqProperties, thermo, turbulence, Su),
XiEqCoef_(readScalar(XiEqModelCoeffs_.lookup("XiEqCoef"))),
XiEqExp_(readScalar(XiEqModelCoeffs_.lookup("XiEqExp"))),
lCoef_(readScalar(XiEqModelCoeffs_.lookup("lCoef"))),
XiEqCoef_(XiEqModelCoeffs_.get<scalar>("XiEqCoef")),
XiEqExp_(XiEqModelCoeffs_.get<scalar>("XiEqExp")),
lCoef_(XiEqModelCoeffs_.get<scalar>("lCoef")),
SuMin_(0.01*Su.average()),
uPrimeCoef_(readScalar(XiEqModelCoeffs_.lookup("uPrimeCoef"))),
subGridSchelkin_
(
readBool(XiEqModelCoeffs_.lookup("subGridSchelkin"))
),
uPrimeCoef_(XiEqModelCoeffs_.get<scalar>("uPrimeCoef")),
subGridSchelkin_(XiEqModelCoeffs_.get<bool>("subGridSchelkin")),
MaModel
(
Su.mesh().lookupObject<IOdictionary>("combustionProperties"),
......
......@@ -49,7 +49,7 @@ Foam::XiEqModels::instability::instability
)
:
XiEqModel(XiEqProperties, thermo, turbulence, Su),
XiEqIn(readScalar(XiEqModelCoeffs_.lookup("XiEqIn"))),
XiEqIn(XiEqModelCoeffs_.get<scalar>("XiEqIn")),
XiEqModel_(XiEqModel::New(XiEqModelCoeffs_, thermo, turbulence, Su))
{}
......
......@@ -49,7 +49,7 @@ Foam::XiGModels::KTS::KTS
)
:
XiGModel(XiGProperties, thermo, turbulence, Su),
GEtaCoef_(readScalar(XiGModelCoeffs_.lookup("GEtaCoef")))
GEtaCoef_(XiGModelCoeffs_.get<scalar>("GEtaCoef"))
{}
......
......@@ -52,7 +52,7 @@ Foam::XiModels::algebraic::algebraic
)
:
XiModel(XiProperties, thermo, turbulence, Su, rho, b, phi),
XiShapeCoef(readScalar(XiModelCoeffs_.lookup("XiShapeCoef"))),
XiShapeCoef(XiModelCoeffs_.get<scalar>("XiShapeCoef")),
XiEqModel_(XiEqModel::New(XiProperties, thermo, turbulence, Su)),
XiGModel_(XiGModel::New(XiProperties, thermo, turbulence, Su))
{}
......
......@@ -57,7 +57,7 @@ Foam::XiModels::transport::transport
)
:
XiModel(XiProperties, thermo, turbulence, Su, rho, b, phi),
XiShapeCoef(readScalar(XiModelCoeffs_.lookup("XiShapeCoef"))),
XiShapeCoef(XiModelCoeffs_.get<scalar>("XiShapeCoef")),
XiEqModel_(XiEqModel::New(XiProperties, thermo, turbulence, Su)),
XiGModel_(XiGModel::New(XiProperties, thermo, turbulence, Su))
{}
......
......@@ -53,8 +53,8 @@ Foam::laminarFlameSpeedModels::SCOPE::polynomial::polynomial
)
:
FixedList<scalar, 7>(polyDict.lookup("coefficients")),
ll(readScalar(polyDict.lookup("lowerLimit"))),
ul(readScalar(polyDict.lookup("upperLimit"))),
ll(polyDict.get<scalar>("lowerLimit")),
ul(polyDict.get<scalar>("upperLimit")),
llv(polyPhi(ll, *this)),
ulv(polyPhi(ul, *this)),
lu(0)
......@@ -75,39 +75,30 @@ Foam::laminarFlameSpeedModels::SCOPE::SCOPE
(
IFstream
(
fileName
(
dict.lookup("fuelFile")
)
dict.get<fileName>("fuelFile")
)()
).optionalSubDict(typeName + "Coeffs")
),
LFL_
(
readScalar
coeffsDict_.getCompat<scalar>
(
coeffsDict_.lookupCompat
(
"lowerFlammabilityLimit",
{{"lowerFlamabilityLimit", 1712}}
)
"lowerFlammabilityLimit",
{{"lowerFlamabilityLimit", 1712}}
)
),
UFL_
(
readScalar
coeffsDict_.getCompat<scalar>
(
coeffsDict_.lookupCompat
(
"upperFlammabilityLimit",
{{"upperFlamabilityLimit", 1712}}
)
"upperFlammabilityLimit",
{{"upperFlamabilityLimit", 1712}}
)
),
SuPolyL_(coeffsDict_.subDict("lowerSuPolynomial")),
SuPolyU_(coeffsDict_.subDict("upperSuPolynomial")),
Texp_(readScalar(coeffsDict_.lookup("Texp"))),
pexp_(readScalar(coeffsDict_.lookup("pexp"))),
Texp_(coeffsDict_.get<scalar>("Texp")),
pexp_(coeffsDict_.get<scalar>("pexp")),
MaPolyL_(coeffsDict_.subDict("lowerMaPolynomial")),
MaPolyU_(coeffsDict_.subDict("upperMaPolynomial"))
{
......
......@@ -18,8 +18,8 @@
)
);
scalar p0 = readScalar(initialConditions.lookup("p"));
scalar T0 = readScalar(initialConditions.lookup("T"));
scalar p0 = initialConditions.get<scalar>("p");
scalar T0 = initialConditions.get<scalar>("T");
#include "createBaseFields.H"
......
......@@ -40,7 +40,7 @@
const word& name = Y[i].name();
if (fractions.found(name))
{
X0[i] = readScalar(fractions.lookup(name));
X0[i] = fractions.get<scalar>(name);
}
}
......@@ -64,7 +64,7 @@
const word& name = Y[i].name();
if (fractions.found(name))
{
Y0[i] = readScalar(fractions.lookup(name));
Y0[i] = fractions.get<scalar>(name);
}
}
......
......@@ -29,7 +29,7 @@ License
const dictionary& pimpleDict = pimple.dict();
// Maximum flow Courant number
scalar maxCo(readScalar(pimpleDict.lookup("maxCo")));
scalar maxCo(pimpleDict.get<scalar>("maxCo"));
// Maximum time scale
scalar maxDeltaT(pimpleDict.lookupOrDefault<scalar>("maxDeltaT", GREAT));
......@@ -118,7 +118,7 @@ License
if (Yref.found(Yi.name()))
{
foundY = true;
scalar Yrefi = readScalar(Yref.lookup(Yi.name()));
const scalar Yrefi = Yref.get<scalar>(Yi.name());
rDeltaTY.field() = max
(
......
......@@ -84,7 +84,7 @@ Foam::smoluchowskiJumpTFvPatchScalarField::smoluchowskiJumpTFvPatchScalarField
rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
psiName_(dict.lookupOrDefault<word>("psi", "thermo:psi")),
muName_(dict.lookupOrDefault<word>("mu", "thermo:mu")),
accommodationCoeff_(readScalar(dict.lookup("accommodationCoeff"))),
accommodationCoeff_(dict.get<scalar>("accommodationCoeff")),
Twall_("Twall", dict, p.size()),
gamma_(dict.lookupOrDefault<scalar>("gamma", 1.4))
{
......
......@@ -85,7 +85,7 @@ Foam::maxwellSlipUFvPatchVectorField::maxwellSlipUFvPatchVectorField
psiName_(dict.lookupOrDefault<word>("psi", "thermo:psi")),
muName_(dict.lookupOrDefault<word>("mu", "thermo:mu")),
tauMCName_(dict.lookupOrDefault<word>("tauMC", "tauMC")),
accommodationCoeff_(readScalar(dict.lookup("accommodationCoeff"))),
accommodationCoeff_(dict.get<scalar>("accommodationCoeff")),
Uwall_("Uwall", dict, p.size()),
thermalCreep_(dict.lookupOrDefault("thermalCreep", true)),
curvature_(dict.lookupOrDefault("curvature", true))
......
......@@ -25,8 +25,8 @@
if (!local)
{
const scalar T0 = readScalar(eosDict.lookup("T0"));
const scalar p0 = readScalar(eosDict.lookup("p0"));
const scalar T0 = eosDict.get<scalar>("T0");
const scalar p0 = eosDict.get<scalar>("p0");
he = thermo.he(p, pow(p/p0, (gamma - scalar(1))/gamma)*T0);
}
......
......@@ -12,7 +12,7 @@ IOdictionary mdEquilibrationDict
)
);
scalar targetTemperature = readScalar
scalar targetTemperature
(
mdEquilibrationDict.lookup("targetTemperature")
mdEquilibrationDict.get<scalar>("targetTemperature")
);
......@@ -139,10 +139,9 @@ basicKinematicTypeCloud kinematicCloud
scalar alphacMin
(
1.0
- readScalar
(
- (
kinematicCloud.particleProperties().subDict("constantProperties")
.lookup("alphaMax")
.get<scalar>("alphaMax")
)
);
......
......@@ -29,7 +29,7 @@ License
const dictionary& pimpleDict = pimple.dict();
// Maximum flow Courant number
scalar maxCo(readScalar(pimpleDict.lookup("maxCo")));
scalar maxCo(pimpleDict.get<scalar>("maxCo"));
// Maximum time scale
scalar maxDeltaT(pimpleDict.lookupOrDefault<scalar>("maxDeltaT", GREAT));
......
......@@ -29,7 +29,7 @@ License
const dictionary& pimpleDict = pimple.dict();
// Maximum flow Courant number
scalar maxCo(readScalar(pimpleDict.lookup("maxCo")));
scalar maxCo(pimpleDict.get<scalar>("maxCo"));
// Maximum time scale
scalar maxDeltaT(pimpleDict.lookupOrDefault<scalar>("maxDeltaT", GREAT));
......
......@@ -160,10 +160,9 @@ basicKinematicMPPICCloud kinematicCloud
scalar alphacMin
(
1.0
- readScalar
(
- (
kinematicCloud.particleProperties().subDict("constantProperties")
.lookup("alphaMax")
.get<scalar>("alphaMax")
)
);
......
......@@ -31,7 +31,7 @@ Description
scalar maxAlphaCo
(
readScalar(runTime.controlDict().lookup("maxAlphaCo"))
runTime.controlDict().get<scalar>("maxAlphaCo")
);
scalar alphaCoNum = 0.0;
......
......@@ -2,5 +2,5 @@
scalar maxAcousticCo
(
readScalar(runTime.controlDict().lookup("maxAcousticCo"))
runTime.controlDict().get<scalar>("maxAcousticCo")
);
......@@ -70,10 +70,10 @@
// Remove the swirl component of velocity for "wedge" cases
if (pimple.dict().found("removeSwirl"))
{
label swirlCmpt(readLabel(pimple.dict().lookup("removeSwirl")));
label swirlCmpt(pimple.dict().get<label>("removeSwirl"));
Info<< "Removing swirl component-" << swirlCmpt << " of U" << endl;
U.field().replace(swirlCmpt, 0.0);
U.field().replace(swirlCmpt, Zero);
}
U.correctBoundaryConditions();
......
......@@ -2,5 +2,5 @@
scalar maxAcousticCo
(
readScalar(runTime.controlDict().lookup("maxAcousticCo"))
runTime.controlDict().get<scalar>("maxAcousticCo")
);
......@@ -73,10 +73,10 @@
// Remove the swirl component of velocity for "wedge" cases
if (pimple.dict().found("removeSwirl"))
{
label swirlCmpt(readLabel(pimple.dict().lookup("removeSwirl")));
label swirlCmpt(pimple.dict().get<label>("removeSwirl"));
Info<< "Removing swirl component-" << swirlCmpt << " of U" << endl;
U.field().replace(swirlCmpt, 0.0);
U.field().replace(swirlCmpt, Zero);
}
U.correctBoundaryConditions();
......
......@@ -763,8 +763,8 @@ void Foam::multiphaseMixtureThermo::solve()
const Time& runTime = mesh_.time();
const dictionary& alphaControls = mesh_.solverDict("alpha");
label nAlphaSubCycles(readLabel(alphaControls.lookup("nAlphaSubCycles")));
scalar cAlpha(readScalar(alphaControls.lookup("cAlpha")));
label nAlphaSubCycles(alphaControls.get<label>("nAlphaSubCycles"));
scalar cAlpha(alphaControls.get<scalar>("cAlpha"));
volScalarField& alpha = phases_.first();
......
const dictionary& alphaControls = mesh.solverDict(alpha1.name());
label nAlphaCorr(readLabel(alphaControls.lookup("nAlphaCorr")));
label nAlphaCorr(alphaControls.get<label>("nAlphaCorr"));
label nAlphaSubCycles(readLabel(alphaControls.lookup("nAlphaSubCycles")));
label nAlphaSubCycles(alphaControls.get<label>("nAlphaSubCycles"));
bool MULESCorr(alphaControls.lookupOrDefault("MULESCorr", false));
......
......@@ -31,7 +31,7 @@ Description
scalar maxAlphaCo
(
readScalar(runTime.controlDict().lookup("maxAlphaCo"))
runTime.controlDict().get<scalar>("maxAlphaCo")
);
scalar maxAlphaDdt
......
......@@ -198,7 +198,7 @@ void Foam::radiation::laserDTRM::initialise()
{
case pdGaussian:
{
sigma_ = readScalar(lookup("sigma"));
sigma_ = get<scalar>("sigma");
break;
}
case pdManual:
......@@ -325,8 +325,8 @@ Foam::radiation::laserDTRM::laserDTRM(const volScalarField& T)
mode_(powerDistNames_.lookup("mode", *this)),
DTRMCloud_(mesh_, "DTRMCloud", IDLList<DTRMParticle>()),
nParticles_(0),
ndTheta_(readLabel(lookup("nTheta"))),
ndr_(readLabel(lookup("nr"))),
ndTheta_(get<label>("nTheta")),
ndr_(get<label>("nr")),
maxTrackLength_(mesh_.bounds().mag()),
focalLaserPosition_
......@@ -339,7 +339,7 @@ Foam::radiation::laserDTRM::laserDTRM(const volScalarField& T)
Function1<vector>::New("laserDirection", *this)
),
focalLaserRadius_(readScalar(lookup("focalLaserRadius"))),
focalLaserRadius_(get<scalar>("focalLaserRadius")),
qualityBeamLaser_
(
lookupOrDefault<scalar>("qualityBeamLaser", 0.0)
......@@ -435,8 +435,8 @@ Foam::radiation::laserDTRM::laserDTRM
mode_(powerDistNames_.lookup("mode", *this)),
DTRMCloud_(mesh_, "DTRMCloud", IDLList<DTRMParticle>()),
nParticles_(0),
ndTheta_(readLabel(lookup("nTheta"))),
ndr_(readLabel(lookup("nr"))),
ndTheta_(get<label>("nTheta")),
ndr_(get<label>("nr")),
maxTrackLength_(mesh_.bounds().mag()),
focalLaserPosition_
......@@ -448,7 +448,7 @@ Foam::radiation::laserDTRM::laserDTRM
Function1<vector>::New("laserDirection", *this)
),
focalLaserRadius_(readScalar(lookup("focalLaserRadius"))),
focalLaserRadius_(get<scalar>("focalLaserRadius")),
qualityBeamLaser_
(
lookupOrDefault<scalar>("qualityBeamLaser", 0.0)
......
......@@ -53,7 +53,7 @@ Foam::radiation::FresnelLaser::FresnelLaser
)
:
reflectionModel(dict, mesh),
epsilon_(readScalar(dict.lookup("epsilon")))
epsilon_(dict.get<scalar>("epsilon"))
{}
......
......@@ -53,8 +53,8 @@ Foam::porousModels::VollerPrakash::VollerPrakash
)
:
porousModel(dict, mesh),
Cu_(readScalar(dict.lookup("Cu"))),
solidPhase_(dict.lookup("solidPhase"))
Cu_(dict.get<scalar>("Cu")),
solidPhase_(dict.get<word>("solidPhase"))
{}
......
......@@ -191,7 +191,7 @@ void Foam::MultiComponentPhaseModel<BasePhaseModel, phaseThermo>::solveYi
const dictionary& MULEScontrols = mesh.solverDict(alpha1.name());
scalar cAlpha(readScalar(MULEScontrols.lookup("cYi")));
scalar cAlpha(MULEScontrols.get<scalar>("cYi"));
PtrList<surfaceScalarField> phiYiCorrs(species_.size());
const surfaceScalarField& phi = this->fluid().phi();
......
......@@ -269,8 +269,8 @@ void Foam::multiphaseSystem::solve()
const fvMesh& mesh = this->mesh();
const dictionary& alphaControls = mesh.solverDict("alpha");
label nAlphaSubCycles(readLabel(alphaControls.lookup("nAlphaSubCycles")));
label nAlphaCorr(readLabel(alphaControls.lookup("nAlphaCorr")));
label nAlphaSubCycles(alphaControls.get<label>("nAlphaSubCycles"));
label nAlphaCorr(alphaControls.get<label>("nAlphaCorr"));
mesh.solverDict("alpha").readEntry("cAlphas", cAlphas_);
// Reset ddtAlphaMax
......
......@@ -50,10 +50,7 @@ Foam::temperaturePhaseChangeTwoPhaseMixture::New
const word modelType
(
phaseChangePropertiesDict.lookup
(
"phaseChangeTwoPhaseModel"
)
phaseChangePropertiesDict.get<word>("phaseChangeTwoPhaseModel")
);
Info<< "Selecting phaseChange model " << modelType << endl;
......
const dictionary& alphaControls = mesh.solverDict(alpha1.name());
label nAlphaCorr(readLabel(alphaControls.lookup("nAlphaCorr")));
label nAlphaCorr(alphaControls.get<label>("nAlphaCorr"));
label nAlphaSubCycles(readLabel(alphaControls.lookup("nAlphaSubCycles")));
label nAlphaSubCycles(alphaControls.get<label>("nAlphaSubCycles"));
......@@ -155,13 +155,10 @@ Foam::threePhaseInterfaceProperties::threePhaseInterfaceProperties
mixture_(mixture),
cAlpha_
(
readScalar
mixture.U().mesh().solverDict
(
mixture.U().mesh().solverDict
(
mixture_.alpha1().name()
).lookup("cAlpha")
)
mixture_.alpha1().name()
).get<scalar>("cAlpha")
),
sigma12_("sigma12", dimensionSet(1, 0, -2, 0, 0), mixture),
sigma13_("sigma13", dimensionSet(1, 0, -2, 0, 0), mixture),
......
......@@ -31,7 +31,7 @@ Description
scalar maxAlphaCo
(
readScalar(runTime.controlDict().lookup("maxAlphaCo"))
runTime.controlDict().get<scalar>("maxAlphaCo")
);
scalar alphaCoNum = 0.0;
......
const dictionary& alphaControls = mesh.solverDict(alpha1.name());
label nAlphaSubCycles(readLabel(alphaControls.lookup("nAlphaSubCycles")));
label nAlphaSubCycles(alphaControls.get<label>("nAlphaSubCycles"));