diff --git a/Cantera/src/thermo/ThermoPhase.cpp b/Cantera/src/thermo/ThermoPhase.cpp index 215237cca..ac060e27d 100644 --- a/Cantera/src/thermo/ThermoPhase.cpp +++ b/Cantera/src/thermo/ThermoPhase.cpp @@ -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) { diff --git a/Cantera/src/thermo/ThermoPhase.h b/Cantera/src/thermo/ThermoPhase.h index 4b2f17ee3..f4c2042a0 100755 --- a/Cantera/src/thermo/ThermoPhase.h +++ b/Cantera/src/thermo/ThermoPhase.h @@ -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 xMol_Ref; + private: //! Error function that gets called for unhandled cases