Figure 7.29:

Fluid molar concentrations versus reactor volume.

Code for Figure 7.29

Text of the GNU GPL.

main.m


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
% 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.

%
% added log transformation in pellet
% jbr
% 12/13/03

global  npts A Aint Bint Rint caf cbf ccf ...
        k10 E1 k20 E2 Ka0 Ea Kc0 Ec Da Db Dc T ...
        Ra Rb Rc Da Db Dc kma kmb kmc dcadr dcbdr dccdr ...
        epsb a T Ntfin Nafin Ncfin Pin Tin Qin Q Cptot U ...
        Ta Rt delH1 delH2 km Rp vis massf Ac xc Pext

Rg  = 8.314;  % J/K mol
Mair= 28.96; % g/mol, mol weight air
%Pin   = 1.5*1.013e5;  % N/m^2
Pin   = 2.0*1.013e5;  % N/m^2
Pext  = 1.013e5; % minimum allowed exit pressure
Tin   = 550; % K
Rt  = 10/2; %cm, tube radius
At  = pi*Rt*Rt; % cm^2, tube cross-sectional area
Ta  = 325; % K, ambient temperature
U    = 5.5e-3; % cal/(cm^2 K s), heat transfer coefficient
delH1 = (-67.63e3); % cal/mol CO;
delH2 = (-460.4e3); % cal/mol C_3H_6;
Cp  = 0.25; % cal/(g K), heat capacity of air
vis = 0.028e-2; % g/(cm s), viscosity of air
bt  = 1; % bed to tube area ratio
%u   = 500/bt;  % cm/sec, feed gas velocity entering bed
u  = 75/bt;  % cm/sec, feed gas velocity entering bed
Ac  = bt*At;  % cm^2 area of bed, 4 x area of tube
Qin = u*Ac;  % cm^3/sec, feed volumetric flowrate
P   = Pin;
T   = Tin;
Q   = Qin;
cfin= P/(Rg*T)*1e-6; % mol/cm^3
Rp  = 0.175; % cm radius of catalyst particle
a   = Rp/3;
rhob = 0.51; % g/cm^3 bed density
rhop = 0.68; % g/cm^3 particle density
epsb = 1 - rhob/rhop; % bed porosity, dimensionless
%epsb = 0.4;
xc  = 0.996;

cafin = cfin*0.02;
cbfin = cfin*0.03;
ccfin = cfin*5e-4;

Nafin = Q*cafin;
Nbfin = Q*cbfin;
Ncfin = Q*ccfin;
Nfin  = [Nafin; Nbfin; Ncfin];
Ntfin = Q*cfin;
massf = Ntfin*Mair; % mass flowrate, g/s, remains constant
Cptot = massf*Cp;

alpha = 1;
k10  = alpha*6.802e16*2.6e6*80/100*0.05/100;  %mol/cm^3 s
k20  = alpha*1.416e18*2.6e6*80/100*0.05/100;  %mol/cm^3 s
E1   = 13108; %K
E2   = 15109; %K
Ka0  = 8.099e6; % cm^3/mol
Kc0  = 2.579e8; % cm^3/mol
Ea   = - 409; %K
Ec   = 191; %K
Da   = 0.0487; % cm^2/s
Db   = 0.0469; % cm^2/s
Dc   = 0.0487; % cm^2/s
kma  = 0.4*9.76;   % cm/s
kmb  = 0.4*10.18;  % cm/s
kmc  = 0.4*9.76;   % cm/s

%
% calculate initial reaction rates
%
k1      = k10*exp(-E1/Tin);
k2      = k20*exp(-E2/Tin);
Ka      = Ka0*exp(-Ea/Tin);
Kc      = Kc0*exp(-Ec/Tin);
den     = (1+Ka*cafin+Kc*ccfin)*(1+Ka*cafin+Kc*ccfin);
r1      = k1*cafin*cbfin/den;
r2      = k2*ccfin*cbfin/den;
%
% adiabatic temperature rise and
% Ucrit to achieve a zero intial temperature derivative
%
adrise = -(cafin*delH1+ccfin*delH2)/(Cp*cfin*Mair)
Ucrit  = (r1*delH1 + r2*delH2)/(2/Rt*(Ta-T))

%
% global collocation
%
npts = 40;
[R A B Q] = colloc(npts-2, 'left', 'right');
R = R*Rp;
A = A/Rp;
B = B/(Rp*Rp);
Q = Q*Rp;
Aint = A(2:npts-1,:);
Bint = B(2:npts-1,:);
Rint = R(2:npts-1);

%
% find the pellet profile at tube inlet
%
caf = cafin; cbf=cbfin; ccf=ccfin;
zain = log(1e-9*caf); zaout = log(0.75*caf);
%zain = log(1e-12*caf); zaout = log(0.9*caf); %P=1.5
za0 = zain + R/Rp*(zaout-zain);
zbin = log(0.75*cbf); zbout = log(cbf);
zb0 = zbin + R/Rp*(zbout-zbin);
zcin = log(1e-6*ccf); zcout = log(ccf);
%zcin = log(1e-9*ccf); zcout = log(0.9*ccf); %P=1.5
zc0 = zcin + R/Rp*(zcout-zcin);

z0 = [za0;zb0;zc0];
fsolve_options = optimset ('TolFun', 1e-16, 'TolX', 1e-10);
[z,fval,info] = fsolve('pellet',z0,fsolve_options);
fsolve_failed = info <= 0;

if (fsolve_failed)
  plot(R,[z0(1:npts),z(1:npts),z0(npts+1:2*npts),z(npts+1:2*npts), ...
          z0(2*npts+1:3*npts),z(2*npts+1:3*npts)])
  error ('cannot find pellet profile at tube inlet')
end

za = z(1:npts);
zb = z(npts+1:2*npts);
zc = z(2*npts+1:3*npts);

ca = exp(za);
cb = exp(zb);
cc = exp(zc);

%
% march down the bed
%
nvs    = 201;
%vfinal = 4737;
vfinal = 2000;
vsteps = linspace (0,vfinal,nvs)';
vout   = vsteps;
y0     = [Nfin; Tin; Pin; z];
ydot0    = zeros(length(y0),1);
res      = bed(0,y0,ydot0);
ydot0(1:5)    = -res(1:5);

ymin = min(y0);
opts = odeset ('RelTol', 1e-10, 'AbsTol', 1e-10, 'Events', @stop);
t0=cputime();
[vout,y] = ode15i (@bed, vsteps, y0, ydot0, opts);
cpu = cputime()-t0
nout = length(vout);
if ( nout == nvs )
  fprintf ('hey, did not reach final conversion, increase vfinal\n');
end
xa = (Nafin-y(end,1))/Nafin
xb = (Nbfin-y(end,2))/Nbfin
xc = (Ncfin-y(end,3))/Ncfin
P=y(:,5);
T=y(:,4);
ctot = P./(Rg*T)*1e-6;
Nt = Ntfin - 1/2*(Nafin-y(:,1))+1/2*(Ncfin-y(:,3));
Q = Nt./ctot;
caf = y(:,1)./Q;
cbf = y(:,2)./Q;
ccf = y(:,3)./Q;
Patm = P/1.013e5;
table1 = [vout, caf, cbf, ccf, T, Patm];
%
% pick out some good length locations for pellet profiles
%
nrows = 5;
%rowsp = ceil(linspace(1,nout,nrows));
rowsp = [1,5,10,50,90,100,nout]
vout(rowsp)
cols = [6:npts+5];
ca   = exp(y(rowsp,cols)');
cols = [npts+6:2*npts+5];
cb   = exp(y(rowsp,cols)');
cols = [2*npts+6:3*npts+5];
cc   = exp(y(rowsp,cols)');
table2 = [R, ca, cb, cc];

save multicolloc_log.dat table1 table2;

if (~ strcmp (getenv ('OMIT_PLOTS'), 'true')) % PLOTTING
subplot (2, 2, 1);
semilogy (table1(:,1), table1(:,2:4));
% TITLE multicolloc_log_1

subplot (2, 2, 2);
plot (table1(:,1), table1(:,5));
% TITLE multicolloc_log_2

subplot (2, 2, 4);
plot (table1(:,1), table1(:,6));
% TITLE multicolloc_log_2

subplot (2, 2, 3);
semilogy (table2(:,1), table2(:,2:8));
% TITLE multicolloc_log_3
end % PLOTTING

pellet.m


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function retval = pellet(x)
  global  npts A Aint Bint Rint  caf cbf ccf ...
          k10 E1 k20 E2 Ka0 Ea Kc0 Ec Da Db Dc T ...
          Ra Rb Rc Da Db Dc kma kmb kmc dcadr dcbdr dccdr
  %
  % component A
  %
  za = x(1:npts);
  zb = x(npts+1:2*npts);
  zc = x(2*npts+1:3*npts);
  ca = exp(za);
  cb = exp(zb);
  cc = exp(zc);

  k1      = k10*exp(-E1/T);
  k2      = k20*exp(-E2/T);
  Ka      = Ka0*exp(-Ea/T);
  Kc      = Kc0*exp(-Ec/T);
  den     = (1+Ka*ca+Kc*cc).^2;
  r1      = k1.*ca.*cb./den;
  r2      = k2*cc.*cb./den;
  Ra      = - r1;
  Rb      = - 1/2*r1  - 9/2*r2;
  Rc      = - r2;
  ip = 1;
  retval(ip,1)    = A(1,:)*za;
  caint = ca(2:npts-1);
  retval(ip+1:ip+npts-2,1) = Bint*za + Aint*za.*(Aint*za + 2./Rint) + ...
      Ra(2:npts-1)./(Da*caint);
  dzadr = A(npts,:)*za;
  retval(ip+npts-1,1) = Da*dzadr - kma*(caf/ca(npts) - 1);
  %
  % component B
  %
  ip = npts+1;
  cbint = cb(2:npts-1);
  retval(ip,1)    = A(1,:)*zb;
  retval(ip+1:ip+npts-2,1) = Bint*zb + Aint*zb.*(Aint*zb + 2./Rint) + ...
      Rb(2:npts-1)./(Db*cbint);
  dzbdr = A(npts,:)*zb;
  retval(ip+npts-1,1) =  Db*dzbdr - kmb*(cbf/cb(npts) - 1);
  %
  % component C
  %
  ip = 2*npts+1;
  ccint = cc(2:npts-1);
  retval(ip,1)    = A(1,:)*zc;
  retval(ip+1:ip+npts-2,1) = Bint*zc + Aint*zc.*(Aint*zc + 2./Rint) + ...
      Rc(2:npts-1)./(Dc*ccint);
  dzcdr = A(npts,:)*zc;
  retval(ip+npts-1,1) = Dc*dzcdr - kmc*(ccf/cc(npts) - 1);
  dcadr = A(npts,:)*ca;
  dcbdr = A(npts,:)*cb;
  dccdr = A(npts,:)*cc;

bed.m


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function res = bed(t, y, ydot)
  global epsb Da Db Dc a T ...
      Ntfin Nafin Ncfin Pin Tin Qin Q Cptot U Ta Rt delH1 delH2 ...
      km Rp  vis massf Ac dcadr dcbdr dccdr caf cbf ccf
%  fprintf('time= %g \n',t);
  Naf = y(1);
  Nbf = y(2);
  Ncf = y(3);
  T   = y(4);
  P   = y(5);
  zpellet = y(6:length(y));

  Ntf  = Ntfin -1/2*(Nafin - Naf) + 1/2*(Ncfin - Ncf);
  Q  = Qin * Pin/P*T/Tin*Ntf/Ntfin;
  caf = Naf/Q;
  cbf = Nbf/Q;
  ccf = Ncf/Q;
  %
  % calculate pellet residual and update
  % total pellet reaction rate through dcadr dcbdr dccdr
  %
  pelletres = pellet(zpellet);
  r1p   = Da/a*dcadr;
  r2p   = Dc/a*dccdr;

  Rj    = -(1-epsb)/a*[ Da*dcadr; Db*dcbdr; Dc*dccdr];
  dT    = ( -(delH1*r1p + delH2*r2p) + 2/Rt*U*(Ta-T) ) / Cptot;
%  dT    = 0;
  dP    = - (1-epsb)*Q / ( 2*Rp*epsb^3.*Ac^2. ) * ...
          ( 150*(1-epsb)*vis/(2*Rp) + 7/4*massf/Ac );
%  dP = 0;
  rhs = [Rj; dT; dP];
  res(1:5,1) = ydot(1:5) - rhs;
  res(6:length(y),1) = pelletres;

stop.m


1
2
3
4
5
6
7
8
9
function [retval, isterminal, direction] = stop(t,y,ydot)
  global xc Ncfin Pext
  Ncf = y(3);
  P   = y(5);
  convtest = xc - (1-Ncf/Ncfin);
  presstest = P - Pext;
  retval = min(convtest,presstest);
  isterminal = 1;
  direction = 0;