Skip to content

Commit

Permalink
Add set_equivalence_ratio to SolutionArray objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Ingmar Schoegl committed Aug 6, 2019
1 parent bbdc790 commit c31a351
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
17 changes: 17 additions & 0 deletions interfaces/cython/cantera/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,23 @@ def equilibrate(self, *args, **kwargs):
self._phase.equilibrate(*args, **kwargs)
self._states[index][:] = self._phase.state

def set_equivalence_ratio(self, phi, *args, **kwargs):
"""
See `ThermoPhase.set_equivalence_ratio`
Note that *phi* either needs to be a scalar value or dimensions have
to be matched to the SolutionArray.
"""

# broadcast argument shape
phi, _ = np.broadcast_arrays(phi, self._output_dummy)

# loop over values
for index in self._indices:
self._phase.state = self._states[index]
self._phase.set_equivalence_ratio(phi[index], *args, **kwargs)
self._states[index][:] = self._phase.state

def collect_data(self, cols=('extra','T','density','Y'), threshold=0,
species='Y'):
"""
Expand Down
19 changes: 19 additions & 0 deletions interfaces/cython/cantera/test/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,25 @@ def test_purefluid(self):
states.TP = np.linspace(400, 500, 5), 101325
self.assertArrayNear(states.X.squeeze(), np.ones(5))

def test_set_equivalence_ratio(self):
states = ct.SolutionArray(self.gas, 8)
phi = np.linspace(.5, 2., 8)
args = 'H2:1.0', 'O2:1.0'
states.set_equivalence_ratio(phi, *args)
states.set_equivalence_ratio(phi[0], *args)
states.set_equivalence_ratio(list(phi), *args)

with self.assertRaises(ValueError):
states.set_equivalence_ratio(phi[:-1], *args)

states = ct.SolutionArray(self.gas, (2,4))
states.set_equivalence_ratio(phi.reshape((2,4)), *args)

with self.assertRaises(ValueError):
states.set_equivalence_ratio(phi, *args)
with self.assertRaises(ValueError):
states.set_equivalence_ratio(phi.reshape((4,2)), *args)

def test_species_slicing(self):
states = ct.SolutionArray(self.gas, (2,5))
states.TPX = np.linspace(500, 1000, 5), 2e5, 'H2:0.5, O2:0.4'
Expand Down

0 comments on commit c31a351

Please sign in to comment.