Commit 8eddcc07 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 990d00d4
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment