Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set_equivalence_ratio to SolutionArray objects #677

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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