You are on page 1of 46

Phn 2: m phng my tnh

Modeling, simulation and optimization for chemical process

Instructor: Hoang Ngoc Ha Email: ha.hoang@hcmut.edu.vn B mn QT&TB

Introduction

Numerical Analysis

Computer Programming
TION

SIMULA

Computer simulation
Some simulation techniques for solving some of the systems of equations
Solution of (nonlinear) algebraic equations Ordinary differential equations (ODEs) Partial differential equations (PDEs)

Numerical methods
Iterative methods Discrete difference methods Femlab, Fortran, Ansys

Matlab/Simulink

Computer simulation
Computer programming
Assume that you know some computer programming language We are not interested in generating the most efficient and elegant code but in solving problems (from point of view of engineers)
Including extensive comment statements Use of symbols (the same ones in the equations describing the systems) Debugging (for mistakes in coding and/or in logic)

Computer simulation

Example:

Computer simulation

Computer simulation

Computer simulation
Interval halving (chia i khong)

Computer simulation
This problem can be formulated under the following form:

f (x) = 0, x R
The goal is to find the solution of this nonlinear equations (in ONE VARIABLE) Tools (Iterative methods)
Bisection method (phng php phn on) Newtons (or Newton-Raphson) method

Iterative method
Intermediate value theorem
If f is a real-valued continuous function on the interval [a, b], and u is a number between f(a) and f(b), then there is a c [a, b] such that f(c) = u

If f(a) and f(b) are of opposite sign, there exist a number p in [a, b] with f(p)=0

Iterative method
Bisection method

Computer programming: Matlab

Iterative method
Newtons method

Numerical solutions of nonlinear systems of equations (of SEVERAL VARIABLES) (See Ref.)

Computer simulation
Interpolation and polynomial approximation
Interpolation and the Lagrange polynomial Cubic spline interpolation

Numerical differentiation and intergration


Numerical differentiation Richardsons extrapolation

(See Ref.)

Numerical intergration of Ordinary Differential Equations (ODEs)

Numerical intergration of Ordinary Differential Equations (ODEs)

y(t) y(t0 ) y(t1 ) x


x Interpolation

y(tN )
x

t0 t1

tN t

Numerical intergration of Ordinary Differential Equations (ODEs)


Tools:
Eulers method Higher-Order Taylor methods Runge-Kutta methods

Numerical intergration of Ordinary Differential Equations (ODEs)


Eulers method

Numerical intergration of Ordinary Differential Equations (ODEs)


Eulers method

Numerical intergration of Ordinary Differential Equations (ODEs)


Example

y 0 = y t2 + 1, t [0 2] y(0) = 0.5
P/p Euler n=10? Approximate solution?

Exact solution?

n = 10 h =

ba n

= 0.2

y(t) = 0.5 exp(t) + (t + 1)2


Computer programming: Matlab

Numerical intergration of Ordinary Differential Equations (ODEs)


Local truncation error
Definition

The local truncation error in Eulers method is

O(h)

Numerical intergration of Ordinary Differential Equations (ODEs)


Higher-Order Taylor methods

Numerical intergration of Ordinary Differential Equations (ODEs)


Higher-Order Taylor methods

Numerical intergration of Ordinary Differential Equations (ODEs)


Runge-Kutta methods

Numerical intergration of Ordinary Differential Equations (ODEs)


Runge-Kutta methods
Xy dng cng thc tnh wi+1 theo wi m khng phi o hm tay , cn xp x T (k) m khng dng o hm vi O(hk )
Minh ha qua k=2

(2)

(t, y) = f (t, y) +

0 f 0 (t, y) = ft0 (t, y) + fy (t, y)y (t)

h 0 f (t, y) 2 0

f (t, y)

Numerical intergration of Ordinary Differential Equations (ODEs)


Nh vy

(2)

(t, y) = f (t, y) +

h 0 f (t, y) 2 t

h 0 f (t, y)f (t, y) 2 y

Cn tm a1 , 1 , 1 vi sai s O(h2 )

a1 f (t + 1 , y + 1 ) ' T (2) (t, y) f (t + 1 , y + 1 ) ' f (t, y) + 0 +fy (t, y)1


0 ft (t, y)1

Numerical intergration of Ordinary Differential Equations (ODEs)


Cn chn
0 a1 f (t, y) + a1 1 ft0 (t, y) + a1 1 fy (t, y) = h 0 h 0 f (t, y) + 2 ft (t, y) + 2 fy (t, y)f (t, y)

ng nht hai v

a1 = 1 a1 1 = h 2 a1 1 = h f (t, y) 2

a1 = 1 1 = h 2 h 1 = 2 f (t, y)

Numerical intergration of Ordinary Differential Equations (ODEs)


wi+1 wi+1 = wi + hT (2) (ti , wi ) h i h h = wi + h f (ti + 2 , wi + 2 f (ti , wi )) w0 = h k1 = 2 f (ti , wi ) k2 = hf (ti + h , wi + k1 ) 2 wi+1 = wi + k2

S trung im (R_K bc 2)

Computer programming: Matlab

Numerical intergration of Ordinary Differential Equations (ODEs)


S R_K bc 4

w0 = k = hf (t , w ) 1 i i k1 h k2 = hf (ti + 2 , wi + 2 ) k2 h k3 = hf (ti + 2 , wi + 2 ) k4 = hf (ti + h, wi + k3 ) 1 wi+1 = wi + 6 (k1 + 2k2 + 2k3 + k4 )


V nh t c R_K cho h v vit chng trnh R_K cho h

Numerical intergration of Partial Differential Equations (PDEs)


Click here

Gii thiu chung

Inlet material and/or energetic flux

u = u(x . . . , t)

dV n chemical species P k k Sk = 0
H PHN B

Outlet material and/or energetic flux

mt i lng vt l ca h kho st Profile

{C, T . . . }

Local observation

Ba dng phng trnh o hm ring c bn


ng hc bin h thng u = u(x . . . , t) c th thuc v cc dng phng trnh sau: Phng trnh elliptic (tnh-static)
2u x2

+
u t

2u y 2

= f (x, y)

P/t parabolic (b/ton truyn nhit)

Phng trnh hyperbolic (b/ton truyn sng)


2u t2

2 2u a x2

2 2u a x2

Ba dng phng trnh o hm ring c bn


Phng php tm nghim
Phng php gii tch Phng php s
tng: xp x sai phn cc o hm ring ti cc im ri rc (kg,tg) v tnh gi tr ca

u = u(x . . . , t) ti t (x, t + t) t u(x, t) (x, t) x

u(x,t) t

u(x,t+t)u(x,t) t

Xp x sai phn
t (x x, t) (x + x, t) x (x, t) x
2 u(x,t) x2

u(x+x,t)2u(x,t)+u(xx,t) (x)2

Xp x sai phn
y P4 y P1 x P P2

P3 P = (x, y) x

h = x = y

2 u(P ) x2

2 u(P ) y 2

u(P1 )+u(P2 )+u(P3 )+u(P4 )4u(P ) h2

BI TON ELLIPTIC
(
Bi ton elliptic vi iu kin bin Dirichlet

+ = f (x, y), (x, y) R2 u = u(x, y) = g(x, y), (x, y)

2u x2

2u y 2

BI TON ELLIPTIC
Phn hoch v to li : chia nh bi cc ng thng // vi Ox v Oy
To li bc chia cch u

h = x = y
K hiu P1, P2, P3 v P4 l 4 im ri rc x/q P u(P1 )+u(P2 )+u(P3 )+u(P4 )4u(P ) h2

u(P ) Ln lt thay Pk = (xk , yk ) vo phng trnh elliptic, s H PTTT n uk = u(Pk ) dng cng thc xp x & iu kin bin

BI TON ELLIPTIC
Example

Li 4 nt n

nh s 4 gi tr cn tm. SD PTSP & Gi tr trn bin

H PTTT

M phng Matlab

BI TON PARABOLIC (m hnh truyn nhit)

BI TON PARABOLIC (m hnh truyn nhit)

BI TON PARABOLIC (m hnh truyn nhit)


Phn hoch v xp x
Chia cch u bc x v Mc th k: t (k)

= kt u = (. . . uk . . . ) i u(0) bit Mc th 0: u(1) cha bit Mc th 1:

Xp x o hm ring cp 1:

u(x,t) t

TIN - LI

BI TON PARABOLIC (m hnh truyn nhit)


V d

S hin (s/p tin)

S n (s/p li)

BI TON PARABOLIC (m hnh truyn nhit tng qut)

Min

= {(x, t)|0 x 1, t 0}

Xp x

u u 2 u , , t x x2

& K bin, u

Gi tr u ti cc im li

Sai phn tin & Sai phn li

BI TON PARABOLIC (m hnh truyn nhit)

BI TON PARABOLIC (m hnh truyn nhit)


K hiu u(k)
k k = [uk . . . uk ], f (k) = [f1 . . . fn ] n 1

BI TON PARABOLIC (m hnh truyn nhit)


S Crank-Nicholson

Outline
General introduction
Structure and operation of chemical engineering systems What is a chemical process? Motivation examples

Part I: Process modeling Part II: Computer simulation Part III: Optimization of chemical processes

You might also like