Clean up comments in VCS equilibrium solver

This commit is contained in:
Ray Speth 2015-10-19 20:01:51 -04:00
parent 4382ae6c85
commit 618c485c55
27 changed files with 2365 additions and 3353 deletions

View file

@ -14,33 +14,33 @@ namespace Cantera
//! Translate a MultiPhase object into a VCS_PROB problem definition object
/*!
* @param mphase MultiPhase object that is the source for all of the information
* @param vprob VCS_PROB problem definition that gets all of the information
* @param mphase MultiPhase object that is the source for all of the information
* @param vprob VCS_PROB problem definition that gets all of the information
*
* Note, both objects share the underlying ThermoPhase objects. So, neither
* can be const objects.
* Note, both objects share the underlying ThermoPhase objects. So, neither can
* be const objects.
*/
int vcs_Cantera_to_vprob(MultiPhase* mphase, VCS_PROB* vprob);
//! Translate a MultiPhase information into a VCS_PROB problem definition object
/*!
* This version updates the problem statement information only. All species and
* phase definitions remain the same.
* This version updates the problem statement information only. All species and
* phase definitions remain the same.
*
* @param mphase MultiPhase object that is the source for all of the information
* @param vprob VCS_PROB problem definition that gets all of the information
* @param mphase MultiPhase object that is the source for all of the information
* @param vprob VCS_PROB problem definition that gets all of the information
*/
int vcs_Cantera_update_vprob(MultiPhase* mphase, VCS_PROB* vprob);
//! %Cantera's Interface to the Multiphase chemical equilibrium solver.
/*!
* Class vcs_MultiPhaseEquil is designed to be used to set a mixture
* containing one or more phases to a state of chemical equilibrium.
* Class vcs_MultiPhaseEquil is designed to be used to set a mixture containing
* one or more phases to a state of chemical equilibrium.
*
* Note, as currently constructed, the underlying ThermoPhase objects are
* shared between the MultiPhase object and this object. Therefore, mix is not
* a const argument, and the return parameters are contained in underlying
* ThermoPhase objects.
* Note, as currently constructed, the underlying ThermoPhase objects are shared
* between the MultiPhase object and this object. Therefore, mix is not a const
* argument, and the return parameters are contained in underlying ThermoPhase
* objects.
*
* @ingroup equilfunctions
*/
@ -74,25 +74,22 @@ public:
//! Return the index of the ith component
/*!
* Returns the index of the ith component in the equilibrium
* calculation. The index refers to the ordering of the species
* in the MultiPhase object.
* Returns the index of the ith component in the equilibrium calculation.
* The index refers to the ordering of the species in the MultiPhase object.
*
* @param m Index of the component. Must be between 0 and the
* number of components, which can be obtained from the
* numComponents() command.
* @param m Index of the component. Must be between 0 and the number of
* components, which can be obtained from the numComponents() command.
*/
size_t component(size_t m) const;
//! Get the stoichiometric reaction coefficients for a single
//! reaction index
/*!
* This returns a stoichiometric reaction vector for a single
* formation reaction for a noncomponent species. There are
* (nSpecies() - nComponents) formation reactions. Each
* formation reaction will have a value of 1.0 for the species
* that is being formed, and the other non-zero coefficients will
* all involve the components of the mixture.
* This returns a stoichiometric reaction vector for a single formation
* reaction for a noncomponent species. There are (nSpecies() - nComponents)
* formation reactions. Each formation reaction will have a value of 1.0 for
* the species that is being formed, and the other non-zero coefficients
* will all involve the components of the mixture.
*
* @param rxn Reaction number.
* @param nu Vector of coefficients for the formation reaction. Length is
@ -108,24 +105,24 @@ public:
//! Equilibrate the solution using the current element abundances
//! stored in the MultiPhase object
/*!
* Use the vcs algorithm to equilibrate the current multiphase mixture.
* Use the vcs algorithm to equilibrate the current multiphase mixture.
*
* @param XY Integer representing what two thermo quantities are
* held constant during the equilibration
* @param estimateEquil integer indicating whether the solver should
* estimate its own initial condition.
* - If 0, the initial mole fraction vector in the
* ThermoPhase object is used as the initial condition.
* - If 1, the initial mole fraction vector is used if
* the element abundances are satisfied.
* - if -1, the initial mole fraction vector is thrown
* out, and an estimate is formulated.
* @param printLvl Determines the amount of printing that gets sent to
* stdout from the vcs package (Note, you may have to
* compile with debug flags to get some printing).
* @param err Internal error level
* @param maxsteps max steps allowed.
* @param loglevel Determines the amount of printing to the output file.
* @param XY Integer representing what two thermo quantities are
* held constant during the equilibration
* @param estimateEquil integer indicating whether the solver should
* estimate its own initial condition.
* - If 0, the initial mole fraction vector in the ThermoPhase object is
* used as the initial condition.
* - If 1, the initial mole fraction vector is used if the element
* abundances are satisfied.
* - if -1, the initial mole fraction vector is thrown out, and an
* estimate is formulated.
* @param printLvl Determines the amount of printing that gets sent to
* stdout from the vcs package (Note, you may have to compile with debug
* flags to get some printing).
* @param err Internal error level
* @param maxsteps max steps allowed.
* @param loglevel Determines the amount of printing to the output file.
*/
int equilibrate(int XY, int estimateEquil = 0,
int printLvl= 0, doublereal err = 1.0e-6,
@ -134,22 +131,22 @@ public:
//! Equilibrate the solution using the current element abundances
//! stored in the MultiPhase object using constant T and P
/*!
* Use the vcs algorithm to equilibrate the current multiphase mixture.
* Use the vcs algorithm to equilibrate the current multiphase mixture.
*
* @param estimateEquil integer indicating whether the solver should
* estimate its own initial condition.
* - If 0, the initial mole fraction vector in the
* ThermoPhase object is used as the initial condition.
* - If 1, the initial mole fraction vector is used if the
* element abundances are satisfied.
* - if -1, the initial mole fraction vector is thrown
* out, and an estimate is formulated.
* @param printLvl Determines the amount of printing that gets sent to
* stdout from the vcs package (Note, you may have to
* compile with debug flags to get some printing).
* @param err Internal error level
* @param maxsteps max steps allowed.
* @param loglevel Determines the amount of printing to the output file.
* @param estimateEquil integer indicating whether the solver should
* estimate its own initial condition.
* - If 0, the initial mole fraction vector in the ThermoPhase object is
* used as the initial condition.
* - If 1, the initial mole fraction vector is used if the element
* abundances are satisfied.
* - if -1, the initial mole fraction vector is thrown out, and an
* estimate is formulated.
* @param printLvl Determines the amount of printing that gets sent to
* stdout from the vcs package (Note, you may have to compile with debug
* flags to get some printing).
* @param err Internal error level
* @param maxsteps max steps allowed.
* @param loglevel Determines the amount of printing to the output file.
*/
int equilibrate_TP(int estimateEquil = 0,
int printLvl= 0, doublereal err = 1.0e-6,
@ -159,71 +156,69 @@ public:
//! stored in the MultiPhase object using either constant H and P
//! or constant U and P.
/*!
* Use the vcs algorithm to equilibrate the current multiphase
* mixture. The pressure of the calculation is taken from
* the current pressure stored with the MultiPhase object.
* Use the vcs algorithm to equilibrate the current multiphase mixture. The
* pressure of the calculation is taken from the current pressure stored
* with the MultiPhase object.
*
* @param Htarget Value of the total mixture enthalpy or total internal
* energy that will be kept constant. Note, this is and
* must be an extensive quantity. units = Joules
* @param XY Integer flag indicating what is held constant.
* Must be either HP or UP.
* @param Tlow Lower limit of the temperature. It's an error condition
* if the temperature falls below Tlow.
* @param Thigh Upper limit of the temperature. It's an error condition
* if the temperature goes higher than Thigh.
* @param estimateEquil integer indicating whether the solver
* should estimate its own initial condition.
* - If 0, the initial mole fraction vector in the
* ThermoPhase object is used as the initial condition.
* - If 1, the initial mole fraction vector is used if the
* element abundances are satisfied.
* - if -1, the initial mole fraction vector is thrown
* out, and an estimate is formulated.
* @param printLvl Determines the amount of printing that
* gets sent to stdout from the vcs package
* (Note, you may have to compile with debug
* flags to get some printing). See main
* constructor call for meaning of the levels.
* @param err Internal error level
* @param maxsteps max steps allowed.
* @param loglevel Determines the amount of printing to the output file.
* @param Htarget Value of the total mixture enthalpy or total internal
* energy that will be kept constant. Note, this is and must be an
* extensive quantity. units = Joules
* @param XY Integer flag indicating what is held constant. Must be
* either HP or UP.
* @param Tlow Lower limit of the temperature. It's an error condition
* if the temperature falls below Tlow.
* @param Thigh Upper limit of the temperature. It's an error condition
* if the temperature goes higher than Thigh.
* @param estimateEquil integer indicating whether the solver
* should estimate its own initial condition.
* - If 0, the initial mole fraction vector in the ThermoPhase object is
* used as the initial condition.
* - If 1, the initial mole fraction vector is used if the element
* abundances are satisfied.
* - if -1, the initial mole fraction vector is thrown out, and an
* estimate is formulated.
* @param printLvl Determines the amount of printing that gets sent to
* stdout from the vcs package (Note, you may have to
* compile with debug flags to get some printing). See main
* constructor call for meaning of the levels.
* @param err Internal error level
* @param maxsteps max steps allowed.
* @param loglevel Determines the amount of printing to the output file.
*/
int equilibrate_HP(doublereal Htarget, int XY, double Tlow, double Thigh,
int estimateEquil = 0,
int printLvl = 0, doublereal err = 1.0E-6,
int maxsteps = VCS_MAXSTEPS, int loglevel=-99);
//! Equilibrate the solution using the current element abundances
//! stored in the MultiPhase object using constant S and P.
//! Equilibrate the solution using the current element abundances stored in
//! the MultiPhase object using constant S and P.
/*!
* Use the vcs algorithm to equilibrate the current multiphase
* mixture. The pressure of the calculation is taken from
* the current pressure stored with the MultiPhase object.
* Use the vcs algorithm to equilibrate the current multiphase mixture. The
* pressure of the calculation is taken from the current pressure stored
* with the MultiPhase object.
*
* @param Starget Value of the total mixture entropy that will be kept
* constant. Note, this is and must be an extensive
* quantity. units = Joules/K
* @param Tlow Lower limit of the temperature. It's an error condition
* if the temperature falls below Tlow.
* @param Thigh Upper limit of the temperature. It's an error condition
* if the temperature goes higher than Thigh.
* @param estimateEquil integer indicating whether the solver should
* estimate its own initial condition.
* - If 0, the initial mole fraction vector in the
* ThermoPhase object is used as the initial condition.
* - If 1, the initial mole fraction vector is used if the
* element abundances are satisfied.
* - If -1, the initial mole fraction vector is thrown
* out, and an estimate is formulated.
* @param printLvl Determines the amount of printing that
* gets sent to stdout from the vcs package
* (Note, you may have to compile with debug
* flags to get some printing). See main
* constructor call for meaning of the levels.
* @param err Internal error level
* @param maxsteps max steps allowed.
* @param loglevel Determines the amount of printing to the output file.
* @param Starget Value of the total mixture entropy that will be kept
* constant. Note, this is and must be an extensive quantity.
* units = Joules/K
* @param Tlow Lower limit of the temperature. It's an error condition if
* the temperature falls below Tlow.
* @param Thigh Upper limit of the temperature. It's an error condition if
* the temperature goes higher than Thigh.
* @param estimateEquil integer indicating whether the solver should
* estimate its own initial condition.
* - If 0, the initial mole fraction vector in the ThermoPhase object is
* used as the initial condition.
* - If 1, the initial mole fraction vector is used if the element
* abundances are satisfied.
* - If -1, the initial mole fraction vector is thrown out, and an
* estimate is formulated.
* @param printLvl Determines the amount of printing that gets sent to
* stdout from the vcs package (Note, you may have to
* compile with debug flags to get some printing). See main
* constructor call for meaning of the levels.
* @param err Internal error level
* @param maxsteps max steps allowed.
* @param loglevel Determines the amount of printing to the output file.
*/
int equilibrate_SP(doublereal Starget, double Tlow, double Thigh,
int estimateEquil = 0,
@ -233,31 +228,30 @@ public:
//! Equilibrate the solution using the current element abundances stored
//! in the MultiPhase object using constant V and constant T, H, U or S.
/*!
* Use the vcs algorithm to equilibrate the current multiphase
* mixture. The pressure of the calculation is taken from
* the current pressure stored with the MultiPhase object.
* Use the vcs algorithm to equilibrate the current multiphase mixture. The
* pressure of the calculation is taken from the current pressure stored
* with the MultiPhase object.
*
* @param XY Integer flag indicating what is held constant.
* Must be either TV, HV, UV, or SV.
* @param xtarget Value of the total thermodynamic parameter to
* be held constant in addition to V.
* Note, except for T, this must be an extensive
* quantity. units = Joules/K or Joules
* @param estimateEquil integer indicating whether the solver should
* estimate its own initial condition.
* - If 0, the initial mole fraction vector in the
* ThermoPhase object is used as the initial condition.
* - If 1, the initial mole fraction vector is used if the
* element abundances are satisfied.
* - if -1, the initial mole fraction vector is thrown
* out, and an estimate is formulated.
* @param printLvl Determines the amount of printing that gets sent to
* stdout from the vcs package (Note, you may have to
* compile with debug flags to get some printing). See
* main constructor call for meaning of the levels.
* @param err Internal error level
* @param maxsteps max steps allowed.
* @param logLevel Determines the amount of printing to the output file.
* @param XY Integer flag indicating what is held constant.
* Must be either TV, HV, UV, or SV.
* @param xtarget Value of the total thermodynamic parameter to be held
* constant in addition to V. Note, except for T, this must be an
* extensive quantity. units = Joules/K or Joules
* @param estimateEquil integer indicating whether the solver should
* estimate its own initial condition.
* - If 0, the initial mole fraction vector in the ThermoPhase object is
* used as the initial condition.
* - If 1, the initial mole fraction vector is used if the element
* abundances are satisfied.
* - if -1, the initial mole fraction vector is thrown out, and an
* estimate is formulated.
* @param printLvl Determines the amount of printing that gets sent to
* stdout from the vcs package (Note, you may have to compile with debug
* flags to get some printing). See main constructor call for meaning of
* the levels.
* @param err Internal error level
* @param maxsteps max steps allowed.
* @param logLevel Determines the amount of printing to the output file.
*/
int equilibrate_TV(int XY, doublereal xtarget,
int estimateEquil = 0,
@ -266,38 +260,39 @@ public:
//! Determine the phase stability of a phase at the current conditions
/*!
* Equilibration of the solution is not done before the determination is made.
* Equilibration of the solution is not done before the determination is
* made.
*
* @param iph Phase number to determine the equilibrium. If the phase
* has a non-zero mole number....
* @param funcStab Value of the phase pop function
* @param printLvl Determines the amount of printing that gets sent to
* stdout from the vcs package (Note, you may have to
* compile with debug flags to get some printing).
* @param logLevel Determines the amount of printing to the output file.
* @param iph Phase number to determine the equilibrium. If the phase
* has a non-zero mole number....
* @param funcStab Value of the phase pop function
* @param printLvl Determines the amount of printing that gets sent to
* stdout from the vcs package (Note, you may have to compile with debug
* flags to get some printing).
* @param logLevel Determines the amount of printing to the output file.
*/
int determine_PhaseStability(int iph, double& funcStab, int printLvl= 0, int logLevel = -99);
//! Report the equilibrium answer in a comma separated table format
/*!
* This routine is used for in the test suite.
* This routine is used for in the test suite.
*
* @param reportFile Base name of the file to get the report.
* File name is incremented by 1 for each report.
* @param reportFile Base name of the file to get the report. File name is
* incremented by 1 for each report.
*/
void reportCSV(const std::string& reportFile);
//! reports the number of components in the equilibration problem
/*!
* @return returns the number of components. If an equilibrium
* problem hasn't been solved yet, it returns -1.
* @returns the number of components. If an equilibrium
* problem hasn't been solved yet, it returns -1.
*/
size_t numComponents() const;
//! Reports the number of element constraints in the equilibration problem
/*!
* @return returns the number of element constraints. If an equilibrium
* problem hasn't been solved yet, it returns -1.
* @returns the number of element constraints. If an equilibrium problem
* hasn't been solved yet, it returns -1.
*/
size_t numElemConstraints() const;
@ -308,22 +303,22 @@ public:
protected:
//! Vector that takes into account of the current sorting of the species
/*!
* The index of m_order is the original k value of the species in the
* multiphase. The value of m_order, k_sorted, is the current value of
* the species index.
* The index of m_order is the original k value of the species in the
* multiphase. The value of m_order, k_sorted, is the current value of the
* species index.
*
* `m_order[korig] = k_sorted`
* `m_order[korig] = k_sorted`
*/
vector_int m_order;
//! Object which contains the problem statement
/*!
* The problem statement may contain some subtleties. For example, the
* element constraints may be different than just an element conservation
* contraint equations. There may be kinetically frozen degrees of
* freedom. There may be multiple electrolyte phases with zero charge
* constraints. All of these make the problem statement different than
* the simple element conservation statement.
* The problem statement may contain some subtleties. For example, the
* element constraints may be different than just an element conservation
* contraint equations. There may be kinetically frozen degrees of freedom.
* There may be multiple electrolyte phases with zero charge constraints.
* All of these make the problem statement different than the simple element
* conservation statement.
*/
VCS_PROB m_vprob;
@ -335,16 +330,16 @@ protected:
//! Print level from the VCSnonlinear package
/*!
* (Note, you may have to compile with debug flags to get some printing).
* (Note, you may have to compile with debug flags to get some printing).
*
* - 0: No IO from the routine whatsoever
* - 1: file IO from reportCSV() carried out. One line print statements
* from equilibrate_XY() functions
* - 2: Problem statement information from vcs_Cantera_update_vprob();
* Final state of the system from vcs_solve_TP()
* - 3: Several more setup tables; Problem initialization routine
* - 4: One table for each iteration within vcs_solve_Tp()
* - 5: Multiple tables for each iteration within vcs_solve_TP()
* - 0: No IO from the routine whatsoever
* - 1: file IO from reportCSV() carried out. One line print statements
* from equilibrate_XY() functions
* - 2: Problem statement information from vcs_Cantera_update_vprob();
* Final state of the system from vcs_solve_TP()
* - 3: Several more setup tables; Problem initialization routine
* - 4: One table for each iteration within vcs_solve_Tp()
* - 5: Multiple tables for each iteration within vcs_solve_TP()
*/
int m_printLvl;
@ -354,10 +349,8 @@ protected:
//! Iteration Count
int m_iter;
//! Vector of indices for species that are included in the calculation.
/*!
* This is used to exclude pure-phase species with invalid thermo data
*/
//! Vector of indices for species that are included in the calculation. This
//! is used to exclude pure-phase species with invalid thermo data
vector_int m_species;
//! The object that does all of the equilibration work.

View file

@ -22,28 +22,35 @@ public:
//! Name of the species
std::string SpName;
VCS_SPECIES_THERMO* SpeciesThermo; /* Pointer to the thermo
structure for this species */
double WtSpecies; /* Molecular Weight of the species (gm/mol) */
//! Pointer to the thermo structure for this species
VCS_SPECIES_THERMO* SpeciesThermo;
//! Molecular Weight of the species (gm/mol)
double WtSpecies;
//! Column of the formula matrix, comprising the
//! element composition of the species */
//! element composition of the species
vector_fp FormulaMatrixCol;
double Charge; /* Charge state of the species -> This may
be duplication of what's in the
FormulaMatrixCol entries. However, it's prudent
to separate it out. */
int SurfaceSpecies; /* True if this species belongs to a surface phase */
//! Charge state of the species -> This may be duplication of what's in the
//! FormulaMatrixCol entries. However, it's prudent to separate it out.
double Charge;
//! True if this species belongs to a surface phase
int SurfaceSpecies;
/*
* Various Calculated Quantities that are appropriate to
* keep copies of at this level.
* Various Calculated Quantities that are appropriate to keep copies of at
* this level.
*/
double VolPM; /* Partial molar volume of the species */
double ReferenceMoleFraction; /* Representative value of the mole
fraction of this species in a phase.
This value is used for convergence issues
and for calculation of numerical derivs */
//! Partial molar volume of the species
double VolPM;
//! Representative value of the mole fraction of this species in a phase.
//! This value is used for convergence issues and for calculation of
//! numerical derivs
double ReferenceMoleFraction;
vcs_SpeciesProperties(size_t indexPhase, size_t indexSpeciesPhase,
vcs_VolPhase* owning);

View file

@ -44,44 +44,41 @@ class VCS_SOLVE;
//! Phase information and Phase calculations for vcs.
/*!
* Each phase in a vcs calculation has a vcs_VolPhase object associated
* with it. This object helps to coordinate property evaluations for
* species within the phase. Usually these evaluations must be carried
* out on a per phase basis. However, vcs frequently needs per species
* quantities. Therefore, we need an interface layer between vcs
* and Cantera's ThermoPhase.
* Each phase in a vcs calculation has a vcs_VolPhase object associated with it.
* This object helps to coordinate property evaluations for species within the
* phase. Usually these evaluations must be carried out on a per phase basis.
* However, vcs frequently needs per species quantities. Therefore, we need an
* interface layer between vcs and Cantera's ThermoPhase.
*
* The species stay in the same ordering within this structure.
* The vcs algorithm will change the ordering of species in
* the global species list. However, the indexing of species in this
* list stays the same. This structure contains structures that
* point to the species belonging to this phase in the global
* vcs species list.
* The species stay in the same ordering within this structure. The vcs
* algorithm will change the ordering of species in the global species list.
* However, the indexing of species in this list stays the same. This structure
* contains structures that point to the species belonging to this phase in the
* global vcs species list.
*
* This object is considered not to own the underlying Cantera ThermoPhase
* object for the phase.
*
* This object contains an idea of the temperature and pressure.
* It checks to see if if the temperature and pressure has changed before calling
* underlying property evaluation routines.
* This object contains an idea of the temperature and pressure. It checks to
* see if if the temperature and pressure has changed before calling underlying
* property evaluation routines.
*
* The object contains values for the electric potential of a phase.
* It coordinates the evaluation of properties wrt when the electric
* potential of a phase has changed.
* The object contains values for the electric potential of a phase. It
* coordinates the evaluation of properties wrt when the electric potential of a
* phase has changed.
*
* The object knows about the mole fractions of the phase. It controls
* the values of mole fractions, and coordinates the property evaluation
* wrt to changes in the mole fractions. It also will keep track of the
* likely values of mole fractions in multicomponent phases even when
* the phase doesn't actually exist within the thermo program.
* The object knows about the mole fractions of the phase. It controls the
* values of mole fractions, and coordinates the property evaluation wrt to
* changes in the mole fractions. It also will keep track of the likely values
* of mole fractions in multicomponent phases even when the phase doesn't
* actually exist within the thermo program.
*
* The object knows about the total moles of a phase. It checks to
* see if the phase currently exists or not, and modifies its behavior
* accordingly.
* The object knows about the total moles of a phase. It checks to see if the
* phase currently exists or not, and modifies its behavior accordingly.
*
* Activity coefficients and volume calculations are lagged. They are only
* called when they are needed (and when the state has changed so that they
* need to be recalculated).
* called when they are needed (and when the state has changed so that they need
* to be recalculated).
*/
class vcs_VolPhase
{
@ -97,10 +94,10 @@ public:
//! The resize() function fills in all of the initial information if it
//! is not given in the constructor.
/*!
* @param phaseNum index of the phase in the vcs problem
* @param numSpecies Number of species in the phase
* @param phaseName String name for the phase
* @param molesInert kmoles of inert in the phase (defaults to zero)
* @param phaseNum index of the phase in the vcs problem
* @param numSpecies Number of species in the phase
* @param phaseName String name for the phase
* @param molesInert kmoles of inert in the phase (defaults to zero)
*/
void resize(const size_t phaseNum, const size_t numSpecies,
const size_t numElem, const char* const phaseName,
@ -110,9 +107,8 @@ public:
//! Evaluate activity coefficients and return the kspec coefficient
/*!
* We carry out a calculation whenever #m_UpToDate_AC is false.
* Specifically whenever a phase goes zero, we do not carry out
* calculations on it.
* We carry out a calculation whenever #m_UpToDate_AC is false. Specifically
* whenever a phase goes zero, we do not carry out calculations on it.
*
* @param kspec species number
*/
@ -121,44 +117,42 @@ public:
//! Set the moles and/or mole fractions within the phase
/*!
* @param molNum total moles in the phase
* @param moleFracVec Vector of input mole fractions
* @param vcsStateStatus Status flag for this update
* @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);
//! Set the moles within the phase
/*!
* This function takes as input the mole numbers in vcs format, and
* then updates this object with their values. This is essentially
* a gather routine.
* This function takes as input the mole numbers in vcs format, and then
* updates this object with their values. This is essentially a gather
* routine.
*
* @param molesSpeciesVCS Array of mole numbers. Note, the indices for
* species in this array may not be contiguous. IndSpecies[] is
* needed to gather the species into the local contiguous
* vector format.
* @param molesSpeciesVCS Array of mole numbers. Note, the indices for
* species in this array may not be contiguous. IndSpecies[] is needed
* to gather the species into the local contiguous vector format.
*/
void setMolesFromVCS(const int stateCalc,
const double* molesSpeciesVCS = 0);
//! Set the moles within the phase
/*!
* This function takes as input the mole numbers in vcs format, and
* then updates this object with their values. This is essentially
* a gather routine.
* This function takes as input the mole numbers in vcs format, and then
* updates this object with their values. This is essentially a gather
* routine.
*
* Additionally it checks to see that the total moles value in
* TPhMoles[iplace] is equal to the internally computed value.
* If this isn't the case, an error exit is carried out.
* Additionally it checks to see that the total moles value in
* TPhMoles[iplace] is equal to the internally computed value. If this isn't
* the case, an error exit is carried out.
*
* @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 indices
* for species in this array may not be contiguous. IndSpecies[] is
* needed to gather the species into the local contiguous vector
* format.
* @param TPhMoles VCS's array containing the number of moles in each phase.
* @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 indices for
* species in this array may not be contiguous. IndSpecies[] is needed
* to gather the species into the local contiguous vector format.
* @param TPhMoles VCS's array containing the number of moles in each phase.
*/
void setMolesFromVCSCheck(const int vcsStateStatus,
const double* molesSpeciesVCS,
@ -166,25 +160,24 @@ public:
//! Update the moles within the phase, if necessary
/*!
* This function takes as input the stateCalc value, which determines
* where within VCS_SOLVE to fetch the mole numbers. It then updates this
* object with their values. This is essentially a gather routine.
* This function takes as input the stateCalc value, which determines where
* within VCS_SOLVE to fetch the mole numbers. 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 stateCalc State calc value either VCS_STATECALC_OLD or
* VCS_STATECALC_NEW. With any other value nothing is done.
*/
void updateFromVCS_MoleNumbers(const int stateCalc);
//! Fill in an activity coefficients vector within a VCS_SOLVE object
/*!
* This routine will calculate the activity coefficients for the
* current phase, and fill in the corresponding entries in the
* VCS activity coefficients vector.
* This routine will calculate the activity coefficients for the current
* phase, and fill in the corresponding entries in the VCS activity
* coefficients vector.
*
* @param AC vector of activity coefficients for all of the species
* in all of the phases in a VCS problem. Only the
* entries for the current phase are filled in.
* @param AC vector of activity coefficients for all of the species in all
* of the phases in a VCS problem. Only the entries for the current
* phase are filled in.
*/
void sendToVCS_ActCoeff(const int stateCalc, double* const AC);
@ -202,13 +195,11 @@ public:
//! Gibbs free energy calculation for standard state of one species
/*!
* Calculate the Gibbs free energies for the standard state
* of the kth species.
* The results are held internally within the object.
* Calculate the Gibbs free energies for the standard state of the kth
* species. The results are held internally within the object.
*
* @param kspec Species number (within the phase)
* @return Gstar[kspec] returns the Gibbs free energy for the
* standard state of the kth species.
* @returns the Gibbs free energy for the standard state of the kth species.
*/
double GStar_calc_one(size_t kspec) const;
@ -232,25 +223,25 @@ public:
//! Fill in the partial molar volume vector for VCS
/*!
* This routine will calculate the partial molar volumes for the
* current phase (if needed), and fill in the corresponding entries in the
* VCS partial molar volumes vector.
* This routine will calculate the partial molar volumes for the current
* phase (if needed), and fill in the corresponding entries in the VCS
* partial molar volumes vector.
*
* @param VolPM vector of partial molar volumes for all of the species
* in all of the phases in a VCS problem. Only the
* entries for the current phase are filled in.
* @param VolPM vector of partial molar volumes for all of the species in
* all of the phases in a VCS problem. Only the entries for the current
* phase are filled in.
*/
double sendToVCS_VolPM(double* const VolPM) const;
//! Fill in the partial molar volume vector for VCS
/*!
* This routine will calculate the partial molar volumes for the
* current phase (if needed), and fill in the corresponding entries in the
* VCS partial molar volumes vector.
* This routine will calculate the partial molar volumes for the
* current phase (if needed), and fill in the corresponding entries in the
* VCS partial molar volumes vector.
*
* @param VolPM vector of partial molar volumes for all of the species
* in all of the phases in a VCS problem. Only the
* entries for the current phase are filled in.
* @param VolPM vector of partial molar volumes for all of the species in
* all of the phases in a VCS problem. Only the entries for the current
* phase are filled in.
*
* @todo This function's documentation is incorrect.
*/
@ -259,25 +250,25 @@ public:
//! Sets the temperature and pressure in this object and underlying
//! ThermoPhase objects
/*!
* @param temperature_Kelvin (Kelvin)
* @param pressure_PA Pressure (MKS units - Pascal)
* @param temperature_Kelvin (Kelvin)
* @param pressure_PA Pressure (MKS units - Pascal)
*/
void setState_TP(const double temperature_Kelvin, const double pressure_PA);
//! Sets the temperature in this object and underlying ThermoPhase objects
/*!
* @param temperature_Kelvin (Kelvin)
* @param temperature_Kelvin (Kelvin)
*/
void setState_T(const double temperature_Kelvin);
// Downloads the ln ActCoeff Jacobian into the VCS version of the
// ln ActCoeff Jacobian.
/*
* This is essentially a scatter operation.
* This is essentially a scatter operation.
*
* @param LnAcJac_VCS Jacobian parameter
* The Jacobians are actually d( lnActCoeff) / d (MolNumber);
* dLnActCoeffdMolNumber(k,j)
* @param LnAcJac_VCS Jacobian parameter
* The Jacobians are actually d( lnActCoeff) / d (MolNumber);
* dLnActCoeffdMolNumber(k,j)
*
* j = id of the species mole number
* k = id of the species activity coefficient
@ -286,8 +277,8 @@ public:
//! Set the pointer for Cantera's ThermoPhase parameter
/*!
* When we first initialize the ThermoPhase object, we read the
* state of the ThermoPhase into vcs_VolPhase object.
* When we first initialize the ThermoPhase object, we read the state of the
* ThermoPhase into vcs_VolPhase object.
*
* @param tp_ptr Pointer to the ThermoPhase object corresponding
* to this phase.
@ -308,7 +299,7 @@ public:
//! Returns the mole fraction of the kspec species
/*!
* @param kspec Index of the species in the phase
* @param kspec Index of the species in the phase
*
* @return Value of the mole fraction
*/
@ -316,17 +307,17 @@ public:
//! Sets the total moles in the phase
/*!
* We don't have to flag the internal state as changing here
* because we have just changed the total moles.
* We don't have to flag the internal state as changing here because we have
* just changed the total moles.
*
* @param totalMols Total moles in the phase (kmol)
* @param totalMols Total moles in the phase (kmol)
*/
void setTotalMoles(const 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.
* This will trigger the object to go get the current mole numbers when it
* needs it.
*/
void setMolesOutOfDate(int stateCalc = -1);
@ -336,8 +327,8 @@ public:
private:
//! Set the mole fractions from a conventional mole fraction vector
/*!
* @param xmol Value of the mole fractions for the species
* in the phase. These are contiguous.
* @param xmol Value of the mole fractions for the species in the phase.
* These are contiguous.
*/
void setMoleFractions(const double* const xmol);
@ -355,20 +346,21 @@ public:
//! Return a const reference to the creationMoleNumbers stored in the object.
/*!
* @return Returns a const reference to the vector of creationMoleNumbers
* @returns a const reference to the vector of creationMoleNumbers
*/
const vector_fp & creationMoleNumbers(std::vector<size_t> &creationGlobalRxnNumbers) const;
//! Returns whether the phase is an ideal solution phase
bool isIdealSoln() const;
//! Return the index of the species that represents the
//! the voltage of the phase
//! Return the index of the species that represents the the voltage of the
//! phase
size_t phiVarIndex() const;
void setPhiVarIndex(size_t phiVarIndex);
//! Retrieve the kth Species structure for the species belonging to this phase
//! Retrieve the kth Species structure for the species belonging to this
//! phase
/*!
* The index into this vector is the species index within the phase.
*
@ -378,67 +370,62 @@ public:
//! int indicating whether the phase exists or not
/*!
* returns the m_existence int for the phase
* returns the m_existence int for the phase
*
* - VCS_PHASE_EXIST_ZEROEDPHASE = -6: Set to not exist by fiat from a
* higher level.
* This is used in phase stability boundary calculations
* - VCS_PHASE_EXIST_NO = 0: Doesn't exist currently
* - VCS_PHASE_EXIST_MINORCONC = 1: Exists, but the concentration is
* so low that an alternate
* method is used to calculate the total phase concentrations.
* - VCS_PHASE_EXIST_YES = 2 : Does exist currently
* - VCS_PHASE_EXIST_ALWAYS = 3: Always exists because it contains
* inerts which can't exist in any other phase. Or,
* the phase exists always because it consists of a single
* species, which is identified with the voltage, i.e.,
* it's an electron metal phase.
* - VCS_PHASE_EXIST_ZEROEDPHASE = -6: Set to not exist by fiat from a
* higher level. This is used in phase stability boundary calculations
* - VCS_PHASE_EXIST_NO = 0: Doesn't exist currently
* - VCS_PHASE_EXIST_MINORCONC = 1: Exists, but the concentration is so low
* that an alternate method is used to calculate the total phase
* concentrations.
* - VCS_PHASE_EXIST_YES = 2 : Does exist currently
* - VCS_PHASE_EXIST_ALWAYS = 3: Always exists because it contains inerts
* which can't exist in any other phase. Or, the phase exists always
* because it consists of a single species, which is identified with the
* voltage, i.e., it's an electron metal phase.
*/
int exists() const;
//! Set the existence flag in the object
/*!
* Note the total moles of the phase must have been set appropriately
* before calling this routine.
* Note the total moles of the phase must have been set appropriately before
* calling this routine.
*
* @param existence Phase existence flag
*
* @note try to eliminate this routine
* @note try to eliminate this routine
*/
void setExistence(const int existence);
//! Return the Global VCS index of the kth species in the phase
/*!
* @param spIndex local species index (0 to the number of species
* in the phase)
* @param spIndex local species index (0 to the number of species in the
* phase)
*
* @return Returns the VCS_SOLVE species index of the species.
* This changes as rearrangements are carried out.
* @returns the VCS_SOLVE species index of the species. This changes as
* rearrangements are carried out.
*/
size_t spGlobalIndexVCS(const size_t spIndex) const;
//! set the Global VCS index of the kth species in the phase
/*!
* @param spIndex local species index (0 to the number of species
* in the phase)
* @param spIndex local species index (0 to the number of species
* in the phase)
*
* @return Returns the VCS_SOLVE species index of the that species
* This changes as rearrangements are carried out.
* @returns the VCS_SOLVE species index of the that species This changes as
* rearrangements are carried out.
*/
void setSpGlobalIndexVCS(const size_t spIndex, const size_t spGlobalIndex);
//! Sets the total moles of inert in the phase
/*!
* @param tMolesInert Value of the total kmols of inert species in the
* phase.
* phase.
*/
void setTotalMolesInert(const double tMolesInert);
//! returns the value of the total kmol of inert in the phase
/*!
* @return Returns the total value of the kmol of inert in the phase
*/
//! Returns the value of the total kmol of inert in the phase
double totalMolesInert() const;
//! Returns the global index of the local element index for the phase
@ -473,11 +460,11 @@ public:
*/
void setElementType(const size_t e, const int eType);
//! Transfer all of the element information from the
//! ThermoPhase object to the vcs_VolPhase object.
//! Transfer all of the element information from the ThermoPhase object to
//! the vcs_VolPhase object.
/*!
* Also decide whether we need a new charge neutrality element in the
* phase to enforce a charge neutrality constraint.
* Also decide whether we need a new charge neutrality element in the phase
* to enforce a charge neutrality constraint.
*
* @param tPhase Pointer to the ThermoPhase object
*/
@ -509,16 +496,15 @@ public:
private:
//! Evaluate the activity coefficients at the current conditions
/*!
* We carry out a calculation whenever #m_UpToDate_AC is false.
* Specifically whenever a phase goes zero, we do not carry out
* calculations on it.
* We carry out a calculation whenever #m_UpToDate_AC is false. Specifically
* whenever a phase goes zero, we do not carry out calculations on it.
*/
void _updateActCoeff() const;
//! Gibbs free energy calculation for standard states
/*!
* Calculate the Gibbs free energies for the standard states
* The results are held internally within the object.
* Calculate the Gibbs free energies for the standard states The results are
* held internally within the object.
*/
void _updateGStar() const;
@ -536,7 +522,7 @@ private:
//! Calculate the partial molar volumes of all species and return the
//! total volume
/*!
* Calculates these quantities internally and then stores them
* Calculates these quantities internally and then stores them
*
* @return total volume [m^3]
*/
@ -544,27 +530,27 @@ private:
//! Evaluation of Activity Coefficient Jacobians
/*!
* This is the derivative of the ln of the activity coefficient with
* respect to mole number of jth species. (temp, pressure, and other mole
* numbers held constant)
* This is the derivative of the ln of the activity coefficient with respect
* to mole number of jth species. (temp, pressure, and other mole numbers
* held constant)
*
* We employ a finite difference derivative approach here. Because we have
* to change the mole numbers, this is not a const function, even though
* the paradigm would say that it should be.
* We employ a finite difference derivative approach here. Because we have
* to change the mole numbers, this is not a const function, even though the
* paradigm would say that it should be.
*/
void _updateLnActCoeffJac();
//! Updates the mole fraction dependencies
/*!
* Whenever the mole fractions change, this routine should be called.
* Whenever the mole fractions change, this routine should be called.
*/
void _updateMoleFractionDependencies();
private:
//! Backtrack value of VCS_SOLVE *
/*!
* Note the default for this is 0. That's a valid value too, since
* VCS_PROB also uses vcs_VolPhase objects.
* Note the default for this is 0. That's a valid value too, since VCS_PROB
* also uses vcs_VolPhase objects.
*/
VCS_SOLVE* m_owningSolverObject;
@ -588,12 +574,12 @@ public:
//! Type of the equation of state
/*!
* The known types are listed at the top of this file.
* The known types are listed at the top of this file.
*/
int m_eqnState;
//! This is the element number for the charge neutrality
//! condition of the phase
//! This is the element number for the charge neutrality condition of the
//! phase
/*!
* If it has one. If it does not have a charge neutrality
* constraint, then this value is equal to -1
@ -603,9 +589,9 @@ public:
//! Units for the chemical potential data, pressure data, volume,
//! and species amounts
/*!
* All internally stored quantities will have these units. Also, printed
* quantities will display in these units. Input quantities are expected
* in these units.
* All internally stored quantities will have these units. Also, printed
* quantities will display in these units. Input quantities are expected in
* these units.
*
* | | | Chem_Pot | Pres | vol | moles|
* |---|--------------------|-------------------------|------|------|------|
@ -615,13 +601,13 @@ public:
* | 2 | VCS_UNITS_KELVIN | KELVIN -> MU / R | Pa | m**3 | kmol |
* | 3 | VCS_UNITS_MKS | Joules / Kmol (Cantera) | Pa | m**3 | kmol |
*
* see vcs_defs.h for more information.
* see vcs_defs.h for more information.
*
* Currently, this value should be the same as the owning VCS_PROB or
* VCS_SOLVE object. There is no code for handling anything else atm.
* Currently, this value should be the same as the owning VCS_PROB or
* VCS_SOLVE object. There is no code for handling anything else atm.
*
* (This variable is needed for the vcsc code, where it is not equal
* to VCS_UNITS_MKS).
* (This variable is needed for the vcsc code, where it is not equal to
* VCS_UNITS_MKS).
*/
int p_VCS_UnitsFormat;
@ -680,8 +666,8 @@ private:
*/
vector_int m_speciesUnknownType;
//! Index of the element number in the global list of elements
//! stored in VCS_PROB or VCS_SOLVE
//! Index of the element number in the global list of elements
//! stored in VCS_PROB or VCS_SOLVE
std::vector<size_t> m_elemGlobalIndex;
//! Number of species in the phase
@ -760,18 +746,18 @@ private:
//! Vector of creation global reaction numbers for the phase stability problem
/*!
* The phase stability problem requires a global reaction number for each
* species in the phase. Usually this is the krxn = kglob - M for species
* in the phase that are not components. For component species, the
* choice of the reaction is one which maximizes the chance that the phase
* pops into (or remains in) existence.
* The phase stability problem requires a global reaction number for each
* species in the phase. Usually this is the krxn = kglob - M for species in
* the phase that are not components. For component species, the choice of
* the reaction is one which maximizes the chance that the phase pops into
* (or remains in) existence.
*
* The index here is the local phase species index. the value of the
* variable is the global vcs reaction number. Note, that the global
* reaction number will go out of order when the species positions are
* swapped. So, this number has to be recalculated.
* The index here is the local phase species index. the value of the
* variable is the global vcs reaction number. Note, that the global
* reaction number will go out of order when the species positions are
* swapped. So, this number has to be recalculated.
*
* Length = number of species in phase
* Length = number of species in phase
*/
std::vector<size_t> creationGlobalRxnNumbers_;
@ -786,8 +772,8 @@ private:
//! current Temperature.
/*!
* Note, This is the chemical potential derived strictly from the polynomial
* in temperature. Pressure effects have to be added in to
* get to the standard state.
* in temperature. Pressure effects have to be added in to get to the
* standard state.
*
* Units -> depends on VCS_UnitsFormat variable. Cantera -> J/kmol
*/
@ -811,8 +797,8 @@ private:
//! Vector of calculated activity coefficients for the current state
/*!
* Whether or not this vector is current is determined by
* the bool #m_UpToDate_AC.
* Whether or not this vector is current is determined by the bool
* #m_UpToDate_AC.
*/
mutable vector_fp ActCoeff;
@ -853,8 +839,8 @@ private:
/*!
* Activity coefficients and volume calculations are lagged. They are only
* called when they are needed (and when the state has changed so that they
* need to be recalculated).
* Star volumes are sensitive to temperature and pressure
* need to be recalculated). Star volumes are sensitive to temperature and
* pressure
*/
mutable bool m_UpToDate_VolStar;
@ -862,8 +848,8 @@ private:
/*!
* Activity coefficients and volume calculations are lagged. They are only
* called when they are needed (and when the state has changed so that they
* need to be recalculated).
* partial molar volumes are sensitive to everything
* need to be recalculated). partial molar volumes are sensitive to
* everything
*/
mutable bool m_UpToDate_VolPM;
@ -888,8 +874,8 @@ private:
//! Return a string representing the equation of state
/*!
* @param EOSType : integer value of the equation of state
* @return returns a string representing the EOS. The string is no more than 16 characters.
* @param EOSType : integer value of the equation of state
* @return a string representing the EOS. The string is no more than 16 characters.
*/
std::string string16_EOSType(int EOSType);

View file

@ -43,20 +43,20 @@ namespace Cantera
* @{
*/
//! Cutoff relative mole fraction value,
//! below which species are deleted from the equilibrium problem.
//! Cutoff relative mole fraction value, below which species are deleted from
//! the equilibrium problem.
#ifndef VCS_RELDELETE_SPECIES_CUTOFF
#define VCS_RELDELETE_SPECIES_CUTOFF 1.0e-64
#endif
//! Cutoff relative mole number value,
//! below which species are deleted from the equilibrium problem.
//! Cutoff relative mole number value, below which species are deleted from the
//! equilibrium problem.
#ifndef VCS_DELETE_MINORSPECIES_CUTOFF
#define VCS_DELETE_MINORSPECIES_CUTOFF 1.0e-140
#endif
//! Relative value of multiphase species mole number for a
//! multiphase species which is small.
//! Relative value of multiphase species mole number for a multiphase species
//! which is small.
#ifndef VCS_SMALL_MULTIPHASE_SPECIES
#define VCS_SMALL_MULTIPHASE_SPECIES 1.0e-25
#endif
@ -67,17 +67,16 @@ namespace Cantera
#define VCS_DELETE_PHASE_CUTOFF 1.0e-13
#endif
//! Relative mole number of species in a phase that is created
//! We want this to be comfortably larger than the VCS_DELETE_PHASE_CUTOFF value
//! so that the phase can have a chance to survive.
//! Relative mole number of species in a phase that is created We want this to
//! be comfortably larger than the VCS_DELETE_PHASE_CUTOFF value so that the
//! phase can have a chance to survive.
#ifndef VCS_POP_PHASE_MOLENUM
#define VCS_POP_PHASE_MOLENUM 1.0e-11
#endif
//! Cutoff moles below which a phase or species which
//! comprises the bulk of an element's total concentration
//! is deleted.
//! Cutoff moles below which a phase or species which comprises the bulk of an
//! element's total concentration is deleted.
#ifndef VCS_DELETE_ELEMENTABS_CUTOFF
#define VCS_DELETE_ELEMENTABS_CUTOFF 1.0e-280
#endif
@ -133,68 +132,67 @@ namespace Cantera
//! Species lies in a multicomponent phase, with a small phase concentration
/*!
* The species lies in a multicomponent phase that exists.
* It concentration is currently very low, necessitating a
* different method of calculation.
* The species lies in a multicomponent phase that exists. It concentration is
* currently very low, necessitating a different method of calculation.
*/
#define VCS_SPECIES_SMALLMS -1
//! Species lies in a multicomponent phase with concentration zero
/*!
* The species lies in a multicomponent phase which currently doesn't exist.
* It concentration is currently zero.
* The species lies in a multicomponent phase which currently doesn't exist.
* It concentration is currently zero.
*/
#define VCS_SPECIES_ZEROEDMS -2
//! Species is a SS phase, that is currently zeroed out.
/*!
* The species lies in a single-species phase which
* is currently zeroed out.
* The species lies in a single-species phase which is currently zeroed out.
*/
#define VCS_SPECIES_ZEROEDSS -3
//! Species has such a small mole fraction it is deleted even though its
//! phase may possibly exist.
/*!
* The species is believed to have such a small mole fraction
* that it best to throw the calculation of it out.
* It will be added back in at the end of the calculation.
* The species is believed to have such a small mole fraction that it best to
* throw the calculation of it out. It will be added back in at the end of the
* calculation.
*/
#define VCS_SPECIES_DELETED -4
//! Species refers to an electron in the metal.
/*!
* The unknown is equal to the electric potential of the phase
* in which it exists.
* The unknown is equal to the electric potential of the phase in which it
* exists.
*/
#define VCS_SPECIES_INTERFACIALVOLTAGE -5
//! Species lies in a multicomponent phase that is zeroed atm
/*!
* The species lies in a multicomponent phase that is currently
* deleted and will stay deleted due to a choice from a higher level.
* These species will formally always have zero mole numbers in the
* solution vector.
* The species lies in a multicomponent phase that is currently deleted and will
* stay deleted due to a choice from a higher level. These species will formally
* always have zero mole numbers in the solution vector.
*/
#define VCS_SPECIES_ZEROEDPHASE -6
//! Species lies in a multicomponent phase that is active, but species concentration is zero
//! Species lies in a multicomponent phase that is active, but species
//! concentration is zero
/*!
* The species lies in a multicomponent phase which currently does exist.
* It concentration is currently identically zero, though the phase exists. Note, this
* is a temporary condition that exists at the start of an equilibrium problem.
* The species is soon "birthed" or "deleted".
* The species lies in a multicomponent phase which currently does exist. It
* concentration is currently identically zero, though the phase exists. Note,
* this is a temporary condition that exists at the start of an equilibrium
* problem. The species is soon "birthed" or "deleted".
*/
#define VCS_SPECIES_ACTIVEBUTZERO -7
//! Species lies in a multicomponent phase that is active,
//! but species concentration is zero due to stoich constraint
/*!
* The species lies in a multicomponent phase which currently does exist. Its concentration is currently
* identically zero, though the phase exists. This is a permanent condition due to stoich constraints.
* The species lies in a multicomponent phase which currently does exist. Its
* concentration is currently identically zero, though the phase exists. This is
* a permanent condition due to stoich constraints.
*
* An example of this would be a species that contains Ni. But,
* the amount of Ni elements in the current problem statement is exactly zero.
* An example of this would be a species that contains Ni. But, the amount of Ni
* elements in the current problem statement is exactly zero.
*/
#define VCS_SPECIES_STOICHZERO -8
@ -265,11 +263,11 @@ namespace Cantera
//@}
/*!
* @name Types of Element Constraint Equations
* @name Types of Element Constraint Equations
*
* There may be several different types of element constraints handled
* by the equilibrium program. These defines are used to assign each
* constraint to one category.
* There may be several different types of element constraints handled by the
* equilibrium program. These defines are used to assign each constraint to one
* category.
* @{
*/
@ -280,9 +278,9 @@ namespace Cantera
//! Normal element constraint consisting of positive coefficients for the
//! formula matrix.
/*!
* All species have positive coefficients within the formula matrix.
* With this constraint, we may employ various strategies to handle
* small values of the element number successfully.
* All species have positive coefficients within the formula matrix. With this
* constraint, we may employ various strategies to handle small values of the
* element number successfully.
*/
#define VCS_ELEM_TYPE_ABSPOS 0
@ -301,27 +299,28 @@ namespace Cantera
//! Constraint associated with maintaining a fixed lattice stoichiometry in the
//! solids
/*!
* The constraint may have positive or negative values. The lattice 0 species will
* have negative values while higher lattices will have positive values
* The constraint may have positive or negative values. The lattice 0 species
* will have negative values while higher lattices will have positive values
*/
#define VCS_ELEM_TYPE_LATTICERATIO 3
//! Constraint associated with maintaining frozen kinetic equilibria in
//! some functional groups within molecules
/*!
* We seek here to say that some functional groups or ionic states should be
* treated as if they are separate elements given the time scale of the problem.
* This will be abs positive constraint. We have not implemented any examples yet.
* A requirement will be that we must be able to add and subtract these constraints.
* We seek here to say that some functional groups or ionic states should be
* treated as if they are separate elements given the time scale of the problem.
* This will be abs positive constraint. We have not implemented any examples
* yet. A requirement will be that we must be able to add and subtract these
* constraints.
*/
#define VCS_ELEM_TYPE_KINETICFROZEN 4
//! Constraint associated with the maintenance of a surface phase
/*!
* We don't have any examples of this yet either. However, surfaces only exist
* because they are interfaces between bulk layers. If we want to treat surfaces
* within thermodynamic systems we must come up with a way to constrain their total
* number.
* We don't have any examples of this yet either. However, surfaces only exist
* because they are interfaces between bulk layers. If we want to treat surfaces
* within thermodynamic systems we must come up with a way to constrain their
* total number.
*/
#define VCS_ELEM_TYPE_SURFACECONSTRAINT 5
//! Other constraint equations
@ -338,21 +337,18 @@ namespace Cantera
//! Unknown refers to mole number of a single species
#define VCS_SPECIES_TYPE_MOLNUM 0
//! Unknown refers to the voltage level of a phase
//! Unknown refers to the voltage level of a phase
/*!
* Typically, these species are electrons in metals. There is an
* infinite supply of them. However, their electrical potential
* is sometimes allowed to vary, for example if the open circuit voltage
* is sought after.
* Typically, these species are electrons in metals. There is an infinite supply
* of them. However, their electrical potential is sometimes allowed to vary,
* for example if the open circuit voltage is sought after.
*/
#define VCS_SPECIES_TYPE_INTERFACIALVOLTAGE -5
//@}
/*!
* @name Types of State Calculations within VCS
* These values determine where the
* results are stored within the VCS_SOLVE
* object.
* @name Types of State Calculations within VCS. These values determine where
* the results are stored within the VCS_SOLVE object.
* @{
*/
//! State Calculation is currently in an unknown state
@ -363,9 +359,9 @@ namespace Cantera
//! 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
//! 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

View file

@ -22,16 +22,16 @@ namespace Cantera
//! define this Cantera function to replace cout << endl;
/*!
* We use this to place an endl in the log file, and
* ensure that the IO buffers are flushed.
* We use this to place an endl in the log file, and ensure that the IO buffers
* are flushed.
*/
#define plogendl() writelogendl()
//! Global hook for turning on and off time printing.
/*!
* Default is to allow printing. But, you can assign this to zero globally to
* turn off all time printing. This is helpful for test suite purposes where
* you are interested in differences in text files.
* turn off all time printing. This is helpful for test suite purposes where you
* are interested in differences in text files.
*/
extern int vcs_timing_print_lvl;
@ -50,8 +50,8 @@ public:
//! of vcs_TP() to solve for thermo equilibrium
int T_Its;
//! Current number of iterations in the main loop
//! of vcs_TP() to solve for thermo equilibrium
//! Current number of iterations in the main loop
//! of vcs_TP() to solve for thermo equilibrium
int Its;
//! Total number of optimizations of the components basis set done
@ -60,8 +60,8 @@ public:
//! number of optimizations of the components basis set done
int Basis_Opts;
//! Current number of times the initial thermo
//! equilibrium estimator has been called
//! Current number of times the initial thermo equilibrium estimator has
//! been called
int T_Calls_Inest;
//! Current number of calls to vcs_TP
@ -108,7 +108,6 @@ typedef double(*VCS_FUNC_PTR)(double xval, double Vtarget,
//! determine the l2 norm of a vector of doubles
/*!
* @param vec vector of doubles
*
* @return Returns the l2 norm of the vector
*/
double vcs_l2norm(const vector_fp vec);
@ -120,13 +119,12 @@ double vcs_l2norm(const vector_fp vec);
* before making the decision. Ignored if set to NULL.
* @param j lowest index to search from
* @param n highest index to search from
* @return Return index of the greatest value on X(i) searched
* j <= i < n
* @returns index of the greatest value on X(i) searched, j <= i < n
*/
size_t vcs_optMax(const double* x, const double* xSize, size_t j, size_t n);
//! Returns a const char string representing the type of the
//! species given by the first argument
//! Returns a const char string representing the type of the species given by
//! the first argument
/*!
* @param speciesStatus Species status integer representing the type
* of the species.
@ -138,28 +136,27 @@ const char* vcs_speciesType_string(int speciesStatus, int length = 100);
//! Print a string within a given space limit
/*!
* This routine limits the amount of the string that will be printed to a
* maximum of "space" characters. Printing is done to
* to Cantera's writelog() function.
* This routine limits the amount of the string that will be printed to a
* maximum of "space" characters. Printing is done to to Cantera's writelog()
* function.
*
* @param str String, which must be null terminated.
* @param space space limit for the printing.
* @param alignment Alignment of string within the space:
* - 0 centered
* - 1 right aligned
* - 2 left aligned
* @param str String, which must be null terminated.
* @param space space limit for the printing.
* @param alignment Alignment of string within the space:
* - 0 centered
* - 1 right aligned
* - 2 left aligned
*/
void vcs_print_stringTrunc(const char* str, size_t space, int alignment);
//! Simple routine to check whether two doubles are equal up to
//! roundoff error
//! Simple routine to check whether two doubles are equal up to roundoff error
/*!
* Currently it's set to check for 10 digits of relative accuracy.
* Currently it's set to check for 10 digits of relative accuracy.
*
* @param d1 first double
* @param d2 second double
*
* @return returns true if the doubles are "equal" and false otherwise
* @returns true if the doubles are "equal" and false otherwise
*/
bool vcs_doubleEqual(double d1, double d2);
}

View file

@ -24,10 +24,8 @@ class VCS_SPECIES_THERMO;
class VCS_PROB
{
public:
//! Problem type. I.e., the identity of what is held constant.
/*!
* Currently, T and P are held constant, and this input is ignored
*/
//! Problem type. I.e., the identity of what is held constant. Currently, T
//! and P are held constant, and this input is ignored
int prob_type;
//! Total number of species in the problems
@ -49,56 +47,50 @@ public:
//! Number of phases used to malloc data structures
size_t NPHASE0;
//! Vector of chemical potentials of the species
/*!
* This is a calculated output quantity. length = number of species.
* units = m_VCS_UnitsFormat
*/
//! Vector of chemical potentials of the species. This is a calculated
//! output quantity. length = number of species. units = m_VCS_UnitsFormat
vector_fp m_gibbsSpecies;
//! Total number of moles of the kth species.
//! Total number of moles of the kth species.
/*!
* This is both an input and an output variable.
* On input, this is an estimate of the mole numbers.
* The actual element abundance vector contains the problem specification.
* This is both an input and an output variable. On input, this is an
* estimate of the mole numbers. The actual element abundance vector
* contains the problem specification.
*
* On output, this contains the solution for the total number of moles
* of the kth species.
* On output, this contains the solution for the total number of moles of
* the kth species.
*
* units = m_VCS_UnitsFormat
*/
vector_fp w;
//! Mole fraction vector
/*!
* This is a calculated vector, calculated from w[].
* length number of species.
*/
//! Mole fraction vector. This is a calculated vector, calculated from w[].
//! length number of species.
vector_fp mf;
//! Element abundances for jth element
//! Element abundances for jth element
/*!
* This is input from the input file and is considered a constant from
* thereon within the vcs_solve_TP(). units = m_VCS_UnitsFormat
* This is input from the input file and is considered a constant from
* thereon within the vcs_solve_TP(). units = m_VCS_UnitsFormat
*/
vector_fp gai;
//! Formula Matrix for the problem
//! Formula Matrix for the problem
/*!
* FormulaMatrix(kspec,j) = Number of elements, j, in the kspec species
* FormulaMatrix(kspec,j) = Number of elements, j, in the kspec species
*/
Array2D FormulaMatrix;
//! Specifies the species unknown type
/*!
* There are two types. One is the straightforward species, with the
* mole number w[k], as the unknown. The second is the an interfacial
* voltage where w[k] refers to the interfacial voltage in volts.
* There are two types. One is the straightforward species, with the mole
* number w[k], as the unknown. The second is the an interfacial voltage
* where w[k] refers to the interfacial voltage in volts.
*
* These species types correspond to metallic electrons corresponding to
* electrodes. The voltage and other interfacial conditions sets up an
* interfacial current, which is set to zero in this initial treatment.
* Later we may have non-zero interfacial currents.
* These species types correspond to metallic electrons corresponding to
* electrodes. The voltage and other interfacial conditions sets up an
* interfacial current, which is set to zero in this initial treatment.
* Later we may have non-zero interfacial currents.
*/
vector_int SpeciesUnknownType;
@ -117,23 +109,23 @@ public:
//! Volume of the entire system
/*!
* units given by m_VCS_UnitsFormat
* Note, this is an output variable atm
* units given by m_VCS_UnitsFormat
* Note, this is an output variable atm
*/
double Vol;
//! Partial Molar Volumes of species
/*!
* This is a calculated vector, calculated from w[].
* length number of species.
* length number of species.
*/
vector_fp VolPM;
//! Units for the chemical potential data, pressure data, volume,
//! and species amounts
//! Units for the chemical potential data, pressure data, volume, and
//! species amounts
/*!
* All internally stored quantities will have these units. Also, printed
* quantities will display in these units.
* All internally stored quantities will have these units. Also, printed
* quantities will display in these units.
*
* | | | Chem_Pot | Pres | vol | moles|
* |---|----------------------|-------------------------|------|-------|------|
@ -158,7 +150,7 @@ public:
//! Tolerance requirement for major species
double tolmaj;
//! Tolerance requirement for minor species
//! Tolerance requirement for minor species
double tolmin;
//! Mapping between the species and the phases
@ -214,8 +206,8 @@ public:
//! Constructor
/*!
* This constructor initializes the sizes within the object
* to parameter values.
* This constructor initializes the sizes within the object to parameter
* values.
*
* @param nsp number of species
* @param nel number of elements
@ -227,42 +219,42 @@ public:
//! Resizes all of the phase lists within the structure
/*!
* Note, this doesn't change the number of phases in the problem.
* It will change #NPHASE0 if `nPhase` is greater than #NPHASE0.
* Note, this doesn't change the number of phases in the problem. It will
* change #NPHASE0 if `nPhase` is greater than #NPHASE0.
*
* @param nPhase size to dimension all the phase lists to
* @param force If true, this will dimension the size to be equal to `nPhase`
* even if `nPhase` is less than the current value of NPHASE0
* @param nPhase size to dimension all the phase lists to
* @param force If true, this will dimension the size to be equal to
* `nPhase` even if `nPhase` is less than the current value of NPHASE0
*/
void resizePhase(size_t nPhase, int force);
//! Resizes all of the species lists within the structure
/*!
* Note, this doesn't change the number of species in the problem.
* It will change #NSPECIES0 if `nsp` is greater than #NSPECIES0.
* Note, this doesn't change the number of species in the problem.
* It will change #NSPECIES0 if `nsp` is greater than #NSPECIES0.
*
* @param nsp size to dimension all the species lists to
* @param force If true, this will dimension the size to be equal to `nsp`
* even if `nsp` is less than the current value of #NSPECIES0
* @param nsp size to dimension all the species lists to
* @param force If true, this will dimension the size to be equal to `nsp`
* even if `nsp` is less than the current value of #NSPECIES0
*/
void resizeSpecies(size_t nsp, int force);
//! Resizes all of the element lists within the structure
/*!
* Note, this doesn't change the number of element constraints in the
* problem. It will change #NE0 if `nel` is greater than #NE0.
* Note, this doesn't change the number of element constraints in the
* problem. It will change #NE0 if `nel` is greater than #NE0.
*
* @param nel size to dimension all the elements lists
* @param force If true, this will dimension the size to be equal to `nel`
* even if `nel` is less than the current value of #NE0
* @param nel size to dimension all the elements lists
* @param force If true, this will dimension the size to be equal to `nel`
* even if `nel` is less than the current value of #NE0
*/
void resizeElements(size_t nel, int force);
//! Calculate the element abundance vector from the mole numbers
void set_gai();
//! Print out the problem specification in all generality
//! as it currently exists in the VCS_PROB object
//! Print out the problem specification in all generality as it currently
//! exists in the VCS_PROB object
/*!
* @param print_lvl Parameter lvl for printing
* * 0 - no printing
@ -272,47 +264,44 @@ public:
//! Add elements to the local element list
/*!
* This routine sorts through the elements defined in the vcs_VolPhase
* object. It then adds the new elements to the VCS_PROB object, and
* creates a global map, which is stored in the vcs_VolPhase object. Id
* and matching of elements is done strictly via the element name, with
* case not mattering.
* This routine sorts through the elements defined in the vcs_VolPhase
* object. It then adds the new elements to the VCS_PROB object, and creates
* a global map, which is stored in the vcs_VolPhase object. Id and matching
* of elements is done strictly via the element name, with case not
* mattering.
*
* The routine also fills in the position of the element
* in the vcs_VolPhase object's ElGlobalIndex field.
* The routine also fills in the position of the element in the vcs_VolPhase
* object's ElGlobalIndex field.
*
* @param volPhase Object containing the phase to be added.
* The elements in this phase are parsed for
* addition to the global element list
* @param volPhase Object containing the phase to be added. The elements in
* this phase are parsed for addition to the global element list
*/
void addPhaseElements(vcs_VolPhase* volPhase);
//! This routine resizes the number of elements in the VCS_PROB object by
//! adding a new element to the end of the element list
//! This routine resizes the number of elements in the VCS_PROB object by
//! adding a new element to the end of the element list
/*!
* The element name is added. Formula vector entries ang element
* abundances for the new element are set to zero.
* The element name is added. Formula vector entries ang element abundances
* for the new element are set to zero.
*
* Returns the index number of the new element.
*
* @param elNameNew New name of the element
* @param elType Type of the element
* @param elactive boolean indicating whether the element is active
* @return returns the index number of the new element
* @param elNameNew New name of the element
* @param elType Type of the element
* @param elactive boolean indicating whether the element is active
* @returns the index number of the new element
*/
size_t addElement(const char* elNameNew, int elType, int elactive);
//! This routines adds entries for the formula matrix for one species
/*!
* This routines adds entries for the formula matrix for this object
* for one species
* This routines adds entries for the formula matrix for this object for one
* species
*
* This object also fills in the index filed, IndSpecies, within
* the volPhase object.
* This object also fills in the index filed, IndSpecies, within the
* volPhase object.
*
* @param volPhase object containing the species
* @param k Species number within the volPhase k
* @param kT global Species number within this object
* @param volPhase object containing the species
* @param k Species number within the volPhase k
* @param kT global Species number within this object
*
*/
size_t addOnePhaseSpecies(vcs_VolPhase* volPhase, size_t k, size_t kT);
@ -321,7 +310,7 @@ public:
//! Set the debug level
/*!
* @param vcs_debug_print_lvl input debug level
* @param vcs_debug_print_lvl input debug level
*/
void setDebugPrintLvl(int vcs_debug_print_lvl);
};

File diff suppressed because it is too large Load diff

View file

@ -28,10 +28,10 @@ class vcs_VolPhase;
#define VCS_SSSTAR_IDEAL_GAS 1
/*!
* Identifies the thermo model for the species. This structure is shared by
* volumetric and surface species. However, each will have its own types of
* thermodynamic models. These quantities all have appropriate units. The
* units are specified by VCS_UnitsFormat.
* Identifies the thermo model for the species. This structure is shared by
* volumetric and surface species. However, each will have its own types of
* thermodynamic models. These quantities all have appropriate units. The units
* are specified by VCS_UnitsFormat.
*/
class VCS_SPECIES_THERMO
{
@ -48,9 +48,8 @@ public:
//! Pointer to the owning phase object.
vcs_VolPhase* OwningPhase;
//! Integer representing the models for the species standard state
//! Naught temperature dependence. They are listed above and start
//! with VCS_SS0_...
//! Integer representing the models for the species standard state Naught
//! temperature dependence. They are listed above and start with VCS_SS0_...
int SS0_Model;
//! Internal storage of the last calculation of the reference naught Gibbs
@ -74,7 +73,7 @@ public:
double SS0_Cp0;
//! Value of the pressure for the reference state.
//! defaults to 1.01325E5 = 1 atm
//! defaults to 1.01325E5 = 1 atm
double SS0_Pref;
//! Integer value representing the star state model.
@ -104,25 +103,23 @@ public:
* @param kspec species global index
* @param TKelvin Temperature in Kelvin
* @param pres pressure is given in units specified by if__ variable.
*
* @return standard state free energy in units of Kelvin.
*/
virtual double GStar_R_calc(size_t kspec, double TKelvin, double pres);
/**
* This function calculates the standard state Gibbs free energy
* for species, kspec, at the temperature TKelvin
* This function calculates the standard state Gibbs free energy for
* species, kspec, at the temperature TKelvin
*
* @param kglob species global index.
* @param TKelvin Temperature in Kelvin
*
* @return standard state free energy in Kelvin.
* @param kglob species global index.
* @param TKelvin Temperature in Kelvin
* @return standard state free energy in Kelvin.
*/
virtual double G0_R_calc(size_t kglob, double TKelvin);
/**
* This function calculates the standard state molar volume
* for species, kspec, at the temperature TKelvin and pressure, Pres,
* This function calculates the standard state molar volume for species,
* kspec, at the temperature TKelvin and pressure, Pres,
*
* @return standard state volume in cm**3 per mol.
* (if__=3) m**3 / kmol
@ -130,15 +127,13 @@ public:
virtual double VolStar_calc(size_t kglob, double TKelvin, double Pres);
/**
* This function evaluates the activity coefficient for species, kspec
* This function evaluates the activity coefficient for species, kspec
*
* @param kspec index of the species in the global species list within
* VCS_SOLVE. Phase and local species id can be looked up
* within object.
*
* Note, T, P and mole fractions are obtained from the
* single private instance of VCS_SOLVE
* Note, T, P and mole fractions are obtained from the single private
* instance of VCS_SOLVE
*
* @param kspec index of the species in the global species list within
* VCS_SOLVE. Phase and local species id can be looked up within object.
* @return activity coefficient for species kspec
*/
virtual double eval_ac(size_t kspec);

View file

@ -37,10 +37,9 @@ vcs_MultiPhaseEquil::vcs_MultiPhaseEquil(MultiPhase* mix, int printLvl) :
{
m_mix = mix;
m_vprob.m_printLvl = m_printLvl;
/*
* Work out the details of the VCS_VPROB construction and
* Transfer the current problem to VCS_PROB object
*/
// Work out the details of the VCS_VPROB construction and Transfer the
// current problem to VCS_PROB object
int res = vcs_Cantera_to_vprob(mix, &m_vprob);
if (res != 0) {
plogf("problems\n");
@ -205,8 +204,8 @@ int vcs_MultiPhaseEquil::equilibrate_HP(doublereal Htarget,
Hlow = Hnow;
}
} else {
// the current enthalpy is greater than the target; therefore the
// current temperature is too high. Set the high bounds.
// the current enthalpy is greater than the target; therefore
// the current temperature is too high. Set the high bounds.
if (Tnow < Thigh) {
Thigh = Tnow;
Hhigh = Hnow;
@ -329,8 +328,8 @@ int vcs_MultiPhaseEquil::equilibrate_SP(doublereal Starget,
}
}
} else {
// the current enthalpy is greater than the target; therefore the
// current temperature is too high. Set the high bounds.
// the current enthalpy is greater than the target; therefore
// the current temperature is too high. Set the high bounds.
if (Tnow < Thigh) {
Thigh = Tnow;
Shigh = Snow;
@ -449,11 +448,8 @@ int vcs_MultiPhaseEquil::equilibrate_TP(int estimateEquil,
m_printLvl = printLvl;
m_vprob.m_printLvl = printLvl;
/*
* Extract the current state information
* from the MultiPhase object and
* Transfer it to VCS_PROB object.
*/
// Extract the current state information from the MultiPhase object and
// Transfer it to VCS_PROB object.
int res = vcs_Cantera_update_vprob(m_mix, &m_vprob);
if (res != 0) {
plogf("problems\n");
@ -466,9 +462,8 @@ int vcs_MultiPhaseEquil::equilibrate_TP(int estimateEquil,
m_vprob.iest = 0;
}
// Check obvious bounds on the temperature and pressure
// NOTE, we may want to do more here with the real bounds
// given by the ThermoPhase objects.
// Check obvious bounds on the temperature and pressure NOTE, we may want to
// do more here with the real bounds given by the ThermoPhase objects.
double T = m_mix->temperature();
if (T <= 0.0) {
throw CanteraError("vcs_MultiPhaseEquil::equilibrate",
@ -480,10 +475,8 @@ int vcs_MultiPhaseEquil::equilibrate_TP(int estimateEquil,
"Pressure less than zero on input");
}
/*
* Print out the problem specification from the point of
* view of the vprob object.
*/
// Print out the problem specification from the point of
// view of the vprob object.
m_vprob.prob_report(m_printLvl);
/*
@ -498,14 +491,11 @@ int vcs_MultiPhaseEquil::equilibrate_TP(int estimateEquil,
}
int iSuccess = m_vsolve.vcs(&m_vprob, 0, ipr, ip1, maxit);
/*
* Transfer the information back to the MultiPhase object.
* Note we don't just call setMoles, because some multispecies
* solution phases may be zeroed out, and that would cause a problem
* for that routine. Also, the mole fractions of such zeroed out
* phases actually contain information about likely reemergent
* states.
*/
// Transfer the information back to the MultiPhase object. Note we don't
// just call setMoles, because some multispecies solution phases may be
// zeroed out, and that would cause a problem for that routine. Also, the
// mole fractions of such zeroed out phases actually contain information
// about likely reemergent states.
m_mix->uploadMoleFractionsFromPhases();
size_t kGlob = 0;
for (size_t ip = 0; ip < m_vprob.NPhase; ip++) {
@ -705,9 +695,7 @@ void vcs_MultiPhaseEquil::reportCSV(const std::string& reportFile)
}
#ifdef DEBUG_MODE
/*
* Check consistency: These should be equal
*/
// Check consistency: These should be equal
tref.getChemPotentials(fe+istart);
for (size_t k = 0; k < nSpecies; k++) {
if (!vcs_doubleEqual(fe[istart+k], mu[k])) {
@ -722,17 +710,13 @@ void vcs_MultiPhaseEquil::reportCSV(const std::string& reportFile)
fclose(FP);
}
/*
* HKM -> Work on transferring the current value of the voltages into the
* equilibrium problem.
*/
// HKM -> Work on transferring the current value of the voltages into the
// equilibrium problem.
int vcs_Cantera_to_vprob(MultiPhase* mphase, VCS_PROB* vprob)
{
VCS_SPECIES_THERMO* ts_ptr = 0;
/*
* Calculate the total number of species and phases in the problem
*/
// Calculate the total number of species and phases in the problem
size_t totNumPhases = mphase->nPhases();
size_t totNumSpecies = mphase->nSpecies();
@ -752,65 +736,47 @@ int vcs_Cantera_to_vprob(MultiPhase* mphase, VCS_PROB* vprob)
int printLvl = vprob->m_printLvl;
/*
* Loop over the phases, transferring pertinent information
*/
// Loop over the phases, transferring pertinent information
int kT = 0;
for (size_t iphase = 0; iphase < totNumPhases; iphase++) {
/*
* Get the ThermoPhase object - assume volume phase
*/
// Get the ThermoPhase object - assume volume phase
ThermoPhase* tPhase = &mphase->phase(iphase);
size_t nelem = tPhase->nElements();
/*
* Query Cantera for the equation of state type of the
* current phase.
*/
// Query Cantera for the equation of state type of the current phase.
int eos = tPhase->eosType();
bool gasPhase = (eos == cIdealGas);
/*
* Find out the number of species in the phase
*/
// Find out the number of species in the phase
size_t nSpPhase = tPhase->nSpecies();
/*
* Find out the name of the phase
*/
// Find out the name of the phase
string phaseName = tPhase->name();
/*
* Call the basic vcs_VolPhase creation routine.
* Properties set here:
* ->PhaseNum = phase number in the thermo problem
* ->GasPhase = Boolean indicating whether it is a gas phase
* ->NumSpecies = number of species in the phase
* ->TMolesInert = Inerts in the phase = 0.0 for cantera
* ->PhaseName = Name of the phase
*/
// Call the basic vcs_VolPhase creation routine.
// Properties set here:
// ->PhaseNum = phase number in the thermo problem
// ->GasPhase = Boolean indicating whether it is a gas phase
// ->NumSpecies = number of species in the phase
// ->TMolesInert = Inerts in the phase = 0.0 for cantera
// ->PhaseName = Name of the phase
vcs_VolPhase* VolPhase = vprob->VPhaseList[iphase];
VolPhase->resize(iphase, nSpPhase, nelem, phaseName.c_str(), 0.0);
VolPhase->m_gasPhase = gasPhase;
/*
* Tell the vcs_VolPhase pointer about cantera
*/
// Tell the vcs_VolPhase pointer about cantera
VolPhase->p_VCS_UnitsFormat = vprob->m_VCS_UnitsFormat;
VolPhase->setPtrThermoPhase(tPhase);
VolPhase->setTotalMoles(0.0);
/*
* Set the electric potential of the volume phase from the
* ThermoPhase object's value.
*/
// Set the electric potential of the volume phase from the
// ThermoPhase object's value.
VolPhase->setElectricPotential(tPhase->electricPotential());
/*
* Query the ThermoPhase object to find out what convention
* it uses for the specification of activity and Standard State.
*/
// Query the ThermoPhase object to find out what convention
// it uses for the specification of activity and Standard State.
VolPhase->p_activityConvention = tPhase->activityConvention();
/*
* Assign the value of eqn of state
* -> Handle conflicts here.
*/
// Assign the value of eqn of state. Handle conflicts here.
switch (eos) {
case cIdealGas:
VolPhase->m_eqnState = VCS_EOS_IDEAL_GAS;
@ -843,62 +809,43 @@ int vcs_Cantera_to_vprob(MultiPhase* mphase, VCS_PROB* vprob)
break;
}
/*
* Transfer all of the element information from the
* ThermoPhase object to the vcs_VolPhase object.
* Also decide whether we need a new charge neutrality
* element in the phase to enforce a charge neutrality
* constraint.
* We also decide whether this is a single species phase
* with the voltage being the independent variable setting
* the chemical potential of the electrons.
*/
// Transfer all of the element information from the ThermoPhase object
// to the vcs_VolPhase object. Also decide whether we need a new charge
// neutrality element in the phase to enforce a charge neutrality
// constraint. We also decide whether this is a single species phase
// with the voltage being the independent variable setting the chemical
// potential of the electrons.
VolPhase->transferElementsFM(tPhase);
/*
* Combine the element information in the vcs_VolPhase
* object into the vprob object.
*/
// Combine the element information in the vcs_VolPhase
// object into the vprob object.
vprob->addPhaseElements(VolPhase);
VolPhase->setState_TP(vprob->T, vprob->PresPA);
vector_fp muPhase(tPhase->nSpecies(),0.0);
tPhase->getChemPotentials(&muPhase[0]);
double tMoles = 0.0;
/*
* Loop through each species in the current phase
*/
// Loop through each species in the current phase
for (size_t k = 0; k < nSpPhase; k++) {
/*
* Obtain the molecular weight of the species from the
* ThermoPhase object
*/
// Obtain the molecular weight of the species from the
// ThermoPhase object
vprob->WtSpecies[kT] = tPhase->molecularWeight(k);
/*
* Obtain the charges of the species from the
* ThermoPhase object
*/
// Obtain the charges of the species from the ThermoPhase object
vprob->Charge[kT] = tPhase->charge(k);
/*
* Set the phaseid of the species
*/
// Set the phaseid of the species
vprob->PhaseID[kT] = iphase;
/*
* Transfer the Species name
*/
// Transfer the Species name
string stmp = mphase->speciesName(kT);
vprob->SpName[kT] = stmp;
/*
* Transfer the type of unknown
*/
// Transfer the type of unknown
vprob->SpeciesUnknownType[kT] = VolPhase->speciesUnknownType(k);
if (vprob->SpeciesUnknownType[kT] == VCS_SPECIES_TYPE_MOLNUM) {
/*
* Set the initial number of kmoles of the species
* and the mole fraction vector
*/
// Set the initial number of kmoles of the species
// and the mole fraction vector
vprob->w[kT] = mphase->speciesMoles(kT);
tMoles += vprob->w[kT];
vprob->mf[kT] = mphase->moleFraction(kT);
@ -910,26 +857,20 @@ int vcs_Cantera_to_vprob(MultiPhase* mphase, VCS_PROB* vprob)
"Unknown species type: {}", vprob->SpeciesUnknownType[kT]);
}
/*
* transfer chemical potential vector
*/
// transfer chemical potential vector
vprob->m_gibbsSpecies[kT] = muPhase[k];
/*
* Transfer the species information from the
* volPhase structure to the VPROB structure
* This includes:
* FormulaMatrix[][]
* VolPhase->IndSpecies[]
*/
// Transfer the species information from the
// volPhase structure to the VPROB structure
// This includes:
// FormulaMatrix[][]
// VolPhase->IndSpecies[]
vprob->addOnePhaseSpecies(VolPhase, k, kT);
/*
* Get a pointer to the thermo object
*/
// Get a pointer to the thermo object
ts_ptr = vprob->SpeciesThermo[kT];
/*
* Fill in the vcs_SpeciesProperty structure
*/
// Fill in the vcs_SpeciesProperty structure
vcs_SpeciesProperties* sProp = VolPhase->speciesProperty(k);
sProp->NumElements = vprob->ne;
sProp->SpName = vprob->SpName[kT];
@ -943,20 +884,16 @@ int vcs_Cantera_to_vprob(MultiPhase* mphase, VCS_PROB* vprob)
sProp->SurfaceSpecies = false;
sProp->VolPM = 0.0;
/*
* Transfer the thermo specification of the species
* vprob->SpeciesThermo[]
*/
// Transfer the thermo specification of the species
// vprob->SpeciesThermo[]
ts_ptr->m_VCS_UnitsFormat = VolPhase->p_VCS_UnitsFormat;
/*
* Add lookback connectivity into the thermo object first
*/
// Add lookback connectivity into the thermo object first
ts_ptr->IndexPhase = iphase;
ts_ptr->IndexSpeciesPhase = k;
ts_ptr->OwningPhase = VolPhase;
/*
* get a reference to the Cantera species thermo.
*/
// get a reference to the Cantera species thermo.
SpeciesThermo& sp = tPhase->speciesThermo();
int spType = sp.reportType(k);
@ -985,13 +922,10 @@ int vcs_Cantera_to_vprob(MultiPhase* mphase, VCS_PROB* vprob)
ts_ptr->SSStar_Model = VCS_SSSTAR_NOTHANDLED;
}
/*
* Transfer the Volume Information -> NEEDS WORK
*/
// Transfer the Volume Information -> NEEDS WORK
if (gasPhase) {
ts_ptr->SSStar_Vol_Model = VCS_SSVOL_IDEALGAS;
ts_ptr->SSStar_Vol0 = 82.05 * 273.15 / 1.0;
} else {
vector_fp phaseTermCoeff(nSpPhase, 0.0);
int nCoeff;
@ -1002,21 +936,17 @@ int vcs_Cantera_to_vprob(MultiPhase* mphase, VCS_PROB* vprob)
kT++;
}
/*
* Now go back through the species in the phase and assign
* a valid mole fraction to all phases, even if the initial
* estimate of the total number of moles is zero.
*/
// Now go back through the species in the phase and assign a valid mole
// fraction to all phases, even if the initial estimate of the total
// number of moles is zero.
if (tMoles > 0.0) {
for (size_t k = 0; k < nSpPhase; k++) {
size_t kTa = VolPhase->spGlobalIndexVCS(k);
vprob->mf[kTa] = vprob->w[kTa] / tMoles;
}
} else {
/*
* Perhaps, we could do a more sophisticated treatment below.
* But, will start with this.
*/
// Perhaps, we could do a more sophisticated treatment below.
// But, will start with this.
for (size_t k = 0; k < nSpPhase; k++) {
size_t kTa = VolPhase->spGlobalIndexVCS(k);
vprob->mf[kTa]= 1.0 / (double) nSpPhase;
@ -1024,10 +954,9 @@ int vcs_Cantera_to_vprob(MultiPhase* mphase, VCS_PROB* vprob)
}
VolPhase->setMolesFromVCS(VCS_STATECALC_OLD, &vprob->w[0]);
/*
* Now, calculate a sample naught Gibbs free energy calculation
* at the specified temperature.
*/
// Now, calculate a sample naught Gibbs free energy calculation
// at the specified temperature.
double R = vcsUtil_gasConstant(vprob->m_VCS_UnitsFormat);
for (size_t k = 0; k < nSpPhase; k++) {
vcs_SpeciesProperties* sProp = VolPhase->speciesProperty(k);
@ -1037,16 +966,12 @@ int vcs_Cantera_to_vprob(MultiPhase* mphase, VCS_PROB* vprob)
}
}
/*
* Transfer initial element abundances to the vprob object.
* We have to find the mapping index from one to the other
*/
// Transfer initial element abundances to the vprob object.
// We have to find the mapping index from one to the other
vprob->gai.resize(vprob->ne, 0.0);
vprob->set_gai();
/*
* Printout the species information: PhaseID's and mole nums
*/
// Printout the species information: PhaseID's and mole nums
if (vprob->m_printLvl > 1) {
writeline('=', 80, true, true);
writeline('=', 16, false);
@ -1069,9 +994,7 @@ int vcs_Cantera_to_vprob(MultiPhase* mphase, VCS_PROB* vprob)
}
}
/*
* Printout of the Phase structure information
*/
// Printout of the Phase structure information
writeline('-', 80, true, true);
plogf(" Information about phases\n");
plogf(" PhaseName PhaseNum SingSpec GasPhase EqnState NumSpec");
@ -1114,18 +1037,16 @@ int vcs_Cantera_update_vprob(MultiPhase* mphase, VCS_PROB* vprob)
for (size_t iphase = 0; iphase < totNumPhases; iphase++) {
ThermoPhase* tPhase = &mphase->phase(iphase);
vcs_VolPhase* volPhase = vprob->VPhaseList[iphase];
/*
* Set the electric potential of the volume phase from the
* ThermoPhase object's value.
*/
// Set the electric potential of the volume phase from the
// ThermoPhase object's value.
volPhase->setElectricPotential(tPhase->electricPotential());
volPhase->setState_TP(vprob->T, vprob->PresPA);
vector_fp muPhase(tPhase->nSpecies(),0.0);
tPhase->getChemPotentials(&muPhase[0]);
/*
* Loop through each species in the current phase
*/
// Loop through each species in the current phase
size_t nSpPhase = tPhase->nSpecies();
tmpMoles.resize(nSpPhase);
for (size_t k = 0; k < nSpPhase; k++) {
@ -1133,9 +1054,7 @@ int vcs_Cantera_update_vprob(MultiPhase* mphase, VCS_PROB* vprob)
vprob->w[kT] = mphase->speciesMoles(kT);
vprob->mf[kT] = mphase->moleFraction(kT);
/*
* transfer chemical potential vector
*/
// transfer chemical potential vector
vprob->m_gibbsSpecies[kT] = muPhase[k];
kT++;
@ -1154,18 +1073,14 @@ int vcs_Cantera_update_vprob(MultiPhase* mphase, VCS_PROB* vprob)
volPhase->setExistence(VCS_PHASE_EXIST_NO);
}
}
/*
* Transfer initial element abundances to the vprob object.
* Put them in the front of the object. There may be
* more constraints than there are elements. But, we
* know the element abundances are in the front of the
* vector.
*/
// Transfer initial element abundances to the vprob object. Put them in the
// front of the object. There may be more constraints than there are
// elements. But, we know the element abundances are in the front of the
// vector.
vprob->set_gai();
/*
* Printout the species information: PhaseID's and mole nums
*/
// Printout the species information: PhaseID's and mole nums
if (vprob->m_printLvl > 1) {
writeline('=', 80, true, true);
writeline('=', 20, false);
@ -1188,9 +1103,7 @@ int vcs_Cantera_update_vprob(MultiPhase* mphase, VCS_PROB* vprob)
}
}
/*
* Printout of the Phase structure information
*/
// Printout of the Phase structure information
writeline('-', 80, true, true);
plogf(" Information about phases\n");
plogf(" PhaseName PhaseNum SingSpec GasPhase EqnState NumSpec");
@ -1262,11 +1175,8 @@ int vcs_MultiPhaseEquil::determine_PhaseStability(int iph, double& funcStab, int
m_printLvl = printLvl;
m_vprob.m_printLvl = printLvl;
/*
* Extract the current state information
* from the MultiPhase object and
* Transfer it to VCS_PROB object.
*/
// Extract the current state information from the MultiPhase object and
// Transfer it to VCS_PROB object.
int res = vcs_Cantera_update_vprob(m_mix, &m_vprob);
if (res != 0) {
plogf("problems\n");
@ -1286,25 +1196,18 @@ int vcs_MultiPhaseEquil::determine_PhaseStability(int iph, double& funcStab, int
"Pressure less than zero on input");
}
/*
* Print out the problem specification from the point of
* view of the vprob object.
*/
// Print out the problem specification from the point of
// view of the vprob object.
m_vprob.prob_report(m_printLvl);
/*
* Call the thermo Program
*/
// Call the thermo Program
int iStable = m_vsolve.vcs_PS(&m_vprob, iph, printLvl, funcStab);
/*
* Transfer the information back to the MultiPhase object.
* Note we don't just call setMoles, because some multispecies
* solution phases may be zeroed out, and that would cause a problem
* for that routine. Also, the mole fractions of such zeroed out
* phases actually contain information about likely reemergent
* states.
*/
// Transfer the information back to the MultiPhase object. Note we don't
// just call setMoles, because some multispecies solution phases may be
// zeroed out, and that would cause a problem for that routine. Also, the
// mole fractions of such zeroed out phases actually contain information
// about likely reemergent states.
m_mix->uploadMoleFractionsFromPhases();
m_mix->getChemPotentials(m_vprob.m_gibbsSpecies.data());

View file

@ -6,68 +6,52 @@ namespace Cantera
{
int VCS_SOLVE::vcs_TP(int ipr, int ip1, int maxit, double T_arg, double pres_arg)
{
/*
* Store the temperature and pressure in the private global variables
*/
// Store the temperature and pressure in the private global variables
m_temperature = T_arg;
m_pressurePA = pres_arg;
/*
* Evaluate the standard state free energies
* at the current temperatures and pressures.
*/
// Evaluate the standard state free energies
// at the current temperatures and pressures.
int iconv = vcs_evalSS_TP(ipr, ip1, m_temperature, pres_arg);
/*
* Prepare the problem data:
* ->nondimensionalize the free energies using
* the divisor, R * T
*/
// Prepare the problem data: nondimensionalize the free energies using the
// divisor, R * T
vcs_nondim_TP();
/*
* Prep the fe field
*/
// Prep the fe field
vcs_fePrep_TP();
/*
* Decide whether we need an initial estimate of the solution
* If so, go get one. If not, then
*/
// Decide whether we need an initial estimate of the solution If so, go get
// one. If not, then
if (m_doEstimateEquil) {
int retn = vcs_inest_TP();
if (retn != VCS_SUCCESS) {
plogf("vcs_inest_TP returned a failure flag\n");
}
}
/*
* Solve the problem at a fixed Temperature and Pressure
* (all information concerning Temperature and Pressure has already
* been derived. The free energies are now in dimensionless form.)
*/
// Solve the problem at a fixed Temperature and Pressure (all information
// concerning Temperature and Pressure has already been derived. The free
// energies are now in dimensionless form.)
iconv = vcs_solve_TP(ipr, ip1, maxit);
/*
* Redimensionalize the free energies using
* the reverse of vcs_nondim to add back units.
*/
// Redimensionalize the free energies using the reverse of vcs_nondim to add
// back units.
vcs_redim_TP();
/*
* Return the convergence success flag.
*/
// Return the convergence success flag.
return iconv;
}
int VCS_SOLVE::vcs_evalSS_TP(int ipr, int ip1, double Temp, double pres)
{
/*
* We need to special case VCS_UNITS_UNITLESS, here.
* cpc_ts_GStar_calc() returns units of Kelvin. Also, the temperature
* comes into play in calculating the ideal equation of state
* contributions, and other equations of state also. Therefore,
* we will emulate the VCS_UNITS_KELVIN case, here by changing
* the initial Gibbs free energy units to Kelvin before feeding
* them to the cpc_ts_GStar_calc() routine. Then, we will revert
* them back to unitless at the end of this routine.
*/
// We need to special case VCS_UNITS_UNITLESS, here. cpc_ts_GStar_calc()
// returns units of Kelvin. Also, the temperature comes into play in
// calculating the ideal equation of state contributions, and other
// equations of state also. Therefore, we will emulate the VCS_UNITS_KELVIN
// case, here by changing the initial Gibbs free energy units to Kelvin
// before feeding them to the cpc_ts_GStar_calc() routine. Then, we will
// revert them back to unitless at the end of this routine.
for (size_t iph = 0; iph < m_numPhases; iph++) {
vcs_VolPhase* vph = m_VolPhaseList[iph];
vph->setState_TP(m_temperature, m_pressurePA);
@ -85,11 +69,9 @@ int VCS_SOLVE::vcs_evalSS_TP(int ipr, int ip1, double Temp, double pres)
void VCS_SOLVE::vcs_fePrep_TP()
{
for (size_t i = 0; i < m_numSpeciesTot; ++i) {
/*
* For single species phases, initialize the chemical
* potential with the value of the standard state chemical
* potential. This value doesn't change during the calculation
*/
// For single species phases, initialize the chemical potential with the
// value of the standard state chemical potential. This value doesn't
// change during the calculation
if (m_SSPhase[i]) {
m_feSpecies_old[i] = m_SSfeSpecies[i];
m_feSpecies_new[i] = m_SSfeSpecies[i];

View file

@ -134,9 +134,8 @@ vcs_VolPhase& vcs_VolPhase::operator=(const vcs_VolPhase& b)
m_isIdealSoln = b.m_isIdealSoln;
m_existence = b.m_existence;
m_MFStartIndex = b.m_MFStartIndex;
/*
* Do a shallow copy because we haven' figured this out.
*/
// Do a shallow copy because we haven' figured this out.
IndSpecies = b.IndSpecies;
for (size_t k = 0; k < old_num; k++) {
@ -150,13 +149,13 @@ vcs_VolPhase& vcs_VolPhase::operator=(const vcs_VolPhase& b)
ListSpeciesPtr[k] =
new vcs_SpeciesProperties(*(b.ListSpeciesPtr[k]));
}
/*
* Do a shallow copy of the ThermoPhase object pointer.
* We don't duplicate the object.
* Um, there is no reason we couldn't do a
* duplicateMyselfAsThermoPhase() call here. This will
* have to be looked into.
*/
// Do a shallow copy of the ThermoPhase object pointer. We don't
// duplicate the object.
//
// Um, there is no reason we couldn't do a
// duplicateMyselfAsThermoPhase() call here. This will have to be looked
// into.
TP_ptr = b.TP_ptr;
v_totalMoles = b.v_totalMoles;
Xmol_ = b.Xmol_;
@ -466,10 +465,9 @@ void vcs_VolPhase::setMolesFromVCS(const int stateCalc,
// This is currently unimplemented.
m_existence = VCS_PHASE_EXIST_NO;
}
/*
* Update the electric potential if it is a solution variable
* in the equation system
*/
// Update the electric potential if it is a solution variable in the
// equation system
if (m_phiVarIndex != npos) {
size_t kglob = IndSpecies[m_phiVarIndex];
if (m_numSpecies == 1) {
@ -488,18 +486,14 @@ void vcs_VolPhase::setMolesFromVCS(const int stateCalc,
m_existence = VCS_PHASE_EXIST_ALWAYS;
}
/*
* If stateCalc is old and the total moles is positive,
* then we have a valid state. If the phase went away, it would
* be a valid starting point for F_k's. So, save the state.
*/
// If stateCalc is old and the total moles is positive, then we have a valid
// state. If the phase went away, it would be a valid starting point for
// F_k's. So, save the state.
if (stateCalc == VCS_STATECALC_OLD && v_totalMoles > 0.0) {
creationMoleNumbers_ = Xmol_;
}
/*
* Set flags indicating we are up to date with the VCS state vector.
*/
// Set flags indicating we are up to date with the VCS state vector.
m_UpToDate = true;
m_vcsStateStatus = stateCalc;
}
@ -509,9 +503,8 @@ void vcs_VolPhase::setMolesFromVCSCheck(const int vcsStateStatus,
const double* const TPhMoles)
{
setMolesFromVCS(vcsStateStatus, molesSpeciesVCS);
/*
* Check for consistency with TPhMoles[]
*/
// Check for consistency with TPhMoles[]
double Tcheck = TPhMoles[VP_ID_];
if (Tcheck != v_totalMoles) {
if (vcs_doubleEqual(Tcheck, v_totalMoles)) {
@ -646,9 +639,7 @@ void vcs_VolPhase::_updateLnActCoeffJac()
phaseTotalMoles = 1.0;
}
/*
* Evaluate the current base activity coefficients if necessary
*/
// Evaluate the current base activity coefficients if necessary
if (!m_UpToDate_AC) {
_updateActCoeff();
}
@ -673,45 +664,34 @@ void vcs_VolPhase::_updateLnActCoeffJac()
vector_fp Xmol_Base(Xmol_);
double TMoles_base = phaseTotalMoles;
/*
* Loop over the columns species to be deltad
*/
// Loop over the columns species to be deltad
for (size_t j = 0; j < m_numSpecies; j++) {
/*
* Calculate a value for the delta moles of species j
* -> Note Xmol_[] and Tmoles are always positive or zero
* quantities.
*/
// Calculate a value for the delta moles of species j. Note Xmol_[] and
// Tmoles are always positive or zero quantities.
double moles_j_base = phaseTotalMoles * Xmol_Base[j];
deltaMoles_j = 1.0E-7 * moles_j_base + 1.0E-13 * phaseTotalMoles + 1.0E-150;
/*
* Now, update the total moles in the phase and all of the
* mole fractions based on this.
*/
// Now, update the total moles in the phase and all of the mole
// fractions based on this.
phaseTotalMoles = TMoles_base + deltaMoles_j;
for (size_t k = 0; k < m_numSpecies; k++) {
Xmol_[k] = Xmol_Base[k] * TMoles_base / phaseTotalMoles;
}
Xmol_[j] = (moles_j_base + deltaMoles_j) / phaseTotalMoles;
/*
* Go get new values for the activity coefficients.
* -> Note this calls setState_PX();
*/
// Go get new values for the activity coefficients. Note this calls
// setState_PX();
_updateMoleFractionDependencies();
_updateActCoeff();
/*
* Revert to the base case Xmol_, v_totalMoles
*/
// Revert to the base case Xmol_, v_totalMoles
v_totalMoles = TMoles_base;
Xmol_ = Xmol_Base;
}
/*
* Go get base values for the activity coefficients.
* -> Note this calls setState_TPX() again;
* -> Just wanted to make sure that cantera is in sync
* with VolPhase after this call.
*/
// Go get base values for the activity coefficients. Note this calls
// setState_TPX() again; Just wanted to make sure that cantera is in sync
// with VolPhase after this call.
setMoleFractions(&Xmol_Base[0]);
_updateMoleFractionDependencies();
_updateActCoeff();
@ -719,16 +699,11 @@ void vcs_VolPhase::_updateLnActCoeffJac()
void vcs_VolPhase::sendToVCS_LnActCoeffJac(Array2D& np_LnACJac_VCS)
{
/*
* update the Ln Act Coeff Jacobian entries with respect to the
* mole number of species in the phase -> we always assume that
* they are out of date.
*/
// update the Ln Act Coeff Jacobian entries with respect to the mole number
// of species in the phase -> we always assume that they are out of date.
_updateLnActCoeffJac();
/*
* Now copy over the values
*/
// Now copy over the values
for (size_t j = 0; j < m_numSpecies; j++) {
size_t jglob = IndSpecies[j];
for (size_t k = 0; k < m_numSpecies; k++) {
@ -758,9 +733,7 @@ void vcs_VolPhase::setPtrThermoPhase(ThermoPhase* tp_ptr)
creationMoleNumbers_ = Xmol_;
_updateMoleFractionDependencies();
/*
* figure out ideal solution tag
*/
// figure out ideal solution tag
if (nsp == 1) {
m_isIdealSoln = true;
} else {
@ -1015,12 +988,10 @@ static bool hasChargedSpecies(const ThermoPhase* const tPhase)
return false;
}
/*!
* This utility routine decides whether a Cantera ThermoPhase needs
* a constraint equation representing the charge neutrality of the
* phase. It does this by searching for charged species. If it
* finds one, and if the phase needs one, then it returns true.
*/
//! This utility routine decides whether a Cantera ThermoPhase needs
//! a constraint equation representing the charge neutrality of the
//! phase. It does this by searching for charged species. If it
//! finds one, and if the phase needs one, then it returns true.
static bool chargeNeutralityElement(const ThermoPhase* const tPhase)
{
int hasCharge = hasChargedSpecies(tPhase);
@ -1036,19 +1007,15 @@ size_t vcs_VolPhase::transferElementsFM(const ThermoPhase* const tPhase)
size_t ne = nebase;
size_t ns = tPhase->nSpecies();
/*
* Decide whether we need an extra element constraint for charge
* neutrality of the phase
*/
// Decide whether we need an extra element constraint for charge
// neutrality of the phase
bool cne = chargeNeutralityElement(tPhase);
if (cne) {
ChargeNeutralityElement = ne;
ne++;
}
/*
* Assign and malloc structures
*/
// Assign and malloc structures
elemResize(ne);
if (ChargeNeutralityElement != npos) {
@ -1058,15 +1025,12 @@ size_t vcs_VolPhase::transferElementsFM(const ThermoPhase* const tPhase)
size_t eFound = npos;
if (hasChargedSpecies(tPhase)) {
if (cne) {
/*
* We need a charge neutrality constraint.
* We also have an Electron Element. These are
* duplicates of each other. To avoid trouble with
* possible range error conflicts, sometimes we eliminate
* the Electron condition. Flag that condition for elimination
* by toggling the ElActive variable. If we find we need it
* later, we will retoggle ElActive to true.
*/
// We need a charge neutrality constraint. We also have an Electron
// Element. These are duplicates of each other. To avoid trouble
// with possible range error conflicts, sometimes we eliminate the
// Electron condition. Flag that condition for elimination by
// toggling the ElActive variable. If we find we need it later, we
// will retoggle ElActive to true.
for (size_t eT = 0; eT < nebase; eT++) {
if (tPhase->elementName(eT) == "E") {
eFound = eT;
@ -1132,11 +1096,9 @@ size_t vcs_VolPhase::transferElementsFM(const ThermoPhase* const tPhase)
}
}
/*
* Here, we figure out what is the species types are
* The logic isn't set in stone, and is just for a particular type
* of problem that I'm solving first.
*/
// Here, we figure out what is the species types are The logic isn't set in
// stone, and is just for a particular type of problem that I'm solving
// first.
if (ns == 1 && tPhase->charge(0) != 0.0) {
m_speciesUnknownType[0] = VCS_SPECIES_TYPE_INTERFACIALVOLTAGE;
setPhiVarIndex(0);

View file

@ -28,14 +28,11 @@ bool VCS_SOLVE::vcs_elabcheck(int ibound)
if (ibound) {
top = m_numElemConstraints;
}
/*
* Require 12 digits of accuracy on non-zero constraints.
*/
for (size_t i = 0; i < top; ++i) {
// Require 12 digits of accuracy on non-zero constraints.
if (m_elementActive[i] && fabs(m_elemAbundances[i] - m_elemAbundancesGoal[i]) > fabs(m_elemAbundancesGoal[i]) * 1.0e-12) {
/*
* This logic is for charge neutrality condition
*/
// This logic is for charge neutrality condition
if (m_elType[i] == VCS_ELEM_TYPE_CHARGENEUTRALITY &&
m_elemAbundancesGoal[i] != 0.0) {
throw CanteraError("VCS_SOLVE::vcs_elabcheck",
@ -43,12 +40,11 @@ bool VCS_SOLVE::vcs_elabcheck(int ibound)
}
if (m_elemAbundancesGoal[i] == 0.0 || (m_elType[i] == VCS_ELEM_TYPE_ELECTRONCHARGE)) {
double scale = VCS_DELETE_MINORSPECIES_CUTOFF;
/*
* Find out if the constraint is a multisign constraint.
* If it is, then we have to worry about roundoff error
* in the addition of terms. We are limited to 13
* digits of finite arithmetic accuracy.
*/
// Find out if the constraint is a multisign constraint. If it
// is, then we have to worry about roundoff error in the
// addition of terms. We are limited to 13 digits of finite
// arithmetic accuracy.
bool multisign = false;
for (size_t kspec = 0; kspec < m_numSpeciesTot; kspec++) {
double eval = m_formulaMatrix(kspec,i);
@ -69,10 +65,8 @@ bool VCS_SOLVE::vcs_elabcheck(int ibound)
}
}
} else {
/*
* For normal element balances, we require absolute compliance
* even for ridiculously small numbers.
*/
// For normal element balances, we require absolute compliance
// even for ridiculously small numbers.
if (m_elType[i] == VCS_ELEM_TYPE_ABSPOS) {
return false;
} else {
@ -120,12 +114,9 @@ int VCS_SOLVE::vcs_elcorr(double aa[], double x[])
l2before = sqrt(l2before/m_numElemConstraints);
#endif
/*
* Special section to take out single species, single component,
* moles. These are species which have non-zero entries in the
* formula matrix, and no other species have zero values either.
*
*/
// Special section to take out single species, single component,
// moles. These are species which have non-zero entries in the
// formula matrix, and no other species have zero values either.
bool changed = false;
for (size_t i = 0; i < m_numElemConstraints; ++i) {
int numNonZero = 0;
@ -182,15 +173,13 @@ int VCS_SOLVE::vcs_elcorr(double aa[], double x[])
vcs_elab();
}
/*
* Section to check for maximum bounds errors on all species
* due to elements.
* This may only be tried on element types which are VCS_ELEM_TYPE_ABSPOS.
* This is because no other species may have a negative number of these.
*
* Note, also we can do this over ne, the number of elements, not just
* the number of components.
*/
// Section to check for maximum bounds errors on all species due to
// elements. This may only be tried on element types which are
// VCS_ELEM_TYPE_ABSPOS. This is because no other species may have a
// negative number of these.
//
// Note, also we can do this over ne, the number of elements, not just the
// number of components.
changed = false;
for (size_t i = 0; i < m_numElemConstraints; ++i) {
int elType = m_elType[i];
@ -234,11 +223,8 @@ int VCS_SOLVE::vcs_elcorr(double aa[], double x[])
vcs_elab();
}
/*
* Ok, do the general case. Linear algebra problem is
* of length nc, not ne, as there may be degenerate rows when
* nc .ne. ne.
*/
// Ok, do the general case. Linear algebra problem is of length nc, not ne,
// as there may be degenerate rows when nc .ne. ne.
for (size_t i = 0; i < m_numComponents; ++i) {
x[i] = m_elemAbundances[i] - m_elemAbundancesGoal[i];
if (fabs(x[i]) > 1.0E-13) {
@ -258,9 +244,8 @@ int VCS_SOLVE::vcs_elcorr(double aa[], double x[])
}
ct_dgetrs(ctlapack::NoTranspose, m_numComponents, 1, aa,
m_numElemConstraints, &ipiv[0], x, m_numElemConstraints, info);
/*
* Now apply the new direction without creating negative species.
*/
// Now apply the new direction without creating negative species.
double par = 0.5;
for (size_t i = 0; i < m_numComponents; ++i) {
if (m_molNumSpecies_old[i] > 0.0) {
@ -299,23 +284,15 @@ int VCS_SOLVE::vcs_elcorr(double aa[], double x[])
}
}
/*
* We have changed the element abundances. Calculate them again
*/
// We have changed the element abundances. Calculate them again
vcs_elab();
/*
* We have changed the total moles in each phase. Calculate them again
*/
// We have changed the total moles in each phase. Calculate them again
vcs_tmoles();
/*
* Try some ad hoc procedures for fixing the problem
*/
// Try some ad hoc procedures for fixing the problem
if (retn >= 2) {
/*
* First find a species whose adjustment is a win-win
* situation.
*/
// First find a species whose adjustment is a win-win situation.
for (size_t kspec = 0; kspec < m_numSpeciesTot; kspec++) {
if (m_speciesUnknownType[kspec] == VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
continue;
@ -358,10 +335,9 @@ int VCS_SOLVE::vcs_elcorr(double aa[], double x[])
}
m_molNumSpecies_old[kspec] += xx;
m_molNumSpecies_old[kspec] = std::max(m_molNumSpecies_old[kspec], 1.0E-10);
/*
* If we are dealing with a deleted species, then
* we need to reinsert it into the active list.
*/
// If we are dealing with a deleted species, then we need to
// reinsert it into the active list.
if (kspec >= m_numSpeciesRdc) {
vcs_reinsert_deleted(kspec);
m_molNumSpecies_old[m_numSpeciesRdc - 1] = xx;
@ -401,11 +377,8 @@ int VCS_SOLVE::vcs_elcorr(double aa[], double x[])
goto L_CLEANUP;
}
/*
* For electron charges element types, we try positive deltas
* in the species concentrations to match the desired
* electron charge exactly.
*/
// For electron charges element types, we try positive deltas in the species
// concentrations to match the desired electron charge exactly.
for (size_t i = 0; i < m_numElemConstraints; ++i) {
double dev = m_elemAbundancesGoal[i] - m_elemAbundances[i];
if (m_elType[i] == VCS_ELEM_TYPE_ELECTRONCHARGE && (fabs(dev) > 1.0E-300)) {

View file

@ -33,10 +33,8 @@ int VCS_SOLVE::vcs_elem_rearrange(double* const aw, double* const sa,
plogendl();
}
/*
* Use a temporary work array for the element numbers
* Also make sure the value of test is unique.
*/
// Use a temporary work array for the element numbers
// Also make sure the value of test is unique.
bool lindep = true;
double test = -1.0E10;
while (lindep) {
@ -50,22 +48,17 @@ int VCS_SOLVE::vcs_elem_rearrange(double* const aw, double* const sa,
}
}
/*
* Top of a loop of some sort based on the index JR. JR is the
* current number independent elements found.
*/
// Top of a loop of some sort based on the index JR. JR is the current
// number independent elements found.
size_t jr = 0;
while (jr < ncomponents) {
size_t k;
/*
* Top of another loop point based on finding a linearly
* independent species
*/
// Top of another loop point based on finding a linearly independent
// species
while (true) {
/*
* Search the remaining part of the mole fraction vector, AW,
* for the largest remaining species. Return its identity in K.
*/
// Search the remaining part of the mole fraction vector, AW, for
// the largest remaining species. Return its identity in K.
k = m_numElemConstraints;
for (size_t ielem = jr; ielem < m_numElemConstraints; ielem++) {
if (m_elementActive[ielem] && aw[ielem] != test) {
@ -78,36 +71,27 @@ int VCS_SOLVE::vcs_elem_rearrange(double* const aw, double* const sa,
"Shouldn't be here. Algorithm misfired.");
}
/*
* Assign a large negative number to the element that we have
* just found, in order to take it out of further consideration.
*/
// Assign a large negative number to the element that we have just
// found, in order to take it out of further consideration.
aw[k] = test;
/* *********************************************************** */
/* **** CHECK LINEAR INDEPENDENCE OF CURRENT FORMULA MATRIX */
/* **** LINE WITH PREVIOUS LINES OF THE FORMULA MATRIX ****** */
/* *********************************************************** */
/*
* Modified Gram-Schmidt Method, p. 202 Dalquist
* QR factorization of a matrix without row pivoting.
*/
// CHECK LINEAR INDEPENDENCE OF CURRENT FORMULA MATRIX LINE WITH
// PREVIOUS LINES OF THE FORMULA MATRIX
//
// Modified Gram-Schmidt Method, p. 202 Dalquist QR factorization of
// a matrix without row pivoting.
size_t jl = jr;
/*
* Fill in the row for the current element, k, under consideration
* The row will contain the Formula matrix value for that element
* from the current component.
*/
// Fill in the row for the current element, k, under consideration
// The row will contain the Formula matrix value for that element
// from the current component.
for (size_t j = 0; j < ncomponents; ++j) {
sm[j + jr*ncomponents] = m_formulaMatrix(j,k);
}
if (jl > 0) {
/*
* Compute the coefficients of JA column of the
* the upper triangular R matrix, SS(J) = R_J_JR
* (this is slightly different than Dalquist)
* R_JA_JA = 1
*/
// Compute the coefficients of JA column of the the upper
// triangular R matrix, SS(J) = R_J_JR (this is slightly
// different than Dalquist) R_JA_JA = 1
for (size_t j = 0; j < jl; ++j) {
ss[j] = 0.0;
for (size_t i = 0; i < ncomponents; ++i) {
@ -115,10 +99,9 @@ int VCS_SOLVE::vcs_elem_rearrange(double* const aw, double* const sa,
}
ss[j] /= sa[j];
}
/*
* Now make the new column, (*,JR), orthogonal to the
* previous columns
*/
// Now make the new column, (*,JR), orthogonal to the previous
// columns
for (size_t j = 0; j < jl; ++j) {
for (size_t l = 0; l < ncomponents; ++l) {
sm[l + jr*ncomponents] -= ss[j] * sm[l + j*ncomponents];
@ -126,24 +109,18 @@ int VCS_SOLVE::vcs_elem_rearrange(double* const aw, double* const sa,
}
}
/*
* Find the new length of the new column in Q.
* It will be used in the denominator in future row calcs.
*/
// Find the new length of the new column in Q. It will be used in
// the denominator in future row calcs.
sa[jr] = 0.0;
for (size_t ml = 0; ml < ncomponents; ++ml) {
sa[jr] += pow(sm[ml + jr*ncomponents], 2);
}
/* **************************************************** */
/* **** IF NORM OF NEW ROW .LT. 1E-6 REJECT ********** */
/* **************************************************** */
// IF NORM OF NEW ROW .LT. 1E-6 REJECT
if (sa[jr] > 1.0e-6) {
break;
}
}
/* ****************************************** */
/* **** REARRANGE THE DATA ****************** */
/* ****************************************** */
// REARRANGE THE DATA
if (jr != k) {
if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
plogf(" --- ");
@ -171,10 +148,9 @@ void VCS_SOLVE::vcs_switch_elem_pos(size_t ipos, size_t jpos)
AssertThrowMsg(ipos < m_numElemConstraints && jpos < m_numElemConstraints,
"vcs_switch_elem_pos",
"inappropriate args: {} {}", ipos, jpos);
/*
* Change the element Global Index list in each vcs_VolPhase object
* to reflect the switch in the element positions.
*/
// Change the element Global Index list in each vcs_VolPhase object
// to reflect the switch in the element positions.
for (size_t iph = 0; iph < m_numPhases; iph++) {
vcs_VolPhase* volPhase = m_VolPhaseList[iph];
for (size_t e = 0; e < volPhase->nElemConstraints(); e++) {

View file

@ -24,12 +24,8 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm,
size_t nspecies = m_numSpeciesTot;
size_t nrxn = m_numRxnTot;
/*
* CALL ROUTINE TO SOLVE MAX(CC*molNum) SUCH THAT AX*molNum = BB
* AND molNum(I) .GE. 0.0
*
* Note, both of these programs do this.
*/
// CALL ROUTINE TO SOLVE MAX(CC*molNum) SUCH THAT AX*molNum = BB AND
// molNum(I) .GE. 0.0. Note, both of these programs do this.
vcs_setMolesLinProg();
if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
@ -60,17 +56,13 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm,
plogendl();
}
/*
* Make sure all species have positive definite mole numbers
* Set voltages to zero for now, until we figure out what to do
*/
// Make sure all species have positive definite mole numbers Set voltages to
// zero for now, until we figure out what to do
m_deltaMolNumSpecies.assign(m_deltaMolNumSpecies.size(), 0.0);
for (size_t kspec = 0; kspec < nspecies; ++kspec) {
if (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
if (m_molNumSpecies_old[kspec] <= 0.0) {
/*
* HKM Should eventually include logic here for non SS phases
*/
// HKM Should eventually include logic here for non SS phases
if (!m_SSPhase[kspec]) {
m_molNumSpecies_old[kspec] = 1.0e-30;
}
@ -80,24 +72,17 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm,
}
}
/*
* Now find the optimized basis that spans the stoichiometric
* coefficient matrix
*/
// Now find the optimized basis that spans the stoichiometric coefficient
// matrix
bool conv;
vcs_basopt(false, aw, sa, sm, ss, test, &conv);
/* ***************************************************************** */
/* **** CALCULATE TOTAL MOLES, ****************** */
/* **** CHEMICAL POTENTIALS OF BASIS ****************** */
/* ***************************************************************** */
/*
* Calculate TMoles and m_tPhaseMoles_old[]
*/
// CALCULATE TOTAL MOLES, CHEMICAL POTENTIALS OF BASIS
// Calculate TMoles and m_tPhaseMoles_old[]
vcs_tmoles();
/*
* m_tPhaseMoles_new[] will consist of just the component moles
*/
// m_tPhaseMoles_new[] will consist of just the component moles
for (size_t iph = 0; iph < m_numPhases; iph++) {
m_tPhaseMoles_new[iph] = TPhInertMoles[iph] + 1.0E-20;
}
@ -144,9 +129,8 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm,
}
}
}
/* ********************************************************** */
/* **** ESTIMATE REACTION ADJUSTMENTS *********************** */
/* ********************************************************** */
// ESTIMATE REACTION ADJUSTMENTS
vector_fp& xtphMax = m_TmpPhase;
vector_fp& xtphMin = m_TmpPhase2;
m_deltaPhaseMoles.assign(m_deltaPhaseMoles.size(), 0.0);
@ -156,12 +140,10 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm,
}
for (size_t irxn = 0; irxn < nrxn; ++irxn) {
size_t kspec = m_indexRxnToSpecies[irxn];
/*
* For single species phases, we will not estimate the
* mole numbers. If the phase exists, it stays. If it
* doesn't exist in the estimate, it doesn't come into
* existence here.
*/
// For single species phases, we will not estimate the mole numbers. If
// the phase exists, it stays. If it doesn't exist in the estimate, it
// doesn't come into existence here.
if (! m_SSPhase[kspec]) {
size_t iph = m_phaseID[kspec];
if (m_deltaGRxn_new[irxn] > xtphMax[iph]) {
@ -170,15 +152,13 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm,
if (m_deltaGRxn_new[irxn] < xtphMin[iph]) {
m_deltaGRxn_new[irxn] = 0.8 * xtphMin[iph];
}
/*
* HKM -> The TMolesMultiphase is a change of mine.
* It more evenly distributes the initial moles amongst
* multiple multispecies phases according to the
* relative values of the standard state free energies.
* There is no change for problems with one multispecies
* phase.
* It cut diamond4.vin iterations down from 62 to 14.
*/
// HKM -> The TMolesMultiphase is a change of mine. It more evenly
// distributes the initial moles amongst multiple multispecies
// phases according to the relative values of the standard state
// free energies. There is no change for problems with one
// multispecies phase. It cut diamond4.vin iterations down from 62
// to 14.
m_deltaMolNumSpecies[kspec] = 0.5 * (m_tPhaseMoles_new[iph] + TMolesMultiphase)
* exp(-m_deltaGRxn_new[irxn]);
@ -208,9 +188,8 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm,
}
}
}
/* *********************************************************** */
/* **** KEEP COMPONENT SPECIES POSITIVE ********************** */
/* *********************************************************** */
// KEEP COMPONENT SPECIES POSITIVE
double par = 0.5;
for (size_t kspec = 0; kspec < m_numComponents; ++kspec) {
if (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE &&
@ -224,9 +203,8 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm,
} else {
par = 1.0;
}
/* ******************************************** */
/* **** CALCULATE NEW MOLE NUMBERS ************ */
/* ******************************************** */
// CALCULATE NEW MOLE NUMBERS
size_t lt = 0;
size_t ikl = 0;
double s1 = 0.0;
@ -244,17 +222,15 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm,
m_molNumSpecies_old[kspec] = m_deltaMolNumSpecies[kspec] * par;
}
}
/*
* We have a new w[] estimate, go get the
* TMoles and m_tPhaseMoles_old[] values
*/
// We have a new w[] estimate, go get the TMoles and m_tPhaseMoles_old[]
// values
vcs_tmoles();
if (lt > 0) {
break;
}
/* ******************************************* */
/* **** CONVERGENCE FORCING SECTION ********** */
/* ******************************************* */
// CONVERGENCE FORCING SECTION
vcs_setFlagsVolPhases(false, VCS_STATECALC_OLD);
vcs_dfe(VCS_STATECALC_OLD, 0, 0, nspecies);
double s = 0.0;
@ -267,34 +243,26 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm,
if (s < 0.0 && ikl == 0) {
break;
}
/* ***************************************** */
/* *** TRY HALF STEP SIZE ****************** */
/* ***************************************** */
// TRY HALF STEP SIZE
if (ikl == 0) {
s1 = s;
par *= 0.5;
ikl = 1;
continue;
}
/* **************************************************** */
/* **** FIT PARABOLA THROUGH HALF AND FULL STEPS ****** */
/* **************************************************** */
// FIT PARABOLA THROUGH HALF AND FULL STEPS
double xl = (1.0 - s / (s1 - s)) * 0.5;
if (xl < 0.0) {
/* *************************************************** */
/* *** POOR DIRECTION, REDUCE STEP SIZE TO 0.2 ******* */
/* *************************************************** */
// POOR DIRECTION, REDUCE STEP SIZE TO 0.2
par *= 0.2;
} else {
if (xl > 1.0) {
/* *************************************************** */
/* **** TOO BIG A STEP, TAKE ORIGINAL FULL STEP ****** */
/* *************************************************** */
// TOO BIG A STEP, TAKE ORIGINAL FULL STEP
par *= 2.0;
} else {
/* *************************************************** */
/* **** ACCEPT RESULTS OF FORCER ********************* */
/* *************************************************** */
// ACCEPT RESULTS OF FORCER
par = par * 2.0 * xl;
}
}
@ -319,9 +287,7 @@ int VCS_SOLVE::vcs_inest_TP()
int retn = 0;
clockWC tickTock;
if (m_doEstimateEquil > 0) {
/*
* Calculate the elemental abundances
*/
// Calculate the elemental abundances
vcs_elab();
if (vcs_elabcheck(0)) {
if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
@ -339,21 +305,13 @@ int VCS_SOLVE::vcs_inest_TP()
}
}
/*
* Malloc temporary space for usage in this routine and in
* subroutines
* sm[ne*ne]
* ss[ne]
* sa[ne]
* aw[m]
*/
// Malloc temporary space for usage in this routine and in subroutines
vector_fp sm(m_numElemConstraints*m_numElemConstraints, 0.0);
vector_fp ss(m_numElemConstraints, 0.0);
vector_fp sa(m_numElemConstraints, 0.0);
vector_fp aw(m_numSpeciesTot+ m_numElemConstraints, 0.0);
/*
* Go get the estimate of the solution
*/
// Go get the estimate of the solution
if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
plogf("%sGo find an initial estimate for the equilibrium problem",
pprefix);
@ -361,21 +319,17 @@ int VCS_SOLVE::vcs_inest_TP()
}
double test = -1.0E20;
vcs_inest(&aw[0], &sa[0], &sm[0], &ss[0], test);
/*
* Calculate the elemental abundances
*/
// Calculate the elemental abundances
vcs_elab();
/*
* If we still fail to achieve the correct elemental abundances,
* try to fix the problem again by calling the main elemental abundances
* fixer routine, used in the main program. This
* attempts to tweak the mole numbers of the component species to
* satisfy the element abundance constraints.
*
* Note: We won't do this unless we have to since it involves inverting
* a matrix.
*/
// If we still fail to achieve the correct elemental abundances, try to fix
// the problem again by calling the main elemental abundances fixer routine,
// used in the main program. This attempts to tweak the mole numbers of the
// component species to satisfy the element abundance constraints.
//
// Note: We won't do this unless we have to since it involves inverting a
// matrix.
bool rangeCheck = vcs_elabcheck(1);
if (!vcs_elabcheck(0)) {
if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
@ -428,9 +382,7 @@ int VCS_SOLVE::vcs_inest_TP()
plogendl();
}
/*
* Record time
*/
// Record time
m_VCount->T_Time_inest += tickTock.secondsWC();
m_VCount->T_Calls_Inest++;
return retn;

View file

@ -61,11 +61,9 @@ void VCS_SOLVE::vcs_nondim_TP()
m_unitsState = VCS_NONDIMENSIONAL_G;
double tf = 1.0 / vcs_nondimMult_TP(m_VCS_UnitsFormat, m_temperature);
for (size_t i = 0; i < m_numSpeciesTot; ++i) {
/*
* Modify the standard state and total chemical potential data,
* FF(I), to make it dimensionless, i.e., mu / RT.
* Thus, we may divide it by the temperature.
*/
// Modify the standard state and total chemical potential data,
// FF(I), to make it dimensionless, i.e., mu / RT. Thus, we may
// divide it by the temperature.
m_SSfeSpecies[i] *= tf;
m_deltaGRxn_new[i] *= tf;
m_deltaGRxn_old[i] *= tf;
@ -74,16 +72,11 @@ void VCS_SOLVE::vcs_nondim_TP()
m_Faraday_dim = vcs_nondim_Farad(m_VCS_UnitsFormat, m_temperature);
/*
* Scale the total moles if necessary:
* First find out the total moles
*/
// Scale the total moles if necessary: First find out the total moles
double tmole_orig = vcs_tmoles();
/*
* Then add in the total moles of elements that are goals. Either one
* or the other is specified here.
*/
// Then add in the total moles of elements that are goals. Either one or
// the other is specified here.
double esum = 0.0;
for (size_t i = 0; i < m_numElemConstraints; ++i) {
if (m_elType[i] == VCS_ELEM_TYPE_ABSPOS) {
@ -92,11 +85,9 @@ void VCS_SOLVE::vcs_nondim_TP()
}
tmole_orig += esum;
/*
* Ok now test out the bounds on the total moles that this program can
* handle. These are a bit arbitrary. However, it would seem that any
* reasonable input would be between these two numbers below.
*/
// Ok now test out the bounds on the total moles that this program can
// handle. These are a bit arbitrary. However, it would seem that any
// reasonable input would be between these two numbers below.
if (tmole_orig < 1.0E-200 || tmole_orig > 1.0E200) {
throw CanteraError("VCS_SOLVE::vcs_nondim_TP",
"Total input moles, {} is outside the range handled by vcs.\n",
@ -146,10 +137,9 @@ void VCS_SOLVE::vcs_redim_TP()
m_unitsState = VCS_DIMENSIONAL_G;
double tf = vcs_nondimMult_TP(m_VCS_UnitsFormat, m_temperature);
for (size_t i = 0; i < m_numSpeciesTot; ++i) {
/*
* Modify the standard state and total chemical potential data,
* FF(I), to make it have units, i.e. mu = RT * mu_star
*/
// Modify the standard state and total chemical potential data,
// FF(I), to make it have units, i.e. mu = RT * mu_star
m_SSfeSpecies[i] *= tf;
m_deltaGRxn_new[i] *= tf;
m_deltaGRxn_old[i] *= tf;

View file

@ -19,12 +19,10 @@ bool VCS_SOLVE::vcs_popPhasePossible(const size_t iphasePop) const
AssertThrowMsg(!Vphase->exists(), "VCS_SOLVE::vcs_popPhasePossible",
"called for a phase that exists!");
/*
* Loop through all of the species in the phase. We say the phase
* can be popped, if there is one species in the phase that can be
* popped. This does not mean that the phase will be popped or that it
* leads to a lower Gibbs free energy.
*/
// Loop through all of the species in the phase. We say the phase can be
// popped, if there is one species in the phase that can be popped. This
// does not mean that the phase will be popped or that it leads to a lower
// Gibbs free energy.
for (size_t k = 0; k < Vphase->nSpecies(); k++) {
size_t kspec = Vphase->spGlobalIndexVCS(k);
AssertThrowMsg(m_molNumSpecies_old[kspec] <= 0.0,
@ -34,18 +32,19 @@ bool VCS_SOLVE::vcs_popPhasePossible(const size_t iphasePop) const
size_t irxn = kspec - m_numComponents;
if (kspec >= m_numComponents) {
bool iPopPossible = true;
/*
* Note one case is if the component is a member of the popping phase.
* This component will be zeroed and the logic here will negate the current
* species from causing a positive if this component is consumed.
*/
// Note one case is if the component is a member of the popping
// phase. This component will be zeroed and the logic here will
// negate the current species from causing a positive if this
// component is consumed.
for (size_t j = 0; j < m_numComponents; ++j) {
if (m_elType[j] == VCS_ELEM_TYPE_ABSPOS) {
double stoicC = m_stoichCoeffRxnMatrix(j,irxn);
if (stoicC != 0.0) {
double negChangeComp = - stoicC;
if (negChangeComp > 0.0) {
// If there is no component to give, then the species can't be created
// If there is no component to give, then the
// species can't be created
if (m_molNumSpecies_old[j] <= VCS_DELETE_ELEMENTABS_CUTOFF*0.5) {
iPopPossible = false;
}
@ -53,22 +52,22 @@ bool VCS_SOLVE::vcs_popPhasePossible(const size_t iphasePop) const
}
}
}
// We are here when the species can be popped because all its needed components have positive mole numbers
// We are here when the species can be popped because all its needed
// components have positive mole numbers
if (iPopPossible) {
return true;
}
} else {
/*
* We are here when the species, k, in the phase is a component. Its mole number is zero.
* We loop through the regular reaction looking for a reaction that can pop the
* component.
*/
// We are here when the species, k, in the phase is a component. Its
// mole number is zero. We loop through the regular reaction looking
// for a reaction that can pop the component.
for (size_t jrxn = 0; jrxn < m_numRxnRdc; jrxn++) {
bool foundJrxn = false;
// First, if the component is a product of the reaction
if (m_stoichCoeffRxnMatrix(kspec,jrxn) > 0.0) {
foundJrxn = true;
// We can do the reaction if all other reactant components have positive mole fractions
// We can do the reaction if all other reactant components
// have positive mole fractions
for (size_t kcomp = 0; kcomp < m_numComponents; kcomp++) {
if (m_stoichCoeffRxnMatrix(kcomp,jrxn) < 0.0 && m_molNumSpecies_old[kcomp] <= VCS_DELETE_ELEMENTABS_CUTOFF*0.5) {
foundJrxn = false;
@ -78,14 +77,16 @@ bool VCS_SOLVE::vcs_popPhasePossible(const size_t iphasePop) const
return true;
}
} else if (m_stoichCoeffRxnMatrix(kspec,jrxn) < 0.0) {
// Second we are here if the component is a reactant in the reaction, and the reaction goes backwards.
// Second we are here if the component is a reactant in the
// reaction, and the reaction goes backwards.
foundJrxn = true;
size_t jspec = jrxn + m_numComponents;
if (m_molNumSpecies_old[jspec] <= VCS_DELETE_ELEMENTABS_CUTOFF*0.5) {
foundJrxn = false;
continue;
}
// We can do the backwards reaction if all of the product components species are positive
// We can do the backwards reaction if all of the product
// components species are positive
for (size_t kcomp = 0; kcomp < m_numComponents; kcomp++) {
if (m_stoichCoeffRxnMatrix(kcomp,jrxn) > 0.0 && m_molNumSpecies_old[kcomp] <= VCS_DELETE_ELEMENTABS_CUTOFF*0.5) {
foundJrxn = false;
@ -106,20 +107,17 @@ int VCS_SOLVE::vcs_phasePopDeterminePossibleList()
int nfound = 0;
phasePopProblemLists_.clear();
/*
* This is a vector over each component.
* For zeroed components it lists the phases, which are currently zeroed,
* which have a species with a positive stoichiometric value wrt the component.
* Therefore, we could pop the component species and pop that phase at the same time
* if we considered no other factors than keeping the component mole number positive.
*
* It does not count species with positive stoichiometric values if that species
* already has a positive mole number. The phase is already popped.
*/
// This is a vector over each component. For zeroed components it lists the
// phases, which are currently zeroed, which have a species with a positive
// stoichiometric value wrt the component. Therefore, we could pop the
// component species and pop that phase at the same time if we considered no
// other factors than keeping the component mole number positive.
//
// It does not count species with positive stoichiometric values if that
// species already has a positive mole number. The phase is already popped.
std::vector< std::vector<size_t> > zeroedComponentLinkedPhasePops(m_numComponents);
/*
* The logic below calculates zeroedComponentLinkedPhasePops
*/
// The logic below calculates zeroedComponentLinkedPhasePops
for (size_t j = 0; j < m_numComponents; j++) {
if (m_elType[j] == VCS_ELEM_TYPE_ABSPOS && m_molNumSpecies_old[j] <= 0.0) {
std::vector<size_t> &jList = zeroedComponentLinkedPhasePops[j];
@ -137,17 +135,16 @@ int VCS_SOLVE::vcs_phasePopDeterminePossibleList()
}
}
}
/*
* This is a vector over each zeroed phase
* For zeroed phases, it lists the components, which are currently zeroed,
* which have a species with a negative stoichiometric value wrt one or more species in the phase.
* Cut out components which have a pos stoichiometric value with another species in the phase.
*/
// This is a vector over each zeroed phase For zeroed phases, it lists the
// components, which are currently zeroed, which have a species with a
// negative stoichiometric value wrt one or more species in the phase. Cut
// out components which have a pos stoichiometric value with another species
// in the phase.
std::vector< std::vector<size_t> > zeroedPhaseLinkedZeroComponents(m_numPhases);
vector_int linkedPhases;
/*
* The logic below calculates zeroedPhaseLinkedZeroComponents
*/
// The logic below calculates zeroedPhaseLinkedZeroComponents
for (size_t iph = 0; iph < m_numPhases; iph++) {
std::vector<size_t> &iphList = zeroedPhaseLinkedZeroComponents[iph];
iphList.clear();
@ -179,9 +176,7 @@ int VCS_SOLVE::vcs_phasePopDeterminePossibleList()
}
}
/*
* Now fill in the phasePopProblemLists_ list.
*/
// Now fill in the phasePopProblemLists_ list.
for (size_t iph = 0; iph < m_numPhases; iph++) {
vcs_VolPhase* Vphase = m_VolPhaseList[iph];
if (Vphase->exists() < 0) {
@ -233,9 +228,7 @@ size_t VCS_SOLVE::vcs_popPhaseID(std::vector<size_t> & phasePopPhaseIDs)
}
} else {
if (Vphase->m_singleSpecies) {
/***********************************************************************
* Single Phase Stability Resolution
***********************************************************************/
// Single Phase Stability Resolution
size_t kspec = Vphase->spGlobalIndexVCS(0);
size_t irxn = kspec - m_numComponents;
doublereal deltaGRxn = m_deltaGRxn_old[irxn];
@ -264,9 +257,7 @@ size_t VCS_SOLVE::vcs_popPhaseID(std::vector<size_t> & phasePopPhaseIDs)
m_tPhaseMoles_old[iph], anote);
}
} else {
/***********************************************************************
* MultiSpecies Phase Stability Resolution
***********************************************************************/
// MultiSpecies Phase Stability Resolution
if (vcs_popPhasePossible(iph)) {
Fephase = vcs_phaseStabilityTest(iph);
if (Fephase > 0.0) {
@ -297,10 +288,8 @@ size_t VCS_SOLVE::vcs_popPhaseID(std::vector<size_t> & phasePopPhaseIDs)
phasePopPhaseIDs.push_back(iphasePop);
}
/*
* Insert logic here to figure out if phase pops are linked together. Only do one linked
* pop at a time.
*/
// Insert logic here to figure out if phase pops are linked together. Only
// do one linked pop at a time.
if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
plogf(" ---------------------------------------------------------------------\n");
}
@ -351,9 +340,7 @@ int VCS_SOLVE::vcs_popPhaseRxnStepSizes(const size_t iphasePop)
m_deltaMolNumSpecies[kspec] = tPhaseMoles;
}
/*
* section to do damping of the m_deltaMolNumSpecies[]
*/
// section to do damping of the m_deltaMolNumSpecies[]
for (size_t j = 0; j < m_numComponents; ++j) {
double stoicC = m_stoichCoeffRxnMatrix(j,irxn);
if (stoicC != 0.0 && m_elType[j] == VCS_ELEM_TYPE_ABSPOS) {
@ -367,7 +354,8 @@ int VCS_SOLVE::vcs_popPhaseRxnStepSizes(const size_t iphasePop)
}
}
}
// Implement a damping term that limits m_deltaMolNumSpecies to the size of the mole number
// Implement a damping term that limits m_deltaMolNumSpecies to the size
// of the mole number
if (-m_deltaMolNumSpecies[kspec] > m_molNumSpecies_old[kspec]) {
m_deltaMolNumSpecies[kspec] = -m_molNumSpecies_old[kspec];
}
@ -426,8 +414,8 @@ int VCS_SOLVE::vcs_popPhaseRxnStepSizes(const size_t iphasePop)
}
// We may have greatly underestimated the deltaMoles for the phase pop
// Here we create a damp > 1 to account for this possibility.
// We adjust upwards to make sure that a component in an existing multispecies
// Here we create a damp > 1 to account for this possibility. We adjust
// upwards to make sure that a component in an existing multispecies
// phase is modified by a factor of 1/1000.
if (ratioComp > 1.0E-30 && ratioComp < 0.001) {
damp = 0.001 / ratioComp;
@ -455,9 +443,7 @@ int VCS_SOLVE::vcs_popPhaseRxnStepSizes(const size_t iphasePop)
double VCS_SOLVE::vcs_phaseStabilityTest(const size_t iph)
{
/*
* We will use the _new state calc here
*/
// We will use the _new state calc here
vcs_VolPhase* Vphase = m_VolPhaseList[iph];
const size_t nsp = Vphase->nSpecies();
int minNumberIterations = 3;
@ -550,7 +536,8 @@ double VCS_SOLVE::vcs_phaseStabilityTest(const size_t iph)
for (size_t k = 0; k < nsp; k++) {
sumFrac += fracDelta_old[k];
}
// Necessary because this can be identically zero. -> we need to fix this algorithm!
// Necessary because this can be identically zero. -> we need to fix
// this algorithm!
if (sumFrac <= 0.0) {
sumFrac = 1.0;
}
@ -562,21 +549,15 @@ double VCS_SOLVE::vcs_phaseStabilityTest(const size_t iph)
}
}
/*
* Feed the newly formed estimate of the mole fractions back into the
* ThermoPhase object
*/
// Feed the newly formed estimate of the mole fractions back into the
// ThermoPhase object
Vphase->setMoleFractionsState(0.0, &X_est[0], VCS_STATECALC_PHASESTABILITY);
/*
* get the activity coefficients
*/
// get the activity coefficients
Vphase->sendToVCS_ActCoeff(VCS_STATECALC_OLD, &m_actCoeffSpecies_new[0]);
/*
* First calculate altered chemical potentials for component species
* belonging to this phase.
*/
// First calculate altered chemical potentials for component species
// belonging to this phase.
for (size_t i = 0; i < componentList.size(); i++) {
size_t kc = componentList[i];
size_t kc_spec = Vphase->spGlobalIndexVCS(kc);
@ -606,9 +587,7 @@ double VCS_SOLVE::vcs_phaseStabilityTest(const size_t iph)
}
}
/*
* Calculate the E_phi's
*/
// Calculate the E_phi's
sum = 0.0;
funcPhaseStability = sum_Xcomp - 1.0;
for (size_t k = 0; k < nsp; k++) {
@ -624,9 +603,7 @@ double VCS_SOLVE::vcs_phaseStabilityTest(const size_t iph)
}
}
/*
* Calculate the raw estimate of the new fracs
*/
// Calculate the raw estimate of the new fracs
for (size_t k = 0; k < nsp; k++) {
size_t kspec = Vphase->spGlobalIndexVCS(k);
double b = E_phi[k] / sum * (1.0 - sum_Xcomp);
@ -650,9 +627,7 @@ double VCS_SOLVE::vcs_phaseStabilityTest(const size_t iph)
}
}
/*
* Now possibly dampen the estimate.
*/
// Now possibly dampen the estimate.
doublereal sumADel = 0.0;
for (size_t k = 0; k < nsp; k++) {
delFrac[k] = fracDelta_raw[k] - fracDelta_old[k];
@ -718,14 +693,11 @@ double VCS_SOLVE::vcs_phaseStabilityTest(const size_t iph)
}
if (converged) {
/*
* Save the final optimized stated back into the VolPhase object for later use
*/
// Save the final optimized stated back into the VolPhase object for later use
Vphase->setMoleFractionsState(0.0, &X_est[0], VCS_STATECALC_PHASESTABILITY);
/*
* Save fracDelta for later use to initialize the problem better
* @TODO creationGlobalRxnNumbers needs to be calculated here and stored.
*/
// Save fracDelta for later use to initialize the problem better
// @TODO creationGlobalRxnNumbers needs to be calculated here and stored.
Vphase->setCreationMoleNumbers(&fracDelta_new[0], creationGlobalRxnNumbers);
}
} else {

View file

@ -21,11 +21,10 @@ void VCS_SOLVE::vcs_SSPhase()
for (size_t kspec = 0; kspec < m_numSpeciesTot; ++kspec) {
numPhSpecies[m_phaseID[kspec]]++;
}
/*
* Handle the special case of a single species in a phase that
* has been earmarked as a multispecies phase.
* Treat that species as a single-species phase
*/
// Handle the special case of a single species in a phase that has been
// earmarked as a multispecies phase. Treat that species as a single-species
// phase
for (size_t iph = 0; iph < m_numPhases; iph++) {
vcs_VolPhase* Vphase = m_VolPhaseList[iph];
Vphase->m_singleSpecies = false;
@ -37,12 +36,9 @@ void VCS_SOLVE::vcs_SSPhase()
}
}
/*
* Fill in some useful arrays here that have to do with the
* static information concerning the phase ID of species.
* SSPhase = Boolean indicating whether a species is in a
* single species phase or not.
*/
// Fill in some useful arrays here that have to do with the static
// information concerning the phase ID of species. SSPhase = Boolean
// indicating whether a species is in a single species phase or not.
for (size_t kspec = 0; kspec < m_numSpeciesTot; kspec++) {
size_t iph = m_phaseID[kspec];
vcs_VolPhase* Vphase = m_VolPhaseList[iph];
@ -59,16 +55,12 @@ int VCS_SOLVE::vcs_prep_oneTime(int printLvl)
int retn = VCS_SUCCESS;
m_debug_print_lvl = printLvl;
/*
* Calculate the Single Species status of phases
* Also calculate the number of species per phase
*/
// Calculate the Single Species status of phases
// Also calculate the number of species per phase
vcs_SSPhase();
/*
* Set an initial estimate for the number of noncomponent species
* equal to nspecies - nelements. This may be changed below
*/
// Set an initial estimate for the number of noncomponent species equal to
// nspecies - nelements. This may be changed below
if (m_numElemConstraints > m_numSpeciesTot) {
m_numRxnTot = 0;
} else {
@ -97,25 +89,20 @@ int VCS_SOLVE::vcs_prep_oneTime(int printLvl)
}
}
/* ***************************************************** */
/* **** DETERMINE THE NUMBER OF COMPONENTS ************* */
/* ***************************************************** */
/*
* Obtain a valid estimate of the mole fraction. This will
* be used as an initial ordering vector for prioritizing
* which species are defined as components.
*
* If a mole number estimate was supplied from the
* input file, use that mole number estimate.
*
* If a solution estimate wasn't supplied from the input file,
* supply an initial estimate for the mole fractions
* based on the relative reverse ordering of the
* chemical potentials.
*
* For voltage unknowns, set these to zero for the moment.
*/
// DETERMINE THE NUMBER OF COMPONENTS
//
// Obtain a valid estimate of the mole fraction. This will be used as an
// initial ordering vector for prioritizing which species are defined as
// components.
//
// If a mole number estimate was supplied from the input file, use that mole
// number estimate.
//
// If a solution estimate wasn't supplied from the input file, supply an
// initial estimate for the mole fractions based on the relative reverse
// ordering of the chemical potentials.
//
// For voltage unknowns, set these to zero for the moment.
double test = -1.0e-10;
bool modifiedSoln = false;
if (m_doEstimateEquil < 0) {
@ -140,11 +127,8 @@ int VCS_SOLVE::vcs_prep_oneTime(int printLvl)
test = -1.0e20;
}
/*
* NC = number of components is in the vcs.h common block
* This call to BASOPT doesn't calculate the stoichiometric
* reaction matrix.
*/
// NC = number of components is in the vcs.h common block. This call to
// BASOPT doesn't calculate the stoichiometric reaction matrix.
vector_fp awSpace(m_numSpeciesTot + (m_numElemConstraints + 2)*(m_numElemConstraints), 0.0);
double* aw = &awSpace[0];
if (aw == NULL) {
@ -173,9 +157,7 @@ int VCS_SOLVE::vcs_prep_oneTime(int printLvl)
m_numRxnTot = m_numRxnRdc = 0;
}
/*
* The elements might need to be rearranged.
*/
// The elements might need to be rearranged.
awSpace.resize(m_numElemConstraints + (m_numElemConstraints + 2)*(m_numElemConstraints), 0.0);
aw = &awSpace[0];
sa = aw + m_numElemConstraints;
@ -202,9 +184,7 @@ int VCS_SOLVE::vcs_prep_oneTime(int printLvl)
int VCS_SOLVE::vcs_prep()
{
/*
* Initialize various arrays in the data to zero
*/
// Initialize various arrays in the data to zero
m_feSpecies_old.assign(m_feSpecies_old.size(), 0.0);
m_feSpecies_new.assign(m_feSpecies_new.size(), 0.0);
m_molNumSpecies_new.assign(m_molNumSpecies_new.size(), 0.0);
@ -212,9 +192,8 @@ int VCS_SOLVE::vcs_prep()
m_phaseParticipation.zero();
m_deltaPhaseMoles.assign(m_deltaPhaseMoles.size(), 0.0);
m_tPhaseMoles_new.assign(m_tPhaseMoles_new.size(), 0.0);
/*
* Calculate the total number of moles in all phases.
*/
// Calculate the total number of moles in all phases.
vcs_tmoles();
return VCS_SUCCESS;
}

View file

@ -34,11 +34,11 @@ VCS_PROB::VCS_PROB(size_t nsp, size_t nel, size_t nph) :
T(298.15),
PresPA(1.0),
Vol(0.0),
// Set the units for the chemical potential data to be unitless
m_VCS_UnitsFormat(VCS_UNITS_UNITLESS),
/* Set the units for the chemical potential data to be
* unitless */
iest(-1), /* The default is to not expect an initial estimate
* of the species concentrations */
// The default is to not expect an initial estimate of the species
// concentrations
iest(-1),
tolmaj(1.0E-8),
tolmin(1.0E-6),
m_Iterations(0),
@ -162,9 +162,8 @@ void VCS_PROB::set_gai()
void VCS_PROB::prob_report(int print_lvl)
{
m_printLvl = print_lvl;
/*
* Printout the species information: PhaseID's and mole nums
*/
// Printout the species information: PhaseID's and mole nums
if (m_printLvl > 0) {
writeline('=', 80, true, true);
writeline('=', 20, false);
@ -204,9 +203,7 @@ void VCS_PROB::prob_report(int print_lvl)
plogf("\n");
}
/*
* Printout of the Phase structure information
*/
// Printout of the Phase structure information
writeline('-', 80, true, true);
plogf(" Information about phases\n");
plogf(" PhaseName PhaseNum SingSpec GasPhase "
@ -283,17 +280,14 @@ void VCS_PROB::prob_report(int print_lvl)
void VCS_PROB::addPhaseElements(vcs_VolPhase* volPhase)
{
size_t neVP = volPhase->nElemConstraints();
/*
* Loop through the elements in the vol phase object
*/
// Loop through the elements in the vol phase object
for (size_t eVP = 0; eVP < neVP; eVP++) {
size_t foundPos = npos;
std::string enVP = volPhase->elementName(eVP);
/*
* Search for matches with the existing elements.
* If found, then fill in the entry in the global
* mapping array.
*/
// Search for matches with the existing elements. If found, then fill in
// the entry in the global mapping array.
for (size_t e = 0; e < ne; e++) {
std::string en = ElName[e];
if (!strcmp(enVP.c_str(), en.c_str())) {
@ -328,9 +322,7 @@ size_t VCS_PROB::addElement(const char* elNameNew, int elType, int elactive)
size_t VCS_PROB::addOnePhaseSpecies(vcs_VolPhase* volPhase, size_t k, size_t kT)
{
if (kT > nspecies) {
/*
* Need to expand the number of species here
*/
// Need to expand the number of species here
throw CanteraError("VCS_PROB::addOnePhaseSpecies", "Shouldn't be here");
}
const Array2D& fm = volPhase->getFormulaMatrix();
@ -340,10 +332,9 @@ size_t VCS_PROB::addOnePhaseSpecies(vcs_VolPhase* volPhase, size_t k, size_t kT)
"element not found");
FormulaMatrix(kT,e) = fm(k,eVP);
}
/*
* Tell the phase object about the current position of the
* species within the global species vector
*/
// Tell the phase object about the current position of the species within
// the global species vector
volPhase->setSpGlobalIndexVCS(k, kT);
return kT;
}
@ -470,9 +461,7 @@ void VCS_PROB::reportCSV(const std::string& reportFile)
}
if (DEBUG_MODE_ENABLED) {
/*
* Check consistency: These should be equal
*/
// Check consistency: These should be equal
tp->getChemPotentials(&m_gibbsSpecies[0]+istart);
for (size_t k = 0; k < nSpeciesPhase; k++) {
if (!vcs_doubleEqual(m_gibbsSpecies[istart+k], mu[k])) {

View file

@ -16,12 +16,10 @@ int VCS_SOLVE::vcs_rearrange()
{
size_t k1 = 0;
/* - Loop over all of the species */
// Loop over all of the species
for (size_t i = 0; i < m_numSpeciesTot; ++i) {
/*
* Find the index of I in the index vector m_speciesIndexVector[].
* Call it k1 and continue.
*/
// Find the index of I in the index vector m_speciesIndexVector[]. Call
// it k1 and continue.
for (size_t j = 0; j < m_numSpeciesTot; ++j) {
size_t l = m_speciesMapIndex[j];
k1 = j;
@ -29,11 +27,9 @@ int VCS_SOLVE::vcs_rearrange()
break;
}
}
/*
* - Switch the species data back from k1 into i
* -> because we loop over all species, reaction data
* are now permanently hosed.
*/
//Switch the species data back from k1 into i. because we loop over all
//species, reaction data are now permanently hosed.
vcs_switch_pos(false, i, k1);
}
return 0;

View file

@ -19,19 +19,14 @@ int VCS_SOLVE::vcs_report(int iconv)
std::vector<size_t> sortindex(nspecies,0);
vector_fp xy(nspecies,0.0);
/* ************************************************************** */
/* **** SORT DEPENDENT SPECIES IN DECREASING ORDER OF MOLES ***** */
/* ************************************************************** */
// SORT DEPENDENT SPECIES IN DECREASING ORDER OF MOLES
for (size_t i = 0; i < nspecies; ++i) {
sortindex[i] = i;
xy[i] = m_molNumSpecies_old[i];
}
/*
* Sort the XY vector, the mole fraction vector,
* and the sort index vector, sortindex, according to
* the magnitude of the mole fraction vector.
*/
// Sort the XY vector, the mole fraction vector, and the sort index vector,
// sortindex, according to the magnitude of the mole fraction vector.
for (size_t l = m_numComponents; l < m_numSpeciesRdc; ++l) {
size_t k = vcs_optMax(&xy[0], 0, l, m_numSpeciesRdc);
if (k != l) {
@ -40,11 +35,9 @@ int VCS_SOLVE::vcs_report(int iconv)
}
}
/*
* Decide whether we have to nondimensionalize the equations.
* -> For the printouts from this routine, we will use nondimensional
* representations. This may be expanded in the future.
*/
// Decide whether we have to nondimensionalize the equations. For the
// printouts from this routine, we will use nondimensional representations.
// This may be expanded in the future.
if (m_unitsState == VCS_DIMENSIONAL_G) {
vcs_nondim_TP();
}
@ -55,10 +48,8 @@ int VCS_SOLVE::vcs_report(int iconv)
vcs_setFlagsVolPhases(false, VCS_STATECALC_OLD);
vcs_dfe(VCS_STATECALC_OLD, 0, 0, m_numSpeciesTot);
/* ******************************************************** */
/* *** PRINT OUT RESULTS ********************************** */
/* ******************************************************** */
// PRINT OUT RESULTS
plogf("\n\n\n\n");
writeline('-', 80);
writeline('-', 80);
@ -70,9 +61,8 @@ int VCS_SOLVE::vcs_report(int iconv)
} else if (iconv == 1) {
plogf(" RANGE SPACE ERROR: Equilibrium Found but not all Element Abundances are Satisfied\n");
}
/*
* Calculate some quantities that may need updating
*/
// Calculate some quantities that may need updating
vcs_tmoles();
m_totalVol = vcs_VolTotal(m_temperature, m_pressurePA,
&m_molNumSpecies_old[0], &m_PMVolumeSpecies[0]);
@ -85,9 +75,7 @@ int VCS_SOLVE::vcs_report(int iconv)
molScale);
}
/*
* -------- TABLE OF SPECIES IN DECREASING MOLE NUMBERS --------------
*/
// TABLE OF SPECIES IN DECREASING MOLE NUMBERS
plogf("\n\n");
writeline('-', 80);
plogf(" Species Equilibrium kmoles ");
@ -152,9 +140,7 @@ int VCS_SOLVE::vcs_report(int iconv)
writeline('-', 80);
plogf("\n");
/*
* ---------- TABLE OF SPECIES FORMATION REACTIONS ------------------
*/
// TABLE OF SPECIES FORMATION REACTIONS
writeline('-', m_numComponents*10 + 45, true, true);
plogf(" |ComponentID|");
for (size_t j = 0; j < m_numComponents; j++) {
@ -186,9 +172,7 @@ int VCS_SOLVE::vcs_report(int iconv)
writeline('-', m_numComponents*10 + 45);
plogf("\n");
/*
* ------------------ TABLE OF PHASE INFORMATION ---------------------
*/
// TABLE OF PHASE INFORMATION
vector_fp gaPhase(m_numElemConstraints, 0.0);
vector_fp gaTPhase(m_numElemConstraints, 0.0);
double totalMoles = 0.0;
@ -243,15 +227,10 @@ int VCS_SOLVE::vcs_report(int iconv)
writeline('-', m_numElemConstraints*10 + 58);
plogf("\n");
/*
* ----------- GLOBAL SATISFACTION INFORMATION -----------------------
*/
// GLOBAL SATISFACTION INFORMATION
/*
* Calculate the total dimensionless Gibbs Free Energy
* -> Inert species are handled as if they had a standard free
* energy of zero
*/
// Calculate the total dimensionless Gibbs Free Energy. Inert species are
// handled as if they had a standard free energy of zero
double g = vcs_Total_Gibbs(&m_molNumSpecies_old[0], &m_feSpecies_old[0],
&m_tPhaseMoles_old[0]);
plogf("\n\tTotal Dimensionless Gibbs Free Energy = G/RT = %15.7E\n", g);
@ -269,9 +248,7 @@ int VCS_SOLVE::vcs_report(int iconv)
}
plogf("\n");
/*
* ------------------ TABLE OF SPECIES CHEM POTS ---------------------
*/
// TABLE OF SPECIES CHEM POTS
writeline('-', 93, true, true);
plogf("Chemical Potentials of the Species: (dimensionless)\n");
@ -329,9 +306,7 @@ int VCS_SOLVE::vcs_report(int iconv)
plogf(" %20.9E\n", g);
writeline('-', 147);
/*
* ------------- TABLE OF SOLUTION COUNTERS --------------------------
*/
// TABLE OF SOLUTION COUNTERS
plogf("\n");
plogf("\nCounters: Iterations Time (seconds)\n");
if (m_timing_print_lvl > 0) {
@ -348,10 +323,8 @@ int VCS_SOLVE::vcs_report(int iconv)
writeline('-', 80);
writeline('-', 80);
/*
* Set the Units state of the system back to where it was when we
* entered the program.
*/
// Set the Units state of the system back to where it was when we
// entered the program.
if (originalUnitsState != m_unitsState) {
if (originalUnitsState == VCS_DIMENSIONAL_G) {
vcs_redim_TP();
@ -359,9 +332,8 @@ int VCS_SOLVE::vcs_report(int iconv)
vcs_nondim_TP();
}
}
/*
* Return a successful completion flag
*/
// Return a successful completion flag
return VCS_SUCCESS;
}

View file

@ -41,16 +41,14 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial)
#else
char* ANOTE = 0;
#endif
/*
* We update the matrix dlnActCoeffdmolNumber[][] at the
* top of the loop, when necessary
*/
// We update the matrix dlnActCoeffdmolNumber[][] at the top of the loop,
// when necessary
if (m_useActCoeffJac) {
vcs_CalcLnActCoeffJac(&m_molNumSpecies_old[0]);
}
/************************************************************************
******** LOOP OVER THE FORMATION REACTIONS *****************************
************************************************************************/
// LOOP OVER THE FORMATION REACTIONS
for (size_t irxn = 0; irxn < m_numRxnRdc; ++irxn) {
if (DEBUG_MODE_ENABLED) {
sprintf(ANOTE, "Normal Calc");
@ -64,19 +62,14 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial)
}
} else if (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
if (m_molNumSpecies_old[kspec] == 0.0 && (!m_SSPhase[kspec])) {
/********************************************************************/
/******* MULTISPECIES PHASE WITH total moles equal to zero *********/
/*******************************************************************/
/*
* If dg[irxn] is negative, then the multispecies phase should
* come alive again. Add a small positive step size to
* make it come alive.
*/
// MULTISPECIES PHASE WITH total moles equal to zero
//
// If dg[irxn] is negative, then the multispecies phase should
// come alive again. Add a small positive step size to make it
// come alive.
if (m_deltaGRxn_new[irxn] < -1.0e-4) {
/*
* First decide if this species is part of a multiphase that
* is nontrivial in size.
*/
// First decide if this species is part of a multiphase that
// is nontrivial in size.
size_t iph = m_phaseID[kspec];
double tphmoles = m_tPhaseMoles_old[iph];
double trphmoles = tphmoles / m_totalMolNum;
@ -119,15 +112,11 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial)
m_deltaMolNumSpecies[kspec] = 0.0;
}
} else {
/********************************************************************/
/************************* REGULAR PROCESSING ***********************/
/********************************************************************/
/*
* First take care of cases where we want to bail out
*
* Don't bother if superconvergence has already been achieved
* in this mode.
*/
// REGULAR PROCESSING
//
// First take care of cases where we want to bail out. Don't
// bother if superconvergence has already been achieved in this
// mode.
if (fabs(m_deltaGRxn_new[irxn]) <= m_tolmaj2) {
if (DEBUG_MODE_ENABLED) {
sprintf(ANOTE, "Skipped: superconverged DG = %11.3E", m_deltaGRxn_new[irxn]);
@ -140,10 +129,9 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial)
}
continue;
}
/*
* Don't calculate for minor or nonexistent species if
* their values are to be decreasing anyway.
*/
// Don't calculate for minor or nonexistent species if their
// values are to be decreasing anyway.
if ((m_speciesStatus[kspec] != VCS_SPECIES_MAJOR) && (m_deltaGRxn_new[irxn] >= 0.0)) {
if (DEBUG_MODE_ENABLED) {
sprintf(ANOTE, "Skipped: IC = %3d and DG >0: %11.3E", m_speciesStatus[kspec], m_deltaGRxn_new[irxn]);
@ -156,9 +144,8 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial)
}
continue;
}
/*
* Start of the regular processing
*/
// Start of the regular processing
double s;
if (m_SSPhase[kspec]) {
s = 0.0;
@ -177,11 +164,9 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial)
}
}
if (s != 0.0) {
/*
* Take into account of the
* derivatives of the activity coefficients with respect to the
* mole numbers, even in our diagonal approximation.
*/
// Take into account of the derivatives of the activity
// coefficients with respect to the mole numbers, even in
// our diagonal approximation.
if (m_useActCoeffJac) {
double s_old = s;
s = vcs_Hessian_diag_adj(irxn, s_old);
@ -216,7 +201,8 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial)
}
}
}
// Implement a damping term that limits m_deltaMolNumSpecies to the size of the mole number
// Implement a damping term that limits m_deltaMolNumSpecies
// to the size of the mole number
if (-m_deltaMolNumSpecies[kspec] > m_molNumSpecies_old[kspec]) {
if (DEBUG_MODE_ENABLED) {
sprintf(ANOTE, "Delta damped from %g "
@ -226,18 +212,15 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial)
m_deltaMolNumSpecies[kspec] = -m_molNumSpecies_old[kspec];
}
} else {
/* ************************************************************ */
/* **** REACTION IS ENTIRELY AMONGST SINGLE SPECIES PHASES **** */
/* **** DELETE ONE OF THE PHASES AND RECOMPUTE BASIS ********* */
/* ************************************************************ */
/*
* Either the species L will disappear or one of the
* component single species phases will disappear. The sign
* of DG(I) will indicate which way the reaction will go.
* Then, we need to follow the reaction to see which species
* will zero out first.
* -> The species to be zeroed out will be "k".
*/
// REACTION IS ENTIRELY AMONGST SINGLE SPECIES PHASES.
// DELETE ONE OF THE PHASES AND RECOMPUTE BASIS.
//
// Either the species L will disappear or one of the
// component single species phases will disappear. The sign
// of DG(I) will indicate which way the reaction will go.
// Then, we need to follow the reaction to see which species
// will zero out first. The species to be zeroed out will be
// "k".
double dss;
if (m_deltaGRxn_new[irxn] > 0.0) {
dss = m_molNumSpecies_old[kspec];
@ -264,22 +247,20 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial)
}
}
}
/*
* Here we adjust the mole fractions
* according to DSS and the stoichiometric array
* to take into account that we are eliminating
* the kth species. DSS contains the amount
* of moles of the kth species that needs to be
* added back into the component species.
*/
// Here we adjust the mole fractions according to DSS and
// the stoichiometric array to take into account that we are
// eliminating the kth species. DSS contains the amount of
// moles of the kth species that needs to be added back into
// the component species.
if (dss != 0.0) {
if ((k == kspec) && (m_SSPhase[kspec] != 1)) {
/*
* Found out that we can be in this spot, when components of multispecies phases
* are zeroed, leaving noncomponent species of the same phase having all of the
* mole numbers of that phases. it seems that we can suggest a zero of the species
* and the code will recover.
*/
// Found out that we can be in this spot, when
// components of multispecies phases are zeroed,
// leaving noncomponent species of the same phase
// having all of the mole numbers of that phases. it
// seems that we can suggest a zero of the species
// and the code will recover.
if (DEBUG_MODE_ENABLED) {
sprintf(ANOTE, "Delta damped from %g to %g due to delete %s", m_deltaMolNumSpecies[kspec],
-m_molNumSpecies_old[kspec], m_speciesName[kspec].c_str());
@ -293,9 +274,8 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial)
}
continue;
}
/*
* Delete the single species phase
*/
// Delete the single species phase
for (size_t j = 0; j < m_numSpeciesTot; j++) {
m_deltaMolNumSpecies[j] = 0.0;
}
@ -338,15 +318,15 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial)
return iphDel;
}
}
} /* End of regular processing */
} // End of regular processing
if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
plogf(" --- %-12.12s", m_speciesName[kspec]);
plogf(" %12.4E %12.4E %12.4E | %s\n",
m_molNumSpecies_old[kspec], m_deltaMolNumSpecies[kspec],
m_deltaGRxn_new[irxn], ANOTE);
}
} /* End of loop over m_speciesUnknownType */
} /* End of loop over non-component stoichiometric formation reactions */
} // End of loop over m_speciesUnknownType
} // End of loop over non-component stoichiometric formation reactions
if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
plogf(" ");
writeline('-', 82);
@ -369,12 +349,9 @@ int VCS_SOLVE::vcs_rxn_adj_cg()
char* ANOTE = 0;
#endif
/*
* Precalculation loop -> we calculate quantities based on
* loops over the number of species.
* We also evaluate whether the matrix is appropriate for
* this algorithm. If not, we bail out.
*/
// Precalculation loop -> we calculate quantities based on loops over the
// number of species. We also evaluate whether the matrix is appropriate for
// this algorithm. If not, we bail out.
for (size_t irxn = 0; irxn < m_numRxnRdc; ++irxn) {
if (DEBUG_MODE_ENABLED) {
sprintf(ANOTE, "Normal Calc");
@ -382,13 +359,10 @@ int VCS_SOLVE::vcs_rxn_adj_cg()
size_t kspec = m_indexRxnToSpecies[irxn];
if (m_molNumSpecies_old[kspec] == 0.0 && (!m_SSPhase[kspec])) {
/* *******************************************************************/
/* **** MULTISPECIES PHASE WITH total moles equal to zero ************/
/* *******************************************************************/
/*
* HKM -> the statment below presupposes units in m_deltaGRxn_new[]. It probably
* should be replaced with something more relativistic
*/
// MULTISPECIES PHASE WITH total moles equal to zero
//
// HKM -> the statment below presupposes units in m_deltaGRxn_new[].
// It probably should be replaced with something more relativistic
if (m_deltaGRxn_new[irxn] < -1.0e-4) {
if (DEBUG_MODE_ENABLED) {
sprintf(ANOTE, "MultSpec: come alive DG = %11.3E", m_deltaGRxn_new[irxn]);
@ -403,15 +377,10 @@ int VCS_SOLVE::vcs_rxn_adj_cg()
m_deltaMolNumSpecies[kspec] = 0.0;
}
} else {
/* ********************************************** */
/* **** REGULAR PROCESSING ********** */
/* ********************************************** */
/*
* First take care of cases where we want to bail out
*
* Don't bother if superconvergence has already been achieved
* in this mode.
*/
// REGULAR PROCESSING
//
// First take care of cases where we want to bail out. Don't bother
// if superconvergence has already been achieved in this mode.
if (fabs(m_deltaGRxn_new[irxn]) <= m_tolmaj2) {
if (DEBUG_MODE_ENABLED) {
sprintf(ANOTE, "Skipped: converged DG = %11.3E\n", m_deltaGRxn_new[irxn]);
@ -422,10 +391,9 @@ int VCS_SOLVE::vcs_rxn_adj_cg()
}
continue;
}
/*
* Don't calculate for minor or nonexistent species if
* their values are to be decreasing anyway.
*/
// Don't calculate for minor or nonexistent species if their values
// are to be decreasing anyway.
if (m_speciesStatus[kspec] <= VCS_SPECIES_MINOR && m_deltaGRxn_new[irxn] >= 0.0) {
if (DEBUG_MODE_ENABLED) {
sprintf(ANOTE, "Skipped: IC = %3d and DG >0: %11.3E\n", m_speciesStatus[kspec], m_deltaGRxn_new[irxn]);
@ -436,9 +404,8 @@ int VCS_SOLVE::vcs_rxn_adj_cg()
}
continue;
}
/*
* Start of the regular processing
*/
// Start of the regular processing
double s;
if (m_SSPhase[kspec]) {
s = 0.0;
@ -458,17 +425,13 @@ int VCS_SOLVE::vcs_rxn_adj_cg()
if (s != 0.0) {
m_deltaMolNumSpecies[kspec] = -m_deltaGRxn_new[irxn] / s;
} else {
/* ************************************************************ */
/* **** REACTION IS ENTIRELY AMONGST SINGLE SPECIES PHASES **** */
/* **** DELETE ONE SOLID AND RECOMPUTE BASIS ********* */
/* ************************************************************ */
/*
* Either the species L will disappear or one of the
* component single species phases will disappear. The sign
* of DG(I) will indicate which way the reaction will go.
* Then, we need to follow the reaction to see which species
* will zero out first.
*/
// REACTION IS ENTIRELY AMONGST SINGLE SPECIES PHASES. DELETE
// ONE SOLID AND RECOMPUTE BASIS
//
// Either the species L will disappear or one of the component
// single species phases will disappear. The sign of DG(I) will
// indicate which way the reaction will go. Then, we need to
// follow the reaction to see which species will zero out first.
size_t k;
double dss;
if (m_deltaGRxn_new[irxn] > 0.0) {
@ -496,14 +459,12 @@ int VCS_SOLVE::vcs_rxn_adj_cg()
}
}
}
/*
* Here we adjust the mole fractions
* according to DSS and the stoichiometric array
* to take into account that we are eliminating
* the kth species. DSS contains the amount
* of moles of the kth species that needs to be
* added back into the component species.
*/
// Here we adjust the mole fractions according to DSS and the
// stoichiometric array to take into account that we are
// eliminating the kth species. DSS contains the amount of moles
// of the kth species that needs to be added back into the
// component species.
if (dss != 0.0) {
m_molNumSpecies_old[kspec] += dss;
m_tPhaseMoles_old[m_phaseID[kspec]] += dss;
@ -518,11 +479,9 @@ int VCS_SOLVE::vcs_rxn_adj_cg()
plogf("%-12.12s", m_speciesName[k]);
plogf("\n --- Immediate return - Restart iteration\n");
}
/*
* We need to immediately recompute the
* component basis, because we just zeroed
* it out.
*/
// We need to immediately recompute the component basis,
// because we just zeroed it out.
if (k != kspec) {
soldel = 2;
} else {
@ -531,22 +490,19 @@ int VCS_SOLVE::vcs_rxn_adj_cg()
return soldel;
}
}
} /* End of regular processing */
} // End of regular processing
if (DEBUG_MODE_ENABLED) {
plogf(" --- ");
plogf("%-12.12s", m_speciesName[kspec]);
plogf(" %12.4E %12.4E | %s\n", m_molNumSpecies_old[kspec],
m_deltaMolNumSpecies[kspec], ANOTE);
}
} /* End of loop over non-component stoichiometric formation reactions */
} // End of loop over non-component stoichiometric formation reactions
/*
* When we form the Hessian we must be careful to ensure that it
* is a symmetric positive definite matrix, still. This means zeroing
* out columns when we zero out rows as well.
* -> I suggest writing a small program to make sure of this
* property.
*/
// When we form the Hessian we must be careful to ensure that it is a
// symmetric positive definite matrix, still. This means zeroing out columns
// when we zero out rows as well. I suggest writing a small program to make
// sure of this property.
if (DEBUG_MODE_ENABLED) {
plogf(" ");
for (size_t j = 0; j < 77; j++) {
@ -581,14 +537,12 @@ double VCS_SOLVE::vcs_Hessian_actCoeff_diag(size_t irxn)
size_t kph = m_phaseID[kspec];
double np_kspec = std::max(m_tPhaseMoles_old[kph], 1e-13);
double* sc_irxn = m_stoichCoeffRxnMatrix.ptrColumn(irxn);
/*
* First the diagonal term of the Jacobian
*/
// First the diagonal term of the Jacobian
double s = m_np_dLnActCoeffdMolNum(kspec,kspec) / np_kspec;
/*
* Next, the other terms. Note this only a loop over the components
* So, it's not too expensive to calculate.
*/
// Next, the other terms. Note this only a loop over the components So, it's
// not too expensive to calculate.
for (size_t l = 0; l < m_numComponents; l++) {
if (!m_SSPhase[l]) {
for (size_t k = 0; k < m_numComponents; ++k) {
@ -609,24 +563,17 @@ double VCS_SOLVE::vcs_Hessian_actCoeff_diag(size_t irxn)
void VCS_SOLVE::vcs_CalcLnActCoeffJac(const double* const moleSpeciesVCS)
{
/*
* Loop over all of the phases in the problem
*/
// Loop over all of the phases in the problem
for (size_t iphase = 0; iphase < m_numPhases; iphase++) {
vcs_VolPhase* Vphase = m_VolPhaseList[iphase];
/*
* We don't need to call single species phases;
*/
// We don't need to call single species phases;
if (!Vphase->m_singleSpecies && !Vphase->isIdealSoln()) {
/*
* update the mole numbers
*/
// update the mole numbers
Vphase->setMolesFromVCS(VCS_STATECALC_OLD, moleSpeciesVCS);
/*
* Download the resulting calculation into the full vector
* -> This scatter calculation is carried out in the
* vcs_VolPhase object.
*/
// Download the resulting calculation into the full vector. This
// scatter calculation is carried out in the vcs_VolPhase object.
Vphase->sendToVCS_LnActCoeffJac(m_np_dLnActCoeffdMolNum);
}
}
@ -658,9 +605,8 @@ double VCS_SOLVE::vcs_line_search(const size_t irxn, const double dx_orig, char*
vector_fp& molNumBase = m_molNumSpecies_old;
vector_fp& acBase = m_actCoeffSpecies_old;
vector_fp& ac = m_actCoeffSpecies_new;
/*
* Calculate the deltaG value at the dx = 0.0 point
*/
// Calculate the deltaG value at the dx = 0.0 point
vcs_setFlagsVolPhases(false, VCS_STATECALC_OLD);
double deltaGOrig = deltaG_Recalc_Rxn(VCS_STATECALC_OLD, irxn, &molNumBase[0], &acBase[0], &m_feSpecies_old[0]);
double forig = fabs(deltaGOrig) + 1.0E-15;
@ -699,19 +645,16 @@ double VCS_SOLVE::vcs_line_search(const size_t irxn, const double dx_orig, char*
double deltaG1 = deltaG_Recalc_Rxn(VCS_STATECALC_NEW, irxn, &m_molNumSpecies_new[0],
&ac[0], &m_feSpecies_new[0]);
/*
* If deltaG hasn't switched signs when going the full distance
* then we are heading in the appropriate direction, and
* we should accept the current full step size
*/
// If deltaG hasn't switched signs when going the full distance then we are
// heading in the appropriate direction, and we should accept the current
// full step size
if (deltaG1 * deltaGOrig > 0.0) {
dx = dx_orig;
goto finalize;
}
/*
* If we have decreased somewhat, the deltaG return after finding
* a better estimate for the line search.
*/
// If we have decreased somewhat, the deltaG return after finding a better
// estimate for the line search.
if (fabs(deltaG1) < 0.8 * forig) {
if (deltaG1 * deltaGOrig < 0.0) {
double slope = (deltaG1 - deltaGOrig) / dx_orig;
@ -724,10 +667,8 @@ double VCS_SOLVE::vcs_line_search(const size_t irxn, const double dx_orig, char*
dx = dx_orig;
for (its = 0; its < MAXITS; its++) {
/*
* Calculate the approximation to the total Gibbs free energy at
* the dx *= 0.5 point
*/
// Calculate the approximation to the total Gibbs free energy at
// the dx *= 0.5 point
dx *= 0.5;
m_molNumSpecies_new[kspec] = molNumBase[kspec] + dx;
for (size_t k = 0; k < m_numComponents; k++) {
@ -736,18 +677,16 @@ double VCS_SOLVE::vcs_line_search(const size_t irxn, const double dx_orig, char*
vcs_setFlagsVolPhases(false, VCS_STATECALC_NEW);
double deltaG = deltaG_Recalc_Rxn(VCS_STATECALC_NEW, irxn, &m_molNumSpecies_new[0],
&ac[0], &m_feSpecies_new[0]);
/*
* If deltaG hasn't switched signs when going the full distance
* then we are heading in the appropriate direction, and
* we should accept the current step
*/
// If deltaG hasn't switched signs when going the full distance then we
// are heading in the appropriate direction, and we should accept the
// current step
if (deltaG * deltaGOrig > 0.0) {
goto finalize;
}
/*
* If we have decreased somewhat, the deltaG return after finding
* a better estimate for the line search.
*/
// If we have decreased somewhat, the deltaG return after finding
// a better estimate for the line search.
if (fabs(deltaG) / forig < (1.0 - 0.1 * dx / dx_orig)) {
if (deltaG * deltaGOrig < 0.0) {
double slope = (deltaG - deltaGOrig) / dx;

View file

@ -78,11 +78,10 @@ int VCS_SOLVE::vcs_setMolesLinProg()
} else {
abundancesOK = true;
}
/*
* Now find the optimized basis that spans the stoichiometric
* coefficient matrix, based on the current composition, m_molNumSpecies_old[]
* We also calculate sc[][], the reaction matrix.
*/
// Now find the optimized basis that spans the stoichiometric
// coefficient matrix, based on the current composition,
// m_molNumSpecies_old[] We also calculate sc[][], the reaction matrix.
retn = vcs_basopt(false, &aw[0], &sa[0], &sm[0], &ss[0],
test, &usedZeroedSpecies);
if (retn != VCS_SUCCESS) {

View file

@ -121,26 +121,19 @@ void VCS_SOLVE::vcs_initSizes(const size_t nspecies0, const size_t nelements,
m_formulaMatrix.resize(nspecies0, nelements);
TPhInertMoles.resize(nphase0, 0.0);
/*
* ind[] is an index variable that keep track of solution vector
* rotations.
*/
// ind[] is an index variable that keep track of solution vector rotations.
m_speciesMapIndex.resize(nspecies0, 0);
m_speciesLocalPhaseIndex.resize(nspecies0, 0);
/*
* IndEl[] is an index variable that keep track of element vector
* rotations.
*/
// IndEl[] is an index variable that keep track of element vector rotations.
m_elementMapIndex.resize(nelements, 0);
/*
* ir[] is an index vector that keeps track of the irxn to species
* mapping. We can't fill it in until we know the number of c
* components in the problem
*/
// ir[] is an index vector that keeps track of the irxn to species mapping.
// We can't fill it in until we know the number of c components in the
// problem
m_indexRxnToSpecies.resize(nspecies0, 0);
/* Initialize all species to be major species */
// Initialize all species to be major species
m_speciesStatus.resize(nspecies0, 1);
m_SSPhase.resize(2*nspecies0, 0);
@ -150,10 +143,9 @@ void VCS_SOLVE::vcs_initSizes(const size_t nspecies0, const size_t nelements,
m_speciesName.resize(nspecies0, std::string(""));
m_elType.resize(nelements, VCS_ELEM_TYPE_ABSPOS);
m_elementActive.resize(nelements, 1);
/*
* Malloc space for activity coefficients for all species
* -> Set it equal to one.
*/
// Malloc space for activity coefficients for all species. Set it equal to
// one.
m_actConventionSpecies.resize(nspecies0, 0);
m_phaseActConvention.resize(nphase0, 0);
m_lnMnaughtSpecies.resize(nspecies0, 0.0);
@ -163,17 +155,13 @@ void VCS_SOLVE::vcs_initSizes(const size_t nspecies0, const size_t nelements,
m_chargeSpecies.resize(nspecies0, 0.0);
m_speciesThermoList.resize(nspecies0, (VCS_SPECIES_THERMO*)0);
/*
* Malloc Phase Info
*/
// Malloc Phase Info
m_VolPhaseList.resize(nphase0, 0);
for (size_t iph = 0; iph < nphase0; iph++) {
m_VolPhaseList[iph] = new vcs_VolPhase(this);
}
/*
* For Future expansion
*/
// For Future expansion
m_useActCoeffJac = true;
if (m_useActCoeffJac) {
m_np_dLnActCoeffdMolNum.resize(nspecies0, nspecies0, 0.0);
@ -181,10 +169,7 @@ void VCS_SOLVE::vcs_initSizes(const size_t nspecies0, const size_t nelements,
m_PMVolumeSpecies.resize(nspecies0, 0.0);
/*
* Malloc space for counters kept within vcs
*
*/
// Malloc space for counters kept within vcs
m_VCount = new VCS_COUNTERS();
vcs_counters_init(1);
@ -238,10 +223,8 @@ int VCS_SOLVE::vcs(VCS_PROB* vprob, int ifunc, int ipr, int ip1, int maxit)
}
if (ifunc == 0) {
/*
* This function is called to create the private data
* using the public data.
*/
// This function is called to create the private data using the public
// data.
size_t nspecies0 = vprob->nspecies + 10;
size_t nelements0 = vprob->ne;
size_t nphase0 = vprob->NPhase;
@ -252,22 +235,17 @@ int VCS_SOLVE::vcs(VCS_PROB* vprob, int ifunc, int ipr, int ip1, int maxit)
retn);
return retn;
}
/*
* This function is called to copy the public data
* and the current problem specification
* into the current object's data structure.
*/
// This function is called to copy the public data and the current
// problem specification into the current object's data structure.
retn = vcs_prob_specifyFully(vprob);
if (retn != 0) {
plogf("vcs_pub_to_priv returned a bad status, %d: bailing!\n",
retn);
return retn;
}
/*
* Prep the problem data
* - adjust the identity of any phases
* - determine the number of components in the problem
*/
// Prep the problem data
// - adjust the identity of any phases
// - determine the number of components in the problem
retn = vcs_prep_oneTime(ip1);
if (retn != 0) {
plogf("vcs_prep_oneTime returned a bad status, %d: bailing!\n",
@ -276,10 +254,8 @@ int VCS_SOLVE::vcs(VCS_PROB* vprob, int ifunc, int ipr, int ip1, int maxit)
}
}
if (ifunc == 1) {
/*
* This function is called to copy the current problem
* into the current object's data structure.
*/
// This function is called to copy the current problem into the current
// object's data structure.
retn = vcs_prob_specify(vprob);
if (retn != 0) {
plogf("vcs_prob_specify returned a bad status, %d: bailing!\n",
@ -288,62 +264,48 @@ int VCS_SOLVE::vcs(VCS_PROB* vprob, int ifunc, int ipr, int ip1, int maxit)
}
}
if (ifunc != 2) {
/*
* Prep the problem data for this particular instantiation of
* the problem
*/
// Prep the problem data for this particular instantiation of
// the problem
retn = vcs_prep();
if (retn != VCS_SUCCESS) {
plogf("vcs_prep returned a bad status, %d: bailing!\n", retn);
return retn;
}
/*
* Check to see if the current problem is well posed.
*/
// Check to see if the current problem is well posed.
if (!vcs_wellPosed(vprob)) {
plogf("vcs has determined the problem is not well posed: Bailing\n");
return VCS_PUB_BAD;
}
/*
* Once we have defined the global internal data structure defining
* the problem, then we go ahead and solve the problem.
*
* (right now, all we do is solve fixed T, P problems.
* Methods for other problem types will go in at this level.
* For example, solving for fixed T, V problems will involve
* a 2x2 Newton's method, using loops over vcs_TP() to
* calculate the residual and Jacobian)
*/
// Once we have defined the global internal data structure defining the
// problem, then we go ahead and solve the problem.
//
// (right now, all we do is solve fixed T, P problems. Methods for other
// problem types will go in at this level. For example, solving for
// fixed T, V problems will involve a 2x2 Newton's method, using loops
// over vcs_TP() to calculate the residual and Jacobian)
iconv = vcs_TP(ipr, ip1, maxit, vprob->T, vprob->PresPA);
/*
* If requested to print anything out, go ahead and do so;
*/
// If requested to print anything out, go ahead and do so;
if (ipr > 0) {
vcs_report(iconv);
}
/*
* Copy the results of the run back to the VCS_PROB structure,
* which is returned to the user.
*/
// Copy the results of the run back to the VCS_PROB structure, which is
// returned to the user.
vcs_prob_update(vprob);
}
/*
* Report on the time if requested to do so
*/
// Report on the time if requested to do so
double te = tickTock.secondsWC();
m_VCount->T_Time_vcs += te;
if (iprintTime > 0) {
vcs_TCounters_report(m_timing_print_lvl);
}
/*
* Now, destroy the private data, if requested to do so
*
* FILL IN
*/
// Now, destroy the private data, if requested to do so
// FILL IN
if (iconv < 0) {
plogf("ERROR: FAILURE its = %d!\n", m_VCount->Its);
} else if (iconv == 1) {
@ -357,10 +319,7 @@ int VCS_SOLVE::vcs_prob_specifyFully(const VCS_PROB* pub)
const char* ser =
"vcs_pub_to_priv ERROR :ill defined interface -> bailout:\n\t";
/*
* First Check to see whether we have room for the current problem
* size
*/
// First Check to see whether we have room for the current problem size
size_t nspecies = pub->nspecies;
if (NSPECIES0 < nspecies) {
plogf("%sPrivate Data is dimensioned too small\n", ser);
@ -377,37 +336,30 @@ int VCS_SOLVE::vcs_prob_specifyFully(const VCS_PROB* pub)
return VCS_PUB_BAD;
}
/*
* OK, We have room. Now, transfer the integer numbers
*/
// OK, We have room. Now, transfer the integer numbers
m_numElemConstraints = nelements;
m_numSpeciesTot = nspecies;
m_numSpeciesRdc = m_numSpeciesTot;
/*
* nc = number of components -> will be determined later.
* but set it to its maximum possible value here.
*/
// nc = number of components -> will be determined later. but set it to its
// maximum possible value here.
m_numComponents = nelements;
/*
* m_numRxnTot = number of noncomponents, also equal to the
* number of reactions
* Note, it's possible that the number of elements is greater than
* the number of species. In that case set the number of reactions
* to zero.
*/
// m_numRxnTot = number of noncomponents, also equal to the number of
// reactions. Note, it's possible that the number of elements is greater
// than the number of species. In that case set the number of reactions to
// zero.
if (nelements > nspecies) {
m_numRxnTot = 0;
} else {
m_numRxnTot = nspecies - nelements;
}
m_numRxnRdc = m_numRxnTot;
/*
* number of minor species rxn -> all species rxn are major at the start.
*/
// number of minor species rxn -> all species rxn are major at the start.
m_numRxnMinorZeroed = 0;
/*
* NPhase = number of phases
*/
// NPhase = number of phases
m_numPhases = nph;
#ifdef DEBUG_MODE
@ -416,9 +368,7 @@ int VCS_SOLVE::vcs_prob_specifyFully(const VCS_PROB* pub)
m_debug_print_lvl = std::min(2, pub->vcs_debug_print_lvl);
#endif
/*
* FormulaMatrix[] -> Copy the formula matrix over
*/
// FormulaMatrix[] -> Copy the formula matrix over
for (size_t i = 0; i < nspecies; i++) {
bool nonzero = false;
for (size_t j = 0; j < nelements; j++) {
@ -434,20 +384,13 @@ int VCS_SOLVE::vcs_prob_specifyFully(const VCS_PROB* pub)
}
}
/*
* Copy over the species molecular weights
*/
// Copy over the species molecular weights
m_wtSpecies = pub->WtSpecies;
/*
* Copy over the charges
*/
// Copy over the charges
m_chargeSpecies = pub->Charge;
/*
* Malloc and Copy the VCS_SPECIES_THERMO structures
*
*/
// Malloc and Copy the VCS_SPECIES_THERMO structures
for (size_t kspec = 0; kspec < nspecies; kspec++) {
delete m_speciesThermoList[kspec];
VCS_SPECIES_THERMO* spf = pub->SpeciesThermo[kspec];
@ -458,19 +401,13 @@ int VCS_SOLVE::vcs_prob_specifyFully(const VCS_PROB* pub)
}
}
/*
* Copy the species unknown type
*/
// Copy the species unknown type
m_speciesUnknownType = pub->SpeciesUnknownType;
/*
* iest => Do we have an initial estimate of the species mole numbers ?
*/
// iest => Do we have an initial estimate of the species mole numbers ?
m_doEstimateEquil = pub->iest;
/*
* w[] -> Copy the equilibrium mole number estimate if it exists.
*/
// w[] -> Copy the equilibrium mole number estimate if it exists.
if (pub->w.size() != 0) {
m_molNumSpecies_old = pub->w;
} else {
@ -478,9 +415,7 @@ int VCS_SOLVE::vcs_prob_specifyFully(const VCS_PROB* pub)
m_molNumSpecies_old.assign(m_molNumSpecies_old.size(), 0.0);
}
/*
* Formulate the Goal Element Abundance Vector
*/
// Formulate the Goal Element Abundance Vector
if (pub->gai.size() != 0) {
for (size_t i = 0; i < nelements; i++) {
m_elemAbundancesGoal[i] = pub->gai[i];
@ -509,16 +444,13 @@ int VCS_SOLVE::vcs_prob_specifyFully(const VCS_PROB* pub)
}
}
/*
* zero out values that will be filled in later
*/
/*
* TPhMoles[] -> Untouched here. These will be filled in vcs_prep.c
* TPhMoles1[]
* DelTPhMoles[]
*
* T, Pres, copy over here
*/
// zero out values that will be filled in later
//
// TPhMoles[] -> Untouched here. These will be filled in vcs_prep.c
// TPhMoles1[]
// DelTPhMoles[]
//
// T, Pres, copy over here
if (pub->T > 0.0) {
m_temperature = pub->T;
} else {
@ -529,53 +461,40 @@ int VCS_SOLVE::vcs_prob_specifyFully(const VCS_PROB* pub)
} else {
m_pressurePA = OneAtm;
}
/*
* TPhInertMoles[] -> must be copied over here
*/
// TPhInertMoles[] -> must be copied over here
for (size_t iph = 0; iph < nph; iph++) {
vcs_VolPhase* Vphase = pub->VPhaseList[iph];
TPhInertMoles[iph] = Vphase->totalMolesInert();
}
/*
* if__ : Copy over the units for the chemical potential
*/
// if__ : Copy over the units for the chemical potential
m_VCS_UnitsFormat = pub->m_VCS_UnitsFormat;
/*
* tolerance requirements -> copy them over here and later
*/
// tolerance requirements -> copy them over here and later
m_tolmaj = pub->tolmaj;
m_tolmin = pub->tolmin;
m_tolmaj2 = 0.01 * m_tolmaj;
m_tolmin2 = 0.01 * m_tolmin;
/*
* m_speciesIndexVector[] is an index variable that keep track
* of solution vector rotations.
*/
// m_speciesIndexVector[] is an index variable that keep track of solution
// vector rotations.
for (size_t i = 0; i < nspecies; i++) {
m_speciesMapIndex[i] = i;
}
/*
* IndEl[] is an index variable that keep track of element vector
* rotations.
*/
// IndEl[] is an index variable that keep track of element vector rotations.
for (size_t i = 0; i < nelements; i++) {
m_elementMapIndex[i] = i;
}
/*
* Define all species to be major species, initially.
*/
// Define all species to be major species, initially.
for (size_t i = 0; i < nspecies; i++) {
m_speciesStatus[i] = VCS_SPECIES_MAJOR;
}
/*
* PhaseID: Fill in the species to phase mapping
* -> Check for bad values at the same time.
*/
// PhaseID: Fill in the species to phase mapping. Check for bad values at
// the same time.
if (pub->PhaseID.size() != 0) {
std::vector<size_t> numPhSp(nph, 0);
for (size_t kspec = 0; kspec < nspecies; kspec++) {
@ -611,15 +530,11 @@ int VCS_SOLVE::vcs_prob_specifyFully(const VCS_PROB* pub)
}
}
/*
* Copy over the element types
*/
// Copy over the element types
m_elType.resize(nelements, VCS_ELEM_TYPE_ABSPOS);
m_elementActive.resize(nelements, 1);
/*
* Copy over the element names and types
*/
// Copy over the element names and types
for (size_t i = 0; i < nelements; i++) {
m_elementName[i] = pub->ElName[i];
m_elType[i] = pub->m_elType[i];
@ -653,23 +568,18 @@ int VCS_SOLVE::vcs_prob_specifyFully(const VCS_PROB* pub)
}
}
/*
* Copy over the species names
*/
// Copy over the species names
for (size_t i = 0; i < nspecies; i++) {
m_speciesName[i] = pub->SpName[i];
}
/*
* Copy over all of the phase information
* Use the object's assignment operator
*/
// Copy over all of the phase information. Use the object's assignment
// operator
for (size_t iph = 0; iph < nph; iph++) {
*m_VolPhaseList[iph] = *pub->VPhaseList[iph];
/*
* Fix up the species thermo pointer in the vcs_SpeciesThermo object
* It should point to the species thermo pointer in the private
* data space.
*/
// Fix up the species thermo pointer in the vcs_SpeciesThermo object. It
// should point to the species thermo pointer in the private data space.
vcs_VolPhase* Vphase = m_VolPhaseList[iph];
for (size_t k = 0; k < Vphase->nSpecies(); k++) {
vcs_SpeciesProperties* sProp = Vphase->speciesProperty(k);
@ -678,22 +588,17 @@ int VCS_SOLVE::vcs_prob_specifyFully(const VCS_PROB* pub)
}
}
/*
* Specify the Activity Convention information
*/
// Specify the Activity Convention information
for (size_t iph = 0; iph < nph; iph++) {
vcs_VolPhase* Vphase = m_VolPhaseList[iph];
m_phaseActConvention[iph] = Vphase->p_activityConvention;
if (Vphase->p_activityConvention != 0) {
/*
* We assume here that species 0 is the solvent.
* The solvent isn't on a unity activity basis
* The activity for the solvent assumes that the
* it goes to one as the species mole fraction goes to
* one; i.e., it's really on a molarity framework.
* So SpecLnMnaught[iSolvent] = 0.0, and the
* loop below starts at 1, not 0.
*/
// We assume here that species 0 is the solvent. The solvent isn't
// on a unity activity basis The activity for the solvent assumes
// that the it goes to one as the species mole fraction goes to one;
// i.e., it's really on a molarity framework. So
// SpecLnMnaught[iSolvent] = 0.0, and the loop below starts at 1,
// not 0.
size_t iSolvent = Vphase->spGlobalIndexVCS(0);
double mnaught = m_wtSpecies[iSolvent] / 1000.;
for (size_t k = 1; k < Vphase->nSpecies(); k++) {
@ -704,26 +609,20 @@ int VCS_SOLVE::vcs_prob_specifyFully(const VCS_PROB* pub)
}
}
/*
* Copy the title info
*/
// Copy the title info
if (pub->Title.size() == 0) {
m_title = "Unspecified Problem Title";
} else {
m_title = pub->Title;
}
/*
* Copy the volume info
*/
// Copy the volume info
m_totalVol = pub->Vol;
if (m_PMVolumeSpecies.size() != 0) {
m_PMVolumeSpecies = pub->VolPM;
}
/*
* Return the success flag
*/
// Return the success flag
return VCS_SUCCESS;
}
@ -749,17 +648,13 @@ int VCS_SOLVE::vcs_prob_specify(const VCS_PROB* pub)
m_feSpecies_old[kspec] = pub->m_gibbsSpecies[k];
}
/*
* Transfer the element abundance goals to the solve object
*/
// Transfer the element abundance goals to the solve object
for (size_t i = 0; i < m_numElemConstraints; i++) {
size_t j = m_elementMapIndex[i];
m_elemAbundancesGoal[i] = pub->gai[j];
}
/*
* Try to do the best job at guessing at the title
*/
// Try to do the best job at guessing at the title
if (pub->Title.size() == 0) {
if (m_title.size() == 0) {
m_title = "Unspecified Problem Title";
@ -768,14 +663,9 @@ int VCS_SOLVE::vcs_prob_specify(const VCS_PROB* pub)
m_title = pub->Title;
}
/*
* Copy over the phase information.
* -> For each entry in the phase structure, determine
* if that entry can change from its initial value
* Either copy over the new value or create an error
* condition.
*/
// Copy over the phase information. For each entry in the phase structure,
// determine if that entry can change from its initial value Either copy
// over the new value or create an error condition.
bool status_change = false;
for (size_t iph = 0; iph < m_numPhases; iph++) {
vcs_VolPhase* vPhase = m_VolPhaseList[iph];
@ -816,9 +706,8 @@ int VCS_SOLVE::vcs_prob_specify(const VCS_PROB* pub)
if (vPhase->totalMolesInert() != pub_phase_ptr->totalMolesInert()) {
status_change = true;
}
/*
* Copy over the number of inert moles if it has changed.
*/
// Copy over the number of inert moles if it has changed.
TPhInertMoles[iph] = pub_phase_ptr->totalMolesInert();
vPhase->setTotalMolesInert(pub_phase_ptr->totalMolesInert());
if (TPhInertMoles[iph] > 0.0) {
@ -826,9 +715,7 @@ int VCS_SOLVE::vcs_prob_specify(const VCS_PROB* pub)
vPhase->m_singleSpecies = false;
}
/*
* Copy over the interfacial potential
*/
// Copy over the interfacial potential
double phi = pub_phase_ptr->electricPotential();
vPhase->setElectricPotential(phi);
}
@ -836,9 +723,8 @@ int VCS_SOLVE::vcs_prob_specify(const VCS_PROB* pub)
if (status_change) {
vcs_SSPhase();
}
/*
* Calculate the total number of moles in all phases.
*/
// Calculate the total number of moles in all phases.
vcs_tmoles();
return retn;
}
@ -851,19 +737,16 @@ int VCS_SOLVE::vcs_prob_update(VCS_PROB* pub)
&m_molNumSpecies_old[0], &m_PMVolumeSpecies[0]);
for (size_t i = 0; i < m_numSpeciesTot; ++i) {
/*
* Find the index of I in the index vector, m_speciesIndexVector[].
* Call it K1 and continue.
*/
// Find the index of I in the index vector, m_speciesIndexVector[]. Call
// it K1 and continue.
for (size_t j = 0; j < m_numSpeciesTot; ++j) {
k1 = j;
if (m_speciesMapIndex[j] == i) {
break;
}
}
/*
* - Switch the species data back from K1 into I
*/
// Switch the species data back from K1 into I
if (pub->SpeciesUnknownType[i] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
pub->w[i] = m_molNumSpecies_old[k1];
} else {

File diff suppressed because it is too large Load diff

View file

@ -16,16 +16,11 @@ namespace Cantera
int VCS_SOLVE::vcs_PS(VCS_PROB* vprob, int iphase, int printLvl, double& feStable)
{
/*
* ifunc determines the problem type
*/
// ifunc determines the problem type
int ifunc = 0;
int iStab = 0;
/*
* This function is called to create the private data
* using the public data.
*/
// This function is called to create the private data using the public data.
size_t nspecies0 = vprob->nspecies + 10;
size_t nelements0 = vprob->ne;
size_t nphase0 = vprob->NPhase;
@ -37,22 +32,18 @@ int VCS_SOLVE::vcs_PS(VCS_PROB* vprob, int iphase, int printLvl, double& feStabl
return VCS_PUB_BAD;
}
/*
* This function is called to copy the public data
* and the current problem specification
* into the current object's data structure.
*/
// This function is called to copy the public data and the current problem
// specification into the current object's data structure.
int retn = vcs_prob_specifyFully(vprob);
if (retn != 0) {
plogf("vcs_pub_to_priv returned a bad status, %d: bailing!\n",
retn);
return retn;
}
/*
* Prep the problem data
* - adjust the identity of any phases
* - determine the number of components in the problem
*/
// Prep the problem data
// - adjust the identity of any phases
// - determine the number of components in the problem
retn = vcs_prep_oneTime(printLvl);
if (retn != 0) {
plogf("vcs_prep_oneTime returned a bad status, %d: bailing!\n",
@ -60,10 +51,8 @@ int VCS_SOLVE::vcs_PS(VCS_PROB* vprob, int iphase, int printLvl, double& feStabl
return retn;
}
/*
* This function is called to copy the current problem
* into the current object's data structure.
*/
// This function is called to copy the current problem into the current
// object's data structure.
retn = vcs_prob_specify(vprob);
if (retn != 0) {
plogf("vcs_prob_specify returned a bad status, %d: bailing!\n",
@ -71,62 +60,46 @@ int VCS_SOLVE::vcs_PS(VCS_PROB* vprob, int iphase, int printLvl, double& feStabl
return retn;
}
/*
* Prep the problem data for this particular instantiation of
* the problem
*/
// Prep the problem data for this particular instantiation of the problem
retn = vcs_prep();
if (retn != VCS_SUCCESS) {
plogf("vcs_prep returned a bad status, %d: bailing!\n", retn);
return retn;
}
/*
* Check to see if the current problem is well posed.
*/
// Check to see if the current problem is well posed.
if (!vcs_wellPosed(vprob)) {
plogf("vcs has determined the problem is not well posed: Bailing\n");
return VCS_PUB_BAD;
}
/*
* Store the temperature and pressure in the private global variables
*/
// Store the temperature and pressure in the private global variables
m_temperature = vprob->T;
m_pressurePA = vprob->PresPA;
/*
* Evaluate the standard state free energies
* at the current temperatures and pressures.
*/
// Evaluate the standard state free energies at the current temperatures and
// pressures.
vcs_evalSS_TP(printLvl, printLvl, m_temperature, m_pressurePA);
/*
* Prepare the problem data:
* ->nondimensionalize the free energies using
* the divisor, R * T
*/
// Prepare the problem data: nondimensionalize the free energies using the
// divisor, R * T
vcs_nondim_TP();
/*
* Prep the fe field
*/
// Prep the fe field
vcs_fePrep_TP();
/*
* Solve the problem at a fixed Temperature and Pressure
* (all information concerning Temperature and Pressure has already
* been derived. The free energies are now in dimensionless form.)
*/
// Solve the problem at a fixed Temperature and Pressure (all information
// concerning Temperature and Pressure has already been derived. The free
// energies are now in dimensionless form.)
iStab = vcs_solve_phaseStability(iphase, ifunc, feStable, printLvl);
/*
* Redimensionalize the free energies using
* the reverse of vcs_nondim to add back units.
*/
// Redimensionalize the free energies using the reverse of vcs_nondim to add
// back units.
vcs_redim_TP();
vcs_prob_update(vprob);
/*
* Return the convergence success flag.
*/
// Return the convergence success flag.
return iStab;
}

View file

@ -140,12 +140,10 @@ double VCS_SPECIES_THERMO::G0_R_calc(size_t kglob, double TKelvin)
double VCS_SPECIES_THERMO::eval_ac(size_t kglob)
{
/*
* Activity coefficients are frequently evaluated on a per phase
* basis. If they are, then the currPhAC[] boolean may be used
* to reduce repeated work. Just set currPhAC[iph], when the
* activity coefficients for all species in the phase are reevaluated.
*/
// Activity coefficients are frequently evaluated on a per phase basis. If
// they are, then the currPhAC[] boolean may be used to reduce repeated
// work. Just set currPhAC[iph], when the activity coefficients for all
// species in the phase are reevaluated.
size_t kspec = IndexSpeciesPhase;
double ac = OwningPhase->AC_calc_one(kspec);
return ac;

View file

@ -70,7 +70,7 @@ double vcsUtil_gasConstant(int mu_units)
case VCS_UNITS_KELVIN:
return 1.0;
case VCS_UNITS_MKS:
/* joules / kg-mol K = kg m2 / s2 kg-mol K */
// joules / kg-mol K = kg m2 / s2 kg-mol K
return GasConstant;
default:
throw CanteraError("vcsUtil_gasConstant", "uknown units: {}", mu_units);