You are on page 1of 46

om

.c
ng
Phần 2: mô phỏng máy tính

co
an
Modeling, simulation and optimization for chemical process

th
o ng
Instructor: Hoang Ngoc Ha
du
u

Email: ha.hoang@hcmut.edu.vn
cu

Bộ môn QT&TB

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Introduction

om
.c
ng
co
Numerical Computer

an
Analysis Programming
th
o ng
du
u
cu

SIMULA TION

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Computer simulation

om
„ Some simulation techniques for solving some

.c
of the systems of equations

ng
Solution of (nonlinear) algebraic equations

co
‰

Ordinary differential equations (ODEs)

an
‰

th
‰ Partial differential equations (PDEs)
„ Numerical methods
o ng
du

‰ Iterative methods
u
cu

‰ Discrete difference methods


‰ Femlab, Fortran, Ansys… Matlab/Simulink

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Computer simulation

om
„ Computer programming

.c
‰ Assume that you know some computer

ng
programming language

co
‰ We are not interested in generating the most

an
efficient and elegant code but in solving problems

th
(from point of view of engineers)
„
o ng
Including extensive comment statements
du

„ Use of symbols (the same ones in the equations


describing the systems)
u
cu

„ Debugging (for mistakes in coding and/or in logic)


„ …

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Computer simulation

om
.c
ng
Example:

co
an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Computer simulation

om
.c
ng
co
an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Computer simulation

om
.c
ng
co
an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Computer simulation

om
„ Interval halving (chia đôi khoảng)

.c
ng
co
an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Computer simulation

om
„ This problem can be formulated under the

.c
following form:

ng
f (x) = 0, x ∈ R

co
an
th
„ The goal is to find the solution of this
ng
nonlinear equations (in ONE VARIABLE)
o
du

„ Tools (Iterative methods)


u

Bisection method (phương pháp phân đoạn)


cu

‰ Newton’s (or Newton-Raphson) method

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Iterative method

om
„ Intermediate value theorem

.c
‰ If f is a real-valued continuous function on the

ng
interval [a, b], and u is a number between f(a) and

co
f(b), then there is a c ∈ [a, b] such that f(c) = u

an
th
o ng
du
u
cu

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

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Iterative method
„ Bisection method

om
.c
ng
co
an
th
o ng
du
u
cu

Computer programming: Matlab

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Iterative method
„ Newton’s method

om
.c
ng
co
an
th
o ng
du
u
cu

Numerical solutions of nonlinear systems of equations (of


SEVERAL VARIABLES)Î (See Ref.)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Computer simulation

om
„ Interpolation and polynomial approximation

.c
‰ Interpolation and the Lagrange polynomial

ng
Cubic spline interpolation

co
‰

an
‰

th
„ Numerical differentiation and intergration
ng
Numerical differentiation
o
‰
du

‰ Richardson’s extrapolation
u
cu

‰ …

(See Ref.)

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Numerical intergration of Ordinary
Differential Equations (ODEs)

om
.c
ng
co
an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Numerical intergration of Ordinary
Differential Equations (ODEs)

om
.c
ng
co
an
y(t) y(t0 )

th
x y(t1 ) o ng y(tN )
x
du

x
u
cu

Interpolation

t0 t1 tN t

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Numerical intergration of Ordinary
Differential Equations (ODEs)

om
„ Tools:

.c
ng
co
‰ Euler’s method

an
th
‰ Higher-Order Taylor methods
o ng
du

‰ Runge-Kutta methods
u
cu

‰ …

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Numerical intergration of Ordinary
Differential Equations (ODEs)

om
„ Euler’s method

.c
ng
co
an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Numerical intergration of Ordinary
Differential Equations (ODEs)

om
„ Euler’s method

.c
ng
co
an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Numerical intergration of Ordinary
Differential Equations (ODEs)

om
„ Example

.c
y 0 = y − t2 + 1, t ∈ [0 2]

ng
co
y(0) = 0.5

an
P/p Euler n=10?

th
Approximate solution?
o ng
b−a
n = 10 ⇒ h = = 0.2
du

n
u

Exact solution?
cu

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


Computer programming: Matlab

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Numerical intergration of Ordinary
Differential Equations (ODEs)

om
„ Local truncation error

.c
Definition

ng
co
an
th
o ng
du
u
cu

The local truncation error in Euler’s method is O(h)

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Numerical intergration of Ordinary
Differential Equations (ODEs)

om
„ Higher-Order Taylor methods

.c
ng
co
an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Numerical intergration of Ordinary
Differential Equations (ODEs)

om
„ Higher-Order Taylor methods

.c
ng
co
an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Numerical intergration of Ordinary
Differential Equations (ODEs)

om
„ Runge-Kutta methods

.c
ng
co
an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Numerical intergration of Ordinary
Differential Equations (ODEs)

om
„ Runge-Kutta methods

.c
‰ Xây dựng công thức tính wi+1 theo wi mà không

ng
phải đạo hàm « tay », cần xấp xỉ T (k) mà không

co
dùng đạo hàm với O(hk )

an
Minh họa qua k=2

th
„

T (2) o ng
(t, y) = f (t, y) + h 0
f (t, y)
2
du

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


u
cu

f (t, y)

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Numerical intergration of Ordinary
Differential Equations (ODEs)

om
Như vậy

.c
ng
(2) h 0 h 0
T (t, y) = f (t, y) + f (t, y)
2 t
+ f (t, y)f (t, y)
2 y

co
an
Cần tìm a1 , α1 , β1 với sai số O(h2 ) để

th
ng
a1 f (t + α1 , y + β1 ) ' T (2) (t, y)
o
du
u

0
f (t + α1 , y + β1 ) ' f (t, y) + ft (t, y)α1
cu

+fy0 (t, y)β1

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Numerical intergration of Ordinary
Differential Equations (ODEs)

om
Cần chọn

.c
a1 f (t, y) + a1 α1 ft0 (t, y) + a1 β1 fy0 (t, y) =

ng
h 0 h 0

co
f (t, y) + 2 ft (t, y) + 2 fy (t, y)f (t, y)

an
Đồng nhất hai vế

th
⎧ ng ⎧
⎨ a1 = 1 ⎨ a1 = 1
o
du

a1 α1 = h2 α1 = h2
u

⎩ ⎩
cu

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

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Numerical intergration of Ordinary
Differential Equations (ODEs)

om
wi+1 = wi + hT (2) (ti , wi )

.c
h i

ng
h h
wi+1 = wi + h f (ti + 2 , wi + 2 f (ti , wi ))

co
an
Sơ đồ trung điểm (R_K bậc 2)

th

⎪ w0 = α ng

o

du
h
k1 = 2 f (ti , wi )
u

h
cu


⎪ k 2 = hf (ti + , wi + k1 )
⎩ 2
wi+1 = wi + k2
Computer programming: Matlab

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Numerical intergration of Ordinary
Differential Equations (ODEs)

om
Sơ đồ R_K bậc 4

.c

ng

⎪ w 0 = α

co

⎪ k = hf (t , w )

an


1 i i
h k1

th
k2 = hf (ti + 2 , wi + 2 )
⎪ h k2
k3 = hf (ti + 2 , wi + 2 )
o ng


du


⎪ k4 = hf (ti + h, wi + k3 )

u


cu

1
wi+1 = wi + 6 (k1 + 2k2 + 2k3 + k4 )

Về nhà tự đọc R_K cho hệ và viết chương trình R_K cho hệ

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Numerical intergration of Partial
Differential Equations (PDEs)

om
„ Click here

.c
ng
co
an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Giới thiệu chung

om
.c
ng
Inlet material and/or
dV

co
energetic flux
n chemical species
P

an
Outlet material
k νk Sk = 0

th
and/or energetic flux
o ng
du

u = u(x . . . , t) một đại lượng vật lý của hệ khảo sát


u
cu

Profile

{C, T . . . } HỆ PHÂN BỐ
Local observation

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Ba dạng phương trình đạo hàm riêng cơ
bản

om
Động học biến hệ thống u = u(x . . . , t) có

.c
thể thuộc về các dạng phương trình sau:

ng
„ Phương trình elliptic (tĩnh-static)

co
∂2u ∂2u

an
+ = f (x, y)

th
∂x2 ∂y 2
„ P/t parabolic (b/toán truyền nhiệt)
o ng
∂u 2 ∂2u
du

∂t
= a ∂x2
u

Phương trình hyperbolic (b/toán truyền sóng)


cu

∂2u 2 ∂2u
∂t2
= a ∂x2

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Ba dạng phương trình đạo hàm riêng cơ
bản

om
„ Phương pháp tìm nghiệm

.c
‰ Phương pháp giải tích

ng
Phương pháp số

co
‰

an
Ý tưởng: xấp xỉ sai phân các đạo hàm riêng tại các điểm rời rạc (kg,tg)

th
và tính giá trị của u = u(x . . . , t) tại đó
ng (x, ∆t + t)
t
o

du

∆t u(x, t)
u

∂u(x,t) u(x,t+∆t)−u(x,t)

cu

∂t ∆t

(x, t)
x
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Xấp xỉ sai phân

om
t

.c
ng
co
(x − ∆x, t) (x + ∆x, t)

an
• • •

th
∆x (x, t) o ng
du

x
u
cu

∂ 2 u(x,t) u(x+∆x,t)−2u(x,t)+u(x−∆x,t)
∂x2
≈ (∆x)2

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Xấp xỉ sai phân

om
y P4

.c

ng
P1 ∆y P3

co
• • •
∆x P

an
th
h = ∆x = ∆y •
o ng P2 P = (x, y)
du

x
u
cu

∂ 2 u(P ) ∂ 2 u(P ) u(P1 )+u(P2 )+u(P3 )+u(P4 )−4u(P )


∂x2 + ∂y 2
≈ h2

CuuDuongThanCong.com https://fb.com/tailieudientucntt
BÀI TOÁN ELLIPTIC

om
„ Bài toán elliptic với điều kiện biên Dirichlet

.c
(

ng
∂2u ∂2u
∆u = + = f (x, y), (x, y) ∈ Ω ⊂ R2

co
∂x2 ∂y 2
u(x, y) = g(x, y), (x, y) ∈ Γ

an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
BÀI TOÁN ELLIPTIC

om
„ Phân hoạch và tạo lưới Ω : chia nhỏ Ω bởi

.c
các đường thẳng // với Ox và Oy

ng
Tạo lưới bước chia cách đều

co
an
h = ∆x = ∆y

th
o ng Kí hiệu P1, P2, P3 và P4 là 4
du

điểm rời rạc x/q P


u
cu

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


∆u(P ) ≈ h2
Lần lượt thay Pk = (xk , yk ) vào phương trình elliptic, sử
dụng công thức xấp xỉ & điều kiên biên Hệ PTTT ẩn uk = u(Pk )

CuuDuongThanCong.com https://fb.com/tailieudientucntt
BÀI TOÁN ELLIPTIC

om
„ Example

.c
ng
co
an
th
Lưới 4 nút ẩn
o ng
đánh số 4 giá trị cần tìm. SD PTSP & Giá trị trên biên Hệ PTTT
du
u
cu

Mô phỏng Matlab

CuuDuongThanCong.com https://fb.com/tailieudientucntt
BÀI TOÁN PARABOLIC (mô hình
truyền nhiệt)

om
.c
ng
co
an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
BÀI TOÁN PARABOLIC (mô hình
truyền nhiệt)

om
.c
ng
co
an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
BÀI TOÁN PARABOLIC (mô hình
truyền nhiệt)

om
„ Phân hoạch và xấp xỉ

.c
Chia cách đều bước ∆x và ∆t

ng
Mức thứ k: t= k∆t

co
u = (. . . uki . . . )
(k)

an
th
(0)
Mức thứ 0: u đã biết
ng (1)
Mức thứ 1: u chưa biết
o
du
u
cu

Xấp xỉ đạo hàm riêng cấp 1:


∂u(x,t) TIẾN - LÙI
∂t
CuuDuongThanCong.com https://fb.com/tailieudientucntt
BÀI TOÁN PARABOLIC (mô hình
truyền nhiệt)

om
„ Ví dụ

.c
ng
co
an
th
o ng
du
u
cu

Sơ đồ hiện (s/p tiến) Sơ đồ ẩn (s/p lùi)

CuuDuongThanCong.com https://fb.com/tailieudientucntt
BÀI TOÁN PARABOLIC (mô hình
truyền nhiệt tổng quát)

om
.c
ng
co
Miền Ω = {(x, t)|0 ≤ x ≤ 1, t ≥ 0}

an
th
o ng
du
u
cu

∂u ∂u ∂ 2 u
Xấp xỉ , ,
∂t ∂x ∂x2
& ĐK biên, đầu Giá trị u tại các điểm lưới

Sai phân tiến & Sai phân lùi


CuuDuongThanCong.com https://fb.com/tailieudientucntt
BÀI TOÁN PARABOLIC (mô hình
truyền nhiệt)

om
.c
ng
co
an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
BÀI TOÁN PARABOLIC (mô hình
truyền nhiệt)

om
Kí hiệu u(k) = [uk1 . . . ukn ], f (k) = [f1k . . . fnk ]

.c
ng
co
an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
BÀI TOÁN PARABOLIC (mô hình
truyền nhiệt)

om
„ Sơ đồ Crank-Nicholson

.c
ng
co
an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Outline

om
„ General introduction

.c
‰ Structure and operation of chemical engineering

ng
systems

co
What is a chemical process?

an
‰

th
‰ Motivation examples
„ Part I: Process modeling
o ng
du

„ Part II: Computer simulation


u
cu

„ Part III: Optimization of chemical processes

CuuDuongThanCong.com https://fb.com/tailieudientucntt

You might also like