[Thermo] Ensure that site density is always positive

A site density of zero causes divide-by-zero errors in SurfPhase and
EdgePhase. This change makes it possible to initialize SurfPhase and
EdgePhase objects without XML phase descriptions.
This commit is contained in:
Ray Speth 2015-04-27 22:39:25 -04:00
parent c994917bae
commit bc4c71f8ee
3 changed files with 6 additions and 22 deletions

View file

@ -33,7 +33,7 @@ public:
/*!
* @param n0 Surface site density (kmol m-1).
*/
EdgePhase(doublereal n0 = 0.0);
EdgePhase(doublereal n0=1.0);
//! Copy Constructor
/*!

View file

@ -148,7 +148,7 @@ public:
* @param n0 Site Density of the Surface Phase
* Units: kmol m-2.
*/
SurfPhase(doublereal n0 = 0.0);
SurfPhase(doublereal n0 = 1.0);
//! Construct and initialize a SurfPhase ThermoPhase object
//! directly from an ASCII input file

View file

@ -20,19 +20,13 @@ using namespace std;
namespace Cantera
{
SurfPhase::SurfPhase(doublereal n0):
m_n0(n0),
m_logn0(0.0),
m_press(OneAtm)
{
if (n0 > 0.0) {
m_logn0 = log(n0);
}
setSiteDensity(n0);
setNDim(2);
}
SurfPhase::SurfPhase(const std::string& infile, std::string id_) :
m_n0(0.0),
m_logn0(0.0),
m_press(OneAtm)
{
XML_Node* root = get_XML_File(infile);
@ -54,8 +48,6 @@ SurfPhase::SurfPhase(const std::string& infile, std::string id_) :
}
SurfPhase::SurfPhase(XML_Node& xmlphase) :
m_n0(0.0),
m_logn0(0.0),
m_press(OneAtm)
{
string model = xmlphase.child("thermo")["model"];
@ -284,7 +276,7 @@ void SurfPhase::setSiteDensity(doublereal n0)
{
if (n0 <= 0.0) {
throw CanteraError("SurfPhase::setSiteDensity",
"Bad value for parameter");
"Site density must be positive. Got " + fp2str(n0));
}
m_n0 = n0;
m_logn0 = log(m_n0);
@ -373,11 +365,7 @@ void SurfPhase::setParametersFromXML(const XML_Node& eosdata)
{
eosdata._require("model","Surface");
doublereal n = getFloat(eosdata, "site_density", "toSI");
if (n <= 0.0)
throw CanteraError("SurfPhase::setParametersFromXML",
"missing or negative site density");
m_n0 = n;
m_logn0 = log(m_n0);
setSiteDensity(n);
}
void SurfPhase::setStateFromXML(const XML_Node& state)
@ -424,11 +412,7 @@ void EdgePhase::setParametersFromXML(const XML_Node& eosdata)
{
eosdata._require("model","Edge");
doublereal n = getFloat(eosdata, "site_density", "toSI");
if (n <= 0.0)
throw CanteraError("EdgePhase::setParametersFromXML",
"missing or negative site density");
m_n0 = n;
m_logn0 = log(m_n0);
setSiteDensity(n);
}
}