% 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 part of ethane pyrolysis example that is in the
% text. It generates the error plot for the ethane example
% It is titled ethane_error.m
%
% It was last edited 2/5/97
%
% Revised 7/24/2018
%E in Joules, mass in grams, T in Kelvin, time in sec, volume in cm3
Components_1 = [' C2H6 = 1,',' CH3 = 2,',' CH4 = 3,',' C2H5 = 4'];
Components_2 = [' H = 5,',' C2H4 = 6,', ' H2 = 7,',' H2O = 8'];
Ao = [1e17,2e11, 3e14, 3.4e12, 1.6e13]';
Ea = [356000, 44000, 165000, 28000, 0]';
nu = [-1,2,0,0,0,0,0,0
-1,-1,1,1,0,0,0,0
0,0,0,-1,1,1,0,0
-1,0,0,1,-1,0,1,0
1,0,0,-1,-1,0,0,0];
R = 8.3144; % Gas Constant (J/gmole-K)
p.R1 = 82.057; % Gas Constant (cc-atm/gmole-K)
p.T = 925; % Temp (K)
EXP = exp(-Ea/(R*p.T));
p.k = Ao.*EXP;
p.kp = (p.k(1)/(2*p.k(3)) + ((p.k(1)/(2*p.k(3)))^2 + ...
((p.k(1)*p.k(4))/(p.k(3)*p.k(5))))^0.5);
C1o = (50/760)/(82.057*p.T); %gmole/cm3
C8o = (710/760)/(82.057*p.T);
Qf = 35.0; %cc/sec
N1o = C1o*Qf; %gmole/sec
N8o = C8o*Qf;
p.P = 1.0; %atm
Initial = [N1o,0,0,0,0,0,0,N8o]';
v = [0:1:100]';
opts = odeset ('AbsTol', sqrt (eps), 'RelTol', sqrt (eps));
[tsolver, solution] = ode15s(@(v,x) rxrate(v,x,p),v,Initial,opts);
answer = [v solution];
Initial_q = [N1o, 0, 0, 0, N8o]';
% The total mole balance neglects H, CH3 and C2H5 because at 925K they
% are of order 10^-6 the concentration(molar flowrate) of ethane and
% ethane will only change by one order of magnitude.
[tsolver, solution_q] = ode15s(@(v,x) rate_q(v,x,p),v,Initial_q,opts);
answer_q = [v solution_q];
% Delete first row to avoid floating point exception.
Ethylene_exact = solution(2:end,6);
Ethylene_qss = solution_q(2:end,3);
err = abs((Ethylene_exact - Ethylene_qss)./Ethylene_exact);
erro = err*100;
%error = [v(2:length(v)), erro];
% JBR, 2/22/98
error = [v(2:length(v)), err];
save -ascii ethane_error.dat error;
if (~ strcmp (getenv ('OMIT_PLOTS'), 'true')) % PLOTTING
semilogy (error(:,1),error(:,2))
% TITLE
end % PLOTTING