Commit 1c354e09 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: avoid raw dictionary lookup in transportModels (issue #762)

Style changes:
    - use lookupObjectRef instead of using const_cast
    - use tmp::New factory
parent e7c1d469
......@@ -129,14 +129,11 @@ Foam::incompressibleTwoPhaseMixture::mu() const
min(max(alpha1_, scalar(0)), scalar(1))
);
return tmp<volScalarField>
return tmp<volScalarField>::New
(
new volScalarField
(
"mu",
limitedAlpha1*rho1_*nuModel1_->nu()
+ (scalar(1) - limitedAlpha1)*rho2_*nuModel2_->nu()
)
"mu",
limitedAlpha1*rho1_*nuModel1_->nu()
+ (scalar(1) - limitedAlpha1)*rho2_*nuModel2_->nu()
);
}
......@@ -157,14 +154,11 @@ Foam::incompressibleTwoPhaseMixture::muf() const
min(max(fvc::interpolate(alpha1_), scalar(0)), scalar(1))
);
return tmp<surfaceScalarField>
return tmp<surfaceScalarField>::New
(
new surfaceScalarField
(
"muf",
alpha1f*rho1_*fvc::interpolate(nuModel1_->nu())
+ (scalar(1) - alpha1f)*rho2_*fvc::interpolate(nuModel2_->nu())
)
"muf",
alpha1f*rho1_*fvc::interpolate(nuModel1_->nu())
+ (scalar(1) - alpha1f)*rho2_*fvc::interpolate(nuModel2_->nu())
);
}
......@@ -177,16 +171,13 @@ Foam::incompressibleTwoPhaseMixture::nuf() const
min(max(fvc::interpolate(alpha1_), scalar(0)), scalar(1))
);
return tmp<surfaceScalarField>
return tmp<surfaceScalarField>::New
(
new surfaceScalarField
"nuf",
(
"nuf",
(
alpha1f*rho1_*fvc::interpolate(nuModel1_->nu())
+ (scalar(1) - alpha1f)*rho2_*fvc::interpolate(nuModel2_->nu())
)/(alpha1f*rho1_ + (scalar(1) - alpha1f)*rho2_)
)
alpha1f*rho1_*fvc::interpolate(nuModel1_->nu())
+ (scalar(1) - alpha1f)*rho2_*fvc::interpolate(nuModel2_->nu())
)/(alpha1f*rho1_ + (scalar(1) - alpha1f)*rho2_)
);
}
......@@ -207,20 +198,14 @@ bool Foam::incompressibleTwoPhaseMixture::read()
)
)
{
nuModel1_->viscosityProperties().lookup("rho") >> rho1_;
nuModel2_->viscosityProperties().lookup("rho") >> rho2_;
nuModel1_->viscosityProperties().readEntry("rho", rho1_);
nuModel2_->viscosityProperties().readEntry("rho", rho2_);
return true;
}
else
{
return false;
}
}
else
{
return false;
}
return false;
}
......
......@@ -92,10 +92,8 @@ bool Foam::singlePhaseTransportModel::read()
{
return viscosityModelPtr_->read(*this);
}
else
{
return false;
}
return false;
}
......
......@@ -83,8 +83,8 @@ bool Foam::viscosityModels::Arrhenius<ViscousModel>::read
ArrheniusCoeffs_ =
viscosityProperties.optionalSubDict(typeName + "Coeffs");
ArrheniusCoeffs_.lookup("alpha") >> alpha_;
ArrheniusCoeffs_.lookup("Talpha") >> Talpha_;
ArrheniusCoeffs_.readEntry("alpha", alpha_);
ArrheniusCoeffs_.readEntry("Talpha", Talpha_);
return true;
}
......
......@@ -110,10 +110,10 @@ bool Foam::viscosityModels::BirdCarreau::read
BirdCarreauCoeffs_ =
viscosityProperties.optionalSubDict(typeName + "Coeffs");
BirdCarreauCoeffs_.lookup("nu0") >> nu0_;
BirdCarreauCoeffs_.lookup("nuInf") >> nuInf_;
BirdCarreauCoeffs_.lookup("k") >> k_;
BirdCarreauCoeffs_.lookup("n") >> n_;
BirdCarreauCoeffs_.readEntry("nu0", nu0_);
BirdCarreauCoeffs_.readEntry("nuInf", nuInf_);
BirdCarreauCoeffs_.readEntry("k", k_);
BirdCarreauCoeffs_.readEntry("n", n_);
a_ = BirdCarreauCoeffs_.lookupOrDefault
(
"a",
......
......@@ -114,10 +114,10 @@ bool Foam::viscosityModels::Casson::read
CassonCoeffs_ = viscosityProperties.optionalSubDict(typeName + "Coeffs");
CassonCoeffs_.lookup("m") >> m_;
CassonCoeffs_.lookup("tau0") >> tau0_;
CassonCoeffs_.lookup("nuMin_") >> nuMin_;
CassonCoeffs_.lookup("nuMax_") >> nuMax_;
CassonCoeffs_.readEntry("m", m_);
CassonCoeffs_.readEntry("tau0", tau0_);
CassonCoeffs_.readEntry("nuMin_", nuMin_);
CassonCoeffs_.readEntry("nuMax_", nuMax_);
return true;
}
......
......@@ -100,10 +100,10 @@ bool Foam::viscosityModels::CrossPowerLaw::read
CrossPowerLawCoeffs_ =
viscosityProperties.optionalSubDict(typeName + "Coeffs");
CrossPowerLawCoeffs_.lookup("nu0") >> nu0_;
CrossPowerLawCoeffs_.lookup("nuInf") >> nuInf_;
CrossPowerLawCoeffs_.lookup("m") >> m_;
CrossPowerLawCoeffs_.lookup("n") >> n_;
CrossPowerLawCoeffs_.readEntry("nu0", nu0_);
CrossPowerLawCoeffs_.readEntry("nuInf", nuInf_);
CrossPowerLawCoeffs_.readEntry("m", m_);
CrossPowerLawCoeffs_.readEntry("n", n_);
return true;
}
......
......@@ -113,10 +113,10 @@ bool Foam::viscosityModels::HerschelBulkley::read
HerschelBulkleyCoeffs_ =
viscosityProperties.optionalSubDict(typeName + "Coeffs");
HerschelBulkleyCoeffs_.lookup("k") >> k_;
HerschelBulkleyCoeffs_.lookup("n") >> n_;
HerschelBulkleyCoeffs_.lookup("tau0") >> tau0_;
HerschelBulkleyCoeffs_.lookup("nu0") >> nu0_;
HerschelBulkleyCoeffs_.readEntry("k", k_);
HerschelBulkleyCoeffs_.readEntry("n", n_);
HerschelBulkleyCoeffs_.readEntry("tau0", tau0_);
HerschelBulkleyCoeffs_.readEntry("nu0", nu0_);
return true;
}
......
......@@ -76,7 +76,7 @@ bool Foam::viscosityModels::Newtonian::read
{
viscosityModel::read(viscosityProperties);
viscosityProperties_.lookup("nu") >> nu0_;
viscosityProperties_.readEntry("nu", nu0_);
nu_ = nu0_;
return true;
......
......@@ -112,10 +112,10 @@ bool Foam::viscosityModels::powerLaw::read
powerLawCoeffs_ = viscosityProperties.optionalSubDict(typeName + "Coeffs");
powerLawCoeffs_.lookup("k") >> k_;
powerLawCoeffs_.lookup("n") >> n_;
powerLawCoeffs_.lookup("nuMin") >> nuMin_;
powerLawCoeffs_.lookup("nuMax") >> nuMax_;
powerLawCoeffs_.readEntry("k", k_);
powerLawCoeffs_.readEntry("n", n_);
powerLawCoeffs_.readEntry("nuMin", nuMin_);
powerLawCoeffs_.readEntry("nuMax", nuMax_);
return true;
}
......
......@@ -37,7 +37,7 @@ Foam::autoPtr<Foam::viscosityModel> Foam::viscosityModel::New
const surfaceScalarField& phi
)
{
const word modelType(viscosityProperties.lookup("transportModel"));
const word modelType(viscosityProperties.get<word>("transportModel"));
Info<< "Selecting incompressible transport model " << modelType << endl;
......
......@@ -157,10 +157,7 @@ Foam::interfaceProperties::interfaceProperties
transportPropertiesDict_(dict),
cAlpha_
(
readScalar
(
alpha1.mesh().solverDict(alpha1.name()).lookup("cAlpha")
)
alpha1.mesh().solverDict(alpha1.name()).get<scalar>("cAlpha")
),
sigmaPtr_(surfaceTensionModel::New(dict, alpha1.mesh())),
......@@ -233,7 +230,7 @@ void Foam::interfaceProperties::correct()
bool Foam::interfaceProperties::read()
{
alpha1_.mesh().solverDict(alpha1_.name()).lookup("cAlpha") >> cAlpha_;
alpha1_.mesh().solverDict(alpha1_.name()).readEntry("cAlpha", cAlpha_);
sigmaPtr_->readDict(transportPropertiesDict_);
return true;
......
......@@ -63,22 +63,19 @@ Foam::surfaceTensionModels::constant::~constant()
Foam::tmp<Foam::volScalarField>
Foam::surfaceTensionModels::constant::sigma() const
{
return tmp<volScalarField>
return tmp<volScalarField>::New
(
new volScalarField
IOobject
(
IOobject
(
"sigma",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
"sigma",
mesh_.time().timeName(),
mesh_,
sigma_
)
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
mesh_,
sigma_
);
}
......@@ -88,11 +85,11 @@ bool Foam::surfaceTensionModels::constant::readDict(const dictionary& dict)
// Handle sub-dictionary format as a special case
if (dict.isDict("sigma"))
{
dict.subDict("sigma").lookup("sigma") >> sigma_;
dict.subDict("sigma").readEntry("sigma", sigma_);
}
else
{
dict.lookup("sigma") >> sigma_;
dict.readEntry("sigma", sigma_);
}
return true;
......
......@@ -38,7 +38,7 @@ Foam::autoPtr<Foam::surfaceTensionModel> Foam::surfaceTensionModel::New
{
const dictionary& sigmaDict = surfaceTensionModel::sigmaDict(dict);
const word modelType(sigmaDict.lookup("type"));
const word modelType(sigmaDict.get<word>("type"));
Info<< "Selecting surfaceTensionModel " << modelType << endl;
......
......@@ -69,24 +69,21 @@ Foam::surfaceTensionModels::temperatureDependent::~temperatureDependent()
Foam::tmp<Foam::volScalarField>
Foam::surfaceTensionModels::temperatureDependent::sigma() const
{
tmp<volScalarField> tsigma
auto tsigma = tmp<volScalarField>::New
(
new volScalarField
IOobject
(
IOobject
(
"sigma",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
"sigma",
mesh_.time().timeName(),
mesh_,
dimSigma
)
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
mesh_,
dimSigma
);
volScalarField& sigma = tsigma.ref();
auto& sigma = tsigma.ref();
const volScalarField& T = mesh_.lookupObject<volScalarField>(TName_);
......
......@@ -34,8 +34,8 @@ Foam::twoPhaseMixture::twoPhaseMixture
const dictionary& dict
)
:
phase1Name_(wordList(dict.lookup("phases"))[0]),
phase2Name_(wordList(dict.lookup("phases"))[1]),
phase1Name_(dict.get<wordList>("phases")[0]),
phase2Name_(dict.get<wordList>("phases")[1]),
alpha1_
(
......
......@@ -51,7 +51,7 @@ constantAlphaContactAngleFvPatchScalarField
)
:
alphaContactAngleFvPatchScalarField(p, iF, dict),
theta0_(readScalar(dict.lookup("theta0")))
theta0_(dict.get<scalar>("theta0"))
{
evaluate();
}
......
......@@ -71,10 +71,10 @@ dynamicAlphaContactAngleFvPatchScalarField
)
:
alphaContactAngleFvPatchScalarField(p, iF, dict),
theta0_(readScalar(dict.lookup("theta0"))),
uTheta_(readScalar(dict.lookup("uTheta"))),
thetaA_(readScalar(dict.lookup("thetaA"))),
thetaR_(readScalar(dict.lookup("thetaR")))
theta0_(dict.get<scalar>("theta0")),
uTheta_(dict.get<scalar>("uTheta")),
thetaA_(dict.get<scalar>("thetaA")),
thetaR_(dict.get<scalar>("thetaR"))
{
evaluate();
}
......
......@@ -72,10 +72,10 @@ timeVaryingAlphaContactAngleFvPatchScalarField
)
:
alphaContactAngleFvPatchScalarField(p, iF, dict),
t0_(readScalar(dict.lookup("t0"))),
thetaT0_(readScalar(dict.lookup("thetaT0"))),
te_(readScalar(dict.lookup("te"))),
thetaTe_(readScalar(dict.lookup("thetaTe")))
t0_(dict.get<scalar>("t0")),
thetaT0_(dict.get<scalar>("thetaT0")),
te_(dict.get<scalar>("te")),
thetaTe_(dict.get<scalar>("thetaTe"))
{
evaluate();
}
......
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