diff --git a/include/cantera/equil/vcs_MultiPhaseEquil.h b/include/cantera/equil/vcs_MultiPhaseEquil.h index 201d70f07..a3eaaca01 100644 --- a/include/cantera/equil/vcs_MultiPhaseEquil.h +++ b/include/cantera/equil/vcs_MultiPhaseEquil.h @@ -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. diff --git a/include/cantera/equil/vcs_SpeciesProperties.h b/include/cantera/equil/vcs_SpeciesProperties.h index 03dbbd1b9..c10a0db13 100644 --- a/include/cantera/equil/vcs_SpeciesProperties.h +++ b/include/cantera/equil/vcs_SpeciesProperties.h @@ -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); diff --git a/include/cantera/equil/vcs_VolPhase.h b/include/cantera/equil/vcs_VolPhase.h index 721e39ee2..355477362 100644 --- a/include/cantera/equil/vcs_VolPhase.h +++ b/include/cantera/equil/vcs_VolPhase.h @@ -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 &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 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 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); diff --git a/include/cantera/equil/vcs_defs.h b/include/cantera/equil/vcs_defs.h index 653da9a6c..0768eb0c8 100644 --- a/include/cantera/equil/vcs_defs.h +++ b/include/cantera/equil/vcs_defs.h @@ -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 diff --git a/include/cantera/equil/vcs_internal.h b/include/cantera/equil/vcs_internal.h index 4e3eaec8c..9a3121513 100644 --- a/include/cantera/equil/vcs_internal.h +++ b/include/cantera/equil/vcs_internal.h @@ -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); } diff --git a/include/cantera/equil/vcs_prob.h b/include/cantera/equil/vcs_prob.h index 64f74a4b7..cb6dff107 100644 --- a/include/cantera/equil/vcs_prob.h +++ b/include/cantera/equil/vcs_prob.h @@ -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); }; diff --git a/include/cantera/equil/vcs_solve.h b/include/cantera/equil/vcs_solve.h index 5783c5d9f..b48a97d18 100644 --- a/include/cantera/equil/vcs_solve.h +++ b/include/cantera/equil/vcs_solve.h @@ -30,21 +30,18 @@ namespace Cantera { -/* - * Forward references - */ + class vcs_VolPhase; class VCS_SPECIES_THERMO; class VCS_PROB; class VCS_COUNTERS; - //! This is the main structure used to hold the internal data //! used in vcs_solve_TP(), and to solve TP systems. /*! - * The indices of information in this structure may change when the species - * basis changes or when phases pop in and out of existence. Both of these - * operations change the species ordering. + * The indices of information in this structure may change when the species + * basis changes or when phases pop in and out of existence. Both of these + * operations change the species ordering. */ class VCS_SOLVE { @@ -55,65 +52,57 @@ public: //! Initialize the sizes within the VCS_SOLVE object /*! - * This resizes all of the internal arrays within the object. This - * routine operates in two modes. If all of the parameters are the same - * as it currently exists in the object, nothing is done by this routine; - * a quick exit is carried out and all of the data in the object - * persists. + * This resizes all of the internal arrays within the object. This routine + * operates in two modes. If all of the parameters are the same as it + * currently exists in the object, nothing is done by this routine; a quick + * exit is carried out and all of the data in the object persists. * - * If any of the parameters are different than currently exists in the - * object, then all of the data in the object must be redone. It may not - * be zeroed, but it must be redone. + * If any of the parameters are different than currently exists in the + * object, then all of the data in the object must be redone. It may not be + * zeroed, but it must be redone. * - * @param nspecies0 Number of species within the object - * @param nelements Number of element constraints within the problem - * @param nphase0 Number of phases defined within the problem. + * @param nspecies0 Number of species within the object + * @param nelements Number of element constraints within the problem + * @param nphase0 Number of phases defined within the problem. */ void vcs_initSizes(const size_t nspecies0, const size_t nelements, const size_t nphase0); //! Solve an equilibrium problem /*! - * This is the main interface routine to the equilibrium solver + * This is the main interface routine to the equilibrium solver * - * Input: - * @param vprob Object containing the equilibrium Problem statement - * @param ifunc Determines the operation to be done: Valid values: - * 0 -> Solve a new problem by initializing structures - * first. An initial estimate may or may not have - * been already determined. This is indicated in the - * VCS_PROB structure. - * 1 -> The problem has already been initialized and - * set up. We call this routine to resolve it - * using the problem statement and - * solution estimate contained in - * the VCS_PROB structure. - * 2 -> Don't solve a problem. Destroy all the private - * structures. - * @param ipr Printing of results + * @param vprob Object containing the equilibrium Problem statement + * @param ifunc Determines the operation to be done: Valid values: + * 0 -> Solve a new problem by initializing structures first. An + * initial estimate may or may not have been already + * determined. This is indicated in the VCS_PROB structure. + * 1 -> The problem has already been initialized and set up. We + * call this routine to resolve it using the problem + * statement and solution estimate contained in the VCS_PROB + * structure. + * 2 -> Don't solve a problem. Destroy all the private + * structures. + * @param ipr Printing of results * ipr = 1 -> Print problem statement and final results to * standard output * 0 -> don't report on anything - * @param ip1 Printing of intermediate results + * @param ip1 Printing of intermediate results * IP1 = 1 -> Print intermediate results. - * @param maxit Maximum number of iterations for the algorithm - * - * Output: - * - * @return - * nonzero value: failure to solve the problem at hand. - * zero : success + * @param maxit Maximum number of iterations for the algorithm + * @return nonzero value: failure to solve the problem at hand. zero : + * success */ int vcs(VCS_PROB* vprob, int ifunc, int ipr, int ip1, int maxit); - //! Main routine that solves for equilibrium at constant T and P - //! using a variant of the VCS method + //! Main routine that solves for equilibrium at constant T and P using a + //! variant of the VCS method /*! * This is the main routine that solves for equilibrium at constant T and P - * using a variant of the VCS method. Nonideal phases can be accommodated - * as well. + * using a variant of the VCS method. Nonideal phases can be accommodated as + * well. * - * Any number of single-species phases and multi-species phases - * can be handled by the present version. + * Any number of single-species phases and multi-species phases can be + * handled by the present version. * * @param print_lvl 1 -> Print results to standard output; * 0 -> don't report on anything @@ -142,8 +131,8 @@ public: * * The algorithm proceeds to implement these decisions in the previous * position of the species. Then, vcs_switch_pos is called to move the - * species into the last active species slot, incrementing the number - * of active species at the same time. + * species into the last active species slot, incrementing the number of + * active species at the same time. * * This routine is responsible for the global data manipulation only. */ @@ -165,8 +154,8 @@ public: * * @param[in] doJustComponents If true, the m_stoichCoeffRxnMatrix and * m_deltaMolNumPhase are not calculated. - * @param[in] aw Vector of mole fractions which will be used to construct an - * optimal basis from. + * @param[in] aw Vector of mole fractions which will be used to + * construct an optimal basis from. * @param[in] sa Gram-Schmidt orthog work space (nc in length) sa[j] * @param[in] ss Gram-Schmidt orthog work space (nc in length) ss[j] * @param[in] sm QR matrix work space (nc*ne in length) sm[i+j*ne] @@ -177,7 +166,7 @@ public: * The problem may be converged. Or, the * problem may have a range space error and * may not have a proper solution. - * @return Returns VCS_SUCCESS if everything went ok. Returns + * @returns VCS_SUCCESS if everything went ok. Returns * VCS_FAILED_CONVERGENCE if there is a problem. * * ### Internal Variables calculated by this routine: @@ -200,23 +189,23 @@ public: //! Choose a species to test for the next component /*! - * We make the choice based on testing (molNum[i] * spSize[i]) for its - * maximum value. Preference for single species phases is also made. + * We make the choice based on testing (molNum[i] * spSize[i]) for its + * maximum value. Preference for single species phases is also made. * - * @param molNum Mole number vector - * @param j index into molNum[] that indicates where the search - * will start from Previous successful components are - * swapped into the front of molNum[]. - * @param n Length of molNum[] + * @param molNum Mole number vector + * @param j index into molNum[] that indicates where the search will + * start from Previous successful components are swapped into the front + * of molNum[]. + * @param n Length of molNum[] */ size_t vcs_basisOptMax(const double* const molNum, const size_t j, const size_t n); //! Evaluate the species category for the indicated species /*! - * All evaluations are done using the "old" version of the solution. + * All evaluations are done using the "old" version of the solution. * - * @param kspec Species to be evaluated - * @return Returns the calculated species type + * @param kspec Species to be evaluated + * @returns the calculated species type */ int vcs_species_type(const size_t kspec) const; @@ -285,9 +274,8 @@ public: * + ln(ActCoeff[I] * z(I)) - ln(m_tPhaseMoles[iph]) * + m_chargeSpecies[I] * Faraday_dim * m_phasePhi[iphase]; * - * ( This is equivalent to the adding the log of the mole fraction - * multiplied by the activity coefficient onto the standard chemical - * potential. ) + * (This is equivalent to the adding the log of the mole fraction multiplied + * by the activity coefficient onto the standard chemical potential.) * * ### ActivityConvention = 1: molality activity formulation * @@ -317,7 +305,6 @@ public: * * `z(I)/tPhMoles_ptr[iph] = Xmol[i]` is the mole fraction of i in the phase. * - * * NOTE: As per the discussion in vcs_dfe(), for small species where the * mole fraction is small: * @@ -328,12 +315,12 @@ public: * m_feSpecies(I) = m_SSfeSpecies(I) * + ln(ActCoeff[i](VCS_DELETE_MINORSPECIES_CUTOFF)) * - * @param[in] iph Phase to be calculated - * @param[in] molNum Number of moles of species i (VCS species order) - * @param[out] ac Activity coefficients for species in phase (VCS - * species order) - * @param[out] mu_i Dimensionless chemical potentials for phase - * species (VCS species order) + * @param[in] iph Phase to be calculated + * @param[in] molNum Number of moles of species i (VCS species order) + * @param[out] ac Activity coefficients for species in phase (VCS + * species order) + * @param[out] mu_i Dimensionless chemical potentials for phase + * species (VCS species order) */ void vcs_chemPotPhase(const int stateCalc, const size_t iph, const double* const molNum, double* const ac, double* const mu_i, @@ -342,10 +329,10 @@ public: //! Calculate the dimensionless chemical potentials of all species or //! of certain groups of species, at a fixed temperature and pressure. /*! - * We calculate the dimensionless chemical potentials of all species - * or certain groups of species here, at a fixed temperature and pressure, - * for the input mole vector z[] in the parameter list. - * Nondimensionalization is achieved by division by RT. + * We calculate the dimensionless chemical potentials of all species or + * certain groups of species here, at a fixed temperature and pressure, for + * the input mole vector z[] in the parameter list. Nondimensionalization is + * achieved by division by RT. * * Note, for multispecies phases which are currently zeroed out, the * chemical potential is filled out with the standard chemical potential. @@ -427,18 +414,18 @@ public: //! Print out a table of chemical potentials /*! - * @param stateCalc Determines where to get the mole numbers from. - * - VCS_STATECALC_OLD -> from m_molNumSpecies_old - * - VCS_STATECALC_NEW -> from m_molNumSpecies_new + * @param stateCalc Determines where to get the mole numbers from. + * - VCS_STATECALC_OLD -> from m_molNumSpecies_old + * - VCS_STATECALC_NEW -> from m_molNumSpecies_new */ void vcs_printSpeciesChemPot(const int stateCalc) const; - //! This routine uploads the state of the system into all of the - //! vcs_VolumePhase objects in the current problem. + //! This routine uploads the state of the system into all of the + //! vcs_VolumePhase objects in the current problem. /*! - * @param stateCalc Determines where to get the mole numbers from. - * - VCS_STATECALC_OLD -> from m_molNumSpecies_old - * - VCS_STATECALC_NEW -> from m_molNumSpecies_new + * @param stateCalc Determines where to get the mole numbers from. + * - VCS_STATECALC_OLD -> from m_molNumSpecies_old + * - VCS_STATECALC_NEW -> from m_molNumSpecies_new */ void vcs_updateVP(const int stateCalc); @@ -454,17 +441,17 @@ public: * are increased. * * @param iphasePop id of the phase, which is currently zeroed, - * @return Returns true if the phase can come into existence - * and false otherwise. + * @returns true if the phase can come into existence and false otherwise. */ bool vcs_popPhasePossible(const size_t iphasePop) const; - //! Determine the list of problems that need to be checked to see if there are any phases pops + //! Determine the list of problems that need to be checked to see if there + //! are any phases pops /*! - * This routine evaluates and fills in #phasePopProblemLists_. Need to - * work in species that are zeroed by element constraints. + * This routine evaluates and fills in #phasePopProblemLists_. Need to + * work in species that are zeroed by element constraints. * - * @return Returns the number of problems that must be checked. + * @returns the number of problems that must be checked. */ int vcs_phasePopDeterminePossibleList(); @@ -472,8 +459,8 @@ public: /*! * @param phasePopPhaseIDs Vector containing the phase ids of the phases * that will be popped this step. - * @return returns the phase id of the phase that pops back into - * existence. Returns -1 if there are no phases + * @returns the phase id of the phase that pops back into existence. Returns + * -1 if there are no phases */ size_t vcs_popPhaseID(std::vector &phasePopPhaseIDs); @@ -485,7 +472,7 @@ public: * for species irxn + M, where M is the number of components. * * @param iphasePop Phase id of the phase that will come into existence - * @return Returns an int representing the status of the step + * @returns an int representing the status of the step * - 0 : normal return * - 1 : A single species phase species has been zeroed out * in this routine. The species is a noncomponent @@ -497,7 +484,7 @@ public: //! Calculates formation reaction step sizes. /*! - * This is equation 6.4-16, p. 143 in Smith and Missen. + * This is equation 6.4-16, p. 143 in Smith and Missen. * * Output * ------- @@ -512,14 +499,14 @@ public: * @param forceComponentCalc integer flagging whether a component * recalculation needs to be carried out. * @param kSpecial species number of phase being zeroed. - * @return Returns an int representing which phase may need to be zeroed + * @returns an int representing which phase may need to be zeroed */ size_t vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial); //! Calculates the total number of moles of species in all phases. /*! - * Also updates the variable m_totalMolNum and Reconciles Phase existence - * flags with total moles in each phase. + * Also updates the variable m_totalMolNum and Reconciles Phase existence + * flags with total moles in each phase. */ double vcs_tmoles(); #ifdef DEBUG_MODE @@ -529,13 +516,13 @@ public: //! This subroutine calculates reaction free energy changes for //! all noncomponent formation reactions. /*! - * Formation reactions are - * reactions which create each noncomponent species from the component - * species. m_stoichCoeffRxnMatrix(jcomp,irxn) are the stoichiometric - * coefficients for these reactions. A stoichiometric coefficient of - * one is assumed for species irxn in this reaction. + * Formation reactions are + * reactions which create each noncomponent species from the component + * species. m_stoichCoeffRxnMatrix(jcomp,irxn) are the stoichiometric + * coefficients for these reactions. A stoichiometric coefficient of + * one is assumed for species irxn in this reaction. * - * @param l + * @param l * - `L < 0`: Calculate reactions corresponding to major noncomponent * and zeroed species only * - `L = 0`: Do all noncomponent reactions, i, between @@ -543,17 +530,17 @@ public: * - `L > 0`: Calculate reactions corresponding to minor noncomponent * and zeroed species only * - * @param doDeleted Do deleted species - * @param vcsState Calculate deltaG corresponding to either old or new + * @param doDeleted Do deleted species + * @param vcsState Calculate deltaG corresponding to either old or new * free energies - * @param alterZeroedPhases boolean indicating whether we should - * add in a special section for zeroed phases. + * @param alterZeroedPhases boolean indicating whether we should + * add in a special section for zeroed phases. * - * Note we special case one important issue. If the component has zero - * moles, then we do not allow deltaG < 0.0 for formation reactions which - * would lead to the loss of more of that same component. This dG < 0.0 - * condition feeds back into the algorithm in several places, and leads - * to a infinite loop in at least one case. + * Note we special case one important issue. If the component has zero + * moles, then we do not allow deltaG < 0.0 for formation reactions which + * would lead to the loss of more of that same component. This dG < 0.0 + * condition feeds back into the algorithm in several places, and leads + * to a infinite loop in at least one case. */ void vcs_deltag(const int l, const bool doDeleted, const int vcsState, const bool alterZeroedPhases = true); @@ -584,35 +571,33 @@ public: //! Swaps the indices for all of the global data for two species, k1 //! and k2. /*! - * @param ifunc: If true, switch the species data and the noncomponent - * reaction data. This must be called for a non-component - * species only. If false, switch the species data only. - * Typically, we use this option when determining the - * component species and at the end of the calculation, - * when we want to return unscrambled results. All rxn - * data will be out-of-date. - * - * @param k1 First species index - * @param k2 Second species index + * @param ifunc If true, switch the species data and the noncomponent + * reaction data. This must be called for a non-component species only. + * If false, switch the species data only. Typically, we use this option + * when determining the component species and at the end of the + * calculation, when we want to return unscrambled results. All rxn data + * will be out-of-date. + * @param k1 First species index + * @param k2 Second species index */ void vcs_switch_pos(const bool ifunc, const size_t k1, const size_t k2); - //! Birth guess returns the number of moles of a species - //! that is coming back to life. + //! Birth guess returns the number of moles of a species that is coming back + //! to life. /*! - * Birth guess returns the number of moles of a species that is coming - * back to life. Note, this routine is not applicable if the whole phase - * is coming back to life, not just one species in that phase. + * Birth guess returns the number of moles of a species that is coming back + * to life. Note, this routine is not applicable if the whole phase is + * coming back to life, not just one species in that phase. * - * Do a minor alt calculation. But, cap the mole numbers at 1.0E-15. For - * SS phases use VCS_DELETE_SPECIES_CUTOFF * 100. + * Do a minor alt calculation. But, cap the mole numbers at 1.0E-15. For SS + * phases use VCS_DELETE_SPECIES_CUTOFF * 100. * - * The routine makes sure the guess doesn't reduce the concentration of a - * component by more than 1/3. Note this may mean that the vlaue coming - * back from this routine is zero or a very small number. + * The routine makes sure the guess doesn't reduce the concentration of a + * component by more than 1/3. Note this may mean that the vlaue coming back + * from this routine is zero or a very small number. * * @param kspec Species number that is coming back to life - * @return Returns the number of kmol that the species should have. + * @returns the number of kmol that the species should have. */ double vcs_birthGuess(const int kspec); @@ -650,11 +635,11 @@ public: //! Solve an equilibrium problem at a particular fixed temperature //! and pressure /*! - * The actual problem statement is assumed to be in the structure - * already. This is a wrapper around the solve_TP() function. In this - * wrapper, we nondimensionalize the system we calculate the standard - * state Gibbs free energies of the species, and we decide whether to we - * need to use the initial guess algorithm. + * The actual problem statement is assumed to be in the structure already. + * This is a wrapper around the solve_TP() function. In this wrapper, we + * nondimensionalize the system we calculate the standard state Gibbs free + * energies of the species, and we decide whether to we need to use the + * initial guess algorithm. * * @param ipr = 1 -> Print results to standard output; * 0 -> don't report on anything @@ -697,10 +682,9 @@ public: //! Calculation of the total volume and the partial molar volumes /*! - * This function calculates the partial molar volume for all species, - * kspec, in the thermo problem at the temperature TKelvin and pressure, - * Pres, pres is in atm. And, it calculates the total volume of the - * combined system. + * This function calculates the partial molar volume for all species, kspec, + * in the thermo problem at the temperature TKelvin and pressure, Pres, pres + * is in atm. And, it calculates the total volume of the combined system. * * @param[in] tkelvin Temperature in kelvin() * @param[in] pres Pressure in Pascal @@ -708,21 +692,20 @@ public: * numbers in units of kmol. * @param[out] volPM[] For species in all phase, the entries are the * partial molar volumes units of M**3 / kmol. - * @return The return value is the total volume of - * the entire system in units of m**3. + * @returns the total volume of the entire system in units of m**3. */ double vcs_VolTotal(const double tkelvin, const double pres, const double w[], double volPM[]); - //! This routine is mostly concerned with changing the private data - //! to be consistent with what's needed for solution. It is called one - //! time for each new problem structure definition. + //! This routine is mostly concerned with changing the private data to be + //! consistent with what's needed for solution. It is called one time for + //! each new problem structure definition. /*! - * This routine is always followed by vcs_prep(). Therefore, tasks - * that need to be done for every call to vcsc() should be placed in - * vcs_prep() and not in this routine. + * This routine is always followed by vcs_prep(). Therefore, tasks that need + * to be done for every call to vcsc() should be placed in vcs_prep() and + * not in this routine. * - * The problem structure refers to: + * The problem structure refers to: * * - the number and identity of the species. * - the formula matrix and thus the number of components. @@ -741,16 +724,16 @@ public: * in the private data structure. All references to the species * properties must employ the ind[] index vector. * - * @param printLvl Print level of the routine - * @return VCS_SUCCESS = everything went OK + * @param printLvl Print level of the routine + * @return VCS_SUCCESS = everything went OK */ int vcs_prep_oneTime(int printLvl); //! Prepare the object for solution /*! - * This routine is mostly concerned with changing the private data - * to be consistent with that needed for solution. It is called for - * every invocation of the vcs_solve() except for the cleanup invocation. + * This routine is mostly concerned with changing the private data to be + * consistent with that needed for solution. It is called for every + * invocation of the vcs_solve() except for the cleanup invocation. * * Tasks: * 1. Initialization of arrays to zero. @@ -766,11 +749,11 @@ public: //! In this routine, we check for things that will cause the algorithm //! to fail. /*! - * We check to see if the problem is well posed. If it is not, we return - * false and print out error conditions. + * We check to see if the problem is well posed. If it is not, we return + * false and print out error conditions. * - * Current there is one condition. If all the element abundances are - * zero, the algorithm will fail. + * Current there is one condition. If all the element abundances are zero, + * the algorithm will fail. * * @param vprob VCS_PROB pointer to the definition of the equilibrium * problem @@ -813,18 +796,18 @@ public: int vcs_elem_rearrange(double* const aw, double* const sa, double* const sm, double* const ss); - //! Swaps the indices for all of the global data for two elements, ipos - //! and jpos. + //! Swaps the indices for all of the global data for two elements, ipos + //! and jpos. /*! - * This function knows all of the element information with VCS_SOLVE, and - * can therefore switch element positions + * This function knows all of the element information with VCS_SOLVE, and + * can therefore switch element positions * - * @param ipos first global element index - * @param jpos second global element index + * @param ipos first global element index + * @param jpos second global element index */ void vcs_switch_elem_pos(size_t ipos, size_t jpos); - //! Calculates reaction adjustments using a full Hessian approximation + //! Calculates reaction adjustments using a full Hessian approximation /*! * This does what equation 6.4-16, p. 143 in Smith and Missen is supposed * to do. However, a full matrix is formed and then solved via a conjugate @@ -846,29 +829,29 @@ public: * update is contrary to the steepest descent rule. This is an important * attribute of the regular vcs algorithm. We don't want to violate this. * - * NOTE: currently this routine is not used. + * NOTE: currently this routine is not used. */ int vcs_rxn_adj_cg(); - //! Calculates the diagonal contribution to the Hessian due to - //! the dependence of the activity coefficients on the mole numbers. + //! Calculates the diagonal contribution to the Hessian due to + //! the dependence of the activity coefficients on the mole numbers. /*! - * (See framemaker notes, Eqn. 20 - VCS Equations document) + * (See framemaker notes, Eqn. 20 - VCS Equations document) * - * We allow the diagonal to be increased positively to any degree. - * We allow the diagonal to be decreased to 1/3 of the ideal solution - * value, but no more -> it must remain positive. + * We allow the diagonal to be increased positively to any degree. + * We allow the diagonal to be decreased to 1/3 of the ideal solution + * value, but no more -> it must remain positive. * - * NOTE: currently this routine is not used + * NOTE: currently this routine is not used */ double vcs_Hessian_diag_adj(size_t irxn, double hessianDiag_Ideal); //! Calculates the diagonal contribution to the Hessian due to - //! the dependence of the activity coefficients on the mole numbers. + //! the dependence of the activity coefficients on the mole numbers. /*! - * (See framemaker notes, Eqn. 20 - VCS Equations document) + * (See framemaker notes, Eqn. 20 - VCS Equations document) * - * NOTE: currently this routine is not used + * NOTE: currently this routine is not used */ double vcs_Hessian_actCoeff_diag(size_t irxn); @@ -883,85 +866,82 @@ public: //! A line search algorithm is carried out on one reaction /*! - * In this routine we carry out a rough line search algorithm to make - * sure that the m_deltaGRxn_new doesn't switch signs prematurely. + * In this routine we carry out a rough line search algorithm to make + * sure that the m_deltaGRxn_new doesn't switch signs prematurely. * - * @param irxn Reaction number - * @param dx_orig Original step length - * @param ANOTE Output character string stating the conclusions of the - * line search - * @return Returns the optimized step length found by the search + * @param irxn Reaction number + * @param dx_orig Original step length + * @param ANOTE Output character string stating the conclusions of the + * line search + * @returns the optimized step length found by the search */ double vcs_line_search(const size_t irxn, const double dx_orig, char* const ANOTE=0); - //! Print out a report on the state of the equilibrium problem to - //! standard output. + //! Print out a report on the state of the equilibrium problem to + //! standard output. /*! - * @param iconv Indicator of convergence, to be printed out in the report: + * @param iconv Indicator of convergence, to be printed out in the report: * - 0 converged * - 1 range space error * - -1 not converged */ int vcs_report(int iconv); - //! Switch all species data back to the original order. + //! Switch all species data back to the original order. /*! - * This destroys the data based on reaction ordering. + * This destroys the data based on reaction ordering. */ int vcs_rearrange(); //! Returns the multiplier for electric charge terms /* - * This is basically equal to F/RT + * This is basically equal to F/RT * * @param mu_units integer representing the dimensional units system * @param TKelvin double Temperature in Kelvin - * - * @return Returns the value of F/RT + * @returns the value of F/RT */ double vcs_nondim_Farad(int mu_units, double TKelvin) const; //! Returns the multiplier for the nondimensionalization of the equations /*! - * This is basically equal to RT + * This is basically equal to RT * * @param mu_units integer representing the dimensional units system * @param TKelvin double Temperature in Kelvin - * - * @return Returns the value of RT + * @returns the value of RT */ double vcs_nondimMult_TP(int mu_units, double TKelvin) const; //! Nondimensionalize the problem data /*! - * Nondimensionalize the free energies using the divisor, R * T + * Nondimensionalize the free energies using the divisor, R * T * - * Essentially the internal data can either be in dimensional form - * or in nondimensional form. This routine switches the data from - * dimensional form into nondimensional form. + * Essentially the internal data can either be in dimensional form or in + * nondimensional form. This routine switches the data from dimensional form + * into nondimensional form. * - * @todo Add a scale factor based on the total mole numbers. - * The algorithm contains hard coded numbers based on the - * total mole number. If we ever were faced with a problem - * with significantly different total kmol numbers than one - * the algorithm would have problems. + * @todo Add a scale factor based on the total mole numbers. The algorithm + * contains hard coded numbers based on the total mole number. If we + * ever were faced with a problem with significantly different total + * kmol numbers than one the algorithm would have problems. */ void vcs_nondim_TP(); //! Redimensionalize the problem data /*! - * Reddimensionalize the free energies using the multiplier R * T + * Reddimensionalize the free energies using the multiplier R * T * - * Essentially the internal data can either be in dimensional form - * or in nondimensional form. This routine switches the data from - * nondimensional form into dimensional form. + * Essentially the internal data can either be in dimensional form or in + * nondimensional form. This routine switches the data from nondimensional + * form into dimensional form. */ void vcs_redim_TP(); //! Print the string representing the Chemical potential units /*! - * This gets printed using plogf() + * This gets printed using plogf() * * @param unitsFormat Integer representing the units system */ @@ -969,8 +949,8 @@ public: //! Computes the current elemental abundances vector /*! - * Computes the elemental abundances vector, m_elemAbundances[], and stores it - * back into the global structure + * Computes the elemental abundances vector, m_elemAbundances[], and stores + * it back into the global structure */ void vcs_elab(); @@ -992,8 +972,8 @@ public: * the formula matrix be identically zero. We put this into the logic * below. * - * @param ibound 1: Checks constraints up to the number of elements; - * 0: Checks constraints up to the number of components. + * @param ibound 1: Checks constraints up to the number of elements; + * 0: Checks constraints up to the number of components. */ bool vcs_elabcheck(int ibound); @@ -1039,13 +1019,13 @@ public: */ int vcs_elcorr(double aa[], double x[]); - //! Create an initial estimate of the solution to the thermodynamic - //! equilibrium problem. + //! Create an initial estimate of the solution to the thermodynamic + //! equilibrium problem. /*! - * @return Return value indicates success: - * - 0: successful initial guess - * - -1: Unsuccessful initial guess; the elemental abundances aren't - * satisfied. + * @return value indicates success: + * - 0: successful initial guess + * - -1: Unsuccessful initial guess; the elemental abundances aren't + * satisfied. */ int vcs_inest_TP(); @@ -1063,16 +1043,16 @@ public: //! Calculate the total dimensionless Gibbs free energy /*! - * Inert species are handled as if they had a standard free energy of - * zero. Note, for this algorithm this function should be monotonically - * decreasing. + * Inert species are handled as if they had a standard free energy of + * zero. Note, for this algorithm this function should be monotonically + * decreasing. */ double vcs_Total_Gibbs(double* w, double* fe, double* tPhMoles); //! Calculate the total dimensionless Gibbs free energy of a single phase /*! - * Inert species are handled as if they had a standard free energy of - * zero and if they obeyed ideal solution/gas theory. + * Inert species are handled as if they had a standard free energy of + * zero and if they obeyed ideal solution/gas theory. * * @param iphase ID of the phase * @param w Species mole number vector for all species @@ -1084,46 +1064,44 @@ public: //! Transfer the results of the equilibrium calculation back to VCS_PROB /*! - * The VCS_PROB structure is returned to the user. + * The VCS_PROB structure is returned to the user. * - * @param pub Pointer to VCS_PROB object that will get the results of the - * equilibrium calculation transfered to it. + * @param pub Pointer to VCS_PROB object that will get the results of the + * equilibrium calculation transfered to it. */ int vcs_prob_update(VCS_PROB* pub); //! Fully specify the problem to be solved using VCS_PROB /*! - * Use the contents of the VCS_PROB to specify the contents of the - * private data, VCS_SOLVE. + * Use the contents of the VCS_PROB to specify the contents of the + * private data, VCS_SOLVE. * - * @param pub Pointer to VCS_PROB that will be used to - * initialize the current equilibrium problem + * @param pub Pointer to VCS_PROB that will be used to + * initialize the current equilibrium problem */ int vcs_prob_specifyFully(const VCS_PROB* pub); //! Specify the problem to be solved using VCS_PROB, incrementally /*! - * Use the contents of the VCS_PROB to specify the contents of the - * private data, VCS_SOLVE. + * Use the contents of the VCS_PROB to specify the contents of the + * private data, VCS_SOLVE. * - * It's assumed we are solving the same problem. + * It's assumed we are solving the same problem. * - * @param pub Pointer to VCS_PROB that will be used to - * initialize the current equilibrium problem + * @param pub Pointer to VCS_PROB that will be used to initialize the + * current equilibrium problem */ int vcs_prob_specify(const VCS_PROB* pub); private: - - //! Zero out the concentration of a species. + //! Zero out the concentration of a species. /*! - * Make sure to conserveelements and keep track of the total moles in all - * phases. - * - w[] - * - m_tPhaseMoles_old[] - * - * @param kspec Species index + * Make sure to conserveelements and keep track of the total moles in all + * phases. + * - w[] + * - m_tPhaseMoles_old[] * + * @param kspec Species index * @return: * 1: succeeded * 0: failed. @@ -1146,70 +1124,69 @@ private: */ int vcs_delete_species(const size_t kspec); - //! This routine handles the bookkeeping involved with the - //! deletion of multiphase phases from the problem. + //! This routine handles the bookkeeping involved with the deletion of + //! multiphase phases from the problem. /*! - * When they are deleted, all of their species become active - * species, even though their mole numbers are set to zero. - * The routine does not make the decision to eliminate multiphases. + * When they are deleted, all of their species become active species, even + * though their mole numbers are set to zero. The routine does not make the + * decision to eliminate multiphases. * - * Note, species in phases with zero mole numbers are still - * considered active. Whether the phase pops back into - * existence or not is checked as part of the main iteration - * loop. + * Note, species in phases with zero mole numbers are still considered + * active. Whether the phase pops back into existence or not is checked as + * part of the main iteration loop. * * @param iph Phase to be deleted - * @return Returns whether the operation was successful or not + * @returns whether the operation was successful or not */ bool vcs_delete_multiphase(const size_t iph); - //! Change the concentration of a species by delta moles. + //! Change the concentration of a species by delta moles. /*! - * Make sure to conserve elements and keep track of the total kmoles in - * all phases. + * Make sure to conserve elements and keep track of the total kmoles in + * all phases. * - * @param kspec The species index - * @param delta_ptr pointer to the delta for the species. This may + * @param kspec The species index + * @param delta_ptr pointer to the delta for the species. This may * change during the calculation - * @return - * 1: succeeded without change of dx - * 0: Had to adjust dx, perhaps to zero, in order to do the delta. + * @return + * 1: succeeded without change of dx + * 0: Had to adjust dx, perhaps to zero, in order to do the delta. */ int delta_species(const size_t kspec, double* const delta_ptr); - //! Provide an estimate for the deleted species in phases that - //! are not zeroed out + //! Provide an estimate for the deleted species in phases that are not + //! zeroed out /*! - * Try to add back in all deleted species. An estimate of the kmol numbers - * are obtained and the species is added back into the equation system, - * into the old state vector. + * Try to add back in all deleted species. An estimate of the kmol numbers + * are obtained and the species is added back into the equation system, into + * the old state vector. * - * This routine is called at the end of the calculation, just before - * returning to the user. + * This routine is called at the end of the calculation, just before + * returning to the user. */ size_t vcs_add_all_deleted(); //! Recheck deleted species in multispecies phases. /*! - * We are checking the equation: + * We are checking the equation: * * sum_u = sum_j_comp [ sigma_i_j * u_j ] * = u_i_O + log((AC_i * W_i)/m_tPhaseMoles_old) * - * by first evaluating: + * by first evaluating: * * DG_i_O = u_i_O - sum_u. * - * Then, if TL is zero, the phase pops into existence if DG_i_O < 0. - * Also, if the phase exists, then we check to see if the species - * can have a mole number larger than VCS_DELETE_SPECIES_CUTOFF - * (default value = 1.0E-32). + * Then, if TL is zero, the phase pops into existence if DG_i_O < 0. Also, + * if the phase exists, then we check to see if the species can have a mole + * number larger than VCS_DELETE_SPECIES_CUTOFF (default value = 1.0E-32). */ int vcs_recheck_deleted(); //! Recheck deletion condition for multispecies phases. /*! - * We assume here that DG_i_0 has been calculated for deleted species correctly + * We assume here that DG_i_0 has been calculated for deleted species + * correctly * * m_feSpecies(I) = m_SSfeSpecies(I) * + ln(ActCoeff[I]) @@ -1221,25 +1198,25 @@ private: * * DG_i_0 = m_feSpecies(I) - sum_m{ a_i_m DG_m } * - * by first evaluating: + * by first evaluating: * * DG_i_O = u_i_O - sum_u. * - * Then, the phase pops into existence iff + * Then, the phase pops into existence iff * * phaseDG = 1.0 - sum_i{exp(-DG_i_O)} < 0.0 * - * This formula works for both single species phases and for multispecies - * phases. It's an overkill for single species phases. + * This formula works for both single species phases and for multispecies + * phases. It's an overkill for single species phases. * * @param iphase Phase index number - * @return Returns true if the phase is currently deleted - * but should be reinstated. Returns false otherwise. + * @return Returns true if the phase is currently deleted but should be + * reinstated. Returns false otherwise. * - * NOTE: this routine is currently not used in the code, and + * NOTE: this routine is currently not used in the code, and * contains some basic changes that are incompatible. * - * assumptions: + * assumptions: * 1. Vphase Existence is up to date * 2. Vphase->IndSpecies is up to date * 3. m_deltaGRxn_old[irxn] is up to date @@ -1248,38 +1225,38 @@ private: //! Minor species alternative calculation /*! - * This is based upon the following approximation: The mole fraction - * changes due to these reactions don't affect the mole numbers of the - * component species. Therefore the following approximation is valid for - * a small component of an ideal phase: + * This is based upon the following approximation: The mole fraction + * changes due to these reactions don't affect the mole numbers of the + * component species. Therefore the following approximation is valid for + * a small component of an ideal phase: * * 0 = m_deltaGRxn_old(I) + log(molNum_new(I)/molNum_old(I)) * - * `m_deltaGRxn_old` contains the contribution from + * `m_deltaGRxn_old` contains the contribution from * * m_feSpecies_old(I) = * m_SSfeSpecies(I) + * log(ActCoeff[i] * molNum_old(I) / m_tPhaseMoles_old(iph)) - * Thus, + * Thus, * * molNum_new(I)= molNum_old(I) * EXP(-m_deltaGRxn_old(I)) * - * Most of this section is mainly restricting the update to reasonable - * values. We restrict the update a factor of 1.0E10 up and 1.0E-10 down - * because we run into trouble with the addition operator due to roundoff - * if we go larger than ~1.0E15. Roundoff will then sometimes produce - * zero mole fractions. + * Most of this section is mainly restricting the update to reasonable + * values. We restrict the update a factor of 1.0E10 up and 1.0E-10 down + * because we run into trouble with the addition operator due to roundoff if + * we go larger than ~1.0E15. Roundoff will then sometimes produce zero mole + * fractions. * - * Note: This routine was generalized to incorporate nonideal phases and - * phases on the molality basis + * Note: This routine was generalized to incorporate nonideal phases and + * phases on the molality basis * - * @param[in] kspec The current species and corresponding formation - * reaction number. - * @param[in] irxn The current species and corresponding formation - * reaction number. - * @param[out] do_delete: BOOLEAN which if true on return, then we - * branch to the section that deletes a species - * from the current set of active species. + * @param[in] kspec The current species and corresponding formation + * reaction number. + * @param[in] irxn The current species and corresponding formation + * reaction number. + * @param[out] do_delete: BOOLEAN which if true on return, then we + * branch to the section that deletes a species + * from the current set of active species. */ double vcs_minor_alt_calc(size_t kspec, size_t irxn, bool* do_delete, char* ANOTE=0) const; @@ -1287,28 +1264,28 @@ private: //! This routine optimizes the minimization of the total Gibbs free energy //! by making sure the slope of the following functional stays negative: /*! - * The slope of the following functional is equivalent to the slope - * of the total Gibbs free energy of the system: + * The slope of the following functional is equivalent to the slope of the + * total Gibbs free energy of the system: * * d_Gibbs/ds = sum_k( m_deltaGRxn * m_deltaMolNumSpecies[k] ) * - * along the current direction m_deltaMolNumSpecies[], by choosing a value, al: (0 0), - * does this code section kick in. It finds the point on the parabola - * where the slope is equal to zero. + * Only if there has been an inflection point (i.e., s1 < 0 and s2 > 0), + * does this code section kick in. It finds the point on the parabola + * where the slope is equal to zero. */ bool vcs_globStepDamp(); //! Calculate the norm of a deltaGibbs free energy vector /*! - * Positive DG for species which don't exist are ignored. + * Positive DG for species which don't exist are ignored. * * @param dg Vector of local delta G's. */ @@ -1324,20 +1301,20 @@ private: //! Estimate equilibrium compositions /*! - * Algorithm covered in a section of Smith and Missen's Book. + * Algorithm covered in a section of Smith and Missen's Book. * - * Linear programming module is based on using dbolm. + * Linear programming module is based on using dbolm. * - * @param aw aw[i[ Mole fraction work space (ne in length) - * @param sa sa[j] = Gram-Schmidt orthog work space (ne in length) - * @param sm sm[i+j*ne] = QR matrix work space (ne*ne in length) - * @param ss ss[j] = Gram-Schmidt orthog work space (ne in length) - * @param test This is a small negative number. + * @param aw aw[i[ Mole fraction work space (ne in length) + * @param sa sa[j] = Gram-Schmidt orthog work space (ne in length) + * @param sm sm[i+j*ne] = QR matrix work space (ne*ne in length) + * @param ss ss[j] = Gram-Schmidt orthog work space (ne in length) + * @param test This is a small negative number. */ void vcs_inest(double* const aw, double* const sa, double* const sm, double* const ss, double test); - //! Calculate the status of single species phases. + //! Calculate the status of single species phases. void vcs_SSPhase(); //! This function recalculates the deltaG for reaction, irxn @@ -1345,15 +1322,13 @@ private: * This function recalculates the deltaG for reaction irxn, given the mole * numbers in molNum. It uses the temporary space mu_i, to hold the * recalculated chemical potentials. It only recalculates the chemical - * potentials for species in phases which participate in the irxn - * reaction. This function is used by the vcs_line_search algorithm() and - * should not be used widely due to the unknown state it leaves the - * system. + * potentials for species in phases which participate in the irxn reaction. + * This function is used by the vcs_line_search algorithm() and should not + * be used widely due to the unknown state it leaves the system. * * @param[in] irxn Reaction number * @param[in] molNum Current mole numbers of species to be used as input * to the calculation (units = kmol), (length = totalNuMSpecies) - * * @param[out] ac Activity coefficients (length = totalNumSpecies) Note * this is only partially formed. Only species in phases that * participate in the reaction will be updated @@ -1361,7 +1336,7 @@ private: * totalNumSpecies) Note this is only partially formed. Only * species in phases that participate in the reaction will be * updated - * @return Returns the dimensionless deltaG of the reaction + * @returns the dimensionless deltaG of the reaction */ double deltaG_Recalc_Rxn(const int stateCalc, const size_t irxn, const double* const molNum, @@ -1386,8 +1361,8 @@ private: //! Create a report on the plog file containing timing and its information /*! - * @param timing_print_lvl If 0, just report the iteration count. - * If larger than zero, report the timing information + * @param timing_print_lvl If 0, just report the iteration count. If larger + * than zero, report the timing information */ void vcs_TCounters_report(int timing_print_lvl = 1); @@ -1397,11 +1372,11 @@ private: //! Update all underlying vcs_VolPhase objects /*! - * Update the mole numbers and the phase voltages of all phases in the - * vcs problem + * Update the mole numbers and the phase voltages of all phases in the vcs + * problem * - * @param stateCalc Location of the update (either VCS_STATECALC_NEW or - * VCS_STATECALC_OLD). + * @param stateCalc Location of the update (either VCS_STATECALC_NEW or + * VCS_STATECALC_OLD). */ void vcs_updateMolNumVolPhases(const int stateCalc); @@ -1448,22 +1423,16 @@ public: //! Total number of non-component species in the problem size_t m_numRxnTot; - //! Current number of species in the problems - /*! - * Species can be deleted if they aren't - * stable under the current conditions - */ + //! Current number of species in the problems. Species can be deleted if + //! they aren't stable under the current conditions size_t m_numSpeciesRdc; - //! Current number of non-component species in the problem - /*! - * Species can be deleted if they aren't - * stable under the current conditions - */ + //! Current number of non-component species in the problem. Species can be + //! deleted if they aren't stable under the current conditions size_t m_numRxnRdc; - //! Number of active species which are currently either treated as - //! minor species + //! Number of active species which are currently either treated as + //! minor species size_t m_numRxnMinorZeroed; //! Number of Phases in the problem @@ -1477,31 +1446,31 @@ public: */ Array2D m_formulaMatrix; - //! Stoichiometric coefficient matrix for the reaction mechanism expressed in Reduced Canonical Form. + //! Stoichiometric coefficient matrix for the reaction mechanism expressed + //! in Reduced Canonical Form. /*! - * This is the stoichiometric coefficient matrix for the - * reaction which forms species kspec from the component species. A - * stoichiometric coefficient of one is assumed for the species kspec in this mechanism. + * This is the stoichiometric coefficient matrix for the reaction which + * forms species kspec from the component species. A stoichiometric + * coefficient of one is assumed for the species kspec in this mechanism. * - * NOTE: kspec = irxn + m_numComponents + * NOTE: kspec = irxn + m_numComponents * - * m_stoichCoeffRxnMatrix(j,irxn) : - * j refers to the component number, and irxn refers to the irxn_th non-component species. - * The stoichiometric coefficients multilplied by the Formula coefficients of the - * component species add up to the negative value of the number of elements in - * the species kspec. + * m_stoichCoeffRxnMatrix(j,irxn) : j refers to the component number, and + * irxn refers to the irxn_th non-component species. The stoichiometric + * coefficients multilplied by the Formula coefficients of the component + * species add up to the negative value of the number of elements in the + * species kspec. * - * size = nelements0 x nspecies0 + * size = nelements0 x nspecies0 */ Array2D m_stoichCoeffRxnMatrix; //! Absolute size of the stoichiometric coefficients /*! - * scSize[irxn] = abs(Size) of the stoichiometric - * coefficients. These are used to determine - * whether a given species should be - * handled by the alt_min treatment or - * should be handled as a major species. + * scSize[irxn] = abs(Size) of the stoichiometric coefficients. These are + * used to determine whether a given species should be + * handled by the alt_min treatment or should be handled as a + * major species. */ vector_fp m_scSize; @@ -1512,8 +1481,8 @@ public: */ vector_fp m_spSize; - //! Standard state chemical potentials for species K at the current - //! temperature and pressure. + //! Standard state chemical potentials for species K at the current + //! temperature and pressure. /*! * The first NC entries are for components. The following NR entries are * for the current non-component species in the mechanism. @@ -1539,12 +1508,10 @@ public: //! Setting for whether to do an initial estimate /*! * Initial estimate: - * * 0 Do not estimate the solution at all. Use the - * * supplied mole numbers as is. - * * 1 Only do an estimate if the element abundances - * * aren't satisfied. - * * -1 Force an estimate of the soln. Throw out the input - * * mole numbers. + * 0 Do not estimate the solution at all. Use the + * supplied mole numbers as is. + * 1 Only do an estimate if the element abundances aren't satisfied. + * -1 Force an estimate of the soln. Throw out the input mole numbers. */ int m_doEstimateEquil; @@ -1588,11 +1555,11 @@ public: //! Delta G(irxn) for the noncomponent species in the mechanism. /*! - * Computed by the subroutine deltaG. m_deltaGRxn is the free - * energy change for the reaction which forms species K from the - * component species. This vector has length equal to the number - * of noncomponent species in the mechanism. It starts with - * the first current noncomponent species in the mechanism. + * Computed by the subroutine deltaG. m_deltaGRxn is the free energy change + * for the reaction which forms species K from the component species. This + * vector has length equal to the number of noncomponent species in the + * mechanism. It starts with the first current noncomponent species in the + * mechanism. */ vector_fp m_deltaGRxn_new; @@ -1616,24 +1583,21 @@ public: */ vector_fp m_deltaMolNumSpecies; - //! Element abundances vector + //! Element abundances vector /*! - * Vector of moles of each element actually in the solution - * vector. Except for certain parts of the algorithm, - * this is a constant. - * Note other constraint conditions are added to this vector. - * This is input from the input file and - * is considered a constant from thereon. - * units = kmoles + * Vector of moles of each element actually in the solution vector. Except + * for certain parts of the algorithm, this is a constant. Note other + * constraint conditions are added to this vector. This is input from the + * input file and is considered a constant from thereon. units = kmoles */ vector_fp m_elemAbundances; //! Element abundances vector Goals /*! - * Vector of moles of each element that are the goals of the simulation. - * This is a constant in the problem. Note other constraint conditions - * are added to this vector. This is input from the input file and is - * considered a constant from thereon. units = kmoles + * Vector of moles of each element that are the goals of the simulation. + * This is a constant in the problem. Note other constraint conditions are + * added to this vector. This is input from the input file and is considered + * a constant from thereon. units = kmoles */ vector_fp m_elemAbundancesGoal; @@ -1646,18 +1610,18 @@ public: //! Total kmols of species in each phase /*! - * This contains the total number of moles of species in each phase + * This contains the total number of moles of species in each phase * - * Length = number of phases + * Length = number of phases */ vector_fp m_tPhaseMoles_old; //! total kmols of species in each phase in the tentative soln vector /*! - * This contains the total number of moles of species in each phase - * in the tentative solution vector + * This contains the total number of moles of species in each phase + * in the tentative solution vector * - * Length = number of phases + * Length = number of phases */ vector_fp m_tPhaseMoles_new; @@ -1690,10 +1654,10 @@ public: */ double m_pressurePA; - //! Total kmoles of inert to add to each phase + //! Total kmoles of inert to add to each phase /*! - * TPhInertMoles[iph] = Total kmoles of inert to add to each phase - * length = number of phases + * TPhInertMoles[iph] = Total kmoles of inert to add to each phase + * length = number of phases */ vector_fp TPhInertMoles; @@ -1709,38 +1673,38 @@ public: //! Below this, minor species aren't refined any more double m_tolmin2; - //! Index vector that keeps track of the species vector rearrangement + //! Index vector that keeps track of the species vector rearrangement /*! - * At the end of each run, the species vector and associated data gets put back - * in the original order. + * At the end of each run, the species vector and associated data gets put + * back in the original order. * * Example * - * k = m_speciesMapIndex[kspec] + * k = m_speciesMapIndex[kspec] * - * kspec = current order in the vcs_solve object - * k = original order in the vcs_prob object and in the MultiPhase object + * kspec = current order in the vcs_solve object + * k = original order in the vcs_prob object and in the MultiPhase object */ std::vector m_speciesMapIndex; //! Index that keeps track of the index of the species within the local //! phase /*! - * This returns the local index of the species within the phase. Its argument - * is the global species index within the VCS problem. + * This returns the local index of the species within the phase. Its + * argument is the global species index within the VCS problem. * - * k = m_speciesLocalPhaseIndex[kspec] + * k = m_speciesLocalPhaseIndex[kspec] * - * k varies between 0 and the nSpecies in the phase + * k varies between 0 and the nSpecies in the phase * - * Length = number of species + * Length = number of species */ std::vector m_speciesLocalPhaseIndex; //! Index vector that keeps track of the rearrangement of the elements /*! - * At the end of each run, the element vector and associated data gets - * put back in the original order. + * At the end of each run, the element vector and associated data gets + * put back in the original order. * * Example * @@ -1750,8 +1714,8 @@ public: */ std::vector m_elementMapIndex; - //! Mapping between the species index for noncomponent species and the - //! full species index. + //! Mapping between the species index for noncomponent species and the + //! full species index. /*! * ir[irxn] = Mapping between the reaction index for noncomponent * formation reaction of a species and the full species @@ -1765,16 +1729,16 @@ public: //! Major -Minor status vector for the species in the problem /*! - * The index for this is species. The reaction that this is referring to - * is `kspec = irxn + m_numComponents`. For possible values and their - * meanings, see vcs_evaluate_speciesType(). + * The index for this is species. The reaction that this is referring to + * is `kspec = irxn + m_numComponents`. For possible values and their + * meanings, see vcs_evaluate_speciesType(). */ vector_int m_speciesStatus; - //! Mapping from the species number to the phase number + //! Mapping from the species number to the phase number std::vector m_phaseID; - //! Boolean indicating whether a species belongs to a single-species phase + //! Boolean indicating whether a species belongs to a single-species phase // vector can't be used here because it doesn't work with std::swap std::vector m_SSPhase; @@ -1823,10 +1787,10 @@ public: //! Multiplier for the mole numbers within the nondimensionless formulation /*! - * All numbers within the main routine are on an absolute basis. This - * presents some problems wrt very large and very small mole numbers. - * We get around this by using a multiplier coming into and coming - * out of the equilibrium routines + * All numbers within the main routine are on an absolute basis. This + * presents some problems wrt very large and very small mole numbers. We get + * around this by using a multiplier coming into and coming out of the + * equilibrium routines */ double m_totalMoleScale; @@ -1835,7 +1799,7 @@ public: * * 0 = molar based * * 1 = molality based * - * length = number of species + * length = number of species */ vector_int m_actConventionSpecies; @@ -1844,14 +1808,14 @@ public: * * 0 = molar based * * 1 = molality based * - * length = number of phases + * length = number of phases */ vector_int m_phaseActConvention; - //! specifies the ln(Mnaught) used to calculate the chemical potentials + //! specifies the ln(Mnaught) used to calculate the chemical potentials /*! - * For molar based activity conventions this will be equal to 0.0. - * length = number of species. + * For molar based activity conventions this will be equal to 0.0. + * length = number of species. */ vector_fp m_lnMnaughtSpecies; @@ -1859,26 +1823,26 @@ public: //! Length = number of species vector_fp m_actCoeffSpecies_new; - //! Molar-based Activity Coefficients for Species based on old mole numbers + //! Molar-based Activity Coefficients for Species based on old mole numbers /*! - * These activity coefficients are based on the m_molNumSpecies_old - * values Molar based activity coeffients. Length = number of species + * These activity coefficients are based on the m_molNumSpecies_old + * values Molar based activity coeffients. Length = number of species */ vector_fp m_actCoeffSpecies_old; - //! Change in the log of the activity coefficient with respect to the mole number - //! multiplied by the phase mole number + //! Change in the log of the activity coefficient with respect to the mole + //! number multiplied by the phase mole number /*! - * size = nspecies x nspecies + * size = nspecies x nspecies * - * This is a temporary array that gets regenerated every time it's - * needed. It is not swapped wrt species. + * This is a temporary array that gets regenerated every time it's needed. + * It is not swapped wrt species. */ Array2D m_np_dLnActCoeffdMolNum; //! Molecular weight of each species /*! - * units = kg/kmol. length = number of species. + * units = kg/kmol. length = number of species. * * note: this is a candidate for removal. I don't think we use it. */ @@ -1899,9 +1863,8 @@ public: //! Choice of Hessians /*! - * If this is true, then we will use a better approximation to the - * Hessian based on Jacobian of the ln(ActCoeff) with respect to mole - * numbers + * If this is true, then we will use a better approximation to the Hessian + * based on Jacobian of the ln(ActCoeff) with respect to mole numbers */ int m_useActCoeffJac; diff --git a/include/cantera/equil/vcs_species_thermo.h b/include/cantera/equil/vcs_species_thermo.h index 7e2ccb951..3df449153 100644 --- a/include/cantera/equil/vcs_species_thermo.h +++ b/include/cantera/equil/vcs_species_thermo.h @@ -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); diff --git a/src/equil/vcs_MultiPhaseEquil.cpp b/src/equil/vcs_MultiPhaseEquil.cpp index c1aae9224..830696138 100644 --- a/src/equil/vcs_MultiPhaseEquil.cpp +++ b/src/equil/vcs_MultiPhaseEquil.cpp @@ -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()); diff --git a/src/equil/vcs_TP.cpp b/src/equil/vcs_TP.cpp index 803bcc533..23b31209a 100644 --- a/src/equil/vcs_TP.cpp +++ b/src/equil/vcs_TP.cpp @@ -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]; diff --git a/src/equil/vcs_VolPhase.cpp b/src/equil/vcs_VolPhase.cpp index 85c73a41e..684fd5c30 100644 --- a/src/equil/vcs_VolPhase.cpp +++ b/src/equil/vcs_VolPhase.cpp @@ -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); diff --git a/src/equil/vcs_elem.cpp b/src/equil/vcs_elem.cpp index 9d5aed58d..518b0bfab 100644 --- a/src/equil/vcs_elem.cpp +++ b/src/equil/vcs_elem.cpp @@ -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)) { diff --git a/src/equil/vcs_elem_rearrange.cpp b/src/equil/vcs_elem_rearrange.cpp index 68bb9bd77..4bdf0d218 100644 --- a/src/equil/vcs_elem_rearrange.cpp +++ b/src/equil/vcs_elem_rearrange.cpp @@ -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++) { diff --git a/src/equil/vcs_inest.cpp b/src/equil/vcs_inest.cpp index 908b0138b..191983194 100644 --- a/src/equil/vcs_inest.cpp +++ b/src/equil/vcs_inest.cpp @@ -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; diff --git a/src/equil/vcs_nondim.cpp b/src/equil/vcs_nondim.cpp index 894e0d8e1..d98e42f57 100644 --- a/src/equil/vcs_nondim.cpp +++ b/src/equil/vcs_nondim.cpp @@ -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; diff --git a/src/equil/vcs_phaseStability.cpp b/src/equil/vcs_phaseStability.cpp index f66b389bb..ff6d7a02c 100644 --- a/src/equil/vcs_phaseStability.cpp +++ b/src/equil/vcs_phaseStability.cpp @@ -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 > 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 &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 > 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 &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 & 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 & 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 & 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 { diff --git a/src/equil/vcs_prep.cpp b/src/equil/vcs_prep.cpp index 152243eed..d8018c3b0 100644 --- a/src/equil/vcs_prep.cpp +++ b/src/equil/vcs_prep.cpp @@ -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; } diff --git a/src/equil/vcs_prob.cpp b/src/equil/vcs_prob.cpp index 60bca1799..06c07e9eb 100644 --- a/src/equil/vcs_prob.cpp +++ b/src/equil/vcs_prob.cpp @@ -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])) { diff --git a/src/equil/vcs_rearrange.cpp b/src/equil/vcs_rearrange.cpp index 6aa888734..7c32ba47b 100644 --- a/src/equil/vcs_rearrange.cpp +++ b/src/equil/vcs_rearrange.cpp @@ -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; diff --git a/src/equil/vcs_report.cpp b/src/equil/vcs_report.cpp index 0e0d376c3..c050f363c 100644 --- a/src/equil/vcs_report.cpp +++ b/src/equil/vcs_report.cpp @@ -19,19 +19,14 @@ int VCS_SOLVE::vcs_report(int iconv) std::vector 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; } diff --git a/src/equil/vcs_rxnadj.cpp b/src/equil/vcs_rxnadj.cpp index 7845feb4a..8aa5eb5df 100644 --- a/src/equil/vcs_rxnadj.cpp +++ b/src/equil/vcs_rxnadj.cpp @@ -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; diff --git a/src/equil/vcs_setMolesLinProg.cpp b/src/equil/vcs_setMolesLinProg.cpp index 856c6a5e7..76aec21e9 100644 --- a/src/equil/vcs_setMolesLinProg.cpp +++ b/src/equil/vcs_setMolesLinProg.cpp @@ -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) { diff --git a/src/equil/vcs_solve.cpp b/src/equil/vcs_solve.cpp index de635dd2a..cf9ae3d10 100644 --- a/src/equil/vcs_solve.cpp +++ b/src/equil/vcs_solve.cpp @@ -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 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 { diff --git a/src/equil/vcs_solve_TP.cpp b/src/equil/vcs_solve_TP.cpp index 2740475bb..1b29abbdd 100644 --- a/src/equil/vcs_solve_TP.cpp +++ b/src/equil/vcs_solve_TP.cpp @@ -60,9 +60,7 @@ int VCS_SOLVE::vcs_solve_TP(int print_lvl, int printDetails, int maxit) #ifdef DEBUG_MODE char ANOTE[128]; - /* - * Set the debug print lvl to the same as the print lvl. - */ + // Set the debug print lvl to the same as the print lvl. m_debug_print_lvl = printDetails; #else char* ANOTE = 0; @@ -70,23 +68,11 @@ int VCS_SOLVE::vcs_solve_TP(int print_lvl, int printDetails, int maxit) if (printDetails > 0 && print_lvl == 0) { print_lvl = 1; } - /* - * Initialize and set up all counters - */ + // Initialize and set up all counters vcs_counters_init(0); clockWC ticktock; - /* - * Malloc temporary space for usage in this routine and in - * subroutines - * sm[ne*ne] - * ss[ne] - * sa[ne] - * aw[m] - * wx[ne] - * xy[m] - */ - + // Malloc temporary space for usage in this routine and in subroutines m_sm.assign(m_numElemConstraints*m_numElemConstraints, 0.0); m_ss.assign(m_numElemConstraints, 0.0); m_sa.assign(m_numElemConstraints, 0.0); @@ -95,14 +81,10 @@ int VCS_SOLVE::vcs_solve_TP(int print_lvl, int printDetails, int maxit) solveFail = false; - /* ****************************************************** */ - /* **** Evaluate the elemental composition ****** */ - /* ****************************************************** */ + // Evaluate the elemental composition vcs_elab(); - /* ******************************************************* */ - /* **** Printout the initial conditions for problem ****** */ - /* ******************************************************* */ + // Printout the initial conditions for problem if (print_lvl != 0) { plogf("VCS CALCULATION METHOD\n\n "); plogf("%s\n", m_title); @@ -189,24 +171,18 @@ int VCS_SOLVE::vcs_solve_TP(int print_lvl, int printDetails, int maxit) } } - /* - * Evaluate the total moles of species in the problem - */ + // Evaluate the total moles of species in the problem vcs_tmoles(); - /* - * Evaluate all chemical potentials at the old mole numbers at the - * outset of the calculation. - */ + // Evaluate all chemical potentials at the old mole numbers at the outset of + // the calculation. vcs_setFlagsVolPhases(false, VCS_STATECALC_OLD); vcs_dfe(VCS_STATECALC_OLD, 0, 0, m_numSpeciesRdc); bool lec; while (true) { if (stage == MAIN) { - /* *********************************************************** */ - /* **** DETERMINE BASIS SPECIES, EVALUATE STOICHIOMETRY ****** */ - /* *********************************************************** */ + // DETERMINE BASIS SPECIES, EVALUATE STOICHIOMETRY if (forceComponentCalc) { int retn = solve_tp_component_calc(allMinorZeroedSpecies); if (retn != VCS_SUCCESS) { @@ -216,11 +192,9 @@ int VCS_SOLVE::vcs_solve_TP(int print_lvl, int printDetails, int maxit) forceComponentCalc = 0; iti = 0; } - /* - * Check on too many iterations. - * If we have too many iterations, Clean up and exit code even though we haven't - * converged. -> we have run out of iterations! - */ + // Check on too many iterations. If we have too many iterations, + // Clean up and exit code even though we haven't converged. + // -> we have run out of iterations! if (m_VCount->Its > maxit) { return -1; } @@ -228,43 +202,32 @@ int VCS_SOLVE::vcs_solve_TP(int print_lvl, int printDetails, int maxit) forceComponentCalc, stage, printDetails, ANOTE); lec = false; } else if (stage == EQUILIB_CHECK) { - /*************************************************************************/ - /***************** EQUILIBRIUM CHECK FOR MAJOR SPECIES *******************/ - /*************************************************************************/ + // EQUILIBRIUM CHECK FOR MAJOR SPECIES solve_tp_equilib_check(allMinorZeroedSpecies, uptodate_minors, giveUpOnElemAbund, solveFail, iti, it1, maxit, stage, lec); } else if (stage == ELEM_ABUND_CHECK) { - /* *************************************************** */ - /* **** CORRECT ELEMENTAL ABUNDANCES ***************** */ - /* *************************************************** */ + // CORRECT ELEMENTAL ABUNDANCES solve_tp_elem_abund_check(iti, stage, lec, giveUpOnElemAbund, finalElemAbundAttempts, rangeErrorFound); } else if (stage == RECHECK_DELETED) { - /* *************************************************** */ - /* **** RECHECK DELETED SPECIES ********************** */ - /* *************************************************** */ - /* - * We are here for two reasons. One is if we have - * achieved convergence, but some species have been eliminated - * from the problem because they were in multispecies phases - * and their mole fractions drifted less than - * VCS_DELETE_SPECIES_CUTOFF . - * The other reason why we are here is because all of the - * non-component species in the problem have been eliminated - * for one reason or another. - */ + // RECHECK DELETED SPECIES + // + // We are here for two reasons. One is if we have achieved + // convergence, but some species have been eliminated from the + // problem because they were in multispecies phases and their mole + // fractions drifted less than VCS_DELETE_SPECIES_CUTOFF. The other + // reason why we are here is because all of the non-component + // species in the problem have been eliminated for one reason or + // another. npb = vcs_recheck_deleted(); - /* - * If we haven't found any species that needed adding we are done. - */ + + // If we haven't found any species that needed adding we are done. if (npb <= 0) { stage = RETURN_B; } else { - /* - * If we have found something to add, recalculate everything - * for minor species and go back to do a full iteration - */ + // If we have found something to add, recalculate everything for + // minor species and go back to do a full iteration vcs_setFlagsVolPhases(false, VCS_STATECALC_OLD); vcs_dfe(VCS_STATECALC_OLD, 1, 0, m_numSpeciesRdc); vcs_deltag(0, false, VCS_STATECALC_OLD); @@ -272,18 +235,13 @@ int VCS_SOLVE::vcs_solve_TP(int print_lvl, int printDetails, int maxit) stage = MAIN; } } else if (stage == RETURN_A) { - /*************************************************************************/ - /******************** CLEANUP AND RETURN BLOCK ***************************/ - /*************************************************************************/ + // CLEANUP AND RETURN BLOCK npb = vcs_recheck_deleted(); - /* - * If we haven't found any species that needed adding we are done. - */ + + // If we haven't found any species that needed adding we are done. if (npb > 0) { - /* - * If we have found something to add, recalculate everything - * for minor species and go back to do a full iteration - */ + // If we have found something to add, recalculate everything for + // minor species and go back to do a full iteration vcs_setFlagsVolPhases(false, VCS_STATECALC_OLD); vcs_dfe(VCS_STATECALC_OLD, 1, 0, m_numSpeciesRdc); vcs_deltag(0, false, VCS_STATECALC_OLD); @@ -293,10 +251,8 @@ int VCS_SOLVE::vcs_solve_TP(int print_lvl, int printDetails, int maxit) stage = RETURN_B; } } else if (stage == RETURN_B) { - /* - * Add back deleted species in non-zeroed phases. Estimate their - * mole numbers. - */ + // Add back deleted species in non-zeroed phases. Estimate their + // mole numbers. npb = vcs_add_all_deleted(); if (npb > 0) { iti = 0; @@ -310,16 +266,13 @@ int VCS_SOLVE::vcs_solve_TP(int print_lvl, int printDetails, int maxit) } } } - /* - * Make sure the volume phase objects hold the same state and - * information as the vcs object. This also update the Cantera objects - * with this information. - */ + + // Make sure the volume phase objects hold the same state and information as + // the vcs object. This also update the Cantera objects with this + // information. vcs_updateVP(VCS_STATECALC_OLD); - /* - * Evaluate the final mole fractions - * storing them in wt[] - */ + + // Evaluate the final mole fractions storing them in wt[] m_molNumSpecies_new.assign(m_molNumSpecies_new.size(), 0.0); for (size_t kspec = 0; kspec < m_numSpeciesTot; ++kspec) { if (m_SSPhase[kspec]) { @@ -329,12 +282,10 @@ int VCS_SOLVE::vcs_solve_TP(int print_lvl, int printDetails, int maxit) if (m_tPhaseMoles_old[iph] != 0.0) { m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec] / m_tPhaseMoles_old[iph]; } else { - /* - * For MultiSpecies phases that are zeroed out, - * return the mole fraction vector from the VolPhase object. - * This contains the mole fraction that would be true if - * the phase just pops into existence. - */ + // For MultiSpecies phases that are zeroed out, return the mole + // fraction vector from the VolPhase object. This contains the + // mole fraction that would be true if the phase just pops into + // existence. size_t i = m_speciesLocalPhaseIndex[kspec]; m_molNumSpecies_new[kspec] = m_VolPhaseList[iph]->molefraction(i); } @@ -344,9 +295,8 @@ int VCS_SOLVE::vcs_solve_TP(int print_lvl, int printDetails, int maxit) if (rangeErrorFound) { solveFail = 1; } - /* - * Calculate counters - */ + + // Calculate counters double tsecond = ticktock.secondsWC(); m_VCount->Time_vcs_TP = tsecond; m_VCount->T_Time_vcs_TP += m_VCount->Time_vcs_TP; @@ -354,9 +304,8 @@ int VCS_SOLVE::vcs_solve_TP(int print_lvl, int printDetails, int maxit) m_VCount->T_Its += m_VCount->Its; m_VCount->T_Basis_Opts += m_VCount->Basis_Opts; m_VCount->T_Time_basopt += m_VCount->Time_basopt; - /* - * Return a Flag indicating whether convergence occurred - */ + + // Return a Flag indicating whether convergence occurred return solveFail; } @@ -374,14 +323,10 @@ int VCS_SOLVE::solve_tp_component_calc(bool& allMinorZeroedSpecies) vcs_updateVP(VCS_STATECALC_OLD); vcs_deltag(0, false, VCS_STATECALC_OLD); - /*************************************************************************/ - /************** EVALUATE INITIAL SPECIES STATUS VECTOR *******************/ - /*************************************************************************/ + // EVALUATE INITIAL SPECIES STATUS VECTOR allMinorZeroedSpecies = vcs_evaluate_speciesType(); - /*************************************************************************/ - /************** EVALUATE THE ELELEMT ABUNDANCE CHECK ******************/ - /*************************************************************************/ + // EVALUATE THE ELELEMT ABUNDANCE CHECK if (! vcs_elabcheck(0)) { if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { plogf(" --- Element Abundance check failed"); @@ -407,15 +352,12 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, int& stage, bool printDetails, char* ANOTE) { if (iti == 0) { - /* ********************************************************* */ - /* **** SET INITIAL VALUES FOR ITERATION ******************* */ - /* **** EVALUATE REACTION ADJUSTMENTS ******************* */ - /* ********************************************************* */ - /* - * Evaluate the minor non-component species chemical - * potentials and delta G for their formation reactions - * We have already evaluated the major non-components - */ + // SET INITIAL VALUES FOR ITERATION + // EVALUATE REACTION ADJUSTMENTS + // + // Evaluate the minor non-component species chemical potentials and + // delta G for their formation reactions We have already evaluated the + // major non-components if (!uptodate_minors) { vcs_setFlagsVolPhases(false, VCS_STATECALC_OLD); vcs_dfe(VCS_STATECALC_OLD, 1, 0, m_numSpeciesRdc); @@ -438,41 +380,31 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, plogf(" (only major species)\n"); } } - /* - * Calculate the total moles in each phase -> old solution - * -> Needed for numerical stability when phases disappear. - * -> the phase moles tend to drift off without this step. - */ + + // Calculate the total moles in each phase -> old solution + // -> Needed for numerical stability when phases disappear. + // -> the phase moles tend to drift off without this step. #ifdef DEBUG_MODE check_tmoles(); #endif vcs_tmoles(); - /*************************************************************************/ - /************** COPY OLD into NEW and ZERO VECTORS ***********************/ - /*************************************************************************/ - /* - * Copy the old solution into the new solution as an initial guess - */ + // COPY OLD into NEW and ZERO VECTORS + // Copy the old solution into the new solution as an initial guess m_feSpecies_new = m_feSpecies_old; m_actCoeffSpecies_new = m_actCoeffSpecies_old; m_deltaGRxn_new = m_deltaGRxn_old; m_deltaGRxn_Deficient = m_deltaGRxn_old; m_tPhaseMoles_new = m_tPhaseMoles_old; - /* - * Zero out the entire vector of updates. We sometimes would - * query these values below, and we want to be sure that no - * information is left from previous iterations. - */ + // Zero out the entire vector of updates. We sometimes would query these + // values below, and we want to be sure that no information is left from + // previous iterations. m_deltaMolNumSpecies.assign(m_deltaMolNumSpecies.size(), 0.0); - /*************************************************************************/ - /************** DETERMINE IF DEAD PHASES POP INTO EXISTENCE **************/ - /*************************************************************************/ - /* - * First step is a major branch in the algorithm. - * We first determine if a phase pops into existence. - */ + // DETERMINE IF DEAD PHASES POP INTO EXISTENCE + // + // First step is a major branch in the algorithm. We first determine if a + // phase pops into existence. std::vector phasePopPhaseIDs(0); size_t iphasePop = vcs_popPhaseID(phasePopPhaseIDs); if (iphasePop != npos) { @@ -486,19 +418,14 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, } } - /*************************************************************************/ - /* DETERMINE THE REACTION STEP SIZES FOR MAIN STEP AND IF PHASES DIE *****/ - /*************************************************************************/ - /* - * Don't do this step if there is a phase pop - */ + // DETERMINE THE REACTION STEP SIZES FOR MAIN STEP AND IF PHASES DIE + // + // Don't do this step if there is a phase pop size_t iphaseDelete = npos; size_t kspec; if (iphasePop == npos) { - /* - * Figure out the new reaction step sizes - * for the major species (do minor species in the future too) - */ + // Figure out the new reaction step sizes for the major species (do + // minor species in the future too) kspec = npos; iphaseDelete = vcs_RxnStepSizes(forceComponentCalc, kspec); } else if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { @@ -507,30 +434,24 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, } size_t doPhaseDeleteKspec = npos; size_t doPhaseDeleteIph = npos; - /* - * Zero out the net change in moles of multispecies phases - */ + + // Zero out the net change in moles of multispecies phases m_deltaPhaseMoles.assign(m_deltaPhaseMoles.size(), 0.0); - /* ********************************************************************** */ - /* ***************** MAIN LOOP IN CALCULATION *************************** */ - /* ***************** LOOP OVER IRXN TO DETERMINE STEP SIZE ************** */ - /* ********************************************************************** */ - /* - * Loop through all of the reactions, irxn, pertaining to the - * formation reaction for species kspec in canonical form. - * - * At the end of this loop, we will have a new estimate for the - * mole numbers for all species consistent with an extent - * of reaction for all noncomponent species formation - * reactions. We will have also ensured that all predicted - * non-component mole numbers are greater than zero. - * - * Old_Solution New_Solution Description - * ----------------------------------------------------------------------------- - * m_molNumSpecies_old[kspec] m_molNumSpecies_new[kspec] Species Mole Numbers - * m_deltaMolNumSpecies[kspec] Delta in the Species Mole Numbers - */ + // MAIN LOOP IN CALCULATION: LOOP OVER IRXN TO DETERMINE STEP SIZE + // + // Loop through all of the reactions, irxn, pertaining to the formation + // reaction for species kspec in canonical form. + // + // At the end of this loop, we will have a new estimate for the mole numbers + // for all species consistent with an extent of reaction for all + // noncomponent species formation reactions. We will have also ensured that + // all predicted non-component mole numbers are greater than zero. + // + // Old_Solution New_Solution Description + // ----------------------------------------------------------------------------- + // m_molNumSpecies_old[kspec] m_molNumSpecies_new[kspec] Species Mole Numbers + // m_deltaMolNumSpecies[kspec] Delta in the Species Mole Numbers if (iphaseDelete != npos) { if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { plogf(" --- Main Loop Treatment -> Circumvented due to Phase Deletion "); @@ -555,23 +476,18 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, ++m_numRxnMinorZeroed; allMinorZeroedSpecies = (m_numRxnMinorZeroed == m_numRxnRdc); } - /* - * Set the flags indicating the mole numbers in the vcs_VolPhase - * objects are out of date. - */ + + // Set the flags indicating the mole numbers in the vcs_VolPhase objects + // are out of date. vcs_setFlagsVolPhases(false, VCS_STATECALC_NEW); - /* - * Calculate the new chemical potentials using the tentative - * solution values. We only calculate a subset of these, because - * we have only updated a subset of the W(). - */ + // Calculate the new chemical potentials using the tentative solution + // values. We only calculate a subset of these, because we have only + // updated a subset of the W(). vcs_dfe(VCS_STATECALC_NEW, 0, 0, m_numSpeciesTot); - /* - * Evaluate DeltaG for all components if ITI=0, and for - * major components only if ITI NE 0 - */ + // Evaluate DeltaG for all components if ITI=0, and for major components + // only if ITI NE 0 vcs_deltag(0, false, VCS_STATECALC_NEW); } else { if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { @@ -606,16 +522,12 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec]; } } else if (m_speciesStatus[kspec] == VCS_SPECIES_INTERFACIALVOLTAGE) { - /********************************************************************/ - /************************ VOLTAGE SPECIES ***************************/ - /********************************************************************/ + // VOLTAGE SPECIES bool soldel_ret; dx = vcs_minor_alt_calc(kspec, irxn, &soldel_ret, ANOTE); m_deltaMolNumSpecies[kspec] = dx; } else if (m_speciesStatus[kspec] < VCS_SPECIES_MINOR) { - /********************************************************************/ - /********************** ZEROED OUT SPECIES **************************/ - /********************************************************************/ + // ZEROED OUT SPECIES bool resurrect = (m_deltaMolNumSpecies[kspec] > 0.0); if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 3) { plogf(" --- %s currently zeroed (SpStatus=%-2d):", @@ -661,9 +573,8 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, } } } - /* - * Resurrect the species - */ + + // Resurrect the species if (resurrect) { if (Vphase->exists() == VCS_PHASE_EXIST_NO) { if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { @@ -696,13 +607,10 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, dx = 0.0; } } else if (m_speciesStatus[kspec] == VCS_SPECIES_MINOR) { - /********************************************************************/ - /***************************** MINOR SPECIES ************************/ - /********************************************************************/ - /* - * Unless ITI isn't equal to zero we zero out changes - * to minor species. - */ + // MINOR SPECIES + // + // Unless ITI isn't equal to zero we zero out changes to minor + // species. if (iti != 0) { m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec]; m_deltaMolNumSpecies[kspec] = 0.0; @@ -720,69 +628,60 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, } continue; } - /* - * Minor species alternative calculation - * --------------------------------------- - * This is based upon the following approximation: - * The mole fraction changes due to these reactions don't affect - * the mole numbers of the component species. Therefore the - * following approximation is valid for an ideal solution - * 0 = DG(I) + log(WT(I)/W(I)) - * (DG contains the contribution from FF(I) + log(W(I)/TL) ) - * Thus, - * WT(I) = W(I) EXP(-DG(I)) - * If soldel is true on return, then we branch to the section - * that deletes a species from the current set of active species. - */ + + // Minor species alternative calculation + // + // This is based upon the following approximation: + // The mole fraction changes due to these reactions don't affect + // the mole numbers of the component species. Therefore the + // following approximation is valid for an ideal solution + // 0 = DG(I) + log(WT(I)/W(I)) + // (DG contains the contribution from FF(I) + log(W(I)/TL) ) + // Thus, + // WT(I) = W(I) EXP(-DG(I)) + // If soldel is true on return, then we branch to the section + // that deletes a species from the current set of active species. bool soldel_ret; dx = vcs_minor_alt_calc(kspec, irxn, &soldel_ret, ANOTE); m_deltaMolNumSpecies[kspec] = dx; m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec] + dx; if (soldel_ret) { - /*******************************************************************/ - /***** DELETE MINOR SPECIES LESS THAN VCS_DELETE_SPECIES_CUTOFF */ - /***** MOLE NUMBER */ - /*******************************************************************/ + // DELETE MINOR SPECIES LESS THAN VCS_DELETE_SPECIES_CUTOFF + // MOLE NUMBER if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { plogf(" --- Delete minor species in multispec phase: %-12s", m_speciesName[kspec]); plogendl(); } m_deltaMolNumSpecies[kspec] = 0.0; - /* - * Delete species, kspec. The alternate return is for the case - * where all species become deleted. Then, we need to - * branch to the code where we reevaluate the deletion - * of all species. - */ + + // Delete species, kspec. The alternate return is for the + // case where all species become deleted. Then, we need to + // branch to the code where we reevaluate the deletion of + // all species. size_t lnospec = vcs_delete_species(kspec); if (lnospec) { stage = RECHECK_DELETED; break; } - /* - * Go back to consider the next species in the list. - * Note, however, that the next species in the list is now - * in slot l. In deleting the previous species L, We have - * exchanged slot MR with slot l, and then have - * decremented MR. - * Therefore, we will decrement the species counter, here. - */ + + // Go back to consider the next species in the list. Note, + // however, that the next species in the list is now in slot + // l. In deleting the previous species L, We have exchanged + // slot MR with slot l, and then have decremented MR. + // Therefore, we will decrement the species counter, here. --irxn; continue; } } else { - /********************************************************************/ - /*********************** MAJOR SPECIES ******************************/ - /********************************************************************/ + // MAJOR SPECIES if (DEBUG_MODE_ENABLED) { sprintf(ANOTE, "Normal Major Calc"); } - /* - * Check for superconvergence of the formation reaction. Do - * nothing if it is superconverged. Skip to the end of the - * irxn loop if it is superconverged. - */ + + // Check for superconvergence of the formation reaction. Do + // nothing if it is superconverged. Skip to the end of the irxn + // loop if it is superconverged. if (fabs(m_deltaGRxn_new[irxn]) <= m_tolmaj2) { m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec]; m_deltaMolNumSpecies[kspec] = 0.0; @@ -800,15 +699,14 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, } continue; } - /* - * Set the initial step size, dx, equal to the value produced - * by the routine, vcs_RxnStepSize(). - * - * Note the multiplication logic is to make sure that - * dg[] didn't change sign due to w[] changing in the - * middle of the iteration. (it can if a single species - * phase goes out of existence). - */ + + // Set the initial step size, dx, equal to the value produced by + // the routine, vcs_RxnStepSize(). + // + // Note the multiplication logic is to make sure that dg[] + // didn't change sign due to w[] changing in the middle of the + // iteration. (it can if a single species phase goes out of + // existence). if ((m_deltaGRxn_new[irxn] * m_deltaMolNumSpecies[kspec]) <= 0.0) { dx = m_deltaMolNumSpecies[kspec]; } else { @@ -819,55 +717,44 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, "changed initial point"); } } - /* - * Form a tentative value of the new species moles - */ + + //Form a tentative value of the new species moles m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec] + dx; - /* - * Check for non-positive mole fraction of major species. - * If we find one, we branch to a section below. Then, - * depending upon the outcome, we branch to sections below, - * or we restart the entire iteration. - */ + // Check for non-positive mole fraction of major species. If we + // find one, we branch to a section below. Then, depending upon + // the outcome, we branch to sections below, or we restart the + // entire iteration. if (m_molNumSpecies_new[kspec] <= 0.0) { if (DEBUG_MODE_ENABLED) { sprintf(ANOTE, "initial nonpos kmoles= %11.3E", m_molNumSpecies_new[kspec]); } - /* ************************************************* */ - /* *** NON-POSITIVE MOLES OF MAJOR SPECIES ********* */ - /* ************************************************* */ - /* - * We are here when a tentative value of a mole fraction - * created by a tentative value of M_DELTAMOLNUMSPECIES(*) is negative. - * We branch from here depending upon whether this - * species is in a single species phase or in - * a multispecies phase. - */ + // NON-POSITIVE MOLES OF MAJOR SPECIES + // + // We are here when a tentative value of a mole fraction + // created by a tentative value of M_DELTAMOLNUMSPECIES(*) + // is negative. We branch from here depending upon whether + // this species is in a single species phase or in a + // multispecies phase. if (!m_SSPhase[kspec]) { - /* - * Section for multispecies phases: - * - Cut reaction adjustment for positive kmoles of - * major species in multispecies phases. - * Decrease its concentration by a factor of 10. - */ + // Section for multispecies phases: + // - Cut reaction adjustment for positive kmoles of + // major species in multispecies phases. Decrease + // its concentration by a factor of 10. dx = -0.9 * m_molNumSpecies_old[kspec]; m_deltaMolNumSpecies[kspec] = dx; m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec] + dx; } else { - /* - * Section for single species phases: - * Calculate a dx that will wipe out the - * moles in the phase. - */ + // Section for single species phases: + // Calculate a dx that will wipe out the + // moles in the phase. dx = -m_molNumSpecies_old[kspec]; - /* - * Calculate an update that doesn't create a negative mole - * number for a component species. Actually, restrict this - * a little more so that the component values can only be - * reduced by two 99%, - */ + + // Calculate an update that doesn't create a negative + // mole number for a component species. Actually, + // restrict this a little more so that the component + // values can only be reduced by two 99%, for (size_t j = 0; j < m_numComponents; ++j) { if (sc_irxn[j] != 0.0) { m_wx[j] = m_molNumSpecies_old[j] + sc_irxn[j] * dx; @@ -887,21 +774,18 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, "-> reducing step size instead"); } } else { - /* - * We are going to zero the single species phase. - * Set the existence flag - */ + // We are going to zero the single species phase. + // Set the existence flag iph = m_phaseID[kspec]; Vphase = m_VolPhaseList[iph]; if (DEBUG_MODE_ENABLED) { sprintf(ANOTE, "zeroing out SS phase: "); } - /* - * Change the base mole numbers for the iteration. - * We need to do this here, because we have decided - * to eliminate the phase in this special section - * outside the main loop. - */ + + // Change the base mole numbers for the iteration. + // We need to do this here, because we have decided + // to eliminate the phase in this special section + // outside the main loop. m_molNumSpecies_new[kspec] = 0.0; doPhaseDeleteIph = iph; @@ -933,17 +817,15 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, } } } - } /* End of Loop on ic[irxn] -> the type of species */ - /***********************************************************************/ - /****** CALCULATE KMOLE NUMBER CHANGE FOR THE COMPONENT BASIS **********/ - /***********************************************************************/ + } // End of Loop on ic[irxn] -> the type of species + + // CALCULATE KMOLE NUMBER CHANGE FOR THE COMPONENT BASIS if (dx != 0.0 && (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE)) { - /* - * Change the amount of the component compounds according - * to the reaction delta that we just computed. - * This should keep the amount of material constant. - */ + + // Change the amount of the component compounds according to the + // reaction delta that we just computed. This should keep the + // amount of material constant. AssertThrowMsg(fabs(m_deltaMolNumSpecies[kspec] -dx) < 1.0E-14*(fabs(m_deltaMolNumSpecies[kspec]) + fabs(dx) + 1.0E-32), "VCS_SOLVE::solve_tp_inner", @@ -952,10 +834,9 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, for (size_t k = 0; k < m_numComponents; ++k) { m_deltaMolNumSpecies[k] += sc_irxn[k] * dx; } - /* - * Calculate the tentative change in the total number of - * moles in all of the phases - */ + + // Calculate the tentative change in the total number of moles + // in all of the phases for (iph = 0; iph < m_numPhases; iph++) { m_deltaPhaseMoles[iph] += dx * m_deltaMolNumPhase(iph,irxn); } @@ -965,10 +846,8 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, checkDelta1(&m_deltaMolNumSpecies[0], &m_deltaPhaseMoles[0], kspec+1); } - /* - * Branch point for returning - - */ + // Branch point for returning if (m_debug_print_lvl >= 2) { m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec] + m_deltaMolNumSpecies[kspec]; plogf(" --- "); @@ -989,7 +868,7 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, } break; } - } /**************** END OF MAIN LOOP OVER FORMATION REACTIONS ************/ + } // END OF MAIN LOOP OVER FORMATION REACTIONS if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { for (size_t k = 0; k < m_numComponents; k++) { plogf(" --- "); @@ -1004,13 +883,10 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, plogendl(); } - /*************************************************************************/ - /*********** LIMIT REDUCTION OF BASIS SPECIES TO 99% *********************/ - /*************************************************************************/ - /* - * We have a tentative m_deltaMolNumSpecies[]. Now apply other criteria - * to limit its magnitude. - */ + // LIMIT REDUCTION OF BASIS SPECIES TO 99% + // + // We have a tentative m_deltaMolNumSpecies[]. Now apply other criteria + // to limit its magnitude. double par = 0.5; size_t ll; // only used in DEBUG_MODE for (size_t k = 0; k < m_numComponents; ++k) { @@ -1021,10 +897,8 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, ll = k; } } else if (m_deltaMolNumSpecies[k] < 0.0) { - /* - * If we are here, we then do a step which violates element - * conservation. - */ + // If we are here, we then do a step which violates element + // conservation. size_t iph = m_phaseID[k]; m_deltaPhaseMoles[iph] -= m_deltaMolNumSpecies[k]; m_deltaMolNumSpecies[k] = 0.0; @@ -1032,7 +906,7 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, } par = 1.0 / par; if (par <= 1.01 && par > 0.0) { - /* Reduce the size of the step by the multiplicative factor, par */ + // Reduce the size of the step by the multiplicative factor, par par *= 0.99; if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { plogf(" --- Reduction in step size due to component "); @@ -1054,12 +928,11 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, &m_deltaPhaseMoles[0], m_numSpeciesTot); } - /* - * Now adjust the wt[kspec]'s so that the reflect the decrease in - * the overall length of m_deltaMolNumSpecies[kspec] just calculated. At the end - * of this section wt[], m_deltaMolNumSpecies[], tPhMoles, and tPhMoles1 should all be - * consistent with a new estimate of the state of the system. - */ + // Now adjust the wt[kspec]'s so that the reflect the decrease in the + // overall length of m_deltaMolNumSpecies[kspec] just calculated. At the + // end of this section wt[], m_deltaMolNumSpecies[], tPhMoles, and + // tPhMoles1 should all be consistent with a new estimate of the state + // of the system. for (size_t kspec = 0; kspec < m_numSpeciesTot; ++kspec) { m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec] + m_deltaMolNumSpecies[kspec]; if (m_molNumSpecies_new[kspec] < 0.0 && (m_speciesUnknownType[kspec] @@ -1070,35 +943,25 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, } } - /* - * Calculate the tentative total mole numbers for each phase - */ + // Calculate the tentative total mole numbers for each phase for (size_t iph = 0; iph < m_numPhases; iph++) { m_tPhaseMoles_new[iph] = m_tPhaseMoles_old[iph] + m_deltaPhaseMoles[iph]; } - /* - * Set the flags indicating the mole numbers in the vcs_VolPhase - * objects are out of date. - */ + // Set the flags indicating the mole numbers in the vcs_VolPhase objects + // are out of date. vcs_setFlagsVolPhases(false, VCS_STATECALC_NEW); - /* - * Calculate the new chemical potentials using the tentative - * solution values. We only calculate a subset of these, because - * we have only updated a subset of the W(). - */ + // Calculate the new chemical potentials using the tentative solution + // values. We only calculate a subset of these, because we have only + // updated a subset of the W(). vcs_dfe(VCS_STATECALC_NEW, 0, 0, m_numSpeciesTot); - /* - * Evaluate DeltaG for all components if ITI=0, and for - * major components only if ITI NE 0 - */ + // Evaluate DeltaG for all components if ITI=0, and for major components + // only if ITI NE 0 vcs_deltag(0, false, VCS_STATECALC_NEW); - /* *************************************************************** */ - /* **** CONVERGENCE FORCER SECTION ******************************* */ - /* *************************************************************** */ + // CONVERGENCE FORCER SECTION if (printDetails) { plogf(" --- Total Old Dimensionless Gibbs Free Energy = %20.13E\n", vcs_Total_Gibbs(&m_molNumSpecies_old[0], &m_feSpecies_old[0], @@ -1111,9 +974,7 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, bool forced = vcs_globStepDamp(); - /* - * Print out the changes to the solution that FORCER produced - */ + // Print out the changes to the solution that FORCER produced if (printDetails && forced) { plogf(" -----------------------------------------------------\n"); plogf(" --- FORCER SUBROUTINE changed the solution:\n"); @@ -1151,9 +1012,8 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, } } - /* *************************************************************** */ - /* **** ITERATION SUMMARY PRINTOUT SECTION *********************** */ - /* *************************************************************** */ + + // ITERATION SUMMARY PRINTOUT SECTION if (printDetails) { plogf(" "); writeline('-', 103); @@ -1219,21 +1079,16 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, plogendl(); } } - /*************************************************************************/ - /******************* RESET VALUES AT END OF ITERATION ********************/ - /******************* UPDATE MOLE NUMBERS *********************************/ - /*************************************************************************/ - /* - * If the solution wasn't changed in the forcer routine, - * then copy the tentative mole numbers and Phase moles - * into the actual mole numbers and phase moles. - * We will consider this current step to be completed. - * - * Accept the step. -> the tentative solution now becomes - * the real solution. If FORCED is true, then - * we have already done this inside the FORCED - * loop. - */ + + // RESET VALUES AT END OF ITERATION + // UPDATE MOLE NUMBERS + // + // If the solution wasn't changed in the forcer routine, then copy the + // tentative mole numbers and Phase moles into the actual mole numbers and + // phase moles. We will consider this current step to be completed. + // + // Accept the step. -> the tentative solution now becomes the real solution. + // If FORCED is true, then we have already done this inside the FORCED loop. vcs_updateMolNumVolPhases(VCS_STATECALC_NEW); m_tPhaseMoles_old = m_tPhaseMoles_new; m_molNumSpecies_old = m_molNumSpecies_new; @@ -1242,9 +1097,8 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, m_feSpecies_old = m_feSpecies_new; vcs_setFlagsVolPhases(true, VCS_STATECALC_OLD); - /* - * Increment the iteration counters - */ + + // Increment the iteration counters ++m_VCount->Its; ++it1; if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { @@ -1252,16 +1106,13 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, m_VCount->Its); plogendl(); } - /*************************************************************************/ - /******************* HANDLE DELETION OF MULTISPECIES PHASES **************/ - /*************************************************************************/ - /* - * We delete multiphases, when the total moles in the multiphase - * is reduced below a relative threshold. - * Set microscopic multispecies phases with total relative - * number of moles less than VCS_DELETE_PHASE_CUTOFF to - * absolute zero. - */ + + // HANDLE DELETION OF MULTISPECIES PHASES + // + // We delete multiphases, when the total moles in the multiphase is reduced + // below a relative threshold. Set microscopic multispecies phases with + // total relative number of moles less than VCS_DELETE_PHASE_CUTOFF to + // absolute zero. bool justDeletedMultiPhase = false; for (size_t iph = 0; iph < m_numPhases; iph++) { if (!m_VolPhaseList[iph]->m_singleSpecies && m_tPhaseMoles_old[iph] != 0.0 && @@ -1274,12 +1125,10 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, vcs_delete_multiphase(iph); } } - /* - * If we have deleted a multispecies phase because the - * equilibrium moles decreased, then we will update all - * the component basis calculation, and therefore all - * of the thermo functions just to be safe. - */ + + // If we have deleted a multispecies phase because the equilibrium moles + // decreased, then we will update all the component basis calculation, and + // therefore all of the thermo functions just to be safe. if (justDeletedMultiPhase) { bool usedZeroedSpecies; double test = -1.0e-10; @@ -1295,9 +1144,8 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, iti = 0; return; } - /*************************************************************************/ - /***************** CHECK FOR ELEMENT ABUNDANCE****************************/ - /*************************************************************************/ + + // CHECK FOR ELEMENT ABUNDANCE if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { plogf(" --- Normal element abundance check"); } @@ -1316,9 +1164,8 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, plogf(" - passed"); plogendl(); } - /*************************************************************************/ - /***************** CHECK FOR OPTIMUM BASIS *******************************/ - /*************************************************************************/ + + // CHECK FOR OPTIMUM BASIS for (size_t i = 0; i < m_numRxnRdc; ++i) { size_t l = m_indexRxnToSpecies[i]; if (m_speciesUnknownType[l] == VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) { @@ -1364,13 +1211,11 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, plogendl(); } stage = EQUILIB_CHECK; - /*************************************************************************/ - /********************** RE-EVALUATE MAJOR-MINOR VECTOR IF NECESSARY ******/ - /*************************************************************************/ - /* - * Skip this section if we haven't done a full calculation. - * Go right to the check equilibrium section - */ + + // RE-EVALUATE MAJOR-MINOR VECTOR IF NECESSARY + // + // Skip this section if we haven't done a full calculation. Go right to the + // check equilibrium section if (iti != 0) { return; } @@ -1417,10 +1262,9 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1, } m_speciesStatus[kspec] = speciesType; } - /* - * This logical variable indicates whether all current - * non-component species are minor or nonexistent - */ + + // This logical variable indicates whether all current non-component species + // are minor or nonexistent allMinorZeroedSpecies = (m_numRxnMinorZeroed == m_numRxnRdc); } @@ -1439,19 +1283,16 @@ void VCS_SOLVE::solve_tp_equilib_check(bool& allMinorZeroedSpecies, if (m_speciesStatus[kspec] == VCS_SPECIES_MAJOR && (fabs(m_deltaGRxn_new[irxn]) > m_tolmaj)) { if (m_VCount->Its >= maxit) { solveFail = -1; - /* - * Clean up and exit code even though we haven't - * converged. -> we have run out of iterations! - */ + + // Clean up and exit code even though we haven't converged. + // -> we have run out of iterations! stage = RETURN_A; } else { if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { plogf("%s failed\n", m_speciesName[m_indexRxnToSpecies[irxn]]); } - // Convergence amongst major species has not been achieved - /* - * Go back and do another iteration with variable ITI - */ + // Convergence amongst major species has not been achieved. + // Go back and do another iteration with variable ITI iti = ((it1/4) *4) - it1; stage = MAIN; } @@ -1469,14 +1310,10 @@ void VCS_SOLVE::solve_tp_equilib_check(bool& allMinorZeroedSpecies, } // Convergence amongst major species has been achieved - /*************************************************************************/ - /*************** EQUILIBRIUM CHECK FOR MINOR SPECIES *********************/ - /*************************************************************************/ + // EQUILIBRIUM CHECK FOR MINOR SPECIES if (m_numRxnMinorZeroed != 0) { - /* - * Calculate the chemical potential and reaction DeltaG - * for minor species, if needed. - */ + // Calculate the chemical potential and reaction DeltaG for minor + // species, if needed. if (iti != 0) { vcs_setFlagsVolPhases(false, VCS_STATECALC_OLD); vcs_dfe(VCS_STATECALC_OLD, 1, 0, m_numSpeciesRdc); @@ -1491,20 +1328,17 @@ void VCS_SOLVE::solve_tp_equilib_check(bool& allMinorZeroedSpecies, if (m_speciesStatus[kspec] == VCS_SPECIES_MINOR && (fabs(m_deltaGRxn_new[irxn]) > m_tolmin)) { if (m_VCount->Its >= maxit) { solveFail = -1; - /* - * Clean up and exit code. -> Even though we have not - * converged, we have run out of iterations ! - */ + // Clean up and exit code. -> Even though we have not + // converged, we have run out of iterations ! stage = RETURN_A; return; } if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { plogf("%s failed\n", m_speciesName[m_indexRxnToSpecies[irxn]]); } - /* - * Set iti to zero to force a full calculation, and go back - * to the main loop to do another iteration. - */ + + // Set iti to zero to force a full calculation, and go back to + // the main loop to do another iteration. iti = 0; stage = MAIN; return; @@ -1514,26 +1348,21 @@ void VCS_SOLVE::solve_tp_equilib_check(bool& allMinorZeroedSpecies, plogf(" CONVERGENCE achieved\n"); } } - /*************************************************************************/ - /*********************** FINAL ELEMENTAL ABUNDANCE CHECK *****************/ - /*************************************************************************/ - /* - * Recalculate the element abundance vector again - */ + + // FINAL ELEMENTAL ABUNDANCE CHECK + // Recalculate the element abundance vector again vcs_updateVP(VCS_STATECALC_OLD); vcs_elab(); - /* LEC is only true when we are near the end game */ + // LEC is only true when we are near the end game if (lec) { if (!giveUpOnElemAbund) { if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { plogf(" --- Check the Full Element Abundances: "); } - /* - * Final element abundance check: - * If we fail then we need to go back and correct - * the element abundances, and then go do a major step - */ + + // Final element abundance check: If we fail then we need to go back + // and correct the element abundances, and then go do a major step if (! vcs_elabcheck(1)) { if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { if (! vcs_elabcheck(0)) { @@ -1550,15 +1379,14 @@ void VCS_SOLVE::solve_tp_equilib_check(bool& allMinorZeroedSpecies, plogf(" passed\n"); } } - /* - * If we have deleted a species then we need to recheck the - * the deleted species, before exiting - */ + + // If we have deleted a species then we need to recheck the the deleted + // species, before exiting if (m_numSpeciesRdc != m_numSpeciesTot) { stage = RECHECK_DELETED; return; } - /* - Final checks are passed -> go check out */ + // Final checks are passed -> go check out stage = RETURN_A; } lec = true; @@ -1569,40 +1397,32 @@ void VCS_SOLVE::solve_tp_elem_abund_check(size_t& iti, int& stage, bool& lec, int& finalElemAbundAttempts, int& rangeErrorFound) { - /* - * HKM - Put in an element abundance check. The element abundances - * were being corrected even if they were perfectly OK to - * start with. This is actually an expensive operation, so - * I took it out. Also vcs_dfe() doesn't need to be called if - * no changes were made. - */ + + // HKM - Put in an element abundance check. The element abundances were + // being corrected even if they were perfectly OK to start with. This is + // actually an expensive operation, so I took it out. Also vcs_dfe() doesn't + // need to be called if no changes were made. rangeErrorFound = 0; if (! vcs_elabcheck(1)) { bool ncBefore = vcs_elabcheck(0); vcs_elcorr(&m_sm[0], &m_wx[0]); bool ncAfter = vcs_elabcheck(0); bool neAfter = vcs_elabcheck(1); - /* - * Go back to evaluate the total moles of gas and liquid. - */ + + // Go back to evaluate the total moles of gas and liquid. vcs_setFlagsVolPhases(false, VCS_STATECALC_OLD); vcs_dfe(VCS_STATECALC_OLD, 0, 0, m_numSpeciesRdc); vcs_deltag(0, false, VCS_STATECALC_OLD); if (!ncBefore) { if (ncAfter) { - /* - * We have breathed new life into the old problem. Now the - * element abundances up to NC agree. Go back and - * restart the main loop calculation, resetting the - * end conditions. - */ + // We have breathed new life into the old problem. Now the + // element abundances up to NC agree. Go back and restart the + // main loop calculation, resetting the end conditions. lec = false; iti = 0; stage = MAIN; } else { - /* - * We are still hosed - */ + // We are still hosed if (finalElemAbundAttempts >= 3) { giveUpOnElemAbund = true; stage = EQUILIB_CHECK; @@ -1616,9 +1436,7 @@ void VCS_SOLVE::solve_tp_elem_abund_check(size_t& iti, int& stage, bool& lec, return; } else if (ncAfter) { if (!neAfter) { - /* - * Probably an unrecoverable range error - */ + // Probably an unrecoverable range error if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { plogf(" --- vcs_solve_tp: RANGE SPACE ERROR ENCOUNTERED\n"); plogf(" --- vcs_solve_tp: - Giving up on NE Element Abundance satisfaction \n"); @@ -1629,11 +1447,9 @@ void VCS_SOLVE::solve_tp_elem_abund_check(size_t& iti, int& stage, bool& lec, rangeErrorFound = 1; giveUpOnElemAbund = true; } - /* - * Recovery of end element abundances - * -> go do equilibrium check again and then - * check out. - */ + + // Recovery of end element abundances -> go do equilibrium check + // again and then check out. stage = EQUILIB_CHECK; return; } @@ -1677,22 +1493,18 @@ double VCS_SOLVE::vcs_minor_alt_calc(size_t kspec, size_t irxn, bool* do_delete, } } - /* - * get the diagonal of the activity coefficient Jacobian - */ + // get the diagonal of the activity coefficient Jacobian s = m_np_dLnActCoeffdMolNum(kspec,kspec) / m_tPhaseMoles_old[iph]; - /* - * We fit it to a power law approximation of the activity coefficient - * - * gamma = gamma_0 * ( x / x0)**a - * - * where a is forced to be a little bit greater than -1. - * We do this so that the resulting expression is always nonnegative - * - * We then solve the resulting calculation: - * - * gamma * x = gamma_0 * x0 exp (-deltaG/RT); - */ + + // We fit it to a power law approximation of the activity coefficient + // + // gamma = gamma_0 * ( x / x0)**a + // + // where a is forced to be a little bit greater than -1. + // We do this so that the resulting expression is always nonnegative + // We then solve the resulting calculation: + // + // gamma * x = gamma_0 * x0 exp (-deltaG/RT); a = clip(w_kspec * s, -1.0+1e-8, 100.0); tmp = clip(-dg_irxn / (1.0 + a), -200.0, 200.0); wTrial = w_kspec * exp(tmp); @@ -1718,21 +1530,17 @@ double VCS_SOLVE::vcs_minor_alt_calc(size_t kspec, size_t irxn, bool* do_delete, goto L_ZERO_SPECIES; } return molNum_kspec_new - w_kspec; - /* - * - * Alternate return based for cases where we need to delete the species - * from the current list of active species, because its concentration - * has gotten too small. - */ + + // Alternate return based for cases where we need to delete the species + // from the current list of active species, because its concentration + // has gotten too small. L_ZERO_SPECIES: ; *do_delete = true; return - w_kspec; } else { - /* - * Voltage calculation - * Need to check the sign -> This is good for electrons - */ + // Voltage calculation + // Need to check the sign -> This is good for electrons dx = m_deltaGRxn_old[irxn]/ m_Faraday_dim; if (DEBUG_MODE_ENABLED && ANOTE) { sprintf(ANOTE,"voltage species alternative calc"); @@ -1749,10 +1557,8 @@ int VCS_SOLVE::delta_species(const size_t kspec, double* const delta_ptr) AssertThrowMsg(kspec >= m_numComponents, "VCS_SOLVE::delta_species", "delete_species() ERROR: called for a component {}", kspec); if (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) { - /* - * Attempt the given dx. If it doesn't work, try to see if a smaller - * one would work, - */ + // Attempt the given dx. If it doesn't work, try to see if a smaller one + // would work, double dx = delta; double* sc_irxn = m_stoichCoeffRxnMatrix.ptrColumn(irxn); for (size_t j = 0; j < m_numComponents; ++j) { @@ -1763,18 +1569,16 @@ int VCS_SOLVE::delta_species(const size_t kspec, double* const delta_ptr) dx = std::min(dx, - m_molNumSpecies_old[j] / sc_irxn[j]); } } - /* - * If the component has a zero concentration and is a reactant - * in the formation reaction, then dx == 0.0, and we just return. - */ + + // If the component has a zero concentration and is a reactant + // in the formation reaction, then dx == 0.0, and we just return. if (m_molNumSpecies_old[j] <= 0.0 && sc_irxn[j] < 0.0) { *delta_ptr = 0.0; return 0; } } - /* - * ok, we found a positive dx. implement it. - */ + + // ok, we found a positive dx. implement it. *delta_ptr = dx; m_molNumSpecies_old[kspec] += dx; size_t iph = m_phaseID[kspec]; @@ -1798,9 +1602,8 @@ int VCS_SOLVE::delta_species(const size_t kspec, double* const delta_ptr) int VCS_SOLVE::vcs_zero_species(const size_t kspec) { int retn = 1; - /* - * Calculate a delta that will eliminate the species. - */ + + // Calculate a delta that will eliminate the species. if (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) { double dx = -m_molNumSpecies_old[kspec]; if (dx != 0.0) { @@ -1822,19 +1625,17 @@ int VCS_SOLVE::vcs_delete_species(const size_t kspec) const size_t iph = m_phaseID[kspec]; vcs_VolPhase* const Vphase = m_VolPhaseList[iph]; const size_t irxn = kspec - m_numComponents; - /* - * Zero the concentration of the species. - * -> This zeroes w[kspec] and modifies m_tPhaseMoles_old[] - */ + + // Zero the concentration of the species. + // -> This zeroes w[kspec] and modifies m_tPhaseMoles_old[] const int retn = vcs_zero_species(kspec); if (!retn) { throw CanteraError("VCS_SOLVE::vcs_delete_species", "Failed to delete a species!"); } - /* - * Decrement the minor species counter if the current species is - * a minor species - */ + + // Decrement the minor species counter if the current species is a minor + // species if (m_speciesStatus[kspec] != VCS_SPECIES_MAJOR) { --m_numRxnMinorZeroed; } @@ -1844,29 +1645,22 @@ int VCS_SOLVE::vcs_delete_species(const size_t kspec) m_feSpecies_new[kspec] = 0.0; m_feSpecies_old[kspec] = 0.0; m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec]; - /* - * Rearrange the data if the current species isn't the last active - * species. - */ + + // Rearrange the data if the current species isn't the last active species. if (kspec != klast) { vcs_switch_pos(true, klast, kspec); } - /* - * Adjust the total moles in a phase downwards. - */ + + // Adjust the total moles in a phase downwards. Vphase->setMolesFromVCSCheck(VCS_STATECALC_OLD, &m_molNumSpecies_old[0], &m_tPhaseMoles_old[0]); - /* - * Adjust the current number of active species and reactions counters - */ + // Adjust the current number of active species and reactions counters --m_numRxnRdc; --m_numSpeciesRdc; - /* - * Check to see whether we have just annihilated a multispecies phase. - * If it is extinct, call the delete_multiphase() function. - */ + // Check to see whether we have just annihilated a multispecies phase. If it + // is extinct, call the delete_multiphase() function. if (! m_SSPhase[klast] && Vphase->exists() != VCS_PHASE_EXIST_ALWAYS) { bool stillExists = false; for (size_t k = 0; k < m_numSpeciesRdc; k++) { @@ -1880,10 +1674,9 @@ int VCS_SOLVE::vcs_delete_species(const size_t kspec) vcs_delete_multiphase(iph); } } - /* - * When the total number of noncomponent species is zero, we - * have to signal the calling code - */ + + // When the total number of noncomponent species is zero, we have to signal + // the calling code return (m_numRxnRdc == 0); } @@ -1893,11 +1686,10 @@ void VCS_SOLVE::vcs_reinsert_deleted(size_t kspec) if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { plogf(" --- Add back a deleted species: %-12s\n", m_speciesName[kspec]); } - /* - * Set the species back to minor species status - * this adjusts m_molNumSpecies_old[] and m_tPhaseMoles_old[] - * HKM -> make this a relative mole number! - */ + + // Set the species back to minor species status + // this adjusts m_molNumSpecies_old[] and m_tPhaseMoles_old[] + // HKM -> make this a relative mole number! double dx = m_tPhaseMoles_old[iph] * VCS_RELDELETE_SPECIES_CUTOFF * 10.; delta_species(kspec, &dx); m_speciesStatus[kspec] = VCS_SPECIES_MINOR; @@ -1911,15 +1703,11 @@ void VCS_SOLVE::vcs_reinsert_deleted(size_t kspec) Vphase->setMolesFromVCSCheck(VCS_STATECALC_OLD, &m_molNumSpecies_old[0], &m_tPhaseMoles_old[0]); - /* - * We may have popped a multispecies phase back - * into existence. If we did, we have to check - * the other species in that phase. - * Take care of the m_speciesStatus[] flag. - * The value of m_speciesStatus[] must change from - * VCS_SPECIES_ZEROEDPHASE to VCS_SPECIES_ZEROEDMS - * for those other species. - */ + + // We may have popped a multispecies phase back into existence. If we did, + // we have to check the other species in that phase. Take care of the + // m_speciesStatus[] flag. The value of m_speciesStatus[] must change from + // VCS_SPECIES_ZEROEDPHASE to VCS_SPECIES_ZEROEDMS for those other species. if (! m_SSPhase[kspec]) { if (Vphase->exists() == VCS_PHASE_EXIST_NO) { Vphase->setExistence(VCS_PHASE_EXIST_YES); @@ -1938,9 +1726,7 @@ void VCS_SOLVE::vcs_reinsert_deleted(size_t kspec) ++m_numRxnMinorZeroed; if (kspec != (m_numSpeciesRdc - 1)) { - /* - * Rearrange both the species and the non-component global data - */ + // Rearrange both the species and the non-component global data vcs_switch_pos(true, (m_numSpeciesRdc - 1), kspec); } } @@ -1949,23 +1735,18 @@ bool VCS_SOLVE::vcs_delete_multiphase(const size_t iph) { vcs_VolPhase* Vphase = m_VolPhaseList[iph]; bool successful = true; - /* - * set the phase existence flag to dead - */ + + // set the phase existence flag to dead Vphase->setTotalMoles(0.0); if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { plogf(" --- delete_multiphase %d, %s\n", iph, Vphase->PhaseName); } - /* - * Loop over all of the species in the phase. - */ + // Loop over all of the species in the phase. for (size_t kspec = m_numComponents; kspec < m_numSpeciesRdc; ++kspec) { if (m_phaseID[kspec] == iph) { if (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) { - /* - * calculate an extent of rxn, dx, that zeroes out the species. - */ + // calculate an extent of rxn, dx, that zeroes out the species. double dx = - m_molNumSpecies_old[kspec]; double dxTent = dx; @@ -1984,17 +1765,14 @@ bool VCS_SOLVE::vcs_delete_multiphase(const size_t iph) // recover the total phase moles. vcs_tmoles(); } else { - /* - * Set the mole number of that species to zero. - */ + // Set the mole number of that species to zero. m_molNumSpecies_old[kspec] = 0.0; m_molNumSpecies_new[kspec] = 0.0; m_deltaMolNumSpecies[kspec] = 0.0; } - /* - * Change the status flag of the species to that of an - * zeroed phase - */ + + // Change the status flag of the species to that of an zeroed + // phase m_speciesStatus[kspec] = VCS_SPECIES_ZEROEDMS; } } @@ -2051,15 +1829,11 @@ bool VCS_SOLVE::vcs_delete_multiphase(const size_t iph) } } - /* - * Loop over all of the inactive species in the phase: - * Right now we reinstate all species in a deleted multiphase. - * We may only want to reinstate the "major ones" in the future. - * Note, species in phases with zero mole numbers are still - * considered active. Whether the phase pops back into - * existence or not is checked as part of the main iteration - * loop. - */ + // Loop over all of the inactive species in the phase: Right now we + // reinstate all species in a deleted multiphase. We may only want to + // reinstate the "major ones" in the future. Note, species in phases with + // zero mole numbers are still considered active. Whether the phase pops + // back into existence or not is checked as part of the main iteration loop. for (size_t kspec = m_numSpeciesRdc; kspec < m_numSpeciesTot; ++kspec) { if (m_phaseID[kspec] == iph) { m_molNumSpecies_old[kspec] = 0.0; @@ -2075,23 +1849,18 @@ bool VCS_SOLVE::vcs_delete_multiphase(const size_t iph) "was zeroed\n"); } if (kspec != (m_numSpeciesRdc - 1)) { - /* - * Rearrange both the species and the non-component global data - */ + // Rearrange both the species and the non-component global data vcs_switch_pos(true, (m_numSpeciesRdc - 1), kspec); } } } - /* - * Zero out the total moles counters for the phase - */ + // Zero out the total moles counters for the phase m_tPhaseMoles_old[iph] = 0.0; m_tPhaseMoles_new[iph] = 0.0; m_deltaPhaseMoles[iph] = 0.0; - /* - * Upload the state to the VP object - */ + + // Upload the state to the VP object Vphase->setTotalMoles(0.0); return successful; } @@ -2105,12 +1874,10 @@ int VCS_SOLVE::vcs_recheck_deleted() if (m_numSpeciesRdc == m_numSpeciesTot) { return 0; } - /* - * Use the standard chemical potentials for the chemical potentials - * of deleted species. Then, calculate Delta G for - * for formation reactions. - * Note: fe[] here includes everything except for the ln(x[i]) term - */ + + // Use the standard chemical potentials for the chemical potentials of + // deleted species. Then, calculate Delta G for for formation reactions. + // Note: fe[] here includes everything except for the ln(x[i]) term for (size_t kspec = m_numSpeciesRdc; kspec < m_numSpeciesTot; ++kspec) { size_t iph = m_phaseID[kspec]; m_feSpecies_new[kspec] = (m_SSfeSpecies[kspec] + log(m_actCoeffSpecies_old[kspec]) @@ -2118,10 +1885,8 @@ int VCS_SOLVE::vcs_recheck_deleted() + m_chargeSpecies[kspec] * m_Faraday_dim * m_phasePhi[iph]); } - /* - * Recalculate the DeltaG's of the formation reactions for the - * deleted species in the mechanism - */ + // Recalculate the DeltaG's of the formation reactions for the deleted + // species in the mechanism vcs_deltag(0, true, VCS_STATECALC_NEW); for (size_t iph = 0; iph < m_numPhases; iph++) { @@ -2132,32 +1897,27 @@ int VCS_SOLVE::vcs_recheck_deleted() } } - /* - * - * We are checking the equation: - * - * sum_u = sum_j_comp [ sigma_i_j * u_j ] - * = u_i_O + log((AC_i * W_i)/m_tPhaseMoles_old) - * - * by first evaluating: - * - * DG_i_O = u_i_O - sum_u. - * - * Then, if TL is zero, the phase pops into existence if DG_i_O < 0. - * Also, if the phase exists, then we check to see if the species - * can have a mole number larger than VCS_DELETE_SPECIES_CUTOFF - * (default value = 1.0E-32). - * - * HKM: - * This seems to be an inconsistency in the algorithm here that needs - * correcting. The requirement above may bypass some multiphases which - * should exist. The real requirement for the phase to exist is: - * - * sum_i_in_phase [ exp(-DG_i_O) ] >= 1.0 - * - * Thus, we need to amend the code. Also nonideal solutions will tend to - * complicate matters severely also. - */ + // We are checking the equation: + // + // sum_u = sum_j_comp [ sigma_i_j * u_j ] + // = u_i_O + log((AC_i * W_i)/m_tPhaseMoles_old) + // + // by first evaluating: + // + // DG_i_O = u_i_O - sum_u. + // + // Then, if TL is zero, the phase pops into existence if DG_i_O < 0. Also, + // if the phase exists, then we check to see if the species can have a mole + // number larger than VCS_DELETE_SPECIES_CUTOFF (default value = 1.0E-32). + // + // HKM: This seems to be an inconsistency in the algorithm here that needs + // correcting. The requirement above may bypass some multiphases which + // should exist. The real requirement for the phase to exist is: + // + // sum_i_in_phase [ exp(-DG_i_O) ] >= 1.0 + // + // Thus, we need to amend the code. Also nonideal solutions will tend to + // complicate matters severely also. int npb = 0; for (size_t irxn = m_numRxnRdc; irxn < m_numRxnTot; ++irxn) { size_t kspec = m_indexRxnToSpecies[irxn]; @@ -2218,12 +1978,12 @@ size_t VCS_SOLVE::vcs_add_all_deleted() if (m_numSpeciesRdc == m_numSpeciesTot) { return 0; } - /* - * Use the standard chemical potentials for the chemical potentials of deleted species. Then, calculate Delta G for - * for formation reactions. - * We are relying here on a old saved value of m_actCoeffSpecies_old[kspec] - * being sufficiently good. Note, we will recalculate everything at the end of the routine. - */ + + // Use the standard chemical potentials for the chemical potentials of + // deleted species. Then, calculate Delta G for for formation reactions. We + // are relying here on a old saved value of m_actCoeffSpecies_old[kspec] + // being sufficiently good. Note, we will recalculate everything at the end + // of the routine. m_molNumSpecies_new = m_molNumSpecies_old; for (int cits = 0; cits < 3; cits++) { for (size_t kspec = m_numSpeciesRdc; kspec < m_numSpeciesTot; ++kspec) { @@ -2238,9 +1998,9 @@ size_t VCS_SOLVE::vcs_add_all_deleted() m_feSpecies_new[kspec] = (m_SSfeSpecies[kspec] + log(m_actCoeffSpecies_new[kspec]) - m_lnMnaughtSpecies[kspec] + m_chargeSpecies[kspec] * m_Faraday_dim * m_phasePhi[iph]); } - /* - * Recalculate the DeltaG's of the formation reactions for the deleted species in the mechanism - */ + + // Recalculate the DeltaG's of the formation reactions for the deleted + // species in the mechanism vcs_deltag(0, true, VCS_STATECALC_NEW); for (size_t irxn = m_numRxnRdc; irxn < m_numRxnTot; ++irxn) { size_t kspec = m_indexRxnToSpecies[irxn]; @@ -2313,9 +2073,7 @@ bool VCS_SOLVE::vcs_globStepDamp() { double* dptr = &m_deltaGRxn_new[0]; - /* *************************************************** */ - /* **** CALCULATE SLOPE AT END OF THE STEP ********** */ - /* *************************************************** */ + // CALCULATE SLOPE AT END OF THE STEP double s2 = 0.0; for (size_t irxn = 0; irxn < m_numRxnRdc; ++irxn) { size_t kspec = irxn + m_numComponents; @@ -2324,9 +2082,7 @@ bool VCS_SOLVE::vcs_globStepDamp() } } - /* *************************************************** */ - /* **** CALCULATE ORIGINAL SLOPE ********************* */ - /* ************************************************** */ + // CALCULATE ORIGINAL SLOPE double s1 = 0.0; dptr = &m_deltaGRxn_old[0]; for (size_t irxn = 0; irxn < m_numRxnRdc; ++irxn) { @@ -2362,9 +2118,7 @@ bool VCS_SOLVE::vcs_globStepDamp() return false; } - /* *************************************************** */ - /* **** FIT PARABOLA ********************************* */ - /* *************************************************** */ + // FIT PARABOLA double al = 1.0; if (fabs(s1 -s2) > 1.0E-200) { al = s1 / (s1 - s2); @@ -2379,9 +2133,7 @@ bool VCS_SOLVE::vcs_globStepDamp() plogf(" --- subroutine FORCE produced a damping factor = %g\n", al); } - /* *************************************************** */ - /* **** ADJUST MOLE NUMBERS, CHEM. POT *************** */ - /* *************************************************** */ + // ADJUST MOLE NUMBERS, CHEM. POT if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) { m_deltaGRxn_tmp = m_deltaGRxn_new; } @@ -2400,19 +2152,15 @@ bool VCS_SOLVE::vcs_globStepDamp() plogf(" --- subroutine FORCE adjusted the mole " "numbers, AL = %10.3f\n", al); } - /* - * Because we changed the mole numbers, we need to - * calculate the chemical potentials again. If a major- - * only step is being carried out, then we don't need to - * update the minor noncomponents. - */ + + // Because we changed the mole numbers, we need to calculate the chemical + // potentials again. If a major-only step is being carried out, then we + // don't need to update the minor noncomponents. vcs_setFlagsVolPhases(false, VCS_STATECALC_NEW); vcs_dfe(VCS_STATECALC_NEW, 0, 0, m_numSpeciesRdc); - /* - * Evaluate DeltaG for all components if ITI=0, and for - * major components only if ITI NE 0 - */ + // Evaluate DeltaG for all components if ITI=0, and for major components + // only if ITI NE 0 vcs_deltag(0, false, VCS_STATECALC_NEW); dptr = &m_deltaGRxn_new[0]; @@ -2478,25 +2226,20 @@ int VCS_SOLVE::vcs_basopt(const bool doJustComponents, double aw[], double sa[], } } - /* - * Calculate the maximum value of the number of components possible - * It's equal to the minimum of the number of elements and the - * number of total species. - */ + // Calculate the maximum value of the number of components possible. It's + // equal to the minimum of the number of elements and the number of total + // species. size_t ncTrial = std::min(m_numElemConstraints, m_numSpeciesTot); m_numComponents = ncTrial; *usedZeroedSpecies = false; vector_int ipiv(ncTrial); int info; - /* - * Use a temporary work array for the mole numbers, aw[] - */ + // Use a temporary work array for the mole numbers, aw[] std::copy(m_molNumSpecies_old.begin(), m_molNumSpecies_old.begin() + m_numSpeciesTot, aw); - /* - * Take out the Voltage unknowns from consideration - */ + + // Take out the Voltage unknowns from consideration for (k = 0; k < m_numSpeciesTot; k++) { if (m_speciesUnknownType[k] == VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) { aw[k] = test; @@ -2504,61 +2247,56 @@ int VCS_SOLVE::vcs_basopt(const bool doJustComponents, double aw[], double sa[], } size_t jr = 0; - /* - * Top of a loop of some sort based on the index JR. JR is the - * current number of component species found. - */ + + // Top of a loop of some sort based on the index JR. JR is the current + // number of component species found. while (jr < ncTrial) { - /* - 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. - * The first search criteria is always the largest positive - * magnitude of the mole number. - */ + // Search the remaining part of the mole fraction vector, AW, for + // the largest remaining species. Return its identity in K. The + // first search criteria is always the largest positive magnitude of + // the mole number. k = vcs_basisOptMax(aw, jr, m_numSpeciesTot); - /* - * The fun really starts when you have run out of species that have a significant - * concentration. It becomes extremely important to make a good choice of which - * species you want to pick to fill out the basis. Basically, you don't want to - * use species with elements abundances which aren't pegged to zero. This means - * that those modes will never be allowed to grow. You want to have the - * best chance that the component will grow positively. - * - * Suppose you start with CH4, N2, as the only species with nonzero compositions. - * You have the following abundances: - * - * Abundances: - * ---------------- - * C 2.0 - * N 2.0 - * H 4.0 - * O 0.0 - * - * For example, Make the following choice: - * - * CH4 N2 O choose -> OH - * or - * CH4 N2 O choose -> H2 - * - * OH and H2 both fill out the basis. They will pass the algorithm. However, - * choosing OH as the next species will create a situation where H2 can not - * grow in concentration. This happened in practice, btw. The reason is that - * the formation reaction for H2 will cause one of the component species - * to go negative. - * - * The basic idea here is to pick a simple species whose mole number - * can grow according to the element compositions. Candidates are still - * filtered according to their linear independence. - * - * Note, if there is electronic charge and the electron species, - * you should probably pick the electron as a component, if it - * linearly independent. The algorithm below will do this automagically. - * - */ + // The fun really starts when you have run out of species that have + // a significant concentration. It becomes extremely important to + // make a good choice of which species you want to pick to fill out + // the basis. Basically, you don't want to use species with elements + // abundances which aren't pegged to zero. This means that those + // modes will never be allowed to grow. You want to have the best + // chance that the component will grow positively. + // + // Suppose you start with CH4, N2, as the only species with nonzero + // compositions. You have the following abundances: + // + // Abundances: + // ---------------- + // C 2.0 + // N 2.0 + // H 4.0 + // O 0.0 + // + // For example, Make the following choice: + // + // CH4 N2 O choose -> OH + // or + // CH4 N2 O choose -> H2 + // + // OH and H2 both fill out the basis. They will pass the algorithm. + // However, choosing OH as the next species will create a situation + // where H2 can not grow in concentration. This happened in + // practice, btw. The reason is that the formation reaction for H2 + // will cause one of the component species to go negative. + // + // The basic idea here is to pick a simple species whose mole number + // can grow according to the element compositions. Candidates are + // still filtered according to their linear independence. + // + // Note, if there is electronic charge and the electron species, you + // should probably pick the electron as a component, if it linearly + // independent. The algorithm below will do this automagically. if ((aw[k] != test) && aw[k] < VCS_DELETE_MINORSPECIES_CUTOFF) { *usedZeroedSpecies = true; double maxConcPossKspec = 0.0; @@ -2584,7 +2322,8 @@ int VCS_SOLVE::vcs_basopt(const bool doJustComponents, double aw[], double sa[], if (kfound == npos || nonZeroesKspec < minNonZeroes) { kfound = kspec; } else { - // ok we are sitting pretty equal here decide on the raw ss Gibbs energy + // ok we are sitting pretty equal here + // decide on the raw ss Gibbs energy if (m_SSfeSpecies[kspec] <= m_SSfeSpecies[kfound]) { kfound = kspec; } @@ -2630,29 +2369,23 @@ int VCS_SOLVE::vcs_basopt(const bool doJustComponents, double aw[], double sa[], } goto L_END_LOOP; } - /* - * Assign a small negative number to the component that we have - * just found, in order to take it out of further consideration. - */ + + // Assign a small negative number to the component that we have just + // found, in order to take it out of further consideration. aw[k] = test; - /* *********************************************************** */ - /* **** CHECK LINEAR INDEPENDENCE WITH PREVIOUS SPECIES ****** */ - /* *********************************************************** */ - /* - * Modified Gram-Schmidt Method, p. 202 Dalquist - * QR factorization of a matrix without row pivoting. - */ + + // CHECK LINEAR INDEPENDENCE WITH PREVIOUS SPECIES + // + // Modified Gram-Schmidt Method, p. 202 Dalquist + // QR factorization of a matrix without row pivoting. size_t jl = jr; for (size_t j = 0; j < m_numElemConstraints; ++j) { sm[j + jr*m_numElemConstraints] = m_formulaMatrix(k,j); } 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 < m_numElemConstraints; ++i) { @@ -2660,34 +2393,29 @@ int VCS_SOLVE::vcs_basopt(const bool doJustComponents, double aw[], double 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 < m_numElemConstraints; ++l) { sm[l + jr*m_numElemConstraints] -= ss[j] * sm[l + j*m_numElemConstraints]; } } } - /* - * 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 < m_numElemConstraints; ++ml) { sa[jr] += pow(sm[ml + jr*m_numElemConstraints], 2); } - /* **************************************************** */ - /* **** IF NORM OF NEW ROW .LT. 1E-3 REJECT ********** */ - /* **************************************************** */ + + // IF NORM OF NEW ROW .LT. 1E-3 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(" --- %-12.12s", m_speciesName[k]); @@ -2715,7 +2443,7 @@ int VCS_SOLVE::vcs_basopt(const bool doJustComponents, double aw[], double sa[], } plogf(" as component %3d\n", jr); } - /* - entry point from up above */ +// entry point from up above L_END_LOOP: ; // If we haven't found enough components, go back and find some more. @@ -2725,40 +2453,33 @@ L_END_LOOP: if (doJustComponents) { goto L_CLEANUP; } - /* ****************************************************** */ - /* **** EVALUATE THE STOICHIOMETRY ********************** */ - /* ****************************************************** */ - /* - * Formulate the matrix problem for the stoichiometric - * coefficients. CX + B = 0 - * C will be an nc x nc matrix made up of the formula - * vectors for the components. - * n RHS's will be solved for. Thus, B is an nc x n - * matrix. - * - * BIG PROBLEM 1/21/99: - * - * This algorithm makes the assumption that the - * first nc rows of the formula matrix aren't rank deficient. - * However, this might not be the case. For example, assume - * that the first element in m_formulaMatrix[] is argon. Assume that - * no species in the matrix problem actually includes argon. - * Then, the first row in sm[], below will be identically - * zero. bleh. - * What needs to be done is to perform a rearrangement - * of the ELEMENTS -> i.e. rearrange, m_formulaMatrix, sp, - * and m_elemAbundancesGoal, such - * that the first nc elements form in combination with the - * nc components create an invertible sm[]. not a small - * project, but very doable. - * An alternative would be to turn the matrix problem - * below into an ne x nc problem, and do QR elimination instead - * of Gauss-Jordan elimination. - * Note the rearrangement of elements need only be done once - * in the problem. It's actually very similar to the top of - * this program with ne being the species and nc being the - * elements!! - */ + + // EVALUATE THE STOICHIOMETRY + // + // Formulate the matrix problem for the stoichiometric + // coefficients. CX + B = 0 + // + // C will be an nc x nc matrix made up of the formula vectors for the + // components. n RHS's will be solved for. Thus, B is an nc x n matrix. + // + // BIG PROBLEM 1/21/99: + // + // This algorithm makes the assumption that the first nc rows of the formula + // matrix aren't rank deficient. However, this might not be the case. For + // example, assume that the first element in m_formulaMatrix[] is argon. + // Assume that no species in the matrix problem actually includes argon. + // Then, the first row in sm[], below will be identically zero. bleh. + // + // What needs to be done is to perform a rearrangement of the ELEMENTS -> + // i.e. rearrange, m_formulaMatrix, sp, and m_elemAbundancesGoal, such that + // the first nc elements form in combination with the nc components create + // an invertible sm[]. not a small project, but very doable. + // + // An alternative would be to turn the matrix problem below into an ne x nc + // problem, and do QR elimination instead of Gauss-Jordan elimination. Note + // the rearrangement of elements need only be done once in the problem. It's + // actually very similar to the top of this program with ne being the + // species and nc being the elements!! for (size_t j = 0; j < ncTrial; ++j) { for (size_t i = 0; i < ncTrial; ++i) { sm[i + j*m_numElemConstraints] = m_formulaMatrix(j,i); @@ -2780,11 +2501,8 @@ L_END_LOOP: ct_dgetrs(ctlapack::NoTranspose, ncTrial, m_numRxnTot, sm, m_numElemConstraints, &ipiv[0], m_stoichCoeffRxnMatrix.ptrColumn(0), m_numElemConstraints, info); - /* - * NOW, if we have interfacial voltage unknowns, what we did - * was just wrong -> hopefully it didn't blow up. Redo the problem. - * Search for inactive E - */ + // NOW, if we have interfacial voltage unknowns, what we did was just wrong + // -> hopefully it didn't blow up. Redo the problem. Search for inactive E juse = npos; jlose = npos; for (size_t j = 0; j < m_numElemConstraints; j++) { @@ -2833,9 +2551,7 @@ L_END_LOOP: } } - /* - * Calculate the szTmp array for each formation reaction - */ + // Calculate the szTmp array for each formation reaction for (size_t i = 0; i < m_numRxnTot; i++) { double szTmp = 0.0; for (size_t j = 0; j < ncTrial; j++) { @@ -2876,10 +2592,8 @@ L_END_LOOP: plogf("\n"); } - /* - * Manual check on the satisfaction of the reaction matrix's ability - * to conserve elements - */ + // Manual check on the satisfaction of the reaction matrix's ability to + // conserve elements double sumMax = -1.0; size_t iMax = npos; size_t jMax = npos; @@ -2926,24 +2640,19 @@ L_END_LOOP: } plogf("\n"); } - /* **************************************************** */ - /* **** EVALUATE DELTA N VALUES *********************** */ - /* **************************************************** */ - /* - * Evaluate the change in gas and liquid total moles - * due to reaction vectors, DNG and DNL. - */ - /* - * Zero out the change of Phase Moles array - */ + // EVALUATE DELTA N VALUES + // + // Evaluate the change in gas and liquid total moles due to reaction + // vectors, DNG and DNL. + + // Zero out the change of Phase Moles array m_deltaMolNumPhase.zero(); m_phaseParticipation.zero(); - /* - * Loop over each reaction, creating the change in Phase Moles - * array, m_deltaMolNumPhase(iphase,irxn), - * and the phase participation array, PhaseParticipation[irxn][iphase] - */ + + // Loop over each reaction, creating the change in Phase Moles array, + // m_deltaMolNumPhase(iphase,irxn), and the phase participation array, + // PhaseParticipation[irxn][iphase] for (size_t irxn = 0; irxn < m_numRxnTot; ++irxn) { scrxn_ptr = m_stoichCoeffRxnMatrix.ptrColumn(irxn); size_t kspec = m_indexRxnToSpecies[irxn]; @@ -2972,21 +2681,19 @@ L_CLEANUP: size_t VCS_SOLVE::vcs_basisOptMax(const double* const molNum, const size_t j, const size_t n) { - /* - * The factors of 1.01 and 1.001 are placed in this routine for a purpose. - * The purpose is to ensure that roundoff errors don't influence major - * decisions. This means that the optimized and non-optimized versions of - * the code remain close to each other. - * - * (we try to avoid the logic: a = b - * if (a > b) { do this } - * else { do something else } - * because roundoff error makes a difference in the inequality evaluation) - * - * Mole numbers are frequently equal to each other in equilibrium problems - * due to constraints. Swaps are only done if there are a 1% difference in - * the mole numbers. Of course this logic isn't foolproof. - */ + // The factors of 1.01 and 1.001 are placed in this routine for a purpose. + // The purpose is to ensure that roundoff errors don't influence major + // decisions. This means that the optimized and non-optimized versions of + // the code remain close to each other. + // + // (we try to avoid the logic: a = b + // if (a > b) { do this } + // else { do something else } + // because roundoff error makes a difference in the inequality evaluation) + // + // Mole numbers are frequently equal to each other in equilibrium problems + // due to constraints. Swaps are only done if there are a 1% difference in + // the mole numbers. Of course this logic isn't foolproof. size_t largest = j; double big = molNum[j] * m_spSize[j] * 1.01; if (m_spSize[j] <= 0.0) { @@ -3024,7 +2731,7 @@ size_t VCS_SOLVE::vcs_basisOptMax(const double* const molNum, const size_t j, int VCS_SOLVE::vcs_species_type(const size_t kspec) const { - // ---------- Treat special cases first --------------------- + // Treat special cases first if (m_speciesUnknownType[kspec] == VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) { return VCS_SPECIES_INTERFACIALVOLTAGE; } @@ -3034,17 +2741,14 @@ int VCS_SOLVE::vcs_species_type(const size_t kspec) const vcs_VolPhase* VPhase = m_VolPhaseList[iph]; int phaseExist = VPhase->exists(); - // ---------- Treat zeroed out species first ---------------- + // Treat zeroed out species first if (m_molNumSpecies_old[kspec] <= 0.0) { if (m_tPhaseMoles_old[iph] <= 0.0 && !m_SSPhase[kspec]) { return VCS_SPECIES_ZEROEDMS; } - /* - * see if the species has an element - * which is so low that species will always be zero - * - */ + // see if the species has an element which is so low that species will + // always be zero for (size_t j = 0; j < m_numElemConstraints; ++j) { int elType = m_elType[j]; if (elType == VCS_ELEM_TYPE_ABSPOS) { @@ -3067,13 +2771,10 @@ int VCS_SOLVE::vcs_species_type(const size_t kspec) const } } - /* - * The Gibbs free energy for this species is such that - * it will pop back into existence. - * -> An exception to this is if a needed regular element - * is also zeroed out. Then, don't pop the phase or the species back into - * existence. - */ + // The Gibbs free energy for this species is such that it will pop back + // into existence. An exception to this is if a needed regular element + // is also zeroed out. Then, don't pop the phase or the species back + // into existence. if (irxn >= 0) { for (size_t j = 0; j < m_numComponents; ++j) { double stoicC = m_stoichCoeffRxnMatrix(j,irxn); @@ -3114,9 +2815,7 @@ int VCS_SOLVE::vcs_species_type(const size_t kspec) const } if (irxn >= 0 && m_deltaGRxn_old[irxn] >= 0.0) { - /* - * We are here when the species is or should remain zeroed out - */ + // We are here when the species is or should remain zeroed out if (m_SSPhase[kspec]) { return VCS_SPECIES_ZEROEDSS; } else { @@ -3129,9 +2828,8 @@ int VCS_SOLVE::vcs_species_type(const size_t kspec) const } } } - /* - * If the current phase already exists, - */ + + // If the current phase already exists, if (m_tPhaseMoles_old[iph] > 0.0) { if (m_SSPhase[kspec]) { return VCS_SPECIES_MAJOR; @@ -3140,15 +2838,10 @@ int VCS_SOLVE::vcs_species_type(const size_t kspec) const } } - /* - * The Gibbs free energy for this species is such that - * it will pop back into existence. - * - * -> Set it to a major species in anticipation. - * -> note, if we had an estimate for the emerging mole - * fraction of the species in the phase, we could do - * better here. - */ + // The Gibbs free energy for this species is such that it will pop back + // into existence. Set it to a major species in anticipation. Note, if + // we had an estimate for the emerging mole fraction of the species in + // the phase, we could do better here. if (m_tPhaseMoles_old[iph] <= 0.0) { if (m_SSPhase[kspec]) { return VCS_SPECIES_MAJOR; @@ -3158,35 +2851,28 @@ int VCS_SOLVE::vcs_species_type(const size_t kspec) const } } - // ---------- Treat species with non-zero mole numbers next ------------ + // Treat species with non-zero mole numbers next - /* - * Always treat species in single species phases as majors if the - * phase exists. - */ + // Always treat species in single species phases as majors if the phase + // exists. if (m_SSPhase[kspec]) { return VCS_SPECIES_MAJOR; } - /* - * Check to see whether the current species is a major component - * of its phase. If it is, it is a major component. This is consistent - * with the above rule about single species phases. A major component - * (i.e., a species with a high mole fraction) - * in any phase is always treated as a major species - */ + // Check to see whether the current species is a major component of its + // phase. If it is, it is a major component. This is consistent with the + // above rule about single species phases. A major component i.e., a species + // with a high mole fraction) in any phase is always treated as a major + // species if (m_molNumSpecies_old[kspec] > (m_tPhaseMoles_old[iph] * 0.001)) { return VCS_SPECIES_MAJOR; } - /* - * Main check in the loop: - * Check to see if there is a component with a mole number that is - * within a factor of 100 of the current species. - * If there is and that component is not part of a single species - * phase and shares a non-zero stoichiometric coefficient, then - * the current species is a major species. - */ + // Main check in the loop: Check to see if there is a component with a mole + // number that is within a factor of 100 of the current species. If there is + // and that component is not part of a single species phase and shares a + // non-zero stoichiometric coefficient, then the current species is a major + // species. if (irxn < 0) { return VCS_SPECIES_MAJOR; } else { @@ -3296,10 +2982,9 @@ void VCS_SOLVE::vcs_dfe(const int stateCalc, } double* tlogMoles = &m_TmpPhase[0]; - /* - * Might as well recalculate the phase mole vector - * and compare to the stored one. They should be correct. - */ + + // Might as well recalculate the phase mole vector and compare to the stored + // one. They should be correct. double* tPhInertMoles = &TPhInertMoles[0]; for (size_t iph = 0; iph < m_numPhases; iph++) { tlogMoles[iph] = tPhInertMoles[iph]; @@ -3333,11 +3018,9 @@ void VCS_SOLVE::vcs_dfe(const int stateCalc, l2 = ltop; } - /* - * Calculate activity coefficients for all phases that are - * not current. Here we also trigger an update check for each - * VolPhase to see if its mole numbers are current with vcs - */ + // Calculate activity coefficients for all phases that are not current. Here + // we also trigger an update check for each VolPhase to see if its mole + // numbers are current with vcs for (size_t iphase = 0; iphase < m_numPhases; iphase++) { vcs_VolPhase* Vphase = m_VolPhaseList[iphase]; Vphase->updateFromVCS_MoleNumbers(stateCalc); @@ -3346,15 +3029,13 @@ void VCS_SOLVE::vcs_dfe(const int stateCalc, } m_phasePhi[iphase] = Vphase->electricPotential(); } - /* ************************************************************** */ - /* **** ALL SPECIES, OR COMPONENTS ****************************** */ - /* ************************************************************** */ - /* - * Do all of the species when LL = 0. Then we are done for the routine - * When LL ne 0., just do the initial components. We will then - * finish up below with loops over either the major noncomponent - * species or the minor noncomponent species. - */ + + // ALL SPECIES, OR COMPONENTS + // + // Do all of the species when LL = 0. Then we are done for the routine When + // LL ne 0., just do the initial components. We will then finish up below + // with loops over either the major noncomponent species or the minor + // noncomponent species. for (size_t kspec = l1; kspec < l2; ++kspec) { size_t iphase = m_phaseID[kspec]; if (m_speciesUnknownType[kspec] == VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) { @@ -3393,10 +3074,9 @@ void VCS_SOLVE::vcs_dfe(const int stateCalc, } } } - /* ************************************************ */ - /* **** MAJORS ONLY ******************************* */ - /* ************************************************ */ + if (ll < 0) { + // MAJORS ONLY for (size_t irxn = 0; irxn < m_numRxnRdc; ++irxn) { size_t kspec = m_indexRxnToSpecies[irxn]; if (m_speciesStatus[kspec] != VCS_SPECIES_MINOR) { @@ -3438,10 +3118,8 @@ void VCS_SOLVE::vcs_dfe(const int stateCalc, } } } - /* ************************************************ */ - /* **** MINORS ONLY ******************************* */ - /* ************************************************ */ } else if (ll > 0) { + // MINORS ONLY for (size_t irxn = 0; irxn < m_numRxnRdc; ++irxn) { size_t kspec = m_indexRxnToSpecies[irxn]; if (m_speciesStatus[kspec] == VCS_SPECIES_MINOR) { @@ -3791,10 +3469,9 @@ void VCS_SOLVE::vcs_deltag(const int l, const bool doDeleted, plogf("minor noncomponents\n"); } } - /* ************************************************* */ - /* **** MAJORS and ZEROED SPECIES ONLY ************* */ - /* ************************************************* */ + if (l < 0) { + // MAJORS and ZEROED SPECIES ONLY for (size_t irxn = 0; irxn < m_numRxnRdc; ++irxn) { size_t kspec = irxn + m_numComponents; if (m_speciesStatus[kspec] != VCS_SPECIES_MINOR) { @@ -3813,9 +3490,7 @@ void VCS_SOLVE::vcs_deltag(const int l, const bool doDeleted, } } } else if (l == 0) { - /* ************************************************* */ - /* **** ALL REACTIONS ****************************** */ - /* ************************************************* */ + // ALL REACTIONS for (size_t irxn = 0; irxn < irxnl; ++irxn) { icase = 0; deltaGRxn[irxn] = feSpecies[m_indexRxnToSpecies[irxn]]; @@ -3832,9 +3507,7 @@ void VCS_SOLVE::vcs_deltag(const int l, const bool doDeleted, } } } else { - /* ************************************************* */ - /* **** MINORS AND ZEROED SPECIES ****************** */ - /* ************************************************* */ + // MINORS AND ZEROED SPECIES for (size_t irxn = 0; irxn < m_numRxnRdc; ++irxn) { size_t kspec = irxn + m_numComponents; if (m_speciesStatus[kspec] <= VCS_SPECIES_MINOR) { @@ -3854,48 +3527,46 @@ void VCS_SOLVE::vcs_deltag(const int l, const bool doDeleted, } } } - /* ************************************************* */ + /* **** MULTISPECIES PHASES WITH ZERO MOLES ******** */ - /* ************************************************* */ - /* - * Massage the free energies for species with zero mole fractions - * in multispecies phases. This section implements the - * Equation 3.8-5 in Smith and Missen, p.59. - * A multispecies phase will exist iff - * 1 < sum_i(exp(-dg_i)/AC_i) - * If DG is negative then that species wants to be reintroduced into - * the calculation. - * For small dg_i, the expression below becomes: - * 1 - sum_i(exp(-dg_i)/AC_i) ~ sum_i((dg_i-1)/AC_i) + 1 - * - * So, what we are doing here is equalizing all DG's in a multispecies - * phase whose total mole number has already been zeroed out. - * It must have to do with the case where a complete multispecies - * phase is currently zeroed out. In that case, when one species - * in that phase has a negative DG, then the phase should kick in. - * This code section will cause that to happen, because a negative - * DG will dominate the calculation of SDEL. Then, DG(I) for all - * species in that phase will be forced to be equal and negative. - * Thus, all species in that phase will come into being at the - * same time. - * - * HKM -> The ratio of mole fractions at the reinstatement - * time should be equal to the normalized weighting - * of exp(-dg_i) / AC_i. This should be implemented. - * - * HKM -> There is circular logic here. ActCoeff depends on the - * mole fractions of a phase that does not exist. In actuality - * the proto-mole fractions should be selected from the - * solution of a nonlinear problem with NsPhase unknowns - * - * X_i = exp(-dg[irxn]) / ActCoeff_i / denom - * - * where - * denom = sum_i[ exp(-dg[irxn]) / ActCoeff_i ] - * - * This can probably be solved by successive iteration. - * This should be implemented. - */ + // + // Massage the free energies for species with zero mole fractions in + // multispecies phases. This section implements the Equation 3.8-5 in Smith + // and Missen, p.59. A multispecies phase will exist iff + // + // 1 < sum_i(exp(-dg_i)/AC_i) + // + // If DG is negative then that species wants to be reintroduced into the + // calculation. For small dg_i, the expression below becomes: + // + // 1 - sum_i(exp(-dg_i)/AC_i) ~ sum_i((dg_i-1)/AC_i) + 1 + // + // So, what we are doing here is equalizing all DG's in a multispecies phase + // whose total mole number has already been zeroed out. It must have to do + // with the case where a complete multispecies phase is currently zeroed + // out. In that case, when one species in that phase has a negative DG, then + // the phase should kick in. This code section will cause that to happen, + // because a negative DG will dominate the calculation of SDEL. Then, DG(I) + // for all species in that phase will be forced to be equal and negative. + // Thus, all species in that phase will come into being at the same time. + // + // HKM -> The ratio of mole fractions at the reinstatement time should be + // equal to the normalized weighting of exp(-dg_i) / AC_i. This should be + // implemented. + // + // HKM -> There is circular logic here. ActCoeff depends on the mole + // fractions of a phase that does not exist. In actuality the proto-mole + // fractions should be selected from the solution of a nonlinear problem + // with NsPhase unknowns + // + // X_i = exp(-dg[irxn]) / ActCoeff_i / denom + // + // where + // + // denom = sum_i[ exp(-dg[irxn]) / ActCoeff_i ] + // + // This can probably be solved by successive iteration. This should be + // implemented. if (alterZeroedPhases && false) { for (size_t iph = 0; iph < m_numPhases; iph++) { bool lneed = false; @@ -3927,11 +3598,11 @@ void VCS_SOLVE::vcs_deltag(const int l, const bool doDeleted, poly += exp(-deltaGRxn[irxn])/actCoeffSpecies[kspec]; } } - /* - * Calculate deltaGRxn[] for each species in a zeroed multispecies phase. - * All of the m_deltaGRxn_new[]'s will be equal. If deltaGRxn[] is - * negative, then the phase will come back into existence. - */ + + // Calculate deltaGRxn[] for each species in a zeroed + // multispecies phase. All of the m_deltaGRxn_new[]'s will be + // equal. If deltaGRxn[] is negative, then the phase will come + // back into existence. for (size_t k = 0; k < Vphase->nSpecies(); k++) { size_t kspec = Vphase->spGlobalIndexVCS(k); if (kspec >= m_numComponents) { @@ -4099,10 +3770,8 @@ void VCS_SOLVE::vcs_deltag_Phase(const size_t iphase, const bool doDeleted, iphase); } - /* - * Single species Phase - */ if (vPhase->m_singleSpecies) { + // Single species Phase size_t kspec = vPhase->spGlobalIndexVCS(0); AssertThrowMsg(iphase == m_phaseID[kspec], "VCS_SOLVE::vcs_deltag_Phase", "index error"); @@ -4114,9 +3783,7 @@ void VCS_SOLVE::vcs_deltag_Phase(const size_t iphase, const bool doDeleted, } } } else { - /* - * Multispecies Phase - */ + // Multispecies Phase bool zeroedPhase = true; for (size_t irxn = 0; irxn < irxnl; ++irxn) { size_t kspec = m_indexRxnToSpecies[irxn]; @@ -4131,44 +3798,40 @@ void VCS_SOLVE::vcs_deltag_Phase(const size_t iphase, const bool doDeleted, } } - /* - * special section for zeroed phases - */ - /* ************************************************* */ - /* **** MULTISPECIES PHASES WITH ZERO MOLES************ */ - /* ************************************************* */ - /* - * Massage the free energies for species with zero mole fractions - * in multispecies phases. This section implements the - * Equation 3.8-5 in Smith and Missen, p.59. - * A multispecies phase will exist iff - * 1 < sum_i(exp(-dg_i)/AC_i) - * If DG is negative then that species wants to be reintroduced into - * the calculation. - * For small dg_i, the expression below becomes: - * 1 - sum_i(exp(-dg_i)/AC_i) ~ sum_i((dg_i-1)/AC_i) + 1 - * - * HKM -> The ratio of mole fractions at the reinstatement - * time should be equal to the normalized weighting - * of exp(-dg_i) / AC_i. This should be implemented. - * - * HKM -> There is circular logic here. ActCoeff depends on the - * mole fractions of a phase that does not exist. In actuality - * the proto-mole fractions should be selected from the - * solution of a nonlinear problem with NsPhase unknowns - * - * X_i = exp(-dg[irxn]) / ActCoeff_i / denom - * - * where - * denom = sum_i[ exp(-dg[irxn]) / ActCoeff_i ] - * - * This can probably be solved by successive iteration. - * This should be implemented. - * - * Calculate dg[] for each species in a zeroed multispecies phase. - * All of the dg[]'s will be equal. If dg[] is negative, then - * the phase will come back into existence. - */ + // MULTISPECIES PHASES WITH ZERO MOLES + // + // Massage the free energies for species with zero mole fractions in + // multispecies phases. This section implements the Equation 3.8-5 in + // Smith and Missen, p.59. A multispecies phase will exist iff + // + // 1 < sum_i(exp(-dg_i)/AC_i) + // + // If DG is negative then that species wants to be reintroduced into the + // calculation. For small dg_i, the expression below becomes: + // + // 1 - sum_i(exp(-dg_i)/AC_i) ~ sum_i((dg_i-1)/AC_i) + 1 + // + // HKM -> The ratio of mole fractions at the reinstatement time should + // be equal to the normalized weighting of exp(-dg_i) / AC_i. This + // should be implemented. + // + // HKM -> There is circular logic here. ActCoeff depends on the mole + // fractions of a phase that does not exist. In actuality the proto-mole + // fractions should be selected from the solution of a nonlinear problem + // with NsPhase unknowns + // + // X_i = exp(-dg[irxn]) / ActCoeff_i / denom + // + // where + // + // denom = sum_i[ exp(-dg[irxn]) / ActCoeff_i ] + // + // This can probably be solved by successive iteration. This should be + // implemented. + // + // Calculate dg[] for each species in a zeroed multispecies phase. All + // of the dg[]'s will be equal. If dg[] is negative, then the phase will + // come back into existence. if (alterZeroedPhases && zeroedPhase) { double phaseDG = 1.0; for (size_t irxn = 0; irxn < irxnl; ++irxn) { @@ -4178,9 +3841,8 @@ void VCS_SOLVE::vcs_deltag_Phase(const size_t iphase, const bool doDeleted, phaseDG -= exp(-deltaGRxn[irxn])/actCoeffSpecies[kspec]; } } - /* - * Overwrite the individual dg's with the phase DG. - */ + + // Overwrite the individual dg's with the phase DG. for (size_t irxn = 0; irxn < irxnl; ++irxn) { size_t kspec = m_indexRxnToSpecies[irxn]; if (m_phaseID[kspec] == iphase) { @@ -4201,9 +3863,8 @@ void VCS_SOLVE::vcs_switch_pos(const bool ifunc, const size_t k1, const size_t k plogf("vcs_switch_pos: ifunc = 0: inappropriate args: %d %d\n", k1, k2); } - /* - * Handle the index pointer in the phase structures first - */ + + // Handle the index pointer in the phase structures first vcs_VolPhase* pv1 = m_VolPhaseList[m_phaseID[k1]]; vcs_VolPhase* pv2 = m_VolPhaseList[m_phaseID[k2]]; size_t kp1 = m_speciesLocalPhaseIndex[k1]; @@ -4248,13 +3909,10 @@ void VCS_SOLVE::vcs_switch_pos(const bool ifunc, const size_t k1, const size_t k } } std::swap(m_speciesStatus[k1], m_speciesStatus[k2]); - /* - * Handle the index pointer in the phase structures - */ + + // Handle the index pointer in the phase structures if (ifunc) { - /* - * Find the Rxn indices corresponding to the two species - */ + // Find the Rxn indices corresponding to the two species size_t i1 = k1 - m_numComponents; size_t i2 = k2 - m_numComponents; if (DEBUG_MODE_ENABLED && (i1 > m_numRxnTot || i2 >= m_numRxnTot)) { @@ -4291,31 +3949,21 @@ double VCS_SOLVE::vcs_birthGuess(const int kspec) "VCS_SOLVE::vcs_birthGuess", "we shouldn't be here"); int ss = m_SSPhase[kspec]; if (!ss) { - /* - * Logic to handle species in multiple species phases - * we cap the moles here at 1.0E-15 kmol. - */ + // Logic to handle species in multiple species phases. We cap the moles + // here at 1.0E-15 kmol. bool soldel_ret; double dxm = vcs_minor_alt_calc(kspec, irxn, &soldel_ret); dx = std::min(w_kspec + dxm, 1e-15); } else { - /* - * Logic to handle single species phases - * There is no real way to estimate the moles. So - * we set it to a small number. - */ + // Logic to handle single species phases. There is no real way to + // estimate the moles. So we set it to a small number. dx = 1.0E-30; } - /* - * Check to see if the current value of the components - * allow the dx just estimated. - * If we are in danger of zeroing a component, - * only go 1/3 the way to zeroing the component with - * this dx. Note, this may mean that dx= 0 coming - * back from this routine. This evaluation should - * be respected. - */ + // Check to see if the current value of the components allow the dx just + // estimated. If we are in danger of zeroing a component, only go 1/3 the + // way to zeroing the component with this dx. Note, this may mean that dx= 0 + // coming back from this routine. This evaluation should be respected. double* sc_irxn = m_stoichCoeffRxnMatrix.ptrColumn(irxn); for (size_t j = 0; j < m_numComponents; ++j) { // Only loop over element constraints that involve positive def. constraints diff --git a/src/equil/vcs_solve_phaseStability.cpp b/src/equil/vcs_solve_phaseStability.cpp index 025779d87..4f47db49a 100644 --- a/src/equil/vcs_solve_phaseStability.cpp +++ b/src/equil/vcs_solve_phaseStability.cpp @@ -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; } diff --git a/src/equil/vcs_species_thermo.cpp b/src/equil/vcs_species_thermo.cpp index d77dc004c..a0f82fe62 100644 --- a/src/equil/vcs_species_thermo.cpp +++ b/src/equil/vcs_species_thermo.cpp @@ -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; diff --git a/src/equil/vcs_util.cpp b/src/equil/vcs_util.cpp index 99bdb9e64..b88a579c9 100644 --- a/src/equil/vcs_util.cpp +++ b/src/equil/vcs_util.cpp @@ -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);