General cleanup of class ThermoPhase

This commit is contained in:
Ray Speth 2014-02-06 22:59:07 +00:00
parent 14b1bf093b
commit fb2f52b2ec
2 changed files with 26 additions and 87 deletions

View file

@ -90,19 +90,15 @@ class XML_Node;
* activity concentrations. The dimensions depend on the number
* of products and reactants.
*
*
* The kinetics manager requires the calculation of K_c for the
* calculation of the reverse rate constant
*
*
* @ingroup thermoprops
* @ingroup phases
*/
class ThermoPhase : public Phase
{
public:
//! Constructor. Note that ThermoPhase is meant to be used as
//! a base class, so this constructor should not be called
//! explicitly.
@ -119,15 +115,12 @@ public:
//! Assignment operator
/*!
* This is NOT a virtual function.
*
* @param right Reference to %ThermoPhase object to be copied into the
* current one.
*/
ThermoPhase& operator=(const ThermoPhase& right);
//! Duplication routine for objects which inherit from
//! ThermoPhase.
//! Duplication routine for objects which inherit from ThermoPhase.
/*!
* This virtual routine can be used to duplicate %ThermoPhase objects
* inherited from %ThermoPhase even if the application only has
@ -335,9 +328,8 @@ public:
* @}
* @name Electric Potential
*
* The phase may be at some non-zero electrical
* potential. These methods set or get the value of the
* electric potential.
* The phase may be at some non-zero electrical potential. These methods
* set or get the value of the electric potential.
*/
//@{
@ -372,8 +364,7 @@ public:
* \hat R T \log a_k. \f] The quantity \f$\mu_k^0(T,P)\f$ is
* the standard chemical potential at unit activity,
* which depends on temperature and pressure,
* but not on composition. The
* activity is dimensionless.
* but not on composition. The activity is dimensionless.
* @{
*/
@ -951,8 +942,7 @@ public:
/**
* @name Setting the State
*
* These methods set all or part of the thermodynamic
* state.
* These methods set all or part of the thermodynamic state.
* @{
*/
@ -1084,7 +1074,6 @@ public:
virtual void setState_UV(doublereal u, doublereal v, doublereal tol = 1.e-4);
private:
//! Carry out work in HP and UV calculations.
/*!
* @param h Specific enthalpy or internal energy (J/kg)
@ -1098,7 +1087,6 @@ private:
doublereal tol = 1.e-4, bool doUV = false);
public:
//! Set the specific entropy (J/kg/K) and pressure (Pa).
/*!
* This function fixes the internal state of the phase so that
@ -1152,7 +1140,6 @@ public:
* @{
*/
//!This method is used by the ChemEquil equilibrium solver.
/*!
* It sets the state such that the chemical potentials satisfy
@ -1182,7 +1169,6 @@ public:
*/
void setElementPotentials(const vector_fp& lambda);
//! Returns the element potentials stored in the ThermoPhase object
/*!
* Returns the stored element potentials.
@ -1209,20 +1195,17 @@ public:
/// Critical temperature (K).
virtual doublereal critTemperature() const {
err("critTemperature");
return -1.0;
return err("critTemperature");
}
/// Critical pressure (Pa).
virtual doublereal critPressure() const {
err("critPressure");
return -1.0;
return err("critPressure");
}
/// Critical density (kg/m3).
virtual doublereal critDensity() const {
err("critDensity");
return -1.0;
return err("critDensity");
}
//@}
@ -1240,8 +1223,7 @@ public:
* @param p Pressure (Pa)
*/
virtual doublereal satTemperature(doublereal p) const {
err("satTemperature");
return -1.0;
return err("satTemperature");
}
//! Return the saturation pressure given the temperature
@ -1249,14 +1231,12 @@ public:
* @param t Temperature (Kelvin)
*/
virtual doublereal satPressure(doublereal t) {
err("satPressure");
return -1.0;
return err("satPressure");
}
//! Return the fraction of vapor at the current conditions
virtual doublereal vaporFraction() const {
err("vaprFraction");
return -1.0;
return err("vaprFraction");
}
//! Set the state to a saturated system at a particular temperature
@ -1334,8 +1314,7 @@ public:
/**
* @internal
* Initialization of a ThermoPhase object using an
* ctml file.
* Initialization of a ThermoPhase object using an ctml file.
*
* This routine is a precursor to initThermoXML(XML_Node*)
* routine, which does most of the work.
@ -1426,7 +1405,6 @@ public:
virtual void setParameters(int n, doublereal* const c) {
}
//! Get the equation of state parameters in a vector
/*!
* @internal
@ -1438,10 +1416,8 @@ public:
virtual void getParameters(int& n, doublereal* const c) const {
}
//! Set equation of state parameter values from XML entries.
/*!
*
* This method is called by function importPhase() in
* file importCTML.cpp when processing a phase definition in
* an input file. It should be overloaded in subclasses to set
@ -1454,7 +1430,6 @@ public:
*/
virtual void setParametersFromXML(const XML_Node& eosdata) {}
//! Set the initial state of the phase to the conditions
//! specified in the state XML element.
/*!
@ -1576,7 +1551,6 @@ public:
//@}
protected:
//! Fills `names` and `data` with the column names and species thermo
//! properties to be included in the output of the reportCSV method.
virtual void getCsvReportData(std::vector<std::string>& names,
@ -1637,13 +1611,11 @@ protected:
std::vector<doublereal> xMol_Ref;
private:
//! Error function that gets called for unhandled cases
/*!
* @param msg String containing the message.
*/
doublereal err(const std::string& msg) const;
};
//! typedef for the ThermoPhase class
@ -1652,4 +1624,3 @@ typedef ThermoPhase thermo_t;
}
#endif

View file

@ -21,7 +21,6 @@ namespace Cantera
{
ThermoPhase::ThermoPhase() :
Phase(),
m_spthermo(0), m_speciesData(0),
m_phi(0.0),
m_hasElementPotentials(false),
@ -39,7 +38,6 @@ ThermoPhase::~ThermoPhase()
}
ThermoPhase::ThermoPhase(const ThermoPhase& right) :
Phase(),
m_spthermo(0),
m_speciesData(0),
m_phi(0.0),
@ -53,8 +51,7 @@ ThermoPhase::ThermoPhase(const ThermoPhase& right) :
*this = operator=(right);
}
ThermoPhase& ThermoPhase::
operator=(const ThermoPhase& right)
ThermoPhase& ThermoPhase::operator=(const ThermoPhase& right)
{
/*
* Check for self assignment.
@ -153,22 +150,19 @@ void ThermoPhase::setState_TPX(doublereal t, doublereal p, const std::string& x)
setState_TP(t,p);
}
void ThermoPhase::setState_TPY(doublereal t, doublereal p,
const doublereal* y)
void ThermoPhase::setState_TPY(doublereal t, doublereal p, const doublereal* y)
{
setMassFractions(y);
setState_TP(t,p);
}
void ThermoPhase::setState_TPY(doublereal t, doublereal p,
compositionMap& y)
void ThermoPhase::setState_TPY(doublereal t, doublereal p, compositionMap& y)
{
setMassFractionsByName(y);
setState_TP(t,p);
}
void ThermoPhase::setState_TPY(doublereal t, doublereal p,
const std::string& y)
void ThermoPhase::setState_TPY(doublereal t, doublereal p, const std::string& y)
{
compositionMap yy = parseCompString(y, speciesNames());
setMassFractionsByName(yy);
@ -199,8 +193,7 @@ void ThermoPhase::setState_HP(doublereal Htarget, doublereal p,
setState_HPorUV(Htarget, p, dTtol, false);
}
void ThermoPhase::setState_UV(doublereal u, doublereal v,
doublereal dTtol)
void ThermoPhase::setState_UV(doublereal u, doublereal v, doublereal dTtol)
{
setState_HPorUV(u, v, dTtol, true);
}
@ -217,12 +210,11 @@ void ThermoPhase::setState_HPorUV(doublereal Htarget, doublereal p,
doublereal dTtol, bool doUV)
{
doublereal dt;
doublereal Hmax = 0.0, Hmin = 0.0;
doublereal v = 0.0;
// Assign the specific volume or pressure and make sure it's positive
if (doUV) {
v = p;
doublereal v = p;
if (v < 1.0E-300) {
throw CanteraError("setState_HPorUV (UV)",
"Input specific volume is too small or negative. v = " + fp2str(v));
@ -301,7 +293,7 @@ void ThermoPhase::setState_HPorUV(doublereal Htarget, doublereal p,
// Check Max and Min values
if (Tnew > Tmax && !ignoreBounds) {
setState_conditional_TP(Tmax, p, !doUV);
Hmax = (doUV) ? intEnergy_mass() : enthalpy_mass();
double Hmax = (doUV) ? intEnergy_mass() : enthalpy_mass();
if (Hmax >= Htarget) {
if (Htop < Htarget) {
Ttop = Tmax;
@ -314,7 +306,7 @@ void ThermoPhase::setState_HPorUV(doublereal Htarget, doublereal p,
}
if (Tnew < Tmin && !ignoreBounds) {
setState_conditional_TP(Tmin, p, !doUV);
Hmin = (doUV) ? intEnergy_mass() : enthalpy_mass();
double Hmin = (doUV) ? intEnergy_mass() : enthalpy_mass();
if (Hmin <= Htarget) {
if (Hbot > Htarget) {
Tbot = Tmin;
@ -644,7 +636,6 @@ SpeciesThermo& ThermoPhase::speciesThermo(int k)
void ThermoPhase::initThermoFile(const std::string& inputFile,
const std::string& id)
{
if (inputFile.size() == 0) {
throw CanteraError("ThermoPhase::initThermoFile",
"input file is null");
@ -659,7 +650,6 @@ void ThermoPhase::initThermoFile(const std::string& inputFile,
* The phase object automatically constructs an XML object.
* Use this object to store information.
*/
//XML_Node& phaseNode_XML = xml();
XML_Node* fxml = new XML_Node();
fxml->build(fin);
XML_Node* fxml_phase = findXMLPhase(fxml, id);
@ -668,8 +658,6 @@ void ThermoPhase::initThermoFile(const std::string& inputFile,
"ERROR: Can not find phase named " +
id + " in file named " + inputFile);
}
//fxml_phase->copy(&phaseNode_XML);
//initThermoXML(*fxml_phase, id);
bool m_ok = importPhase(*fxml_phase, this);
if (!m_ok) {
throw CanteraError("ThermoPhase::initThermoFile","importPhase failed ");
@ -679,10 +667,6 @@ void ThermoPhase::initThermoFile(const std::string& inputFile,
void ThermoPhase::initThermoXML(XML_Node& phaseNode, const std::string& id)
{
/*
* and sets the state
*/
if (phaseNode.hasChild("state")) {
XML_Node& stateNode = phaseNode.child("state");
setStateFromXML(stateNode);
@ -694,28 +678,20 @@ void ThermoPhase::setReferenceComposition(const doublereal* const x)
{
xMol_Ref.resize(m_kk);
if (x) {
for (size_t k = 0; k < m_kk; k++) {
xMol_Ref[k] = x[k];
}
copy(x, x + m_kk, xMol_Ref.begin());
} else {
getMoleFractions(DATA_PTR(xMol_Ref));
}
double sum = -1.0;
for (size_t k = 0; k < m_kk; k++) {
sum += xMol_Ref[k];
getMoleFractions(&xMol_Ref[0]);
}
double sum = accumulate(xMol_Ref.begin(), xMol_Ref.end(), -1.0);
if (fabs(sum) > 1.0E-11) {
throw CanteraError("ThermoPhase::setReferenceComposition",
"input mole fractions don't sum to 1.0");
}
}
void ThermoPhase::getReferenceComposition(doublereal* const x) const
{
for (size_t k = 0; k < m_kk; k++) {
x[k] = xMol_Ref[k];
}
copy(xMol_Ref.begin(), xMol_Ref.end(), x);
}
void ThermoPhase::initThermo()
@ -775,7 +751,6 @@ void ThermoPhase::setStateFromXML(const XML_Node& state)
void ThermoPhase::setElementPotentials(const vector_fp& lambda)
{
doublereal rrt = 1.0/(GasConstant* temperature());
size_t mm = nElements();
if (lambda.size() < mm) {
throw CanteraError("setElementPotentials", "lambda too small");
@ -783,19 +758,14 @@ void ThermoPhase::setElementPotentials(const vector_fp& lambda)
if (!m_hasElementPotentials) {
m_lambdaRRT.resize(mm);
}
for (size_t m = 0; m < mm; m++) {
m_lambdaRRT[m] = lambda[m] * rrt;
}
scale(m_lambdaRRT, 1.0/(GasConstant* temperature()));
m_hasElementPotentials = true;
}
bool ThermoPhase::getElementPotentials(doublereal* lambda) const
{
doublereal rt = GasConstant* temperature();
if (m_hasElementPotentials) {
for (size_t m = 0; m < nElements(); m++) {
lambda[m] = m_lambdaRRT[m] * rt;
}
scale(lambda, lambda + nElements(), lambda, GasConstant* temperature());
}
return m_hasElementPotentials;
}
@ -946,7 +916,6 @@ std::string ThermoPhase::report(bool show_thermo) const
getMassFractions(&y[0]);
getChemPotentials(&mu[0]);
doublereal rt = GasConstant * temperature();
//if (th.nSpecies() > 1) {
if (show_thermo) {
sprintf(p, " \n X "
@ -979,7 +948,6 @@ std::string ThermoPhase::report(bool show_thermo) const
}
}
}
//}
catch (CanteraError& err) {
err.save();
}