STYLE: simplify read/write coding for some thermophysicalModels

This commit is contained in:
Mark Olesen
2018-10-18 12:57:32 +02:00
parent 3b74512231
commit 3c5fffcd1c
24 changed files with 171 additions and 172 deletions

View File

@ -49,9 +49,12 @@ void Foam::constAnIsoSolidTransport<Thermo>::constAnIsoSolidTransport::write
{ {
Thermo::write(os); Thermo::write(os);
dictionary dict("transport"); // Entries in dictionary format
dict.add("kappa", kappa_); {
os << indent << dict.dictName() << dict; os.beginBlock("transport");
os.writeEntry("kappa", kappa_);
os.endBlock();
}
} }

View File

@ -49,9 +49,12 @@ void Foam::constIsoSolidTransport<Thermo>::constIsoSolidTransport::write
{ {
Thermo::write(os); Thermo::write(os);
dictionary dict("transport"); // Entries in dictionary format
dict.add("kappa", kappa_); {
os << indent << dict.dictName() << dict; os.beginBlock("transport");
os.writeEntry("kappa", kappa_);
os.endBlock();
}
} }

View File

@ -35,15 +35,10 @@ Foam::exponentialSolidTransport<Thermo>::exponentialSolidTransport
) )
: :
Thermo(dict), Thermo(dict),
kappa0_(0.0), kappa0_(dict.subDict("transport").get<scalar>("kappa0")),
n0_(0.0), n0_(dict.subDict("transport").get<scalar>("n0")),
Tref_(0.0) Tref_(dict.subDict("transport").get<scalar>("Tref"))
{ {}
const dictionary& subDict = dict.subDict("transport");
subDict.readEntry("kappa0", kappa0_);
subDict.readEntry("n0", n0_);
subDict.readEntry("Tref", Tref_);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -56,11 +51,14 @@ void Foam::exponentialSolidTransport<Thermo>::exponentialSolidTransport::write
{ {
Thermo::write(os); Thermo::write(os);
dictionary dict("transport"); // Entries in dictionary format
dict.add("kappa0", kappa0_); {
dict.add("n0", n0_); os.beginBlock("transport");
dict.add("Tref", Tref_); os.writeEntry("kappa0", kappa0_);
os << indent << dict.dictName() << dict; os.writeEntry("n0", n0_);
os.writeEntry("Tref", Tref_);
os.endBlock();
}
} }

View File

@ -35,15 +35,8 @@ Foam::polynomialSolidTransport<Thermo, PolySize>::polynomialSolidTransport
) )
: :
Thermo(dict), Thermo(dict),
kappaCoeffs_ kappaCoeffs_(dict.subDict("transport").lookup(coeffsName("kappa")))
( {}
dict.subDict("transport").lookup
(
"kappaCoeffs<" + Foam::name(PolySize) + '>'
)
)
{
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -53,14 +46,12 @@ void Foam::polynomialSolidTransport<Thermo, PolySize>::write(Ostream& os) const
{ {
Thermo::write(os); Thermo::write(os);
dictionary dict("transport"); // Entries in dictionary format
{
dict.add os.beginBlock("transport");
( os.writeEntry(coeffsName("kappa"), kappaCoeffs_);
word("kappaCoeffs<" + Foam::name(PolySize) + '>'), os.endBlock();
kappaCoeffs_ }
);
os << indent << dict.dictName() << dict;
} }

View File

@ -115,6 +115,12 @@ class polynomialSolidTransport
// Private Member Functions // Private Member Functions
//- Coeffs name. Eg, "kappaCoeffs<10>"
inline static word coeffsName(const char* name)
{
return word(name + ("Coeffs<" + std::to_string(PolySize) + '>'));
}
//- Construct from components //- Construct from components
inline polynomialSolidTransport inline polynomialSolidTransport
( (

View File

@ -47,12 +47,15 @@ template<class Specie>
void Foam::Boussinesq<Specie>::write(Ostream& os) const void Foam::Boussinesq<Specie>::write(Ostream& os) const
{ {
Specie::write(os); Specie::write(os);
dictionary dict("equationOfState");
dict.add("rho0", rho0_);
dict.add("T0", T0_);
dict.add("beta", beta_);
os << indent << dict.dictName() << dict; // Entries in dictionary format
{
os.beginBlock("equationOfState");
os.writeEntry("rho0", rho0_);
os.writeEntry("T0", T0_);
os.writeEntry("beta", beta_);
os.endBlock();
}
} }

View File

@ -49,13 +49,15 @@ void Foam::adiabaticPerfectFluid<Specie>::write(Ostream& os) const
{ {
Specie::write(os); Specie::write(os);
dictionary dict("equationOfState"); // Entries in dictionary format
dict.add("p0", p0_); {
dict.add("rho0", rho0_); os.beginBlock("equationOfState");
dict.add("gamma", gamma_); os.writeEntry("p0", p0_);
dict.add("B", B_); os.writeEntry("rho0", rho0_);
os.writeEntry("gamma", gamma_);
os << indent << dict.dictName() << dict; os.writeEntry("B", B_);
os.endBlock();
}
} }

View File

@ -37,13 +37,7 @@ template<class Specie, int PolySize>
icoPolynomial<Specie, PolySize>::icoPolynomial(const dictionary& dict) icoPolynomial<Specie, PolySize>::icoPolynomial(const dictionary& dict)
: :
Specie(dict), Specie(dict),
rhoCoeffs_ rhoCoeffs_(dict.subDict("equationOfState").lookup(coeffsName("rho")))
(
dict.subDict("equationOfState").lookup
(
"rhoCoeffs<" + Foam::name(PolySize) + '>'
)
)
{} {}
@ -54,14 +48,12 @@ void icoPolynomial<Specie, PolySize>::write(Ostream& os) const
{ {
Specie::write(os); Specie::write(os);
dictionary dict("equationOfState"); // Entries in dictionary format
dict.add {
( os.beginBlock("equationOfState");
word("rhoCoeffs<" + Foam::name(PolySize) + '>'), os.writeEntry(coeffsName("rho"), rhoCoeffs_);
rhoCoeffs_ os.endBlock();
); }
os << indent << dict.dictName() << dict;
} }

View File

@ -123,6 +123,15 @@ class icoPolynomial
Polynomial<PolySize> rhoCoeffs_; Polynomial<PolySize> rhoCoeffs_;
// Private Member Functions
//- Coeffs name. Eg, "rhoCoeffs<10>"
inline static word coeffsName(const char* name)
{
return word(name + ("Coeffs<" + std::to_string(PolySize) + '>'));
}
public: public:
// Constructors // Constructors

View File

@ -45,10 +45,13 @@ template<class Specie>
void Foam::incompressiblePerfectGas<Specie>::write(Ostream& os) const void Foam::incompressiblePerfectGas<Specie>::write(Ostream& os) const
{ {
Specie::write(os); Specie::write(os);
dictionary dict("equationOfState");
dict.add("pRef", pRef_);
os << indent << dict.dictName() << dict; // Entries in dictionary format
{
os.beginBlock("equationOfState");
os.writeEntry("pRef", pRef_);
os.endBlock();
}
} }

View File

@ -44,11 +44,13 @@ void Foam::linear<Specie>::write(Ostream& os) const
{ {
Specie::write(os); Specie::write(os);
dictionary dict("equationOfState"); // Entries in dictionary format
dict.add("psi", psi_); {
dict.add("rho0", rho0_); os.beginBlock("equationOfState");
os.writeEntry("psi", psi_);
os << indent << dict.dictName() << dict; os.writeEntry("rho0", rho0_);
os.endBlock();
}
} }

View File

@ -44,11 +44,13 @@ void Foam::perfectFluid<Specie>::write(Ostream& os) const
{ {
Specie::write(os); Specie::write(os);
dictionary dict("equationOfState"); // Entries in dictionary format
dict.add("R", R_); {
dict.add("rho0", rho0_); os.beginBlock("equationOfState");
os.writeEntry("R", R_);
os << indent << dict.dictName() << dict; os.writeEntry("rho0", rho0_);
os.endBlock();
}
} }

View File

@ -43,10 +43,12 @@ void Foam::rhoConst<Specie>::write(Ostream& os) const
{ {
Specie::write(os); Specie::write(os);
dictionary dict("equationOfState"); // Entries in dictionary format
dict.add("rho", rho_); {
os.beginBlock("equationOfState");
os << indent << dict.dictName() << dict; os.writeEntry("rho", rho_);
os.endBlock();
}
} }

View File

@ -39,7 +39,7 @@ namespace Foam
Foam::specie::specie(const dictionary& dict) Foam::specie::specie(const dictionary& dict)
: :
name_(dict.dictName()), name_(dict.dictName()),
Y_(dict.subDict("specie").lookupOrDefault("massFraction", 1.0)), Y_(dict.subDict("specie").lookupOrDefault<scalar>("massFraction", 1)),
molWeight_(dict.subDict("specie").get<scalar>("molWeight")) molWeight_(dict.subDict("specie").get<scalar>("molWeight"))
{} {}
@ -48,13 +48,13 @@ Foam::specie::specie(const dictionary& dict)
void Foam::specie::write(Ostream& os) const void Foam::specie::write(Ostream& os) const
{ {
dictionary dict("specie"); // Entries in dictionary format
if (Y_ != 1)
{ {
dict.add("massFraction", Y_); os.beginBlock("specie");
os.writeEntryIfDifferent<scalar>("massFraction", 1, Y_);
os.writeEntry("molWeight", molWeight_);
os.endBlock();
} }
dict.add("molWeight", molWeight_);
os << indent << dict.dictName() << dict;
} }

View File

@ -44,10 +44,13 @@ void Foam::eConstThermo<EquationOfState>::write(Ostream& os) const
{ {
EquationOfState::write(os); EquationOfState::write(os);
dictionary dict("thermodynamics"); // Entries in dictionary format
dict.add("Cv", Cv_); {
dict.add("Hf", Hf_); os.beginBlock("thermodynamics");
os << indent << dict.dictName() << dict; os.writeEntry("Cv", Cv_);
os.writeEntry("Hf", Hf_);
os.endBlock();
}
} }

View File

@ -44,10 +44,13 @@ void Foam::hConstThermo<EquationOfState>::write(Ostream& os) const
{ {
EquationOfState::write(os); EquationOfState::write(os);
dictionary dict("thermodynamics"); // Entries in dictionary format
dict.add("Cp", Cp_); {
dict.add("Hf", Hf_); os.beginBlock("thermodynamics");
os << indent << dict.dictName() << dict; os.writeEntry("Cp", Cp_);
os.writeEntry("Hf", Hf_);
os.endBlock();
}
} }

View File

@ -37,13 +37,7 @@ Foam::hPolynomialThermo<EquationOfState, PolySize>::hPolynomialThermo
EquationOfState(dict), EquationOfState(dict),
Hf_(dict.subDict("thermodynamics").get<scalar>("Hf")), Hf_(dict.subDict("thermodynamics").get<scalar>("Hf")),
Sf_(dict.subDict("thermodynamics").get<scalar>("Sf")), Sf_(dict.subDict("thermodynamics").get<scalar>("Sf")),
CpCoeffs_ CpCoeffs_(dict.subDict("thermodynamics").lookup(coeffsName("Cp"))),
(
dict.subDict("thermodynamics").lookup
(
"CpCoeffs<" + Foam::name(PolySize) + '>'
)
),
hCoeffs_(), hCoeffs_(),
sCoeffs_() sCoeffs_()
{ {
@ -68,15 +62,14 @@ void Foam::hPolynomialThermo<EquationOfState, PolySize>::write
{ {
EquationOfState::write(os); EquationOfState::write(os);
dictionary dict("thermodynamics"); // Entries in dictionary format
dict.add("Hf", Hf_); {
dict.add("Sf", Sf_); os.beginBlock("thermodynamics");
dict.add os.writeEntry("Hf", Hf_);
( os.writeEntry("Sf", Sf_);
word("CpCoeffs<" + Foam::name(PolySize) + '>'), os.writeEntry(coeffsName("Cp"), CpCoeffs_);
CpCoeffs_ os.endBlock();
); }
os << indent << dict.dictName() << dict;
} }

View File

@ -148,6 +148,12 @@ class hPolynomialThermo
// Private Member Functions // Private Member Functions
//- Coeffs name. Eg, "CpCoeffs<10>"
inline static word coeffsName(const char* name)
{
return word(name + ("Coeffs<" + std::to_string(PolySize) + '>'));
}
//- Construct from components //- Construct from components
inline hPolynomialThermo inline hPolynomialThermo
( (

View File

@ -46,12 +46,15 @@ void Foam::hRefConstThermo<EquationOfState>::write(Ostream& os) const
{ {
EquationOfState::write(os); EquationOfState::write(os);
dictionary dict("thermodynamics"); // Entries in dictionary format
dict.add("Cp", Cp_); {
dict.add("Hf", Hf_); os.beginBlock("thermodynamics");
dict.add("Tref", Tref_); os.writeEntry("Cp", Cp_);
dict.add("Href", Href_); os.writeEntry("Hf", Hf_);
os << indent << dict.dictName() << dict; os.writeEntry("Tref", Tref_);
os.writeEntry("Href", Href_);
os.endBlock();
}
} }

View File

@ -93,13 +93,16 @@ void Foam::janafThermo<EquationOfState>::write(Ostream& os) const
lowCpCoeffs[coefLabel] = lowCpCoeffs_[coefLabel]/this->R(); lowCpCoeffs[coefLabel] = lowCpCoeffs_[coefLabel]/this->R();
} }
dictionary dict("thermodynamics"); // Entries in dictionary format
dict.add("Tlow", Tlow_); {
dict.add("Thigh", Thigh_); os.beginBlock("thermodynamics");
dict.add("Tcommon", Tcommon_); os.writeEntry("Tlow", Tlow_);
dict.add("highCpCoeffs", highCpCoeffs); os.writeEntry("Thigh", Thigh_);
dict.add("lowCpCoeffs", lowCpCoeffs); os.writeEntry("Tcommon", Tcommon_);
os << indent << dict.dictName() << dict; os.writeEntry("highCpCoeffs", highCpCoeffs);
os.writeEntry("lowCpCoeffs", lowCpCoeffs);
os.endBlock();
}
} }

View File

@ -35,20 +35,8 @@ Foam::logPolynomialTransport<Thermo, PolySize>::logPolynomialTransport
) )
: :
Thermo(dict), Thermo(dict),
muCoeffs_ muCoeffs_(dict.subDict("transport").lookup(coeffsName("mu"))),
( kappaCoeffs_(dict.subDict("transport").lookup(coeffsName("kappa")))
dict.subDict("transport").lookup
(
"muLogCoeffs<" + Foam::name(PolySize) + '>'
)
),
kappaCoeffs_
(
dict.subDict("transport").lookup
(
"kappaLogCoeffs<" + Foam::name(PolySize) + '>'
)
)
{} {}
@ -64,16 +52,8 @@ void Foam::logPolynomialTransport<Thermo, PolySize>::write(Ostream& os) const
// Entries in dictionary format // Entries in dictionary format
{ {
os.beginBlock("transport"); os.beginBlock("transport");
os.writeEntry os.writeEntry(coeffsName("mu"), muCoeffs_);
( os.writeEntry(coeffsName("kappa"), kappaCoeffs_);
word("muLogCoeffs<" + Foam::name(PolySize) + '>'),
muCoeffs_
);
os.writeEntry
(
word("kappaLogCoeffs<" + Foam::name(PolySize) + '>'),
kappaCoeffs_
);
os.endBlock(); os.endBlock();
} }

View File

@ -139,6 +139,12 @@ class logPolynomialTransport
// Private Member Functions // Private Member Functions
//- Coeffs name. Eg, "muLogCoeffs<10>"
inline static word coeffsName(const char* name)
{
return word(name + ("LogCoeffs<" + std::to_string(PolySize) + '>'));
}
//- Construct from components //- Construct from components
inline logPolynomialTransport inline logPolynomialTransport
( (

View File

@ -35,20 +35,8 @@ Foam::polynomialTransport<Thermo, PolySize>::polynomialTransport
) )
: :
Thermo(dict), Thermo(dict),
muCoeffs_ muCoeffs_(dict.subDict("transport").lookup(coeffsName("mu"))),
( kappaCoeffs_(dict.subDict("transport").lookup(coeffsName("kappa")))
dict.subDict("transport").lookup
(
"muCoeffs<" + Foam::name(PolySize) + '>'
)
),
kappaCoeffs_
(
dict.subDict("transport").lookup
(
"kappaCoeffs<" + Foam::name(PolySize) + '>'
)
)
{} {}
@ -64,16 +52,8 @@ void Foam::polynomialTransport<Thermo, PolySize>::write(Ostream& os) const
// Entries in dictionary format // Entries in dictionary format
{ {
os.beginBlock("transport"); os.beginBlock("transport");
os.writeEntry os.writeEntry(coeffsName("mu"), muCoeffs_);
( os.writeEntry(coeffsName("kappa"), kappaCoeffs_);
word("muCoeffs<" + Foam::name(PolySize) + '>'),
muCoeffs_
);
os.writeEntry
(
word("kappaCoeffs<" + Foam::name(PolySize) + '>'),
kappaCoeffs_
);
os.endBlock(); os.endBlock();
} }

View File

@ -128,6 +128,12 @@ class polynomialTransport
// Private Member Functions // Private Member Functions
//- Coeffs name. Eg, "muCoeffs<10>"
inline static word coeffsName(const char* name)
{
return word(name + ("Coeffs<" + std::to_string(PolySize) + '>'));
}
//- Construct from components //- Construct from components
inline polynomialTransport inline polynomialTransport
( (