Week 9 - Senstivity Analysis Assignment
Aim
To simulate Sensitivity Analysis for the 10 most sensitve reactions in GRI mechanism with respect to temperature as the parameter.
Sensitivity Analysis
It is a process to get the realationship between the parameters and the output of a model.
Eg Effect of reactions/ Rate on temperature
In the form of ODE ,it is given as follows
`dz/dt = F(z,t;a)`
z is a vector of temperarure and species
`W_(j,i) = dz_j/(da_i)`
where
j is a independent variable.
i is reactions
a net reaction rate multiplier(perturbation factor)
"""
Sensitivity Analysis
"""
import sys
import cantera as ct
import numpy as np
import matplotlib.pyplot as plt
gas = ct.Solution('gri30.xml')
#Temperature K
Temp = 1500
#Pressure atm i.e 101325 Pa
Press = ct.one_atm
#Stiometric Conditions
gas.TPX = Temp,Press,'CH4:1 ,O2:2 ,N2:7.52'
r = ct.IdealGasConstPressureReactor(gas, name='R1')
sim = ct.ReactorNet([r])
reactions = gas.reaction_equations()
n_reactions = gas.n_reactions
# Number of sensitive reaction to be calculated from the total reactions
n = 10
parameter = 'temperature'
sensitivity = [0]*n_reactions
for i in range(n_reactions):
r.add_sensitivity_reaction(i)
sim.rtol = 1.0e-6
sim.atol = 1.0e-15
sim.rtol_sensitivity = 1.0e-6
sim.atol_sensitivity = 1.0e-6
states = ct.SolutionArray(gas,extra = 't')
for t in np.arange(0,2e-3,5e-6):
sim.advance(t)
states.append(r.thermo.state , t=1000*t)
for j in range(n_reactions):
s = sim.sensitivity(parameter,j)
if np.abs(s)>np.abs(sensitivity[j]):
sensitivity[j] = s
reaction_number = np.arange(1,n_reactions+1)
abs_sensitivity = np.abs(sensitivity)
reactions = [a for b , a in sorted(zip(abs_sensitivity,reactions),reverse = True)]
reaction_number =[a for b , a in sorted(zip(abs_sensitivity,reaction_number),reverse = True)]
sensitivity = [a for b , a in sorted(zip(abs_sensitivity,sensitivity),reverse = True)]
n_reactions = reactions[0:n]
n_reaction_number = reaction_number[0:n]
n_sensitivity = sensitivity[0:n]
print('The %d most sensitive reaction are:'%n)
for k in range (n):
log_message = 'Reaction Number = %5d ,Reaction =%30s, Sensitivity =%10.6f' %(n_reaction_number[k], n_reactions[k],n_sensitivity[k])
print(log_message)
n_reactions.reverse()
n_reaction_number.reverse()
n_sensitivity.reverse()
# Plotting the figures
plt.subplot(3,2,1)
plt.plot(states.t,states.T)
plt.xlabel('Time (ms)')
plt.ylabel('Temperature (K)')
plt.subplot(3,2,2)
plt.plot(states.t,states('OH').X)
plt.xlabel('Time (ms)')
plt.ylabel('OH mole Fraction')
plt.subplot(3,2,3)
plt.plot(states.t,states('H').X)
plt.xlabel('Time (ms)')
plt.ylabel('H mole Fraction')
plt.subplot(3,2,4)
plt.plot(states.t,states('CH4').X)
plt.xlabel('Time (ms)')
plt.ylabel('CH4 mole Fraction')
plt.subplot(3,2,5)
plt.plot(states.t,states('O2').X)
plt.xlabel('Time (ms)')
plt.ylabel('O2 mole Fraction')
plt.tight_layout()
plt.figure(2)
plt.title('Sensitivity with respect to Temperature')
plt.barh(n_reactions,n_sensitivity,color= 'r')
plt.xlabel('Sensitivity')
plt.ylabel('Reactions')
plt.tight_layout()
plt.show()
As we can see from the plot for the sensitivity the only few reactions are on the negative side and most of them are on the positive side of the sensitivity. This means that the reactions that are on the positive side of the senstivity coefficient has decreases in the Ignition delay meaning the reaction burns faster. When the reactions has negative sensitivity coefficient there is an increase in the ignition delay meaning it takes time to burn.
This depends upon the equivalance ratio, temperature and pressure of the reactor systems. As for this reactor the the species are in stiochiometric condtions with an equivalance ratio of 1.
For the mole fraction of OH the concentration is 0 but after the reactions takes places the OH mole fraction concentration increases meaning that the combustion has taken place. The mole fraction of H is similair to the the mole fraction of OH initially it is zero but the time progress and the ignition takes place the mole fraction increased at short interval then it decreased. This means that these species where generated after the reations.
As for the mole fraction of CH4 and O2 , initially the mole fraction was high when the reaction started the mole fraction started to decrease which meant that the methane and oxygen where used in the reaction. For temperature it was initially at 1500 K and temperature rised to about more than 2700 K indicating that the combustion has taken place and remaind till the end time 2 milliseconds.