Senstivity Analysis
Objective:
In this assignment, we will be writing a Python/Cantera Code to find the 10 most sensitive reactions out of all the reactions in the GRI3.0 mechanism. The main parameters of this assignment are given below:
- Write a code that takes all the reactions from the GRI mechanism and calculates 10 most sensitive reactions
- The sensitivity parameter should be with respect to the Temperature
- The program should show the reaction strings in the order of greatest sensitivity to the least sensitivity
Sensitivity Analysis
The correct description of chemical changes requires the application of reaction mechanisms consist of several hundred or thousand reactions. This means that the chemistry of the combustion process is described by a huge number of parameters and hence the application of the sensitivity analysis techniques is very useful for its understanding.
Application of sensitivity analysis in combustion chemistry is are usually related to either the huge size and complexity of combustion models or the high uncertainty of their parameters. Sensitivity analysis can be applied for the analysis of combustion chemical models. Such an analysis reveals which are the main control parameters in the model, which are the indirect effects of parameter changes and provides information about the structure of the model. Detailed chemical models are too big for many practical combustion simulations. Sensitivity analysis can be used for mechanism reduction, that is, finding a smaller model that produces similar predictions for some of the variables (i.e., species concentrations and temperature).
Sensitivity Analysis is a set of processes to get a relationship between the parameters and the output model. The main aim of this process is to calculate the ignition delay in the combustion and sensitivity analysis tells which reaction causes more sensitivity ignition delay and we can adjust the mechanism reaction tuning.
In this case, the GRI3.0 mechanism is used for the study of sensitivity analysis, which contains 325 reactions. The analysis performs the sensitivity of reactions against the temperature. The transient implicit scheme is used to solve the whole mechanism and once all reactions state is solved, the sensitivity of the top 10 reactions is plotted on the bar graph.
The reactor mechanism is used which helps to solve the state of the reactions and properties of the gas like temperature, enthalpy, entropy, internal energy, etc. As the scheme is transient, sufficient timestep is chosen to advance the time in each iteration which gives better control of the analysis. The sensitivities at all timestep is a huge data to manage, so only maximum sensitivity value is chosen at a corresponding temperature which would help to plot the top 10 sensitive reactions.
The code to perform the analysis is,
from cantera import*
from numpy import*
from sys import*
from matplotlib.pyplot import*
import os
# Constant Pressure adiabatic kinetic simulation with sensitivity analysis.
gas = Solution('gri30.xml')
temp = 1500.0
press = one_atm
n = 325 # Number of reaction in GRI3.0
gas.TPX = temp,press,{'CH4':1, 'O2':2,'N2':7.52} #Methane is used as a fuel
r = IdealGasConstPressureReactor(gas,name='R1')
sim = ReactorNet([r])
s_min = [0]*325
reaction = [0]*20
react = []
flame = []
sensitivity_list = []
n_reaction = []
# Sensitivity of the first all Reactions
for i in range(n):
r.add_sensitivity_reaction(i)
# Set the tolerance for the solution and for the sensitivity coefficients.
sim.rtol = 1.0e-6 # Relative change in solution should be less than this tolerence.
sim.atol = 1.0e-15 # Absolute change in solution should be less than this tolerence.
sim.rtol_sensitivity = 1.0e-6 #Relative change in sensitivity should be less than this tolerence.
sim.atol_sensitivity = 1.0e-6 #Absolute change in sensitivity should be less than this tolerence.
states = SolutionArray(gas, extra=['t'])
for t in arange(0,2e-3,5e-6):
sim.advance(t)
for j in range(n):
s = sim.sensitivity(1, j) # 1 express the temperature and j is a reaction number.
if abs(s)>abs(s_min[j]): # Condition to choose high sensitive reaction at corrosponding time.
s_min[j] = s
states.append(r.thermo.state, t = 1000*t)
print('{:10.3e} {:10.3f} {:10.3f} {:14.6e}'.format(sim.time, r.T, r.thermo.P, r.thermo.u))
k = linspace(1,n,n)
sensitivity_list = (tuple(zip(k,s_min))) # Compile the reaction data and corrosponding sensitivity value.
sensitivity_list_max = sorted(sensitivity_list, key=lambda sensitivity_list:-sensitivity_list[1]) # Sorting the sensitivities in descending order.
# Select the top 10 highly sensitivies reaction against the temperature.
names = []
sensitive_value = []
for l in range(10):
n_reaction1 = sensitivity_list_max[l]
n_reaction2 = int(n_reaction1[0])
n_reaction.append(n_reaction2)
n_reaction3 = int(n_reaction1[1])
sensitive_value.append(n_reaction3)
# Take out reaction string for GRI3.0 File.
os.chdir('C:\Program Files\Cantera\data')
for i in (n_reaction):
k=str(int(i))
#k = str(155)
file = open('gri30.cti','r')
ct = 1
ct1 = 1
j=0
for line in file:
if 'Reaction' in line:
if k in line:
j = ct
ct = ct+1
file = open('gri30.cti','r')
for line in file:
if 'reaction(' in line:
ct1 = ct1+1
if ct1 == j:
names.append(line.split('"')[1])
#Plot the results
subplot(2,2,1)
plot(states.t, states.T)
xlabel('Time (ms)')
ylabel('Temperature (K)')
suptitle('Temperature and Mole Fraction in Reactor')
subplot(2,2,2)
plot(states.t, states('OH').X)
xlabel('Time (ms)')
ylabel('OH Mole Fraction')
subplot(2,2,3)
plot(states.t, states('H').X)
xlabel('Time (ms)')
ylabel('H Mole Fraction')
subplot(2,2,4)
plot(states.t, states('CH4').X)
xlabel('Time (ms)')
ylabel('CH4 Mole Fraction')
tight_layout()
x = linspace(0,9,10)
figure(2)
barh(x,sensitive_value)
yticks(x,names)
title('Sensitivities for GRI 3.0')
tight_layout()
show()
Plots are:
The plot gives us a pictorial representation of the top ten sensitive reactions for Temperature in the GRI3.0 mechanism. The results showed that `CH_3 +0_2 iff CH_3O+O`reaction has the highest temperature sensitivity and likewise, the other 9 reaction allows to have better control over which parameters to control to get the desired result.