0% found this document useful (0 votes)
225 views3 pages

Ignition Time Calculation Program

This document contains the code for a program that models hydrogen combustion in a constant volume reactor. It defines arrays to store reaction rate constants and initializes values for temperature, pressures, species masses, and reaction rates. It then enters a loop over different pressures, using Euler integration to model how temperature and species masses change over small time steps due to chemical reactions. It checks for ignition when fuel is depleted by 25% and records ignition delay times. The data is then saved to a text file.

Uploaded by

buynowhhh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
225 views3 pages

Ignition Time Calculation Program

This document contains the code for a program that models hydrogen combustion in a constant volume reactor. It defines arrays to store reaction rate constants and initializes values for temperature, pressures, species masses, and reaction rates. It then enters a loop over different pressures, using Euler integration to model how temperature and species masses change over small time steps due to chemical reactions. It checks for ignition when fuel is depleted by 25% and records ignition delay times. The data is then saved to a text file.

Uploaded by

buynowhhh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

program hw4a

!----------------------------------------------------------------------------------
-----------
integer:: i,j,l,idim,ignited
double precision:: t_f,dt,m,V,cp,R,Z,m_dot
double precision:: W_h,W_h2,W_h2o,W_o2,W_n2,W_mixture
double precision:: Tu,Y_hu,Y_h2u,Y_h2ou,Y_o2u,Y_n2u
double precision:: T_old,Y_h_old,Y_h2_old,Y_h2o_old,Y_o2_old,Y_n2_old
double precision:: T_new,Y_h_new,Y_h2_new,Y_h2o_new,Y_o2_new,Y_n2_new,tt_new
double precision:: Y_h_temp,Y_h2_temp,Y_h2o_temp,Y_o2_temp
double precision:: C_h,C_h2,C_h2o,C_o2,C_n2,C_oh,C_o,C_ho2,C_M,w_I,w_II
double precision, dimension(:), allocatable:: B,n,E,k,t_igni,P
character(len=30)::filename
!----------------------------------------------------------------------------------
-----------
!Define control parameters and allocate arrays
m_dot=0.0D0; filename='hw4a_data.txt'
t_f=3D-1;
dt=1D-8; idim=10;
allocate(B(16),n(16),E(16),k(16),t_igni(idim),P(idim))
Tu=975.0D0; t_igni(:)=-1.0D0
V=1D6; cp=1.4D0;
do i=1,idim
P(i)=1.01325D5*i
end do
!----------------------------------------------------------------------------------
-----------
!Define constants
R=8.3145D0;
B=(/2.000E+14, 1.568E+13, 5.060E+04, 2.222E+04, 1.000E+08, 4.312E+08,
1.500E+09,&
1.473E+10, 2.300E+18, 3.190E+18, 1.500E+14, 2.500E+13, 6.000E+13,
4.400E+06,&
4.956E+08, 2.200E+04/);
n=(/0.0e0, 0.0e0, 2.67e0, 2.67e0, 1.6e0, 1.6e0, 1.14e0, 1.14e0, -0.8e0,&
-0.8e0, 0.0e0, 0.0e0, 0.0e0, 1.5e0, 1.5e0, 3.0e0 /)
E=(/7.0300E+04, 3.5200E+03, 2.6300E+04, 1.8290E+04, 1.3800E+04, 7.6460E+04,
4.2000E+02,&
7.1090E+04, 0.0000E+00, 1.9539E+05, 4.2000E+03, 2.9000E+03, 0.0000E+00, -
3.1000E+03,&
8.9760E+04, 3.6600E+04/)
!Sequence 1f(1) 1b(2) 2f(3) 2b(4) 3f(5) 3b(6) 4f(7) 4b(8) 5f(9) 5b(10) 6(11) 7(12)
!8(13) 18f(14) 18b(15) 38f(16)
W_h=1.008D-3; W_h2=2.016D-3; W_h2o=18.016D-3; W_o2=32.0D-3; W_n2=28.016D-3;
!----------------------------------------------------------------------------------
-----------
!Define initial values
Z=1/(1+(0.5D0*W_o2/W_h2/0.232D0));
Y_h2u=Z; Y_o2u=0.232D0*(1.0D0-Z);
Y_hu=1D-12; Y_h2ou=1D-12; Y_n2u=1.0D0-Y_o2u-Y_h2u;
W_mixture=1.0D0/(Y_h2u/W_h2+Y_o2u/W_o2+Y_n2u/W_n2)
!----------------------------------------------------------------------------------
-----------
!Begins loops
do i=1,idim !Loop over pressures
!------------------------------------------
!Reinitialize values for new pressure
ignited=0;
m=P(i)*(V/1D6)/(R/W_mixture)/Tu;
T_old=Tu; Y_h_old=Y_hu; Y_h2_old=Y_h2u; Y_h2o_old=Y_h2ou; Y_o2_old=Y_o2u;
Y_n2_old=Y_n2u;
!------------------------------------------
do j=1,nint(t_f/dt) !Euler forward iterations
tt_new=j*dt;
!Define intermediate quantities
do l=1,size(k)
k(l)=B(l)*(T_old**n(l))*exp(-E(l)/R/T_old);
end do
C_h=(m/V)*(Y_h_old/W_h); C_h2=(m/V)*(Y_h2_old/W_h2);
C_h2o=(m/V)*(Y_h2o_old/W_h2o); C_o2=(m/V)*(Y_o2_old/W_o2);
C_n2=(m/V)*(Y_n2_old/W_n2);
C_oh=(k(6)/k(5))*(C_h2o*C_h/C_h2);
C_o=(k(1)*C_o2*C_h+k(4)*C_oh*C_h+k(7)*C_oh**2)/
(k(2)*C_oh+k(3)*C_h2+k(8)*C_h2o);
C_M=C_h2+6.5*C_h2o+0.4*C_o2+0.4*C_n2;
C_ho2=k(9)*C_o2*C_h*C_M/(k(10)*C_M+(k(11)+k(12))*C_h+k(13)*C_oh);
w_I=k(1)*C_o2*C_h-k(2)*C_oh*C_o+k(11)*C_ho2*C_h;
w_II=k(9)*C_o2*C_h*C_M-k(10)*C_ho2*C_M;
!------------------------------------------
!Temperature estimation
T_new=T_old+dt*((m_dot/m)*(Tu-T_old)+(V/m/cp)*(47.68*w_I+435.972*w_II));
!Mass fraction estimation
Y_h_temp=Y_h_old+dt*((m_dot/m)*(Y_hu-Y_h_old)+(V*W_h/m)*(2*w_I-2*w_II));
Y_h_new=max(1D-12, Y_h_temp);
Y_h2_temp=Y_h2_old+dt*((m_dot/m)*(Y_h2u-Y_h2_old)+(V*W_h2/m)*(-
3*w_I+w_II));
Y_h2_new=max(1D-12, Y_h2_temp);
Y_h2o_temp=Y_h2o_old+dt*((m_dot/m)*(Y_h2ou-Y_h2o_old)+(V*W_h2o/m)*(2*w_I));
Y_h2o_new=max(1D-12, Y_h2o_temp);
Y_o2_temp=Y_o2_old+dt*((m_dot/m)*(Y_o2u-Y_o2_old)+(V*W_o2/m)*(-w_I));
Y_o2_new=max(1D-12, Y_o2_temp);
Y_n2_new=max(1D-12, 1-Y_h_new-Y_h2_new-Y_h2o_new-Y_o2_new);
!------------------------------------------
!Check for ignition
if(Y_h2_new .le. 2.5D-1*Y_h2u) then !Less than 25% fuel left = ignition
t_igni(i)=tt_new
ignited=1
exit
end if
!------------------------------------------
!Update values for next iteration
T_old=T_new; Y_h_old=Y_h_new; Y_h2_old=Y_h2_new;
Y_h2o_old=Y_h2o_new; Y_o2_old=Y_o2_new; Y_n2_old=Y_n2_new;
end do
!------------------------------------------
!Display
if(ignited == 1) then
print *, P(i), tt_new
else
print *, P(i), tt_new, 'No ignition'
end if
end do
!----------------------------------------------------------------------------------
-----------
!Save data
call arraytotxt(P,t_igni,idim,filename)
deallocate(B,n,E,k,P,t_igni)
end program hw4a
!----------------------------------------------------------------------------------
-----------
!----------------------------------------------------------------------------------
-----------
subroutine arraytotxt(P,t_igni,icount,filename)
integer:: i,icount
character(len=30)::filename
double precision, dimension(icount) :: P,t_igni
open(unit=11, file=filename, status="replace", action="write")
do i=1,icount
write(11,"(F35.20)",advance='no') P(i)
write(11, '(A)',advance='no') " "
write(11,"(F35.20)") t_igni(i)
end do
close(11)
end subroutine arraytotxt

You might also like