Skip to content

Commit

Permalink
[Thermo] add support for concentration string in findIsomers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ingmar Schoegl committed Sep 24, 2019
1 parent 84a0981 commit ff5a863
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions include/cantera/thermo/Phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,11 @@ class Phase
//! @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.
Expand Down
1 change: 1 addition & 0 deletions interfaces/cython/cantera/_cantera.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ cdef extern from "cantera/thermo/ThermoPhase.h" namespace "Cantera":
void setCaseSensitiveSpecies(cbool)
cbool 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()
Expand Down
2 changes: 2 additions & 0 deletions interfaces/cython/cantera/test/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,8 @@ def test_isomers(self):
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})
Expand Down
8 changes: 6 additions & 2 deletions interfaces/cython/cantera/thermo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,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 [b.decode('utf-8') for b in iso]

Expand Down
5 changes: 5 additions & 0 deletions src/thermo/Phase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,11 @@ vector<std::string> Phase::findIsomers(const compositionMap& compMap) const
return isomersVector;
}

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);
Expand Down

0 comments on commit ff5a863

Please sign in to comment.