Consolidate duplicate species checks in Phase::addSpecies
This commit is contained in:
parent
e49f843797
commit
11f6c2f993
5 changed files with 14 additions and 30 deletions
|
|
@ -585,8 +585,6 @@ class species(object):
|
|||
global _enames
|
||||
_species.append(self)
|
||||
global _speciesnames
|
||||
if name in _speciesnames:
|
||||
raise CTI_Error('species '+name+' multiply defined.')
|
||||
_speciesnames.append(name)
|
||||
for e in self._atoms.keys():
|
||||
_enames[e] = 1
|
||||
|
|
@ -1783,8 +1781,6 @@ class phase(object):
|
|||
self._sp.append(('', spnames))
|
||||
|
||||
for s in spnames.split():
|
||||
if s != 'all' and s in self._spmap:
|
||||
raise CTI_Error('Multiply-declared species '+s+' in phase '+self._name)
|
||||
self._spmap[s] = self._dim
|
||||
|
||||
self._rxns = reactions
|
||||
|
|
|
|||
|
|
@ -427,7 +427,7 @@ class CtmlConverterTest(utilities.CanteraTest):
|
|||
except RuntimeError as e:
|
||||
err = e
|
||||
|
||||
self.assertIn('Multiply-declared species', err.args[0])
|
||||
self.assertIn('already contains', err.args[0])
|
||||
|
||||
def test_noninteger_atomicity(self):
|
||||
gas = ct.Solution('../data/noninteger-atomicity.cti')
|
||||
|
|
|
|||
|
|
@ -621,6 +621,11 @@ class TestThermoPhase(utilities.CanteraTest):
|
|||
gc.collect()
|
||||
self.phase.add_species(ref.species('CH2O'))
|
||||
|
||||
def test_add_species_duplicate(self):
|
||||
species = self.phase.species('H2O2')
|
||||
with self.assertRaises(RuntimeError):
|
||||
self.phase.add_species(species)
|
||||
|
||||
|
||||
class TestThermo(utilities.CanteraTest):
|
||||
def setUp(self):
|
||||
|
|
|
|||
|
|
@ -757,6 +757,11 @@ size_t Phase::addElement(const std::string& symbol, doublereal weight,
|
|||
}
|
||||
|
||||
bool Phase::addSpecies(shared_ptr<Species> spec) {
|
||||
if (m_species.find(spec->name) != m_species.end()) {
|
||||
throw CanteraError("Phase::addSpecies",
|
||||
"Phase '{}' already contains a species named '{}'.",
|
||||
m_name, spec->name);
|
||||
}
|
||||
m_species[spec->name] = spec;
|
||||
vector_fp comp(nElements());
|
||||
for (const auto& elem : spec->composition) {
|
||||
|
|
|
|||
|
|
@ -190,16 +190,7 @@ static void formSpeciesXMLNodeList(std::vector<XML_Node*> &spDataNodeList,
|
|||
spnames.resize(nsp);
|
||||
for (size_t nn = 0; nn < nsp; nn++) {
|
||||
string stemp = (*allsp[nn])["name"];
|
||||
bool skip = false;
|
||||
if (declared[stemp]) {
|
||||
if (sprule[jsp] >= 10) {
|
||||
skip = true;
|
||||
} else {
|
||||
throw CanteraError("ThermoFactory::formSpeciesXMLNodeList()",
|
||||
"duplicate species: \"" + stemp + "\"");
|
||||
}
|
||||
}
|
||||
if (!skip) {
|
||||
if (!declared[stemp] || sprule[jsp] < 10) {
|
||||
declared[stemp] = true;
|
||||
spNamesList.push_back(stemp);
|
||||
spDataNodeList.push_back(allsp[nn]);
|
||||
|
|
@ -212,11 +203,7 @@ static void formSpeciesXMLNodeList(std::vector<XML_Node*> &spDataNodeList,
|
|||
spnames.resize(nsp);
|
||||
for (size_t nn = 0; nn < nsp; nn++) {
|
||||
string stemp = (*allsp[nn])["name"];
|
||||
bool skip = false;
|
||||
if (declared[stemp]) {
|
||||
skip = true;
|
||||
}
|
||||
if (!skip) {
|
||||
if (!declared[stemp]) {
|
||||
declared[stemp] = true;
|
||||
spNamesList.push_back(stemp);
|
||||
spDataNodeList.push_back(allsp[nn]);
|
||||
|
|
@ -231,16 +218,7 @@ static void formSpeciesXMLNodeList(std::vector<XML_Node*> &spDataNodeList,
|
|||
}
|
||||
for (size_t k = 0; k < nsp; k++) {
|
||||
string stemp = spnames[k];
|
||||
bool skip = false;
|
||||
if (declared[stemp]) {
|
||||
if (sprule[jsp] >= 10) {
|
||||
skip = true;
|
||||
} else {
|
||||
throw CanteraError("ThermoFactory::formSpeciesXMLNodeList()",
|
||||
"duplicate species: \"" + stemp + "\"");
|
||||
}
|
||||
}
|
||||
if (!skip) {
|
||||
if (!declared[stemp] || sprule[jsp] < 10) {
|
||||
declared[stemp] = true;
|
||||
// Find the species in the database by name.
|
||||
auto iter = speciesNodes.find(stemp);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue