Fixed a bug in the calculation of reference state values, for
thermophase objects that derive from VPStandardStateTP
This commit is contained in:
parent
77bb1baa7e
commit
aa7bf0421b
7 changed files with 368 additions and 20 deletions
|
|
@ -49,6 +49,8 @@ namespace Cantera {
|
|||
m_densWaterSS(1000.),
|
||||
m_waterProps(0)
|
||||
{
|
||||
m_useTmpRefStateStorage = true;
|
||||
m_useTmpStandardStateStorage = false;
|
||||
m_npActCoeff.resize(3);
|
||||
m_npActCoeff[0] = 0.1127;
|
||||
m_npActCoeff[1] = -0.01049;
|
||||
|
|
@ -78,11 +80,13 @@ namespace Cantera {
|
|||
m_densWaterSS(1000.),
|
||||
m_waterProps(0)
|
||||
{
|
||||
m_useTmpRefStateStorage = true;
|
||||
m_useTmpStandardStateStorage = false;
|
||||
m_npActCoeff.resize(3);
|
||||
m_npActCoeff[0] = 0.1127;
|
||||
m_npActCoeff[1] = -0.01049;
|
||||
m_npActCoeff[2] = 1.545E-3;
|
||||
constructPhaseFile(inputFile, id);
|
||||
constructPhaseFile(inputFile, id);
|
||||
}
|
||||
|
||||
DebyeHuckel::DebyeHuckel(XML_Node& phaseRoot, std::string id) :
|
||||
|
|
@ -100,11 +104,13 @@ namespace Cantera {
|
|||
m_densWaterSS(1000.),
|
||||
m_waterProps(0)
|
||||
{
|
||||
m_useTmpRefStateStorage = true;
|
||||
m_useTmpStandardStateStorage = false;
|
||||
m_npActCoeff.resize(3);
|
||||
m_npActCoeff[0] = 0.1127;
|
||||
m_npActCoeff[1] = -0.01049;
|
||||
m_npActCoeff[2] = 1.545E-3;
|
||||
constructPhaseXML(phaseRoot, id);
|
||||
constructPhaseXML(phaseRoot, id);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -1013,6 +1019,113 @@ namespace Cantera {
|
|||
vol[0] = molecularWeight(0)/dd;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DebyeHuckel::getGibbs_RT_ref(doublereal *grt) const {
|
||||
/*
|
||||
* Call the function that makes sure the local copy of
|
||||
* the species reference thermo functions are up to date
|
||||
* for the current temperature.
|
||||
*/
|
||||
_updateRefStateThermo();
|
||||
/*
|
||||
* Copy the gibbs function into return vector.
|
||||
*/
|
||||
copy(m_g0_RT.begin(), m_g0_RT.end(), grt);
|
||||
|
||||
if (m_waterSS) {
|
||||
double pnow = m_Pcurrent;
|
||||
double tnow = temperature();
|
||||
m_waterSS->setTempPressure(tnow, m_p0);
|
||||
double mu0 = m_waterSS->gibbs_mole();
|
||||
m_waterSS->setTempPressure(tnow, pnow);
|
||||
double rt = _RT();
|
||||
grt[0] = mu0 / rt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DebyeHuckel::getEnthalpy_RT_ref(doublereal *hrt) const {
|
||||
/*
|
||||
* Call the function that makes sure the local copy of
|
||||
* the species reference thermo functions are up to date
|
||||
* for the current temperature.
|
||||
*/
|
||||
_updateRefStateThermo();
|
||||
/*
|
||||
* Copy the gibbs function into return vector.
|
||||
*/
|
||||
copy(m_h0_RT.begin(), m_h0_RT.end(), hrt);
|
||||
|
||||
if (m_waterSS) {
|
||||
double pnow = m_Pcurrent;
|
||||
double tnow = temperature();
|
||||
m_waterSS->setTempPressure(tnow, m_p0);
|
||||
double h0 = m_waterSS->enthalpy_mole();
|
||||
m_waterSS->setTempPressure(tnow, pnow);
|
||||
double rt = _RT();
|
||||
hrt[0] = h0 / rt;
|
||||
}
|
||||
}
|
||||
|
||||
void DebyeHuckel::getEntropy_R_ref(doublereal *sr) const {
|
||||
/*
|
||||
* Call the function that makes sure the local copy of
|
||||
* the species reference thermo functions are up to date
|
||||
* for the current temperature.
|
||||
*/
|
||||
_updateRefStateThermo();
|
||||
/*
|
||||
* Copy the gibbs function into return vector.
|
||||
*/
|
||||
copy(m_s0_R.begin(), m_s0_R.end(), sr);
|
||||
|
||||
if (m_waterSS) {
|
||||
double pnow = m_Pcurrent;
|
||||
double tnow = temperature();
|
||||
m_waterSS->setTempPressure(tnow, m_p0);
|
||||
double s0 = m_waterSS->entropy_mole();
|
||||
m_waterSS->setTempPressure(tnow, pnow);
|
||||
sr[0] = s0 / GasConstant;
|
||||
}
|
||||
}
|
||||
|
||||
void DebyeHuckel::getCp_R_ref(doublereal *cpr) const {
|
||||
/*
|
||||
* Call the function that makes sure the local copy of
|
||||
* the species reference thermo functions are up to date
|
||||
* for the current temperature.
|
||||
*/
|
||||
_updateRefStateThermo();
|
||||
copy(m_cp0_R.begin(), m_cp0_R.end(), cpr);
|
||||
if (m_waterSS) {
|
||||
double pnow = m_Pcurrent;
|
||||
double tnow = temperature();
|
||||
m_waterSS->setTempPressure(tnow, m_p0);
|
||||
double cp0 = m_waterSS->cp_mole();
|
||||
m_waterSS->setTempPressure(tnow, pnow);
|
||||
cpr[0] = cp0 / GasConstant;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the molar volumes of each species in their reference
|
||||
* states at the current
|
||||
* <I>T</I> and <I>P</I> of the solution.
|
||||
* units = m^3 / kmol
|
||||
*/
|
||||
void DebyeHuckel::getStandardVolumes_ref(doublereal *vol) const {
|
||||
double psave = m_Pcurrent;
|
||||
_updateStandardStateThermo(m_p0);
|
||||
copy(m_speciesSize.begin(),
|
||||
m_speciesSize.end(), vol);
|
||||
if (m_waterSS) {
|
||||
double dd = m_waterSS->density();
|
||||
vol[0] = molecularWeight(0)/dd;
|
||||
}
|
||||
_updateStandardStateThermo(psave);
|
||||
}
|
||||
|
||||
/*
|
||||
* ------ Thermodynamic Values for the Species Reference States ---
|
||||
|
|
@ -1703,6 +1816,11 @@ namespace Cantera {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (m_waterSS) {
|
||||
m_useTmpRefStateStorage = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lastly set the state
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1209,6 +1209,56 @@ namespace Cantera {
|
|||
*/
|
||||
virtual void getStandardVolumes(doublereal *vol) const;
|
||||
|
||||
//! Returns the vector of nondimensional
|
||||
//! Gibbs Free Energies of the reference state at the current temperature
|
||||
//! of the solution and the reference pressure for the species.
|
||||
/*!
|
||||
* @param grt Output vector containing the nondimensional reference state
|
||||
* Gibbs Free energies. Length: m_kk.
|
||||
*/
|
||||
virtual void getGibbs_RT_ref(doublereal *grt) const;
|
||||
|
||||
//! Returns the vector of nondimensional
|
||||
//! enthalpies of the reference state at the current temperature
|
||||
//! of the solution and the reference pressure for the species.
|
||||
/*!
|
||||
* @param hrt Output vector containing the nondimensional reference state enthalpies
|
||||
* Length: m_kk.
|
||||
*/
|
||||
virtual void getEnthalpy_RT_ref(doublereal *hrt) const;
|
||||
|
||||
/*!
|
||||
* Returns the vector of nondimensional
|
||||
* entropies of the reference state at the current temperature
|
||||
* of the solution and the reference pressure for each species.
|
||||
*
|
||||
* @param er Output vector containing the nondimensional reference state
|
||||
* entropies. Length: m_kk.
|
||||
*/
|
||||
virtual void getEntropy_R_ref(doublereal *er) const;
|
||||
|
||||
/*!
|
||||
* Returns the vector of nondimensional
|
||||
* constant pressure heat capacities of the reference state
|
||||
* at the current temperature of the solution
|
||||
* and reference pressure for each species.
|
||||
*
|
||||
* @param cprt Output vector of nondimensional reference state
|
||||
* heat capacities at constant pressure for the species.
|
||||
* Length: m_kk
|
||||
*/
|
||||
virtual void getCp_R_ref(doublereal *cprt) const;
|
||||
|
||||
//! Get the molar volumes of the species reference states at the current
|
||||
//! <I>T</I> and <I>P_ref</I> of the solution.
|
||||
/*!
|
||||
* units = m^3 / kmol
|
||||
*
|
||||
* @param vol Output vector containing the standard state volumes.
|
||||
* Length: m_kk.
|
||||
*/
|
||||
virtual void getStandardVolumes_ref(doublereal *vol) const;
|
||||
|
||||
protected:
|
||||
|
||||
//! Updates the standard state thermodynamic functions at the current T and P of the solution.
|
||||
|
|
|
|||
|
|
@ -1132,7 +1132,7 @@ namespace Cantera {
|
|||
getStandardChemPotentials(gpure);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
*
|
||||
* getEnthalpy_RT() (virtual, const)
|
||||
*
|
||||
|
|
@ -1149,8 +1149,19 @@ namespace Cantera {
|
|||
*/
|
||||
void HMWSoln::
|
||||
getEnthalpy_RT(doublereal* hrt) const {
|
||||
/*
|
||||
* Call the function that makes sure the local copy of
|
||||
* the species reference thermo functions are up to date
|
||||
* for the current temperature.
|
||||
*/
|
||||
_updateStandardStateThermo();
|
||||
getEnthalpy_RT_ref(hrt);
|
||||
/*
|
||||
* Copy the gibbs function into return vector.
|
||||
*/
|
||||
copy(m_h0_RT.begin(), m_h0_RT.end(), hrt);
|
||||
// We don't call the reference state functions, because there may
|
||||
// not be a solution at 1 atm for the water equation.
|
||||
// getEnthalpy_RT_ref(hrt);
|
||||
doublereal pref;
|
||||
doublereal delta_p;
|
||||
double RT = _RT();
|
||||
|
|
@ -1163,7 +1174,7 @@ namespace Cantera {
|
|||
hrt[0] /= RT;
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* getEntropy_R() (virtual, const)
|
||||
*
|
||||
* Get the nondimensional Entropies for the species
|
||||
|
|
@ -1180,7 +1191,13 @@ namespace Cantera {
|
|||
void HMWSoln::
|
||||
getEntropy_R(doublereal* sr) const {
|
||||
_updateStandardStateThermo();
|
||||
getEntropy_R_ref(sr);
|
||||
/*
|
||||
* Copy the gibbs function into return vector.
|
||||
*/
|
||||
copy(m_s0_R.begin(), m_s0_R.end(), sr);
|
||||
// We don't call the reference state functions, because there may
|
||||
// not be a solution at 1 atm for the water equation.
|
||||
//getEntropy_R_ref(sr);
|
||||
sr[0] = m_waterSS->entropy_mole();
|
||||
sr[0] /= GasConstant;
|
||||
}
|
||||
|
|
@ -1202,7 +1219,8 @@ namespace Cantera {
|
|||
*/
|
||||
void HMWSoln::getCp_R(doublereal* cpr) const {
|
||||
_updateStandardStateThermo();
|
||||
getCp_R_ref(cpr);
|
||||
copy(m_cp0_R.begin(), m_cp0_R.end(), cpr);
|
||||
//getCp_R_ref(cpr);
|
||||
cpr[0] = m_waterSS->cp_mole();
|
||||
cpr[0] /= GasConstant;
|
||||
}
|
||||
|
|
@ -1222,8 +1240,110 @@ namespace Cantera {
|
|||
vol[0] = molecularWeight(0)/dd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HMWSoln::getGibbs_RT_ref(doublereal *grt) const {
|
||||
/*
|
||||
* Call the function that makes sure the local copy of
|
||||
* the species reference thermo functions are up to date
|
||||
* for the current temperature.
|
||||
*/
|
||||
_updateRefStateThermo();
|
||||
/*
|
||||
* Copy the gibbs function into return vector.
|
||||
*/
|
||||
copy(m_g0_RT.begin(), m_g0_RT.end(), grt);
|
||||
|
||||
double pnow = m_Pcurrent;
|
||||
double tnow = temperature();
|
||||
m_waterSS->setTempPressure(tnow, m_p0);
|
||||
double mu0 = m_waterSS->gibbs_mole();
|
||||
m_waterSS->setTempPressure(tnow, pnow);
|
||||
double rt = _RT();
|
||||
grt[0] = mu0 / rt;
|
||||
}
|
||||
|
||||
void HMWSoln::getEnthalpy_RT_ref(doublereal *hrt) const {
|
||||
/*
|
||||
* Call the function that makes sure the local copy of
|
||||
* the species reference thermo functions are up to date
|
||||
* for the current temperature.
|
||||
*/
|
||||
_updateRefStateThermo();
|
||||
/*
|
||||
* Copy the gibbs function into return vector.
|
||||
*/
|
||||
copy(m_h0_RT.begin(), m_h0_RT.end(), hrt);
|
||||
|
||||
double pnow = m_Pcurrent;
|
||||
double tnow = temperature();
|
||||
m_waterSS->setTempPressure(tnow, m_p0);
|
||||
double h0 = m_waterSS->enthalpy_mole();
|
||||
m_waterSS->setTempPressure(tnow, pnow);
|
||||
double rt = _RT();
|
||||
hrt[0] = h0 / rt;
|
||||
}
|
||||
|
||||
|
||||
void HMWSoln::getEntropy_R_ref(doublereal *sr) const {
|
||||
/*
|
||||
* Call the function that makes sure the local copy of
|
||||
* the species reference thermo functions are up to date
|
||||
* for the current temperature.
|
||||
*/
|
||||
_updateRefStateThermo();
|
||||
/*
|
||||
* Copy the gibbs function into return vector.
|
||||
*/
|
||||
copy(m_s0_R.begin(), m_s0_R.end(), sr);
|
||||
|
||||
double pnow = m_Pcurrent;
|
||||
double tnow = temperature();
|
||||
m_waterSS->setTempPressure(tnow, m_p0);
|
||||
double s0 = m_waterSS->entropy_mole();
|
||||
m_waterSS->setTempPressure(tnow, pnow);
|
||||
sr[0] = s0 / GasConstant;
|
||||
}
|
||||
|
||||
|
||||
void HMWSoln::getCp_R_ref(doublereal *cpr) const {
|
||||
/*
|
||||
* Call the function that makes sure the local copy of
|
||||
* the species reference thermo functions are up to date
|
||||
* for the current temperature.
|
||||
*/
|
||||
_updateRefStateThermo();
|
||||
copy(m_cp0_R.begin(), m_cp0_R.end(), cpr);
|
||||
double pnow = m_Pcurrent;
|
||||
double tnow = temperature();
|
||||
m_waterSS->setTempPressure(tnow, m_p0);
|
||||
double cp0 = m_waterSS->cp_mole();
|
||||
m_waterSS->setTempPressure(tnow, pnow);
|
||||
cpr[0] = cp0 / GasConstant;
|
||||
}
|
||||
|
||||
/*
|
||||
* Updates the standard state thermodynamic functions at the current T and P of the solution.
|
||||
* Get the molar volumes of each species in their reference
|
||||
* states at the current
|
||||
* <I>T</I> and <I>P</I> of the solution.
|
||||
* units = m^3 / kmol
|
||||
*/
|
||||
void HMWSoln::getStandardVolumes_ref(doublereal *vol) const {
|
||||
double psave = m_Pcurrent;
|
||||
_updateStandardStateThermo(m_p0);
|
||||
copy(m_speciesSize.begin(),
|
||||
m_speciesSize.end(), vol);
|
||||
if (m_waterSS) {
|
||||
double dd = m_waterSS->density();
|
||||
vol[0] = molecularWeight(0)/dd;
|
||||
}
|
||||
_updateStandardStateThermo(psave);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Updates the standard state thermodynamic functions at the current T and
|
||||
* P of the solution.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
|
|
@ -3527,7 +3647,6 @@ namespace Cantera {
|
|||
std::exit(-1);
|
||||
}
|
||||
|
||||
double d2_wateract_dT2;
|
||||
std::string sni, snj, snk;
|
||||
|
||||
const double *molality = DATA_PTR(m_molalities);
|
||||
|
|
|
|||
|
|
@ -621,6 +621,56 @@ namespace Cantera {
|
|||
*/
|
||||
virtual void getStandardVolumes(doublereal *vol) const;
|
||||
|
||||
//! Returns the vector of nondimensional
|
||||
//! Gibbs Free Energies of the reference state at the current temperature
|
||||
//! of the solution and the reference pressure for the species.
|
||||
/*!
|
||||
* @param grt Output vector containing the nondimensional reference state
|
||||
* Gibbs Free energies. Length: m_kk.
|
||||
*/
|
||||
virtual void getGibbs_RT_ref(doublereal *grt) const;
|
||||
|
||||
//! Returns the vector of nondimensional
|
||||
//! enthalpies of the reference state at the current temperature
|
||||
//! of the solution and the reference pressure for the species.
|
||||
/*!
|
||||
* @param hrt Output vector containing the nondimensional reference state enthalpies
|
||||
* Length: m_kk.
|
||||
*/
|
||||
virtual void getEnthalpy_RT_ref(doublereal *hrt) const;
|
||||
|
||||
/*!
|
||||
* Returns the vector of nondimensional
|
||||
* entropies of the reference state at the current temperature
|
||||
* of the solution and the reference pressure for each species.
|
||||
*
|
||||
* @param er Output vector containing the nondimensional reference state
|
||||
* entropies. Length: m_kk.
|
||||
*/
|
||||
virtual void getEntropy_R_ref(doublereal *er) const;
|
||||
|
||||
/*!
|
||||
* Returns the vector of nondimensional
|
||||
* constant pressure heat capacities of the reference state
|
||||
* at the current temperature of the solution
|
||||
* and reference pressure for each species.
|
||||
*
|
||||
* @param cprt Output vector of nondimensional reference state
|
||||
* heat capacities at constant pressure for the species.
|
||||
* Length: m_kk
|
||||
*/
|
||||
virtual void getCp_R_ref(doublereal *cprt) const;
|
||||
|
||||
//! Get the molar volumes of the species reference states at the current
|
||||
//! <I>T</I> and <I>P_ref</I> of the solution.
|
||||
/*!
|
||||
* units = m^3 / kmol
|
||||
*
|
||||
* @param vol Output vector containing the standard state volumes.
|
||||
* Length: m_kk.
|
||||
*/
|
||||
virtual void getStandardVolumes_ref(doublereal *vol) const;
|
||||
|
||||
protected:
|
||||
|
||||
//! Updates the standard state thermodynamic functions at the current T and P of the solution.
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ namespace Cantera {
|
|||
MolalityVPSSTP(),
|
||||
m_formGC(2)
|
||||
{
|
||||
m_useTmpRefStateStorage = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -77,14 +78,18 @@ namespace Cantera {
|
|||
}
|
||||
|
||||
IdealMolalSoln::IdealMolalSoln(std::string inputFile, std::string id) :
|
||||
MolalityVPSSTP()
|
||||
MolalityVPSSTP(),
|
||||
m_formGC(2)
|
||||
{
|
||||
m_useTmpRefStateStorage = true;
|
||||
constructPhaseFile(inputFile, id);
|
||||
}
|
||||
|
||||
IdealMolalSoln::IdealMolalSoln(XML_Node& root, std::string id) :
|
||||
MolalityVPSSTP()
|
||||
MolalityVPSSTP(),
|
||||
m_formGC(2)
|
||||
{
|
||||
m_useTmpRefStateStorage = true;
|
||||
constructPhaseXML(root, id);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ namespace Cantera {
|
|||
m_tlast_ref(-1.0),
|
||||
m_plast(-1.0),
|
||||
m_p0(OneAtm),
|
||||
m_useTmpRefStateStorage(true),
|
||||
m_useTmpRefStateStorage(false),
|
||||
m_useTmpStandardStateStorage(false)
|
||||
{
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ namespace Cantera {
|
|||
m_tlast_ref(-1.0),
|
||||
m_plast(-1.0),
|
||||
m_p0(OneAtm),
|
||||
m_useTmpRefStateStorage(true),
|
||||
m_useTmpRefStateStorage(false),
|
||||
m_useTmpStandardStateStorage(false)
|
||||
{
|
||||
*this = b;
|
||||
|
|
@ -390,12 +390,18 @@ namespace Cantera {
|
|||
void VPStandardStateTP::initLengths() {
|
||||
m_kk = nSpecies();
|
||||
int leng = m_kk;
|
||||
if (m_useTmpRefStateStorage){
|
||||
m_h0_RT.resize(leng);
|
||||
m_g0_RT.resize(leng);
|
||||
m_cp0_R.resize(leng);
|
||||
m_s0_R.resize(leng);
|
||||
}
|
||||
/*
|
||||
* malloc the storage for this even if
|
||||
* m_useTmpRefStateStorage is set to false.
|
||||
* So many functions need that temporary storage anyway.
|
||||
* However, that variable is still used to see if the
|
||||
* storage is used to supply the complete picture.
|
||||
*/
|
||||
m_h0_RT.resize(leng);
|
||||
m_g0_RT.resize(leng);
|
||||
m_cp0_R.resize(leng);
|
||||
m_s0_R.resize(leng);
|
||||
|
||||
if (m_useTmpStandardStateStorage) {
|
||||
m_hss_RT.resize(leng);
|
||||
m_gss_RT.resize(leng);
|
||||
|
|
|
|||
|
|
@ -510,7 +510,7 @@ namespace Cantera {
|
|||
|
||||
/*!
|
||||
* boolean indicating whether temporary reference state storage is used
|
||||
* -> default is true
|
||||
* -> default is false
|
||||
*/
|
||||
bool m_useTmpRefStateStorage;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue