25 for (
int j = 0; j < 82; j++) {
29 plogf(
" --- Subroutine vcs_RxnStepSizes called - Details:\n");
31 for (
int j = 0; j < 82; j++) {
35 plogf(
" --- Species KMoles Rxn_Adjustment DeltaG" 47 ANOTE =
"Normal Calc";
52 ANOTE =
"ZeroedPhase: Phase is artificially zeroed";
71 ANOTE = fmt::sprintf(
"MultSpec (%s): Species not born due to STOICH/PHASEPOP even though DG = %11.3E",
75 ANOTE = fmt::sprintf(
"MultSpec (%s): small species born again DG = %11.3E",
79 ANOTE = fmt::sprintf(
"MultSpec (%s):still dead, no phase pop, even though DG = %11.3E",
82 if (Vphase->
exists() > 0 && trphmoles > 0.0) {
84 ANOTE = fmt::sprintf(
"MultSpec (%s): birthed species because it was zero in a small existing phase with DG = %11.3E",
89 ANOTE = fmt::sprintf(
"MultSpec (%s): still dead DG = %11.3E",
100 ANOTE = fmt::sprintf(
"Skipped: superconverged DG = %11.3E",
m_deltaGRxn_new[irxn]);
103 plogf(
" %12.4E %12.4E %12.4E | %s\n",
113 ANOTE = fmt::sprintf(
"Skipped: IC = %3d and DG >0: %11.3E",
117 plogf(
" %12.4E %12.4E %12.4E | %s\n",
149 ANOTE = fmt::sprintf(
"Normal calc: diag adjusted from %g " 150 "to %g due to act coeff", s_old, s);
161 ANOTE = fmt::sprintf(
"Delta damped from %g " 166 ANOTE = fmt::sprintf(
"Delta damped from %g " 177 ANOTE = fmt::sprintf(
"Delta damped from %g " 225 if ((k == kspec) && (
m_SSPhase[kspec] != 1)) {
232 ANOTE = fmt::sprintf(
"Delta damped from %g to %g due to delete %s",
m_deltaMolNumSpecies[kspec],
237 plogf(
" %12.4E %12.4E %12.4E | %s\n",
257 ANOTE = fmt::sprintf(
"Delete component SS phase %d named %s - SS phases only",
260 ANOTE = fmt::sprintf(
"Delete this SS phase %d - SS components only", iphDel);
264 plogf(
" %12.4E %12.4E %12.4E | %s\n",
267 plogf(
" --- vcs_RxnStepSizes Special section to set up to delete %s",
272 forceComponentCalc = 1;
274 plogf(
" --- Force a component recalculation \n");
288 plogf(
" %12.4E %12.4E %12.4E | %s\n",
304 "Unused. To be removed after Cantera 2.3.");
308 for (
size_t j = 0; j < 77; j++) {
311 plogf(
"\n --- Subroutine rxn_adj_cg() called\n");
312 plogf(
" --- Species Moles Rxn_Adjustment | Comment\n");
317 for (
size_t irxn = 0; irxn <
m_numRxnRdc; ++irxn) {
318 sprintf(ANOTE,
"Normal Calc");
327 sprintf(ANOTE,
"MultSpec: come alive DG = %11.3E",
m_deltaGRxn_new[irxn]);
332 sprintf(ANOTE,
"MultSpec: still dead DG = %11.3E",
m_deltaGRxn_new[irxn]);
341 sprintf(ANOTE,
"Skipped: converged DG = %11.3E\n",
m_deltaGRxn_new[irxn]);
424 plogf(
" --- vcs_st2 Special section to delete ");
426 plogf(
"\n --- Immediate return - Restart iteration\n");
450 for (
size_t j = 0; j < 77; j++) {
459 double diag = hessianDiag_Ideal;
461 if (hessianDiag_Ideal <= 0.0) {
463 "We shouldn't be here");
465 if (hessActCoef >= 0.0) {
467 }
else if (fabs(hessActCoef) < 0.6666 * hessianDiag_Ideal) {
470 diag -= 0.6666 * hessianDiag_Ideal;
508 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
527 "Unused. To be removed after Cantera 2.3.");
529 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
534 double deltaG = mu_i[kspec];
544 "Unused. To be removed after Cantera 2.3.");
547 const int MAXITS = 10;
557 double forig = fabs(deltaGOrig) + 1.0E-15;
558 if (deltaGOrig > 0.0) {
562 sprintf(ANOTE,
"Rxn reduced to zero step size in line search: dx>0 dg > 0");
566 }
else if (deltaGOrig < 0.0) {
570 sprintf(ANOTE,
"Rxn reduced to zero step size in line search: dx<0 dg < 0");
574 }
else if (deltaGOrig == 0.0) {
577 if (dx_orig == 0.0) {
582 double molSum = molNumBase[kspec];
586 molSum += molNumBase[k];
596 if (deltaG1 * deltaGOrig > 0.0) {
603 if (fabs(deltaG1) < 0.8 * forig) {
604 if (deltaG1 * deltaGOrig < 0.0) {
605 double slope = (deltaG1 - deltaGOrig) / dx_orig;
606 dx = -deltaGOrig / slope;
614 for (its = 0; its < MAXITS; its++) {
629 if (deltaG * deltaGOrig > 0.0) {
635 if (fabs(deltaG) / forig < (1.0 - 0.1 * dx / dx_orig)) {
636 if (deltaG * deltaGOrig < 0.0) {
637 double slope = (deltaG - deltaGOrig) / dx;
638 dx = -deltaGOrig / slope;
647 sprintf(ANOTE,
"Rxn reduced to zero step size from %g to %g (MAXITS)", dx_orig, dx);
651 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.
bool isIdealSoln() const
Returns whether the phase is an ideal solution phase.
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.
vector_int m_speciesUnknownType
Specifies the species unknown type.
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.
vector_fp m_molNumSpecies_old
Total moles of the species.
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< vcs_VolPhase * > m_VolPhaseList
Array of Phase Structures. Length = number of phases.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
vector_fp m_feSpecies_new
Dimensionless new free energy for all the species in the mechanism at the new tentative T...
vector_fp m_deltaMolNumSpecies
Reaction Adjustments for each species during the current step.
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...
vector_fp m_deltaGRxn_new
Delta G(irxn) for the noncomponent species in the mechanism.
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.
#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.
#define VCS_STATECALC_NEW
State Calculation based on the new or tentative mole numbers.
Base class for exceptions thrown by Cantera classes.
vector_fp m_feSpecies_old
Free energy vector from the start of the current iteration.
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.
#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.
vector_fp m_tPhaseMoles_old
Total kmols of species in each phase.
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...
int exists() const
int indicating whether the phase exists or not
vector_fp m_actCoeffSpecies_new
Molar-based Activity Coefficients for Species.
#define plogendl()
define this Cantera function to replace cout << endl;
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
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.
int vcs_rxn_adj_cg()
Calculates reaction adjustments using a full Hessian approximation.
vector_int m_speciesStatus
Major -Minor status vector for the species in the problem.
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...
#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...
Namespace for the Cantera kernel.
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.
vector_fp m_molNumSpecies_new
Tentative value of the mole number vector.
Array2D m_np_dLnActCoeffdMolNum
Change in the log of the activity coefficient with respect to the mole number multiplied by the phase...
vector_fp m_actCoeffSpecies_old
Molar-based Activity Coefficients for Species based on old mole numbers.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
void vcs_CalcLnActCoeffJac(const double *const moleSpeciesVCS)
Recalculate all of the activity coefficients in all of the phases based on input mole numbers...