Figure A.8:

Magnified view of Figure A.7.

Code for Figure A.8

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
% 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.


global epsb a Nafin Ntfin Qf Da k1 A Bint Aint Rint npts Da caf xa

xa  = 0.75;
Rg  = 8.314;  % J/K mol
P   = 4*1.013e5;  % N/m^2
T   = 550; % K
ctf = P/(Rg*T)*1e-6; % mol/cm^3
Rp  = 0.45; % cm radius of catalyst particle
a   = Rp/3;
Nafin = 10; % mol/sec
NIf   = 10;
Ntf   = Nafin+NIf;
caf = ctf*0.5;
Qf  = Nafin/caf;
k1  = 2.25e5;  %cm^3/mol s
Da   = 0.008; % cm^2/s
rhob = 0.60; % g/cm^3 bed density
rhop = 0.68; % g/cm^3 particle density
epsb = 1 - rhob/rhop; % bed porosity, dimensionless
%
% global collocation
%
npts = 25;
[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 bed inlet
%

ca0 = logspace(log10(caf)-2,log10(caf),npts)';
tol = 1e-12;
opts = optimset ('TolFun', tol);
[ca,fval,info] = fsolve('pellet',ca0,opts);

info;



%
% march down the bed
%
nvs    = 100;
vfinal = 4e5;
vsteps = linspace (0,vfinal,nvs)';
vout   = vsteps;
y0     = [Nafin; ca];
ydot0    = zeros(length(y0),1);
res      = bed(y0,ydot0,0);
ydot0(1) = -res(1);

ymin = min(y0);
opts = odeset ('AbsTol', sqrt (eps), 'RelTol', 1e-10, 'Events', @stop);
[vout,y] = ode15i (@bed, vsteps, y0, ydot0, opts);
nout = length(vout);
if ( nout == nvs )
  fprintf ('hey, did not reach final conversion, increase vfinal\n');
end
xa = (Nafin-y(end,1))/Nafin;
Naf = y(:,1);
vplot = vout/1000.; %lit
VR = vplot(end);
tableex = [vplot, Naf];
%
% pick out some good length locations for pellet profiles
%
rowsc = [1,nout];
colsc = [2:npts+1];
ca   = y(rowsc,colsc)';
table2 = [R, ca];
Naout = (1-xa)*Nafin;
Natop = (1-xa+0.10)*Nafin;
% dashedlines = [0,      Naout, VR, 0,     300,  Naout, VR, 2  ;
%                1.1*VR, Naout, VR, Natop, 400,  Naout, VR, 3  ];

% Compare to the two approximations given in ch7,
% Example 7.5, Figure 7.26

par.k     = k1;
par.Nafin   = Nafin;
par.T     = T;
par.rhop  = rhop;
par.rhob  = rhob;
par.Da    = Da;
par.Rp    = Rp;
par.Rg    = 82.06;
par.P     = 4;
par.n     = 2;
par.xa    = xa;
par.nvs  = nvs;
par.vfinal= vfinal;

% solve reactor with: eta = 1./Phi*( 1./tanh(3*Phi) - 1/(3*Phi) );
par.eta = (@(x) 1./x*( 1./tanh(3*x) - 1/(3*x) ));
[vap1, xap1] = pbrsolve(par);

% solve reactor with:  eta = 1./Phi;
par.eta = (@(x) 1./x);
[vap2, xap2] = pbrsolve(par);

vap1 = vap1/1000.;
VRap1 = vap1(end);

vap2 = vap2/1000.;
VRap2 = vap2(end);
tableap1 = [vap1 xap1];
tableap2 =  [vap2 xap2];
dashedlines = ...
[0,      Naout, VR, 0,     VRap1, 0,     VRap2, 0; ...
 1.1*VR, Naout, VR, Natop, VRap1, Natop, VRap2, Natop];

save fb2colloc.dat tableex tableap1 tableap2 dashedlines

if (~ strcmp (getenv ('OMIT_PLOTS'), 'true')) % PLOTTING
%plot the molar flow versus reactor volume and 75% conversion line
  plot(vplot, Naf, ...
       vap1, xap1, ...
       vap2, xap2, ...
       dashedlines(:,1), dashedlines(:,2), ...
       dashedlines(:,3), dashedlines(:,4), ...
       dashedlines(:,5), dashedlines(:,6), ...
       dashedlines(:,7), dashedlines(:,8))

axis ([0, 400, 2, 10])
% TITLE
end % PLOTTING

pbrsolve.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
function [vout, x] = pbrsolve (par)
  vtotal = par.vfinal*linspace(0,1,par.nvs)';
  vsteps = vtotal;
  x0=par.Nafin;
  opts = odeset ('Events', @(t,x) stop (t,x,par), 'AbsTol', sqrt (eps), 'RelTol', sqrt (eps));
  [vout, x] = ode15s (@(t,x) pbr (t,x,par), vsteps, x0, opts);
  if ( numel(vout) == par.nvs )
    fprintf ('hey, did not reach final conversion, increase stopping time\n');
  end%if
end%function

function xdot = pbr (t, x, par)
  Na = x(1);
  ca = par.P/(par.Rg*par.T) * Na/(2*par.Nafin);
  Phi = par.Rp/3*sqrt((par.n+1)/2*par.k*ca/par.Da);
  xdot = -par.rhob/par.rhop*par.eta(Phi)*par.k*ca^par.n;
end%function

function [retval, isterminal, direction] = stop(t, x, par)
  Na = x(1);
  retval = Na - (1-par.xa)*par.Nafin;
  isterminal = 1;
  direction = 0;
end%function

pellet.m


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
function retval = pellet(x)
  global  k1 A Bint Aint Rint Da caf npts dcadr
  %
  % component A
  %
  ca = x(1:npts);
  r1      = k1.*ca.*ca;
  Ra      = - r1;
  ip = 1;
  retval(ip,1)    = A(1,:)*ca;
%  caint = ca(ip+1:ip+npts-2);
  retval(ip+1:ip+npts-2,1) = Bint*ca + 2*Aint*ca./Rint + ...
      Ra(2:npts-1)/Da;
  dcadr = A(npts,:)*ca;
%  retval(ip+npts-1) = Da*dcadr - kma*(caf - ca(npts));
  retval(ip+npts-1,1) = caf - ca(npts);

bed.m


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
function res = bed(t, y, ydot)
  global epsb a Ntfin Qf Da dcadr caf
%  fprintf('time= %g \n',t);
  Naf = y(1);
  cpellet = y(2:length(y));
  Q  = Qf;
  caf = Naf/Q;
  %
  % calculate pellet residual and update
  % total pellet reaction rate through dcadr
  %
  pelletres = pellet(cpellet);
  r1p   = Da/a*dcadr;
%  RA    = -(1-epsb)/a*[ Da*dcadr];
  RA    = -(1-epsb)*r1p;
  res(1,1) = ydot(1) - RA;
  res(2:length(y),1) = pelletres;

stop.m


1
2
3
4
5
6
7
function [retval, isterminal, direction] = stop(t,y,ydot)
  global xa Nafin
  Naf = y(1);
  convtest = xa - (1-Naf/Nafin);
  retval = convtest;
  isterminal = 1;
  direction = 0;