Challenge

Week 7 - Auto ignition using Cantera

import cantera as ct
import matplotlib.pyplot as plt
import numpy as np


gas = ct.Solution('gri30.xml')
T_initial = 1250           # constant temperature,k
P_initial = 101325         # initial pressure
P_final = 5*101325         # final pressure

pressure = np.linspace(P_initial,P_final,5)

t_initial = 0
t_final = 10

time_step = 1e-3

no_time_steps = int((t_final-t_initial)/time_step)  # no. of time steps

states_temperature =[]

t_auto_pressure = []


for p in pressure:


	gas.TPX = T_initial,p,{'CH4':1,'O2':2,'N2':7.52}       #{species_dict}
	r = ct.IdealGasReactor(gas)                    # Reactor
	sim =  ct.ReactorNet([r])                      # Reactor Net
	T_auto =0
	time_auto = 0
	time=0  #  Declaring the time equal to zero before the start of the simulation 
	#States of reactor which contains all attributes of reactor
	states = ct.SolutionArray(gas,extra = ['time_in_ms','t'])
	
	for n in range(no_time_steps):
		time += 1e-3   ## Time shouild be time =time+1e-03==> in programming it can be written as this
		sim.advance(time)
		states.append(r.thermo.state, time_in_ms = time*1e-3, t=time)
	states_temperature.append(states.T)	
		
	for i in range (no_time_steps):
		error = states.T[i]-T_initial-400
		if error >0:
			T_auto = states.T[i]
			time_auto = states.time_in_ms[i]
			break

	t_auto_pressure.append(time_auto)





plt.figure(1)
plt.plot(pressure,t_auto_pressure,'-o')
plt.xlabel('Pressure[pa]')
plt.ylabel('Ignition_Delay[ms]')
plt.show()



states_temperature=np.array(states_temperature)
plt.figure(2)
plt.plot(states.time_in_ms, states_temperature[0 ,:])
plt.plot(states.time_in_ms, states_temperature[1 ,:])
plt.plot(states.time_in_ms, states_temperature[2, :])
plt.plot(states.time_in_ms, states_temperature[3, :])
plt.plot(states.time_in_ms, states_temperature[4, :])
plt.xlabel('time[ms]')
plt.ylabel('Temperature[k]')
plt.show()






import cantera as ct
import matplotlib.pyplot as plt
import numpy as np


gas = ct.Solution('gri30.xml')
P = 5*101325
T_initial = 950
T_final = 1250

Temperature = np.linspace(T_initial,T_final,5)

t_initial = 0
t_final = 10

time_step = 1e-3

no_time_steps = int((t_final-t_initial)/time_step)  # no. of time steps

states_temperature =[]

# Intializing the auto ignition array
t_auto_T = []

for T in Temperature:

	#You have used P and Temperaure instead of Temperature and Pressure during initialization
	#gas.TPX = P,T,{'CH4':1,'O2':2,'N2':7.52}   
	gas.TPX = T,P,{'CH4':1,'O2':2,'N2':7.52}       #{species_dict}
	r = ct.IdealGasReactor(gas)                    # Reactor
	sim =  ct.ReactorNet([r])                      # Reactor Net
	T_auto =0
	time_auto = 0
	time=0                            # Declaring the time equal to zero before the start of the simulation 

	#States of reactor which contains all attributes of reactor
	states = ct.SolutionArray(gas,extra = ['time_in_ms','t'])
	
	for n in range(no_time_steps):
		time += 1e-3                           ## Time shouild be time =time+1e-03==> in programming it can be written as this
		sim.advance(time)
		states.append(r.thermo.state, time_in_ms = time*1e-3, t=time)
	states_temperature.append(states.T)	
		
	for i in range (no_time_steps):
		error = states.T[i] - T - 400

		if error > 0:
			T_auto = states.T[i]
			time_auto = states.time_in_ms[i]
			break

	t_auto_T.append(time_auto)





plt.figure(1)
#Plotting temerature vs auto ignition
plt.plot(Temperature,t_auto_T,'-o')
plt.xlabel('Temperature[k]')
plt.ylabel('Ignition_Delay[ms]')
plt.show()



states_temperature=np.array(states_temperature)
plt.figure(2)
plt.plot(states.time_in_ms, states_temperature[0,:])
plt.plot(states.time_in_ms, states_temperature[1,:])
plt.plot(states.time_in_ms, states_temperature[2, :])
plt.plot(states.time_in_ms, states_temperature[3, :])
plt.plot(states.time_in_ms, states_temperature[4, :])
plt.xlabel('time[ms]')
plt.ylabel('Temperature[k]')
plt.show()






"""
     Calculating Rate of change of concentration of species H2O,OH,OH

"""
import cantera as ct
import matplotlib.pyplot as plt
import numpy as np

gas = ct.Solution('gri30.xml')

Temp = [500,1000]
P = 5*101325

sim_time = 10*1000

for T in Temp:
		gas.TPX = T,P,{'CH4':1,'O2':2,'N2':7.52}       #{species_dict}
		r = ct.IdealGasReactor(gas)                    # Creating an Ideal gas Reactor
		sim =  ct.ReactorNet([r])                      # Creating the simulation objectReactor Net 
		T_old = T 
		time = 0                         # initial time

		states = ct.SolutionArray(gas,extra = ['time_in_ms','t'])   # Creating the states object which sets an array for all properties 
                                                                    # of gas at different steps
		for i in range(sim_time):
				time += 1e-3            # for every 1e-3s, the solution gets calculated
				sim.advance(time)      # integrating the system for given time
				states.append(r.thermo.state, time_in_ms = time*1e-3, t=time)    # appending all the states value


		plt.figure(1)
		plt.plot(states.t,states.X[:,gas.species_index('H2O')])
		plt.xlabel('Time[s]')
		plt.ylabel('Species Concentration[H2O]')

		plt.figure(2)
		plt.plot(states.t,states.X[:,gas.species_index('O2')])
		plt.xlabel('Time[s]')
		plt.ylabel('Species Concentration[O2]')

		plt.figure(3)
		plt.plot(states.t,states.X[:,gas.species_index('OH')])
		plt.xlabel('Time[s]')
		plt.ylabel('Species Concentration[OH]')
		plt.show()




		

Objective :

This project worked on Auto-Ignition and Ignition Delay depending on variation temperature and pressure using Cantera. simulate the Auto Ignition Time for Methane under the following conditions,(simulation time = 10 secs)

  • Plot the variation of Auto Ignition time for Methane with a constant temperature of 1250K and pressure varying from 1 to 5 atm.
  • Plot the variation of Auto Ignition time for Methane with a constant pressure of 5 atm and temperature varying from 950k to 1450k

Further, observe and print the rate of of change of molar concentrations of the given elements "H20,O2,OH" with respect to the time, (simulation time = 10secs)

Explain the behavior of the graph for 2 cases,

  • When Temperature is 1000k and pressure 5 bar
  • When Temperature is 500k and pressure 5 bar

Auto-Ignition :

When the fuel particles auto-ignite. This normally happens after the spark has been introduced. Auto-Ignition depends upon the Self-Ignition temperature, fuel-air mixture ratio, Valve timings, angle of spark plug and initial temperature of the cylinder.

Basically, when we have a high cylinder temperature, the fuel particles are almost near to the their combustion temperature. So,when the spark is introduced, the flame front propagates, this flame boundary further increases the temperature of the fuel molecule,which is already at a high temperature. Keep in mind that the flame has not reached the molecule yet. This high pressure and temperature of the molecule, allows itself to be oxidized/Burn. So,this molecule would have a seperate flame in front of its own,let's call it local flame front. When the main flame front and the local flame front collide , we have a jerk inside the engine. This is what we call knocking.

Ignition Delay :

Ignition delay is the time required for ignition to take place, Ignition delay take depends on temperature,pressure and mixture composition.

Reactor :

A cantera Reactor() represents the simplest form of chemically reacting system.It corrosponds to an extensive thermodynamic control volume V, in which all the state variable are homogeneously distributed. The system is generally unsteady- that all states are function of time. In particular, transient state changes due to chemical reactions are possible .However, thermodynamic (but not chemical) equilibrium is assumed to be present throughout the reactor at all instants of time.

The state variable for cantera's general reactor model are

  • General Reactor() : U, the total internal energy of the reactors contents
  • ConstantPressureReactor(): H, the total enthalpy of the reactors contents
  • IdealGasReactor() and IdeaGasConstantPressureReactor() :T, the temperature

AUTO-IGNITION TEMPERATURE :

Auto ignition temperature is the lowest temperature at which ignition takes place.

Time_(ignition delay) = Time_(initial temperature) + 400k

CODE PROCEDURE (PART 1)

  • Importing all the necessary libraries to python.
  • Creating a Gas object by using solution class of GRI30.xml.
  • Specify the values of temperature,intial pressure and final pressure
  • Create a for loop with a range of pressure array.
  • Giving the values of initial and final time 0 and 10 sec. respectively and execute the value of time step i.e 1e-3. The question is why we using this timestep because in each iteration i need to increament by a every millisecond.
  • Define total number of timestep
  • Execute the empty matrix for states_temperature.
  • Setting up the conditions by using gas.TPX method.
  • Creating a IdealGasReactor with a object name of r and creating a simulation object.
  • Provide the initial time before starting the simulation is 0.
  • Creating the 'states' object which is an array to store all properties at every time step.
  • Using time loop and sim.advance method initializing the simulation by integrating at every 1e-3s
  • Declare the empty matrix of ' states_temperature ' variable.
  • Declaring a for loop of range 1 to 1000 means it will going to exicutes for 1000 times, then storing the value of time i.e 1e-3 or we can say that in each and every iteration the value of time is going to be increase as 1e-3 into the previous time
  • Now, 'sim.advance' command is used for solving the particular time ,basically advance is a function of cantera to solve the equation for the particular timestep. Here i am providing time variable inside the sim.advance i.e ' sim.advance(time) '
  • As i know previously i was created a variable called 'states' which is 'SolutionArray' so whatever solution i get after executing/simulate 'sim.advance' and i am going to append states. so we are appending thermo.state(whatever the properties inside the thermodynamics). Advance is designed especially if the reactor network is at t =0 ,if we are in advance it will go one step ahead in time.
  • Appending all the states.
  • Append the value of status_temperature and this storing the values of temperature for every end of the timestep. This is storing for the every timestep the is storing for only last value of the timestep whatever is coming and how do we know this is storing for the every pressure because it is in the pressure loop. Basically at every 100 timestep whatever the value of pressure is coming this is going to store only those values.
  • Creating the if loop to calculate the ignition delay.
  • Plotting the results.
Initial Pressure[atm] Ignition-delay[s]
1 2.2e-5
2 1.205e-6
3 8.9e-6
4 6.94e-6
5 5.17e-6

The above table represents the auto-ignition delay with respect to the varying initial pressure. we can clearly observe that the ignition dealy time decreases as we increase the initial pressure. This shows that the ignition delay is sensitive to pressure .

Initial Temperature Ignition-delay
949 0.000428
1024 0.000117
1100 3.9e-5
1175 1.7e-5
1249 7.1e-6

The above table represents the auto-ignition delay with respect to the varying initial temperature. We can clearly observe that the ignition dealy time decreases as we increases the initial temperature. This shows that the ignition delay is sensitive to temperature.

It can be clearly observe from teh ignition delay grapgh for varying temperature and pressure that the auto-ignition dealay is more sensitive to temperature change towards pressure change, as the graph drops steeply(mostly) in case of increase in temperature.

OBSERVATION : CASE (1)

From plot 1 we can observe that as initial temperature increases the ignition delay decreases. so from plot 2 we can conclude that the ignition dealy is sensitive to both pressure and temperature. As the initial temperature or pressure increases the ignition delay or auto ignition gets reduced.

CASE (2)

This plot no.1 is very similar to the temperature varying plot as ignition delay is increasing with the decrease in the initial pressure. One more thing need to observe from plot 2 is that the decreased pressure increasing the auto ignition temperature, so that ignition delay is sensitive to initial pressure.

CODE PROCEDURE ( PART 2)

  • Importing all the necessary libraries to python
  • Creating a gas object by using solution class of GRI30.xml
  • Creating a for loop with a large range of temperature array and a constant pressure of 5 bar for both cases.
  • Setting up the conditions by using gas.TPX method.
  • Creating a IdealGasReactor with a object name of r and creating a simulation object.
  • Creating the states object which is an array to store all the properties at every time step.
  • Using time loop and sim.advance method for initializing the simulation by integrating at every 1e-3s.
  • Appending all the states.
  • Plotting the results by using states.X[:,gas.species_index('species')] vs states.t

CONCLUSION (CASE 1) :

The plot (a) shows the change in molar concentration of H2O,O2 and OH with a initial temperature and pressure of 500k and 5bar

From the O2 plot (b)we can see that the for the above case the ignition does not take place because the auto ignition temperature of methane is 900k

But from the above plot of H2O and OH we can see that the molar concentration of H2Oand OH increases due to some intermediate reactions taking place

CONCLUSION (CASE 2) :

The (d),(e),(f) plot shows the change in molar concentration of H2O ,O2 and OH with initial temperature and pressure of 1000k and 5 bar

so from these plots we can say that after reaction starts there is increases in concentration of H2O and OH and decrease in concentration of O2 which suggest that H2O and OH is formed and O2 is consumed during the combustion process.

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.