From ba490205850670ef7781d92f6c1778901e988d1f Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Mon, 23 Jun 2008 23:40:20 +0000 Subject: [PATCH] vcs_VolPhase: incremental update to make more member data private. --- Cantera/src/equil/vcs_MultiPhaseEquil.cpp | 8 +-- Cantera/src/equil/vcs_VolPhase.cpp | 64 ++++++++++++++++------- Cantera/src/equil/vcs_VolPhase.h | 43 ++++++++++----- Cantera/src/equil/vcs_solve.cpp | 9 ++-- Cantera/src/equil/vcs_solve.h | 4 +- Cantera/src/equil/vcs_solve_TP.cpp | 33 ++++++------ 6 files changed, 100 insertions(+), 61 deletions(-) diff --git a/Cantera/src/equil/vcs_MultiPhaseEquil.cpp b/Cantera/src/equil/vcs_MultiPhaseEquil.cpp index b69702691..88b729c3f 100644 --- a/Cantera/src/equil/vcs_MultiPhaseEquil.cpp +++ b/Cantera/src/equil/vcs_MultiPhaseEquil.cpp @@ -1005,7 +1005,7 @@ namespace VCSnonideal { VolPhase->FormulaMatrix.resize(ne, ns, 0.0); - VolPhase->SpeciesUnknownType.resize(ns, VCS_SPECIES_TYPE_MOLNUM); + VolPhase->m_speciesUnknownType.resize(ns, VCS_SPECIES_TYPE_MOLNUM); VolPhase->ElGlobalIndex.resize(ne, -1); @@ -1055,7 +1055,7 @@ namespace VCSnonideal { */ if (ns == 1) { if (tPhase->charge(0) != 0.0) { - VolPhase->SpeciesUnknownType[0] = VCS_SPECIES_TYPE_INTERFACIALVOLTAGE; + VolPhase->m_speciesUnknownType[0] = VCS_SPECIES_TYPE_INTERFACIALVOLTAGE; VolPhase->m_phiVarIndex = 0; } } @@ -1161,7 +1161,7 @@ namespace VCSnonideal { * Query the ThermoPhase object to find out what convention * it uses for the specification of activity and Standard State. */ - VolPhase->ActivityConvention = tPhase->activityConvention(); + VolPhase->m_activityConvention = tPhase->activityConvention(); /* * Assign the value of eqn of state * -> Handle conflicts here. @@ -1266,7 +1266,7 @@ namespace VCSnonideal { /* * Transfer the type of unknown */ - vprob->SpeciesUnknownType[kT] = VolPhase->SpeciesUnknownType[k]; + vprob->SpeciesUnknownType[kT] = VolPhase->m_speciesUnknownType[k]; /* * Transfer the species information from the * volPhase structure to the VPROB structure diff --git a/Cantera/src/equil/vcs_VolPhase.cpp b/Cantera/src/equil/vcs_VolPhase.cpp index 77615bd8f..dff1edc6c 100644 --- a/Cantera/src/equil/vcs_VolPhase.cpp +++ b/Cantera/src/equil/vcs_VolPhase.cpp @@ -42,12 +42,12 @@ namespace VCSnonideal { NVolSpecies(0), TMolesInert(0.0), m_molarVolInert(1000.), - ActivityConvention(0), + m_activityConvention(0), m_isIdealSoln(false), Existence(0), + m_MFStartIndex(0), IndexSpecialSpecies(-1), Activity_Coeff_Model(VCS_AC_CONSTANT), - Activity_Coeff_Params(0), IndSpecies(0), IndSpeciesContig(true), m_VCS_UnitsFormat(VCS_UNITS_MKS), @@ -104,12 +104,12 @@ namespace VCSnonideal { ChargeNeutralityElement(b.ChargeNeutralityElement), NVolSpecies(b.NVolSpecies), TMolesInert(b.TMolesInert), - ActivityConvention(b.ActivityConvention), + m_activityConvention(b.m_activityConvention), m_isIdealSoln(b.m_isIdealSoln), Existence(b.Existence), + m_MFStartIndex(b.m_MFStartIndex), IndexSpecialSpecies(b.IndexSpecialSpecies), Activity_Coeff_Model(b.Activity_Coeff_Model), - Activity_Coeff_Params(b.Activity_Coeff_Params), IndSpeciesContig(b.IndSpeciesContig), m_VCS_UnitsFormat(b.m_VCS_UnitsFormat), m_useCanteraCalls(b.m_useCanteraCalls), @@ -176,21 +176,21 @@ namespace VCSnonideal { } } - SpeciesUnknownType = b.SpeciesUnknownType; + m_speciesUnknownType = b.m_speciesUnknownType; ElGlobalIndex = b.ElGlobalIndex; NVolSpecies = b.NVolSpecies; PhaseName = b.PhaseName; TMolesInert = b.TMolesInert; - ActivityConvention = b.ActivityConvention; + m_activityConvention = b.m_activityConvention; m_isIdealSoln = b.m_isIdealSoln; Existence = b.Existence; + m_MFStartIndex = b.m_MFStartIndex; IndexSpecialSpecies = b.IndexSpecialSpecies; Activity_Coeff_Model = b.Activity_Coeff_Model; /* * Do a shallow copy because we haven' figured this out. */ - Activity_Coeff_Params = b.Activity_Coeff_Params; IndSpecies = b.IndSpecies; IndSpeciesContig = b.IndSpeciesContig; @@ -325,7 +325,7 @@ namespace VCSnonideal { dLnActCoeffdMolNumber.resize(nspecies, nspecies, 0.0); - SpeciesUnknownType.resize(nspecies, VCS_SPECIES_TYPE_MOLNUM); + m_speciesUnknownType.resize(nspecies, VCS_SPECIES_TYPE_MOLNUM); m_UpToDate = false; m_vcsStateStatus = VCS_STATECALC_OLD; m_UpToDate_AC = false; @@ -339,6 +339,8 @@ namespace VCSnonideal { /*! * We carry out a calculation whenever UpTODate_AC is false. Specifically * whenever a phase goes zero, we do not carry out calculations on it. + * + * (private) */ void vcs_VolPhase::_updateActCoeff() const { if (m_isIdealSoln) { @@ -372,7 +374,7 @@ namespace VCSnonideal { * one. */ double vcs_VolPhase::AC_calc_one(int kspec) const { - if (! m_UpToDate_AC) { + if (! m_UpToDate_AC) { _updateActCoeff(); } return(ActCoeff[kspec]); @@ -490,7 +492,7 @@ namespace VCSnonideal { m_UpToDate = false; m_vcsStateStatus = VCS_STATECALC_TMP; } - /***********************************************************************/ + /****************************************************************************/ // Updates the mole fractions in subobjects /* @@ -500,7 +502,7 @@ namespace VCSnonideal { void vcs_VolPhase::_updateMoleFractionDependencies() { if (m_useCanteraCalls) { if (TP_ptr) { - TP_ptr->setState_PX(Pres, VCS_DATA_PTR(Xmol)); + TP_ptr->setState_PX(Pres, &(Xmol[m_MFStartIndex])); } } if (!m_isIdealSoln) { @@ -508,13 +510,13 @@ namespace VCSnonideal { m_UpToDate_VolPM = false; } } - /************************************************************************/ + /****************************************************************************/ // Return a const reference to the mole fraction vector in the phase const std::vector & vcs_VolPhase::moleFractions() const { return Xmol; } - /***********************************************************************/ + /****************************************************************************/ // Set the moles within the phase /* @@ -573,14 +575,14 @@ namespace VCSnonideal { #endif for (int k = 0; k < NVolSpecies; k++) { - if (SpeciesUnknownType[k] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) { + if (m_speciesUnknownType[k] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) { kglob = IndSpecies[k]; v_totalMoles += MAX(0.0, molesSpeciesVCS[kglob]); } } if (v_totalMoles > 0.0) { for (int k = 0; k < NVolSpecies; k++) { - if (SpeciesUnknownType[k] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) { + if (m_speciesUnknownType[k] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) { kglob = IndSpecies[k]; tmp = MAX(0.0, molesSpeciesVCS[kglob]); Xmol[k] = tmp / v_totalMoles; @@ -624,7 +626,7 @@ namespace VCSnonideal { m_vcsStateStatus = stateCalc; } - /**************************************************************************/ + /******************************************************************************/ // Set the moles within the phase /* @@ -657,7 +659,7 @@ namespace VCSnonideal { } } } - /**************************************************************************/ + /******************************************************************************/ // Update the moles within the phase, if necessary /* @@ -716,7 +718,7 @@ namespace VCSnonideal { * in all of the phases in a VCS problem. Only the * entries for the current phase are filled in. */ - double vcs_VolPhase::sendToVCS_VolPM(double * const VolPM) const { + double vcs_VolPhase::sendToVCS_VolPM(double * const VolPM) const { if (!m_UpToDate_VolPM) { (void) _updateVolPM(); } @@ -752,7 +754,7 @@ namespace VCSnonideal { /****************************************************************************/ - void vcs_VolPhase::setElectricPotential(double phi) { + void vcs_VolPhase::setElectricPotential(const double phi) { m_phi = phi; if (m_useCanteraCalls) { TP_ptr->setElectricPotential(m_phi); @@ -1080,6 +1082,30 @@ namespace VCSnonideal { } /************************************************************************************/ + // Sets the mole flag within the object to out of date + /* + * This will trigger the object to go get the current mole numbers + * when it needs it. + */ + void vcs_VolPhase::setMolesOutOfDate(int stateCalc) { + m_UpToDate = false; + if (stateCalc != -1) { + m_vcsStateStatus = stateCalc; + } + } + /************************************************************************************/ + + // Sets the mole flag within the object to be current + /* + * + */ + void vcs_VolPhase::setMolesCurrent(int stateCalc) { + m_UpToDate = true; + m_vcsStateStatus = stateCalc; + } + /************************************************************************************/ + + // Return a string representing the equation of state /* * The string is no more than 16 characters. diff --git a/Cantera/src/equil/vcs_VolPhase.h b/Cantera/src/equil/vcs_VolPhase.h index 431a2c226..ffec88d12 100644 --- a/Cantera/src/equil/vcs_VolPhase.h +++ b/Cantera/src/equil/vcs_VolPhase.h @@ -223,7 +223,7 @@ namespace VCSnonideal { /*! * @param phi electric potential (volts) */ - void setElectricPotential(double phi); + void setElectricPotential(const double phi); //! Returns the electric field of the phase /*! @@ -368,6 +368,19 @@ namespace VCSnonideal { */ void setTotalMoles(double totalMols); + //! Sets the mole flag within the object to out of date + /*! + * This will trigger the object to go get the current mole numbers + * when it needs it. + */ + void setMolesOutOfDate(int stateCalc = -1); + + //! Sets the mole flag within the object to be current + /*! + * + */ + void setMolesCurrent(int stateCalc); + //! Set the mole fractions from a conventional mole fraction vector /*! * @@ -546,7 +559,7 @@ namespace VCSnonideal { * metal electron -> VCS_SPECIES_INTERFACIALVOLTAGE * ( unknown is the interfacial voltage (volts) */ - std::vector SpeciesUnknownType; + std::vector m_speciesUnknownType; //! Index of the element number in the global list of elements //! storred in VCS_PROB or VCS_SOLVE @@ -574,7 +587,7 @@ namespace VCSnonideal { * mu = mu_0 + ln a_molality * standard state is based on unity molality */ - int ActivityConvention; + int m_activityConvention; //! Boolean indicating whether the phase is an ideal solution //! and therefore it's molar-based activity coefficients are @@ -589,8 +602,20 @@ namespace VCSnonideal { * inerts which can't exist in any other * phase */ - int Existence; + int Existence; + private: + // Index of the first MF species in the list of unknowns for this phase + /*! + * This is always equal to zero. + * Am anticipating the case where the phase potential is species # 0, + * for multiphase phases. Right now we have the phase potential equal + * to 0 for single species phases, where we set by hand the mole fraction + * of species 0 to one. + */ + int m_MFStartIndex; + + public: //! Index of the species which is special in //! with respect to the thermo treatment. /*! @@ -606,11 +631,6 @@ namespace VCSnonideal { */ int Activity_Coeff_Model; - //! General pointer for hanging stuff off of - /*! - * Currently, not implemented very well - */ - void *Activity_Coeff_Params; //! Index into the species vectors /*! @@ -728,6 +748,7 @@ namespace VCSnonideal { */ mutable std::vector ActCoeff; + private: //! Vector of the derivatives of the ln activity coefficient wrt to the //! current mole number /*! @@ -737,7 +758,6 @@ namespace VCSnonideal { */ mutable DoubleStarStar dLnActCoeffdMolNumber; - //! Status /*! * valid values are @@ -746,17 +766,14 @@ namespace VCSnonideal { */ int m_vcsStateStatus; - private: //! Value of the potential for the phase (Volts) double m_phi; - public: //! Boolean indicating whether the object has an uptodate mole number vector //! and potential with respect to the current vcs state calc status bool m_UpToDate; - private: //! Boolean indicating whether activity coefficients are uptodate. /*! * Activity coefficients and volume calculations are lagged. They are only diff --git a/Cantera/src/equil/vcs_solve.cpp b/Cantera/src/equil/vcs_solve.cpp index 8426bd663..05a417920 100644 --- a/Cantera/src/equil/vcs_solve.cpp +++ b/Cantera/src/equil/vcs_solve.cpp @@ -735,8 +735,8 @@ namespace VCSnonideal { */ for (iph = 0; iph < nph; iph++) { Vphase = m_VolPhaseList[iph]; - m_phaseActConvention[iph] = Vphase->ActivityConvention; - if (Vphase->ActivityConvention != 0) { + m_phaseActConvention[iph] = Vphase->m_activityConvention; + if (Vphase->m_activityConvention != 0) { /* * We assume here that species 0 is the solvent. * The solvent isn't on a unity activity basis @@ -750,7 +750,7 @@ namespace VCSnonideal { double mnaught = m_wtSpecies[iSolvent] / 1000.; for (int k = 1; k < Vphase->NVolSpecies; k++) { int kspec = Vphase->IndSpecies[k]; - m_actConventionSpecies[kspec] = Vphase->ActivityConvention; + m_actConventionSpecies[kspec] = Vphase->m_activityConvention; m_lnMnaughtSpecies[kspec] = log(mnaught); } } @@ -985,13 +985,12 @@ namespace VCSnonideal { } } - 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); } - if (pubPhase->SpeciesUnknownType[k] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) { + if (pubPhase->m_speciesUnknownType[k] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) { sumMoles += pub->w[kT]; } } diff --git a/Cantera/src/equil/vcs_solve.h b/Cantera/src/equil/vcs_solve.h index a3936a107..385dbbe47 100644 --- a/Cantera/src/equil/vcs_solve.h +++ b/Cantera/src/equil/vcs_solve.h @@ -1031,7 +1031,7 @@ private: * 1: succeeded * 0: failed. */ - int zero_species(const int kspec); + int vcs_zero_species(const int kspec); //! Change a single species from active to inactive status /*! @@ -1047,7 +1047,7 @@ private: * noncomponent species is equal to zero. A recheck of deleted species * is carried out in the main code. */ - int delete_species(const int kspec); + int vcs_delete_species(const int kspec); //! This routine handles the bookkeepking involved with the //! deletion of multiphase phases from the problem. diff --git a/Cantera/src/equil/vcs_solve_TP.cpp b/Cantera/src/equil/vcs_solve_TP.cpp index 3a5cb4223..5ab5bcb7b 100644 --- a/Cantera/src/equil/vcs_solve_TP.cpp +++ b/Cantera/src/equil/vcs_solve_TP.cpp @@ -733,7 +733,7 @@ namespace VCSnonideal { * branch to the code where we reevaluate the deletion * of all species. */ - lnospec = delete_species(kspec); + lnospec = vcs_delete_species(kspec); if (lnospec) goto L_RECHECK_DELETED; /* * Go back to consider the next species in the list. @@ -2218,7 +2218,7 @@ namespace VCSnonideal { * 1: succeeded * 0: failed. */ - int VCS_SOLVE::zero_species(const int kspec) { + int VCS_SOLVE::vcs_zero_species(const int kspec) { int retn = 1; /* * Calculate a delta that will eliminate the species. @@ -2230,7 +2230,7 @@ namespace VCSnonideal { #ifdef DEBUG_MODE if (!retn) { if (m_debug_print_lvl >= 1) { - plogf("zero_species: Couldn't zero the species %d, " + plogf("vcs_zero_species: Couldn't zero the species %d, " "did delta of %g. orig conc of %g", kspec, dx, m_molNumSpecies_old[kspec] + dx); plogendl(); @@ -2257,7 +2257,7 @@ namespace VCSnonideal { * noncomponent species is equal to zero. A recheck of deleted species * is carried out in the main code. */ - int VCS_SOLVE::delete_species(const int kspec) { + int VCS_SOLVE::vcs_delete_species(const int kspec) { const int klast = m_numSpeciesRdc - 1; const int iph = m_phaseID[kspec]; vcs_VolPhase * const Vphase = m_VolPhaseList[iph]; @@ -2266,7 +2266,7 @@ namespace VCSnonideal { * Zero the concentration of the species. * -> This zeroes w[kspec] and modifies m_tPhaseMoles_old[] */ - const int retn = zero_species(kspec); + const int retn = vcs_zero_species(kspec); #ifdef DEBUG_MODE if (! retn) { plogf("Failed to delete a species!"); @@ -4693,12 +4693,12 @@ namespace VCSnonideal { /* * Calculate activity coefficients for all phases that are - * not current + * not current. Here we also trigger an update check for each + * VolPhase to see if its mole numbers are current with vcs */ for (iphase = 0; iphase < m_numPhases; iphase++) { Vphase = m_VolPhaseList[iphase]; if (!Vphase->SingleSpecies) { - // Vphase->setMolesFromVCS(stateCalc, molNum); Vphase->sendToVCS_ActCoeff(stateCalc, VCS_DATA_PTR(actCoeff_ptr)); } m_phasePhi[iphase] = Vphase->electricPotential(); @@ -5386,14 +5386,13 @@ namespace VCSnonideal { vcs_VolPhase *Vphase; if (!upToDate) { for (iph = 0; iph < m_numPhases; iph++) { - Vphase = m_VolPhaseList[iph]; - Vphase->m_UpToDate = false; + Vphase = m_VolPhaseList[iph]; + Vphase->setMolesOutOfDate(stateCalc); } } else { for (iph = 0; iph < m_numPhases; iph++) { - Vphase = m_VolPhaseList[iph]; - Vphase->m_UpToDate = true; - Vphase->m_vcsStateStatus = stateCalc; + Vphase = m_VolPhaseList[iph]; + Vphase->setMolesCurrent(stateCalc); } } } @@ -5401,14 +5400,11 @@ namespace VCSnonideal { void VCS_SOLVE::vcs_setFlagsVolPhase(const int iph, const bool upToDate, const int stateCalc) { - vcs_VolPhase *Vphase; + vcs_VolPhase *Vphase = m_VolPhaseList[iph]; if (!upToDate) { - Vphase = m_VolPhaseList[iph]; - Vphase->m_UpToDate = false; + Vphase->setMolesOutOfDate(stateCalc); } else { - Vphase = m_VolPhaseList[iph]; - Vphase->m_UpToDate = true; - Vphase->m_vcsStateStatus = stateCalc; + Vphase->setMolesCurrent(stateCalc); } } /*******************************************************************************/ @@ -5421,5 +5417,6 @@ namespace VCSnonideal { Vphase->updateFromVCS_MoleNumbers(stateCalc); } } + /*******************************************************************************/ }