Treat duplicate keys in composition strings as errors
For example, 'H2:0.5, O2:0.5, H2:0.1', which would previously have been treated as equivalent to 'O2:0.5, H2:0.1'.
This commit is contained in:
parent
0e4b0cba0f
commit
b38a9332e2
2 changed files with 9 additions and 0 deletions
|
|
@ -133,6 +133,10 @@ class TestThermoPhase(utilities.CanteraTest):
|
|||
self.phase.X = 'H2:1e-1.4'
|
||||
self.assertArrayNear(X0, self.phase.X)
|
||||
|
||||
with self.assertRaises(Exception):
|
||||
self.phase.X = 'H2:0.5, O2:1.0, H2:0.1'
|
||||
self.assertArrayNear(X0, self.phase.X)
|
||||
|
||||
def test_setCompositionDict(self):
|
||||
self.phase.X = {b'H2':1.0, b'O2':3.0}
|
||||
X = self.phase.X
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
#include "cantera/base/stringUtils.h"
|
||||
#include "cantera/base/ctexceptions.h"
|
||||
#include "cantera/base/ctml.h"
|
||||
#include "cantera/base/utilities.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <cstdio>
|
||||
|
|
@ -155,6 +156,10 @@ compositionMap parseCompString(const std::string& ss,
|
|||
throw CanteraError("parseCompString",
|
||||
"unknown species '" + name + "'");
|
||||
}
|
||||
if (getValue(x, name, 0.0) != 0.0) {
|
||||
throw CanteraError("parseCompString",
|
||||
"Duplicate key: '" + name + "'.");
|
||||
}
|
||||
x[name] = fpValueCheck(ss.substr(valstart, stop-colon-1));
|
||||
start = ss.find_first_not_of(", ;\n\t", stop+1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue