17 static void printProgress(
const vector<string> &spName,
18 const vector<double> &soln,
19 const vector<double> &ff)
22 plogf(
" --- Summary of current progress:\n");
23 plogf(
" --- Name Moles - SSGibbs \n");
24 plogf(
" -------------------------------------------------------------------------------------\n");
25 for (
size_t k = 0; k < soln.size(); k++) {
26 plogf(
" --- %20s %12.4g - %12.4g\n", spName[k].c_str(), soln[k], ff[k]);
27 sum += soln[k] * ff[k];
29 plogf(
" --- Total sum to be minimized = %g\n", sum);
32 int VCS_SOLVE::vcs_setMolesLinProg()
35 double test = -1.0E-10;
37 if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
38 plogf(
" --- call setInitialMoles\n");
49 double delta_xi, dxi_min = 1.0e10;
53 bool abundancesOK =
true;
54 bool usedZeroedSpecies;
56 std::vector<double> sm(m_numElemConstraints*m_numElemConstraints, 0.0);
57 std::vector<double> ss(m_numElemConstraints, 0.0);
58 std::vector<double> sa(m_numElemConstraints, 0.0);
59 std::vector<double> wx(m_numElemConstraints, 0.0);
60 std::vector<double> aw(m_numSpeciesTot, 0.0);
62 for (ik = 0; ik < m_numSpeciesTot; ik++) {
64 m_molNumSpecies_old[ik] = max(0.0, m_molNumSpecies_old[ik]);
68 if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
69 printProgress(m_speciesName, m_molNumSpecies_old, m_SSfeSpecies);
74 if (!vcs_elabcheck(0)) {
75 if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
76 plogf(
" --- seMolesLinProg Mole numbers failing element abundances\n");
77 plogf(
" --- seMolesLinProg Call vcs_elcorr to attempt fix\n");
95 test, &usedZeroedSpecies);
100 if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
101 plogf(
"iteration %d\n", iter);
110 for (irxn = 0; irxn < m_numRxnTot; irxn++) {
113 ik = m_numComponents + irxn;
114 dg_rt = m_SSfeSpecies[ik];
116 const double* sc_irxn = m_stoichCoeffRxnMatrix.ptrColumn(irxn);
117 for (
size_t jcomp = 0; jcomp < m_numElemConstraints; jcomp++) {
118 dg_rt += m_SSfeSpecies[jcomp] * sc_irxn[jcomp];
123 idir = (dg_rt < 0.0 ? 1 : -1);
125 dxi_min = m_molNumSpecies_old[ik];
128 for (
size_t jcomp = 0; jcomp < m_numComponents; jcomp++) {
134 delta_xi = fabs(m_molNumSpecies_old[jcomp]/nu);
138 if (delta_xi < 1.0e-10 && (m_molNumSpecies_old[ik] >= 1.0E-10)) {
139 if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
140 plogf(
" --- Component too small: %s\n", m_speciesName[jcomp].c_str());
145 dxi_min = std::min(dxi_min, delta_xi);
152 double dsLocal = idir*dxi_min;
153 m_molNumSpecies_old[ik] += dsLocal;
154 m_molNumSpecies_old[ik] = max(0.0, m_molNumSpecies_old[ik]);
155 for (
size_t jcomp = 0; jcomp < m_numComponents; jcomp++) {
157 if (m_molNumSpecies_old[jcomp] > 1.0E-15) {
160 m_molNumSpecies_old[jcomp] += sc_irxn[jcomp] * dsLocal;
161 m_molNumSpecies_old[jcomp] = max(0.0, m_molNumSpecies_old[jcomp]);
163 if (m_molNumSpecies_old[jcomp] < 1.0E-60) {
170 if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
171 printProgress(m_speciesName, m_molNumSpecies_old, m_SSfeSpecies);
175 if (DEBUG_MODE_ENABLED && m_debug_print_lvl == 1) {
176 printProgress(m_speciesName, m_molNumSpecies_old, m_SSfeSpecies);
177 plogf(
" --- setInitialMoles end\n");
182 }
else if (iter > 15) {
#define VCS_DATA_PTR(vvv)
Points to the data in a std::vector<> object.
#define VCS_SPECIES_INTERFACIALVOLTAGE
Species refers to an electron in the metal.
Header file for the internal object that holds the vcs equilibrium problem (see Class VCS_SOLVE and E...
#define plogf
define this Cantera function to replace printf