Figure 8.12:

Start-up of the tubular reactor; c_A(t,z) versus z for various times, 0\leq t\leq 2.5min, \Delta t=0.25min.

Code for Figure 8.12

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
% 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 k v D A B caf ncolpt order
%
%
% 2 A --> B,  r = k c_A^order
%
%
% transient behavior in a dispersed plug flow reactor
% steady-state profile in a PFR
% jbr, 10/20/01
%
%
k = 1/2;
v = 1/2;
D = 0.01;
caf = 1;
length = 1;
ncolpt = 50;
order = 2;
[z, A, B, Q] = colloc(ncolpt-2,'left','right');

%x0=ones(ncolpt,1);
%[x, fval, info] = fsolve('pfrcol',x0);
%info


tsteps=linspace(0,2.5,11);
% initial condition, zero conc. in tube
y0=zeros(ncolpt,1);
ydot0=zeros(ncolpt,1);
[tout,y] = ode15i (@pfrtran, tsteps, y0, ydot0);

table = [z y'];

%  %
%  % calculate the steady-state PFR for this problem
%  %
%  function res = pfr(t, x, xdot)
%    global  order k v
%    ca = x;
%    dcadz = xdot;
%    Ra = -2*k*ca^order;
%    res = dcadz - Ra/v;
%  end%function

%  x0    =caf;
%  xdot0 = - pfr(x0,0,0);
%  [tout,x] = ode15i (@pfr, z, x0, xdot0);

save -ascii dispersedpfrtran.dat table;
if (~ strcmp (getenv ('OMIT_PLOTS'), 'true')) % PLOTTING
plot (table(:,1), table(:,2:12));
% TITLE
end % PLOTTING

pfrcol.m


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
function res = pfrcol(x)
  global v D A B k caf ncolpt order
  %
  % express the diff eq at every collocation point
  %
  first = A*x;
  Ra = -2*k*(x.^order);
  second = B*x;
  res = -v*first + D*second + Ra;
  % write over the first and last points with the
  % boundary conditions
  res(1) = v*x(1)-D*first(1)-v*caf;
  res(ncolpt) = first(ncolpt);

pfrtran.m


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
function res = pfrtran(t, y, ydot)
  global ncolpt
  tmp = pfrcol(y);
  a = tmp(1);
  b = tmp(ncolpt);
  res = ydot-tmp;
  %
  % put bc at ends
  %
  res(1) = a;
  res(ncolpt)=b;