[Thermo] Keep PureFluidPhase state data consistent
Previously, calls to setTemperature, setDensity, and setState_TR did not result in the underlying Substance object being updated. In addition, the isothermalCompressibility and thermalExpansionCoeff methods did not synchronize the state. Now, setting the state of the PureFluidPhase object always sets the state of the Substance object, and no synchronization is required in property calculation functions.
This commit is contained in:
parent
b5b542d10b
commit
fb68cae145
3 changed files with 24 additions and 23 deletions
|
|
@ -68,6 +68,8 @@ public:
|
|||
* @param p Pressure (Pa)
|
||||
*/
|
||||
virtual void setPressure(doublereal p);
|
||||
virtual void setTemperature(double T);
|
||||
virtual void setDensity(double rho);
|
||||
|
||||
virtual void getChemPotentials(doublereal* mu) const {
|
||||
mu[0] = gibbs_mole();
|
||||
|
|
@ -178,9 +180,6 @@ protected:
|
|||
*/
|
||||
void Set(tpx::PropertyPair::type n, double x, double y) const;
|
||||
|
||||
//! Sets the state using a TPX::TV call
|
||||
void setTPXState() const;
|
||||
|
||||
private:
|
||||
//! Pointer to the underlying tpx object Substance that does the work
|
||||
mutable std::unique_ptr<tpx::Substance> m_sub;
|
||||
|
|
|
|||
|
|
@ -138,6 +138,11 @@ class TestPureFluid(utilities.CanteraTest):
|
|||
self.assertNear(ref.thermal_expansion_coeff,
|
||||
self.water.thermal_expansion_coeff, 1e-5)
|
||||
|
||||
def test_thermal_expansion_coeff_TD(self):
|
||||
for T in [440, 550, 660]:
|
||||
self.water.TD = T, 0.1
|
||||
self.assertNear(T * self.water.thermal_expansion_coeff, 1.0, 1e-2)
|
||||
|
||||
def test_fd_properties_twophase(self):
|
||||
self.water.TX = 400, 0.1
|
||||
self.assertEqual(self.water.cp, np.inf)
|
||||
|
|
|
|||
|
|
@ -85,50 +85,55 @@ double PureFluidPhase::maxTemp(size_t k) const
|
|||
|
||||
doublereal PureFluidPhase::enthalpy_mole() const
|
||||
{
|
||||
setTPXState();
|
||||
return m_sub->h() * m_mw;
|
||||
}
|
||||
|
||||
doublereal PureFluidPhase::intEnergy_mole() const
|
||||
{
|
||||
setTPXState();
|
||||
return m_sub->u() * m_mw;
|
||||
}
|
||||
|
||||
doublereal PureFluidPhase::entropy_mole() const
|
||||
{
|
||||
setTPXState();
|
||||
return m_sub->s() * m_mw;
|
||||
}
|
||||
|
||||
doublereal PureFluidPhase::gibbs_mole() const
|
||||
{
|
||||
setTPXState();
|
||||
return m_sub->g() * m_mw;
|
||||
}
|
||||
|
||||
doublereal PureFluidPhase::cp_mole() const
|
||||
{
|
||||
setTPXState();
|
||||
return m_sub->cp() * m_mw;
|
||||
}
|
||||
|
||||
doublereal PureFluidPhase::cv_mole() const
|
||||
{
|
||||
setTPXState();
|
||||
return m_sub->cv() * m_mw;
|
||||
}
|
||||
|
||||
doublereal PureFluidPhase::pressure() const
|
||||
{
|
||||
setTPXState();
|
||||
return m_sub->P();
|
||||
}
|
||||
|
||||
void PureFluidPhase::setPressure(doublereal p)
|
||||
{
|
||||
Set(tpx::PropertyPair::TP, temperature(), p);
|
||||
setDensity(1.0/m_sub->v());
|
||||
ThermoPhase::setDensity(1.0/m_sub->v());
|
||||
}
|
||||
|
||||
void PureFluidPhase::setTemperature(double T)
|
||||
{
|
||||
ThermoPhase::setTemperature(T);
|
||||
Set(tpx::PropertyPair::TV, T, m_sub->v());
|
||||
}
|
||||
|
||||
void PureFluidPhase::setDensity(double rho)
|
||||
{
|
||||
ThermoPhase::setDensity(rho);
|
||||
Set(tpx::PropertyPair::TV, m_sub->Temp(), 1.0/rho);
|
||||
}
|
||||
|
||||
void PureFluidPhase::Set(tpx::PropertyPair::type n, double x, double y) const
|
||||
|
|
@ -136,11 +141,6 @@ void PureFluidPhase::Set(tpx::PropertyPair::type n, double x, double y) const
|
|||
m_sub->Set(n, x, y);
|
||||
}
|
||||
|
||||
void PureFluidPhase::setTPXState() const
|
||||
{
|
||||
Set(tpx::PropertyPair::TV, temperature(), 1.0/density());
|
||||
}
|
||||
|
||||
doublereal PureFluidPhase::isothermalCompressibility() const
|
||||
{
|
||||
return m_sub->isothermalCompressibility();
|
||||
|
|
@ -356,24 +356,21 @@ doublereal PureFluidPhase::satPressure(doublereal t)
|
|||
|
||||
doublereal PureFluidPhase::vaporFraction() const
|
||||
{
|
||||
setTPXState();
|
||||
return m_sub->x();
|
||||
}
|
||||
|
||||
void PureFluidPhase::setState_Tsat(doublereal t, doublereal x)
|
||||
{
|
||||
setTemperature(t);
|
||||
setTPXState();
|
||||
Set(tpx::PropertyPair::TX, t, x);
|
||||
setDensity(1.0/m_sub->v());
|
||||
ThermoPhase::setTemperature(t);
|
||||
ThermoPhase::setDensity(1.0/m_sub->v());
|
||||
}
|
||||
|
||||
void PureFluidPhase::setState_Psat(doublereal p, doublereal x)
|
||||
{
|
||||
setTPXState();
|
||||
Set(tpx::PropertyPair::PX, p, x);
|
||||
setTemperature(m_sub->Temp());
|
||||
setDensity(1.0/m_sub->v());
|
||||
ThermoPhase::setTemperature(m_sub->Temp());
|
||||
ThermoPhase::setDensity(1.0/m_sub->v());
|
||||
}
|
||||
|
||||
std::string PureFluidPhase::report(bool show_thermo, doublereal threshold) const
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue