[Thermo] Prevent setting thermodynamic state variables to NaN
Throwing an exception when a state variable is being set to NaN transforms some reactor network integration errors from unrecoverable errors into recoverable errors.
This commit is contained in:
parent
2b7bcf2b3e
commit
bb2d1c0993
2 changed files with 19 additions and 5 deletions
|
|
@ -611,10 +611,12 @@ 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.0) {
|
||||
throw CanteraError("Phase::setDensity()", "density must be positive");
|
||||
if (density_ > 0.0) {
|
||||
m_dens = density_;
|
||||
} else {
|
||||
throw CanteraError("Phase::setDensity()",
|
||||
"density must be positive");
|
||||
}
|
||||
m_dens = density_;
|
||||
}
|
||||
|
||||
//! Set the internally stored molar density (kmol/m^3) of the phase.
|
||||
|
|
@ -624,11 +626,12 @@ public:
|
|||
//! Set the internally stored temperature of the phase (K).
|
||||
//! @param temp Temperature in Kelvin
|
||||
virtual void setTemperature(const doublereal temp) {
|
||||
if (temp <= 0) {
|
||||
if (temp > 0) {
|
||||
m_temp = temp;
|
||||
} else {
|
||||
throw CanteraError("Phase::setTemperature",
|
||||
"temperature must be positive");
|
||||
}
|
||||
m_temp = temp;
|
||||
}
|
||||
//@}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,4 +91,15 @@ TEST_F(TestThermoMethods, getMassFractionsByName)
|
|||
EXPECT_EQ(Y.size(), (size_t) 3);
|
||||
}
|
||||
|
||||
TEST_F(TestThermoMethods, setState_nan)
|
||||
{
|
||||
double nan = std::numeric_limits<double>::quiet_NaN();
|
||||
thermo->setState_TP(500, 12345);
|
||||
EXPECT_THROW(thermo->setState_TP(nan, 55555), CanteraError);
|
||||
EXPECT_THROW(thermo->setState_TP(555, nan), CanteraError);
|
||||
EXPECT_THROW(thermo->setState_HP(nan, 55555), CanteraError);
|
||||
EXPECT_THROW(thermo->setState_SV(1234, nan), CanteraError);
|
||||
EXPECT_THROW(thermo->setState_TR(555, nan), CanteraError);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue