Commit 873b2f0a authored by Mark OLESEN's avatar Mark OLESEN
Browse files

STYLE: use explicit dictionary access for dictionaryEntry

- clarifies the meanings of get<T> etc, avoids later ambiguities.

ENH: simplify phaseProperties construction, add input checks
parent 7864672c
......@@ -39,8 +39,6 @@ SourceFiles
#include "rhoThermo.H"
#include "volFields.H"
#include "dictionaryEntry.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -30,9 +30,10 @@ License
Foam::cellModel::cellModel(Istream& is)
{
dictionaryEntry dict(dictionary::null, is);
const dictionaryEntry dictEntry(dictionary::null, is);
const dictionary& dict = dictEntry.dict();
name_ = dict.keyword();
name_ = dictEntry.keyword();
dict.readEntry("index", index_);
dict.readEntry("numberOfPoints", nPoints_);
dict.readEntry("faces", faces_);
......
......@@ -26,6 +26,7 @@ License
#include "motionSolver.H"
#include "Time.H"
#include "polyMesh.H"
#include "dictionaryEntry.H"
#include "dlLibraryTable.H"
#include "twoDPointCorrector.H"
......@@ -172,7 +173,7 @@ Foam::autoPtr<Foam::motionSolver> Foam::motionSolver::iNew::operator()
Istream& is
) const
{
dictionaryEntry dict(dictionary::null, is);
dictionaryEntry dictEntry(dictionary::null, is);
return motionSolver::New
(
......@@ -181,11 +182,11 @@ Foam::autoPtr<Foam::motionSolver> Foam::motionSolver::iNew::operator()
(
IOobject
(
dict.name() + ":meshSolver",
dictEntry.name() + ":meshSolver",
mesh_.time().constant(),
mesh_
),
dict
dictEntry
)
);
}
......
......@@ -40,15 +40,13 @@ SourceFiles
#include "Time.H"
#include "polyMesh.H"
#include "dictionaryEntry.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward class declarations
class polyMesh;
// Forward declarations
class mapPolyMesh;
/*---------------------------------------------------------------------------*\
......
......@@ -62,19 +62,20 @@ Foam::Istream& Foam::functionObjects::operator>>
{
is.check(FUNCTION_NAME);
const dictionaryEntry entry(dictionary::null, is);
const dictionaryEntry dictEntry(dictionary::null, is);
const dictionary& dict = dictEntry.dict();
faItem.active_ = false;
faItem.fieldName_ = entry.keyword();
faItem.mean_ = entry.get<bool>("mean");
faItem.prime2Mean_ = entry.get<bool>("prime2Mean");
faItem.base_ = faItem.baseTypeNames_.lookup("base", entry);
faItem.window_ = entry.lookupOrDefault<scalar>("window", -1.0);
faItem.fieldName_ = dictEntry.keyword();
faItem.mean_ = dict.get<bool>("mean");
faItem.prime2Mean_ = dict.get<bool>("prime2Mean");
faItem.base_ = faItem.baseTypeNames_.lookup("base", dict);
faItem.window_ = dict.lookupOrDefault<scalar>("window", -1.0);
if (faItem.window_ > 0)
{
faItem.windowType_ =
faItem.windowTypeNames_.lookup("windowType", entry);
faItem.windowTypeNames_.lookup("windowType", dict);
if (faItem.windowType_ != fieldAverageItem::windowType::NONE)
{
......@@ -84,17 +85,17 @@ Foam::Istream& Foam::functionObjects::operator>>
&& label(faItem.window_) < 1
)
{
FatalIOErrorInFunction(entry)
FatalIOErrorInFunction(dictEntry)
<< "Window must be 1 or more for base type "
<< faItem.baseTypeNames_[fieldAverageItem::baseType::ITER]
<< exit(FatalIOError);
}
faItem.windowName_ = entry.lookupOrDefault<word>("windowName", "");
faItem.windowName_ = dict.lookupOrDefault<word>("windowName", "");
if (faItem.windowType_ == fieldAverageItem::windowType::EXACT)
{
faItem.allowRestart_ = entry.get<bool>("allowRestart");
faItem.allowRestart_ = dict.get<bool>("allowRestart");
if (!faItem.allowRestart_)
{
......
......@@ -124,18 +124,18 @@ void Foam::phaseProperties::setCarrierIds
void Foam::phaseProperties::checkTotalMassFraction() const
{
scalar total = 0.0;
forAll(Y_, speciei)
scalar total = 0;
for (const scalar& val : Y_)
{
total += Y_[speciei];
total += val;
}
if (Y_.size() != 0 && mag(total - 1.0) > SMALL)
if (Y_.size() && mag(total - 1.0) > SMALL)
{
FatalErrorInFunction
<< "Specie fractions must total to unity for phase "
<< phaseTypeNames[phase_] << nl
<< "Species: " << nl << names_ << nl
<< "Species: " << nl << flatOutput(names_) << nl
<< exit(FatalError);
}
}
......@@ -143,22 +143,21 @@ void Foam::phaseProperties::checkTotalMassFraction() const
Foam::word Foam::phaseProperties::phaseToStateLabel(const phaseType pt) const
{
word state = "(unknown)";
switch (pt)
{
case GAS:
{
state = "(g)";
return "(g)";
break;
}
case LIQUID:
{
state = "(l)";
return "(l)";
break;
}
case SOLID:
{
state = "(s)";
return "(s)";
break;
}
default:
......@@ -167,10 +166,11 @@ Foam::word Foam::phaseProperties::phaseToStateLabel(const phaseType pt) const
<< "Invalid phase: " << phaseTypeNames[pt] << nl
<< " phase must be gas, liquid or solid" << nl
<< exit(FatalError);
break;
}
}
return state;
return "(unknown)";
}
......@@ -180,9 +180,9 @@ Foam::phaseProperties::phaseProperties()
:
phase_(UNKNOWN),
stateLabel_("(unknown)"),
names_(0),
Y_(0),
carrierIds_(0)
names_(),
Y_(),
carrierIds_()
{}
......@@ -196,12 +196,6 @@ Foam::phaseProperties::phaseProperties(const phaseProperties& pp)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::phaseProperties::~phaseProperties()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::phaseProperties::reorder
......@@ -246,6 +240,7 @@ void Foam::phaseProperties::reorder
<< "Invalid phase: " << phaseTypeNames[phase_] << nl
<< " phase must be gas, liquid or solid" << nl
<< exit(FatalError);
break;
}
}
}
......@@ -317,15 +312,7 @@ const Foam::labelList& Foam::phaseProperties::carrierIds() const
Foam::label Foam::phaseProperties::id(const word& specieName) const
{
forAll(names_, speciei)
{
if (names_[speciei] == specieName)
{
return speciei;
}
}
return -1;
return names_.find(specieName);
}
......
......@@ -120,14 +120,14 @@ public:
phaseProperties();
//- Construct from Istream
phaseProperties(Istream&);
phaseProperties(Istream& is);
//- Construct as copy
phaseProperties(const phaseProperties&);
phaseProperties(const phaseProperties& pp);
//- Destructor
~phaseProperties();
~phaseProperties() = default;
// Public Member Functions
......
......@@ -32,34 +32,11 @@ Foam::phaseProperties::phaseProperties(Istream& is)
:
phase_(UNKNOWN),
stateLabel_("(unknown)"),
names_(0),
Y_(0),
carrierIds_(0)
names_(),
Y_(),
carrierIds_()
{
is.check(FUNCTION_NAME);
dictionaryEntry phaseInfo(dictionary::null, is);
phase_ = phaseTypeNames[phaseInfo.keyword()];
stateLabel_ = phaseToStateLabel(phase_);
const label nComponents = phaseInfo.size();
if (nComponents)
{
names_.setSize(nComponents, "unknownSpecie");
Y_.setSize(nComponents, 0.0);
carrierIds_.setSize(nComponents, -1);
label cmptI = 0;
forAllConstIter(IDLList<entry>, phaseInfo, iter)
{
names_[cmptI] = iter().keyword();
Y_[cmptI] = readScalar(phaseInfo.lookup(names_[cmptI]));
cmptI++;
}
checkTotalMassFraction();
}
is >> *this;
}
......@@ -69,28 +46,25 @@ Foam::Istream& Foam::operator>>(Istream& is, phaseProperties& pp)
{
is.check(FUNCTION_NAME);
dictionaryEntry phaseInfo(dictionary::null, is);
const dictionaryEntry phaseInfo(dictionary::null, is);
const dictionary& dict = phaseInfo.dict();
pp.phase_ = pp.phaseTypeNames[phaseInfo.keyword()];
pp.stateLabel_ = pp.phaseToStateLabel(pp.phase_);
const label nComponents = phaseInfo.size();
if (nComponents)
// The names in the dictionary order of appearance
pp.names_ = dict.toc();
const label nComponents = pp.names_.size();
pp.Y_.resize(nComponents, 0.0);
pp.carrierIds_.resize(nComponents, -1);
for (label cmpti = 0; cmpti < nComponents; ++cmpti)
{
pp.names_.setSize(nComponents, "unknownSpecie");
pp.Y_.setSize(nComponents, 0.0);
pp.carrierIds_.setSize(nComponents, -1);
label cmptI = 0;
forAllConstIter(IDLList<entry>, phaseInfo, iter)
{
pp.names_[cmptI] = iter().keyword();
pp.Y_[cmptI] = readScalar(phaseInfo.lookup(pp.names_[cmptI]));
cmptI++;
}
pp.checkTotalMassFraction();
pp.Y_[cmpti] = dict.get<scalar>(pp.names_[cmpti]);
}
pp.checkTotalMassFraction();
return is;
}
......@@ -102,9 +76,9 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const phaseProperties& pp)
os.beginBlock(pp.phaseTypeNames[pp.phase_]);
forAll(pp.names_, cmptI)
forAll(pp.names_, cmpti)
{
os.writeEntry(pp.names_[cmptI], pp.Y_[cmptI]);
os.writeEntry(pp.names_[cmpti], pp.Y_[cmpti]);
}
os.endBlock();
......
......@@ -74,12 +74,14 @@ Foam::Istream& Foam::operator>>
{
is.check(FUNCTION_NAME);
const dictionaryEntry entry(dictionary::null, is);
const dictionaryEntry dictEntry(dictionary::null, is);
const dictionary& dict = dictEntry.dict();
pid.patchName_ = entry.keyword();
entry.readEntry("type", pid.interactionTypeName_);
pid.e_ = entry.lookupOrDefault<scalar>("e", 1.0);
pid.mu_ = entry.lookupOrDefault<scalar>("mu", 0.0);
pid.patchName_ = dictEntry.keyword();
dict.readEntry("type", pid.interactionTypeName_);
pid.e_ = dict.lookupOrDefault<scalar>("e", 1.0);
pid.mu_ = dict.lookupOrDefault<scalar>("mu", 0.0);
return is;
}
......
Supports Markdown
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