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

ENH: add read guard for dimensionedType constructors (#762)

- deprecate dimensionedType constructors using an Istream in favour of
  versions accepting a keyword and a dictionary.

  Dictionary entries are almost the exclusive means of read
  constructing a dimensionedType. By construct from the dictionary
  entry instead of doing a lookup() first, we can detect possible
  input errors such as too many tokens as a result of a input syntax
  error.

  Constructing a dimensionedType from a dictionary entry now has
  two forms.

  1.  dimensionedType(key, dims, dict);

      This is the constructor that will normally be used.

      It accepts entries with optional leading names and/or
      dimensions. If the entry contains dimensions, they are
      verified against the expected dimensions and an IOError is
      raised if they do not correspond. On conclusion, checks the
      token stream for any trailing rubbish.

  2.  dimensionedType(key, dict);

      This constructor is used less frequently.

      ...
parent efdbeae2
......@@ -31,11 +31,6 @@ IOdictionary transportProperties
Info<< "Reading diffusivity DT\n" << endl;
dimensionedScalar DT
(
"DT",
dimArea/dimTime,
transportProperties
);
dimensionedScalar DT("DT", dimViscosity, transportProperties);
#include "createFvOptions.H"
......@@ -47,7 +47,4 @@
Info<< "Reading diffusivity DT\n" << endl;
dimensionedScalar DT
(
transportProperties.lookup("DT")
);
dimensionedScalar DT("DT", dimViscosity, transportProperties);
......@@ -47,12 +47,7 @@ IOdictionary transportProperties
Info<< "Reading diffusivity DT\n" << endl;
dimensionedScalar DT
(
"DT",
dimArea/dimTime,
transportProperties
);
dimensionedScalar DT("DT", dimViscosity, transportProperties);
#include "createPhi.H"
......
......@@ -49,8 +49,8 @@ Foam::XiGModels::instabilityG::instabilityG
)
:
XiGModel(XiGProperties, thermo, turbulence, Su),
GIn_(XiGModelCoeffs_.lookup("GIn")),
lambdaIn_(XiGModelCoeffs_.lookup("lambdaIn")),
GIn_("GIn", dimless/dimTime, XiGModelCoeffs_),
lambdaIn_("lambdaIn", dimLength, XiGModelCoeffs_),
XiGModel_(XiGModel::New(XiGModelCoeffs_, thermo, turbulence, Su))
{}
......
......@@ -408,7 +408,7 @@ Foam::laminarFlameSpeedModels::SCOPE::Ma() const
(
dimensionedScalar
(
psiuReactionThermo_.lookup("stoichiometricAirFuelMassRatio")
"stoichiometricAirFuelMassRatio", dimless, psiuReactionThermo_
)*ft/(scalar(1) - ft)
);
}
......@@ -449,7 +449,7 @@ Foam::laminarFlameSpeedModels::SCOPE::operator()() const
psiuReactionThermo_.Tu(),
dimensionedScalar
(
psiuReactionThermo_.lookup("stoichiometricAirFuelMassRatio")
"stoichiometricAirFuelMassRatio", dimless, psiuReactionThermo_
)*ft/(scalar(1) - ft)
);
}
......
......@@ -12,34 +12,34 @@
)
);
word SuModel
const word SuModel
(
combustionProperties.lookup("SuModel")
combustionProperties.get<word>("SuModel")
);
dimensionedScalar sigmaExt
(
combustionProperties.lookup("sigmaExt")
"sigmaExt", dimless/dimTime, combustionProperties
);
word XiModel
const word XiModel
(
combustionProperties.lookup("XiModel")
combustionProperties.get<word>("XiModel")
);
dimensionedScalar XiCoef
(
combustionProperties.lookup("XiCoef")
"XiCoef", dimless, combustionProperties
);
dimensionedScalar XiShapeCoef
(
combustionProperties.lookup("XiShapeCoef")
"XiShapeCoef", dimless, combustionProperties
);
dimensionedScalar uPrimeCoef
(
combustionProperties.lookup("uPrimeCoef")
"uPrimeCoef", dimless, combustionProperties
);
ignition ign(combustionProperties, runTime, mesh);
......@@ -14,12 +14,16 @@
dimensionedScalar epsilon0
(
physicalProperties.lookup("epsilon0")
"epsilon0",
dimensionSet(-1, -3, 4, 0, 0, 2, 0),
physicalProperties
);
dimensionedScalar k
(
physicalProperties.lookup("k")
"k",
dimensionSet(-1, 0, 2, 0, 0, 1, 0),
physicalProperties
);
......
......@@ -16,21 +16,21 @@ dimensionedScalar strike
(
"strike",
dimLength,
financialProperties.lookup("strike")
financialProperties
);
dimensionedScalar r
(
"r",
dimless/dimTime,
financialProperties.lookup("r")
financialProperties
);
dimensionedScalar sigma
(
"sigma",
dimensionSet(0, 0, -0.5, 0, 0),
financialProperties.lookup("sigma")
financialProperties
);
dimensionedScalar sigmaSqr = sqr(sigma);
......
......@@ -10,32 +10,12 @@ IOdictionary transportProperties
)
);
dimensionedScalar mug
(
transportProperties.lookup("mug")
);
dimensionedScalar mul
(
transportProperties.lookup("mul")
);
dimensionedScalar sigma
(
transportProperties.lookup("sigma")
);
dimensionedScalar mug("mug", dimViscosity, transportProperties);
dimensionedScalar mul("mul", dimViscosity, transportProperties);
dimensionedScalar rhol
(
transportProperties.lookup("rhol")
);
dimensionedScalar rhog("rhog", dimDensity, transportProperties);
dimensionedScalar rhol("rhol", dimDensity, transportProperties);
dimensionedScalar rhog
(
transportProperties.lookup("rhog")
);
dimensionedScalar sigma("sigma", dimMass/sqr(dimTime), transportProperties);
dimensionedScalar h0
(
transportProperties.lookup("h0")
);
dimensionedScalar h0("h0", dimLength, transportProperties);
......@@ -12,25 +12,13 @@ areaScalarField Cs
aMesh
);
dimensioned<scalar> Cs0
(
"Cs0",
dimensionSet(1, -2, 0, 0, 0, 0, 0),
1.0
);
dimensionedScalar Cs0("Cs0", dimMass/dimArea, 1.0);
const areaVectorField& R = aMesh.areaCentres();
Cs = Cs0*(1.0 + R.component(vector::X)/mag(R));
dimensioned<scalar> Ds
(
"Ds",
dimensionSet(0, 2, -1, 0, 0, 0, 0),
1.0
);
dimensionedScalar Ds("Ds", dimViscosity, 1.0);
areaVectorField Us
(
......
......@@ -29,10 +29,7 @@ IOdictionary transportProperties
Info<< "Reading diffusivity D\n" << endl;
dimensionedScalar Ds
(
transportProperties.lookup("Ds")
);
dimensionedScalar Ds("Ds", dimViscosity, transportProperties);
areaVectorField Us
(
......
......@@ -16,7 +16,7 @@ dimensionedScalar nu
(
"nu",
dimViscosity,
transportProperties.lookup("nu")
transportProperties
);
Info<< "Reading field p\n" << endl;
......
......@@ -12,12 +12,13 @@ IOdictionary gravitationalProperties
)
);
const dimensionedVector g(gravitationalProperties.lookup("g"));
const dimensionedVector g("g", dimAcceleration, gravitationalProperties);
const bool rotating(gravitationalProperties.get<bool>("rotating"));
const dimensionedVector Omega =
(
rotating ? gravitationalProperties.lookup("Omega")
: dimensionedVector("Omega", -dimTime, vector(0,0,0))
rotating
? dimensionedVector("Omega", dimless/dimTime, gravitationalProperties)
: dimensionedVector("Omega", dimless/dimTime, Zero)
);
const dimensionedScalar magg = mag(g);
const dimensionedVector gHat = g/magg;
......@@ -72,10 +72,7 @@ dimensionedScalar rhocValue
(
IOobject::groupName("rho", continuousPhaseName),
dimDensity,
continuousPhaseTransport.lookup
(
IOobject::groupName("rho", continuousPhaseName)
)
continuousPhaseTransport
);
volScalarField rhoc
......
......@@ -55,7 +55,7 @@ constantSurfaceTensionCoefficient
)
:
surfaceTensionModel(dict, pair, registerObject),
sigma_("sigma", dimensionSet(1, 0, -2, 0, 0), dict.lookup("sigma"))
sigma_("sigma", dimMass/sqr(dimTime), dict)
{}
......
......@@ -53,10 +53,15 @@ Foam::temperaturePhaseChangeTwoPhaseMixtures::constant::constant
)
:
temperaturePhaseChangeTwoPhaseMixture(mixture, mesh),
coeffC_(subDict(type() + "Coeffs").lookup("coeffC")),
coeffE_(subDict(type() + "Coeffs").lookup("coeffE"))
{
}
coeffC_
(
"coeffC", dimless/dimTime/dimTemperature, subDict(type() + "Coeffs")
),
coeffE_
(
"coeffE", dimless/dimTime/dimTemperature, subDict(type() + "Coeffs")
)
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
......@@ -163,10 +168,8 @@ bool Foam::temperaturePhaseChangeTwoPhaseMixtures::constant::read()
return true;
}
else
{
return false;
}
return false;
}
......
......@@ -160,8 +160,8 @@ Foam::threePhaseInterfaceProperties::threePhaseInterfaceProperties
mixture_.alpha1().name()
).get<scalar>("cAlpha")
),
sigma12_("sigma12", dimensionSet(1, 0, -2, 0, 0), mixture),
sigma13_("sigma13", dimensionSet(1, 0, -2, 0, 0), mixture),
sigma12_("sigma12", dimMass/sqr(dimTime), mixture),
sigma13_("sigma13", dimMass/sqr(dimTime), mixture),
deltaN_
(
......
......@@ -47,7 +47,4 @@
Info<< "Reading diffusivity DT\n" << endl;
dimensionedScalar DT
(
transportProperties.lookup("DT")
);
dimensionedScalar DT("DT", dimViscosity, transportProperties);
......@@ -57,7 +57,7 @@ y.correctBoundaryConditions();
// Set the mean boundary-layer thickness
dimensionedScalar ybl("ybl", dimLength, 0);
dimensionedScalar ybl("ybl", dimLength, Zero);
if (args.found("ybl"))
{
......
......@@ -12,35 +12,17 @@ IOdictionary engineGeometry
)
);
vector swirlAxis
(
engineGeometry.lookup("swirlAxis")
);
vector swirlAxis(engineGeometry.get<vector>("swirlAxis"));
vector swirlCenter
(
engineGeometry.lookup("swirlCenter")
);
vector swirlCenter(engineGeometry.get<vector>("swirlCenter"));
dimensionedScalar swirlRPMRatio
(
engineGeometry.lookup("swirlRPMRatio")
);
dimensionedScalar swirlRPMRatio("swirlRPMRatio", engineGeometry);
dimensionedScalar swirlProfile
(
engineGeometry.lookup("swirlProfile")
);
dimensionedScalar swirlProfile("swirlProfile", engineGeometry);
dimensionedScalar bore
(
engineGeometry.lookup("bore")
);
dimensionedScalar bore("bore", dimLength, engineGeometry);
dimensionedScalar rpm
(
engineGeometry.lookup("rpm")
);
dimensionedScalar rpm("rpm", dimless/dimTime, engineGeometry);
Info<< "Reading field U\n" << endl;
......
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