From 8299646059c451eb69b15fa592fb6dde4d5bf2bb Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 5 Aug 2015 17:14:08 -0400 Subject: [PATCH] [Python] Add example demonstrating use of class Quantity --- .../cython/cantera/examples/reactors/mix1.py | 3 ++ .../cython/cantera/examples/thermo/mixing.py | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 interfaces/cython/cantera/examples/thermo/mixing.py diff --git a/interfaces/cython/cantera/examples/reactors/mix1.py b/interfaces/cython/cantera/examples/reactors/mix1.py index 83e7c7f3c..8e32dfacc 100644 --- a/interfaces/cython/cantera/examples/reactors/mix1.py +++ b/interfaces/cython/cantera/examples/reactors/mix1.py @@ -11,6 +11,9 @@ mechanism, species are matched by name. If the upstream reactor contains a species that is not present in the downstream reaction mechanism, it will be ignored. In general, reaction mechanisms for downstream reactors should contain all species that might be present in any upstream reactor. + +Compare this approach for the transient problem to the method used for the +steady-state problem in thermo/mixing.py. """ import cantera as ct diff --git a/interfaces/cython/cantera/examples/thermo/mixing.py b/interfaces/cython/cantera/examples/thermo/mixing.py new file mode 100644 index 000000000..b3394b20b --- /dev/null +++ b/interfaces/cython/cantera/examples/thermo/mixing.py @@ -0,0 +1,35 @@ +""" +Mixing two streams using `Quantity` objects. + +In this example, air and methane are mixed in stoichiometric proportions. This +is a simpler, steady-state version of the example ``reactors/mix1.py``. + +Since the goal is to simulate a continuous flow system, the mixing takes place +at constant enthalpy and pressure. +""" + +import cantera as ct + +gas = ct.Solution('gri30.xml') + +# Stream A (air) +A = ct.Quantity(gas, constant='HP') +A.TPX = 300.0, ct.one_atm, 'O2:0.21, N2:0.78, AR:0.01' + +# Stream B (methane) +B = ct.Quantity(gas, constant='HP') +B.TPX = 300.0, ct.one_atm, 'CH4:1' + +# Set the molar flow rates corresponding to stoichiometric reaction, +# CH4 + 2 O2 -> CO2 + 2 H2O +A.moles = 1 +nO2 = A.X[A.species_index('O2')] +B.moles = nO2 * 0.5 + +# Compute the mixed state +M = A + B +print(M.report()) + +# Show that this state corresponds to stoichiometric combustion +M.equilibrate('TP') +print(M.report())