%
% Example 14.1: Activated Sludge Anaerobic Zone
%
% - Batch reactor formulation
%
% Bob Newell, March 1996
%
%-----------------------------------------------------------
% parameters
Khnfe = 3 * 0.1;
Kx = 0.1;
qfe = 3.0;
Kfe = 20;
qpha = 3;
Ka = 4;
Kpp = 0.01;
Ypo4 = 0.4;
%
muaerobic = 6;
Ko2 = 0.2;
Kfa = 4;
muanoxic = 6*0.8;
Kno3 = 0.5;
Yh = 0.63;
%-----------------------------------------------------------
% initial states
Xh = 400;
Xpao = 1000; 
%
global p
p = [ Khnfe Kx qfe Kfe qpha Ka Kpp Ypo4 Xh Xpao ...
       muaerobic Ko2 Kfa muanoxic Kno3 Yh ];
%-----------------------------------------------------------
% initial states
Xs = 100;
Sf = 70;             % 20 - 250
Sa = 40;             % 10 - 60
Xpp = 50;
Spo4 = 5;            % 2 - 20
Xpha = 0;
%
So2 = 0; Sno3 = 0;
%
xo = [ Xs Sf Sa Xpp Spo4 Xpha So2 Sno3 ];
%-----------------------------------------------------------
% operational section
to = clock;
days = 1/24;
[ t, x ] = ode45( 'Anaerobic_Zone', [ 0 days ], xo );
secs = etime( clock,to)
%-----------------------------------------------------------
% plot the results
figure
hax = plotyy( 24*t, x(:,[5 6]), 24*t, x(:,[3 7 8]) );
axesyy( hax, [ 0 24*days -100 100 0 100 ], ...
   'Time in hours', ...
   'Production in mg/l', ...
   'Consumption in mg/l', 2, ...
   [ 0 50 100 ], [ 0 20 40 ] );
%
h = text( 0.3, 45, 'PHA' );
set( h, 'fontsize', 24 );
h = text( 0.3, 5, 'phosphate' );
set( h, 'fontsize', 24 );
h = text( 0.3, -40, 'acetate' );
set( h, 'fontsize', 24 );
%
printsto -f1 -deps2 ex14-3a.eps
%
%-----------------------------------------------------------
xo(7) = 5; xo(8) = 8;
to = clock;
days = 1/24;
[ t, x ] = ode45( 'Anaerobic_Zone', [ 0 days ], xo );
secs = etime( clock,to)
%-----------------------------------------------------------
% plot the results
figure
hax = plotyy( 24*t, x(:,[5 6]), 24*t, x(:,[3 7 8]) );
axesyy( hax, [ 0 24*days -100 100 0 100 ], ...
   'Time in hours', ...
   'Production in mg/l', ...
   'Consumption in mg/l', 2, ...
   [ 0 50 100 ], [ 0 20 40 ] );
%
h = text( 0.3, 45, 'PHA' );
set( h, 'fontsize', 24 );
h = text( 0.3, 5, 'phosphate' );
set( h, 'fontsize', 24 );
h = text( 0.3, -55, 'acetate' );
set( h, 'fontsize', 24 );
h = text( 0.10, -92.5, 'DO' );
set( h, 'fontsize', 24 );
h = text( 0.05, -75, 'nitrate' );
set( h, 'fontsize', 24 );
%
printsto -f2 -deps2 ex14-3b.eps
%
%-----------------------------------------------------------
% the end!
