Hi all.
I'm currently learning to use cantera, and I wanted to study the behavior of a well-stirred reactor while varing the residence time.
I'm using the code posted below. For various residence times, it plots the combustor temperature and the heat that is released. I also wanted to get the molar fraction of certain species after the combustion as a function of the residence time. How could I do so for the different products? Thanks in advance, the code is posted below.
# Create the combustor, and fill it initially with a mixture consisting of the
# equilibrium products of the inlet mixture. This state corresponds to the state
# the reactor would reach with infinite residence time, and thus provides a good
# initial condition from which to reach a steady-state solution on the reacting
# branch.
gas.equilibrate('HP')
combustor = ct.IdealGasReactor(gas)
combustor.volume = 1
# Create a reservoir for the exhaust
exhaust = ct.Reservoir(gas)
# Use a variable mass flow rate to keep the residence time in the reactor
# constant (residence_time = mass / mass_flow_rate). The mass flow rate function
# can access variables defined in the calling scope, including state variables
# of the Reactor object (combustor) itself.
def mdot(t):
return combustor.mass / residence_time
inlet_mfc = ct.MassFlowController(inlet, combustor, mdot=mdot)
# A PressureController has a baseline mass flow rate matching the 'master'
# MassFlowController, with an additional pressure-dependent term. By explicitly
# including the upstream mass flow rate, the pressure is kept constant without
# needing to use a large value for 'K', which can introduce undesired stiffness.
outlet_mfc = ct.PressureController(combustor, exhaust, primary=inlet_mfc, K=0.01)
# the simulation only contains one reactor
sim = ct.ReactorNet([combustor])
# Run a loop over decreasing residence times, until the reactor is extinguished,
# saving the state after each iteration.
states = ct.SolutionArray(gas, extra=['tres'])
residence_time = 5.0 # starting residence time
while combustor.T > 500:
sim.initial_time = 0.0 # reset the integrator
sim.advance_to_steady_state()
print('tres = {:.2e}; T = {:.1f}'.format(residence_time, combustor.T))
states.append(combustor.thermo.state, tres=residence_time)
residence_time *= 0.9 # decrease the residence time for the next iteration
# Plot results
f, ax1 = plt.subplots(1, 1)
ax1.plot(states.tres, states.heat_release_rate, '.-', color='C0')
ax2 = ax1.twinx()
ax2.plot(states.tres[:-1], states.T[:-1], '.-', color='C1')
ax1.set_xlabel('residence time [s]')
ax1.set_ylabel('heat release rate [W/m$^3$]', color='C0')
ax2.set_ylabel('temperature [K]', color='C1')
f.tight_layout()
plt.show()