Challenge

Week 9 - Senstivity Analysis Assignment

Objective:

  • Write a code that takes all the reactions from the GRI mechanism and calculates the 10 most sensitive reactions.
  • The sensitivity parameter should be with respect to the Temperature.

Introduction

Sensitivity analysis is a process to get relationship between the parameters and output of the model. The ignition delay is sensitive to all the reaction parameters and sensitive to reactions. Some reactions are more sensitive and some reactions are less sensitive. The sensitivity analysis gives the sensitivity of different reactions. So that we can tune the reaction mechanism.

Coding approach

For obtaining the sensitivity of different reactions in GRI mechanism with temperature we are using python and cantera.

Initial conditions

Pressure = 1 atm

Temperature= 1500 K

The stoichiometric reaction of combustion of methane is,

CH4+2 (O2+3.76N2)=> CO2+ 2 H2O +7.52 N2

The initial conditions and initial mole fraction are pass into the gas object. 'IdealGasConstPressureReactor' is used in this challenge and a reactor network is created.

'r.add_sensitivity_reaction' is used for adding sensitivity to all the reactions in the GRI mechanism. Absolute and relative tolerance for ODE and Sensitivity is given.

'SolutionArray' is created for storing all the parameters. 'zip' and 'sorted' are used for sorting the most sensitive 10 reactions and its sensitivity values. The plots are created using matplotlib.

Python code

"""
sensitiivty analysis of methane combustion
"""
import sys
import matplotlib.pyplot as plt 
import numpy as np 
import cantera as ct 
#
gas=ct.Solution('gri30.xml')
temp=1500 #k
pres=ct.one_atm
gas.TPX=temp,pres,'CH4:1,O2:2,N2:7.52'
r=ct.IdealGasConstPressureReactor(gas)
sim=ct.ReactorNet([r])
#Number of reactions
N_reac=gas.n_reactions
n=10

for i in range(N_reac):
	r.add_sensitivity_reaction(i)

#tolerance values for species ODE
sim.rtol=1e-6
sim.atol=1e-15
#tolerance values for sensitivity ODE
sim.rtol_sensitivity=1e-6
sim.atol_sensitivity=1e-6

sens=np.zeros(N_reac)
r_names=[]
states=ct.SolutionArray(gas,extra=['t'])

for t in np.arange(0,2e-3,5e-6):
	sim.advance(t)
	for k in range (N_reac):
		
		r_names.append(sim.sensitivity_parameter_name(k))
		s=sim.sensitivity('temperature',k)
		if (np.abs(s)>np.abs(sens[k])):
			sens[k]=s


	states.append(r.thermo.state,t=t*1000)
#sorting sensitivity values	
sensabs=np.abs(sens)
r_names=[a for b,a in sorted(zip(sensabs,r_names),reverse=True)]
sens=[a for b,a in sorted(zip(sensabs,sens),reverse=True)]
#extracting 10 most sensiive reactions and sensitivity values
max_r=r_names[0:n]
max_s=sens[0:n]
for i in range (10):
	max_s[i]=max_s[i]/16.8

#plotting the sensitivity values
plt.figure(1)
plt.barh(max_r,max_s,0.4,color='brown')
plt.xlabel('Temperature sensitivity')
plt.grid(linestyle=':',color='black')
plt.title('Highest temperature sensitive reactions in GRI30 for stoichiometric combustion of methane')

plt.figure(2)
plt.subplot(2,2,1)
plt.plot(states.t,states.T)
plt.xlabel('time(ms)')
plt.ylabel('Temperature')
plt.subplot(2,2,2)
plt.plot(states.t,states('OH').X)
plt.xlabel('Time(ms)')
plt.ylabel('OH mole fraction')
plt.subplot(2,2,3)
plt.plot(states.t,states('H').X)
plt.xlabel('Time(ms)')
plt.ylabel('H mole fraction')
plt.subplot(2,2,4)
plt.plot(states.t,states('CH4').X)
plt.xlabel('Time(ms)')
plt.ylabel('CH4 mole fraction')
plt.tight_layout()

plt.show()

Result

The normalized sensitivity values for the highest temperature sensitive reaction for GRI30 for stoichiometric combustion of methane is given below,

'CH3+O2<=>CH30+O' reaction has the highest positive sensitivity coefficient and 'H3+HO2<=>CH4+O2' has the highest negative sensitivity coefficient. i.e if we increase the reaction rate of 'CH3+O2<=>CH30+O', then it starts burning fast and the temperature rises, ignition delay decreases. Also if we increase the reaction rate of 'H3+HO2<=>CH4+O2', Since it has a negative sensitivity coefficient, the fuel burns slower, and ignition delay increases.

Temperature and mole fraction of different species with time are shown below,

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.