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.

      Similar to the previous description, except that it is initially
      dimensionless. If entry contains dimensions, they are used
      without further verification. The constructor also includes a
      token stream check.

      This constructor is useful when the dimensions are entirely
      defined from the dictionary input, but also when handling
      transition code where the input dimensions are not obvious from
      the source.

      This constructor can also be handy when obtaining values from
      a dictionary without needing to worry about the input dimensions.
      For example,

         Info<< "rho: " << dimensionedScalar("rho", dict).value() << nl;

      This will accept a large range of inputs without hassle.

ENH: consistent handling of dimensionedType for inputs (#1083)

BUG: incorrect Omega dimensions (fixes #2084)
This commit is contained in:
Mark Olesen 2018-11-20 15:14:10 +01:00
parent efdbeae27e
commit dd87c98393
52 changed files with 301 additions and 337 deletions

View File

@ -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"

View File

@ -47,7 +47,4 @@
Info<< "Reading diffusivity DT\n" << endl;
dimensionedScalar DT
(
transportProperties.lookup("DT")
);
dimensionedScalar DT("DT", dimViscosity, transportProperties);

View File

@ -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"

View File

@ -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))
{}

View File

@ -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)
);
}

View File

@ -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);

View File

@ -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
);

View File

@ -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);

View File

@ -10,32 +10,12 @@ IOdictionary transportProperties
)
);
dimensionedScalar mug
(
transportProperties.lookup("mug")
);
dimensionedScalar mug("mug", dimViscosity, transportProperties);
dimensionedScalar mul("mul", dimViscosity, transportProperties);
dimensionedScalar mul
(
transportProperties.lookup("mul")
);
dimensionedScalar rhog("rhog", dimDensity, transportProperties);
dimensionedScalar rhol("rhol", dimDensity, transportProperties);
dimensionedScalar sigma
(
transportProperties.lookup("sigma")
);
dimensionedScalar sigma("sigma", dimMass/sqr(dimTime), transportProperties);
dimensionedScalar rhol
(
transportProperties.lookup("rhol")
);
dimensionedScalar rhog
(
transportProperties.lookup("rhog")
);
dimensionedScalar h0
(
transportProperties.lookup("h0")
);
dimensionedScalar h0("h0", dimLength, transportProperties);

View File

@ -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
(

View File

@ -29,10 +29,7 @@ IOdictionary transportProperties
Info<< "Reading diffusivity D\n" << endl;
dimensionedScalar Ds
(
transportProperties.lookup("Ds")
);
dimensionedScalar Ds("Ds", dimViscosity, transportProperties);
areaVectorField Us
(

View File

@ -16,7 +16,7 @@ dimensionedScalar nu
(
"nu",
dimViscosity,
transportProperties.lookup("nu")
transportProperties
);
Info<< "Reading field p\n" << endl;

View File

@ -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;

View File

@ -72,10 +72,7 @@ dimensionedScalar rhocValue
(
IOobject::groupName("rho", continuousPhaseName),
dimDensity,
continuousPhaseTransport.lookup
(
IOobject::groupName("rho", continuousPhaseName)
)
continuousPhaseTransport
);
volScalarField rhoc

View File

@ -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)
{}

View File

@ -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;
}

View File

@ -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_
(

View File

@ -47,7 +47,4 @@
Info<< "Reading diffusivity DT\n" << endl;
dimensionedScalar DT
(
transportProperties.lookup("DT")
);
dimensionedScalar DT("DT", dimViscosity, transportProperties);

View File

@ -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"))
{

View File

@ -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;

View File

@ -25,19 +25,25 @@ License
#include "dimensionSet.H"
#include "dimensionedScalar.H"
#include "StringStream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(dimensionSet, 1);
const scalar dimensionSet::smallExponent = SMALL;
defineTypeNameAndDebug(dimensionSet, 1);
}
const Foam::scalar Foam::dimensionSet::smallExponent = SMALL;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::dimensionSet::dimensionSet()
:
exponents_(Zero)
{}
Foam::dimensionSet::dimensionSet
(
const scalar mass,
@ -48,6 +54,8 @@ Foam::dimensionSet::dimensionSet
const scalar current,
const scalar luminousIntensity
)
:
exponents_()
{
exponents_[MASS] = mass;
exponents_[LENGTH] = length;
@ -66,9 +74,9 @@ Foam::dimensionSet::dimensionSet(const FixedList<scalar,7>& dims)
Foam::dimensionSet::dimensionSet(const dimensionSet& ds)
{
reset(ds);
}
:
exponents_(ds.exponents_)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

View File

@ -229,6 +229,9 @@ public:
// Constructors
//- Construct null (dimensionless).
dimensionSet();
//- Construct from exponents for the first five or all seven dimensions
dimensionSet
(
@ -254,7 +257,7 @@ public:
}
//- Construct from Istream
dimensionSet(Istream& is);
explicit dimensionSet(Istream& is);
// Member functions
@ -377,48 +380,48 @@ public:
// Friend operators
friend dimensionSet operator-(const dimensionSet&);
friend dimensionSet operator-(const dimensionSet& ds);
friend dimensionSet operator+
(
const dimensionSet&,
const dimensionSet&
const dimensionSet& ds1,
const dimensionSet& ds2
);
friend dimensionSet operator-
(
const dimensionSet&,
const dimensionSet&
const dimensionSet& ds1,
const dimensionSet& ds2
);
friend dimensionSet operator*
(
const dimensionSet&,
const dimensionSet&
const dimensionSet& ds1,
const dimensionSet& ds2
);
friend dimensionSet operator/
(
const dimensionSet&,
const dimensionSet&
const dimensionSet& ds1,
const dimensionSet& ds2
);
friend dimensionSet operator&
(
const dimensionSet&,
const dimensionSet&
const dimensionSet& ds1,
const dimensionSet& ds2
);
friend dimensionSet operator^
(
const dimensionSet&,
const dimensionSet&
const dimensionSet& ds1,
const dimensionSet& ds2
);
friend dimensionSet operator&&
(
const dimensionSet&,
const dimensionSet&
const dimensionSet& ds1,
const dimensionSet& ds2
);

View File

@ -119,7 +119,7 @@ public:
}
//- (if valid) obtain set of coefficients of unitNames
void coefficients(scalarField&) const;
void coefficients(scalarField& exponents) const;
};

View File

@ -30,13 +30,12 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::dimensioned<Type>::initialize(Istream& is)
void Foam::dimensioned<Type>::initialize(Istream& is, bool checkDims)
{
token nextToken(is);
is.putBack(nextToken);
// Check if the original format is used in which the name is provided
// and reset the name to that read
// Optional name found - use it
if (nextToken.isWord())
{
is >> name_;
@ -44,26 +43,27 @@ void Foam::dimensioned<Type>::initialize(Istream& is)
is.putBack(nextToken);
}
// If the dimensions are provided compare with the argument
scalar multiplier = 1.0;
scalar mult(1.0);
if (nextToken == token::BEGIN_SQR)
{
dimensionSet dims(dimless);
dims.read(is, multiplier);
// Optional dimensions found - use them
const dimensionSet curr(dimensions_);
dimensions_.read(is, mult);
if (dims != dimensions_)
if (checkDims && curr != dimensions_)
{
FatalIOErrorInFunction(is)
<< "The dimensions " << dims
<< " provided do not match the required dimensions "
<< dimensions_
<< "The dimensions " << dimensions_
<< " provided do not match the expected dimensions "
<< curr << endl
<< abort(FatalIOError);
}
}
// Read value
is >> value_;
value_ *= multiplier;
value_ *= mult;
}
@ -124,10 +124,7 @@ Foam::dimensioned<Type>::dimensioned
template<class Type>
Foam::dimensioned<Type>::dimensioned
(
Istream& is
)
Foam::dimensioned<Type>::dimensioned(Istream& is)
:
dimensions_(dimless)
{
@ -145,10 +142,13 @@ Foam::dimensioned<Type>::dimensioned
name_(name),
dimensions_(dimless)
{
scalar multiplier;
dimensions_.read(is, multiplier);
// Read dimensionSet + multiplier
scalar mult(1.0);
dimensions_.read(is, mult);
// Read value
is >> value_;
value_ *= multiplier;
value_ *= mult;
}
@ -164,7 +164,7 @@ Foam::dimensioned<Type>::dimensioned
dimensions_(dims),
value_(Zero)
{
initialize(is);
initialize(is, true); // checkDims
}
@ -172,15 +172,32 @@ template<class Type>
Foam::dimensioned<Type>::dimensioned
(
const word& name,
const dimensionSet& dims,
const dictionary& dict
)
:
dimensioned<Type>(name, dimless, dict, false) // no checkDims
{}
template<class Type>
Foam::dimensioned<Type>::dimensioned
(
const word& name,
const dimensionSet& dims,
const dictionary& dict,
const bool checkDims
)
:
name_(name),
dimensions_(dims),
value_(Zero)
{
initialize(dict.lookup(name));
// Like dictionary::lookup(), but in two stages to detect input errors
const entry& e = dict.lookupEntry(name, keyType::REGEX);
ITstream& is = e.stream();
initialize(is, checkDims);
e.checkITstream(is);
}
@ -195,12 +212,13 @@ Foam::dimensioned<Type> Foam::dimensioned<Type>::lookupOrDefault
const Type& defaultValue
)
{
if (dict.found(name))
{
return dimensioned<Type>(name, dims, dict.get<Type>(name));
}
return dimensioned<Type>(name, dims, defaultValue);
return
dimensioned<Type>
(
name,
dims,
dict.lookupOrDefault<Type>(name, defaultValue)
);
}
@ -325,6 +343,25 @@ bool Foam::dimensioned<Type>::readIfPresent(const dictionary& dict)
}
template<class Type>
Foam::Istream& Foam::dimensioned<Type>::read(Istream& is)
{
// Read name
is >> name_;
// Read dimensionSet + multiplier
scalar mult(1.0);
dimensions_.read(is, mult);
// Read value
is >> value_;
value_ *= mult;
is.check(FUNCTION_NAME);
return is;
}
template<class Type>
Foam::Istream&
Foam::dimensioned<Type>::read(Istream& is, const dictionary& readSet)
@ -333,7 +370,7 @@ Foam::dimensioned<Type>::read(Istream& is, const dictionary& readSet)
is >> name_;
// Read dimensionSet + multiplier
scalar mult;
scalar mult(1.0);
dimensions_.read(is, mult, readSet);
// Read value
@ -356,7 +393,7 @@ Foam::Istream& Foam::dimensioned<Type>::read
is >> name_;
// Read dimensionSet + multiplier
scalar mult;
scalar mult(1.0);
dimensions_.read(is, mult, readSet);
// Read value
@ -368,25 +405,6 @@ Foam::Istream& Foam::dimensioned<Type>::read
}
template<class Type>
Foam::Istream& Foam::dimensioned<Type>::read(Istream& is)
{
// Read name
is >> name_;
// Read dimensionSet + multiplier
scalar mult;
dimensions_.read(is, mult);
// Read value
is >> value_;
value_ *= mult;
is.check(FUNCTION_NAME);
return is;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Type>
@ -574,29 +592,7 @@ Foam::dimensioned<Type> Foam::min
template<class Type>
Foam::Istream& Foam::operator>>(Istream& is, dimensioned<Type>& dt)
{
token nextToken(is);
is.putBack(nextToken);
// Check if the original format is used in which the name is provided
// and reset the name to that read
if (nextToken.isWord())
{
is >> dt.name_;
is >> nextToken;
is.putBack(nextToken);
}
// If the dimensions are provided reset the dimensions to those read
scalar multiplier = 1.0;
if (nextToken == token::BEGIN_SQR)
{
dt.dimensions_.read(is, multiplier);
}
// Read the value
is >> dt.value_;
dt.value_ *= multiplier;
dt.initialize(is, false); // no checkDims
is.check(FUNCTION_NAME);
return is;
}
@ -609,7 +605,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const dimensioned<Type>& dt)
os << dt.name() << token::SPACE;
// Write the dimensions
scalar mult;
scalar mult(1.0);
dt.dimensions().write(os, mult);
os << token::SPACE;

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -79,9 +79,16 @@ class dimensioned
// Private member functions
//- Initialize from Istream
// Helper-function for constructors
void initialize(Istream& is);
//- Constructor helper.
// Requires a value, optional preceded with name and/or dimensions.
// \verbatim
// [name] [dims] value
// \endverbatim
// If the name is present, it is used to rename.
// If dimensions are present, they are read.
// With checkDims = true, the dimensions read are verified
// against the current (expected) dimensions.
void initialize(Istream& is, bool checkDims);
public:
@ -92,7 +99,7 @@ public:
// Constructors
//- Null constructor: a dimensionless Zero, named "0"
//- Construct null: a dimensionless Zero, named "0"
dimensioned();
//- A dimensioned Zero, named "0"
@ -101,7 +108,7 @@ public:
//- A dimensioned Zero, named "0"
explicit dimensioned(const dimensionSet& dims, const zero);
//- Construct dimensionless from given value.
//- Implicit construct dimensionless from given value.
dimensioned(const Type& val)
:
name_(::Foam::name(val)),
@ -109,7 +116,7 @@ public:
value_(val)
{}
//- Copy construct a dimensioned Type with a new name
//- Copy construct dimensioned Type with a new name
dimensioned(const word& name, const dimensioned<Type>& dt);
//- Construct from components: name, dimensionSet and a value.
@ -120,21 +127,31 @@ public:
const Type& val
);
//- Construct from Istream.
dimensioned(Istream& is);
//- Construct from dictionary lookup with a given name.
// The dictionary entry may contain optional name and dimensions.
// \verbatim
// [name] [dims] value
// \endverbatim
// If the optional name is found, it is used for renaming.
// If the optional dimensions are present, they are read and
// used without further verification.
// If no dimensions are found, the quantity is dimensionless.
dimensioned(const word& name, const dictionary& dict);
//- Construct from Istream with a given name
dimensioned(const word& name, Istream& is);
//- Construct from Istream with a given name and dimensions
dimensioned(const word& name, const dimensionSet& dims, Istream& is);
//- Construct from dictionary lookup with a given name and dimensions
//- Construct from dictionary lookup with a given name and dimensions.
// The dictionary entry may contain optional name and dimensions.
// \verbatim
// [name] [dims] value
// \endverbatim
// If the optional name is found, it is used for renaming.
// If the optional dimensions are present, they are read and
// normally verified against the expected dimensions.
dimensioned
(
const word& name,
const dimensionSet& dims,
const dictionary& dict
const dictionary& dict,
const bool checkDims = true //!< verify dimensions read
);
@ -181,7 +198,7 @@ public:
);
// Member functions
// Member Functions
//- Return const reference to name.
const word& name() const;
@ -210,26 +227,29 @@ public:
//- Return transpose.
dimensioned<Type> T() const;
//- Update the value of dimensioned<Type>
//- Update the value of dimensioned\<Type\>
void read(const dictionary& dict);
//- Update the value of dimensioned<Type> if found in the dictionary.
//- Update the value of dimensioned\<Type\> if found in the dictionary.
bool readIfPresent(const dictionary& dict);
// I/O
// IO
//- Read value from stream and units from dictionary
Istream& read(Istream& is, const dictionary& readSet);
//- Read value from stream and units from table
Istream& read(Istream& is, const HashTable<dimensionedScalar>& readSet);
//- Read value from stream and units from system table
//- Read name, dimensions, value from stream,
//- using units from system table
Istream& read(Istream& is);
//- Read name, dimensions, value from stream,
//- using units from dictionary
Istream& read(Istream& is, const dictionary& readSet);
// Member operators
//- Read name, dimensions, value from stream,
//- using units from table
Istream& read(Istream& is, const HashTable<dimensionedScalar>& readSet);
// Member Operators
//- Return a component as a dimensioned<cmptType>
dimensioned<cmptType> operator[](const direction d) const;
@ -242,6 +262,9 @@ public:
// IOstream operators
//- Read from stream. The name and dimensions are optional.
// If the optional dimensions are present, they are used
// used without further verification.
friend Istream& operator>> <Type>
(
Istream& is,
@ -253,6 +276,33 @@ public:
Ostream& os,
const dimensioned<Type>& dt
);
// Housekeeping
//- Deprecated(2018-11) Construct from Istream
//- (expects name, dimensions, value)
// \deprecated(2018-11) - should generally use one of the construct
// from dictionary constructors instead. They provide additional
// checks on the input stream.
explicit dimensioned(Istream& is);
//- Deprecated(2018-11) Construct from Istream with given name
//- (expects dimensions, value)
// \deprecated(2018-11) - should generally use one of the construct
// from dictionary constructors instead. They provide additional
// checks on the input stream.
dimensioned(const word& name, Istream& is);
//- Deprecated(2018-11) Construct from Istream with given name
//- and expected dimensions.
// Expects value, but supports optional name and dimensions.
// If the optional dimensions are present, they are read and
// verified against the expected dimensions.
// \deprecated(2018-11) - should generally use one of the construct
// from dictionary constructors instead. They provide additional
// checks on the input stream.
dimensioned(const word& name, const dimensionSet& dims, Istream& is);
};

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -25,16 +25,17 @@ License
#include "dimensionedConstants.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
dictionary* dimensionedConstantsPtr_(nullptr);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dictionary* dimensionedConstantsPtr_(nullptr);
dictionary& dimensionedConstants()
Foam::dictionary& Foam::dimensionedConstants()
{
return debug::switchSet
(
@ -44,7 +45,7 @@ dictionary& dimensionedConstants()
}
dimensionedScalar dimensionedConstant
Foam::dimensionedScalar Foam::dimensionedConstant
(
const word& group,
const word& varName
@ -57,28 +58,24 @@ dimensionedScalar dimensionedConstant
if (!dict.found("unitSet"))
{
std::cerr<< "Cannot find unitSet in dictionary " << dict.name()
std::cerr
<< "Cannot find unitSet in dictionary " << dict.name()
<< std::endl;
}
const word unitSetCoeffs(dict.get<word>("unitSet") + "Coeffs");
if (!dict.found(unitSetCoeffs))
const dictionary* unitDictPtr = dict.findDict(unitSetCoeffs);
if (!unitDictPtr)
{
std::cerr<< "Cannot find " << unitSetCoeffs << " in dictionary "
std::cerr
<< "Cannot find " << unitSetCoeffs << " in dictionary "
<< dict.name() << std::endl;
}
dictionary& unitDict = dict.subDict(unitSetCoeffs);
dictionary& groupDict = unitDict.subDict(group);
return dimensionedScalar(groupDict.lookup(varName));
return dimensionedScalar(varName, unitDictPtr->subDict(group));
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -74,11 +74,11 @@ Foam::crankConRod::crankConRod
systemName,
constantName
),
rpm_(dict_.lookup("rpm")),
conRodLength_(dimensionedScalar("conRodLength", dimLength, 0)),
bore_(dimensionedScalar("bore", dimLength, 0)),
stroke_(dimensionedScalar("stroke", dimLength, 0)),
clearance_(dimensionedScalar("clearance", dimLength, 0))
rpm_("rpm", dimless/dimTime, dict_),
conRodLength_("conRodLength", dimLength, Zero),
bore_("bore", dimLength, Zero),
stroke_("stroke", dimLength, Zero),
clearance_("clearance", dimLength, Zero)
{
// geometric parameters are not strictly required for Time
dict_.readIfPresent("conRodLength", conRodLength_);
@ -112,10 +112,8 @@ bool Foam::crankConRod::read()
timeAdjustment();
return true;
}
else
{
return false;
}
return false;
}

View File

@ -4,7 +4,7 @@
{
// Calculate volume of ignition kernel
dimensionedScalar Vk("Vk", dimVolume, gSum(c*mesh.V().field()));
dimensionedScalar Ak("Ak", dimArea, 0.0);
dimensionedScalar Ak("Ak", dimArea, Zero);
if (Vk.value() > SMALL)
{
@ -39,7 +39,7 @@
// Assume it is part-circular
dimensionedScalar thickness
(
combustionProperties.lookup("ignitionThickness")
"ignitionThickness", dimLength, combustionProperties
);
scalar circleFraction
@ -67,7 +67,7 @@
// Assume it is plane or two planes
Ak = dimensionedScalar
(
combustionProperties.lookup("ignitionKernelArea")
"ignitionKernelArea", dimArea, combustionProperties
);
break;
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -108,13 +108,11 @@ void Foam::fixedPressureCompressibleDensityFvPatchScalarField::updateCoeffs()
const dictionary& thermoProps =
db().lookupObject<IOdictionary>("thermodynamicProperties");
const scalar rholSat =
dimensionedScalar(thermoProps.lookup("rholSat")).value();
const scalar rholSat = dimensionedScalar("rholSat", thermoProps).value();
const scalar pSat =
dimensionedScalar(thermoProps.lookup("pSat")).value();
const scalar pSat = dimensionedScalar("pSat", thermoProps).value();
const scalar psil = dimensionedScalar(thermoProps.lookup("psil")).value();
const scalar psil = dimensionedScalar("psil", thermoProps).value();
operator==(rholSat + psil*(pp - pSat));

View File

@ -93,7 +93,7 @@ bool Foam::functionObjects::PecletNo::calc()
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar(model.lookup("nu"))
dimensionedScalar("nu", dimViscosity, model)
);
}
else

View File

@ -141,7 +141,7 @@ Foam::heatTransferCoeffModels::ReynoldsAnalogy::devReff() const
const dictionary& transportProperties =
mesh_.lookupObject<dictionary>("transportProperties");
dimensionedScalar nu(transportProperties.lookup("nu"));
dimensionedScalar nu("nu", dimViscosity, transportProperties);
const volVectorField& U = mesh_.lookupObject<volVectorField>(UName_);

View File

@ -50,9 +50,9 @@ Foam::solidParticleCloud::solidParticleCloud
IOobject::NO_WRITE
)
),
rhop_(dimensionedScalar(particleProperties_.lookup("rhop")).value()),
e_(dimensionedScalar(particleProperties_.lookup("e")).value()),
mu_(dimensionedScalar(particleProperties_.lookup("mu")).value())
rhop_(dimensionedScalar("rhop", particleProperties_).value()),
e_(dimensionedScalar("e", particleProperties_).value()),
mu_(dimensionedScalar("mu", particleProperties_).value())
{
if (readFields)
{

View File

@ -222,7 +222,7 @@ Foam::laminarFlameSpeedModels::Gulders::operator()() const
psiuReactionThermo_.Tu(),
dimensionedScalar
(
psiuReactionThermo_.lookup("stoichiometricAirFuelMassRatio")
"stoichiometricAirFuelMassRatio", dimless, psiuReactionThermo_
)*ft/max(1 - ft, SMALL)
);
}

View File

@ -226,7 +226,7 @@ Foam::laminarFlameSpeedModels::GuldersEGR::operator()() const
psiuReactionThermo_.Tu(),
dimensionedScalar
(
psiuReactionThermo_.lookup("stoichiometricAirFuelMassRatio")
"stoichiometricAirFuelMassRatio", dimless, psiuReactionThermo_
)/
(
scalar(1)/psiuReactionThermo_.composition().Y("ft")

View File

@ -313,7 +313,7 @@ Foam::laminarFlameSpeedModels::RaviPetersen::operator()() const
EqR =
dimensionedScalar
(
psiuReactionThermo_.lookup("stoichiometricAirFuelMassRatio")
"stoichiometricAirFuelMassRatio", dimless, psiuReactionThermo_
)*ft/max(1 - ft, SMALL);
}
else

View File

@ -54,7 +54,7 @@ Foam::laminarFlameSpeedModels::constant::constant
:
laminarFlameSpeed(dict, ct),
Su_(dict.lookup("Su"))
Su_("Su", dimVelocity, dict)
{}

View File

@ -50,7 +50,7 @@ Foam::laminarFlameSpeed::laminarFlameSpeed
if (!psiuReactionThermo_.composition().contains("ft"))
{
equivalenceRatio_ =
dimensionedScalar(dict.lookup("equivalenceRatio")).value();
dimensionedScalar("equivalenceRatio", dimless, dict).value();
}
}

View File

@ -54,15 +54,9 @@ Foam::radiation::constantAbsorptionEmission::constantAbsorptionEmission
:
absorptionEmissionModel(dict, mesh),
coeffsDict_(dict.optionalSubDict(typeName + "Coeffs")),
a_(coeffsDict_.lookup("absorptivity")),
e_(coeffsDict_.lookup("emissivity")),
E_(coeffsDict_.lookup("E"))
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::radiation::constantAbsorptionEmission::~constantAbsorptionEmission()
a_("absorptivity", coeffsDict_),
e_("emissivity", coeffsDict_),
E_("E", coeffsDict_)
{}

View File

@ -84,7 +84,7 @@ public:
//- Destructor
virtual ~constantAbsorptionEmission();
virtual ~constantAbsorptionEmission() = default;
// Member Functions

View File

@ -54,14 +54,8 @@ Foam::radiation::constantScatter::constantScatter
:
scatterModel(dict, mesh),
coeffsDict_(dict.optionalSubDict(typeName + "Coeffs")),
sigma_(coeffsDict_.lookup("sigma")),
C_(coeffsDict_.lookup("C"))
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::radiation::constantScatter::~constantScatter()
sigma_("sigma", dimless/dimLength, coeffsDict_),
C_("C", dimless, coeffsDict_)
{}

View File

@ -85,7 +85,7 @@ public:
//- Destructor
virtual ~constantScatter();
virtual ~constantScatter() = default;
// Member Functions

View File

@ -50,12 +50,6 @@ Foam::radiation::noScatter::noScatter
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::radiation::noScatter::~noScatter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::tmp<Foam::volScalarField> Foam::radiation::noScatter::sigmaEff() const

View File

@ -69,7 +69,7 @@ public:
//- Destructor
virtual ~noScatter();
virtual ~noScatter() = default;
// Member Functions

View File

@ -50,7 +50,7 @@ Foam::egrMixture<ThermoType>::egrMixture
phaseName
),
stoicRatio_(thermoDict.lookup("stoichiometricAirFuelMassRatio")),
stoicRatio_("stoichiometricAirFuelMassRatio", dimless, thermoDict),
fuel_(thermoDict.subDict("fuel")),
oxidant_(thermoDict.subDict("oxidant")),
@ -101,7 +101,7 @@ const ThermoType& Foam::egrMixture<ThermoType>::mixture
template<class ThermoType>
void Foam::egrMixture<ThermoType>::read(const dictionary& thermoDict)
{
stoicRatio_ = thermoDict.lookup("stoichiometricAirFuelMassRatio");
thermoDict.readEntry("stoichiometricAirFuelMassRatio", stoicRatio_);
fuel_ = ThermoType(thermoDict.subDict("fuel"));
oxidant_ = ThermoType(thermoDict.subDict("oxidant"));

View File

@ -93,8 +93,7 @@ public:
//- Destructor
virtual ~egrMixture()
{}
virtual ~egrMixture() = default;
// Member functions

View File

@ -54,7 +54,7 @@ Foam::inhomogeneousMixture<ThermoType>::inhomogeneousMixture
phaseName
),
stoicRatio_(thermoDict.lookup("stoichiometricAirFuelMassRatio")),
stoicRatio_("stoichiometricAirFuelMassRatio", dimless, thermoDict),
fuel_(thermoDict.subDict("fuel")),
oxidant_(thermoDict.subDict("oxidant")),
@ -98,7 +98,7 @@ const ThermoType& Foam::inhomogeneousMixture<ThermoType>::mixture
template<class ThermoType>
void Foam::inhomogeneousMixture<ThermoType>::read(const dictionary& thermoDict)
{
stoicRatio_ = thermoDict.lookup("stoichiometricAirFuelMassRatio");
thermoDict.readEntry("stoichiometricAirFuelMassRatio", stoicRatio_);
fuel_ = ThermoType(thermoDict.subDict("fuel"));
oxidant_ = ThermoType(thermoDict.subDict("oxidant"));

View File

@ -90,8 +90,7 @@ public:
//- Destructor
virtual ~inhomogeneousMixture()
{}
virtual ~inhomogeneousMixture() = default;
// Member functions

View File

@ -129,8 +129,7 @@ public:
//- Destructor
virtual ~singleStepReactingMixture()
{}
virtual ~singleStepReactingMixture() = default;
// Member functions

View File

@ -55,7 +55,7 @@ Foam::veryInhomogeneousMixture<ThermoType>::veryInhomogeneousMixture
phaseName
),
stoicRatio_(thermoDict.lookup("stoichiometricAirFuelMassRatio")),
stoicRatio_("stoichiometricAirFuelMassRatio", dimless, thermoDict),
fuel_(thermoDict.subDict("fuel")),
oxidant_(thermoDict.subDict("oxidant")),

View File

@ -98,8 +98,7 @@ public:
//- Destructor
virtual ~veryInhomogeneousMixture()
{}
virtual ~veryInhomogeneousMixture() = default;
// Member functions

View File

@ -48,7 +48,7 @@ Foam::surfaceTensionModels::constant::constant
)
:
surfaceTensionModel(mesh),
sigma_("sigma", dimensionSet(1, 0, -2, 0, 0), dict)
sigma_("sigma", dimMass/sqr(dimTime), dict)
{}

View File

@ -15,7 +15,7 @@ const scalar nu2 =
(
"nu",
dimViscosity,
transportProperties.lookup("nu")
transportProperties
).value();
Info<< "Reading viscoelastic properties\n" << endl;