28 for (
int j = 0; j < 82; j++) {
32 plogf(
" --- Subroutine vcs_RxnStepSizes called - Details:\n");
34 for (
int j = 0; j < 82; j++) {
38 plogf(
" --- Species KMoles Rxn_Adjustment DeltaG"
56 if (DEBUG_MODE_ENABLED) {
57 sprintf(ANOTE,
"Normal Calc");
64 if (DEBUG_MODE_ENABLED) {
65 sprintf(ANOTE,
"ZeroedPhase: Phase is artificially zeroed");
90 if (DEBUG_MODE_ENABLED) {
91 sprintf(ANOTE,
"MultSpec (%s): Species not born due to STOICH/PHASEPOP even though DG = %11.3E",
96 if (DEBUG_MODE_ENABLED) {
97 sprintf(ANOTE,
"MultSpec (%s): small species born again DG = %11.3E",
102 if (DEBUG_MODE_ENABLED) {
103 sprintf(ANOTE,
"MultSpec (%s):still dead, no phase pop, even though DG = %11.3E",
107 if (Vphase->
exists() > 0 && trphmoles > 0.0) {
109 if (DEBUG_MODE_ENABLED) {
111 "MultSpec (%s): birthed species because it was zero in a small existing phase with DG = %11.3E",
118 if (DEBUG_MODE_ENABLED) {
137 if (DEBUG_MODE_ENABLED) {
138 sprintf(ANOTE,
"Skipped: superconverged DG = %11.3E",
m_deltaGRxn_new[irxn]);
141 plogf(
" %12.4E %12.4E %12.4E | %s\n",
153 if (DEBUG_MODE_ENABLED) {
157 plogf(
" %12.4E %12.4E %12.4E | %s\n",
197 if (DEBUG_MODE_ENABLED && s_old != s) {
198 sprintf(ANOTE,
"Normal calc: diag adjusted from %g "
199 "to %g due to act coeff", s_old, s);
211 if (DEBUG_MODE_ENABLED) {
212 sprintf(ANOTE,
"Delta damped from %g "
213 "to %g due to component %lu (%10s) going neg", m_deltaMolNumSpecies[kspec],
218 if (DEBUG_MODE_ENABLED) {
219 sprintf(ANOTE,
"Delta damped from %g "
220 "to %g due to component %lu (%10s) zero", m_deltaMolNumSpecies[kspec],
223 m_deltaMolNumSpecies[kspec] = 0.0;
230 if (DEBUG_MODE_ENABLED) {
231 sprintf(ANOTE,
"Delta damped from %g "
287 if ((k == kspec) && (
m_SSPhase[kspec] != 1)) {
294 if (DEBUG_MODE_ENABLED) {
301 plogf(
" %12.4E %12.4E %12.4E | %s\n",
321 if (DEBUG_MODE_ENABLED) {
323 sprintf(ANOTE,
"Delete component SS phase %lu named %s - SS phases only", iphDel,
326 sprintf(ANOTE,
"Delete this SS phase %lu - SS components only", iphDel);
330 plogf(
" %12.4E %12.4E %12.4E | %s\n",
333 plogf(
" --- vcs_RxnStepSizes Special section to set up to delete %s",
339 forceComponentCalc = 1;
341 plogf(
" --- Force a component recalculation \n");
355 plogf(
" %12.4E %12.4E %12.4E | %s\n",
374 for (
size_t j = 0; j < 77; j++) {
377 plogf(
"\n --- Subroutine rxn_adj_cg() called\n");
378 plogf(
" --- Species Moles Rxn_Adjustment | Comment\n");
389 for (
size_t irxn = 0; irxn <
m_numRxnRdc; ++irxn) {
390 if (DEBUG_MODE_ENABLED) {
391 sprintf(ANOTE,
"Normal Calc");
404 if (DEBUG_MODE_ENABLED) {
405 sprintf(ANOTE,
"MultSpec: come alive DG = %11.3E",
m_deltaGRxn_new[irxn]);
411 if (DEBUG_MODE_ENABLED) {
412 sprintf(ANOTE,
"MultSpec: still dead DG = %11.3E",
m_deltaGRxn_new[irxn]);
428 if (DEBUG_MODE_ENABLED) {
429 sprintf(ANOTE,
"Skipped: converged DG = %11.3E\n",
m_deltaGRxn_new[irxn]);
442 if (DEBUG_MODE_ENABLED) {
530 if (DEBUG_MODE_ENABLED) {
531 plogf(
" --- vcs_st2 Special section to delete ");
533 plogf(
"\n --- Immediate return - Restart iteration\n");
549 if (DEBUG_MODE_ENABLED) {
566 if (DEBUG_MODE_ENABLED) {
568 for (
size_t j = 0; j < 77; j++) {
578 double diag = hessianDiag_Ideal;
580 if (hessianDiag_Ideal <= 0.0) {
582 "We shouldn't be here");
584 if (hessActCoef >= 0.0) {
586 }
else if (fabs(hessActCoef) < 0.6666 * hessianDiag_Ideal) {
589 diag -= 0.6666 * hessianDiag_Ideal;
632 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
656 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
661 double deltaG = mu_i[kspec];
672 const int MAXITS = 10;
683 double forig = fabs(deltaGOrig) + 1.0E-15;
684 if (deltaGOrig > 0.0) {
687 if (DEBUG_MODE_ENABLED && ANOTE) {
688 sprintf(ANOTE,
"Rxn reduced to zero step size in line search: dx>0 dg > 0");
692 }
else if (deltaGOrig < 0.0) {
695 if (DEBUG_MODE_ENABLED && ANOTE) {
696 sprintf(ANOTE,
"Rxn reduced to zero step size in line search: dx<0 dg < 0");
700 }
else if (deltaGOrig == 0.0) {
703 if (dx_orig == 0.0) {
708 double molSum = molNumBase[kspec];
712 molSum += molNumBase[k];
724 if (deltaG1 * deltaGOrig > 0.0) {
732 if (fabs(deltaG1) < 0.8 * forig) {
733 if (deltaG1 * deltaGOrig < 0.0) {
734 double slope = (deltaG1 - deltaGOrig) / dx_orig;
735 dx = -deltaGOrig / slope;
744 for (its = 0; its < MAXITS; its++) {
762 if (deltaG * deltaGOrig > 0.0) {
769 if (fabs(deltaG) / forig < (1.0 - 0.1 * dx / dx_orig)) {
770 if (deltaG * deltaGOrig < 0.0) {
771 double slope = (deltaG - deltaGOrig) / dx;
772 dx = -deltaGOrig / slope;
782 sprintf(ANOTE,
"Rxn reduced to zero step size from %g to %g (MAXITS)", dx_orig, dx);
788 sprintf(ANOTE,
"Line Search reduced step size from %g to %g", dx_orig, dx);
size_t vcs_RxnStepSizes(int &forceComponentCalc, size_t &kSpecial)
Calculates formation reaction step sizes.
std::vector< size_t > m_phaseID
Mapping from the species number to the phase number.
double vcs_Hessian_actCoeff_diag(size_t irxn)
Calculates the diagonal contribution to the Hessian due to the dependence of the activity coefficient...
double vcs_line_search(const size_t irxn, const double dx_orig, char *const ANOTE=0)
A line search algorithm is carried out on one reaction.
double m_totalMolNum
Total number of kmoles in all phases.
bool m_singleSpecies
If true, this phase consists of a single species.
void vcs_chemPotPhase(const int stateCalc, const size_t iph, const double *const molNum, double *const ac, double *const mu_i, const bool do_deleted=false)
We calculate the dimensionless chemical potentials of all species in a single phase.
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 coefficient...
#define VCS_SPECIES_MINOR
Species is a major species.
Array2D m_stoichCoeffRxnMatrix
Stoichiometric coefficient matrix for the reaction mechanism expressed in Reduced Canonical Form...
int m_useActCoeffJac
Choice of Hessians.
const size_t npos
index returned by functions to indicate "no position"
std::vector< double > m_feSpecies_new
Dimensionless new free energy for all the species in the mechanism at the new tentatite T...
#define VCS_DATA_PTR(vvv)
Points to the data in a std::vector<> object.
std::vector< vcs_VolPhase * > m_VolPhaseList
Array of Phase Structures. Length = number of phases.
doublereal * ptrColumn(size_t j)
Return a pointer to the top of column j, columns are contiguous in memory.
size_t m_numRxnRdc
Current number of non-component species in the problem.
#define VCS_SMALL_MULTIPHASE_SPECIES
Relative value of multiphase species mole number for a multiphase species which is small...
std::vector< double > m_molNumSpecies_old
Total moles of the species.
void setMolesFromVCS(const int stateCalc, const double *molesSpeciesVCS=0)
Set the moles within the phase.
Header file for the internal object that holds the vcs equilibrium problem (see Class VCS_SOLVE and E...
Header for the object representing each phase within vcs.
#define VCS_SPECIES_ZEROEDPHASE
Species lies in a multicomponent phase that is zeroed atm.
std::vector< double > m_actCoeffSpecies_new
Molar-based Activity Coefficients for Species.
#define VCS_DELETE_PHASE_CUTOFF
Cutoff relative moles below which a phase is deleted from the equilibrium problem.
size_t m_numSpeciesTot
Total number of species in the problems.
std::vector< int > m_speciesUnknownType
Specifies the species unknown type.
#define VCS_STATECALC_NEW
State Calculation based on the new or tentative mole numbers.
Base class for exceptions thrown by Cantera classes.
bool isIdealSoln() const
Returns whether the phase is an ideal solution phase.
std::vector< double > m_tPhaseMoles_old
Total kmols of species in each phase.
int exists() const
int indicating whether the phase exists or not
int m_debug_print_lvl
Debug printing lvl.
#define VCS_SPECIES_MAJOR
Species is a major species.
size_t m_numComponents
Number of components calculated for the problem.
std::vector< double > m_molNumSpecies_new
Tentative value of the mole number vector.
std::vector< double > m_actCoeffSpecies_old
Molar-based Activity Coefficients for Species based on old mole numbers.
int vcs_rxn_adj_cg(void)
Calculates reaction adjustments using a full Hessian approximation.
#define VCS_SPECIES_STOICHZERO
Species lies in a multicomponent phase that is active, but species concentration is zero due to stoic...
size_t m_numRxnMinorZeroed
Number of active species which are currently either treated as minor species.
std::vector< char > m_SSPhase
Boolean indicating whether a species belongs to a single-species phase.
Phase information and Phase calculations for vcs.
std::vector< std::string > m_speciesName
Species string name for the kth species.
#define VCS_STATECALC_OLD
State Calculation based on the old or base mole numbers.
Array2D m_deltaMolNumPhase
Change in the number of moles of phase, iphase, due to the noncomponent formation reaction...
#define plogendl()
define this Cantera function to replace cout << endl;
std::vector< int > m_speciesStatus
Major -Minor status vector for the species in the problem.
double deltaG_Recalc_Rxn(const int stateCalc, const size_t irxn, const double *const molNum, double *const ac, double *const mu_i)
This function recalculates the deltaG for reaction, irxn.
const char * vcs_speciesType_string(int speciesStatus, int length)
Returns a const char string representing the type of the species given by the first argument...
std::vector< double > m_deltaMolNumSpecies
Reaction Adjustments for each species during the current step.
#define plogf
define this Cantera function to replace printf
#define VCS_SPECIES_TYPE_INTERFACIALVOLTAGE
Unknown refers to the voltage level of a phase.
Array2D m_phaseParticipation
This is 1 if the phase, iphase, participates in the formation reaction irxn, and zero otherwise...
std::vector< size_t > m_indexRxnToSpecies
Mapping between the species index for noncomponent species and the full species index.
size_t m_numPhases
Number of Phases in the problem.
double m_tolmaj2
Below this, major species aren't refined any more.
Array2D m_np_dLnActCoeffdMolNum
Change in the log of the activity coefficient with respect to the mole number multiplied by the phase...
std::vector< double > m_feSpecies_old
Free energy vector from the start of the current iteration.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
std::vector< double > m_deltaGRxn_new
Delta G(irxn) for the noncomponent species in the mechanism.
void vcs_CalcLnActCoeffJac(const double *const moleSpeciesVCS)
Recalculate all of the activity coefficients in all of the phases based on input mole numbers...