From 0fddd6a12900befd6bf1be2fb1315cca79d94471 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 18 Jul 2013 19:07:14 +0000 Subject: [PATCH] [Thermo] Fix errors in setState_SPorSV This corrects the behavior in cases where the correct temperature is below the nominal minimum temperature for the phase. Add test cases for this and analogous cases for the maximum temperature and setState_HPorUV. Fixes Issue 151. --- interfaces/cython/cantera/test/test_thermo.py | 63 +++++++++++++++++++ src/thermo/ThermoPhase.cpp | 4 +- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/interfaces/cython/cantera/test/test_thermo.py b/interfaces/cython/cantera/test/test_thermo.py index 64df0e03f..8f1a92e59 100644 --- a/interfaces/cython/cantera/test/test_thermo.py +++ b/interfaces/cython/cantera/test/test_thermo.py @@ -290,6 +290,69 @@ class TestThermoPhase(utilities.CanteraTest): self.assertEqual(self.phase.max_temp, 3500.0) +class TestThermo(utilities.CanteraTest): + def setUp(self): + self.gas = ct.ThermoPhase('h2o2.xml') + + def test_setSV_lowT(self): + """ + Set state in terms of (s,v) when the end temperature is below the + phase's nominal temperature limit. + """ + + self.gas.TPX = 450, 1e5, 'H2:1.0, O2:0.4, AR:3' + s1, v1 = self.gas.SV + self.gas.SV = s1, 3 * v1 + + self.assertNear(self.gas.s, s1) + self.assertNear(self.gas.v, 3 * v1) + self.assertTrue(self.gas.T < self.gas.min_temp) + + def test_setSV_highT(self): + """ + Set state in terms of (s,v) when the end temperature is above the + phase's nominal temperature limit. + """ + + self.gas.TPX = 2900, 1e5, 'H2:1.0, O2:0.4, AR:3' + s1, v1 = self.gas.SV + self.gas.SV = s1, 0.3 * v1 + + self.assertNear(self.gas.s, s1) + self.assertNear(self.gas.v, 0.3 * v1) + self.assertTrue(self.gas.T > self.gas.max_temp) + + def test_setHP_lowT(self): + """ + Set state in terms of (s,v) when the end temperature is below the + phase's nominal temperature limit. + """ + + self.gas.TPX = 450, 1e5, 'H2:1.0, O2:0.4, AR:3' + deltaH = 1.25e5 + h1, p1 = self.gas.HP + self.gas.HP = h1 - deltaH, None + + self.assertNear(self.gas.h, h1 - deltaH) + self.assertNear(self.gas.P, p1) + self.assertTrue(self.gas.T < self.gas.min_temp) + + def test_setHP_highT(self): + """ + Set state in terms of (s,v) when the end temperature is above the + phase's nominal temperature limit. + """ + + self.gas.TPX = 2800, 1e5, 'H2:1.0, O2:0.4, AR:3' + deltaH = 8.25e5 + h1, p1 = self.gas.HP + self.gas.HP = h1 + deltaH, None + + self.assertNear(self.gas.h, h1 + deltaH) + self.assertNear(self.gas.P, p1) + self.assertTrue(self.gas.T > self.gas.max_temp) + + class TestInterfacePhase(utilities.CanteraTest): def setUp(self): self.gas = ct.Solution('diamond.xml', 'gas') diff --git a/src/thermo/ThermoPhase.cpp b/src/thermo/ThermoPhase.cpp index 408a6aff0..d80bf4d31 100644 --- a/src/thermo/ThermoPhase.cpp +++ b/src/thermo/ThermoPhase.cpp @@ -516,10 +516,10 @@ void ThermoPhase::setState_SPorSV(doublereal Starget, doublereal p, } } else if (Tnew < Tmin && !ignoreBounds) { setState_conditional_TP(Tmin, p, !doSV); - double Smin = enthalpy_mass(); + double Smin = entropy_mass(); if (Smin <= Starget) { if (Sbot > Starget) { - Sbot = Tmin; + Tbot = Tmin; Sbot = Smin; } } else {