From 60b98b362ce2614a6b066e6d830cc77a80b9c79f Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sun, 23 Aug 2015 19:29:49 -0400 Subject: [PATCH] [Kinetics] Prevent positive feedback in negative species concentrations For binary (or higher order) reactions, multiple negative (but small, i.e. with respect to integration tolerances) species concentrations should not produce positive reaction rates that would drive those concentrations to even more negative values. --- include/cantera/kinetics/StoichManager.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/include/cantera/kinetics/StoichManager.h b/include/cantera/kinetics/StoichManager.h index 67ce2c693..9a9fc805e 100644 --- a/include/cantera/kinetics/StoichManager.h +++ b/include/cantera/kinetics/StoichManager.h @@ -220,7 +220,11 @@ public: } void multiply(const doublereal* S, doublereal* R) const { - R[m_rxn] *= S[m_ic0] * S[m_ic1]; + if (S[m_ic0] < 0 && S[m_ic1] < 0) { + R[m_rxn] = 0; + } else { + R[m_rxn] *= S[m_ic0] * S[m_ic1]; + } } void incrementReaction(const doublereal* S, doublereal* R) const { @@ -281,7 +285,12 @@ public: } void multiply(const doublereal* S, doublereal* R) const { - R[m_rxn] *= S[m_ic0] * S[m_ic1] * S[m_ic2]; + if ((S[m_ic0] < 0 && (S[m_ic1] < 0 || S[m_ic2] < 0)) || + (S[m_ic1] < 0 && S[m_ic2] < 0)) { + R[m_rxn] = 0; + } else { + R[m_rxn] *= S[m_ic0] * S[m_ic1] * S[m_ic2]; + } } void incrementReaction(const doublereal* S, doublereal* R) const { @@ -357,12 +366,19 @@ public: void multiply(const doublereal* input, doublereal* output) const { doublereal oo; + int neg_count = 0; for (size_t n = 0; n < m_n; n++) { oo = m_order[n]; if (oo != 0.0) { + if (input[m_ic[n]] < 0) { + neg_count++; + } output[m_rxn] *= ppow(input[m_ic[n]], oo); } } + if (neg_count > 1) { + output[m_rxn] = 0; + } } void incrementSpecies(const doublereal* input,