10.34, Numerical Methods Applied to Chemical Engineering Professor William H. Green Lecture #20: Boundary Value Problems Lecture 3. Finite Differences, Method of Lines, and Finite Elements. Finite Differences mesh finite difference for D̂ Dˆ ϕ + S (ϕ ) = 0 ⎯⎯ ⎯⎯→ A ⋅ φ + S = 0 Fi(φ) = (ΣAijφj) + S(φi) = 0 Jin = ∂Fi ∂φ n i = 1, Nmesh*Nscalar fields Solve F(φ) = 0 by Newton-type methods ⎛% ⎜ ⎜% ⎜ ⎜ ⎜ ⎜ Need Jacobian J: Jin = Ain +δinS’(φi). J = ⎜ ⎜ ⎜ ⎜% ⎜ ⎜⎜ ⎝0 % % % % % % % % % % % % % % 0 % % % % % 0 % % % % % % 0⎞ ⎟ ⎟ %⎟ ⎟ ⎟ ⎟ + ⎛⎜% 0 ⎞⎟ ⎟ ⎜ 0 %⎟ ⎠ ⎟ ⎝ ⎟ ⎟ %⎟ ⎟ %⎟⎠ Iterative, need good initial guess φguess! (normally, JΔφ = -F ) Method of Lines e.g. 2D, vy = 0, vx independent of φ: v x ( x, y ) ∂ϕ ∂x +ϕ x , yi convection ∂v x ∂x x , yi ⎛ ∂ 2ϕ ∂ 2ϕ ⎞ ∂ ∂ + D⎜⎜ 2 + 2 ⎟⎟ + S (ϕ ( x, y ) ) = 0 ∇ ⋅ (ϕ v) = (ϕv x ) + (ϕv y ) ∂x ∂y ∂y ⎠ ⎝ ∂x diffusion coefficient D replace 0 if vy = 0 ϕ ( x, y i +1 ) − 2ϕ ( x, y i ) + ϕ ( x, yi −1 ) (Δy ) 2 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]. ui(x) = φ(x,yi) w(x) = ∂φ ⎛ u1 ⎜ ⎜ w1 ⎜u ⎜ 2 ⎜ w2 ⎜ d ⎜ # dx ⎜ u i ⎜ ⎜ wi ⎜ # ⎜ ⎜uNy ⎜w ⎝ xy ⎞ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎛ ⎟ = ⎜ v x ( x, y i ) 1 ∂v x wi − ⎟ ⎜− ⎜ D D ∂x ⎟ ⎝ ⎟ ⎟ ⎟ ⎟ ⎟ ⎠ wi ⎞ ⎟ u i +1 ui u i −1 S (u i ) ⎟ −2 − − ui − D ⎟⎠ ( Δy ) 2 (Δy ) 2 (Δy ) 2 x , yi /∂x|(x,yi) A mess, but we can solve stiff ODEs better than PDEs. Variables: 2Nmesh. Coarse discretization easy; finer mesh makes complexity rise. Better for steep front. Diffusion/conduction dominated – Elliptic PDEs • microfluidics, cells, reaction no convection • no sharp fronts Finite Differences, Method of Lines every φ(xi, yj) depends on all the others Convection-dominated, wave equations – Hyperbolic PDEs • information flows in a direction, shockwaves, flames Stiff ODEs solve with • sharp fronts Å-----Æ numerical instabilities, oscillations adaptive mesh Finite Element Method (FEM) Î FEMLAB Galerkin’s Method φ = ∑ cn χ n (x ) want to retain sparsity local basis functions χ n (x − x n ) points connected only to neighbors. Used in fluid mechanics and quantum mechanics (must consider electrostatic attraction). 1D example 10.34, Numerical Methods Applied to Chemical Engineering Prof. William Green Lecture 20 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]. ⎧ ⎪ χ n = ⎨1 − ⎪⎩ | x − xn | Δx 0 if x n -1 < x < x n+1 Add lots of xn close to steep gradient otherwise Singularities but can integrate by parts. Figure 1. Add points close to steep gradient. Separate into parts at singularity. ∫ dx χ n ( x)(Dˆ ϕ ( x) + S (ϕ )) = 0 ∫ χ n ∇ ϕ = − ∫ ∇χ n ⋅∇ϕ − ∫ ∇ ⋅(χ n ∇ϕ ) 2 0 n = 1, N mesh Local integral: 0 except in range xn-1< x < xn+1. f n (φ n −1 , φ n , φ n +1 ) = 0 F (φ ) = 0 Nonzero close to mesh point. Method good when there are only short range forces. This equation is difficult to write. Usually use software that is already written: e. g. MATLAB PDE Tool Box or FEMLab ⎛% % 0 ⎞ ⎟ ⎜ J = ⎜% % %⎟ { easy to solve this Jacobian for finite differences, sparse matrix ⎜ 0 % %⎟ ⎠ ⎝ Discussion V2φ cylindrical: 3D 1 ∂ ⎛ ∂ϕ ⎞ ⎜r ⎟ r ∂r ⎝ ∂r ⎠ Nmesh ~ 106 J ~ 106 x 106 = 1012 (computer cannot store this) Conjugate gradient-type solvers for JΔφ = -F (N steps: still 106) MatLAB solver: GMRes Works even if matrix is not positive definite f(Δφ) = ||JΔφ + F||2 (minimize this within N steps) Preconditioning Text has a number of tricks for good preconditioning (i.e. Jacobi method see textbook) Initial guess of φ is important for convergence 10.34, Numerical Methods Applied to Chemical Engineering Prof. William Green Lecture 20 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]. Finite Volumes ∂ϕ = Dˆ ϕ + S (ϕ ) ∂t Instead of mesh points, we use mesh volumes. Operator splitting Method transport ~ → t + Δt/2 ϕ ( xi , y i ,.t ) ⎯t⎯ ⎯⎯→ ϕ new ( xi , y i ,.t ) d ϕ i = s (ϕ i ) using Nmesh ODE solver: φ(t0) = φnew dt Δt transport, ( Δt / 2 ) ϕ new ⎯chemistry, ⎯ ⎯ ⎯⎯ → ϕ i (t f ) ⎯⎯ ⎯ ⎯ ⎯⎯→ ϕ ( xi , yi , t + Δt ) splitting error ~(Δt)2 Δt< Δx/vx to prevent numerical instability Model system must have no mixing. Nspecies compare to NspeciesNmesh for Method of Lines 10.34, Numerical Methods Applied to Chemical Engineering Prof. William Green Lecture 20 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].