21 static void printProgress(
const vector<string> &spName,
22 const vector<double> &soln,
23 const vector<double> &ff)
25 int nsp = soln.size();
27 plogf(
" --- Summary of current progress:\n");
28 plogf(
" --- Name Moles - SSGibbs \n");
29 plogf(
" -------------------------------------------------------------------------------------\n");
30 for (
int k = 0; k < nsp; k++) {
31 plogf(
" --- %20s %12.4g - %12.4g\n", spName[k].c_str(), soln[k], ff[k]);
32 sum += soln[k] * ff[k];
34 plogf(
" --- Total sum to be minimized = %g\n", sum);
38 int VCS_SOLVE::vcs_setMolesLinProg()
41 double test = -1.0E-10;
44 std::string pprefix(
" --- seMolesLinProg ");
45 if (m_debug_print_lvl >= 2) {
46 plogf(
" --- call setInitialMoles\n");
59 double delta_xi, dxi_min = 1.0e10;
63 bool abundancesOK =
true;
64 bool usedZeroedSpecies;
66 std::vector<double> sm(m_numElemConstraints*m_numElemConstraints, 0.0);
67 std::vector<double> ss(m_numElemConstraints, 0.0);
68 std::vector<double> sa(m_numElemConstraints, 0.0);
69 std::vector<double> wx(m_numElemConstraints, 0.0);
70 std::vector<double> aw(m_numSpeciesTot, 0.0);
72 for (ik = 0; ik < m_numSpeciesTot; ik++) {
74 m_molNumSpecies_old[ik] = max(0.0, m_molNumSpecies_old[ik]);
79 if (m_debug_print_lvl >= 2) {
80 printProgress(m_speciesName, m_molNumSpecies_old, m_SSfeSpecies);
86 if (!vcs_elabcheck(0)) {
88 if (m_debug_print_lvl >= 2) {
89 plogf(
"%s Mole numbers failing element abundances\n", pprefix.c_str());
90 plogf(
"%sCall vcs_elcorr to attempt fix\n", pprefix.c_str());
109 test, &usedZeroedSpecies);
115 if (m_debug_print_lvl >= 2) {
116 plogf(
"iteration %d\n", iter);
126 for (irxn = 0; irxn < m_numRxnTot; irxn++) {
129 ik = m_numComponents + irxn;
130 dg_rt = m_SSfeSpecies[ik];
132 const double* sc_irxn = m_stoichCoeffRxnMatrix[irxn];
133 for (
size_t jcomp = 0; jcomp < m_numElemConstraints; jcomp++) {
134 dg_rt += m_SSfeSpecies[jcomp] * sc_irxn[jcomp];
139 idir = (dg_rt < 0.0 ? 1 : -1);
141 dxi_min = m_molNumSpecies_old[ik];
144 for (
size_t jcomp = 0; jcomp < m_numComponents; jcomp++) {
150 delta_xi = fabs(m_molNumSpecies_old[jcomp]/nu);
154 if (delta_xi < 1.0e-10 && (m_molNumSpecies_old[ik] >= 1.0E-10)) {
156 if (m_debug_print_lvl >= 2) {
157 plogf(
" --- Component too small: %s\n", m_speciesName[jcomp].c_str());
163 if (delta_xi < dxi_min) {
172 double dsLocal = idir*dxi_min;
173 m_molNumSpecies_old[ik] += dsLocal;
174 m_molNumSpecies_old[ik] = max(0.0, m_molNumSpecies_old[ik]);
175 for (
size_t jcomp = 0; jcomp < m_numComponents; jcomp++) {
177 if (m_molNumSpecies_old[jcomp] > 1.0E-15) {
180 m_molNumSpecies_old[jcomp] += sc_irxn[jcomp] * dsLocal;
181 m_molNumSpecies_old[jcomp] = max(0.0, m_molNumSpecies_old[jcomp]);
183 if (m_molNumSpecies_old[jcomp] < 1.0E-60) {
195 if (m_debug_print_lvl >= 2) {
196 printProgress(m_speciesName, m_molNumSpecies_old, m_SSfeSpecies);
202 if (m_debug_print_lvl == 1) {
203 printProgress(m_speciesName, m_molNumSpecies_old, m_SSfeSpecies);
204 plogf(
" --- setInitialMoles end\n");
210 }
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...
Header for the object representing each phase within vcs.
Internal declarations for the VCSnonideal package.
#define plogf
define this Cantera function to replace printf