Challenge

Week 9 - Senstivity Analysis Assignment

AIM:-

To

  • Write a code that takes all the reactions from the GRI mechanism and calculates 10 most sensitive reactions
  • Show the reaction strings in the order of greatest sensitivity to the least sensitivity.
  • Plot sensitivities vs the reactions

EXPLANATION and CODING APPROACH:-

Sensitivity analysis is the study of how the uncertainty in the output of a marhetical model or system (numerical or otherwise) can be divided and allocated to different sources of uncertainty in its inputs. A related practice is uncertainty analysis, which has a greater focus on uncertainity qualification and prpogation uncertainity; ideally, uncertainty and sensitivity analysis should be run in tandem.

The process of recalculating outcomes under alternative assumptions to determine the impact of a variable under sensitivity analysis can be useful for a range of purposes, including:

  • Testing the robustness of the results of a model or system in the presence of uncertainty.
  • Increased understanding of the relationships between input and output variables in a system or model.
  • Uncertainty reduction, through the identification of model input that cause significant uncertainty in the output and should therefore be the focus of attention in order to increase robustness (perhaps by further research).
  • Searching for errors in the model (by encountering unexpected relationships between inputs and outputs).
  • Model simplification – fixing model input that has no effect on the output, or identifying and removing redundant parts of the model structure.
  • Enhancing communication from modelers to decision makers (e.g. by making recommendations more credible, understandable, compelling or persuasive).
  • Finding regions in the space of input factors for which the model output is either maximum or minimum or meets some optimum criterion
  • In case of calibrating models with large number of parameters, a primary sensitivity test can ease the calibration stage by focusing on the sensitive parameters. Not knowing the sensitivity of parameters can result in time being uselessly spent on non-sensitive ones.
  • To seek to identify important connections between observations, model inputs, and predictions or forecasts, leading to the development of better models

CODING Approach:-

The number of reaction happening is found using the reaction object from gri mechanish. Then the for loop is created for the number of reactions to run sensitivity test wrt temperature for each reaction.

The source coding for sorting in decending order of the sensitivity is obtained from python coding blogs and sorted the sensitivity Then ifrst ten in is seperated and appended in a new variable and plotted.

There are 325 reactions happening and garph will be plotted with an input n

CODE:-

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, name = 'R1')
sim = ct.ReactorNet([r])

reac = gas.reaction_equations()
n_reac = gas.n_reactions
n = 20
S_max = [0]*n_reac
for i in range(n_reac):
	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

states = ct.SolutionArray(gas, extra = 't')

reac_num = np.arange(1,n_reac+1)

for t in np.arange(0, 2e-3, 5e-6):
	sim.advance(t)
	states.append(r.thermo.state, t = 1000*t)

	for j in range(n_reac):
		s = sim.sensitivity('temperature', j)
		if np.abs(s)>np.abs(S_max[j]):
			S_max[j] = s

S_abs = np.abs(S_max)

reac = [a for b, a in sorted(zip(S_abs,reac), reverse=True)]
reac_num = [ a for b, a in sorted(zip(S_abs,reac_num), reverse=True)]
S_max = [a for b, a in sorted(zip(S_abs,S_max), reverse=True)]

max_r = reac[0:n]
max_n = reac_num[0:n]
max_s = S_max[0:n]

plt.figure(1)
plt.grid('on')
plt.barh(max_r, max_s, color = 'green')
plt.gca().invert_yaxis()
plt.xlabel('sensitivity')
plt.ylabel('Reactions')
plt.title('Top {} sensitivity with respect to temperature'.format(n))

plt.figure(2)
plt.subplot(2,2,1)
plt.plot(states.t, states.T)
plt.xlabel('time(ms)')
plt.ylabel('temperature(k)')
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()

Sensitivity Graph for n=10 (reactions)

Molar fraction wrt graph

We can now see the no of reactions with the input of 'n'

Here we are plotting for 10 and 20 reactions and see the sensitivity graphs

Sensitivity Graph for n=20 (reactions)

CONCLUSION:

  • We have plotted and executed the parametric code with the corresponding reactions.
  • The ignition happened after 1 millisecond and completed within 1.5 second which is plotted in the graph.
  • Temperature went high (2750K) at 1m/s and came down after the ignition is completed after 1.5 milli second.
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.