32 for (
int j = 0; j < 82; j++) {
36 plogf(
" --- Subroutine vcs_RxnStepSizes called - Details:\n");
38 for (
int j = 0; j < 82; j++) {
42 plogf(
" --- Species KMoles Rxn_Adjustment DeltaG"
59 sprintf(ANOTE,
"Normal Calc");
67 sprintf(ANOTE,
"ZeroedPhase: Phase is artificially zeroed");
96 sprintf(ANOTE,
"MultSpec (%s): Species not born due to STOICH/PHASEPOP even though DG = %11.3E",
102 sprintf(ANOTE,
"MultSpec (%s): small species born again DG = %11.3E",
108 sprintf(ANOTE,
"MultSpec (%s):still dead, no phase pop, even though DG = %11.3E",
112 if (Vphase->
exists() > 0 && trphmoles > 0.0) {
116 "MultSpec (%s): birthed species because it was zero in a small existing phase with DG = %11.3E",
143 sprintf(ANOTE,
"Skipped: superconverged DG = %11.3E",
m_deltaGRxn_new[irxn]);
146 plogf(
" %12.4E %12.4E %12.4E | %s\n",
162 plogf(
" %12.4E %12.4E %12.4E | %s\n",
203 sprintf(ANOTE,
"Normal calc: diag adjusted from %g "
204 "to %g due to act coeff", s_old, s);
218 sprintf(ANOTE,
"Delta damped from %g "
219 "to %g due to component %lu (%10s) going neg", m_deltaMolNumSpecies[kspec],
225 sprintf(ANOTE,
"Delta damped from %g "
226 "to %g due to component %lu (%10s) zero", m_deltaMolNumSpecies[kspec],
229 m_deltaMolNumSpecies[kspec] = 0.0;
237 sprintf(ANOTE,
"Delta damped from %g "
292 if ((k == kspec) && (
m_SSPhase[kspec] != 1)) {
307 plogf(
" %12.4E %12.4E %12.4E | %s\n",
330 sprintf(ANOTE,
"Delete component SS phase %lu named %s - SS phases only", iphDel,
333 sprintf(ANOTE,
"Delete this SS phase %lu - SS components only", iphDel);
337 plogf(
" %12.4E %12.4E %12.4E | %s\n",
340 plogf(
" --- vcs_RxnStepSizes Special section to set up to delete %s",
346 forceComponentCalc = 1;
349 plogf(
" --- Force a component recalculation \n");
367 plogf(
" %12.4E %12.4E %12.4E | %s\n",
390 double* dnPhase_irxn;
394 for (j = 0; j < 77; j++) {
397 plogf(
"\n --- Subroutine rxn_adj_cg() called\n");
398 plogf(
" --- Species Moles Rxn_Adjustment | Comment\n");
409 sprintf(ANOTE,
"Normal Calc");
425 (void) sprintf(ANOTE,
"MultSpec: come alive DG = %11.3E",
m_deltaGRxn_new[irxn]);
432 (void) sprintf(ANOTE,
"MultSpec: still dead DG = %11.3E",
m_deltaGRxn_new[irxn]);
449 sprintf(ANOTE,
"Skipped: converged DG = %11.3E\n",
m_deltaGRxn_new[irxn]);
548 plogf(
" --- vcs_st2 Special section to delete ");
550 plogf(
"\n --- Immediate return - Restart iteration\n");
585 for (j = 0; j < 77; j++) {
595 double diag = hessianDiag_Ideal;
597 if (hessianDiag_Ideal <= 0.0) {
598 plogf(
"vcs_Hessian_diag_adj::We shouldn't be here\n");
601 if (hessActCoef >= 0.0) {
603 }
else if (fabs(hessActCoef) < 0.6666 * hessianDiag_Ideal) {
606 diag -= 0.6666 * hessianDiag_Ideal;
613 size_t kspec, k, l, kph;
619 if (np_kspec < 1.0E-13) {
655 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
680 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
681 if (pp_ptr[iphase]) {
685 double deltaG = mu_i[kspec];
688 deltaG += sc_irxn[k] * mu_i[k];
701 size_t kspec = m_indexRxnToSpecies[irxn];
702 const int MAXITS = 10;
704 double* sc_irxn = m_stoichCoeffRxnMatrix[irxn];
715 double forig = fabs(deltaGOrig) + 1.0E-15;
716 if (deltaGOrig > 0.0) {
720 if (m_debug_print_lvl >= 2) {
723 sprintf(ANOTE,
"Rxn reduced to zero step size in line search: dx>0 dg > 0");
727 }
else if (deltaGOrig < 0.0) {
731 if (m_debug_print_lvl >= 2) {
734 sprintf(ANOTE,
"Rxn reduced to zero step size in line search: dx<0 dg < 0");
738 }
else if (deltaGOrig == 0.0) {
741 if (dx_orig == 0.0) {
745 vcs_dcopy(
VCS_DATA_PTR(m_molNumSpecies_new), molNumBase, m_numSpeciesRdc);
746 molSum = molNumBase[kspec];
747 m_molNumSpecies_new[kspec] = molNumBase[kspec] + dx_orig;
748 for (k = 0; k < m_numComponents; k++) {
749 m_molNumSpecies_new[k] = molNumBase[k] + sc_irxn[k] * dx_orig;
750 molSum += molNumBase[k];
762 if (deltaG1 * deltaGOrig > 0.0) {
770 if (fabs(deltaG1) < 0.8 * forig) {
771 if (deltaG1 * deltaGOrig < 0.0) {
772 slope = (deltaG1 - deltaGOrig) / dx_orig;
773 dx = -deltaGOrig / slope;
782 for (its = 0; its < MAXITS; its++) {
788 m_molNumSpecies_new[kspec] = molNumBase[kspec] + dx;
789 for (k = 0; k < m_numComponents; k++) {
790 m_molNumSpecies_new[k] = molNumBase[k] + sc_irxn[k] * dx;
800 if (deltaG * deltaGOrig > 0.0) {
807 if (fabs(deltaG) / forig < (1.0 - 0.1 * dx / dx_orig)) {
808 if (deltaG * deltaGOrig < 0.0) {
809 slope = (deltaG - deltaGOrig) / dx;
810 dx = -deltaGOrig / slope;
820 sprintf(ANOTE,
"Rxn reduced to zero step size from %g to %g (MAXITS)", dx_orig, dx);
826 sprintf(ANOTE,
"Line Search reduced step size from %g to %g", dx_orig, dx);
size_t m_numComponents
Number of components calculated for the problem.
IntStarStar m_phaseParticipation
This is 1 if the phase, iphase, participates in the formation reaction irxn, and zero otherwise...
#define VCS_SPECIES_MINOR
Species is a major species.
const size_t npos
index returned by functions to indicate "no position"
#define VCS_DATA_PTR(vvv)
Points to the data in a std::vector<> object.
std::vector< size_t > m_indexRxnToSpecies
Mapping between the species index for noncomponent species and the full species index.
size_t m_numRxnMinorZeroed
Number of active species which are currently either treated as minor species.
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...
int m_debug_print_lvl
Debug printing lvl.
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.
void vcs_CalcLnActCoeffJac(const double *const moleSpeciesVCS)
Recalculate all of the activity coefficients in all of the phases based on input mole numbers...
std::vector< double > m_deltaGRxn_new
Delta G(irxn) for the noncomponent species in the mechanism.
#define VCS_SMALL_MULTIPHASE_SPECIES
Relative value of multiphase species mole number for a multiphase species which is small...
double m_totalMolNum
Total number of kmoles in all phases.
double *const * baseDataAddr()
Returns a double** pointer to the base address.
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.
int m_useActCoeffJac
Choice of Hessians.
Phase information and Phase calculations for vcs.
#define VCS_SPECIES_ZEROEDPHASE
Species lies in a multicomponent phase that is zeroed atm.
bool isIdealSoln() const
Returns whether the phase is an ideal solution phase.
Internal declarations for the VCSnonideal package.
std::vector< double > m_molNumSpecies_old
Total moles of the species.
size_t m_numSpeciesTot
Total number of species in the problems.
DoubleStarStar m_deltaMolNumPhase
Change in the number of moles of phase, iphase, due to the noncomponent formation reaction...
void vcs_print_line(const char *string, int num)
Prints a line consisting of multiple occurrences of the same string.
#define VCS_DELETE_PHASE_CUTOFF
Cutoff relative moles below which a phase is deleted from the equilibrium problem.
#define VCS_STATECALC_NEW
State Calculation based on the new or tentative mole numbers.
double m_tolmaj2
Below this, major species aren't refined any more.
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.
std::vector< double > m_deltaMolNumSpecies
Reaction Adjustments for each species during the current step.
std::vector< int > m_speciesStatus
Major -Minor status vector for the species in the problem.
#define VCS_SPECIES_MAJOR
Species is a major species.
std::vector< vcs_VolPhase * > m_VolPhaseList
Array of Phase Structures. Length = number of phases.
DoubleStarStar m_np_dLnActCoeffdMolNum
Change in the log of the activity coefficient with respect to the mole number multiplied by the phase...
#define VCS_SPECIES_STOICHZERO
Species lies in a multicomponent phase that is active, but species concentration is zero due to stoic...
size_t m_numPhases
Number of Phases in the problem.
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...
std::vector< size_t > m_phaseID
Mapping from the species number to the phase number.
bool m_singleSpecies
If true, this phase consists of a single species.
#define VCS_STATECALC_OLD
State Calculation based on the old or base mole numbers.
void setMolesFromVCS(const int stateCalc, const double *molesSpeciesVCS=0)
Set the moles within the phase.
std::vector< double > m_tPhaseMoles_old
Total kmols of species in each phase.
#define plogendl()
define this Cantera function to replace cout << endl;
DoubleStarStar m_stoichCoeffRxnMatrix
Stoichiometric coefficient matrix for the reaction mechanism expressed in Reduced Canonical Form...
std::vector< char > m_SSPhase
Boolean indicating whether a species belongs to a single-species phase.
double vcs_line_search(const size_t irxn, const double dx_orig, char *const ANOTE)
A line search algorithm is carried out on one reaction.
double vcs_Hessian_actCoeff_diag(size_t irxn)
Calculates the diagonal contribution to the Hessian due to the dependence of the activity coefficient...
int exists() const
int indicating whether the phase exists or not
#define plogf
define this Cantera function to replace printf
#define VCS_SPECIES_TYPE_INTERFACIALVOLTAGE
Unknown refers to the voltage level of a phase.
size_t vcs_RxnStepSizes(int &forceComponentCalc, size_t &kSpecial)
Calculates formation reaction step sizes.
std::vector< int > m_speciesUnknownType
Specifies the species unknown type.
int vcs_rxn_adj_cg(void)
Calculates reaction adjustments using a full Hessian approximation.
size_t m_numRxnRdc
Current number of non-component species in the problem.
std::vector< std::string > m_speciesName
Species string name for the kth species.