All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM - Sensitivity analysis with respect to temerature for the auto ignition of methane. OBJECTIVE - To write a code that takes all the reaction from the GRI mechanism and calculates the 10 most sensitive reactions. The sensitivity parameter is with respect to the temperature but we will design the code in such a way the…
Amol Patel
updated on 06 Oct 2021
AIM - Sensitivity analysis with respect to temerature for the auto ignition of methane.
OBJECTIVE -
THEORY -
We can easily simulate auto ignition for methane and the ignition delay using cantera as a tool. Reactor class helps to store the information for each state and ReactorNet class that helps to advance and simulate the reaction for each time step. Now we will be analysis the sensitivity of the intermidiate reaction during the combustion of methane with respect to the temperature and this analysis will be done using sensitivity method within the ReactorNet class.
The sensitivity(self,component,int p, int r=0) method/function returns the sensitivity of a solution variable component in a reactor r with respect to parameter p. the component can be a string or interger. also by default r = 0 that is the first reactor.
The step that are followed to code this analysis are as follows:
CODE -
The code for our analysis for the sensitivity with respect to the temperature for the auto ignition of Methane is given below:
"""
Sensitivity analysis code for Methane with respect to temperature
"""
import numpy as np
import cantera as ct
gas = ct.Solution('gri30.xml')
temp = 1500
pres = ct.one_atm
gas.TPX = temp,pres,{'CH4':1,'O2':2,'N2':7.56}
r = ct.IdealGasConstPressureReactor(gas,name = 'R1')
sim = ct.ReactorNet([r])
# enable sensitivity with respect to the rates for all reactions
for i in range(gas.n_reactions):
r.add_sensitivity_reaction(i)
# Setting the tolerance for the solution
sim.rtol = 1e-6 # relative change in solution should be less than this value (relative => Xold - Xnew/Xold)
sim.atol = 1e-15 # absolute change in solution should be less than this value (abs0lute => Xold -X new)
# setting the tolerance for the sensitivity coefficients
sim.rtol_sensitivity = 1e-6 # relative change should be less than this value
sim.atol_sensitivity = 1e-6 # absolute change should be less than this value
# empty array to store sensitivity for each reaction
s =np.zeros(gas.n_reactions)
# empty array to store the maximum sensitivity of each reaction
sens_max = np.zeros(gas.n_reactions)
# empty array to store the reactions
reaction_list = []
# array to store the id of each reaction
reaction_id = np.linspace(1,325,325).astype(int)
# appending the reactions in the reaction_list array
for i in range(gas.n_reactions):
reaction_list.append(sim.sensitivity_parameter_name(i))
# to store the state at each time step
states = ct.SolutionArray(gas, extra = ['t','sens'])
# time loop with time step 5e-6 and total time 2e-3
for t in np.arange(0,2e-3,5e-6):
# simulating using the advance method
sim.advance(t)
# to find the sensitivity with respect to temperature for each reaction
for j in range(gas.n_reactions):
s[j] = sim.sensitivity(r.component_index('temperature'),j)
# to update the maximum value of the sensitivity for each reaction
if np.abs(sens_max[j]) < np.abs(s[j]):
sens_max[j] = s[j]
# appending the state at each time step
states.append(r.thermo.state,t = 1000*t,sens = s)
# using the sorted zip method
# to store the reaction in decreasing order
reac_n = [a for b, a in sorted(zip(np.abs(sens_max),reaction_list), reverse = True)]
# to store the sensitivity in decreasing order
s_max = [a for b, a in sorted(zip(np.abs(sens_max),sens_max), reverse = True)]
# top N sensitive reactions
N=10
# Array to store top N sensitive reactions
max_reactions = reac_n[0:N]
#Array to store top N sensitivities
max_sensitivity = s_max[0:N]
# Loop to print top N sensitive reactions with their sensitivities
print(str(N)+' most sensitive reactions in GRI3.0 mechanism in '+str(gas.n_reactions)+' reactions are as follows:')
for i in range(N):
print('For reaction ' +str(max_reactions[i])+' sensitivity is '+str(max_sensitivity[i]))
# plotting
import matplotlib.pyplot as plt
plt.figure(1)
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('O2').X)
plt.xlabel('time(ms)')
plt.ylabel('O2 mole fraction')
plt.subplot(3,2,5)
plt.plot(states.t,states('CH3').X)
plt.xlabel('time(ms)')
plt.ylabel('CH3 mole fraction')
plt.subplot(3,2,6)
plt.plot(states.t,states('CH4').X)
plt.xlabel('time(ms)')
plt.ylabel('CH4 mole fraction')
plt.tight_layout()
plt.figure(2)
plt.plot(states.t,states.sens)
plt.xlabel('time(ms)')
plt.ylabel('Temperature sensitivity')
plt.figure(3)
plt.gca().invert_yaxis()
plt.barh(range(N), max_sensitivity)
plt.yticks(range(N),max_reactions)
plt.grid()
plt.ylabel('Chemical Reactions')
plt.xlabel('Temperature Sensitivity')
plt.suptitle('Top '+str(N)+' reactions with higher sensitivities')
plt.tight_layout()
plt.show()
Output:
the output window gives us the top 10 sensitive reaction with respect to temperature in decreasing order
and the output plots are shown below:
Plot 1: It gives the temperature and concentration porfiles during the simulation
Plot 2: Plot for the temperature sensitivity for each of the reactions during the simulation
Plot 3: Bar plot that shown the 10 most sensitive reaction with respect to temperature
Now if we want to find the sensitivity with respect to any other parameter we can do it easliy just by changing the parameter in line number 52 and if we want to change the value of N that gives the top N reaction we can tweak it in like number 68 of our code.
Thought we might need to change some title and subtitles in the plotting section but that all needed. So this code is quite intutive and parametric according to our need .
CONCLUSION -
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Week 6: Conjugate Heat Transfer Simulation
AIM- To simulate a Conjugate Heat Transfer flow through a pipe, while the inlet Reynolds number should be 7000. To run the grid independance test on 3 grids and show that the outlet temperature converges to a particular value To observe the effect of various supercycle stage interval on the total simulation time.…
09 Nov 2022 06:55 AM IST
Week 7: Shock tube simulation project
AIM - To set up a transient shock tube simulation Plot the pressure and temperature history in the entire domain Plot the cell count as a function of time SHOCK TUBE- The shock tube is an instrument used to replicate and direct blast waves at a sensor or a model in order to simulate actual explosions…
07 Nov 2022 09:18 PM IST
Week 5: Prandtl Meyer Shock problem
AIM - 1. To understand what is a shock wave. 2. To understand the what are the different boundary conditions used for a shock flow problems. 3. To understand the effect of SGS parameter on shock location. 4. To simulate Prandalt Meyer Shcok Wave. OBJECTIVE - Que 1. What is Shock Wave? A shock wave or shock,…
01 Nov 2022 06:36 PM IST
Week 4.2: Project - Transient simulation of flow over a throttle body
AIM - Transient simulation of flow over a throttle body. OBJECTIVE - Setup and run transient state simulation for flow over a throttle body. Post process the results and show pressure and velocity contours. Show the mesh (i.e surface with edges) Show the plots for pressure, velocity, mass flow rate and total…
12 Feb 2022 07:08 AM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.