15 static void printProgress(
const vector<string> &spName,
20 plogf(
" --- Summary of current progress:\n");
21 plogf(
" --- Name Moles - SSGibbs \n");
22 plogf(
" -------------------------------------------------------------------------------------\n");
23 for (
size_t k = 0; k < soln.size(); k++) {
24 plogf(
" --- %20s %12.4g - %12.4g\n", spName[k], soln[k], ff[k]);
25 sum += soln[k] * ff[k];
27 plogf(
" --- Total sum to be minimized = %g\n", sum);
30 int VCS_SOLVE::vcs_setMolesLinProg()
32 double test = -1.0E-10;
34 if (m_debug_print_lvl >= 2) {
35 plogf(
" --- call setInitialMoles\n");
38 double dxi_min = 1.0e10;
41 bool abundancesOK =
true;
42 bool usedZeroedSpecies;
49 for (
size_t ik = 0; ik < m_nsp; ik++) {
51 m_molNumSpecies_old[ik] = max(0.0, m_molNumSpecies_old[ik]);
55 if (m_debug_print_lvl >= 2) {
56 printProgress(m_speciesName, m_molNumSpecies_old, m_SSfeSpecies);
61 if (!vcs_elabcheck(0)) {
62 if (m_debug_print_lvl >= 2) {
63 plogf(
" --- seMolesLinProg Mole numbers failing element abundances\n");
64 plogf(
" --- seMolesLinProg Call vcs_elcorr to attempt fix\n");
66 retn = vcs_elcorr(&sm[0], &wx[0]);
79 retn = vcs_basopt(
false, &aw[0], &sa[0], &sm[0], &ss[0],
80 test, &usedZeroedSpecies);
85 if (m_debug_print_lvl >= 2) {
86 plogf(
"iteration %d\n", iter);
95 for (
size_t irxn = 0; irxn < m_numRxnTot; irxn++) {
97 size_t ik = m_numComponents + irxn;
98 double dg_rt = m_SSfeSpecies[ik];
100 const double* sc_irxn = m_stoichCoeffRxnMatrix.ptrColumn(irxn);
101 for (
size_t jcomp = 0; jcomp < m_nelem; jcomp++) {
102 dg_rt += m_SSfeSpecies[jcomp] * sc_irxn[jcomp];
107 int idir = (dg_rt < 0.0 ? 1 : -1);
109 dxi_min = m_molNumSpecies_old[ik];
112 for (
size_t jcomp = 0; jcomp < m_numComponents; jcomp++) {
113 double nu = sc_irxn[jcomp];
117 double delta_xi = fabs(m_molNumSpecies_old[jcomp]/nu);
120 if (!redo && delta_xi < 1.0e-10 && (m_molNumSpecies_old[ik] >= 1.0E-10)) {
121 if (m_debug_print_lvl >= 2) {
122 plogf(
" --- Component too small: %s\n", m_speciesName[jcomp]);
126 dxi_min = std::min(dxi_min, delta_xi);
133 double dsLocal = idir*dxi_min;
134 m_molNumSpecies_old[ik] += dsLocal;
135 m_molNumSpecies_old[ik] = max(0.0, m_molNumSpecies_old[ik]);
136 for (
size_t jcomp = 0; jcomp < m_numComponents; jcomp++) {
138 if (m_molNumSpecies_old[jcomp] > 1.0E-15) {
141 m_molNumSpecies_old[jcomp] += sc_irxn[jcomp] * dsLocal;
142 m_molNumSpecies_old[jcomp] = max(0.0, m_molNumSpecies_old[jcomp]);
143 if (full && m_molNumSpecies_old[jcomp] < 1.0E-60) {
149 if (m_debug_print_lvl >= 2) {
150 printProgress(m_speciesName, m_molNumSpecies_old, m_SSfeSpecies);
154 if (m_debug_print_lvl == 1) {
155 printProgress(m_speciesName, m_molNumSpecies_old, m_SSfeSpecies);
156 plogf(
" --- setInitialMoles end\n");
161 }
else if (iter > 15) {
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Namespace for the Cantera kernel.
#define VCS_SPECIES_INTERFACIALVOLTAGE
Species refers to an electron in the metal.
#define plogf
define this Cantera function to replace printf
Header file for the internal object that holds the vcs equilibrium problem (see Class VCS_SOLVE and E...