import cantera as ct
import numpy as np
import matplotlib.pyplot as plt
#######################################################################
# Input Parameters
#######################################################################
# Define input conditions
flow_rate_sccm = 280 # SCCM
pressure = 6 * 101325 # 6 bar in Pa
T_0 = 893 # Standard temperature in K
# Mechanism file (using first mechanism as example to get mean molecular weight)
gas1 = ct.Solution('gri30.cti')
# Convert SCCM to kg/s
flow_rate_m3s = flow_rate_sccm * 1e-6 / 60 # SCCM to m³/s
# flow_rate_kgs = flow_rate_m3s * gas1.density
# Set initial mole fractions
X_initial = {'CH4': 0.0714, 'O2': 0.0714, 'Ar': 0.8571}
# Reactor dimensions
length = 0.7 # 70 cm in meters
diameter = 6e-3 # 6 mm in meters
area = np.pi * (diameter / 2) ** 2
# Resolution: The PFR will be simulated by 'n_steps' time steps or by a chain of 'n_steps' stirred reactors.
n_steps = 200
#####################################################################
# Import the gas model and set the initial conditions
gas1.TPX = T_0, pressure, X_initial
u_0 = flow_rate_m3s / area
# Create a new reactor
r1 = ct.IdealGasConstPressureReactor(gas1)
# Create a reactor network for performing time integration
sim1 = ct.ReactorNet([r1])
#
# Approximate a time step to achieve a similar resolution as in the next method
t_total = length / u_0
print(t_total)
dt = t_total / n_steps
print(dt)
t1 = (np.arange(n_steps) + 1) * dt
print(t1)
z1 = np.zeros_like(t1)
u1 = np.zeros_like(t1)
states1 = ct.SolutionArray(r1.thermo)
for n1, t_i in enumerate(t1):
# Perform time integration
sim1.advance(t_i)
# Compute velocity and transform into space
u1[n1] = flow_rate_kgs / area / r1.thermo.density
z1[n1] = z1[n1 - 1] + u1[n1] * dt if n1 > 0 else u1[n1] * dt
states1.append(r1.thermo.state)
#####################################################################
# Compare Results in matplotlib
#####################################################################
Plot Temperature along reactor length
plt.figure()
plt.plot(z1, states1.T, label='Temperature')
plt.xlabel('Reactor Length (m)')
plt.ylabel('Temperature (K)')
plt.legend()
plt.savefig('pfr_T_z.png')
plt.show()
# Plot Methane (CH4) Mole Fraction along reactor length
plt.figure()
plt.plot(z1, states1.X[:, gas1.species_index('CH4')], label='CH4 Mole Fraction')
plt.xlabel('Reactor Length (m)')
plt.ylabel('CH4 Mole Fraction')
plt.legend()
plt.savefig('pfr_XCH4_z.png')
plt.show()
# Plot Oxygen (O2) Mole Fraction along reactor length
plt.figure()
plt.plot(z1, states1.X[:, gas1.species_index('O2')], label='O2 Mole Fraction')
plt.xlabel('Reactor Length (m)')
plt.ylabel('O2 Mole Fraction')
plt.legend()
plt.savefig('pfr_XO2_z.png')
plt.show()
# Plot Acetylene (C2H2) Mole Fraction along reactor length
plt.figure()
plt.plot(z1, states1.X[:, gas1.species_index('C2H2')], label='C2H2 Mole Fraction')
plt.xlabel('Reactor Length (m)')
plt.ylabel('C2H2 Mole Fraction')
plt.legend()
plt.savefig('pfr_XC2H2_z.png')
plt.show()
# Plot Hydrogen (H2) Mole Fraction along reactor length
plt.figure()
plt.plot(z1, states1.X[:, gas1.species_index('H2')], label='H2 Mole Fraction')
plt.xlabel('Reactor Length (m)')
plt.ylabel('H2 Mole Fraction')
plt.legend()
plt.savefig('pfr_XH2_z.png')
plt.show()
# Plot Carbon Monoxide (CO) Mole Fraction along reactor length
plt.figure()
plt.plot(z1, states1.X[:, gas1.species_index('CO')], label='CO Mole Fraction')
plt.xlabel('Reactor Length (m)')
plt.ylabel('CO Mole Fraction')
plt.legend()
plt.savefig('pfr_XCO_z.png')
plt.show()
# Plot Carbon Dioxide (CO2) Mole Fraction along reactor length
plt.figure()
plt.plot(z1, states1.X[:, gas1.species_index('CO2')], label='CO2 Mole Fraction')
plt.xlabel('Reactor Length (m)')
plt.ylabel('CO2 Mole Fraction')
plt.legend()
plt.savefig('pfr_XCO2_z.png')
plt.show()
Thanks and regards
Archanaa