Week 9 - Senstivity Analysis Assignment
Aim:
Sensitivity analysis of GRI 3.0 mechanism.
Objective:
To write a code that takes all the reaction from GRI mechanism and calculate the 10 most sensitive reactions and the program should show the reaction strings in the order of greatest sensitivity to the least sensitivity.
Plot the graph for sensitivity vs reactions.
Sensitivity analysis:
It is a process to get relationshi[ between the parameters and output of a model.
dz/dt= F(z,t:a)
z=(T,Y1,Y2,...Yk)^T
`w_(j,i) = del(z_(j)/a_i)`
here j is independent variable, i is reaction and a is reaction rate multiplier
where z is a vector of species and temperature.
When we increase or decrease the reaction rate of species we get diffrent curves ,the differences is said to be sensitivity.
If the sensitivity coefficient positive,the reaction is faster,lesser ignition delay and opposite for negative coefficient.
Code:
import cantera as ct
import numpy as np
import matplotlib.pyplot as plt
gas = ct.Solution('gri30.xml')
T=1500
P=ct.one_atm
gas.TPX= T,P,{'CH4':1,'O2':2,'N2':7.52}
r=ct.IdealGasConstPressureReactor(gas)
sim=ct.ReactorNet([r])
#extracting reactions,equations and their numbers from gri mechansim
reactions=gas.reaction_equations()
n=gas.n_reactions
#number of reactions used for sensitive calculation
N=10
for i in range(n):
r.add_sensitivity_reaction(i)
sim.rtol=1e-6
sim.atol=1e-15
sim.rtol_sensitivity=1e-6
sim.atol_sensitivity=1e-6
sT_max=[0]*n
states=ct.SolutionArray(gas,extra=['time'])
reac_num=np.arange(1,n+1)
for t in np.arange(0,2e-3,5e-6):
sim.advance(t)
for j in range(n):
sT=sim.sensitivity('temperature',j)
if abs(sT)>=abs(sT_max[j]):
sT_max[j]=sT
states.append(r.thermo.state,time=t*1e3)
s_abs=np.abs(sT_max)
#sorting the reactions
reactions = [a for b, a in sorted(zip(s_abs,reactions),reverse=True)]
reac_num=[a for b , a in sorted(zip(s_abs,reac_num),reverse=True)]
sT_max= [a for b,a in sorted(zip(s_abs,sT_max),reverse=True)]
#assigning the 10 sensitive values
max_r = reactions[0:N]
max_n = reac_num[0:N]
max_s=sT_max[0:N]
#loop to print top N sensitive reactions
print(str(N)+'most sensitivereactions in GRI3.0 mechanism in '+str(gas.n_reactions)+'reactions are as')
for i in range(N):
print('For reaction ' +str(max_r[i])+'sensitivity is ' +str(max_s[i]))
#plotting
plt.figure(1)
plt.subplot(2,2,1)
plt.plot(states.time,states.T)
plt.xlabel('time_in_ms')
plt.ylabel('Temperature')
plt.subplot(2,2,2)
plt.plot(states.time,states('OH').X)
plt.ylabel('mole fraction of OH')
plt.xlabel('time_in_ms')
plt.subplot(2,2,3)
plt.plot(states.time,states('H').X)
plt.ylabel('mole fraction of H')
plt.xlabel('time_in_ms')
plt.subplot(2,2,4)
plt.plot(states.time,states('CH4').X)
plt.ylabel('mole fraction of CH4')
plt.xlabel('time_in_ms')
#bar graph
plt.figure(2)
plt.barh(max_r,max_s,0.5,color='blue')
plt.xlabel('Reactions')
plt.ylabel('Sensitivity')
plt.title('top 10 sensitive reactions')
plt.gca().invert_yaxis()
plt.tight_layout()
plt.show()
Code Approach:
- At first we import necessary modules and initialize gas instance from gri30 mechanism, initial Temperature of 1500Kand pressure of one atmosphere.
- We create the IdealGasConstPressureReactor for gas instance and Reactor network for simulation.
- Then extract the reactions and the no .of equations from the gri mechansim and add all the sensitivity of reactions of the reactions in the reactor network.
- And we set the abs and rel tolerances for species and the sensitivity and we create solution array.
- We advance in time and find the sensitivity of reactions with respect to temperature and store the top 10 reaction.
- Print the most 10 sensitive reaction values and plot the graph for the species and the time in ms .
- Plot bar graph for the top 10 reactions and the sensitivity.
Plot results:
It shows the top 10 sensitive reactions in GRI 3.0 mechansim :


The bar graph shows the positive and negative sensitivity of top 10 reactions.The positive sensitivity indicates that with increase in reactions parameters, the combustion takes place faster and the auto ignition delay is decreased.
Then negative sensitivity shows that with decrease in reaction parameters,the combustion takes place slower and the auto ignition delay is more or increased.

The above plot shows the plot between time and mole fraction of species like (CH4,H,OH) and Tempearture.