[Thermo] add support for concentration string in findIsomers
This commit is contained in:
parent
4f42164443
commit
54c12fc59c
5 changed files with 21 additions and 2 deletions
|
|
@ -716,6 +716,11 @@ public:
|
||||||
//! @return A vector of species names for matching species.
|
//! @return A vector of species names for matching species.
|
||||||
virtual std::vector<std::string> findIsomers(const compositionMap& compMap) const;
|
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
|
//! Return the Species object for the named species. Changes to this object
|
||||||
//! do not affect the ThermoPhase object until the #modifySpecies function
|
//! do not affect the ThermoPhase object until the #modifySpecies function
|
||||||
//! is called.
|
//! is called.
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,7 @@ cdef extern from "cantera/thermo/ThermoPhase.h" namespace "Cantera":
|
||||||
void setCaseSensitiveSpecies(cbool)
|
void setCaseSensitiveSpecies(cbool)
|
||||||
void addSpeciesAlias(string, string) except +translate_exception
|
void addSpeciesAlias(string, string) except +translate_exception
|
||||||
vector[string] findIsomers(Composition&) 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 molecularWeight(size_t) except +translate_exception
|
||||||
double meanMolecularWeight()
|
double meanMolecularWeight()
|
||||||
|
|
|
||||||
|
|
@ -1145,6 +1145,8 @@ class TestSpecies(utilities.CanteraTest):
|
||||||
self.assertTrue(self.gas.species_index('hydrogen') == 0)
|
self.assertTrue(self.gas.species_index('hydrogen') == 0)
|
||||||
self.gas.X = 'hydrogen:.5, O2:.5'
|
self.gas.X = 'hydrogen:.5, O2:.5'
|
||||||
self.assertNear(self.gas.X[0], 0.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'):
|
with self.assertRaisesRegex(ct.CanteraError, 'Unable to add alias'):
|
||||||
self.gas.add_species_alias('spam', 'eggs')
|
self.gas.add_species_alias('spam', 'eggs')
|
||||||
|
|
||||||
|
|
@ -1152,6 +1154,8 @@ class TestSpecies(utilities.CanteraTest):
|
||||||
gas = ct.Solution('nDodecane_Reitz.yaml')
|
gas = ct.Solution('nDodecane_Reitz.yaml')
|
||||||
iso = gas.find_isomers({'C':4, 'H':9, 'O':2})
|
iso = gas.find_isomers({'C':4, 'H':9, 'O':2})
|
||||||
self.assertTrue(len(iso) == 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})
|
iso = gas.find_isomers({'C':7, 'H':15})
|
||||||
self.assertTrue(len(iso) == 1)
|
self.assertTrue(len(iso) == 1)
|
||||||
iso = gas.find_isomers({'C':7, 'H':16})
|
iso = gas.find_isomers({'C':7, 'H':16})
|
||||||
|
|
|
||||||
|
|
@ -535,8 +535,12 @@ cdef class ThermoPhase(_SolutionBase):
|
||||||
Find species/isomers matching a composition specified by *comp*.
|
Find species/isomers matching a composition specified by *comp*.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert isinstance(comp, dict), 'Composition needs to be specified as dictionary'
|
if isinstance(comp, dict):
|
||||||
iso = self.thermo.findIsomers(comp_map(comp))
|
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]
|
return [pystr(b) for b in iso]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -881,6 +881,11 @@ vector<std::string> Phase::findIsomers(const compositionMap& compMap) const
|
||||||
return isomerNames;
|
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
|
shared_ptr<Species> Phase::species(const std::string& name) const
|
||||||
{
|
{
|
||||||
size_t k = speciesIndex(name);
|
size_t k = speciesIndex(name);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue