You are on page 1of 22

CHEMICAL ENGINEERING

COMPUTATION
KKKK3522

Jarinah Mohd Ali, PhD


Jabatan Kejuruteraan Kimia & Proses
Fakulti Kejuruteraan dan Alam Bina
Universiti Kebangsaan Malaysia

jarinah@ukm.edu.my
BOUNDARY VALUE
PROBLEMS
OBJECTIVES
1) Able to differentiate the initial-value and boundary-
value problems.
2) Able to express an nth order ODE as a system of n
first-order ODEs.
3) Able to use the shooting method for linear and
nonlinear ODEs
4) Understanding how derivative boundary conditions
are incorporated into the shooting method.
5) Able to implement the finite difference method

28/11/2019 KKKK3522 Chemical Engineering Computation 2


BOUNDARY VALUE PROBLEMS

• Ordinary differential equation (ODE) often deals


with an initial value problem, where all conditions
are specified at the same value of independent
variable.
• If nth order of system, n conditions are required
• However, some cases are dealing with unknown
single point conditions but given at different values
of the independent variables
• Thus, specified at extreme point or boundaries and
addressed as boundary-value problems
• In order to solve the boundary value problem
numerically shooting method is applied

28/11/2019 KKKK3522 Chemical Engineering Computation 3


SHOOTING METHOD

• Based on converting the boundary-


value problem into an equivalent
initial-value problem
• A guess is required undefined
values since the system do not have
sufficient initial conditions
• The guesses are changed following
a trial and error approach to obtain
a final solution that satisfies all the
boundary conditions

28/11/2019 KKKK3522 Chemical Engineering Computation 4


BOUNDARY CONDITIONS

TWO TYPES OF BOUNDARY CONDITIONS


WHERE SHOOTING METHOD CAN BE APPLIED

1. Dirichlet boundary conditions are those where a fixed


value of a variable is known at a particular location

2. Neumann boundary conditions are those where a


derivative is known at a particular location

28/11/2019 KKKK3522 Chemical Engineering Computation 5


SHOOTING METHOD FOR LINEAR ODE
Consider a linear ODE for the heated rod as follows:

(1)

Subject to a boundary conditions:

Convert this boundary value problem into an initial value problem by


defining the rate of change of temperature or the gradient:

2 pairs of
Re-expressed the above equation (1): ODEs

28/11/2019 KKKK3522 Chemical Engineering Computation 6


SHOOTING METHOD FOR LINEAR ODE

If initial condition of ! and " are available, those equations can be easily
solved using initial-value problem. Unfortunately, only ! 0 = !% is
available, thus the value for " 0 = "%,' is guessed.

Then by considering interpolation approach:

28/11/2019 KKKK3522 Chemical Engineering Computation 7


SHOOTING METHOD FOR LINEAR ODE
Apply shooting method to solve Eqn. (1), given ! = 10%, ℎ( =
0.05%+,, -. = 200 K, - 0 = 300 K and - 10 = 400 K, ∆3 = 2
Solution
Known - 0 = 300 K , guess 45,6 = −5 K/m for 4 0 . Then
integrate from 3 = 0 to 3 = 10
Help ODE45
in MATLAB
In MATLAB : ODE45 solver
tspan = [0 10];
y0 = [300,-5];
[t,y] = ode45(@(t,y) [y(2);-0.05*(200-y(1))], tspan, y0);
%Plot the solution.
plot(t,y,'-o')
28/11/2019 KKKK3522 Chemical Engineering Computation 8
SHOOTING METHOD FOR NONLINEAR ODE

1. Similarly, the nonlinear second-order equation is first expressed


as two first-order ODEs
2. Generate the coding to solve the problem

In MATLAB : ODE45 solver nonlinear equation

tspan = [0 10];
y0 = [300,-5];
[t,y] = ode45(@(t,y) [y(2);-0.05*(200-y(1))-2.7e-9*(1.6e9-
y(1)^4)], tspan, y0);

28/11/2019 KKKK3522 Chemical Engineering Computation 9


FINITE-DIFFERENCE METHOD

Recall the heated rod, now divide it into series of nodes

Then converted into algebraic equation to use finite-difference


method

In Matrix form:

28/11/2019 KKKK3522 Chemical Engineering Computation 10


INCORPORATE DERIVATIVE BOUNDARY

Using Neumann boundary conditions

dt/dx
In matrix form we get: given

28/11/2019 KKKK3522 Chemical Engineering Computation 11


FINITE-DIFFERENCE METHOD

Coding in MATLAB

A = [2.2 -1 0 0; -1 2.2 -1 0; 0 -1 2.2 -1; 0 0 -1 2.2];


b = [340; 40; 40; 440];
T = A\b;

Coding in MATLAB with Neumann boundary conditions


A = [2.2 -2 0 0 0; -1 2.2 -1 0 0; 0 -1 2.2 -1 0; 0 0 -1
2.2 -1; 0 0 0 -1 2.2];
b = [40; 40; 40; 40; 440];
T = A\b;

28/11/2019 KKKK3522 Chemical Engineering Computation 12


ASSIGNMENT FINITE- DIFFERENCE
METHOD
Solve below nodes in two conditions:
a) Without boundary condition Dateline:
06/12/2019
b) With boundary condition, if T5 = 200

28/11/2019 KKKK3522 Chemical Engineering Computation 13


ADDITIONAL USAGE OF ODE

28/11/2019 KKKK3522 Chemical Engineering Computation 14


PROCESS MODELLING USING
SIMULINK & M-FILE ODE SOLVER

Link ODE solver in m-file with SIMULINK

28/11/2019 KKKK3522 Chemical Engineering Computation 15


PROCESS MODELLING USING
SIMULINK & M-FILE ODE SOLVER

1. Divide m-file into 3:


a) solvingode.m
b) reactor.m
c) Reactor_sfcn.m
2. Create a SIMULINK model (use s-function block from
SIMULINK Library)
3. Save all files in similar folder/path
4. Run only the SIMULINK model

28/11/2019 KKKK3522 Chemical Engineering Computation 16


PROCESS MODELLING USING
SIMULINK & M-FILE ODE SOLVER

a) solvingode.m

%Solving the ODE45 of CSTR

[t,x] = ode45(@reactor,[0 10],[0.1;40],[],55);

% manipulated variable = Tj = 55

28/11/2019 KKKK3522 Chemical Engineering Computation 17


PROCESS MODELLING USING
SIMULINK & M-FILE ODE SOLVER
b) reactor.m
R = 1.987;
V = 750;
function dx = reactor(t,x,u) F = 3000;
% Caf = 0.132;
% model for reactor Tf = 60;
% Tj = 55;
A =1221;
Ca = x(1); %lbmol/ft^3
T = x(2); % degF ra = k0*exp(-
Ea/(R*(T+460)))*Ca;
Ea = 32400; %BTU/lbmol dCa = (F/V)*(Caf-Ca)-ra;
k0 = 15e12; %hr^-1 dT = (F/V)*(Tf-T)-
dH = -45000; %BTU/lbmol (dH)/(rhocp)*ra-
U = 75; %BTU/hr-ft^2-degF (U*A)/(rhocp*V)*(T-Tj);
rhocp = 53.25; %BTU/ft^-3
dx = [dCa;dT];

28/11/2019 KKKK3522 Chemical Engineering Computation 18


s.NumContStates
= 2;

PROCESS MODELLING USING


s.NumDiscStates
= 0;
s.NumOutputs =

SIMULINK & M-FILE ODE SOLVER


2;
s.NumInputs = 1;
s.DirFeedthrough
= 0;
s.NumSampleTimes

c) Reactor_sfcn.m
= 1;

sys = simsizes(s);

x0 = [Cinit, Tinit];
function [sys,x0,str,ts] =
reactor_sfcn(t,x,u,flag,Cinit,Ti case 1 % derivatives
nit)
u = 55;
switch flag Tj = u;
sys =
case 0 % initialize reactor(t,x,Tj);

str = []; case 3 % output


ts = [0 0];
sys = x;
s = simsizes;
case {2 4 9} %
s.NumContStates 2:discrete
= 2; %
s.NumDiscStates 4:calcTimeHit
= 0; %
s.NumOutputs = 9:termination
2;
s.NumInputs = 1; sys = [];
s.DirFeedthrough
= 0; otherwise
s.NumSampleTimes
= 1; error(['unhandled flag =
',num2str(flag)]);
sys = simsizes(s);

x0 = [Cinit, Tinit]; end

28/11/2019
case 1 % KKKK3522 Chemical Engineering Computation
derivatives 19
PROCESS MODELLING USING
SIMULINK & M-FILE ODE SOLVER
2. Create a SIMULINK model (use s-function block from
SIMULINK Library)

28/11/2019 KKKK3522 Chemical Engineering Computation 20


PROCESS MODELLING USING
SIMULINK & M-FILE ODE SOLVER

3. Save all files in similar folder/path


4. Run only the SIMULINK model

28/11/2019 KKKK3522 Chemical Engineering Computation 21

You might also like