Skip to content

Commit

Permalink
[Python] Add Quantity.set_equivalence_ratio and set_mixture_fraction
Browse files Browse the repository at this point in the history
Fixes #1446
  • Loading branch information
speth committed Jun 29, 2023
1 parent 6f1d242 commit d3a545e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions interfaces/cython/cantera/composite.py
Expand Up @@ -302,6 +302,20 @@ def equilibrate(self, XY=None, *args, **kwargs):
self.phase.equilibrate(XY, *args, **kwargs)
self.state = self._phase.state

def set_equivalence_ratio(self, phi, fuel, oxidizer, basis="mole", *, diluent=None,
fraction=None):
self._phase.state = self.state
self._phase.set_equivalence_ratio(phi, fuel, oxidizer, basis, diluent=diluent,
fraction=fraction)
self.state = self._phase.state
set_equivalence_ratio.__doc__ = Solution.set_equivalence_ratio.__doc__

def set_mixture_fraction(self, mixture_fraction, fuel, oxidizer, basis='mole'):
self._phase.state = self.state
self._phase.set_mixture_fraction(mixture_fraction, fuel, oxidizer, basis)
self.state = self._phase.state
set_mixture_fraction.__doc__ = Solution.set_mixture_fraction.__doc__

def __imul__(self, other):
self.mass *= other
return self
Expand Down
17 changes: 17 additions & 0 deletions test/python/test_thermo.py
Expand Up @@ -1639,6 +1639,23 @@ def test_extensive(self):
self.assertNear(q1.entropy, q1.S)
self.assertNear(q1.gibbs, q1.G)

def test_set_equivalence_ratio(self):
q1 = ct.Quantity(self.gas, mass=3)
T1, P1 = q1.TP
q1.set_equivalence_ratio(2.0, 'CH4:1.0', 'O2:1.0, N2:3.76')
assert q1.T == approx(T1)
assert q1.P == approx(P1)
assert q1.X[q1.species_index('CH4')] == approx(1.0 / (1 + 4.76))

def test_set_mixture_fraction(self):
q1 = ct.Quantity(self.gas, mass=3)
T1, P1 = q1.TP
q1.set_mixture_fraction(1.0, 'CH3OH:1.0', 'O2:1.0, N2:3.76')
assert q1.T == approx(T1)
assert q1.P == approx(P1)
assert q1.mass == 3
assert q1.X[q1.species_index('CH3OH')] == approx(1.0)

def test_basis(self):
q1 = ct.Quantity(self.gas, mass=5)
T1, P1 = q1.TP
Expand Down

0 comments on commit d3a545e

Please sign in to comment.