ENH: add guarded lookup for dimensionedSet

STYLE: use standard dimensionedSets
This commit is contained in:
Mark Olesen
2019-01-02 16:53:41 +01:00
parent 2ce944a748
commit 505b4b9c1c
22 changed files with 58 additions and 80 deletions

View File

@ -71,9 +71,8 @@
const surfaceVectorField& Sf = mesh.Sf(); const surfaceVectorField& Sf = mesh.Sf();
forAll(faces, i) for (const label facei : faces)
{ {
label facei = faces[i];
murf[facei] = muri; murf[facei] = muri;
Mrf[facei] = Mri*(orientationi & Sf[facei]); Mrf[facei] = Mri*(orientationi & Sf[facei]);
} }

View File

@ -1,7 +1,7 @@
Info<< "Constructing momentum equations" << endl; Info<< "Constructing momentum equations" << endl;
fvVectorMatrix U1Eqn(U1, rho1.dimensions()*U1.dimensions()*dimVol/dimTime); fvVectorMatrix U1Eqn(U1, rho1.dimensions()*U1.dimensions()*dimVolume/dimTime);
fvVectorMatrix U2Eqn(U2, rho2.dimensions()*U2.dimensions()*dimVol/dimTime); fvVectorMatrix U2Eqn(U2, rho2.dimensions()*U2.dimensions()*dimVolume/dimTime);
{ {
autoPtr<phaseSystem::momentumTransferTable> autoPtr<phaseSystem::momentumTransferTable>

View File

@ -1,7 +1,7 @@
Info<< "Constructing face momentum equations" << endl; Info<< "Constructing face momentum equations" << endl;
fvVectorMatrix U1Eqn(U1, rho1.dimensions()*U1.dimensions()*dimVol/dimTime); fvVectorMatrix U1Eqn(U1, rho1.dimensions()*U1.dimensions()*dimVolume/dimTime);
fvVectorMatrix U2Eqn(U2, rho2.dimensions()*U2.dimensions()*dimVol/dimTime); fvVectorMatrix U2Eqn(U2, rho2.dimensions()*U2.dimensions()*dimVolume/dimTime);
{ {
volScalarField Vm(fluid.Vm()); volScalarField Vm(fluid.Vm());

View File

@ -57,7 +57,7 @@ Foam::kineticTheoryModels::conductivityModels::HrenyaSinclair::HrenyaSinclair
: :
conductivityModel(dict), conductivityModel(dict),
coeffDict_(dict.optionalSubDict(typeName + "Coeffs")), coeffDict_(dict.optionalSubDict(typeName + "Coeffs")),
L_("L", dimensionSet(0, 1, 0, 0, 0), coeffDict_) L_("L", dimLength, coeffDict_)
{} {}

View File

@ -57,7 +57,7 @@ Foam::kineticTheoryModels::viscosityModels::HrenyaSinclair::HrenyaSinclair
: :
viscosityModel(dict), viscosityModel(dict),
coeffDict_(dict.optionalSubDict(typeName + "Coeffs")), coeffDict_(dict.optionalSubDict(typeName + "Coeffs")),
L_("L", dimensionSet(0, 1, 0, 0, 0), coeffDict_) L_("L", dimLength, coeffDict_)
{} {}

View File

@ -60,12 +60,7 @@ Foam::RASModels::phasePressureModel::phasePressureModel
alphaMax_(coeffDict_.get<scalar>("alphaMax")), alphaMax_(coeffDict_.get<scalar>("alphaMax")),
preAlphaExp_(coeffDict_.get<scalar>("preAlphaExp")), preAlphaExp_(coeffDict_.get<scalar>("preAlphaExp")),
expMax_(coeffDict_.get<scalar>("expMax")), expMax_(coeffDict_.get<scalar>("expMax")),
g0_ g0_("g0", dimPressure, coeffDict_)
(
"g0",
dimensionSet(1, -1, -2, 0, 0),
coeffDict_.lookup("g0")
)
{ {
nut_ == dimensionedScalar(nut_.dimensions(), Zero); nut_ == dimensionedScalar(nut_.dimensions(), Zero);
@ -76,12 +71,6 @@ Foam::RASModels::phasePressureModel::phasePressureModel
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::RASModels::phasePressureModel::~phasePressureModel()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::RASModels::phasePressureModel::read() bool Foam::RASModels::phasePressureModel::read()
@ -101,11 +90,9 @@ bool Foam::RASModels::phasePressureModel::read()
return true; return true;
} }
else
{
return false; return false;
} }
}
Foam::tmp<Foam::volScalarField> Foam::tmp<Foam::volScalarField>
@ -138,7 +125,7 @@ Foam::RASModels::phasePressureModel::R() const
IOobject::NO_WRITE IOobject::NO_WRITE
), ),
mesh_, mesh_,
dimensioned<symmTensor>(dimensionSet(0, 2, -2, 0, 0)) //Zero dimensioned<symmTensor>(dimensionSet(0, 2, -2, 0, 0), Zero)
); );
} }

View File

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

View File

@ -4,8 +4,8 @@ MRF.correctBoundaryVelocity(U1);
MRF.correctBoundaryVelocity(U2); MRF.correctBoundaryVelocity(U2);
MRF.correctBoundaryVelocity(U); MRF.correctBoundaryVelocity(U);
fvVectorMatrix U1Eqn(U1, rho1.dimensions()*U1.dimensions()*dimVol/dimTime); fvVectorMatrix U1Eqn(U1, rho1.dimensions()*U1.dimensions()*dimVolume/dimTime);
fvVectorMatrix U2Eqn(U2, rho2.dimensions()*U2.dimensions()*dimVol/dimTime); fvVectorMatrix U2Eqn(U2, rho2.dimensions()*U2.dimensions()*dimVolume/dimTime);
volScalarField Kd(fluid.Kd()); volScalarField Kd(fluid.Kd());

View File

@ -5,8 +5,8 @@ MRF.correctBoundaryVelocity(U2);
MRF.correctBoundaryVelocity(U); MRF.correctBoundaryVelocity(U);
Info<< "Constructing face momentum equations" << endl; Info<< "Constructing face momentum equations" << endl;
fvVectorMatrix U1Eqn(U1, rho1.dimensions()*U1.dimensions()*dimVol/dimTime); fvVectorMatrix U1Eqn(U1, rho1.dimensions()*U1.dimensions()*dimVolume/dimTime);
fvVectorMatrix U2Eqn(U2, rho2.dimensions()*U2.dimensions()*dimVol/dimTime); fvVectorMatrix U2Eqn(U2, rho2.dimensions()*U2.dimensions()*dimVolume/dimTime);
{ {
volScalarField Vm(fluid.Vm()); volScalarField Vm(fluid.Vm());

View File

@ -57,7 +57,7 @@ Foam::kineticTheoryModels::conductivityModels::HrenyaSinclair::HrenyaSinclair
: :
conductivityModel(dict), conductivityModel(dict),
coeffDict_(dict.optionalSubDict(typeName + "Coeffs")), coeffDict_(dict.optionalSubDict(typeName + "Coeffs")),
L_("L", dimensionSet(0, 1, 0, 0, 0), coeffDict_) L_("L", dimLength, coeffDict_)
{} {}

View File

@ -114,7 +114,7 @@ Foam::RASModels::kineticTheoryModel::kineticTheoryModel
maxNut_ maxNut_
( (
"maxNut", "maxNut",
dimensionSet(0,2,-1,0,0), dimViscosity,
coeffDict_.lookupOrDefault<scalar>("maxNut",1000) coeffDict_.lookupOrDefault<scalar>("maxNut",1000)
), ),
@ -142,7 +142,7 @@ Foam::RASModels::kineticTheoryModel::kineticTheoryModel
IOobject::NO_WRITE IOobject::NO_WRITE
), ),
U.mesh(), U.mesh(),
dimensionedScalar(dimensionSet(0, 2, -1, 0, 0), Zero) dimensionedScalar(dimViscosity, Zero)
), ),
gs0_ gs0_
@ -156,7 +156,7 @@ Foam::RASModels::kineticTheoryModel::kineticTheoryModel
IOobject::NO_WRITE IOobject::NO_WRITE
), ),
U.mesh(), U.mesh(),
dimensionedScalar(dimensionSet(0, 0, 0, 0, 0), Zero) dimensionedScalar(dimless, Zero)
), ),
kappa_ kappa_
@ -184,7 +184,7 @@ Foam::RASModels::kineticTheoryModel::kineticTheoryModel
IOobject::AUTO_WRITE IOobject::AUTO_WRITE
), ),
U.mesh(), U.mesh(),
dimensionedScalar(dimensionSet(0, 2, -1, 0, 0), Zero) dimensionedScalar(dimViscosity, Zero)
) )
{ {
if (type == typeName) if (type == typeName)

View File

@ -57,7 +57,7 @@ Foam::kineticTheoryModels::viscosityModels::HrenyaSinclair::HrenyaSinclair
: :
viscosityModel(dict), viscosityModel(dict),
coeffDict_(dict.optionalSubDict(typeName + "Coeffs")), coeffDict_(dict.optionalSubDict(typeName + "Coeffs")),
L_("L", dimensionSet(0, 1, 0, 0, 0), coeffDict_) L_("L", dimLength, coeffDict_)
{} {}

View File

@ -63,12 +63,7 @@ Foam::RASModels::phasePressureModel::phasePressureModel
alphaMax_(coeffDict_.get<scalar>("alphaMax")), alphaMax_(coeffDict_.get<scalar>("alphaMax")),
preAlphaExp_(coeffDict_.get<scalar>("preAlphaExp")), preAlphaExp_(coeffDict_.get<scalar>("preAlphaExp")),
expMax_(coeffDict_.get<scalar>("expMax")), expMax_(coeffDict_.get<scalar>("expMax")),
g0_ g0_("g0", dimPressure, coeffDict_)
(
"g0",
dimensionSet(1, -1, -2, 0, 0),
coeffDict_.lookup("g0")
)
{ {
nut_ == dimensionedScalar(nut_.dimensions(), Zero); nut_ == dimensionedScalar(nut_.dimensions(), Zero);
@ -79,12 +74,6 @@ Foam::RASModels::phasePressureModel::phasePressureModel
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::RASModels::phasePressureModel::~phasePressureModel()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::RASModels::phasePressureModel::read() bool Foam::RASModels::phasePressureModel::read()
@ -107,11 +96,9 @@ bool Foam::RASModels::phasePressureModel::read()
return true; return true;
} }
else
{
return false; return false;
} }
}
Foam::tmp<Foam::volScalarField> Foam::tmp<Foam::volScalarField>

View File

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

View File

@ -221,7 +221,7 @@ void Foam::solverTemplate::setRegionProperties
fieldDimensions_[regionI].set fieldDimensions_[regionI].set
( (
i, i,
new dimensionSet(dict.lookup("dimensions")) new dimensionSet(dict, "dimensions")
); );
} }
} }

View File

@ -68,14 +68,14 @@ public:
typedef FixedList<scalar,7> list_type; typedef FixedList<scalar,7> list_type;
// Member constants // Member Constants
enum enum
{ {
nDimensions = 7 //!< 7 base dimensions nDimensions = 7 //!< 7 base dimensions
}; };
//- Define an enumeration for the names of the dimension exponents //- Enumeration for the dimension exponents
enum dimensionType enum dimensionType
{ {
MASS, //!< kilogram kg MASS, //!< kilogram kg
@ -189,9 +189,12 @@ public:
//- Construct from exponents for all seven dimensions //- Construct from exponents for all seven dimensions
dimensionSet(const FixedList<scalar,7>& dimensions); dimensionSet(const FixedList<scalar,7>& dimensions);
//- Copy constructor //- Copy construct
dimensionSet(const dimensionSet& ds); dimensionSet(const dimensionSet& ds);
//- Construct from dictionary entry - usually "dimensions".
dimensionSet(const dictionary& dict, const word& entryName);
//- Construct and return a clone //- Construct and return a clone
autoPtr<dimensionSet> clone() const autoPtr<dimensionSet> clone() const
{ {

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -30,6 +30,17 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::dimensionSet::dimensionSet(const dictionary& dict, const word& entryName)
{
const entry& e = dict.lookupEntry(entryName, keyType::REGEX);
ITstream& is = e.stream();
is >> *this;
e.checkITstream(is);
}
Foam::dimensionSet::dimensionSet(Istream& is) Foam::dimensionSet::dimensionSet(Istream& is)
{ {
is >> *this; is >> *this;
@ -57,7 +68,7 @@ void Foam::dimensionSet::tokeniser::push(const token& t)
} }
else else
{ {
size_++; ++size_;
} }
} }
@ -620,7 +631,7 @@ Foam::Ostream& Foam::dimensionSet::write
if (writeUnits.valid() && os.format() == IOstream::ASCII) if (writeUnits.valid() && os.format() == IOstream::ASCII)
{ {
scalarField exponents(dimensionSet::nDimensions); scalarField exponents(dimensionSet::nDimensions);
for (int d=0; d<dimensionSet::nDimensions; d++) for (int d=0; d<dimensionSet::nDimensions; ++d)
{ {
exponents[d] = exponents_[d]; exponents[d] = exponents_[d];
} }

View File

@ -47,6 +47,7 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Dimensionless
extern const dimensionSet dimless; extern const dimensionSet dimless;
extern const dimensionSet dimMass; extern const dimensionSet dimMass;
@ -59,6 +60,9 @@ extern const dimensionSet dimLuminousIntensity;
extern const dimensionSet dimArea; extern const dimensionSet dimArea;
extern const dimensionSet dimVolume; extern const dimensionSet dimVolume;
//- Older spelling for dimVolume
// \deprecated(2019-01) use dimVolume instead
extern const dimensionSet dimVol; extern const dimensionSet dimVol;
extern const dimensionSet dimDensity; extern const dimensionSet dimDensity;
@ -76,6 +80,7 @@ extern const dimensionSet dimViscosity;
extern const dimensionSet dimDynamicViscosity; extern const dimensionSet dimDynamicViscosity;
//- Construction of unit sets
class dimensionSets class dimensionSets
{ {
// Private data // Private data
@ -120,7 +125,6 @@ public:
//- (if valid) obtain set of coefficients of unitNames //- (if valid) obtain set of coefficients of unitNames
void coefficients(scalarField& exponents) const; void coefficients(scalarField& exponents) const;
}; };

View File

@ -35,7 +35,7 @@ void Foam::DimensionedField<Type, GeoMesh>::readField
const word& fieldDictEntry const word& fieldDictEntry
) )
{ {
dimensions_.reset(dimensionSet(fieldDict.lookup("dimensions"))); dimensions_.reset(dimensionSet(fieldDict, "dimensions"));
// Note: oriented state may have already been set on construction // Note: oriented state may have already been set on construction
// - if so - do not reset by re-reading // - if so - do not reset by re-reading

View File

@ -85,6 +85,7 @@ bool Foam::UniformDimensionedField<Type>::readData(Istream& is)
dictionary dict(is); dictionary dict(is);
scalar multiplier; scalar multiplier;
this->dimensions().read(dict.lookup("dimensions"), multiplier); this->dimensions().read(dict.lookup("dimensions"), multiplier);
dict.readEntry("value", this->value()); dict.readEntry("value", this->value());
this->value() *= multiplier; this->value() *= multiplier;

View File

@ -113,8 +113,6 @@ void Foam::reactionRateFlameAreaModels::relaxation::correct
const volScalarField omegaInf(correlation_.omega0Sigma(sigmaTotal)); const volScalarField omegaInf(correlation_.omega0Sigma(sigmaTotal));
dimensionedScalar sigma0("sigma0", sigma.dimensions(), Zero);
const volScalarField tau(C_*mag(sigmaTotal)); const volScalarField tau(C_*mag(sigmaTotal));
volScalarField Rc volScalarField Rc
@ -157,10 +155,8 @@ bool Foam::reactionRateFlameAreaModels::relaxation::read
); );
return true; return true;
} }
else
{
return false; return false;
} }
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -70,12 +70,7 @@ functions
} }
reduce(ULeft, maxOp<scalar>()); reduce(ULeft, maxOp<scalar>());
dimensionedScalar uInfX dimensionedScalar uInfX("uInfx", dimVelocity, ULeft);
(
"uInfx",
dimensionSet(0, 1, -1, 0, 0),
ULeft
);
Info << "U at inlet = " << uInfX.value() << " m/s" << endl; Info << "U at inlet = " << uInfX.value() << " m/s" << endl;
@ -89,12 +84,7 @@ functions
} }
reduce(magCylinder, maxOp<scalar>()); reduce(magCylinder, maxOp<scalar>());
dimensionedScalar radius dimensionedScalar radius("radius", dimLength, magCylinder);
(
"radius",
dimensionSet(0, 1, 0, 0, 0),
magCylinder
);
Info << "Cylinder radius = " << radius.value() << " m" << endl; Info << "Cylinder radius = " << radius.value() << " m" << endl;