changed interface to vcs_volPhase to better conform to Cantera standards.

Added the VCS_STATECALC_PHASESTABILITY flag
This commit is contained in:
Harry Moffat 2008-10-23 16:48:37 +00:00
parent 64287bbc73
commit 3ec48ac574
7 changed files with 59 additions and 37 deletions

View file

@ -765,7 +765,7 @@ namespace VCSnonideal {
tref.getPartialMolarVolumes(VCS_DATA_PTR(VolPM));
vcs_VolPhase *volP = m_vprob->VPhaseList[iphase];
double TMolesPhase = volP->TotalMoles();
double TMolesPhase = volP->totalMoles();
double VolPhaseVolumes = 0.0;
for (k = 0; k < nSpecies; k++) {
VolPhaseVolumes += VolPM[k] * mf[istart + k];
@ -788,7 +788,7 @@ namespace VCSnonideal {
Cantera::ThermoPhase *tp = &tref;
string phaseName = tref.name();
vcs_VolPhase *volP = m_vprob->VPhaseList[iphase];
double TMolesPhase = volP->TotalMoles();
double TMolesPhase = volP->totalMoles();
//AssertTrace(TMolesPhase == m_mix->phaseMoles(iphase));
nSpecies = tref.nSpecies();
activity.resize(nSpecies, 0.0);
@ -1270,7 +1270,7 @@ namespace VCSnonideal {
VolPhase->VP_ID, VolPhase->m_singleSpecies,
VolPhase->m_gasPhase, sEOS.c_str(),
VolPhase->nSpecies(), VolPhase->totalMolesInert() );
plogf("%16e\n", VolPhase->TotalMoles());
plogf("%16e\n", VolPhase->totalMoles());
}
plogf("\n"); print_char('=', 80); plogf("\n");
@ -1338,7 +1338,7 @@ namespace VCSnonideal {
vprob->w[kglob] = tPhase->electricPotential();
}
volPhase->setMolesFromVCS(VCS_STATECALC_OLD, VCS_DATA_PTR(vprob->w));
if (volPhase->TotalMoles() > 0.0) {
if (volPhase->totalMoles() > 0.0) {
volPhase->setExistence(1);
} else {
volPhase->setExistence(0);
@ -1389,7 +1389,7 @@ namespace VCSnonideal {
VolPhase->VP_ID, VolPhase->m_singleSpecies,
VolPhase->m_gasPhase, sEOS.c_str(),
VolPhase->nSpecies(), VolPhase->totalMolesInert() );
plogf("%16e\n", VolPhase->TotalMoles() );
plogf("%16e\n", VolPhase->totalMoles() );
}
plogf("\n"); print_char('=', 80); plogf("\n");

View file

@ -522,13 +522,15 @@ namespace VCSnonideal {
const int vcsStateStatus) {
if (totalMoles != 0.0) {
if (vcsStateStatus != VCS_STATECALC_TMP) {
// There are other ways to set the mole fractions when VCS_STATECALC
// is set to a normal settting.
if (vcsStateStatus != VCS_STATECALC_TMP) {
printf("vcs_VolPhase::setMolesFractionsState: inappropriate usage\n");
std::exit(-1);
}
m_UpToDate = false;
m_vcsStateStatus = VCS_STATECALC_TMP;
if (m_existence == -VCS_PHASE_EXIST_ZEROEDPHASE ) {
if (m_existence == VCS_PHASE_EXIST_ZEROEDPHASE ) {
printf("vcs_VolPhase::setMolesFractionsState: inappropriate usage\n");
std::exit(-1);
}
@ -540,6 +542,7 @@ namespace VCSnonideal {
m_existence = VCS_PHASE_EXIST_NO;
}
}
v_totalMoles = totalMoles;
double sum = 0.0;
for (int k = 0; k < m_numSpecies; k++) {
Xmol[k] = moleFractions[k];
@ -675,17 +678,20 @@ namespace VCSnonideal {
* then updates this object with their values. This is essentially
* a gather routine.
*
*
* @param vcsStateStatus State calc value either VCS_STATECALC_OLD
* or VCS_STATECALC_NEW. With any other value
* nothing is done.
*
* @param molesSpeciesVCS array of mole numbers. Note,
* the indecises for species in
* this array may not be contiguous. IndSpecies[] is needed
* to gather the species into the local contiguous vector
* format.
*/
void vcs_VolPhase::setMolesFromVCSCheck(const int stateCalc,
void vcs_VolPhase::setMolesFromVCSCheck(const int vcsStateStatus,
const double * molesSpeciesVCS,
const double * const TPhMoles) {
setMolesFromVCS(stateCalc, molesSpeciesVCS);
setMolesFromVCS(vcsStateStatus, molesSpeciesVCS);
/*
* Check for consistency with TPhMoles[]
*/
@ -710,16 +716,16 @@ namespace VCSnonideal {
* It then updates this object with their values. This is essentially
* a gather routine.
*
* @param stateCalc State calc value either VCS_STATECALC_OLD
* or VCS_STATECALC_NEW. With any other value
* nothing is done.
* @param vcsStateStatus State calc value either VCS_STATECALC_OLD
* or VCS_STATECALC_NEW. With any other value
* nothing is done.
*
*/
void vcs_VolPhase::updateFromVCS_MoleNumbers(const int stateCalc) {
if (!m_UpToDate || (stateCalc != m_vcsStateStatus)) {
if (stateCalc == VCS_STATECALC_OLD || stateCalc == VCS_STATECALC_NEW) {
void vcs_VolPhase::updateFromVCS_MoleNumbers(const int vcsStateStatus) {
if (!m_UpToDate || (vcsStateStatus != m_vcsStateStatus)) {
if (vcsStateStatus == VCS_STATECALC_OLD || vcsStateStatus == VCS_STATECALC_NEW) {
if (m_owningSolverObject) {
setMolesFromVCS(stateCalc);
setMolesFromVCS(vcsStateStatus);
}
}
}
@ -736,9 +742,9 @@ namespace VCSnonideal {
* in all of the phases in a VCS problem. Only the
* entries for the current phase are filled in.
*/
void vcs_VolPhase::sendToVCS_ActCoeff(const int stateCalc,
void vcs_VolPhase::sendToVCS_ActCoeff(const int vcsStateStatus,
double * const AC) {
updateFromVCS_MoleNumbers(stateCalc);
updateFromVCS_MoleNumbers(vcsStateStatus);
if (!m_UpToDate_AC) {
_updateActCoeff();
}
@ -1126,7 +1132,7 @@ namespace VCSnonideal {
}
/***************************************************************************/
double vcs_VolPhase::TotalMoles() const {
double vcs_VolPhase::totalMoles() const {
return v_totalMoles;
}
/***************************************************************************/

View file

@ -158,6 +158,15 @@ namespace VCSnonideal {
*/
double AC_calc_one(int kspec) const;
//! Set the moles and/or mole fractions within the phase
/*!
* Sets the mole fraction and total moles within the phase
*
* @param molNum total moles in the phase
* @param moleFracVec Vector of input mole fractions
* @param vcsStateStatus Status flag for this update
*/
void setMoleFractionsState(const double molNum, const double * const moleFracVec,
const int vcsStateStatus);
@ -362,7 +371,7 @@ namespace VCSnonideal {
* Units -> depends on VCS_UnitsFormat variable
* Cantera -> J/kmol
*/
double TotalMoles() const;
double totalMoles() const;
//! Returns the mole fraction of the kspec species
/*!
@ -390,9 +399,9 @@ namespace VCSnonideal {
//! Sets the mole flag within the object to be current
/*!
*
*
*/
void setMolesCurrent(int stateCalc);
void setMolesCurrent(int vcsStateStatus);
private:
//! Set the mole fractions from a conventional mole fraction vector
@ -404,7 +413,9 @@ namespace VCSnonideal {
void setMoleFractions(const double * const xmol);
public:
//! Return a const reference to the mole fractions
//! Return a const reference to the mole fractions storred in the
//! object.
const std::vector<double> & moleFractions() const;
//! Returns whether the phase is an ideal solution phase

View file

@ -334,8 +334,13 @@ namespace VCSnonideal {
//! State Calculation based on the new or tentative mole numbers
#define VCS_STATECALC_NEW 1
//! State Calculation based on tentative mole numbers
//! for a phase which is currently zeroed, but is being
//! evaluated for whether it should pop back into existence
#define VCS_STATECALC_PHASESTABILITY 2
//! State Calculation based on a temporary set of mole numbers
#define VCS_STATECALC_TMP 2
#define VCS_STATECALC_TMP 3
//@}

View file

@ -286,7 +286,7 @@ namespace VCSnonideal {
Vphase->VP_ID, Vphase->m_singleSpecies, Vphase->m_gasPhase);
plogf("%16s %8d %16e ", EOS_cstr.c_str(),
Vphase->nSpecies(), Vphase->totalMolesInert());
if (iest >= 0) plogf("%16e\n", Vphase->TotalMoles());
if (iest >= 0) plogf("%16e\n", Vphase->totalMoles());
else plogf(" N/A\n");
}
@ -493,7 +493,7 @@ namespace VCSnonideal {
volPM.resize(nSpeciesPhase, 0.0);
volP->sendToVCS_VolPM(VCS_DATA_PTR(volPM));
double TMolesPhase = volP->TotalMoles();
double TMolesPhase = volP->totalMoles();
double VolPhaseVolumes = 0.0;
for (k = 0; k < nSpeciesPhase; k++) {
iK++;
@ -520,7 +520,7 @@ namespace VCSnonideal {
string phaseName = volP->PhaseName;
int nSpeciesPhase = volP->nSpecies();
volP->sendToVCS_VolPM(VCS_DATA_PTR(volPM));
double TMolesPhase = volP->TotalMoles();
double TMolesPhase = volP->totalMoles();
//AssertTrace(TMolesPhase == m_mix->phaseMoles(iphase));
activity.resize(nSpeciesPhase, 0.0);
ac.resize(nSpeciesPhase, 0.0);

View file

@ -257,8 +257,8 @@ namespace VCSnonideal {
plogf("%-12.12s |",VPhase->PhaseName.c_str());
plogf("%10.3e |", m_tPhaseMoles_old[iphase]*molScale);
totalMoles += m_tPhaseMoles_old[iphase];
if (m_tPhaseMoles_old[iphase] != VPhase->TotalMoles()) {
if (! vcs_doubleEqual(m_tPhaseMoles_old[iphase], VPhase->TotalMoles())) {
if (m_tPhaseMoles_old[iphase] != VPhase->totalMoles()) {
if (! vcs_doubleEqual(m_tPhaseMoles_old[iphase], VPhase->totalMoles())) {
plogf("We have a problem\n");
exit(-1);
}

View file

@ -982,10 +982,10 @@ namespace VCSnonideal {
vcs_VolPhase *pubPhase = pub->VPhaseList[iph];
vcs_VolPhase *vPhase = m_VolPhaseList[iph];
pubPhase->setTotalMolesInert(vPhase->totalMolesInert());
pubPhase->setTotalMoles(vPhase->TotalMoles());
pubPhase->setTotalMoles(vPhase->totalMoles());
pubPhase->setElectricPotential(vPhase->electricPotential());
double sumMoles = pubPhase->totalMolesInert();
pubPhase->setMoleFractionsState(vPhase->TotalMoles(),
pubPhase->setMoleFractionsState(vPhase->totalMoles(),
VCS_DATA_PTR(vPhase->moleFractions()),
VCS_STATECALC_TMP);
const std::vector<double> & mfVector = pubPhase->moleFractions();
@ -998,23 +998,23 @@ namespace VCSnonideal {
if (! vcs_doubleEqual( pubPhase->electricPotential() , tmp)) {
plogf("We have an inconsistency in voltage, %g, %g\n",
pubPhase->electricPotential(), tmp);
exit(-1);
std::exit(-1);
}
}
if (! vcs_doubleEqual( pub->mf[kT], vPhase->molefraction(k))) {
plogf("We have an inconsistency in mole fraction, %g, %g\n",
pub->mf[kT], vPhase->molefraction(k));
exit(-1);
std::exit(-1);
}
if (pubPhase->speciesUnknownType(k) != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
sumMoles += pub->w[kT];
}
}
if (! vcs_doubleEqual(sumMoles, vPhase->TotalMoles())) {
if (! vcs_doubleEqual(sumMoles, vPhase->totalMoles())) {
plogf("We have an inconsistency in total moles, %g %g\n",
sumMoles, pubPhase->TotalMoles());
exit(-1);
sumMoles, pubPhase->totalMoles());
std::exit(-1);
}
}