From 1becffecb0343e0d887708d03c044c4b9fc9abd9 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sat, 11 Aug 2012 23:58:29 +0000 Subject: [PATCH] Disallow setting negative temperature or density --- include/cantera/thermo/Phase.h | 8 ++++++++ src/thermo/Phase.cpp | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/cantera/thermo/Phase.h b/include/cantera/thermo/Phase.h index 8f70912f2..ddf1fa8ba 100644 --- a/include/cantera/thermo/Phase.h +++ b/include/cantera/thermo/Phase.h @@ -543,6 +543,10 @@ public: //! Note the density of a phase is an independent variable. //! @param[in] density density (kg/m^3). virtual void setDensity(const doublereal density) { + if (density <= 0) { + throw CanteraError("Phase::setDensity", + "density must be positive"); + } m_dens = density; } @@ -553,6 +557,10 @@ public: //! Set the internally stored temperature of the phase (K). //! @param temp Temperature in Kelvin virtual void setTemperature(const doublereal temp) { + if (temp <= 0) { + throw CanteraError("Phase::setTemperature", + "temperature must be positive"); + } m_temp = temp; } //@} diff --git a/src/thermo/Phase.cpp b/src/thermo/Phase.cpp index 484bbdc15..1caa9ae1c 100644 --- a/src/thermo/Phase.cpp +++ b/src/thermo/Phase.cpp @@ -21,7 +21,7 @@ Phase::Phase() : m_xml(new XML_Node("phase")), m_id(""), m_name(""), - m_temp(0.0), + m_temp(0.001), m_dens(0.001), m_mmw(0.0), m_stateNum(-1), @@ -38,7 +38,7 @@ Phase::Phase(const Phase& right) : m_xml(0), m_id(""), m_name(""), - m_temp(0.0), + m_temp(0.001), m_dens(0.001), m_mmw(0.0), m_stateNum(-1),