( ) Finite Differences

advertisement
10.34, Numerical Methods Applied to Chemical Engineering
Professor William H. Green
Lecture #19: Boundary Value Problems (BVPs) Lecture 2.
Finite Differences
df
dx
df
dx
≡
f ( x o + Δx ) − f ( x o − Δx )
+ O ( Δx ) 2
2Δx
≡
f ( x o + Δx ) − f ( x o )
+ O (Δx )
Δx
x0
x0
(
)
Relatively good accuracy, better convergence
ONE SIDED upwind differencing: The error leads
to numerical stability but is a mathematical trick. Adds in error Deff = Dtrue +
V
xΔx/2
and
Pelocal, eff < 2. Still wrong, because artificially increased.
V2φ + v·Vφ + S(φ) = 0
φi +1 − 2φi + φi −1
(Δx)
2
linear
+
vφi +1 − φi
+ f (φ ( x) ) = 0
Δx
linear
⎛ f (φ ( x1 ) )
⎜
M ×φ + ⎜
⎜
0
⎝
⎛ f (φ1 )
⎜
M ×φ + ⎜
⎜ 0
⎝
f (φ 2 )
linear or nonlinear
f (φ ( x 2 ) )
0⎞
⎟
⎟=0
%⎟⎠
0⎞
⎟
⎟=0
%⎟⎠
approx. to differential operators
Newton’s Method
F(φ) = 0
JΔφ = -F
⎛ ∂f
⎜
⎜ ∂φ φ1
⎜
Í Newton update J = M + ⎜
⎜
⎜ 0
⎜
⎜
⎝
∂f
∂φ
φ2
⎞
0⎟
⎟
⎟
⎟
⎟
%⎟⎟
⎟
⎠
Cite as: William Green, Jr., course materials for 10.34 Numerical Methods Applied to Chemical
Engineering, Fall 2006. MIT OpenCourseWare (http://ocw.mit.edu), Massachusetts Institute of
Technology. Downloaded on [DD Month YYYY].
Example: Rectangular Duct With Incompressible Flow
Rectangular duct with incompressible fluid being pulled by gravity:
V2vz(x,y) = ρg/μ
No slip at walls: vz(boundaries) = 0
φ ( xi , y i ) → ϕ ( n)
∂2
∂2
+
∂x 2 ∂y 2
n = (i − 1) * N y + j
⎛ v z ( x1 , y1 ) ⎞
⎟
⎜
⎜ v z ( x1 , y 2 ) ⎟
⎟
ϕ =⎜
#
⎟
⎜
⎜ v z ( x1 , y N y ) ⎟
⎜ v (x , y ) ⎟
⎝ z 2 1 ⎠
Ny
Δy
yÇ
•
↑
•
•
•
•
•
•
•
•
• ← • → •
↓
•
xÆ
Nx
Δx
4• •
3• •
2• •
1 • • Ny + 1
(1,1)
Figure 1. Rectangular duct with incompressible flow.
NxNy = # points
Interior:
v z ( xi +1 , y j ) − 2v z ( xi , y j ) + v z ( xi −1 , y j )
(Δx)
2
+
v z ( xi , y j +1 ) − 2v z ( xi , y j ) + v z ( xi , y j −1 )
(Δy ) 2
Rows of M look like this:
10.34, Numerical Methods Applied to Chemical Engineering
Prof. William Green
Lecture 19
Page 2 of 4
Cite as: William Green, Jr., course materials for 10.34 Numerical Methods Applied to Chemical
Engineering, Fall 2006. MIT OpenCourseWare (http://ocw.mit.edu), Massachusetts Institute of
Technology. Downloaded on [DD Month YYYY].
⎛
⎛ 1
1
1
1
000
− 2⎜⎜
+
M = ⎜ 0.....
2
2
2
⎜
(Δx)
( Δy )
( Δy ) 2
⎝ ( Δx )
⎝
Mφ = ρg/μ
⎞
⎞
1
1
⎟
⎟00
00
00
2
2
⎟ ( Δx )
⎟
( Δy )
⎠
⎠
{Mφ = b}
Shown in MATLAB
function makeAforLaplacian(Nx,Ny,Xmax,Ymax)
Non-sparse: A(n, n+1) = 1/(Δy)2
Sparse format:
mvec(k) = n
Ymax
Ç
ηvec(k) = n+1
A vec(k) = 1/(Δy)2
Æ Nx
MATLAB for Sparse Matrix
Nx = 20;
Ny = 30;
Xmax = 40;
Ymax = 10;
A_sparse = makeA_sparse(Nx,Ny,Xmax,Ymax);
b = zeros(Nx*Ny,1);
% unknown vector
b = b+1;
phi = A_sparse\b;
check = A_sparse*phi;
check(400)
ans = 1.0
bbig = 1e7*b
phi = A_sparse\bbig;
check = A_sparse*phi;
ans = 1e7
How do know if correct?
V_shaped = reshape(phi, Ny, Nx);
surf(V_shaped)
Makes a beautiful plot of the solution
Adding Convection
Peclet number
Pe =
vL
/D
Pelocal =
vxΔx
/D
10.34, Numerical Methods Applied to Chemical Engineering
Prof. William Green
Lecture 19
Page 3 of 4
Cite as: William Green, Jr., course materials for 10.34 Numerical Methods Applied to Chemical
Engineering, Fall 2006. MIT OpenCourseWare (http://ocw.mit.edu), Massachusetts Institute of
Technology. Downloaded on [DD Month YYYY].
V(vφ) + DV2φ + S(φ) = 0
∂v x
∂ϕ
∂ 2ϕ
+ D 2 + S (ϕ ) = 0
ϕ + vx
∂x
∂x
∂x
ϕ'
⎞
∂ ⎛ ϕ ⎞ ⎛⎜
⎜⎜ ⎟⎟ = − v x
S⎟
1 ∂v x
ϕ '−
ϕ− ⎟
∂x ⎝ ϕ ' ⎠ ⎜
D ∂x
D⎠
⎝ D
∂ϕ
∂x
Recall from ODE discussion:
∂ϕ
= −λϕ
∂t
Δt <
2
numerical stability of explicit solvers
λ
v
∂ (ϕ ' )
= − x ϕ '+ stuff
D
∂x
vx
=λ
D
Δx <
2
λ
⇒ Δx <
2
vx
D
Pe local < 2
Achieve Pelocal < 2 by making Δx smaller. This leads to stiffness. Difficulties when implicit
solving. Use adaptive meshing with Gear predictor-corrector.
Deff = Dtrue +
v x Δx
2
∂f
∂x
=
xD
f ( x0 + Δx) − f ( x0 )
+ O(Δx)
Δx
Pe local < 2
Method of lines for flow only in x-direction
∂ϕ
+ D∇ 2ϕ + .....
∂x
⎛ ϕ ( x, y + Δy, z ) − 2ϕ ( x, y, z ) + ϕ ( x, y − Δy, z ) ⎞
∂ϕ
∂ 2ϕ
⎟⎟ + .....
vx
+ D 2 + D⎜⎜
∂x
∂x
(Δy ) 2
⎝
⎠
vx
PDE Æ ODE {works only if: vy, vz ~ negligible; Pelocal< 2}
Equations like this for all discrete z and y values in mesh.
10.34, Numerical Methods Applied to Chemical Engineering
Prof. William Green
Lecture 19
Page 4 of 4
Cite as: William Green, Jr., course materials for 10.34 Numerical Methods Applied to Chemical
Engineering, Fall 2006. MIT OpenCourseWare (http://ocw.mit.edu), Massachusetts Institute of
Technology. Downloaded on [DD Month YYYY].
Download