% Copyright (C) 2001, James B. Rawlings and John G. Ekerdt
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License as
% published by the Free Software Foundation; either version 2, or (at
% your option) any later version.
%
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
% General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; see the file COPYING. If not, write to
% the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
% MA 02111-1307, USA.
%
% This program solves the ethane pyrolysis text example with NO inhibitions.
%
% It was last edited 1/2/2002
% Revised 7/24/2018
% Cleaned up by jbr, 1/15/2022
%E in Joules, mass in grams, T in Kelvin, time in sec, volume in cm3
%Components 1 = C2H6; 2 = NO; 3 = C2H5; 4 = HNO; 5 = H; 6 = C2H4; 7 = H2
A0 = [1e14, 1e12, 3e14, 3.4e12, 1e12, 1e13]';
Ea = [217600, 0, 165300, 28500, 0, 200800]';
R = 8.3144; %(J/gmol-K)
R1 = 82.057; %cc-atm/gmol-K
Tvec = [1000, 1050, 1100]; %K
P = 1.0; % atm
y1f = 0.95;
y2f = 0.05;
Qf = 600.0; %cc/sec
p = struct(); %Create structure to supply parameters to function
p.P = P;
p.R1 = R1;
tags = cellstr (['k1'; 'k_1'; 'k2'; 'k3'; 'k4'; 'k_4']);
v = linspace(0, 1500, 200)';
opts = odeset ('AbsTol', sqrt (eps), 'RelTol', sqrt (eps));
table = zeros(length(v), length(Tvec));
table(:,1) = v;
for j = 1: length(Tvec)
T = Tvec(j);
p.T = T;
N1f = y1f*P/(R1*T)*Qf;
N2f = y2f*P/(R1*T)*Qf;
N0 = [N1f, N2f, 0, 0, 0, 0, 0]';
% compute the rate constants k = A exp(-E/(RT)
for i = 1:length(tags)
p.(tags{i}) = A0(i)*exp(-Ea(i)/(R*T));
end%for
[tsolver, N] = ode15s(@(v,x) rxrate(v,x,p), v, N0, opts);
table(:,j+1) = N(:,1); % store ethane for plotting
end%for
save -ascii ethane_NO_2.dat table;
if (~ strcmp (getenv ('OMIT_PLOTS'), 'true')) % PLOTTING
plot (v, table(:,2:end));
axis([0 1600 0 .007])
% TITLE
end%if % PLOTTING