26void printProgress(
const vector<string>& spName,
const vector_fp& soln,
const vector_fp& ff)
29 plogf(
" --- Summary of current progress:\n");
30 plogf(
" --- Name Moles - SSGibbs \n");
31 plogf(
" -------------------------------------------------------------------------------------\n");
32 for (
size_t k = 0; k < soln.size(); k++) {
33 plogf(
" --- %20s %12.4g - %12.4g\n", spName[k], soln[k], ff[k]);
34 sum += soln[k] * ff[k];
36 plogf(
" --- Total sum to be minimized = %g\n", sum);
46 m_nsp(mphase->nSpecies()),
50 m_numSpeciesRdc(mphase->nSpecies()),
52 m_numRxnMinorZeroed(0),
53 m_numPhases(mphase->nPhases()),
54 m_doEstimateEquil(-1),
56 m_temperature(mphase->temperature()),
57 m_pressurePA(mphase->pressure()),
63 m_totalVol(mphase->volume()),
70 for (
size_t kspec = 0; kspec <
m_nsp; kspec++) {
74 string ser =
"VCS_SOLVE: ERROR:\n\t";
76 plogf(
"%s Number of species is nonpositive\n", ser);
78 " Number of species is nonpositive\n");
81 plogf(
"%s Number of phases is nonpositive\n", ser);
83 " Number of phases is nonpositive\n");
164 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
170 std::string eos = tPhase->
type();
171 bool gasPhase = (eos ==
"IdealGas");
174 size_t nSpPhase = tPhase->
nSpecies();
176 string phaseName = tPhase->
name();
186 VolPhase->
resize(iphase, nSpPhase, nelem, phaseName.c_str(), 0.0);
202 if (eos ==
"IdealGas") {
204 }
else if (eos ==
"ConstDensity") {
206 }
else if (eos ==
"StoichSubstance") {
208 }
else if (eos ==
"IdealSolidSoln") {
210 }
else if (eos ==
"Surf" || eos ==
"Edge") {
212 "Surface/edge phase not handled yet.");
215 writelog(
"Unknown Cantera EOS to VCSnonideal: '{}'\n", eos);
234 for (
size_t k = 0; k < nSpPhase; k++) {
274 for (
size_t e = 0; e <
m_nelem; e++) {
295 double minTemp, maxTemp, refPressure;
296 sp.
reportParams(k, spType, c, minTemp, maxTemp, refPressure);
311 plogf(
"vcs_Cantera_convert: Species Type %d not known \n",
333 for (
size_t k = 0; k < nSpPhase; k++) {
342 for (
size_t j = 0; j <
m_nelem; j++) {
343 for (
size_t kspec = 0; kspec <
m_nsp; kspec++) {
355 writeline(
'=', 80,
true,
true);
356 writeline(
'=', 16,
false);
357 plogf(
" Cantera_to_vprob: START OF PROBLEM STATEMENT ");
360 plogf(
" Phase IDs of species\n");
361 plogf(
" species phaseID phaseName ");
362 plogf(
" Initial_Estimated_kMols\n");
363 for (
size_t i = 0; i <
m_nsp; i++) {
377 writeline(
'-', 80,
true,
true);
378 plogf(
" Information about phases\n");
379 plogf(
" PhaseName PhaseNum SingSpec GasPhase EqnState NumSpec");
380 plogf(
" TMolesInert Tmoles(kmol)\n");
382 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
384 plogf(
"%16s %5d %5d %8d %16s %8d %16e ", VolPhase->
PhaseName.c_str(),
391 writeline(
'=', 80,
true,
true);
392 writeline(
'=', 16,
false);
393 plogf(
" Cantera_to_vprob: END OF PROBLEM STATEMENT ");
407 for (
size_t i = 0; i <
m_nsp; i++) {
412 for (
size_t i = 0; i <
m_nelem; i++) {
419 for (
size_t kspec = 0; kspec <
m_nsp; kspec++) {
423 "Species to Phase Mapping, PhaseID, has a bad value\n"
424 "\tm_phaseID[{}] = {}\n"
425 "Allowed values: 0 to {}", kspec, iph,
m_numPhases - 1);
433 if (numPhSp[iph] != Vphase->
nSpecies()) {
435 "Number of species in phase {}, {}, doesn't match ({} != {}) [vphase = {}]",
440 for (
size_t i = 0; i <
m_nelem; i++) {
445 "Charge neutrality condition {} is signicantly "
446 "nonzero, {}. Giving up",
450 plogf(
"Charge neutrality condition %s not zero, %g. Setting it zero\n",
460 for (
size_t i = 0; i <
m_nsp; i++) {
477 for (
size_t k = 1; k < Vphase->
nSpecies(); k++) {
487VCS_SOLVE::~VCS_SOLVE()
507 plogf(
"vcs_prep_oneTime returned a bad status, %d: bailing!\n",
531 if (ipr > 0 || ip1 > 0) {
538 }
else if (iconv == 1) {
539 plogf(
"WARNING: RANGE SPACE ERROR encountered\n");
548 "called for a phase that exists!");
554 for (
size_t k = 0; k < Vphase->
nSpecies(); k++) {
557 "VCS_SOLVE::vcs_popPhasePossible",
558 "we shouldn't be here {}: {} > 0.0", kspec,
562 bool iPopPossible =
true;
572 double negChangeComp = - stoicC;
573 if (negChangeComp > 0.0) {
577 iPopPossible =
false;
592 for (
size_t jrxn = 0; jrxn <
m_numRxnRdc; jrxn++) {
593 bool foundJrxn =
false;
635 size_t iphasePop =
npos;
636 double FephaseMax = -1.0E30;
637 double Fephase = -1.0E30;
641 plogf(
" --- vcs_popPhaseID() called\n");
642 plogf(
" --- Phase Status F_e MoleNum\n");
643 plogf(
" --------------------------------------------------------------------------\n");
647 int existence = Vphase->
exists();
651 plogf(
" --- %18s %5d NA %11.3e\n",
661 "Index out of bounds due to logic error.");
664 Fephase = exp(-deltaGRxn) - 1.0;
666 strcpy(anote,
" (ready to be birthed)");
667 if (Fephase > FephaseMax) {
669 FephaseMax = Fephase;
670 strcpy(anote,
" (chosen to be birthed)");
674 strcpy(anote,
" (not stable)");
676 "VCS_SOLVE::vcs_popPhaseID",
"shouldn't be here");
680 plogf(
" --- %18s %5d %10.3g %10.3g %s\n",
689 if (Fephase > FephaseMax) {
691 FephaseMax = Fephase;
694 FephaseMax = std::max(FephaseMax, Fephase);
697 plogf(
" --- %18s %5d %11.3g %11.3g\n",
703 plogf(
" --- %18s %5d blocked %11.3g\n",
711 phasePopPhaseIDs.resize(0);
712 if (iphasePop !=
npos) {
713 phasePopPhaseIDs.push_back(iphasePop);
719 plogf(
" ---------------------------------------------------------------------\n");
731 std::vector<size_t> creationGlobalRxnNumbers;
739 "called for a phase that exists!");
741 plogf(
" --- vcs_popPhaseRxnStepSizes() called to pop phase %s %d into existence\n",
792 double sumFrac = 0.0;
793 for (
size_t k = 0; k < Vphase->
nSpecies(); k++) {
794 sumFrac += fracDelta[k];
796 for (
size_t k = 0; k < Vphase->
nSpecies(); k++) {
797 X_est[k] = fracDelta[k] / sumFrac;
800 double deltaMolNumPhase = tPhaseMoles;
805 for (
size_t k = 0; k < Vphase->
nSpecies(); k++) {
807 double delmol = deltaMolNumPhase * X_est[k];
811 throw CanteraError(
"VCS_SOLVE::vcs_popPhaseRxnStepSizes",
812 "Index out of bounds due to logic error.");
817 molNumSpecies_tmp[j] += stoicC * delmol;
823 double ratioComp = 0.0;
826 if (molNumSpecies_tmp[j] < 0.0) {
830 damp = std::min(damp, delta0 / deltaJ * 0.9);
835 if ((jph != iphasePop) && (!
m_SSPhase[j])) {
836 double fdeltaJ = fabs(deltaJ);
849 if (ratioComp > 1.0E-30 && ratioComp < 0.001) {
850 damp = 0.001 / ratioComp;
852 if (damp <= 1.0E-6) {
856 for (
size_t k = 0; k < Vphase->
nSpecies(); k++) {
862 if (X_est[k] > 1.0E-3) {
875 size_t iphDel =
npos;
880 for (
int j = 0; j < 82; j++) {
884 plogf(
" --- Subroutine vcs_RxnStepSizes called - Details:\n");
886 for (
int j = 0; j < 82; j++) {
890 plogf(
" --- Species KMoles Rxn_Adjustment DeltaG"
901 for (
size_t irxn = 0; irxn <
m_numRxnRdc; ++irxn) {
902 ANOTE =
"Normal Calc";
907 ANOTE =
"ZeroedPhase: Phase is artificially zeroed";
926 ANOTE = fmt::sprintf(
"MultSpec (%s): Species not born due to STOICH/PHASEPOP even though DG = %11.3E",
930 ANOTE = fmt::sprintf(
"MultSpec (%s): small species born again DG = %11.3E",
934 ANOTE = fmt::sprintf(
"MultSpec (%s):still dead, no phase pop, even though DG = %11.3E",
937 if (Vphase->
exists() > 0 && trphmoles > 0.0) {
939 ANOTE = fmt::sprintf(
"MultSpec (%s): birthed species because it was zero in a small existing phase with DG = %11.3E",
944 ANOTE = fmt::sprintf(
"MultSpec (%s): still dead DG = %11.3E",
955 ANOTE = fmt::sprintf(
"Skipped: superconverged DG = %11.3E",
m_deltaGRxn_new[irxn]);
958 plogf(
" %12.4E %12.4E %12.4E | %s\n",
968 ANOTE = fmt::sprintf(
"Skipped: IC = %3d and DG >0: %11.3E",
972 plogf(
" %12.4E %12.4E %12.4E | %s\n",
1004 ANOTE = fmt::sprintf(
"Normal calc: diag adjusted from %g "
1005 "to %g due to act coeff", s_old, s);
1012 if (stoicC != 0.0) {
1016 ANOTE = fmt::sprintf(
"Delta damped from %g "
1021 ANOTE = fmt::sprintf(
"Delta damped from %g "
1032 ANOTE = fmt::sprintf(
"Delta damped from %g "
1080 if ((k == kspec) && (
m_SSPhase[kspec] != 1)) {
1087 ANOTE = fmt::sprintf(
"Delta damped from %g to %g due to delete %s",
m_deltaMolNumSpecies[kspec],
1092 plogf(
" %12.4E %12.4E %12.4E | %s\n",
1100 for (
size_t j = 0; j <
m_nsp; j++) {
1112 ANOTE = fmt::sprintf(
"Delete component SS phase %d named %s - SS phases only",
1115 ANOTE = fmt::sprintf(
"Delete this SS phase %d - SS components only", iphDel);
1119 plogf(
" %12.4E %12.4E %12.4E | %s\n",
1122 plogf(
" --- vcs_RxnStepSizes Special section to set up to delete %s\n",
1126 forceComponentCalc = 1;
1139 plogf(
" %12.4E %12.4E %12.4E | %s\n",
1156 const size_t nsp = Vphase->
nSpecies();
1157 int minNumberIterations = 3;
1159 minNumberIterations = 1;
1163 bool doSuccessiveSubstitution =
true;
1164 double funcPhaseStability;
1170 vector<size_t> creationGlobalRxnNumbers(nsp,
npos);
1181 std::vector<size_t> componentList;
1182 for (
size_t k = 0; k < nsp; k++) {
1185 componentList.push_back(k);
1189 double normUpdate = 0.1 *
vcs_l2norm(fracDelta_new);
1190 double damp = 1.0E-2;
1192 if (doSuccessiveSubstitution) {
1195 plogf(
" --- vcs_phaseStabilityTest() called\n");
1196 plogf(
" --- Its X_old[%2d] FracDel_old[%2d] deltaF[%2d] FracDel_new[%2d]"
1197 " normUpdate damp FuncPhaseStability\n", KP, KP, KP, KP);
1198 plogf(
" --------------------------------------------------------------"
1199 "--------------------------------------------------------\n");
1201 plogf(
" --- vcs_phaseStabilityTest() called for phase %d\n", iph);
1204 for (
size_t k = 0; k < nsp; k++) {
1205 if (fracDelta_new[k] < 1.0E-13) {
1206 fracDelta_new[k] =1.0E-13;
1209 bool converged =
false;
1210 double dirProd = 0.0;
1211 for (
int its = 0; its < 200 && (!converged); its++) {
1212 double dampOld = damp;
1213 double normUpdateOld = normUpdate;
1214 fracDelta_old = fracDelta_new;
1215 double dirProdOld = dirProd;
1219 for (
size_t i = 0; i < componentList.size(); i++) {
1220 size_t kc = componentList[i];
1222 fracDelta_old[kc] = 0.0;
1223 for (
size_t k = 0; k < nsp; k++) {
1233 double sumFrac = 0.0;
1234 for (
size_t k = 0; k < nsp; k++) {
1235 sumFrac += fracDelta_old[k];
1239 if (sumFrac <= 0.0) {
1242 double sum_Xcomp = 0.0;
1243 for (
size_t k = 0; k < nsp; k++) {
1244 X_est[k] = fracDelta_old[k] / sumFrac;
1246 sum_Xcomp += X_est[k];
1259 for (
size_t i = 0; i < componentList.size(); i++) {
1260 size_t kc = componentList[i];
1271 for (
size_t i = 0; i < componentList.size(); i++) {
1273 for (
size_t k = 0; k < Vphase->
nSpecies(); k++) {
1290 funcPhaseStability = sum_Xcomp - 1.0;
1291 for (
size_t k = 0; k < nsp; k++) {
1298 funcPhaseStability += E_phi[k];
1305 for (
size_t k = 0; k < nsp; k++) {
1307 double b = E_phi[k] / sum * (1.0 - sum_Xcomp);
1309 fracDelta_raw[k] = b;
1315 for (
size_t i = 0; i < componentList.size(); i++) {
1316 size_t kc = componentList[i];
1318 fracDelta_raw[kc] = 0.0;
1319 for (
size_t k = 0; k < nsp; k++) {
1329 double sumADel = 0.0;
1330 for (
size_t k = 0; k < nsp; k++) {
1331 delFrac[k] = fracDelta_raw[k] - fracDelta_old[k];
1332 sumADel += fabs(delFrac[k]);
1337 for (
size_t k = 0; k < nsp; k++) {
1338 dirProd += fracDelta_old[k] * delFrac[k];
1340 bool crossedSign =
false;
1341 if (dirProd * dirProdOld < 0.0) {
1346 if (dampOld < 0.25) {
1347 damp = 2.0 * dampOld;
1350 if (normUpdate *1.5 > normUpdateOld) {
1351 damp = 0.5 * dampOld;
1352 }
else if (normUpdate *2.0 > normUpdateOld) {
1353 damp = 0.8 * dampOld;
1356 if (normUpdate > normUpdateOld * 2.0) {
1357 damp = 0.6 * dampOld;
1358 }
else if (normUpdate > normUpdateOld * 1.2) {
1359 damp = 0.9 * dampOld;
1363 for (
size_t k = 0; k < nsp; k++) {
1364 if (fabs(damp * delFrac[k]) > 0.3*fabs(fracDelta_old[k])) {
1365 damp = std::max(0.3*fabs(fracDelta_old[k]) / fabs(delFrac[k]),
1366 1.0E-8/fabs(delFrac[k]));
1368 if (delFrac[k] < 0.0 && 2.0 * damp * (-delFrac[k]) > fracDelta_old[k]) {
1369 damp = fracDelta_old[k] / (2.0 * -delFrac[k]);
1371 if (delFrac[k] > 0.0 && 2.0 * damp * delFrac[k] > fracDelta_old[k]) {
1372 damp = fracDelta_old[k] / (2.0 * delFrac[k]);
1375 damp = std::max(damp, 0.000001);
1376 for (
size_t k = 0; k < nsp; k++) {
1377 fracDelta_new[k] = fracDelta_old[k] + damp * delFrac[k];
1381 plogf(
" --- %3d %12g %12g %12g %12g %12g %12g %12g\n", its, X_est[KP], fracDelta_old[KP],
1382 delFrac[KP], fracDelta_new[KP], normUpdate, damp, funcPhaseStability);
1385 if (normUpdate < 1.0E-5 * damp) {
1387 if (its < minNumberIterations) {
1402 throw CanteraError(
"VCS_SOLVE::vcs_phaseStabilityTest",
"not done yet");
1405 plogf(
" ------------------------------------------------------------"
1406 "-------------------------------------------------------------\n");
1408 if (funcPhaseStability > 0.0) {
1409 plogf(
" --- phase %d with func = %g is to be born\n", iph, funcPhaseStability);
1411 plogf(
" --- phase %d with func = %g stays dead\n", iph, funcPhaseStability);
1414 return funcPhaseStability;
1436 plogf(
"vcs_inest_TP returned a failure flag\n");
1456 for (
size_t k = 0; k <
m_nsp; k++) {
1465 for (
size_t i = 0; i <
m_nsp; ++i) {
1477 const double w[],
double volPM[])
1479 double VolTot = 0.0;
1480 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
1512 for (
size_t kspec = 0; kspec <
m_nsp; ++kspec) {
1519 for (
size_t e = 0; e < eSize; e++) {
1543 double test = -1.0e-10;
1544 bool modifiedSoln =
false;
1547 for (
size_t kspec = 0; kspec <
m_nsp; ++kspec) {
1552 if (fabs(sum) < 1.0E-6) {
1553 modifiedSoln =
true;
1556 for (
size_t kspec = 0; kspec <
m_nsp; ++kspec) {
1570 double* aw = &awSpace[0];
1572 plogf(
"vcs_prep_oneTime: failed to get memory: global bailout\n");
1573 return VCS_NOMEMORY;
1575 double* sa = aw +
m_nsp;
1579 retn =
vcs_basopt(
true, aw, sa, sm, ss, test, &conv);
1581 plogf(
"vcs_prep_oneTime:");
1582 plogf(
" Determination of number of components failed: %d\n",
1584 plogf(
" Global Bailout!\n");
1605 plogf(
"vcs_prep_oneTime:");
1606 plogf(
" Determination of element reordering failed: %d\n",
1608 plogf(
" Global Bailout!\n");
1615 for (
size_t kspec = 0; kspec <
m_nsp; ++kspec) {
1634 for (
size_t e = 0; e < m_mix->
nElements(); e++) {
1637 if (sum < 1.0E-20) {
1639 plogf(
"vcs has determined the problem is not well posed: Bailing\n");
1646 double*
const sm,
double*
const ss)
1652 plogf(
" --- Subroutine elem_rearrange() called to ");
1653 plogf(
"check stoich. coefficient matrix\n");
1654 plogf(
" --- and to rearrange the element ordering once\n");
1660 double test = -1.0E10;
1663 for (
size_t i = 0; i <
m_nelem; ++i) {
1666 if (test == aw[i]) {
1675 while (jr < ncomponents) {
1684 for (
size_t ielem = jr; ielem <
m_nelem; ielem++) {
1692 "Shouldn't be here. Algorithm misfired.");
1709 for (
size_t j = 0; j < ncomponents; ++j) {
1716 for (
size_t j = 0; j < jl; ++j) {
1718 for (
size_t i = 0; i < ncomponents; ++i) {
1719 ss[j] += sm[i + jr*ncomponents] * sm[i + j*ncomponents];
1726 for (
size_t j = 0; j < jl; ++j) {
1727 for (
size_t i = 0; i < ncomponents; ++i) {
1728 sm[i + jr*ncomponents] -= ss[j] * sm[i + j*ncomponents];
1736 for (
size_t ml = 0; ml < ncomponents; ++ml) {
1737 sa[jr] += pow(sm[ml + jr*ncomponents], 2);
1740 if (sa[jr] > 1.0e-6) {
1747 plogf(
" --- %-2.2s(%9.2g) replaces %-2.2s(%9.2g) as element %3d\n",
1752 std::swap(aw[jr], aw[k]);
1767 "vcs_switch_elem_pos",
1768 "inappropriate args: {} {}", ipos, jpos);
1788 for (
size_t j = 0; j <
m_nsp; ++j) {
1796 double diag = hessianDiag_Ideal;
1798 if (hessianDiag_Ideal <= 0.0) {
1800 "We shouldn't be here");
1802 if (hessActCoef >= 0.0) {
1803 diag += hessActCoef;
1804 }
else if (fabs(hessActCoef) < 0.6666 * hessianDiag_Ideal) {
1805 diag += hessActCoef;
1807 diag -= 0.6666 * hessianDiag_Ideal;
1845 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
1862 bool inertYes =
false;
1865 std::vector<std::pair<double, size_t>> x_order;
1866 for (
size_t i = 0; i <
m_nsp; i++) {
1879 plogf(
"\t\t VCS_TP REPORT\n");
1883 plogf(
" ERROR: CONVERGENCE CRITERION NOT SATISFIED.\n");
1884 }
else if (iconv == 1) {
1885 plogf(
" RANGE SPACE ERROR: Equilibrium Found but not all Element Abundances are Satisfied\n");
1900 plogf(
" Species Equilibrium kmoles ");
1901 plogf(
"Mole Fraction ChemPot/RT SpecUnkType\n");
1905 writeline(
' ', 13,
false);
1912 size_t j = x_order[i].second;
1914 writeline(
' ', 13,
false);
1924 throw CanteraError(
"VCS_SOLVE::vcs_report",
"we have a problem");
1932 plogf(
" Inert Gas Species ");
1934 plogf(
" Inert Species in phase %16s ",
1942 plogf(
"\n SPECIES WITH LESS THAN 1.0E-32 KMOLES:\n\n");
1946 plogf(
" %14.7E %14.7E %12.4E",
1964 plogf(
" |ComponentID|");
1969 plogf(
" | Components|");
1974 plogf(
" NonComponent | Moles |");
1978 plogf(
" | DG/RT Rxn |\n");
1980 for (
size_t irxn = 0; irxn <
m_numRxnTot; irxn++) {
1982 plogf(
" %3d ", kspec);
1997 double totalMoles = 0.0;
1998 double gibbsPhase = 0.0;
1999 double gibbsTotal = 0.0;
2002 writeline(
'-',
m_nelem*10 + 58);
2003 plogf(
" | ElementID |");
2004 for (
size_t j = 0; j <
m_nelem; j++) {
2008 plogf(
" | Element |");
2009 for (
size_t j = 0; j <
m_nelem; j++) {
2013 plogf(
" PhaseName |KMolTarget |");
2014 for (
size_t j = 0; j <
m_nelem; j++) {
2017 plogf(
" | Gibbs Total |\n");
2018 writeline(
'-',
m_nelem*10 + 58);
2019 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
2020 plogf(
" %3d ", iphase);
2027 throw CanteraError(
"VCS_SOLVE::vcs_report",
"we have a problem");
2030 for (
size_t j = 0; j <
m_nelem; j++) {
2031 plogf(
" %10.3g", gaPhase[j]);
2032 gaTPhase[j] += gaPhase[j];
2036 gibbsTotal += gibbsPhase;
2037 plogf(
" | %18.11E |\n", gibbsPhase);
2039 writeline(
'-',
m_nelem*10 + 58);
2040 plogf(
" TOTAL |%10.3e |", totalMoles);
2041 for (
size_t j = 0; j <
m_nelem; j++) {
2042 plogf(
" %10.3g", gaTPhase[j]);
2044 plogf(
" | %18.11E |\n", gibbsTotal);
2046 writeline(
'-',
m_nelem*10 + 58);
2055 plogf(
"\n\tTotal Dimensionless Gibbs Free Energy = G/RT = %15.7E\n", g);
2057 plogf(
"\t\t(Inert species have standard free energy of zero)\n");
2060 plogf(
"\nElemental Abundances (kmol): ");
2061 plogf(
" Actual Target Type ElActive\n");
2062 for (
size_t i = 0; i <
m_nelem; ++i) {
2063 writeline(
' ', 26,
false);
2071 writeline(
'-', 93,
true,
true);
2072 plogf(
"Chemical Potentials of the Species: (dimensionless)\n");
2075 plogf(
" Name TKMoles StandStateChemPot "
2076 " ln(AC) ln(X_i) | F z_i phi | ChemPot | (-lnMnaught)");
2077 plogf(
"| (MolNum ChemPot)|");
2078 writeline(
'-', 147,
true,
true);
2079 for (
size_t i = 0; i <
m_nsp; ++i) {
2080 size_t j = x_order[i].second;
2095 lx = log(tmp) - log(tpmoles);
2101 plogf(
"%14.7E |", lx);
2102 plogf(
"%14.7E | ", eContrib);
2107 "we have a problem - doesn't add up");
2119 for (
size_t i = 0; i < 125; i++) {
2122 plogf(
" %20.9E\n", g);
2123 writeline(
'-', 147);
2127 plogf(
"\nCounters: Iterations Time (seconds)\n");
2129 plogf(
" vcs_basopt: %5d %11.5E\n",
2131 plogf(
" vcs_TP: %5d %11.5E\n",
2134 plogf(
" vcs_basopt: %5d %11s\n",
2136 plogf(
" vcs_TP: %5d %11s\n",
2148 for (
size_t j = 0; j <
m_nelem; ++j) {
2150 for (
size_t i = 0; i <
m_nsp; ++i) {
2165 for (
size_t i = 0; i < top; ++i) {
2172 "Problem with charge neutrality condition");
2181 bool multisign =
false;
2182 for (
size_t kspec = 0; kspec <
m_nsp; kspec++) {
2216 for (
size_t j = 0; j <
m_nelem; ++j) {
2217 elemAbundPhase[j] = 0.0;
2218 for (
size_t i = 0; i <
m_nsp; ++i) {
2232 plogf(
" --- vcsc_elcorr: Element abundances correction routine");
2234 plogf(
" (m_numComponents != m_nelem)");
2239 for (
size_t i = 0; i <
m_nelem; ++i) {
2242 double l2before = 0.0;
2243 for (
size_t i = 0; i <
m_nelem; ++i) {
2244 l2before += x[i] * x[i];
2246 l2before = sqrt(l2before/
m_nelem);
2251 bool changed =
false;
2252 for (
size_t i = 0; i <
m_nelem; ++i) {
2254 bool multisign =
false;
2255 for (
size_t kspec = 0; kspec <
m_nsp; kspec++) {
2267 if (numNonZero < 2) {
2268 for (
size_t kspec = 0; kspec <
m_nsp; kspec++) {
2278 int numCompNonZero = 0;
2279 size_t compID =
npos;
2289 if (numCompNonZero == 1) {
2315 for (
size_t i = 0; i <
m_nelem; ++i) {
2318 for (
size_t kspec = 0; kspec <
m_nsp; kspec++) {
2321 if (atomComp > 0.0) {
2325 plogf(
" --- vcs_elcorr: Reduced species %s from %g to %g "
2326 "due to %s max bounds constraint\n",
2340 plogf(
" --- vcs_elcorr: Zeroed species %s and changed "
2341 "status to %d due to max bounds constraint\n",
2362 if (fabs(x[i]) > 1.0E-13) {
2379 par = std::min(par, 100.0);
2381 if (par < 1.0 && par > 0.0) {
2420 for (
size_t kspec = 0; kspec <
m_nsp; kspec++) {
2424 double saveDir = 0.0;
2425 bool goodSpec =
true;
2428 if (fabs(dir) > 1.0E-10) {
2430 if (saveDir < 0.0) {
2435 if (saveDir > 0.0) {
2480 for (
size_t i = 0; i <
m_nelem; ++i) {
2506 for (
size_t i = 0; i <
m_nelem; ++i) {
2509 bool useZeroed =
true;
2549 double l2after = 0.0;
2550 for (
size_t i = 0; i <
m_nelem; ++i) {
2553 l2after = sqrt(l2after/
m_nelem);
2555 plogf(
" --- Elem_Abund: Correct Initial "
2557 for (
size_t i = 0; i <
m_nelem; ++i) {
2562 plogf(
" --- Diff_Norm: %20.12E %20.12E\n",
2570 const char* pprefix =
" --- vcs_inest: ";
2578 plogf(
"%s Initial guess passed element abundances on input\n", pprefix);
2579 plogf(
"%s m_doEstimateEquil = 1 so will use the input mole "
2580 "numbers as estimates\n", pprefix);
2584 plogf(
"%s Initial guess failed element abundances on input\n", pprefix);
2585 plogf(
"%s m_doEstimateEquil = 1 so will discard input "
2586 "mole numbers and find our own estimate\n", pprefix);
2598 plogf(
"%sGo find an initial estimate for the equilibrium problem\n",
2601 double test = -1.0E20;
2602 vcs_inest(&aw[0], &sa[0], &sm[0], &ss[0], test);
2617 plogf(
"%sInitial guess failed element abundances\n", pprefix);
2618 plogf(
"%sCall vcs_elcorr to attempt fix\n", pprefix);
2623 plogf(
"%sInitial guess still fails element abundance equations\n",
2625 plogf(
"%s - Inability to ever satisfy element abundance "
2626 "constraints is probable\n", pprefix);
2631 plogf(
"%sInitial guess now satisfies element abundances\n", pprefix);
2633 plogf(
"%sElement Abundances RANGE ERROR\n", pprefix);
2634 plogf(
"%s - Initial guess satisfies NC=%d element abundances, "
2635 "BUT not NE=%d element abundances\n", pprefix,
2643 plogf(
"%sInitial guess satisfies element abundances\n", pprefix);
2645 plogf(
"%sElement Abundances RANGE ERROR\n", pprefix);
2646 plogf(
"%s - Initial guess satisfies NC=%d element abundances, "
2647 "BUT not NE=%d element abundances\n", pprefix,
2654 plogf(
"%sTotal Dimensionless Gibbs Free Energy = %15.7E\n", pprefix,
2667 double test = -1.0E-10;
2670 plogf(
" --- call setInitialMoles\n");
2673 double dxi_min = 1.0e10;
2676 bool abundancesOK =
true;
2677 bool usedZeroedSpecies;
2684 for (
size_t ik = 0; ik <
m_nsp; ik++) {
2698 plogf(
" --- seMolesLinProg Mole numbers failing element abundances\n");
2699 plogf(
" --- seMolesLinProg Call vcs_elcorr to attempt fix\n");
2703 abundancesOK =
false;
2705 abundancesOK =
true;
2708 abundancesOK =
true;
2714 retn =
vcs_basopt(
false, &aw[0], &sa[0], &sm[0], &ss[0],
2715 test, &usedZeroedSpecies);
2721 plogf(
"iteration %d\n", iter);
2730 for (
size_t irxn = 0; irxn <
m_numRxnTot; irxn++) {
2736 for (
size_t jcomp = 0; jcomp <
m_nelem; jcomp++) {
2742 int idir = (dg_rt < 0.0 ? 1 : -1);
2748 double nu = sc_irxn[jcomp];
2761 dxi_min = std::min(dxi_min, delta_xi);
2768 double dsLocal = idir*dxi_min;
2791 plogf(
" --- setInitialMoles end\n");
2794 if (!abundancesOK) {
2796 }
else if (iter > 15) {
2820 g += molesSp[kspec] * chemPot[kspec];
2828 const double*
const fe)
2831 double phaseMols = 0.0;
2834 g += w[kspec] * fe[kspec];
2835 phaseMols += w[kspec];
2873 vector<size_t> invSpecies(
m_nsp);
2874 for (
size_t k = 0; k <
m_nsp; k++) {
2878 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
2885 size_t nSpPhase = tPhase->
nSpecies();
2886 if ((nSpPhase == 1) && (volPhase->
phiVarIndex() == 0)) {
2897 writeline(
'=', 80,
true,
true);
2898 writeline(
'=', 20,
false);
2899 plogf(
" Cantera_to_vprob: START OF PROBLEM STATEMENT ");
2903 plogf(
" Phase IDs of species\n");
2904 plogf(
" species phaseID phaseName ");
2905 plogf(
" Initial_Estimated_kMols\n");
2906 for (
size_t i = 0; i <
m_nsp; i++) {
2919 writeline(
'-', 80,
true,
true);
2920 plogf(
" Information about phases\n");
2921 plogf(
" PhaseName PhaseNum SingSpec GasPhase EqnState NumSpec");
2922 plogf(
" TMolesInert Tmoles(kmol)\n");
2924 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
2926 plogf(
"%16s %5d %5d %8d %16s %8d %16e ", VolPhase->
PhaseName.c_str(),
2933 writeline(
'=', 80,
true,
true);
2934 writeline(
'=', 20,
false);
2935 plogf(
" Cantera_to_vprob: END OF PROBLEM STATEMENT ");
2954 double*
const ss,
double test)
2956 const char* pprefix =
" --- vcs_inest: ";
2964 plogf(
"%s Mole Numbers returned from linear programming (vcs_inest initial guess):\n",
2966 plogf(
"%s SPECIES MOLE_NUMBER -SS_ChemPotential\n", pprefix);
2967 for (
size_t kspec = 0; kspec <
m_nsp; ++kspec) {
2968 plogf(
"%s ", pprefix);
2972 plogf(
"%s Element Abundance Agreement returned from linear "
2973 "programming (vcs_inest initial guess):\n", pprefix);
2974 plogf(
"%s Element Goal Actual\n", pprefix);
2975 for (
size_t j = 0; j <
m_nelem; j++) {
2978 for (
size_t kspec = 0; kspec <
m_nsp; ++kspec) {
2981 plogf(
"%s ", pprefix);
2992 for (
size_t kspec = 0; kspec <
m_nsp; ++kspec) {
3008 vcs_basopt(
false, aw, sa, sm, ss, test, &conv);
3024 double TMolesMultiphase = 0.0;
3050 for (
size_t kspec = 0; kspec <
m_nsp; ++kspec) {
3051 plogf(
"%s", pprefix);
3057 plogf(
"fe* = %15.5g ff = %15.5g dg* = %15.5g\n",
3071 for (
size_t irxn = 0; irxn < nrxn; ++irxn) {
3105 for (
size_t kspec = 0; kspec <
m_nsp; ++kspec) {
3107 plogf(
"%sdirection (", pprefix);
3114 plogf(
" (ssPhase doesn't exist -> stability not checked)");
3131 if (par <= 1.0 && par > 0.0) {
3167 for (
size_t kspec = 0; kspec <
m_nsp; ++kspec) {
3173 if (s < 0.0 && ikl == 0) {
3186 double xl = (1.0 - s / (s1 - s)) * 0.5;
3196 par = par * 2.0 * xl;
3203 plogf(
"%s Final Mole Numbers produced by inest:\n",
3205 plogf(
"%s SPECIES MOLE_NUMBER\n", pprefix);
3206 for (
size_t kspec = 0; kspec <
m_nsp; ++kspec) {
3207 plogf(
"%s %-12.12s %g\n",
3216 for (
size_t kspec = 0; kspec <
m_nsp; ++kspec) {
3237 for (
size_t kspec = 0; kspec <
m_nsp; kspec++) {
3279 plogf(
"\nTCounters: Num_Calls Total_Its Total_Time (seconds)\n");
3280 if (timing_print_lvl > 0) {
3281 plogf(
" vcs_basopt: %5d %5d %11.5E\n",
3284 plogf(
" vcs_TP: %5d %5d %11.5E\n",
3287 plogf(
" vcs_inest: %5d %11.5E\n",
3289 plogf(
" vcs_TotalTime: %11.5E\n",
3292 plogf(
" vcs_basopt: %5d %5d %11s\n",
3294 plogf(
" vcs_TP: %5d %5d %11s\n",
3296 plogf(
" vcs_inest: %5d %11s\n",
3298 plogf(
" vcs_TotalTime: %11s\n",
3309 writeline(
'=', 80,
true,
true);
3310 writeline(
'=', 20,
false);
3311 plogf(
" VCS_PROB: PROBLEM STATEMENT ");
3315 plogf(
"\tSolve a constant T, P problem:\n");
3319 plogf(
"\t\tPres = %g atm\n", pres_atm);
3321 plogf(
" Phase IDs of species\n");
3322 plogf(
" species phaseID phaseName ");
3323 plogf(
" Initial_Estimated_Moles Species_Type\n");
3324 for (
size_t i = 0; i <
m_nsp; i++) {
3344 writeline(
'-', 80,
true,
true);
3345 plogf(
" Information about phases\n");
3346 plogf(
" PhaseName PhaseNum SingSpec GasPhase "
3347 " EqnState NumSpec");
3348 plogf(
" TMolesInert TKmoles\n");
3350 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
3363 plogf(
"\nElemental Abundances: ");
3364 plogf(
" Target_kmol ElemType ElActive\n");
3365 for (
size_t i = 0; i <
m_nelem; ++i) {
3366 writeline(
' ', 26,
false);
3372 plogf(
"\nChemical Potentials: (J/kmol)\n");
3373 plogf(
" Species (phase) "
3374 " SS0ChemPot StarChemPot\n");
3375 for (
size_t iphase = 0; iphase <
m_numPhases; iphase++) {
3378 for (
size_t kindex = 0; kindex < Vphase->
nSpecies(); kindex++) {
3391 writeline(
'=', 80,
true,
true);
3392 writeline(
'=', 20,
false);
3393 plogf(
" VCS_PROB: END OF PROBLEM STATEMENT ");
3404 for (
size_t eVP = 0; eVP < neVP; eVP++) {
3405 size_t foundPos =
npos;
3410 for (
size_t e = 0; e <
m_nelem; e++) {
3412 if (!strcmp(enVP.c_str(), en.c_str())) {
3417 if (foundPos ==
npos) {
3419 int elactive = volPhase->elementActive(eVP);
3420 size_t e =
addElement(enVP.c_str(), elType, elactive);
3430 throw CanteraError(
"VCS_SOLVE::addOnePhaseSpecies",
"Shouldn't be here");
3436 "element not found");
3450 "error: element must have a name");
Headers for the MultiPhase object that is used to set up multiphase equilibrium problems (see Classes...
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
A class for 2D arrays stored in column-major (Fortran-compatible) form.
void zero()
Set all of the entries to zero.
doublereal * ptrColumn(size_t j)
Return a pointer to the top of column j, columns are contiguous in memory.
size_t nColumns() const
Number of columns.
void resize(size_t n, size_t m, double v=0.0)
Resize the array, and fill the new entries with 'v'.
Base class for exceptions thrown by Cantera classes.
A class for full (non-sparse) matrices with Fortran-compatible data storage, which adds matrix operat...
A class for multiphase mixtures.
doublereal pressure() const
Pressure [Pa].
doublereal speciesMoles(size_t kGlob) const
Returns the moles of global species k. units = kmol.
std::string speciesName(const size_t kGlob) const
Name of species with global index kGlob.
doublereal elementMoles(size_t m) const
Total moles of global element m, summed over all phases.
void uploadMoleFractionsFromPhases()
Update the locally-stored composition within this object to match the current compositions of the pha...
doublereal volume() const
The total mixture volume [m^3].
void setPhaseMoles(const size_t n, const doublereal moles)
Set the number of moles of phase with index n.
doublereal temperature() const
Temperature [K].
size_t nElements() const
Number of elements.
ThermoPhase & phase(size_t n)
Return a reference to phase n.
A species thermodynamic property manager for a phase.
virtual int reportType(size_t index) const
This utility function reports the type of parameterization used for the species with index number ind...
virtual void reportParams(size_t index, int &type, doublereal *const c, doublereal &minTemp, doublereal &maxTemp, doublereal &refPressure) const
This utility function reports back the type of parameterization and all of the parameters for the spe...
std::string name() const
Return the name of the phase.
size_t nSpecies() const
Returns the number of species in the phase.
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
size_t nElements() const
Number of elements.
Base class for a phase with thermodynamic properties.
virtual int activityConvention() const
This method returns the convention used in specification of the activities, of which there are curren...
virtual MultiSpeciesThermo & speciesThermo(int k=-1)
Return a changeable reference to the calculation manager for species reference-state thermodynamic pr...
virtual std::string type() const
String indicating the thermodynamic model implemented.
doublereal electricPotential() const
Returns the electric potential of this phase (V).
Class to keep track of time and iterations.
int Its
Current number of iterations in the main loop of vcs_TP() to solve for thermo equilibrium.
int T_Calls_Inest
Current number of times the initial thermo equilibrium estimator has been called.
double T_Time_basopt
Total Time spent in basopt.
double T_Time_inest
Time spent in initial estimator.
int T_Basis_Opts
Total number of optimizations of the components basis set done.
double T_Time_vcs_TP
Current time spent in vcs_TP.
int Basis_Opts
number of optimizations of the components basis set done
double T_Time_vcs
Time spent in the vcs suite of programs.
int T_Its
Total number of iterations in the main loop of vcs_TP() to solve for thermo equilibrium.
int T_Calls_vcs_TP
Current number of calls to vcs_TP.
double Time_basopt
Current Time spent in basopt.
double Time_vcs_TP
Current time spent in vcs_TP.
size_t m_numPhases
Number of Phases in the problem.
int m_doEstimateEquil
Setting for whether to do an initial estimate.
VCS_SOLVE(MultiPhase *mphase, int printLvl=0)
Initialize the sizes within the VCS_SOLVE object.
int vcs_evalSS_TP(int ipr, int ip1, double Temp, double pres)
int vcs_inest_TP()
Create an initial estimate of the solution to the thermodynamic equilibrium problem.
vector_fp m_phasePhi
electric potential of the iph phase
vector_fp m_scSize
Absolute size of the stoichiometric coefficients.
void vcs_deltag(const int L, const bool doDeleted, const int vcsState, const bool alterZeroedPhases=true)
This subroutine calculates reaction free energy changes for all noncomponent formation reactions.
double m_tolmaj2
Below this, major species aren't refined any more.
double vcs_VolTotal(const double tkelvin, const double pres, const double w[], double volPM[])
Calculation of the total volume and the partial molar volumes.
std::vector< std::string > m_speciesName
Species string name for the kth species.
int vcs_elem_rearrange(double *const aw, double *const sa, double *const sm, double *const ss)
Rearrange the constraint equations represented by the Formula Matrix so that the operational ones are...
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_TmpPhase2
Temporary vector of length NPhase.
vector_int m_elType
Type of the element constraint.
size_t m_nelem
Number of element constraints in the problem.
int m_useActCoeffJac
Choice of Hessians.
double m_totalVol
Total volume of all phases. Units are m^3.
vector_int m_speciesStatus
Major -Minor status vector for the species in the problem.
int vcs_basopt(const bool doJustComponents, double aw[], double sa[], double sm[], double ss[], double test, bool *const usedZeroedSpecies)
Choose the optimum species basis for the calculations.
int vcs_prep(int printLvl)
This routine is mostly concerned with changing the private data to be consistent with what's needed f...
int vcs_elcorr(double aa[], double x[])
vector_int m_actConventionSpecies
specifies the activity convention of the phase containing the species
vector_fp m_molNumSpecies_old
Total moles of the species.
void vcs_TCounters_report(int timing_print_lvl=1)
Create a report on the plog file containing timing and its information.
Array2D m_phaseParticipation
This is 1 if the phase, iphase, participates in the formation reaction irxn, and zero otherwise.
static void disableTiming()
Disable printing of timing information.
double vcs_phaseStabilityTest(const size_t iph)
Main program to test whether a deleted phase should be brought back into existence.
vector_fp m_molNumSpecies_new
Tentative value of the mole number vector.
void vcs_inest(double *const aw, double *const sa, double *const sm, double *const ss, double test)
Estimate equilibrium compositions.
bool vcs_popPhasePossible(const size_t iphasePop) const
Utility function that evaluates whether a phase can be popped into existence.
vector_fp m_elemAbundances
Element abundances vector.
vector_int m_speciesUnknownType
Specifies the species unknown type.
vector_fp m_deltaGRxn_tmp
Temporary vector of Rxn DeltaG's.
vector_fp m_deltaGRxn_old
Last deltag[irxn] from the previous step.
int vcs_TP(int ipr, int ip1, int maxit, double T, double pres)
Solve an equilibrium problem at a particular fixed temperature and pressure.
void vcs_elab()
Computes the current elemental abundances vector.
void prob_report(int print_lvl)
Print out the problem specification in all generality as it currently exists in the VCS_SOLVE object.
int m_timing_print_lvl
printing level of timing information
size_t vcs_popPhaseID(std::vector< size_t > &phasePopPhaseIDs)
Decision as to whether a phase pops back into existence.
int vcs_setMolesLinProg()
Estimate the initial mole numbers by constrained linear programming.
double vcs_Total_Gibbs(double *w, double *fe, double *tPhMoles)
Calculate the total dimensionless Gibbs free energy.
void vcs_CalcLnActCoeffJac(const double *const moleSpeciesVCS)
Recalculate all of the activity coefficients in all of the phases based on input mole numbers.
vector_fp m_tPhaseMoles_new
total kmols of species in each phase in the tentative soln vector
vector_fp m_feSpecies_new
Dimensionless new free energy for all the species in the mechanism at the new tentative T,...
void vcs_elabPhase(size_t iphase, double *const elemAbundPhase)
vector_fp m_tPhaseMoles_old
Total kmols of species in each phase.
size_t m_numSpeciesRdc
Current number of species in the problems.
int m_debug_print_lvl
Debug printing lvl.
void vcs_counters_init(int ifunc)
Initialize the internal counters.
vector_fp m_elemAbundancesGoal
Element abundances vector Goals.
void vcs_reinsert_deleted(size_t kspec)
vector_fp TPhInertMoles
Total kmoles of inert to add to each phase.
std::vector< size_t > m_phaseID
Mapping from the species number to the phase number.
std::vector< size_t > m_indexRxnToSpecies
Mapping between the species index for noncomponent species and the full species index.
Array2D m_formulaMatrix
Formula matrix for the problem.
vector_fp m_wtSpecies
Molecular weight of each species.
vector_fp m_deltaPhaseMoles
Change in the total moles in each phase.
void addPhaseElements(vcs_VolPhase *volPhase)
Add elements to the local element list.
int vcs_solve_TP(int print_lvl, int printDetails, int maxit)
Main routine that solves for equilibrium at constant T and P using a variant of the VCS method.
std::vector< size_t > m_speciesLocalPhaseIndex
Index that keeps track of the index of the species within the local phase.
size_t addOnePhaseSpecies(vcs_VolPhase *volPhase, size_t k, size_t kT)
This routines adds entries for the formula matrix for one species.
Array2D m_stoichCoeffRxnMatrix
Stoichiometric coefficient matrix for the reaction mechanism expressed in Reduced Canonical Form.
size_t m_numRxnRdc
Current number of non-component species in the problem.
VCS_COUNTERS * m_VCount
Timing and iteration counters for the vcs object.
int vcs(int ipr, int ip1, int maxit)
Solve an equilibrium problem.
std::vector< std::unique_ptr< VCS_SPECIES_THERMO > > m_speciesThermoList
Vector of pointers to thermo structures which identify the model and parameters for evaluating the th...
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...
double vcs_GibbsPhase(size_t iphase, const double *const w, const double *const fe)
Calculate the total dimensionless Gibbs free energy of a single phase.
size_t m_numComponents
Number of components calculated for the problem.
void vcs_prob_specifyFully()
Fully specify the problem to be solved.
double m_pressurePA
Pressure.
void vcs_SSPhase()
Calculate the status of single species phases.
vector_fp m_chargeSpecies
Charge of each species. Length = number of species.
vector_fp m_feSpecies_old
Free energy vector from the start of the current iteration.
int vcs_report(int iconv)
Print out a report on the state of the equilibrium problem to standard output.
vector_int m_elementActive
Specifies whether an element constraint is active.
double m_Faraday_dim
dimensionless value of Faraday's constant, F / RT (1/volt)
std::vector< char > m_SSPhase
Boolean indicating whether a species belongs to a single-species phase.
size_t m_nsp
Total number of species in the problems.
std::vector< std::unique_ptr< vcs_VolPhase > > m_VolPhaseList
Array of Phase Structures. Length = number of phases.
vector_fp m_spSize
total size of the species
bool vcs_elabcheck(int ibound)
std::vector< size_t > m_elementMapIndex
Index vector that keeps track of the rearrangement of the elements.
void vcs_delete_memory()
Delete memory that isn't just resizable STL containers.
double vcs_Hessian_actCoeff_diag(size_t irxn)
Calculates the diagonal contribution to the Hessian due to the dependence of the activity coefficient...
void vcs_prob_update()
Transfer the results of the equilibrium calculation back from VCS_SOLVE.
size_t vcs_RxnStepSizes(int &forceComponentCalc, size_t &kSpecial)
Calculates formation reaction step sizes.
vector_fp m_deltaMolNumSpecies
Reaction Adjustments for each species during the current step.
vector_fp m_SSfeSpecies
Standard state chemical potentials for species K at the current temperature and pressure.
Array2D m_deltaMolNumPhase
Change in the number of moles of phase, iphase, due to the noncomponent formation reaction,...
std::vector< size_t > m_speciesMapIndex
Index vector that keeps track of the species vector rearrangement.
void vcs_switch_elem_pos(size_t ipos, size_t jpos)
Swaps the indices for all of the global data for two elements, ipos and jpos.
vector_fp m_actCoeffSpecies_old
Molar-based Activity Coefficients for Species based on old mole numbers.
double vcs_tmoles()
Calculates the total number of moles of species in all phases.
vector_fp m_PMVolumeSpecies
Partial molar volumes of the species.
vector_fp m_deltaGRxn_new
Delta G(irxn) for the noncomponent species in the mechanism.
int m_printLvl
Print level for print routines.
void vcs_dfe(const int stateCalc, const int ll, const size_t lbot, const size_t ltop)
Calculate the dimensionless chemical potentials of all species or of certain groups of species,...
vector_fp m_lnMnaughtSpecies
specifies the ln(Mnaught) used to calculate the chemical potentials
vector_int m_phaseActConvention
specifies the activity convention of the phase.
int vcs_popPhaseRxnStepSizes(const size_t iphasePop)
Calculates the deltas of the reactions due to phases popping into existence.
size_t m_numRxnTot
Total number of non-component species in the problem.
void vcs_fePrep_TP()
Initialize the chemical potential of single species phases.
vector_fp m_deltaGRxn_Deficient
Last deltag[irxn] from the previous step with additions for possible births of zeroed phases.
double m_temperature
Temperature (Kelvin)
vector_fp m_TmpPhase
Temporary vector of length NPhase.
vector_fp m_actCoeffSpecies_new
Molar-based Activity Coefficients for Species.
std::vector< std::string > m_elementName
Vector of strings containing the element names.
size_t addElement(const char *elNameNew, int elType, int elactive)
This routine resizes the number of elements in the VCS_SOLVE object by adding a new element to the en...
double m_totalMolNum
Total number of kmoles in all phases.
size_t IndexSpeciesPhase
Index of this species in the current phase.
int SSStar_Vol_Model
Models for the standard state volume of each species.
double SS0_Cp0
Base heat capacity used in the VCS_SS0_CONSTANT_CP model.
double SSStar_Vol0
parameter that is used in the VCS_SSVOL_CONSTANT model.
double SS0_H0
Base enthalpy used in the VCS_SS0_CONSTANT_CP model.
double SS0_T0
Base temperature used in the VCS_SS0_CONSTANT_CP model.
double SS0_TSave
Internal storage of the last temperature used in the calculation of the reference naught Gibbs free e...
int SSStar_Model
Integer value representing the star state model.
double SS0_S0
Base entropy used in the VCS_SS0_CONSTANT_CP model.
int SS0_Model
Integer representing the models for the species standard state Naught temperature dependence.
double SS0_feSave
Internal storage of the last calculation of the reference naught Gibbs free energy at SS0_TSave.
size_t IndexPhase
Index of the phase that this species belongs to.
vcs_VolPhase * OwningPhase
Pointer to the owning phase object.
The class provides the wall clock timer in seconds.
double secondsWC()
Returns the wall clock time in seconds since the last reset.
Properties of a single species.
double VolPM
Partial molar volume of the species.
vector_fp FormulaMatrixCol
Column of the formula matrix, comprising the element composition of the species.
int SurfaceSpecies
True if this species belongs to a surface phase.
std::string SpName
Name of the species.
double WtSpecies
Molecular Weight of the species (gm/mol)
VCS_SPECIES_THERMO * SpeciesThermo
Pointer to the thermo structure for this species.
double Charge
Charge state of the species -> This may be duplication of what's in the FormulaMatrixCol entries.
Phase information and Phase calculations for vcs.
void setElectricPotential(const double phi)
set the electric potential of the phase
std::string eos_name() const
Return the name corresponding to the equation of state.
int speciesUnknownType(const size_t k) const
Returns the type of the species unknown.
size_t elemGlobalIndex(const size_t e) const
Returns the global index of the local element index for the phase.
size_t nSpecies() const
Return the number of species in the phase.
std::string elementName(const size_t e) const
Name of the element constraint with index e.
void setMoleFractionsState(const double molNum, const double *const moleFracVec, const int vcsStateStatus)
Set the moles and/or mole fractions within the phase.
size_t VP_ID_
Original ID of the phase in the problem.
const Array2D & getFormulaMatrix() const
Get a constant form of the Species Formula Matrix.
vcs_SpeciesProperties * speciesProperty(const size_t kindex)
Retrieve the kth Species structure for the species belonging to this phase.
size_t phiVarIndex() const
Return the index of the species that represents the the voltage of the phase.
double totalMolesInert() const
Returns the value of the total kmol of inert in the phase.
bool m_singleSpecies
If true, this phase consists of a single species.
void setMolesFromVCS(const int stateCalc, const double *molesSpeciesVCS=0)
Set the moles within the phase.
void setElemGlobalIndex(const size_t eLocal, const size_t eGlobal)
sets a local phase element to a global index value
void resize(const size_t phaseNum, const size_t numSpecies, const size_t numElem, const char *const phaseName, const double molesInert=0.0)
The resize() function fills in all of the initial information if it is not given in the constructor.
int exists() const
int indicating whether the phase exists or not
size_t nElemConstraints() const
Returns the number of element constraints.
size_t spGlobalIndexVCS(const size_t spIndex) const
Return the Global VCS index of the kth species in the phase.
size_t transferElementsFM(const ThermoPhase *const tPhase)
Transfer all of the element information from the ThermoPhase object to the vcs_VolPhase object.
double GStar_calc_one(size_t kspec) const
Gibbs free energy calculation for standard state of one species.
bool m_gasPhase
If true, this phase is a gas-phase like phase.
std::string PhaseName
String name for the phase.
void setTotalMoles(const double totalMols)
Sets the total moles in the phase.
void setCreationMoleNumbers(const double *const n_k, const std::vector< size_t > &creationGlobalRxnNumbers)
Sets the creationMoleNum's within the phase object.
int p_activityConvention
Convention for the activity formulation.
void sendToVCS_GStar(double *const gstar) const
Fill in the standard state Gibbs free energy vector for VCS.
void sendToVCS_ActCoeff(const int stateCalc, double *const AC)
Fill in an activity coefficients vector within a VCS_SOLVE object.
const vector_fp & creationMoleNumbers(std::vector< size_t > &creationGlobalRxnNumbers) const
Return a const reference to the creationMoleNumbers stored in the object.
double sendToVCS_VolPM(double *const VolPM) const
Fill in the partial molar volume vector for VCS.
int m_eqnState
Type of the equation of state.
double G0_calc_one(size_t kspec) const
Gibbs free energy calculation at a temperature for the reference state of a species,...
void setState_TP(const double temperature_Kelvin, const double pressure_PA)
Sets the temperature and pressure in this object and underlying ThermoPhase objects.
int elementType(const size_t e) const
Type of the element constraint with index e.
void setSpGlobalIndexVCS(const size_t spIndex, const size_t spGlobalIndex)
set the Global VCS index of the kth species in the phase
void setExistence(const int existence)
Set the existence flag in the object.
bool isIdealSoln() const
Returns whether the phase is an ideal solution phase.
double totalMoles() const
Return the total moles in the phase.
void setPtrThermoPhase(ThermoPhase *tp_ptr)
Set the pointer for Cantera's ThermoPhase parameter.
Declarations for a simple class that implements an Ansi C wall clock timer (see Cantera::clockWC).
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
#define AssertThrowMsg(expr, procedure,...)
Assertion must be true or an error is thrown.
void writelog(const std::string &fmt, const Args &... args)
Write a formatted message to the screen.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
const double Faraday
Faraday constant [C/kmol].
int vcs_timing_print_lvl
Global hook for turning on and off time printing.
void debuglog(const std::string &msg, int loglevel)
Write a message to the log only if loglevel > 0.
const char * vcs_speciesType_string(int speciesStatus, int length=100)
Returns a const char string representing the type of the species given by the first argument.
bool vcs_doubleEqual(double d1, double d2)
Simple routine to check whether two doubles are equal up to roundoff error.
std::vector< int > vector_int
Vector of ints.
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
const double GasConstant
Universal Gas Constant [J/kmol/K].
T clip(const T &value, const T &lower, const T &upper)
Clip value such that lower <= value <= upper.
double vcs_l2norm(const vector_fp &vec)
determine the l2 norm of a vector of doubles
int solve(DenseMatrix &A, double *b, size_t nrhs=1, size_t ldb=0)
Solve Ax = b. Array b is overwritten on exit with x.
void writelogendl()
Write an end of line character to the screen and flush output.
Contains const definitions for types of species reference-state thermodynamics managers (see Species ...
#define SIMPLE
Constant Cp thermo.
Contains declarations for string manipulation functions within Cantera.
Header for the object representing each phase within vcs.
#define VCS_SPECIES_INTERFACIALVOLTAGE
Species refers to an electron in the metal.
#define VCS_SPECIES_TYPE_INTERFACIALVOLTAGE
Unknown refers to the voltage level of a phase.
#define VCS_STATECALC_OLD
State Calculation based on the old or base mole numbers.
#define VCS_DELETE_MINORSPECIES_CUTOFF
Cutoff relative mole number value, below which species are deleted from the equilibrium problem.
#define VCS_SSVOL_IDEALGAS
Models for the standard state volume of each species.
#define VCS_SPECIES_COMPONENT
Species is a component which can be nonzero.
#define VCS_SPECIES_MAJOR
Species is a major species.
#define VCS_PHASE_EXIST_NO
Phase doesn't currently exist in the mixture.
#define VCS_PHASE_EXIST_ALWAYS
#define VCS_SPECIES_STOICHZERO
Species lies in a multicomponent phase that is active, but species concentration is zero due to stoic...
#define VCS_ELEM_TYPE_ABSPOS
Normal element constraint consisting of positive coefficients for the formula matrix.
#define VCS_STATECALC_NEW
State Calculation based on the new or tentative mole numbers.
#define VCS_SPECIES_TYPE_MOLNUM
Unknown refers to mole number of a single species.
#define VCS_SPECIES_ZEROEDPHASE
Species lies in a multicomponent phase that is zeroed atm.
#define VCS_ELEM_TYPE_LATTICERATIO
Constraint associated with maintaining a fixed lattice stoichiometry in the solids.
#define VCS_SPECIES_ACTIVEBUTZERO
Species lies in a multicomponent phase that is active, but species concentration is zero.
#define VCS_ELEM_TYPE_ELECTRONCHARGE
This refers to conservation of electrons.
#define VCS_SPECIES_ZEROEDSS
Species is a SS phase, that is currently zeroed out.
#define VCS_DELETE_PHASE_CUTOFF
Cutoff relative moles below which a phase is deleted from the equilibrium problem.
#define VCS_SMALL_MULTIPHASE_SPECIES
Relative value of multiphase species mole number for a multiphase species which is small.
#define VCS_ELEM_TYPE_CHARGENEUTRALITY
This refers to a charge neutrality of a single phase.
#define VCS_SPECIES_MINOR
Species is a major species.
#define VCS_DELETE_ELEMENTABS_CUTOFF
Cutoff moles below which a phase or species which comprises the bulk of an element's total concentrat...
#define VCS_PHASE_EXIST_YES
Phase is a normal phase that currently exists.
#define VCS_STATECALC_PHASESTABILITY
State Calculation based on tentative mole numbers for a phase which is currently zeroed,...
#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 C...