From 6065f17b45a88819f25742f7d5bae80dea1295ed Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Mon, 19 May 2008 21:21:40 +0000 Subject: [PATCH] Modified the algorithm to produce less minor-major species swaps. --- Cantera/src/equil/vcs_inest.cpp | 8 +-- Cantera/src/equil/vcs_solve.h | 6 +-- Cantera/src/equil/vcs_solve_TP.cpp | 78 ++++++++++++++++++++++-------- 3 files changed, 64 insertions(+), 28 deletions(-) diff --git a/Cantera/src/equil/vcs_inest.cpp b/Cantera/src/equil/vcs_inest.cpp index c2035bf90..7a2a8a8fd 100644 --- a/Cantera/src/equil/vcs_inest.cpp +++ b/Cantera/src/equil/vcs_inest.cpp @@ -40,8 +40,8 @@ namespace VCSnonideal { * @param ss ss[j] = Gramm-Schmidt orthog work space (ne in length) * @param test This is a small negative number. */ - void VCS_SOLVE::inest(double * const aw, double * const sa, double * const sm, - double * const ss, double test) { + void VCS_SOLVE::vcs_inest(double * const aw, double * const sa, double * const sm, + double * const ss, double test) { int conv, k, lt, ikl, kspec, iph, irxn; double s; double s1 = 0.0; @@ -448,8 +448,8 @@ namespace VCSnonideal { plogendl(); } #endif - inest(VCS_DATA_PTR(aw), VCS_DATA_PTR(sa), VCS_DATA_PTR(sm), - VCS_DATA_PTR(ss), test); + vcs_inest(VCS_DATA_PTR(aw), VCS_DATA_PTR(sa), VCS_DATA_PTR(sm), + VCS_DATA_PTR(ss), test); /* * Calculate the elemental abundances */ diff --git a/Cantera/src/equil/vcs_solve.h b/Cantera/src/equil/vcs_solve.h index c75a6e2d6..050c499b5 100644 --- a/Cantera/src/equil/vcs_solve.h +++ b/Cantera/src/equil/vcs_solve.h @@ -799,8 +799,8 @@ private: * @param ss ss[j] = Gramm-Schmidt orthog work space (ne in length) * @param test This is a small negative number. */ - void inest(double * const aw, double * const sa, double * const sm, - double * const ss, double test); + void vcs_inest(double * const aw, double * const sa, double * const sm, + double * const ss, double test); @@ -1401,7 +1401,7 @@ public: * - 3 one line per every successful solve_TP calculation * - 4 one line for every successful operation -> solve_TP gets a summary report * - 5 each iteration in solve_TP gets a report with one line per species - * - 6 Each decision in solve_TP gets a line in addition to 4 + * - 6 Each decision in solve_TP gets a line per species in addition to 4 * - 10 Additionally Hessian matrix is printed out * * Levels of printing above 4 are only accessible when DEBUG_MODE is turned on diff --git a/Cantera/src/equil/vcs_solve_TP.cpp b/Cantera/src/equil/vcs_solve_TP.cpp index b7ad2e8a1..f25b33a39 100644 --- a/Cantera/src/equil/vcs_solve_TP.cpp +++ b/Cantera/src/equil/vcs_solve_TP.cpp @@ -314,23 +314,59 @@ namespace VCSnonideal { /************** EVALUATE INITIAL MAJOR-MINOR VECTOR **********************/ /*************************************************************************/ m_numRxnMinorZeroed = 0; +#ifdef DEBUG_MODE + if (m_debug_print_lvl >= 2) { + plogf(" --- MAJOR-MINOR decision is reavaluated: All species are minor except for:\n"); + } else if (m_debug_print_lvl >= 5) { + plogf(" --- MAJOR-MINOR decision is reavaluated"); + plogendl(); + } +#endif + for (irxn = 0; irxn < m_numRxnRdc; ++irxn) { kspec = m_indexRxnToSpecies[irxn]; m_rxnStatus[irxn] = vcs_species_type(kspec); - if (m_rxnStatus[irxn] == VCS_SPECIES_MINOR) { - m_rxnStatus[irxn] = VCS_SPECIES_MAJOR; -#ifdef DEBUG_MODE - if (m_debug_print_lvl >= 2) { - plogf(" --- Minor species changed to major: "); - plogf("%-12s", m_speciesName[kspec].c_str()); - plogendl(); +#ifdef DEBUG_MODE + if (m_debug_print_lvl >= 2) { + if (m_rxnStatus[irxn] != VCS_SPECIES_MINOR) { + switch (m_rxnStatus[irxn]) { + case VCS_SPECIES_MAJOR: + plogf(" --- Major Species : %-s\n", m_speciesName[kspec].c_str()); + break; + case VCS_SPECIES_ZEROEDPHASE: + plogf(" --- Zeroed-Phase Species : %-s\n", m_speciesName[kspec].c_str()); + break; + case VCS_SPECIES_ZEROEDMS: + plogf(" --- Zeroed-MS Phase Species: %-s\n", m_speciesName[kspec].c_str()); + break; + case VCS_SPECIES_ZEROEDSS: + plogf(" --- Zeroed-SS Phase Species: %-s\n", m_speciesName[kspec].c_str()); + break; + case VCS_SPECIES_DELETED: + plogf(" --- Deleted-Small Species : %-s\n", m_speciesName[kspec].c_str()); + break; + case VCS_SPECIES_INTERFACIALVOLTAGE: + plogf(" --- InterfaceVoltage Species: %-s\n", m_speciesName[kspec].c_str()); + break; + default: + plogf(" --- Unknown type - ERROR %d\n", m_rxnStatus[irxn]); + plogendl(); + std::exit(-1); + } } -#endif } +#endif if (m_rxnStatus[irxn] != VCS_SPECIES_MAJOR) { ++m_numRxnMinorZeroed; } } +#ifdef DEBUG_MODE + if (m_debug_print_lvl >= 2) { + plogf(" ---"); + plogendl(); + } +#endif + im = (m_numRxnMinorZeroed == m_numRxnRdc); lec = FALSE; if (! vcs_elabcheck(0)) { @@ -781,21 +817,21 @@ namespace VCSnonideal { * we can't call vcs_species_type() because the phase moles * would be wrong. */ - if (m_molNumSpecies_new[kspec] < 0.005 * m_totalMolNum) { - iph = m_phaseID[kspec]; - if (m_molNumSpecies_new[kspec] < (m_tPhaseMoles_old[iph] * 0.01)) { + // if (m_molNumSpecies_new[kspec] < 0.005 * m_totalMolNum) { + //iph = m_phaseID[kspec]; + //if (m_molNumSpecies_new[kspec] < (m_tPhaseMoles_old[iph] * 0.01)) { #ifdef DEBUG_MODE - if (m_debug_print_lvl >= 2) { - plogf(" --- Major species changed to minor: "); - plogf("%-12s", m_speciesName[kspec].c_str()); - plogendl(); - } + //if (m_debug_print_lvl >= 2) { + // plogf(" --- Major species changed to minor: "); + // plogf("%-12s", m_speciesName[kspec].c_str()); + // plogendl(); + //} #endif - m_rxnStatus[irxn] = VCS_SPECIES_MINOR; - ++m_numRxnMinorZeroed; - im = (m_numRxnMinorZeroed == m_numRxnRdc); - } - } + //m_rxnStatus[irxn] = VCS_SPECIES_MINOR; + //++m_numRxnMinorZeroed; + //im = (m_numRxnMinorZeroed == m_numRxnRdc); + //} + //} } else { /* * Section for single species phases: