[Thermo] add support for concentration string in findIsomers

This commit is contained in:
Ingmar Schoegl 2019-09-24 18:03:28 -05:00 committed by Ray Speth
parent 4f42164443
commit 54c12fc59c
5 changed files with 21 additions and 2 deletions

View file

@ -716,6 +716,11 @@ public:
//! @return A vector of species names for matching species.
virtual std::vector<std::string> findIsomers(const compositionMap& compMap) const;
//! Return a vector with isomers names matching a given composition string
//! @param comp String containing a composition map
//! @return A vector of species names for matching species.
virtual std::vector<std::string> findIsomers(const std::string& comp) const;
//! Return the Species object for the named species. Changes to this object
//! do not affect the ThermoPhase object until the #modifySpecies function
//! is called.

View file

@ -185,6 +185,7 @@ cdef extern from "cantera/thermo/ThermoPhase.h" namespace "Cantera":
void setCaseSensitiveSpecies(cbool)
void addSpeciesAlias(string, string) except +translate_exception
vector[string] findIsomers(Composition&) except +translate_exception
vector[string] findIsomers(string) except +translate_exception
double molecularWeight(size_t) except +translate_exception
double meanMolecularWeight()

View file

@ -1145,6 +1145,8 @@ class TestSpecies(utilities.CanteraTest):
self.assertTrue(self.gas.species_index('hydrogen') == 0)
self.gas.X = 'hydrogen:.5, O2:.5'
self.assertNear(self.gas.X[0], 0.5)
with self.assertRaisesRegex(ct.CanteraError, 'Invalid alias'):
self.gas.add_species_alias('H2', 'O2')
with self.assertRaisesRegex(ct.CanteraError, 'Unable to add alias'):
self.gas.add_species_alias('spam', 'eggs')
@ -1152,6 +1154,8 @@ class TestSpecies(utilities.CanteraTest):
gas = ct.Solution('nDodecane_Reitz.yaml')
iso = gas.find_isomers({'C':4, 'H':9, 'O':2})
self.assertTrue(len(iso) == 2)
iso = gas.find_isomers('C:4, H:9, O:2')
self.assertTrue(len(iso) == 2)
iso = gas.find_isomers({'C':7, 'H':15})
self.assertTrue(len(iso) == 1)
iso = gas.find_isomers({'C':7, 'H':16})

View file

@ -535,8 +535,12 @@ cdef class ThermoPhase(_SolutionBase):
Find species/isomers matching a composition specified by *comp*.
"""
assert isinstance(comp, dict), 'Composition needs to be specified as dictionary'
iso = self.thermo.findIsomers(comp_map(comp))
if isinstance(comp, dict):
iso = self.thermo.findIsomers(comp_map(comp))
elif isinstance(comp, (str, bytes)):
iso = self.thermo.findIsomers(stringify(comp))
else:
raise CanteraError('Invalid composition')
return [pystr(b) for b in iso]

View file

@ -881,6 +881,11 @@ vector<std::string> Phase::findIsomers(const compositionMap& compMap) const
return isomerNames;
}
vector<std::string> Phase::findIsomers(const std::string& comp) const
{
return findIsomers(parseCompString(comp));
}
shared_ptr<Species> Phase::species(const std::string& name) const
{
size_t k = speciesIndex(name);