Process modeling and scale up
Process modeling and scale up
By
Dr A. Abubakar
3
TOPIC 3
NUMERICAL SIMULATION OF
CHEMICAL ENGINEERING
SYSTEMS USING MATLAB
4
3.1 Introduction
▪ Simulation basically involves the determination of the response of output variables
to the change in the input variables.
▪ Since the models of chemical engineering systems consist of both algebraic and
differential equations, they can adequately be simulated using differential
equations solvers in the Matlab software. Some of these solvers are developed
based on the Runge-Kutta numerical simulation method. The most commonly used
solvers for chemical engineering systems are ode45 and ode15s.
▪ In using the solvers, two files must be separately created. The first one is the
function file where the model equations are written. In saving this function file, the
name of the file must be the function name itself. The second one is the run file
where the programme is run and initial steady-state conditions for the differential
equations are inputted. The two files must also be saved in the same folder.
▪ NOTE: Normally only the initial steady-state or nominal values of the dependent
variables in the differential terms of the model to be simulated must be known and
they must be provided as arguments in the ode function in the run file. However, if
nominal values of dependent variables form part of algebraic equation(s) of the
model, such values must also be known and in this case, such nominal values are
provided in the function file.
5
How to Write MATLAB Programme for Model Simulation
Rearrangement of Model Equations
- Making the differential terms the subjects
- Breaking up the multi-variable differential terms
Function File
- Function
- Parameter values
- Forcing functions and or specified variables
- Splitting of states (States are the variables in the differential terms)
- Model equations
- Output
Run File
- Time of simulation (t)
- Steady-state conditions (ssc)
- Ode solver (t and ssc can be directly combined with the Ode solver)
- Result display
6
3.2 Gravity-Flow Tank
Problem description and relevant model equations
We want to simulate the operation of the gravity-flow tank that we considered in
example 1.9 of topic one using Matlab. This is shown in Fig. 3.1.
The model developed gave us a non linear ordinary differential equation (ODE) as;
𝒅𝒗 𝒉 𝑲𝑭 𝒈𝒄 𝟐
=𝒈 − 𝒗 (3.1)
𝒅𝒕 𝑳 𝝆𝑨𝒑
𝑭
𝒗= (3.2)
𝑨𝒑
where 𝑳 = length of the pipe, 𝑨𝒑 = area of the pipe, 𝑲𝑭 = constant
7
Eq. (3.1) is nonlinear because of the presence of 𝒗𝟐 .
To describe the system completely, the following total continuity equation on the
liquid in the tank is also needed.
𝒅𝒉 (3.3)
𝑨𝑻 = 𝑭𝒐 − 𝑭
𝒅𝒕
𝑨𝑻 = area of the tank
Therefore, combining Eqs. (3.2) and (3.3) gives
𝒅𝒉 𝟏 (3.4)
= 𝑭 − 𝒗𝑨𝒑
𝒅𝒕 𝑨𝑻 𝒐
The physical dimensions, parameter values and initial steady-state (or nominal)
values are given in Table 3.1.
SOLUTION
The following steps will be followed to solve this problem:
▪ Determination of degree of freedom.
▪ Writing of the MATLAB programme to simulate the system.
Degrees of freedom of the system
❖ The parameters are 𝒈, 𝑳, 𝑲𝑭 , 𝒈𝒄, 𝝆, 𝑨𝒑 and 𝑨𝑻 .
❖ The forcing function or input variable is 𝑭𝒐 .
❖ The dependent variables are 𝝂 and 𝒉.
❖ There are two equations.
❖ Thus, the degree of freedom is zero.
%------------------------------------------------------------
% Parameter values:
g=32.2; L=3000; gc=32.2; KF=0.0281; rho = 62.52; Ap=7.06; AT=113;
%------------------------------------------------------------
%------------------------------------------------------------ 10
% Splitting the states
v=X(1); % Liquid velocity in the outlet line (ft/s)
h=X(2); % Height of the liquid in the tank (ft)
%------------------------------------------------------------
% THE MODEL
% Force balance
dvdt = g*h./L-KF*gc/(rho*Ap)*v^2;
% Total continuity
dhdt = (F0-v*Ap)/AT;
%------------------------------------------------------------
% Output
dvhdt=[dvdt';dhdt'];
Fig. 3.2a: Plot of liquid height against time for 𝐹𝑜 = 35.1 ft3/s 12
Fig. 3.2b: Plot of liquid height against time for 𝐹𝑜 = 35 ft3/s 13
Fig. 3.2c: Plot of liquid height against time for 𝐹𝑜 = 3.51 ft3/s 14
3.3 Three CSTRs in Series
Problem description and relevant model equations
We want to simulate the operation of three CSTRs in series that we considered in
section 2.1 of topic two for 5 minutes using Matlab. This is shown in Fig. 3.3.
𝑉2 𝑉3
The developed model for the system consists of three linear ODEs as follows:
𝒅𝑪𝑨𝟏 𝟏 (3.5)
= 𝑪𝑨𝒐 − 𝑪𝑨𝟏 − 𝒌𝑪𝑨𝟏
𝒅𝒕 𝝉
𝒅𝑪𝑨𝟐 𝟏 (3.6)
= 𝑪𝑨𝟏 − 𝑪𝑨𝟐 − 𝒌𝑪𝑨𝟐
𝒅𝒕 𝝉
𝒅𝑪𝑨𝟑 𝟏 (3.7)
= 𝑪𝑨𝟐 − 𝑪𝑨𝟑 − 𝒌𝑪𝑨𝟑
𝒅𝒕 𝝉
15
The steady-state conditions for the system are 𝑪𝑨𝟏(𝒔) = 0.4 kmol/m3, 𝑪𝑨𝟐(𝒔) = 0.2
kmol/m3 and 𝑪𝑨𝟑(𝒔) = 0.1 kmol/m3. The forcing function is 𝑪𝑨𝒐 . We will assume that
at time zero, 𝑪𝑨𝒐 is set 1.8 kmol/m3 and held constant. The time constant, 𝝉 is
equal to 2 min and the value of reaction rate constant, 𝒌 is 0.5 min-1.
Problems:
▪ Simulate the CSTRs in series to determine the variations of exit concentrations
from the three reactors with time.
▪ Plot 𝑪𝑨𝟏 , 𝑪𝑨𝟐 and 𝑪𝑨𝟑 as functions of time.
SOLUTION
The following steps will be followed to solve this problem:
▪ Determination of degree of freedom.
▪ Writing of the MATLAB programme to simulate the system.
%------------------------------------------------------------
% Forcing function or input variable:
CA0=1.8; % Inlet concentration of reactant A into reactor 1 (kmol/m3)
%------------------------------------------------------------ 17
% Splitting the states
CA1=X(1); % Exit concentration of reactant A from reactor 1 (kmol/m3)
CA2=X(2); % Exit concentration of reactant A from reactor 2 (kmol/m3)
CA3=X(3); % Exit concentration of reactant A from reactor 3 (kmol/m3)
%------------------------------------------------------------
% THE MODEL
%------------------------------------------------------------
% Output
dcdt=[dCA1dt';dCA2dt';dCA3dt'];
18
Run file (Using ode45 solver):
clc
clear all
tspan=[0 5]; % Range of time for simulation
CAs=[0.4 0.2 0.1]; % Nominal exit concs. from the three reactor(kmol/m3)
[t, X] = ode45('cstrseriesmod', tspan, CAs);
plot(t,X(:,1),'+',t,X(:,2),'*',t,X(:,3),'s')
legend('CA1','CA2','CA3')
xlabel('time (min)')
ylabel('Concentration of reactant A, kmol/m3')
title('Example 3.2')
19
Fig. 3.4: Plot of concentration against time 20
Class Work
Let us reconsider the above three CSTRs in series for a case in which the holdups
and the flow rates are not constant. This condition requires the following controller
equation that represents the hydraulic between reactor holdup and the exit flow rate.
𝑭 = 𝑲𝑽 𝑽 − 𝑽𝒎𝒊𝒏
The additional forcing function, 𝑭𝒐 is set at 600 m3/min and the initial steady-state
values for the holdups are each 300 m3. The minimum holdup (i.e. 𝑽𝒎𝒊𝒏 ) is at a
constant value of 100 m3 for each of the three reactors while the constant 𝑲𝑽 is 2.5
min-1.
21
3.4 Binary Distillation Column
Problem description
We want to simulate the operation of the binary distillation column in Fig. 3.5 for 100
minutes using Matlab.
This system is a slightly modified version of section 2.9 in topic two. The main
differences between the two systems are as follows:
▪ The condenser and reboiler are not included in the number of the stages or trays
in section 2.9 unlike in the current one where the condenser and reboiler are
numbered with the column stages.
▪ In section 2.9 of topic two, the feed condition was not taken into account unlike in
the current one.
▪ There are no level controllers in current system unlike in section 2.9 of topic two.
Stage 𝑵𝑻−𝟏
𝑳𝑵𝑻 , 𝒙𝑫 𝑫, 𝒙𝑫
𝑭, 𝒛𝑭
Feed stage
𝑽𝟏 , 𝒚𝟏 Stage 2
Stage 1
𝑩, 𝒙𝑩
SOLUTION
The following steps will be followed to solve this problem:
▪ Development of the model for this system.
▪ Specification of the parameters, forcing functions, some unknown variables if the
degree of freedom is not zero, and nominal or initial steady-state conditions.
▪ Writing of the MATLAB programme to simulate the system.
24
Relevant model equations for simulation
Condenser and Reflux Drum, i = 𝑵𝑻 (𝑴𝒊 = 𝑴𝑵𝑻 = 𝑴𝑫 , 𝑳𝒊 = 𝑳𝑵𝑻 = 𝑳𝑻 , 𝒙𝒊 = 𝒙𝑵𝑻 = 𝒙𝑫 )
▪ Total continuity equation:
𝒅𝑴𝒊
= 𝑽𝒊−𝟏 − 𝑳𝒊 − 𝑫 (3.8)
𝒅𝒕
▪ Component continuity equation (more volatile component):
𝒅 𝑴𝒊 𝒙 𝒊
= 𝑽𝒊−𝟏 𝒚𝒊−𝟏 − 𝑳𝒊 𝒙𝒊 − 𝑫𝒙𝑫 (3.9)
𝒅𝒕
Column stages (or trays) excluding condenser, feed stage and reboiler
▪ Total continuity equation on stage i (same as stage n in section 2.9 of topic
two): 𝒅𝑴𝒊
= 𝑳𝒊+𝟏 + 𝑽𝒊−𝟏 − 𝑳𝒊 − 𝑽𝒊 (3.10)
𝒅𝒕
▪ Component continuity equation (more volatile component) on stage i :
𝒅 𝑴𝒊 𝒙 𝒊
= 𝑳𝒊+𝟏 𝒙𝒊+𝟏 + 𝑽𝒊−𝟏 𝒚𝒊−𝟏 − 𝑳𝒊 𝒙𝒊 − 𝑽𝒊 𝒚𝒊 (3.11)
𝒅𝒕
Feed stage, i = 𝑵𝑭
▪ Total continuity equation:
𝒅𝑴𝒊
= 𝑳𝒊+𝟏 + 𝑽𝒊−𝟏 − 𝑳𝒊 − 𝑽𝒊 + 𝑭 (3.12)25
𝒅𝒕
▪ Component continuity equation (more volatile component):
𝒅 𝑴𝒊 𝒙 𝒊
= 𝑳𝒊+𝟏 𝒙𝒊+𝟏 + 𝑽𝒊−𝟏 𝒚𝒊−𝟏 − 𝑳𝒊 𝒙𝒊 − 𝑽𝒊 𝒚𝒊 + 𝑭𝒛𝑭 (3.13)
𝒅𝒕
▪ Now, the time rate of change of the composition alone in any stage can be
obtained by applying product rule to the dynamic terms of Eqs. (3.9), (3.11),
(3.13), (3.15) as follows:
𝒅 𝑴𝒊 𝒙 𝒊 𝒅𝑴𝒊
𝒅𝒙𝒊 − 𝒙 𝒊
𝒅𝒕 𝒅𝒕
=
𝒅𝒕 𝑴𝒊
Algebraic equations
▪ The vapour composition 𝒚𝒊 is related to the liquid composition 𝒙𝒊 on the same
stage through the algebraic vapour-liquid equilibrium.
𝜶𝒙𝒊
𝒚𝒊 = (3.16)
𝟏 + 𝜶 − 𝟏 𝒙𝒊
▪ Depending on the feed condition, the vapour flow rate from the feed stage to
the next stages above is given by
𝑽𝑵𝑭 = 𝑽𝑭−𝟏 + 𝟏 − 𝒒𝑭 𝑭
where 𝒒𝑭 is a factor for the feed condition. It is defined as mole fraction of the
liquid in the feed. Therefore, it is equal to 1 for saturated liquid feed.
Therefore, from the assumption of constant molar vapour flows and no
vapour flow dynamics, we have
𝑽𝒊 = 𝑽𝒊−𝟏 𝒊 = 𝟏 𝒕𝒐 𝑵𝑭−𝟏 (3.17a)
▪ Similarly, depending on the feed condition, the liquid flow rate from the feed
stage to the next stages below is given by
𝑳𝑵𝑭 = 𝑳𝑭+𝟏 + 𝒒𝑭 𝑭
27
In liquid phase, there is a liquid flow dynamics. In addition, there is a dependence
of the liquid flow rate on liquid holdup and vapour flow rate which can be
represented by a linearized hydraulic equation as follows:
𝑳𝒊 = 𝑳𝒔𝒊 + 𝑴𝒊 − 𝑴𝒔𝒊 𝝉𝑳 + 𝑽𝒊−𝟏 − 𝑽𝒔𝒊−𝟏 𝝀 (3.18)
where subscript s denotes the nominal or initial steady state values. 𝝉𝑳 = time
constant, 𝝀 = constant for effect of vapour flow on liquid flow ( i.e. K2-effect).
NOTE: Eq. (3.18) is only applicable to column stages. However, considering the
condition of the feed, the equation needs to be written in two forms: the first one
from stage 2 to 𝑁𝐹 and the second one from stage 𝑁𝐹+1 to 𝑁𝑇−1 .
Degrees of freedom of the system:
❖ The parameters and their values: 𝑵𝑻, 𝜶, 𝝀, 𝝉𝑳 , 𝑵𝑭 and 𝒒𝑭 .
❖ The forcing functions that are to be specified are 𝑭 and 𝒛𝑭 .
❖ The number of dependent variables and the number of equations are presented
in the tables in the next slide. From the tables, the number of unknown variables
is 4𝑵𝑻 +1 while number of equations is 4𝑵𝑻 −3.
❖ Therefore, the degree of freedom = (4𝑵𝑻 +1 ) – (4𝑵𝑻 −3) = 4.
This means that four unknown variables must be specified in addition to the
forcing functions to be able to simulate the system.
NOTE: The forcing functions can be considered as dependent or unknown
variables as it is done in some texts. This will still result to specifying six variables. 28
Number of dependent variables
Source No. of
variables
Liquid and vapour flow compositions in column stages (𝒙𝒊 and 𝒚𝒊 : 𝒊 ≠ 1, 𝑵𝑻 ) 2𝑵𝑻 − 𝟒
Condenser/reflux composition (𝒙𝑫 ) and reboiler compositions (𝒙𝑩 and 𝒚𝑩 ) 3
Column liquid flows (𝑳𝒊 : 𝒊 ≠ 1, 𝑵𝑻 ) 𝑵𝑻 − 𝟐
Condenser/reflux flows (𝑳𝑵𝑻 and 𝑫) 2
Reboiler flows (𝑽∗ and 𝑩) 2
Column liquid holdups (𝑴𝒊 : 𝒊 ≠ 1, 𝑵𝑻) 𝑵𝑻 −2
Condenser/reflux drum holdup (𝑴𝑫 ) and reboiler holdup (𝑴𝑩 ) 2
Total 4𝑵𝑻 +1
*Because of constant molar vapour flow assumption, only one vapour flow is needed
Number of equations
Source Equation No. of
equations
Tray total continuity (3.3) 𝑵𝑻
Tray component continuity (3.4) 𝑵𝑻
Stage equilibrium relations (minus condenser/reflux drum) (3.9) 𝑵𝑻 −1
Hydraulic (minus condenser/reflux drum and reboiler) (3.11) 𝑵𝑻 −2
Total 4𝑵𝑻 −3
29
Specification of relevant data
Parameters
𝑁𝑇 = 41, 𝛼 = 1.5, 𝜆 = 0 (i.e. no vapour effect) , 𝜏𝐿 = 0.063 min, 𝑁𝐹 = 21, 𝑞𝐹 = 1.
Forcing functions
𝐹 = 1.0 kmol/min, 𝑧𝐹 = 0.5
Additional four unknown variables
𝐿𝑁𝑇 = 𝐿 𝑇 = 2.70629 kmol/min, 𝑉1 = 𝑉𝐵 = 3.20629 kmol/min,
𝐷 = 0.5 kmol/min, 𝐵 = 0.5 kmol/min
▪ Nominal values of data specifically for the linearized hydraulic equation. They are
needed only because their nominal values are part of the hydraulic equation):
➢ Nominal liquid holdup above the feed stage, 𝐿𝑠 = 2.70629 kmol/min,
➢ Nominal liquid holdup in feed stage and below: 𝐿𝑠𝑏 = 𝐿𝑠 + 𝑞𝐹 𝐹
➢ Nominal vapour holdup below the feed stage, (only needed if 𝜆 ≠ 0), 𝑉𝑠 =
3.20629 kmol/min,
➢ Nominal vapour holdup in feed and above: 𝑉𝑠𝑡 = 𝑉𝑠 + (1 − 𝑞𝐹 )𝐹
30
Simulation of the system
▪ Programme
Function file:
function xprime = distilmod(t,X)
%------------------------------------------------------------
31
% Parameter Values:
% Number of stages (including reboiler and total condenser):
NT=41;
% Location of feed stage (stages are counted from the bottom):
NF=21;
% Relative volatility
alpha=1.5;
% Fraction of liquid in feed
qF =1.0;
% Time constant for liquid dynamics (min)
taul=0.063;
% Effect of vapor flow on liquid flow ("K2-effect")
lambda=0;
%------------------------------------------------------------
% Forcing functions and Inputs or Specified Variables
F=1.0; % Feed flow rate
zF=0.5; % Feed composition
LT=2.70629; % Reflux
VB=3.20629; % Boilup
D=0.5; % Distillate
B=0.5; % Bottoms
%------------------------------------------------------------
% Nominal or Initial Steady-State Conditions (They are needed in
% function file only for the linearized hydraulic equation).
% Nominal liquid holdups: (They are also given as arguments of the ode
% function in the run file since they are in the differential
% terms of the differential equations):
32
Ms(1)=0.5; % Nominal reboiler holdup (kmol)
i=2:NT-1; Ms(i)=0.5*ones(1,NT-2);% Nominal stage (tray) holdups (kmol)
Ms(NT)=0.5; % Nominal condenser holdup (kmol)
% Nominal liquid and vapour flow rates for linearized hydraulic and
% differential equations (does not apply to reboiler and condenser):
Ls=2.70629; % Nominal liquid flow above the feed stage
Lsb=L0 + qF*F; % Nominal liquid flow in feed stage and below feed
Vs=3.20629; % Nominal vapor flow below the feed stage
Vst=Vs+(1-qF)*F; % Nominal vapor flow in feed stage and above
%------------------------------------------------------------
% Splitting the States
x=X(1:NT)'; % Liquid composition from bottom to top
M=X(NT+1:2*NT)'; % Liquid hold up from bottom to top
%------------------------------------------------------------
% THE MODEL
% Vapor-liquid equilibria
i=1:NT-1; y(i)=alpha*x(i)./(1+(alpha-1)*x(i));
% Column
i=2:NT-1;
dMdt(i) = L(i+1) - L(i) + V(i-1) - V(i);
dMxdt(i)= L(i+1).*x(i+1) - L(i).*x(i) + V(i-1).*y(i-1) - V(i).*y(i);
%------------------------------------------------------------
% Output
xprime=[dxdt';dMdt'];
34
Run file (Using ode15s solver):
clc
clear all
[t,X]=ode15s('distilmod',[0:5:200],0.5*ones(1,82));
plot(t,X(:,42),'+',t,X(:,82),'*',t,X(:,1),'s',t,X(:,41))
legend('M1','MNT','x1', 'xNT')
xlabel('time (s)')
ylabel('Liquid holdup (kmol) and composition')
title('Example 3.3a')
35
Fig. 3.6: Plot when the feed is 1.0 kmol/min 36
Fig. 3.7: Plot when the feed is 1.01 kmol/min 37