IERAIVE MEHODS Numerical methods in chemical engineering Edwin Zondervan 1
OVERVIEW Iterative methods for large systems of equations We will solve Laplace s equation for steady state heat conduction
LAPLACE S EQUAIONS t (4-1) hermal diffusivity he steady state problem: 0 (4-) y = b y 0 (4-3) = b3 = b4 = b1 3
RACK EMPERAURE ON A j =Ny (Ny-1)N+1 GRID Inde of a node is given by: K = i + N(j-1) j =3 So that: j = N+1 N+ N+3 N i,j = =i+n(j-1) j =1 1 3 N i =1 i = i =3 i =N 4
ESIMAES OF HE SECOND DIFFERENIALS FOR Assume a piece-wise linear profile in the temperature, e.g.: i+1 i 1/ i 1/ (4-4) i-1 i i i 1, j 1, j i, j i, j i i, j 1, j i 1, j (4-5) 5
INCLUDE HE ESIMAES OF HE SECOND DIFFERENIALS FOR y i 1, j i, j i 1, j i 1, j i, j y i 1, j 0 (4-6) 1 1 N y N 0 (4-7) Equal spaced grid = y =1 N 4 1 1 N 0 (4-8) 6
BOUNDARY CONDIIONS For the nodes on the boundary, we have a simple equations:,boundary some fied temperature he equation on the previous slide and the boundaries can be written as a matri equation: A b (4-10) (4-9) 7
LE S WRIE HIS SUFF AS MARIX EQUAIONS N=5; %number of points along direction Ny=5; %number of points in the y direction d = 1/N; %the grid spacing Alpha = 1; %thermal diffusivity e = ones(nny,1); A = spdiags([e,e,-4e,e,e],[-n,-1,0,1,n],nny,nny); A = Aalpha/d^; 8
MARIX SPARSIY Spy(A) N=Ny = 5 A sparse matri structure, 0 5 10 which is not tridiagonal: there are offset bands. Offset bands can cause your trouble!! 15 0 5 0 5 10 15 0 5 nz = 113 9
SOLUION O HE LAPLACE EQUAION You can solve the system with \, for N=Ny=5 and b1 = 10 b = b3 = b4 = 0 0.9 0.8 0.7 0.6 0.5 0.4 t= 3 tau 10 9 8 7 6 5 4 0.3 3 0. 0.1 1 0 0 0.1 0. 0.3 0.4 0.5 0.6 0.7 0.8 0 10
LU decomposition [L,U,P] = lu(a) subplot(1,,1) spy(l) subplot(1,,) spy(u) With LU decomposition we produce matrices that are less sparse than the original matri. 0 5 0 5 10 15 0 5 0 10 0 nz = 19 10 15 0 5 0 10 0 nz = 19 11
LU DECOMPOSIION Gaussian elimination on a matri lie A requires more memory (with 3D problems, the offset in the diagonal would even be bigger!) In general etra memory allocation will not be a problem for MALAB MALAB is clever, in that sense that it attempts to reorder equations, to move elements closer to the diagonal) 1
IERAIVE MEHODS Alternatives for Gaussian elimination Use iterative methods when systems are large and sparse. Often such systems are encountered when we want to solve PDE s of higher dimensions (>1D) 13
EXAMPLES Jacobi method Gauss-Seidel method Succesive over relaation bicg Bi-conjugate gradient method gmres generalized minimum residuals method bicgstab Bi-conjugate gradient method 14
HE JACOBI MEHOD In our previous eample we derived the following equation: N 1 4 1 N 0 (4-11) Rearranging: N 4 1 1 N (4-1) 15
HE JACOBI MEHOD In the Jacobi scheme the iteration proceeds as follows: Start with an initial guess for the values of at each node, we calculate an new, updated values using the equation of the previous slide and store a new vector:, new N, old 1, old 4 1, old N, old (4-13) Do this for all other nodes, and use new values as guess, Repeat! 16
DIAGRAM OF JACOBI MEHOD Move to net node Set old = new NO NO Set old = a gues Calculate the new node temperature from the guessed values Have all nodes been updated? YES Is ma( new - old ) < tolerance? YES Report the answer as new Only two vectors need to be stored: the old emp. And the new emp. 17
18 Numerical Methods NOW WIH MARICES A A Consider a matri A: Split it into a diagonal matri D and another matri S:
SOLVE A-b Now we can solve A=b by: (D+S). = b D. = b S. D. new = b S. old new = D -1 (b-s. old ) 19
CONVERGENCE OF HE MEHOD Now we define an error at the -th iteration: error = - he error at the net iteration is: +1 = D -1 (b-s. ) Error +1 + = D -1 (b-s.error -S.) D.error +1 =-S.error Error +1 = -D -1 S.error Eigenvalues of D -1 S must always have modulus < 1, to ensure that error +1 < error 0
CONVERGENGE OF HE MEHOD We can epress the vector of error in terms of eigenvectors of D -1 S: So: error= a 1 u 1 + a u + a 3 u 3 + a 4 u 4 + error +1 = -D -1 S(a 1 u 1 + a u + a 3 u 3 + a 4 u 4 + ) = -a 1 D -1 Su 1 -a D -1 Su -a 3 D -1 Su 3 -a 4 D - 1 Su 4 + = -a 1 u 1 -a u -a 3 u 3 -a 4 u 4 + he magnitude of the error will grow each iteration, if s have a comple module >1, So: Find the largest magnitude of eigenvalues for the matri D -1 S (4-14) (4-15) 1
GERSHGORIN S HEOREM For a square matri and row, an eigenvalue is located on the comple plane within a radius equal or less to the sum of the moduli of the off-diagonal elements of that row. m m,1 m,... m, N m, N 1 m,, N (4-16) Im( ) Radius = sum of moduli of off-diagonal elements he eigenvalue must be in this circle. m, Re( )
APPLICAION OF GERSHGORIN S HEOREM Appying Gershgorin s theorem to our Jacobi iteration, the off-diagonal elements of row of D - 1 S are 1/a. times the off-diagonal elements of our original matri A, while the diagonal element is zero: For <1: j a, j, a (4-17) Stability: size of diagonal element must be larger that the sum of moduli of the other elements, such matri is called diagonally dominant. 3
SUMMARY Partial differential equations can be written as sparse systems of linear equations Sparse systems can be handled with a direct method lie Gaussian elimination If you have systems of more than 1 dimension, a direct method still can be used, if there are no memory issues, otherwise an iterative method may be attractive. he Jacobi method was introduced. Many other methods are based on the Jacobi method (SOR method, for eample) 4