[Examples] Add reactor network visualization to mix1.py

This commit is contained in:
Ray Speth 2024-06-15 10:46:27 -04:00 committed by Ray Speth
parent aff6579dc2
commit eec37ffcd8

View File

@ -16,19 +16,23 @@ 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 :doc:`mixing.py <../thermo/mixing>`.
Requires: cantera >= 2.5.0
Requires: cantera >= 3.1.0, graphviz
.. tags:: Python, thermodynamics, reactor network, mixture
"""
import cantera as ct
# %%
# Set up the reactor network
# --------------------------
#
# Use air for stream a.
gas_a = ct.Solution('air.yaml')
gas_a.TPX = 300.0, ct.one_atm, 'O2:0.21, N2:0.78, AR:0.01'
rho_a = gas_a.density
# %%
# Use GRI-Mech 3.0 for stream b (methane) and for the mixer. If it is desired
# to have a pure mixer, with no chemistry, use instead a reaction mechanism
# for gas_b that has no reactions.
@ -36,36 +40,48 @@ gas_b = ct.Solution('gri30.yaml')
gas_b.TPX = 300.0, ct.one_atm, 'CH4:1'
rho_b = gas_b.density
# %%
# Create reservoirs for the two inlet streams and for the outlet stream. The
# upsteam reservoirs could be replaced by reactors, which might themselves be
# upstream reservoirs could be replaced by reactors, which might themselves be
# connected to reactors further upstream. The outlet reservoir could be
# replaced with a reactor with no outlet, if it is desired to integrate the
# composition leaving the mixer in time, or by an arbitrary network of
# downstream reactors.
res_a = ct.Reservoir(gas_a)
res_b = ct.Reservoir(gas_b)
downstream = ct.Reservoir(gas_b)
res_a = ct.Reservoir(gas_a, name='air')
res_b = ct.Reservoir(gas_b, name='fuel')
downstream = ct.Reservoir(gas_b, name='outlet')
# %%
# Create a reactor for the mixer. A reactor is required instead of a
# reservoir, since the state will change with time if the inlet mass flow
# rates change or if there is chemistry occurring.
gas_b.TPX = 300.0, ct.one_atm, 'O2:0.21, N2:0.78, AR:0.01'
mixer = ct.IdealGasReactor(gas_b)
mixer = ct.IdealGasReactor(gas_b, name='mixer')
# create two mass flow controllers connecting the upstream reservoirs to the
# %%
# Create two mass flow controllers connecting the upstream reservoirs to the
# mixer, and set their mass flow rates to values corresponding to
# stoichiometric combustion.
mfc1 = ct.MassFlowController(res_a, mixer, mdot=rho_a*2.5/0.21)
mfc2 = ct.MassFlowController(res_b, mixer, mdot=rho_b*1.0)
# connect the mixer to the downstream reservoir with a valve.
# %%
# Connect the mixer to the downstream reservoir with a valve.
outlet = ct.Valve(mixer, downstream, K=10.0)
sim = ct.ReactorNet([mixer])
# Since the mixer is a reactor, we need to integrate in time to reach steady
# state
# %%
# Get the mixed state
# -------------------
#
# Since the mixer is a reactor, we need to integrate in time to reach steady state.
sim.advance_to_steady_state()
# view the state of the gas in the mixer
print(mixer.thermo.report())
# %%
# Show the network structure
# --------------------------
diagram = sim.draw(print_state=True, species="X")