mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: dimensioned/dimensionedSet handle optional read as per dictionary
This commit is contained in:
@ -874,10 +874,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Optional: "dimensions"
|
// Optional: "dimensions"
|
||||||
dimensionSet dims;
|
dimensionSet dims;
|
||||||
if (dims.readEntry("dimensions", dict, false))
|
ctrl.hasDimensions = dims.readIfPresent("dimensions", dict);
|
||||||
{
|
|
||||||
ctrl.hasDimensions = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.verbose() && !timei)
|
if (args.verbose() && !timei)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -59,6 +59,7 @@ SourceFiles
|
|||||||
#include "scalarField.H"
|
#include "scalarField.H"
|
||||||
#include "PtrList.H"
|
#include "PtrList.H"
|
||||||
#include "HashTable.H"
|
#include "HashTable.H"
|
||||||
|
#include "IOobjectOption.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -146,10 +147,7 @@ private:
|
|||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
Istream& stream()
|
Istream& stream() noexcept { return is_; }
|
||||||
{
|
|
||||||
return is_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasToken() const;
|
bool hasToken() const;
|
||||||
|
|
||||||
@ -230,7 +228,7 @@ public:
|
|||||||
(
|
(
|
||||||
const word& entryName, //!< Lookup key. LITERAL (not REGEX)
|
const word& entryName, //!< Lookup key. LITERAL (not REGEX)
|
||||||
const dictionary& dict,
|
const dictionary& dict,
|
||||||
const bool mandatory = true
|
IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Construct and return a clone
|
//- Construct and return a clone
|
||||||
@ -272,9 +270,24 @@ public:
|
|||||||
(
|
(
|
||||||
const word& entryName, //!< Lookup key. LITERAL (not REGEX)
|
const word& entryName, //!< Lookup key. LITERAL (not REGEX)
|
||||||
const dictionary& dict, //!< The dictionary
|
const dictionary& dict, //!< The dictionary
|
||||||
const bool mandatory = true //!< The entry is mandatory
|
//! The read option
|
||||||
|
IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//- Update the dimensions from dictionary entry.
|
||||||
|
//- FatalIOError if it is found and the number of tokens is incorrect,
|
||||||
|
//- or it is mandatory and not found.
|
||||||
|
//
|
||||||
|
// \return true if the entry was found.
|
||||||
|
bool readIfPresent
|
||||||
|
(
|
||||||
|
const word& entryName, //!< Lookup key. LITERAL (not REGEX)
|
||||||
|
const dictionary& dict //!< The dictionary
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return readEntry(entryName, dict, IOobjectOption::READ_IF_PRESENT);
|
||||||
|
}
|
||||||
|
|
||||||
//- Read using provided units, return scaling in multiplier.
|
//- Read using provided units, return scaling in multiplier.
|
||||||
//- Used only in initial parsing
|
//- Used only in initial parsing
|
||||||
Istream& read
|
Istream& read
|
||||||
|
|||||||
@ -38,12 +38,12 @@ Foam::dimensionSet::dimensionSet
|
|||||||
(
|
(
|
||||||
const word& entryName,
|
const word& entryName,
|
||||||
const dictionary& dict,
|
const dictionary& dict,
|
||||||
const bool mandatory
|
IOobjectOption::readOption readOpt
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
exponents_(Zero)
|
exponents_(Zero)
|
||||||
{
|
{
|
||||||
readEntry(entryName, dict, mandatory);
|
readEntry(entryName, dict, readOpt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -416,9 +416,14 @@ bool Foam::dimensionSet::readEntry
|
|||||||
(
|
(
|
||||||
const word& entryName,
|
const word& entryName,
|
||||||
const dictionary& dict,
|
const dictionary& dict,
|
||||||
const bool mandatory
|
IOobjectOption::readOption readOpt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
if (readOpt == IOobjectOption::NO_READ)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const entry* eptr = dict.findEntry(entryName, keyType::LITERAL);
|
const entry* eptr = dict.findEntry(entryName, keyType::LITERAL);
|
||||||
|
|
||||||
if (eptr)
|
if (eptr)
|
||||||
@ -432,7 +437,7 @@ bool Foam::dimensionSet::readEntry
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (mandatory)
|
else if (IOobjectOption::isReadRequired(readOpt))
|
||||||
{
|
{
|
||||||
FatalIOErrorInFunction(dict)
|
FatalIOErrorInFunction(dict)
|
||||||
<< "Entry '" << entryName << "' not found in dictionary "
|
<< "Entry '" << entryName << "' not found in dictionary "
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -75,11 +75,16 @@ bool Foam::dimensioned<Type>::readEntry
|
|||||||
(
|
(
|
||||||
const word& key,
|
const word& key,
|
||||||
const dictionary& dict,
|
const dictionary& dict,
|
||||||
const bool mandatory,
|
IOobjectOption::readOption readOpt,
|
||||||
const bool checkDims,
|
const bool checkDims,
|
||||||
enum keyType::option matchOpt
|
enum keyType::option matchOpt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
if (readOpt == IOobjectOption::NO_READ)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Largely identical to dictionary::readEntry(),
|
// Largely identical to dictionary::readEntry(),
|
||||||
// but with optional handling of checkDims
|
// but with optional handling of checkDims
|
||||||
|
|
||||||
@ -95,7 +100,7 @@ bool Foam::dimensioned<Type>::readEntry
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (mandatory)
|
else if (IOobjectOption::isReadRequired(readOpt))
|
||||||
{
|
{
|
||||||
FatalIOErrorInFunction(dict)
|
FatalIOErrorInFunction(dict)
|
||||||
<< "Entry '" << key << "' not found in dictionary "
|
<< "Entry '" << key << "' not found in dictionary "
|
||||||
@ -205,7 +210,7 @@ Foam::dimensioned<Type>::dimensioned
|
|||||||
{
|
{
|
||||||
ITstream& is = e.stream();
|
ITstream& is = e.stream();
|
||||||
|
|
||||||
// no checkDims
|
// checkDims = false
|
||||||
initialize(is, false);
|
initialize(is, false);
|
||||||
|
|
||||||
e.checkITstream(is);
|
e.checkITstream(is);
|
||||||
@ -225,7 +230,7 @@ Foam::dimensioned<Type>::dimensioned
|
|||||||
{
|
{
|
||||||
ITstream& is = e.stream();
|
ITstream& is = e.stream();
|
||||||
|
|
||||||
// checkDims
|
// checkDims = true
|
||||||
initialize(is, true);
|
initialize(is, true);
|
||||||
|
|
||||||
e.checkITstream(is);
|
e.checkITstream(is);
|
||||||
@ -243,8 +248,8 @@ Foam::dimensioned<Type>::dimensioned
|
|||||||
dimensions_(),
|
dimensions_(),
|
||||||
value_(Zero)
|
value_(Zero)
|
||||||
{
|
{
|
||||||
// mandatory, no checkDims
|
// checkDims = false
|
||||||
readEntry(name, dict, true, false);
|
readEntry(name, dict, IOobjectOption::MUST_READ, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -260,8 +265,8 @@ Foam::dimensioned<Type>::dimensioned
|
|||||||
dimensions_(dims),
|
dimensions_(dims),
|
||||||
value_(Zero)
|
value_(Zero)
|
||||||
{
|
{
|
||||||
// mandatory, checkDims
|
// checkDims = true
|
||||||
readEntry(name, dict);
|
readEntry(name, dict, IOobjectOption::MUST_READ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -278,8 +283,8 @@ Foam::dimensioned<Type>::dimensioned
|
|||||||
dimensions_(dims),
|
dimensions_(dims),
|
||||||
value_(Zero)
|
value_(Zero)
|
||||||
{
|
{
|
||||||
// mandatory, checkDims
|
// checkDims = true
|
||||||
readEntry(entryName, dict);
|
readEntry(entryName, dict, IOobjectOption::MUST_READ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -296,8 +301,8 @@ Foam::dimensioned<Type>::dimensioned
|
|||||||
dimensions_(dims),
|
dimensions_(dims),
|
||||||
value_(val)
|
value_(val)
|
||||||
{
|
{
|
||||||
// non-mandatory, checkDims
|
// checkDims = true
|
||||||
readEntry(name, dict, false);
|
readEntry(name, dict, IOobjectOption::READ_IF_PRESENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -336,7 +341,7 @@ Foam::dimensioned<Type>::dimensioned
|
|||||||
dimensions_(dims),
|
dimensions_(dims),
|
||||||
value_(Zero)
|
value_(Zero)
|
||||||
{
|
{
|
||||||
// checkDims
|
// checkDims = true
|
||||||
initialize(is, true);
|
initialize(is, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,8 +456,8 @@ bool Foam::dimensioned<Type>::read
|
|||||||
const dictionary& dict
|
const dictionary& dict
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// mandatory, checkDims
|
// checkDims = true
|
||||||
return readEntry(entryName, dict);
|
return readEntry(entryName, dict, IOobjectOption::MUST_READ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -463,8 +468,8 @@ bool Foam::dimensioned<Type>::readIfPresent
|
|||||||
const dictionary& dict
|
const dictionary& dict
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// non-mandatory, checkDims
|
// checkDims = true
|
||||||
return readEntry(entryName, dict, false);
|
return readEntry(entryName, dict, IOobjectOption::READ_IF_PRESENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -35,13 +35,14 @@ SourceFiles
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef dimensionedType_H
|
#ifndef Foam_dimensionedType_H
|
||||||
#define dimensionedType_H
|
#define Foam_dimensionedType_H
|
||||||
|
|
||||||
#include "word.H"
|
#include "word.H"
|
||||||
#include "direction.H"
|
#include "direction.H"
|
||||||
#include "dimensionSet.H"
|
#include "dimensionSet.H"
|
||||||
#include "VectorSpace.H"
|
#include "VectorSpace.H"
|
||||||
|
#include "IOobjectOption.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -107,7 +108,7 @@ class dimensioned
|
|||||||
(
|
(
|
||||||
const word& key,
|
const word& key,
|
||||||
const dictionary& dict,
|
const dictionary& dict,
|
||||||
const bool mandatory = true, //!< entry is mandatory
|
IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ,
|
||||||
const bool checkDims = true, //!< verify dimensions read
|
const bool checkDims = true, //!< verify dimensions read
|
||||||
enum keyType::option matchOpt = keyType::REGEX
|
enum keyType::option matchOpt = keyType::REGEX
|
||||||
);
|
);
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2019-2021 OpenCFD Ltd.
|
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -166,12 +166,7 @@ bool Foam::expressions::volumeExpr::parseDriver::readDict
|
|||||||
|
|
||||||
resultDimensions_.clear(); // Avoid stickiness
|
resultDimensions_.clear(); // Avoid stickiness
|
||||||
|
|
||||||
hasDimensions_ = resultDimensions_.readEntry
|
hasDimensions_ = resultDimensions_.readIfPresent("dimensions", dict);
|
||||||
(
|
|
||||||
"dimensions",
|
|
||||||
dict,
|
|
||||||
false // mandatory=false
|
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -393,7 +393,7 @@ bool Foam::functionObjects::fvExpressionField::read(const dictionary& dict)
|
|||||||
|
|
||||||
// "dimensions" is optional
|
// "dimensions" is optional
|
||||||
dimensions_.clear();
|
dimensions_.clear();
|
||||||
hasDimensions_ = dimensions_.readEntry("dimensions", dict, false);
|
hasDimensions_ = dimensions_.readIfPresent("dimensions", dict);
|
||||||
|
|
||||||
if (action_ == actionType::opNew)
|
if (action_ == actionType::opNew)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user