Sensitivity analysis
Objective:
To write a code that takes all the GRI mech and calculates 10 most sensitive reactions. Thes sensitivity is calculated with respect to temperature.
Solution:
A python program is written in order to calculate the 10 most sensitive reactions found in GRI mech. A sensitivity analysis is a process performed to get a relationship between the parameter and output model. There are a total of 325 reactions in the GRI mechanism, all of which are considered during the computation of the solution.
A positive sensitivity coefficient indicates that the temperature rise will be greater which also means that the ignition delay is low.
Similarly, a negative temperature coefficient indicates that the temperature will drop which also means that the ignition delay is greater.
Chemists use this information to identify which species affects a particular reaction the most and make changes to it by either increasing or decreasing the concentration of that particular species which in turn leads to the increase or decrease of the ignition delay.
The code for the sensitivity analysis is given below:
import numpy as np
import cantera as ct
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])
new_s = [0]*325
reaction = [0]*10
fire = []
#There are 325 eactions in GRI mech
for i in range (325):
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
#help(sim)
states = ct.SolutionArray(gas, extra = [\'t\'])
for t in np.arange(0,2e-3,5e-6):
sim.advance(t)
for l in range(325):
#Calculating sensitivity woth respect to temperature
s = sim.sensitivity(1,l)
#Checking for max sensitivity at each timestep
if (np.abs(s)>np.abs(new_s[l])):
new_s[l] = s
states.append(r.thermo.state, t = 1000*t)
print(\'%10.3e %10.3f %10.3f %14.6e\' % (sim.time,r.T,r.thermo.P, r.thermo.u,))
#Storing the most sensitve reactions
for z in range(10):
maxi = np.max(new_s)
mini = np.min(new_s)
if np.abs(maxi)>np.abs(mini):
reaction[z] = maxi
fire.append(sim.sensitivity_parameter_name(new_s.index(maxi)))
new_s.remove(maxi)
else:
reaction[z] = mini
fire.append(sim.sensitivity_parameter_name(new_s.index(mini)))
new_s.remove(mini)
#Normalizing the values present in a reaction by dividing it with the sensitivity value of the most sensitive species
reaction[z] = reaction[z]/16.8
for g in range(10):
#To remove the term\'IdealGasConstPressureReactor_1\' term from fire
fire[g] = fire[g].translate({ord(g): None for g in\'IdealGasConstPressureReactor_1:\'})
#Printing the most sensitive reactions
print(fire[g],\'\\t\', reaction[g])
plt.subplot(221)
plt.plot(states.t, states.T)
plt.xlabel(\'Time(ms)\')
plt.ylabel(\'Tmeperature (k)\')
plt.subplot(222)
plt.plot(states.t, states(\'OH\').X)
plt.xlabel(\'time(ms)\')
plt.ylabel(\'Oh mole fraction\')
plt.subplot(223)
plt.plot(states.t, states(\'H\').X)
plt.xlabel(\'time (ms)\')
plt.ylabel(\'H mole fraction\')
plt.subplot(224)
plt.plot(states.t, states(\'CH4\').X)
plt.xlabel(\'Time(ms)\')
plt.ylabel(\'CH4 mole fraction\')
plt.tight_layout()
plt.figure(2)
plt.title(\'Most sensitive reactions\')
plt.barh(fire, reaction)
plt.xlabel(\'Temperature sensitivity\')
plt.tight_layout()
plt.show()
Through this program, we are able to calculate the ignition delay, concentrations of OH, H and CH4. Additionally, the top 10 most sensitive species is computed with respect to temperature.
Outputs:
The normalized sensitivity values are given down below.
Normalized values:
H3 + O2 <=> H3O + O 1.0028272310989708
H3 + H2O2 <=> H4 + HO2 -0.8106119368089669
H + O2 <=> O + OH 0.7799825915266906
H3 + H (+M) <=> H4 (+M) -0.6045978727260343
H2(S) + O2 <=> H2O + O 0.4035653127973194
H2 + HO2 <=> H2O + OH 0.3732414476502643
H2(S) + O2 <=> H2O + O 0.2586494767491564
2H6 + H2(S) <=> 2H5 + H3 0.23982050096878407
H2O + O2 <=> HO + HO2 0.2396585557538015
2 HO2 <=> H2O2 + O2 0.20458680666160198
Inference:
From the sensitivity analysis, it is observed that the reaction leading to the formation of H30 and O has the greatest +ve sensitivity followed by the reaction leading to the formation of OH. The reaction leading to the formation of H4 and ho2 has the greatest -ve sensitivity. These values help us identify the ignition delay. Knowing these values helps us optimize the solution to our requirement by changing the concentration of the reacting species.