Added the concept of a reference mole fraction vector.

This is a vector that is a baseline "safe" mole fraction
vector that can be applied anywhere. I was running into problems
with specifying this for molten salts, because just setting
the first component to a mole fraction of 1 causes
charge imbalance.

M    thermo/ThermoPhase.h
M    thermo/ThermoPhase.cpp
This commit is contained in:
Harry Moffat 2009-09-02 22:03:46 +00:00
parent f7e48f0068
commit bf97d0f90a
2 changed files with 51 additions and 0 deletions

View file

@ -864,6 +864,33 @@ namespace Cantera {
XML_Node& stateNode = phaseNode.child("state");
setStateFromXML(stateNode);
}
setReferenceComposition(0);
}
void ThermoPhase::setReferenceComposition(const doublereal *const x) {
xMol_Ref.resize(m_kk);
if (x) {
for (int k = 0; k < m_kk; k++) {
xMol_Ref[k] = x[k];
}
} else {
getMoleFractions(DATA_PTR(xMol_Ref));
}
double sum = -1.0;
for (int k = 0; k < m_kk; k++) {
sum += xMol_Ref[k];
}
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 (int k = 0; k < m_kk; k++) {
x[k] = xMol_Ref[k];
}
}
/*
@ -887,6 +914,7 @@ namespace Cantera {
throw CanteraError("ThermoPhase::initThermo()",
"Number of species is less than or equal to zero");
}
xMol_Ref.resize(m_kk, 0.0);
}
void ThermoPhase::saveSpeciesData(const int k, const XML_Node* const data) {

View file

@ -1392,6 +1392,20 @@ namespace Cantera {
err("getStandardVolumes_ref");
}
//! Sets the reference composition
/*!
* @param x Mole fraction vector to set the reference composition to.
* If this is zero, then the reference mole fraction
* is set to the current mole fraction vector.
*/
virtual void setReferenceComposition(const doublereal * const x);
//! Gets the reference composition
/*!
* The reference mole fraction is a safe mole fraction.
* @param x Mole fraction vector containing the reference composition.
*/
virtual void getReferenceComposition(doublereal * const x) const;
//
// The methods below are not virtual, and should not
@ -2058,6 +2072,15 @@ namespace Cantera {
//! Contains the standard state convention
int m_ssConvention;
//! Reference Mole Fraction Composition
/*!
* Occasionally, the need arises to find a safe mole fraction vector to initialize
* the object to. This contains such a vector.
* The algorithm will pick up the mole fraction vector that is applied from
* the state xml file in the input file
*/
std::vector<doublereal> xMol_Ref;
private:
//! Error function that gets called for unhandled cases