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