Another iteration with vcs_VolPhase: getting it to use private data,

setState concept and StateCalc concepts.
This commit is contained in:
Harry Moffat 2008-06-12 16:00:36 +00:00
parent 451520d238
commit 53fa07bbdc
8 changed files with 1345 additions and 1304 deletions

View file

@ -23,7 +23,7 @@
namespace VCSnonideal { namespace VCSnonideal {
/**************************************************************************** /*
* *
* vcs_VolPhase(): * vcs_VolPhase():
* *
@ -68,6 +68,7 @@ namespace VCSnonideal {
{ {
m_owningSolverObject = owningSolverObject; m_owningSolverObject = owningSolverObject;
} }
/************************************************************************************/
/* /*
* *
@ -82,6 +83,7 @@ namespace VCSnonideal {
sp = 0; sp = 0;
} }
} }
/************************************************************************************/
/* /*
* *
@ -131,8 +133,9 @@ namespace VCSnonideal {
*/ */
*this = b; *this = b;
} }
/*****************************************************************************/
/***************************************************************************** /*
* Assignment operator() * Assignment operator()
* *
* (note, this is used, so keep it current!) * (note, this is used, so keep it current!)
@ -239,7 +242,7 @@ namespace VCSnonideal {
} }
return *this; return *this;
} }
/************************************************************************************/
void vcs_VolPhase::resize(int phaseNum, int nspecies, const char *phaseName, void vcs_VolPhase::resize(int phaseNum, int nspecies, const char *phaseName,
double molesInert) { double molesInert) {
@ -327,7 +330,7 @@ namespace VCSnonideal {
m_UpToDate_VolPM = false; m_UpToDate_VolPM = false;
m_UpToDate_GStar = false; m_UpToDate_GStar = false;
} }
/*******************************************************************************/
//! Evaluate activity coefficients //! Evaluate activity coefficients
/*! /*!
@ -357,8 +360,9 @@ namespace VCSnonideal {
} }
m_UpToDate_AC = true; m_UpToDate_AC = true;
} }
/********************************************************************************/
/****************************************************************************** /*
* *
* Evaluate one activity coefficients. * Evaluate one activity coefficients.
* *
@ -369,7 +373,7 @@ namespace VCSnonideal {
evaluateActCoeff(); evaluateActCoeff();
return(ActCoeff[kspec]); return(ActCoeff[kspec]);
} }
/************************************************************************************/
// Gibbs free energy calculation at a temperature for the reference state // Gibbs free energy calculation at a temperature for the reference state
// of each species // of each species
@ -424,8 +428,7 @@ namespace VCSnonideal {
* @param TKelvin Current temperature * @param TKelvin Current temperature
* @param pres Current pressure (pascal) * @param pres Current pressure (pascal)
*/ */
void vcs_VolPhase::GStar_calc() { void vcs_VolPhase::GStar_calc() const {
setState_TP(Temp, Pres);
if (!m_UpToDate_GStar) { if (!m_UpToDate_GStar) {
if (m_useCanteraCalls) { if (m_useCanteraCalls) {
TP_ptr->getStandardChemPotentials(VCS_DATA_PTR(StarChemicalPotential)); TP_ptr->getStandardChemPotentials(VCS_DATA_PTR(StarChemicalPotential));
@ -452,16 +455,14 @@ namespace VCSnonideal {
* The kth species standard state G is returned * The kth species standard state G is returned
* *
* @param kspec Species number (within the phase) * @param kspec Species number (within the phase)
* @param TKelvin Current temperature (kelvin)
* @param pres Current pressure (pascal)
* *
* @return Gstar[kspec] returns the gibbs free energy for the * @return Gstar[kspec] returns the gibbs free energy for the
* standard state of the kth species. * standard state of the kspec species.
*/ */
double vcs_VolPhase::GStar_calc_one(int kspec, double tkelvin, double vcs_VolPhase::GStar_calc_one(int kspec) {
double pres) { if (!m_UpToDate_GStar) {
setState_TP(tkelvin, pres); GStar_calc();
GStar_calc(); }
return StarChemicalPotential[kspec]; return StarChemicalPotential[kspec];
} }
/***********************************************************************/ /***********************************************************************/
@ -610,9 +611,7 @@ namespace VCSnonideal {
} }
if (!m_isIdealSoln) { if (!m_isIdealSoln) {
m_UpToDate_AC = false; m_UpToDate_AC = false;
m_UpToDate_VolStar = false;
m_UpToDate_VolPM = false; m_UpToDate_VolPM = false;
m_UpToDate_GStar = false;
} }
} }
@ -713,7 +712,6 @@ namespace VCSnonideal {
*/ */
void vcs_VolPhase::sendToVCS_GStar(double * const gstar){ void vcs_VolPhase::sendToVCS_GStar(double * const gstar){
if (!m_UpToDate_GStar) { if (!m_UpToDate_GStar) {
setState_TP(Temp, Pres);
GStar_calc(); GStar_calc();
} }
int kglob; int kglob;
@ -771,7 +769,7 @@ namespace VCSnonideal {
m_UpToDate_VolPM = false; m_UpToDate_VolPM = false;
m_UpToDate_GStar = false; m_UpToDate_GStar = false;
} }
/***********************************************************************/ /***********************************************************************/
// Molar volume calculation for standard states // Molar volume calculation for standard states
/* /*
@ -783,8 +781,7 @@ namespace VCSnonideal {
* *
* Calculations are in m**3/kmol * Calculations are in m**3/kmol
*/ */
void vcs_VolPhase::VolStar_calc(double tkelvin, double pres) { void vcs_VolPhase::VolStar_calc() const {
setState_TP(tkelvin, pres);
if (!m_UpToDate_VolStar) { if (!m_UpToDate_VolStar) {
if (m_useCanteraCalls) { if (m_useCanteraCalls) {
TP_ptr->getStandardVolumes(VCS_DATA_PTR(StarMolarVol)); TP_ptr->getStandardVolumes(VCS_DATA_PTR(StarMolarVol));
@ -794,13 +791,13 @@ namespace VCSnonideal {
vcs_SpeciesProperties *sProp = ListSpeciesPtr[k]; vcs_SpeciesProperties *sProp = ListSpeciesPtr[k];
VCS_SPECIES_THERMO *sTherm = sProp->SpeciesThermo; VCS_SPECIES_THERMO *sTherm = sProp->SpeciesThermo;
StarMolarVol[k] = StarMolarVol[k] =
(sTherm->VolStar_calc(kglob, tkelvin, pres)); (sTherm->VolStar_calc(kglob, Temp, Pres));
} }
} }
m_UpToDate_VolStar = true; m_UpToDate_VolStar = true;
} }
} }
/***********************************************************************/ /***********************************************************************/
// Update the moles within the phase, if necessary // Update the moles within the phase, if necessary
/* /*
@ -815,7 +812,7 @@ namespace VCSnonideal {
* *
*/ */
void vcs_VolPhase::updateFromVCS_MoleNumbers(const int stateCalc) { void vcs_VolPhase::updateFromVCS_MoleNumbers(const int stateCalc) {
if (!m_UpToDate) { if (!m_UpToDate || (stateCalc != m_vcsStateStatus)) {
if (stateCalc == VCS_STATECALC_OLD || stateCalc == VCS_STATECALC_NEW) { if (stateCalc == VCS_STATECALC_OLD || stateCalc == VCS_STATECALC_NEW) {
if (m_owningSolverObject) { if (m_owningSolverObject) {
setMolesFromVCS(stateCalc); setMolesFromVCS(stateCalc);
@ -839,13 +836,16 @@ namespace VCSnonideal {
* state * state
*/ */
double vcs_VolPhase::VolStar_calc_one(int kspec, double tkelvin, double vcs_VolPhase::VolStar_calc_one(int kspec, double tkelvin,
double pres) double pres) {
{ setState_TP(tkelvin, pres);
VolStar_calc(tkelvin, pres); if (!m_UpToDate_VolStar) {
VolStar_calc();
}
return StarMolarVol[kspec]; return StarMolarVol[kspec];
} }
/****************************************************************************/
/**************************************************************************** /*
* *
* VolPM_calc * VolPM_calc
*/ */
@ -885,20 +885,16 @@ namespace VCSnonideal {
m_UpToDate_VolPM = true; m_UpToDate_VolPM = true;
return m_totalVol; return m_totalVol;
} }
/************************************************************************************/
/* /*
* updateLnActCoeffJac(): * updateLnActCoeffJac():
* *
*/ */
void vcs_VolPhase::updateLnActCoeffJac(const double * const moleNumbersVCS) { void vcs_VolPhase::updateLnActCoeffJac() {
int k, j; int k, j;
double deltaMoles_j = 0.0; double deltaMoles_j = 0.0;
/*
* Make sure the base state of this object is fully up to date.
* with the current values of the mole numbers.
* -> This sets TMoles and Xmol[]
*/
setMolesFromVCS(VCS_STATECALC_OLD, moleNumbersVCS);
/* /*
* Evaluate the current base activity coefficients. * Evaluate the current base activity coefficients.
@ -961,6 +957,7 @@ namespace VCSnonideal {
_updateMoleFractionDependencies(); _updateMoleFractionDependencies();
evaluateActCoeff(); evaluateActCoeff();
} }
/************************************************************************************/
// Downloads the ln ActCoeff jacobian into the VCS version of the // Downloads the ln ActCoeff jacobian into the VCS version of the
// ln ActCoeff jacobian. // ln ActCoeff jacobian.
@ -986,7 +983,7 @@ namespace VCSnonideal {
} }
} }
} }
/**********************************************************************/ /************************************************************************************/
// Set the pointer for Cantera's ThermoPhase parameter // Set the pointer for Cantera's ThermoPhase parameter
/* /*
@ -1043,6 +1040,7 @@ namespace VCSnonideal {
m_useCanteraCalls = false; m_useCanteraCalls = false;
} }
} }
/************************************************************************************/
// Return a const ThermoPhase pointer corresponding to this phase // Return a const ThermoPhase pointer corresponding to this phase
/* /*
@ -1051,18 +1049,22 @@ namespace VCSnonideal {
const Cantera::ThermoPhase *vcs_VolPhase::ptrThermoPhase() const { const Cantera::ThermoPhase *vcs_VolPhase::ptrThermoPhase() const {
return TP_ptr; return TP_ptr;
} }
/************************************************************************************/
double vcs_VolPhase::TotalMoles() const { double vcs_VolPhase::TotalMoles() const {
return TMoles; return TMoles;
} }
/************************************************************************************/
double vcs_VolPhase::molefraction(int k) const { double vcs_VolPhase::molefraction(int k) const {
return Xmol[k]; return Xmol[k];
} }
/************************************************************************************/
void vcs_VolPhase::setTotalMoles(double tmols) { void vcs_VolPhase::setTotalMoles(double tmols) {
TMoles = tmols; TMoles = tmols;
} }
/************************************************************************************/
// Return a string representing the equation of state // Return a string representing the equation of state
/* /*

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -324,11 +324,16 @@ namespace VCSnonideal {
* We don't need to call single species phases; * We don't need to call single species phases;
*/ */
if (!Vphase->SingleSpecies && !Vphase->isIdealSoln()) { if (!Vphase->SingleSpecies && !Vphase->isIdealSoln()) {
/*
* update the mole numbers
*/
Vphase->setMolesFromVCS(VCS_STATECALC_OLD, moleSpeciesVCS);
/* /*
* update the Ln Act Coeff jacobian entries with respect to the * update the Ln Act Coeff jacobian entries with respect to the
* mole number of species in the phase * mole number of species in the phase
*/ */
Vphase->updateLnActCoeffJac(moleSpeciesVCS); Vphase->updateLnActCoeffJac();
/* /*
* Download the resulting calculation into the full vector * Download the resulting calculation into the full vector
* -> This scatter calculation is carried out in the * -> This scatter calculation is carried out in the

View file

@ -971,9 +971,7 @@ namespace VCSnonideal {
pubPhase->setMoleFractions(VCS_DATA_PTR(vPhase->moleFractions())); pubPhase->setMoleFractions(VCS_DATA_PTR(vPhase->moleFractions()));
for (int k = 0; k < pubPhase->NVolSpecies; k++) { for (int k = 0; k < pubPhase->NVolSpecies; k++) {
kT = pubPhase->IndSpecies[k]; kT = pubPhase->IndSpecies[k];
//pubPhase->Xmol[k] = vPhase->Xmol[k];
pubPhase->SS0ChemicalPotential[k] = vPhase->SS0ChemicalPotential[k]; pubPhase->SS0ChemicalPotential[k] = vPhase->SS0ChemicalPotential[k];
pubPhase->StarChemicalPotential[k] = vPhase->StarChemicalPotential[k];
pubPhase->StarMolarVol[k] = vPhase->StarMolarVol[k]; pubPhase->StarMolarVol[k] = vPhase->StarMolarVol[k];
pubPhase->PartialMolarVol[k] = vPhase->PartialMolarVol[k]; pubPhase->PartialMolarVol[k] = vPhase->PartialMolarVol[k];
pubPhase->ActCoeff[k] = vPhase->ActCoeff[k]; pubPhase->ActCoeff[k] = vPhase->ActCoeff[k];

View file

@ -1323,6 +1323,8 @@ private:
void vcs_TCounters_report(int timing_print_lvl = 1); void vcs_TCounters_report(int timing_print_lvl = 1);
void vcs_setMoleNumVolPhases(bool upToDate, int stateCalc);
public: public:
//! value of the number of species used to malloc data structures //! value of the number of species used to malloc data structures
int NSPECIES0; int NSPECIES0;

View file

@ -1099,6 +1099,7 @@ namespace VCSnonideal {
* solution values. We only calculate a subset of these, because * solution values. We only calculate a subset of these, because
* we have only updated a subset of the W(). * we have only updated a subset of the W().
*/ */
vcs_setMoleNumVolPhases(false, VCS_STATECALC_NEW);
vcs_updateVP(VCS_STATECALC_NEW); vcs_updateVP(VCS_STATECALC_NEW);
vcs_dfe(VCS_STATECALC_NEW, 0, 0, m_numSpeciesTot); vcs_dfe(VCS_STATECALC_NEW, 0, 0, m_numSpeciesTot);
@ -3273,7 +3274,6 @@ namespace VCSnonideal {
} }
/*****************************************************************************/ /*****************************************************************************/
// This subroutine calculates reaction free energy changes for // This subroutine calculates reaction free energy changes for
// all noncomponent formation reactions. // all noncomponent formation reactions.
/* /*
@ -5361,4 +5361,24 @@ namespace VCSnonideal {
return dx; return dx;
} }
/*******************************************************************************/ /*******************************************************************************/
void VCS_SOLVE::vcs_setMoleNumVolPhases(bool upToDate, int stateCalc) {
int iph;
vcs_VolPhase *Vphase;
if (!upToDate) {
for (iph = 0; iph < m_numPhases; iph++) {
Vphase = m_VolPhaseList[iph];
Vphase->m_UpToDate = false;
}
} else {
for (iph = 0; iph < m_numPhases; iph++) {
Vphase = m_VolPhaseList[iph];
Vphase->m_UpToDate = true;
Vphase->m_vcsStateStatus = stateCalc;
}
}
}
} }

View file

@ -187,7 +187,8 @@ double VCS_SPECIES_THERMO::GStar_R_calc(int kglob, double TKelvin,
if (UseCanteraCalls) { if (UseCanteraCalls) {
AssertThrowVCS(m_VCS_UnitsFormat == VCS_UNITS_MKS, "Possible inconsistency"); AssertThrowVCS(m_VCS_UnitsFormat == VCS_UNITS_MKS, "Possible inconsistency");
int kspec = IndexSpeciesPhase; int kspec = IndexSpeciesPhase;
fe = OwningPhase->GStar_calc_one(kspec, TKelvin, pres); OwningPhase->setState_TP(TKelvin, pres);
fe = OwningPhase->GStar_calc_one(kspec);
double R = vcsUtil_gasConstant(m_VCS_UnitsFormat); double R = vcsUtil_gasConstant(m_VCS_UnitsFormat);
fe /= R; fe /= R;
} else { } else {