[Kinetics] Fix duplicate reaction check to handle unchanged species
This commit is contained in:
parent
513b43200c
commit
4c489c175d
3 changed files with 26 additions and 12 deletions
|
|
@ -728,6 +728,10 @@ class TestDuplicateReactions(utilities.CanteraTest):
|
|||
def test_unmatched_duplicate(self):
|
||||
self.check('J')
|
||||
|
||||
def test_nonreacting_species(self):
|
||||
gas = ct.Solution(self.infile, 'K')
|
||||
self.assertEqual(gas.n_reactions, 3)
|
||||
|
||||
|
||||
class TestReaction(utilities.CanteraTest):
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -180,17 +180,23 @@ std::pair<size_t, size_t> Kinetics::checkDuplicates(bool throw_err) const
|
|||
double Kinetics::checkDuplicateStoich(std::map<int, double>& r1,
|
||||
std::map<int, double>& r2) const
|
||||
{
|
||||
auto b = r1.begin(), e = r1.end();
|
||||
int k1 = b->first;
|
||||
std::unordered_set<int> keys; // species keys (k+1 or -k-1)
|
||||
for (auto& r : r1) {
|
||||
keys.insert(r.first);
|
||||
}
|
||||
for (auto& r : r2) {
|
||||
keys.insert(r.first);
|
||||
}
|
||||
int k1 = r1.begin()->first;
|
||||
// check for duplicate written in the same direction
|
||||
doublereal ratio = 0.0;
|
||||
if (r1[k1] && r2[k1]) {
|
||||
ratio = r2[k1]/r1[k1];
|
||||
++b;
|
||||
bool different = false;
|
||||
for (; b != e; ++b) {
|
||||
k1 = b->first;
|
||||
if (!r1[k1] || !r2[k1] || fabs(r2[k1]/r1[k1] - ratio) > 1.e-8) {
|
||||
for (int k : keys) {
|
||||
if ((r1[k] && !r2[k]) ||
|
||||
(!r1[k] && r2[k]) ||
|
||||
(r1[k] && fabs(r2[k]/r1[k] - ratio) > 1.e-8)) {
|
||||
different = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -201,16 +207,14 @@ double Kinetics::checkDuplicateStoich(std::map<int, double>& r1,
|
|||
}
|
||||
|
||||
// check for duplicate written in the reverse direction
|
||||
b = r1.begin();
|
||||
k1 = b->first;
|
||||
if (r1[k1] == 0.0 || r2[-k1] == 0.0) {
|
||||
return 0.0;
|
||||
}
|
||||
ratio = r2[-k1]/r1[k1];
|
||||
++b;
|
||||
for (; b != e; ++b) {
|
||||
k1 = b->first;
|
||||
if (!r1[k1] || !r2[-k1] || fabs(r2[-k1]/r1[k1] - ratio) > 1.e-8) {
|
||||
for (int k : keys) {
|
||||
if ((r1[k] && !r2[-k]) ||
|
||||
(!r1[k] && r2[-k]) ||
|
||||
(r1[k] && fabs(r2[-k]/r1[k] - ratio) > 1.e-8)) {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ make_gas('G', 'G-*')
|
|||
make_gas('H', 'H-*')
|
||||
make_gas('I', 'I-*')
|
||||
make_gas('J', ['C-1', 'F-1', 'I-1']) # unmatched duplicate
|
||||
make_gas('K', 'K-*')
|
||||
|
||||
kf = [1e10, 0, 100]
|
||||
|
||||
|
|
@ -60,3 +61,8 @@ three_body_reaction('O + H2 + M <=> H + OH + M', kf, id='H-2')
|
|||
# Declared duplicate (allowed)
|
||||
reaction('O + H2 <=> H + OH', kf, options='duplicate', id='I-1')
|
||||
reaction('H + OH <=> O + H2', kf, options='duplicate', id='I-2')
|
||||
|
||||
# Not actually duplicates
|
||||
reaction('O + 2 H <=> H2O', kf, id='K-0') # random other reaction
|
||||
reaction('2 OH + H2 <=> H2O2 + H2', kf, id='K-1')
|
||||
reaction('2 OH <=> H2O2', kf, id='K-2')
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue