Solution Strategies ODEs and PDEs
ODEs: Initial-Value Problems Solution Strategies ODEs: Initial-Value Problems
Differential Equations There are ordinary differential equations - functions of one variable And there are partial differential equations - functions of multiple variables
Order of differential equations 1st order (falling parachutist) 2nd order (mass-spring system with damping) etc.
Higher-Order ODE’s Can always turn a higher order ODE into a set of 1st order ODEs Example: Let then So solutions to first-order ODEs are important
Linear and Nonlinear ODEs Linear: No multiplicative mixing of variables, no nonlinear functions Nonlinear: anything else
Example: Swinging Pendulum nonlinear
Equation Linearization Sometimes, the nonlinear ODE can be linearized Example: for small angles Nonlinear linear
Ordinary Differential Equations ODEs show up everywhere in engineering Dynamics (Newton’s 2nd law) Heat conduction (Fourier’s law) Diffusion (Fick’s law)
Ordinary Differential Equations Given the rate of change (derivative) of y w.r.t. x at every point
New value = old value + slope*step size Runge-Kutta Methods Runge Kutta methods - one step methods Idea is that New value = old value + slope*step size Slope is generally a function of t, hence y(t) Different methods differ in how to estimate
One-Step Method All one-step methods can be expressed in this general form, the only difference being the manner in which the slope is estimated
Ordinary Differential Equations Ordinary differential equations (ODEs) Initial value problems Numerical approximations New value = old value + slope × step size
The solution of ODE depends on the initial condition Initial Conditions The solution of ODE depends on the initial condition Same ODE, but with different initial conditions t
Euler’s method (First-order Taylor Series Method) Approximate the derivative by finite difference Local truncation error or
Euler’s Method Euler’s (Euler-Cauchy or point-slope) method Use the slope at ti to predict yi+1
Euler’s method Straight line approximation y0 t0 h t1 h t2 h t3
Example: Euler’s Method Analytic solution Euler method h = 0.50
Example: Euler’s Method
Euler’s method: y h = 0.25 1 h = 0.5 t 0.25 0.5 0.75 1.0
Euler’s Method (modified M-file)
Euler’s Method >> tt=0:0.01*pi:pi; >> ye=1.5*exp(-tt)+0.5*sin(tt)-0.5*cos(tt); >> [t,y]=Eulode('example2_f',[0 pi],1,0.1*pi); step t y 1 0.0000000000 1.0000000000 2 0.3141592654 0.6858407346 3 0.6283185307 0.5674580652 4 0.9424777961 0.5738440394 5 1.2566370614 0.6477258022 6 1.5707963268 0.7430199565 7 1.8849555922 0.8237526182 8 2.1991148575 0.8637463173 9 2.5132741229 0.8465525934 10 2.8274333882 0.7652584356 11 3.1415926536 0.6219259596 >> H=plot(t,y,'r-o',tt,ye); >> set(H,'LineWidth',3,'MarkerSize',12) >> print -djpeg ode01.jpg
Euler’s Method (h = 0.1)
Euler’s Method (h = 0.05)
Truncation Errors There are Local truncation errors - error from application at a single step Propagated truncation errors - previous errors carried forward The sum is “global truncation error”
Euler’s Method Euler’s method uses Taylor series with only first order terms The true local truncation error is Approximate local truncation error - neglect higher order terms (for sufficiently small h)
Runge-Kutta Methods Higher-order Taylor series methods (see Chapra and Canale, 2002) -- need to compute the derivatives of f(t,y) Runge-Kutta Methods -- estimate the slope without evaluating the exact derivatives Heun’s method Midpoint (or improved polygon) method Third-order Runge-Kutta methods Fourth-order Runge-Kutta methods
Heun’s Method Improvements of Euler’s method - Heun’s method Euler’s method - derivative at the beginning of interval is applied to the entire interval Heun’s method uses average derivative for the entire interval A second-order Runge-Kutta Method
Heun’s Method Heun’s method is a predictor-corrector method Predictor Corrector (may be applied iteratively)
Heun’s Method Iterate the corrector of Heun’s method to obtain an improved estimate Predictor Corrector
Heun’s Method with Iterative Correctors
Heun’s Method with Iterative Correctors » te=0:0.02*pi:pi; ye=example2_e(xe); » [t1,y1]=Euler('example2_f',[0 pi],1,0.1*pi); » [t2,y2]=Heun_iter('example2_f',[0 pi],1,0.1*pi,0); » [t3,y3]=Heun_iter('example2_f',[0 pi],1,0.1*pi,5); » H=plot(te,ye,t1,y1,'r-d',t2,y2,'g-s',t3,y3,'m-o'); » set(H,'LineWidth',3,'MarkerSize',12) » [te' ye' y1',y2',y3'] t yEuler yHeun yHeun_iter ytrue 0 1.0000 1.0000 1.0000 1.0000 0.3142 0.6858 0.7837 0.7704 0.7746 0.6283 0.5675 0.7018 0.6830 0.6896 0.9425 0.5738 0.7064 0.6872 0.6951 1.2566 0.6477 0.7559 0.7395 0.7479 1.5708 0.7430 0.8152 0.8036 0.8118 1.8850 0.8238 0.8565 0.8503 0.8578 2.1991 0.8637 0.8592 0.8584 0.8648 2.5133 0.8466 0.8112 0.8149 0.8199 2.8274 0.7653 0.7082 0.7154 0.7188 3.1416 0.6219 0.5540 0.5631 0.5648
Heun’s Method with Iterative Correctors Heun’s with 5 iterations Exact Euler’s t
Example: Heun’s Method First Step
Example: Heun’s Method Second Step
Example: » [t1,y1]=Eulode('example3',[0 5],1,0.5); » [t2,y2]=Heun_iter('example3',[0,5],1,0.5,0); » [t3,y3]=Heun_iter('example3',[0 5],1,0.5,5); » [t1' y1' y2' y3' ye'] t yEuler yHeun yHeun_iter ytrue 0 1.0000 1.0000 1.0000 1.0000 0.5000 1.0000 1.1250 1.1331 1.1289 1.0000 1.2500 1.5523 1.5804 1.5625 1.5000 1.8090 2.4169 2.4859 2.4414 2.0000 2.8178 3.9463 4.0882 4.0000 2.5000 4.4964 6.4619 6.7192 6.5664 3.0000 7.1470 10.3793 10.8046 10.5625 3.5000 11.1570 16.2082 16.8630 16.5039 4.0000 17.0024 24.5532 25.5065 25.0000 4.5000 25.2492 36.1126 37.4407 36.7539 5.0000 36.5552 51.6796 53.4643 52.5625
Midpoint Method Improved Polygon or Modified Euler Method Use the slope at midpoint to represent the average slope
Runge-Kutta (RK) Methods One-Step Method with general form Where is an increment function which represents the weighted-average slope over the interval Where a’s are constants and k’s are slopes evaluated at selected x locations
Runge-Kutta (RK) Methods One-Step Method General Form of nth-order Runge-Kutta Method Where p’s and q’s are constants k’s are recurrence relationships
Second-Order RK Methods Taylor series expansion Compare to the second-order Taylor formula Three equations for four unknowns (a1, a2, k1, q11)
Second-Order RK Methods Second-order version of Runge-Kutta Methods 3 equations for 4 unknowns
Second-Order RK Methods General Second-order Runge-Kutta methods k2 a1 k1 + a2 k2 k1 Weighted-average slope xi+1 = xi+h xi xi+p1h
Use average slope over the interval Heun’s Method Heun’s method with a single corrector (a2 = 1/2): Choose a2 = 1/2 and solve for the other 3 constants a1 = 1/2, p1 = 1, q11 = 1 Use average slope over the interval
Midpoint Method k2 k1 xi xi+1/2 xi+1 Another Second-order Runge-Kutta method Choose a2 = 1 a1 = 0, p1 = 1/2, q11 = 1/2 k2 k1 xi xi+1/2 xi+1
Midpoint (2nd-order RK) Method
Midpoint (2nd-order RK) Method >> [t,y] = midpoint('example2_f',[0 pi],1,0.05*pi); step t y 1 0.0000000000 1.0000000000 2 0.1570796327 0.8675816988 3 0.3141592654 0.7767452235 4 0.4712388980 0.7206165079 5 0.6283185307 0.6927855807 6 0.7853981634 0.6872735266 7 0.9424777961 0.6985164603 8 1.0995574288 0.7213629094 9 1.2566370614 0.7510812520 10 1.4137166941 0.7833740988 11 1.5707963268 0.8143967658 12 1.7278759595 0.8407772414 13 1.8849555922 0.8596353281 14 2.0420352248 0.8685989204 15 2.1991148575 0.8658156821 16 2.3561944902 0.8499586883 17 2.5132741229 0.8202249154 18 2.6703537556 0.7763257790 19 2.8274333882 0.7184692359 20 2.9845130209 0.6473332788 21 3.1415926536 0.5640309524 >> tt = 0:0.01*pi:pi; yy = example2_e(tt); >> H = plot(t,y,'r-o',tt,yy); >> set(H,'LineWidth',3,'MarkerSize',12);
Midpoint (RK2) Method
Ralston’s Method Second-order Runge-Kutta method Choose a2 = 2/3 a1 = 1/3, p1 = q11 = 3/4 k2 k1 k1/3 + 2k2/3 ti xi+1 = ti+h ti+3h/4
Third-Order Runge-Kutta Method General form Weighted slope
Third-Order Runge-Kutta Methods General Third-order Runge-Kutta methods k3 k2 Weighted-average value of three slopes k1 , k2 , k3 k1 ti ti+p1h ti+p2h ti+1 = ti+h
Third-order Runge-Kutta Methods Nystrom Method Nearly Optimum Method
Classical Third-order Runge-Kutta Method Reduce to Simpson’s 1/3 rule for f = f(t)
3rd-Order Heun Method
Classical 4th-order Runge-Kutta Method One-step method Reduce to Simpson’s 1/3 rule for f = f(t)
Classical 4th-order Runge-Kutta Method ti ti + h/2 ti + h
Example: Classical 4th-order RK Method First step, t = 0.5
Example: Classical 4th-order RK Method Second step, t = 1.0
Fourth-Order Runge-Kutta Method
Fourth-Order Runge-Kutta Method >> tt=0:0.01*pi:pi; yy=example2_e(tt); >> [t,y]=RK4('example2_f',[0 pi],1,0.05*pi); step t y 1 0.0000000000 1.0000000000 2 0.1570796327 0.8663284784 3 0.3141592654 0.7745866433 4 0.4712388980 0.7178375776 5 0.6283185307 0.6896194725 6 0.7853981634 0.6839104249 7 0.9424777961 0.6951106492 8 1.0995574288 0.7180384347 9 1.2566370614 0.7479364401 10 1.4137166941 0.7804851708 11 1.5707963268 0.8118207434 12 1.7278759595 0.8385543106 13 1.8849555922 0.8577907953 14 2.0420352248 0.8671448731 15 2.1991148575 0.8647524420 16 2.3561944902 0.8492761286 17 2.5132741229 0.8199036965 18 2.6703537556 0.7763385417 19 2.8274333882 0.7187817811 20 2.9845130209 0.6479057500 21 3.1415926536 0.5648190301 >> H=plot(x,y,'r-o',xx,yy); >> set(H,'LineWidth',3,'MarkerSize',12);
Fourth-Order Runge-Kutta Method
Numerical Accuracy h = 0.1 h = 0.05 » tt=0:0.01*pi:pi; yy=example2_e(tt); » t0=0; y0=example2_e(t0); » t1=0.1*pi; y1=example2_e(t1); » [t,ya]=Eulode('example2_f',[0 pi],y0,0.1*pi); » [t,yb]=midpoint('example2_f',[0 pi],y0,y1,0.1*pi); » [t,yc]=Heun_iter('example2_f',[0 pi],y0,0.1*pi,5); » [t,yd]=RK4('example2_f',[0 pi],y0,0.1*pi); » H=plot(t,ya,'m-*',t,yb,'c-d',t,yc,'g-s',t,yd,'r-O',tt,yy); » set(H,'LineWidth',3,'MarkerSize',12); » » [t,ya]=Eulode('example2_f',[0 pi],y0,0.05*pi); » [t,yb]=midpoint('example2_f',[0 pi],y0,y1,0.05*pi); » [t,yc]=Heun_iter('example2_f',[0 pi],y0,0.05*pi,5); » [t,yd]=RK4('example2_f',[0 pi],y0,0.05*pi); » print -djpeg075 ode06.jpg h = 0.1 h = 0.05
Numerical Accuracy Euler Midpoint Heun (iterative) RK4 h = 0.1
Numerical Accuracy Euler Midpoint Heun (iterative) RK4 h = 0.05
Butcher’s sixth-order Runge-Kutta Method
System of ODEs A system of simultaneous ODEs n equations with n initial conditions
System of ODEs Bungee Jumper’s velocity and position Two simultaneous ODEs
Nonlinear Pendulum R Second-order ODE W=mg
Second-Order ODE Convert to two first-order ODEs
System of Two first-order ODEs Euler’s Method Any method considered earlier can be used Euler’s method for two ODE-IVPs Basic Euler method Two ODE-IVPs
Hand Calculations: Euler’s Method Solve the following ODE from t = 0 to t = 1 with h = 0.5 Euler method
Euler’s Method for a System of ODEs y is a column vector with n variables
Euler Method for a System of ODEs function f = example5(t,y) % dy1/dt = f1 = -0.5 y1 % dy2/dt = f2 = 4 - 0.1*y1 - 0.3*y2 % let y(1) = y1, y(2) = y2 % tspan = [0 1] % initial conditions y0 = [4, 6] f1 = -0.5*y(1); f2 = 4 - 0.1*y(1) - 0.3*y(2); f = [f1, f2]'; >> [t,y]=Euler_sys('example5',[0 1],[4 6],0.5); t y1 y2 y3 ... 0.000 4.0000000000 6.0000000000 0.500 3.0000000000 6.9000000000 1.000 2.2500000000 7.7150000000 >> [t,y]=Euler_sys('example5',[0 1],[4 6],0.2); 0.200 3.6000000000 6.3600000000 0.400 3.2400000000 6.7064000000 0.600 2.9160000000 7.0392160000 0.800 2.6244000000 7.3585430400 1.000 2.3619600000 7.6645424576 (h = 0.5) (h = 0.2)
Euler Method for Second-Order ODE Nonlinear Pendulum function f = pendulum(t,y) % nonlinear pendulum d^2y/dt^2 + 0.3dy/dt = -sin(y) % convert to two first-order ODEs % dy1/dt = f1 = y2 % dy2/dt = f2 = -0.1*y2 - sin(y1) % let y(1) = y1, y(2) = y2 % tspan = [0 15] % initial conditions y0 = [pi/2, 0] f1 = y(2); f2 = -0.3*y(2) - sin(y(1)); f = [f1, f2]';
Euler’s Method for Second-Order ODE Nonlinear Pendulum » [t,y1]=Euler_sys('pendulum',[0 15],[pi/2 0],15/100); » [t,y2]=Euler_sys('pendulum',[0 15],[pi/2 0],15/200); » [t,y3]=Euler_sys('pendulum',[0 15],[pi/2 0],15/500); » [t,y4]=Euler_sys('pendulum',[0 15],[pi/2 0],15/1000); » H=plot(t1,y1(:,1),t2,y2(:,1),t3,y3(:,1),t4,y4(:,1)) n = 100 n = 200 n = 500 n = 1000
Euler’s Method for Two ODEs Nonlinear Pendulum » [t4,y4]=Euler_sys('pendulum',[0 15],[pi/2 0],15/1000); » H=plot(t4,y4(:,1),t4,y4(:,2),'r'); y1 = 2 equations y2 = n = 1000
Higher Order ODEs In general, nth-order ODE
System of First-Order ODE-IVPs Example Convert to three first-order ODE-IVPs
Euler’s Method for Systems of First-Order ODEs Example
Example: Euler’s Method First step: t(0) = 0, t(1) = 0.5 (h = 0.5) Second step: t(1) = 0.5, t(2) = 1.0
Classical 4th-order Runge-Kutta Method for Systems of ODE-IVPs 2 equations Applicable for any number of equations
Hand Calculations: RK4 Method Solve the following ODE from t = 0 to t = 1 with h = 0.5 Classical RK4 method
Continued: RK4 Method
4th-order Runge-Kutta Method for ODEs Valid for any number of coupled ODEs
4th-order Runge-Kutta Method for ODEs >> [t,y]=RK4_sys('example5',[0 10],[4 6],0.5); t y1 y2 y3 ... 0.000 4.0000000000 6.0000000000 0.500 3.1152343750 6.8576703125 1.000 2.4261713028 7.6321056734 1.500 1.8895230605 8.3268859767 2.000 1.4715767976 8.9468651000 2.500 1.1460766564 9.4976013588 3.000 0.8925743491 9.9849540205 3.500 0.6951445736 10.4148035640 4.000 0.5413845678 10.7928635095 4.500 0.4216349539 11.1245594257 5.000 0.3283729256 11.4149566980 5.500 0.2557396564 11.6687232060 6.000 0.1991722422 11.8901165525 6.500 0.1551170538 12.0829881442 7.000 0.1208064946 12.2507984405 7.500 0.0940851361 12.3966392221 8.000 0.0732743126 12.5232598757 8.500 0.0570666643 12.6330955637 9.000 0.0444440086 12.7282957874 9.500 0.0346133758 12.8107523359 10.000 0.0269571946 12.8821259602
4th-order Runge-Kutta Method for ODE-IVPs Nonlinear Pendulum » tspan=[0 15]; y0=[pi/2 0]; » [t1,y1]=RK4_sys(‘pendulum',tspan,y0,15/25); » [t2,y2]=RK2_sys(‘pendulum',tspan,y0,15/50); » [t3,y3]=RK2_sys(‘pendulum',tspan,y0,15/100); » H=plot(t1,y1(:,1),t2,y2(:,1),t3,y3(:,1)); » set(H,'LineWidth',3.0); n = 25 n = 50 n = 100
Comparison of Numerical Accuracy Nonlinear Pendulum » tspan=[0 15]; y0=[pi/2 0]; » [t1,y1]=Euler_sys(‘pendulum',tspan,y0,15/100); » [t2,y2]=RK2_sys(‘pendulum',tspan,y0,15/100); » [t3,y3]=RK4_sys(‘pendulum',tspan,y0,15/100); » H1=plot(t1,y1(:,1),t2,y2(:,1),t3,y3(:,1)); hold on; » H2=plot(t1,y1(:,2),'b:',t2,y2(:,2),'g:',t3,y3(:,2),'r:'); Euler RK2 RK4
Example: More than 2 ODE-IVPs function f = example(t, y) % solve y' = Ay = f, y0 = [1 0 0 0]' % four first-order ODE-IVPs A = [ -36 30 -20 10 -61 50 -36 18 -34 29 -25 13 -10 10 -10 6]; y=[ y(1) y(2) y(3) y(4)]'; f = A*y;
4th-order Runge-Kutta Method for ODE-IVPs Symbols: n = 20 Lines : n =100 » tspan=[0 2]; y0=[1 0 0 0]; » [t1,y1]=RK4_sys(‘example', tspan, y0, 2/20); » [t2,y2]=RK4_sys(‘example', tspan, y0, 2/100); » H1=plot(t1,y1,'o'); set(H1,'LineWidth',3','MarkerSize',12); » hold on; H2=plot(t2,y2); set(H2,'LineWidth',3);
ODEs: Adaptive Methods and Stiff Systems Solution Strategies ODEs: Adaptive Methods and Stiff Systems
Adaptive Runge Kutta Method Use small step size in high gradient region (abrupt change) automatic step size adjustment
Adaptive Runge Kutta Method First approach: Step halving Estimate local truncation error using two different step sizes Solve each step twice, once as a full step and then as two half steps Second approach: Embedded RK methods (also called RK-Fehlberg methods) Estimate local truncation error between two predictions using different-order RK methods
Step Halving Method Step Halving (Adaptive RK) method Compute the solutions at each step twice Once as a full step h and independently as two half steps (h/2) y1 – one full step; y2 – two half steps Error estimate Correction – 5th-order
Adaptive 4th-order RK Method One full-step with h Two half-steps with h/2 Therefore, Two half-steps
Embedded Runge-Kutta Method MATLAB function: ODE23 BS23 algorithm (Bogacki and Shampine, 1989; Shampine, 1994) Use second- and third-order RK methods simultaneously to solve the ODE and estimate the error for step-size adjustment Error estimate (Note: k1 is the same as k4 from previous step)
Embedded RK Method: ODE23 Uses only three function evaluations (k1, k2, k3) After each step, the error is checked to determine whether it is within desired tolerance. If it is, yi+1 is accepted and k4 becomes k1 for the next time step If the error is too large, the step is repeated with a reduced step sizes until the estimate error is acceptable RelTol: relative tolerance (default = 103) AbsTol: relative tolerance (default = 106)
Adaptive RK Method – ode23 Example 19.2: Use ode23 to solve the following ODE from t = 0 to 4: function ex19_2(t, y) % Example 19.2 in textbook yp = 10*exp(-(t-2)*(t-2)/(2*0.075^2)) - 0.6*y;
(a) RelTol = 103 (b) RelTol = 104 Example 19.2: ode23 >> options = odeset('RelTol',1.e-3); >> ode23('ex19_2', [0 4], 0.5, options); >> options = odeset('RelTol',1.e-4); >> ode23('ex19_2', [0 4], 0.5, options); (a) RelTol = 103 (b) RelTol = 104
Other MATLAB Functions MATLAB Function: ode45 Dormand and Prince (1990) Solve fourth- and fifth-order RK formulas simultaneously Make error estimates for step-size adjustment MATLAB Function: ode113 Adams-Bashforth-Moulton solver (order 1-12) Predictor-corrector method
Runge-Kutta Fehlberg Method Fourth-order Fifth-order These coefficients were developed by Cash and Karp (1990). Also called Cash-Karp RK Method
Runge-Kutta Fehlberg Method Identical coefficients (k1, k2, k3, k4, k5, k6) for both the fourth and fifth order Runge-Kutta-Fehlberg methods Save CPU time Error estimate – use two RK methods of different order to estimate the local truncation error
Runge-Kutta Fehlberg Method First, calculate yi+1 using 4th-order Runge-Kutta Felberg method (y1)4th Then, calculate yi+1 using 5th-order Runge-Kutta Felberg method (y2)5th Calculate Error Ea = (y2)5th - (y1)4th Adjust step size according to error estimate
Step Size Control Use step-halving or Runge-Kutta Fehlberg to estimate the local truncation error Adjust the step size according to error estimate Increase the step size if the error is too small and decrease it if the error is too large For fourth-order schemes
Step Size Adjustment For step size increases (RK4, n = 4) For nth-order RK Method For step size increases (RK4, n = 4) For step size decreases, h is implicit in new Reduce hnew also reduce new
Example Forcing function Runge-Kutta-Fehlberg method with adaptive step size control t small step size around t = 2 solution t
Predator-Prey Equation A simple predator-prey relationship is described by the Lotka-Volterra model, which we write in terms of a fox population f(t), with birth rate bf and death rate df and a geese population g(t) with birth rate bg and death rate dg
Predator-Prey Equation Example: Given bf = 0.3, df = 0.8, bg = 1.2, dg = 0.6, find the populations of predators and preys as a function of time (t = 0 to 20) using ode45. Predator Prey function yp = predprey(t,y) % Fox (Predator) population y1(t), birth rate bf, death rate df % Geese (prey) poupulation y2(t), birth rate bg, death rate dg bf = 0.3; df = 0.8; bg = 1.2; dg = 0.6; yp = [y(1)*(bf*y(2)-df); y(2)*(bg-dg*y(1))];
Adaptive RK method : ode45 >> tspan=[0 20]; y0 = [1, 2]; >> [t,y] = ode45('predprey',tspan,y0); >> out = [t y] out = 0 1.00000000000000 2.00000000000000 0.08372954771699 0.98466335925883 2.10387606351447 0.16745909543397 0.97217906418030 2.21469691968449 0.25118864315096 0.96261463455261 2.33264806768044 0.33491819086794 0.95606000043195 2.45787517860514 0.62870201024789 0.95940830414765 2.95257534365817 0.92248582962784 1.00915715534212 3.53554512325941 1.21626964900779 1.11944001342999 4.17743733245175 1.51005346838774 1.31420023093313 4.80288705430266 1.70029730481714 1.49877617603179 5.14418160032910 1.89054114124654 1.73932623590652 5.37426899115905 2.08078497767594 2.03724630610217 5.44284022577897 2.27102881410534 2.38123550265509 5.31619117469119 2.46127265053474 2.74867929767025 4.98122010458805 2.65151648696414 3.09373931102751 4.48531246964154 2.84176032339354 3.37201992118282 3.89965751560944 3.03200415982294 3.55414367377695 3.29772307544844 3.21873982743099 3.62508046596480 2.75627545562992 3.40547549503903 3.59592495497541 2.29786856084044 3.59221116264708 3.48499741488926 1.93369109247072 3.77894683025512 3.31638942318525 1.65488750920928 3.94714350340851 3.13529220765148 1.46223282653043 4.11534017656189 2.93901369774356 1.31685686503153 4.28353684971528 2.73779832900552 1.20974621108398 4.45173352286867 2.53877488937042 1.13408335792525 4.65875081398499 2.30372716989349 1.07647855767312 4.86576810510130 2.08503830477357 1.05104469525303 5.07278539621762 1.88590370110986 1.05298367705029 ... ... ... 19.13258672508553 1.39621015109817 1.21506308763510 19.36078504002272 1.26894875046392 1.33168491347240 19.58898335495991 1.16392668931057 1.48284270918163 19.69173751621993 1.12358612912238 1.56325743063018 19.79449167747995 1.08747228241032 1.65192298666833 19.89724583873998 1.05554028549720 1.74928308667197 20.00000000000000 1.02776980338246 1.85579178601841
Predator-Prey Model Time history of predator (fox) and prey (geese) populations
Predator-Prey Model State-space plot
Multistep Methods Runge-Kutta methods Multistep methods -- one-step method -- use intermediate values between ti and ti+1 -- several evaluations of slope per step Multistep methods -- use values at ti , ti-1 , ti-2 etc -- only one evaluation of derivative per step
Multistep Methods Comparison of one-step and multistep methods One-step method Weighted-average slope Multistep method xi-2 xi-1 xi xi+1
One-Step and Multistep Methods One-step Multistep
Heun’s Method Start with second-order method Look at Heun’s method (Self-Starting) Euler predictor - O(h2) Trapezoid corrector - O(h3)
Non-Self-Starting Heun’s Method To improve predictor, use 3rd-order Euler method along with the same old corrector iterated until converged Note: are the final results of the corrector iterations at the previous time step
Non-Self Starting Heun’s Method (a) 3rd-order predictor (b) 3rd-order corrector Non-self starting, need yi-1 and yi (two initial values)
Heun’s Method (a) 2nd-order predictor (b) 3rd-order corrector Self-starting, need yi only
Truncation Errors Non-self-starting Heun method Predictor truncation error Corrector truncation error
Modifiers Corrector Modifier Predictor Modifier (not used in textbook) Error in textbook
Non-Self Starting Heun’s Method So the sequence is Predict Adjust prediction Correct Converged? If not, correct again
Hand Calculations Exact solution: y = 12 e – 0.5t – 2 e – t Non-self-starting Heun’s method Need two initial conditions Example: Exact solution: y = 12 e – 0.5t – 2 e – t
Hand Calculations – First Step Predictor: Corrector: First Step (i = 0) : need two initial conditions Predictor:
Hand Calculations – First Step Corrector:
Hand Calculations – Second Step Second Step (i = 1) : Predictor: Predictor Modifier:
Hand Calculations – Second Step Corrector: Corrector Modifier:
Stiffness A stiff system involves rapidly changing components (usually die away quickly) together with slowly ones Long-time solution is dominated by slow varying components
Numerical Stability Amplification or decay of numerical errors A numerical method is stable if error incurred at one stage of the process does not tend to magnify at later stages Ill-conditioned differential equation -- numerical errors will be magnified regardless of numerical method Stiff differential equation -- require extremely small step size to achieve accurate results
Stability Example problem
Euler Explicit Method Stability criterion Region of absolute stability Amplification factor
Unconditionally stable ! Euler Implicit Method Unconditionally stable !
Unconditionally stable Stability Explicit Euler method Second-order Adams-Bashforth Second-order Adams-Moulton If a = 1000, then h 0.002 to ensure stability Unconditionally stable
Example Euler Explicit Euler Implicit
MATLAB Functions for Stiff Systems ode15s – based on Gear backward differentiation for stiff problems of low to medium accuracy ode23s – based on modified Rosenbrock formula ode23t – trapezoidal rule with a free interpolant for moderately stiff problems without numerical damping ode23tb – implicit Runge-Kutta formula
Stiff ODE – van del Pol equation Van der Pol equation for electronic circuit Convert to two first-order ODEs
Stiff ODE – van del Pol equation M-file for van del Pol equation function yp = vanderpol(t,y,mu) % van der Pol equation for electronic circuit % d^2y1/dt^2 - mu*(1-y1^2) * dy1/dt + y1 = 0 % initial conditions, y1(0) = dy1/dt = 1 % convert to two first-order ODEs % The solution becomes progressively stiffer % as mu gets large yp = [y(2); mu*(1-y(1)^2)*y(2)-y(1)];
Nonstiff ODE – van del Pol equation >> [t,y]=ode45(@vanderpol,[0 20],[1 1],[], 1); >> H=plot(t,y(:,1),t,y(:,2),'m--'); >> legend('y1','y2',2); = 1 ode45
Stiff ODE – van del Pol equation >> [t,y]=ode23s(@vanderpol,[0 6000],[1 1],[], 1000); >> H=plot(t,y(:,1)); >> set(H,'LineWidth',3) = 1000 ode23s
Bungee Jumper – Coupled ODEs Vertical Dynamics of a jumper connected to a stationary platform with a bungee cord (Chapter 18) Air resistance depending on whether the cord is slack or stretched – use sign(v) for drag force Spring constant k (N/m) and damping coefficient (N·s/m) Need to solve two simultaneous ODEs for x and v k = = 0 if x L
Non-stiff ODEs: Bungee Jumper Use ode45 for non-stiff ODEs to solve for the distance and velocity of a bungee jumper function dydt = bungee(t,y,L,cd,m,k,gamma) g = 9.81; cord = 0; if y(1) > L % determine if the cord exerts a force cord = k/m * (y(1)-L) + gamma/m * y(2); end dydt = [y(2); g - sign(y(2)) * cd/m*y(2)^2 - cord];
Bungee jumper velocity Bungee jumper distance >> [t,y] = ode45(@bungee,[0 50],[0 0],[],30,0.25,68.1,40,8); >> h1 = plot(t,-y(:,1),t,y(:,2),'m--'); >> h2 = legend('x (m)','v(m/s)'); >> set(h1,'LineWidth',3); set(h2,'FontSize',12); Bungee jumper velocity Bungee jumper distance
Solution Strategies PDEs
OVERVIEW Overview of the computational solution procedures Governing Equations ICS/BCS System of Algebraic Equations Equation (Matrix) Solver Approximate Solution Discretization Ui (x,y,z,t) p (x,y,z,t) T (x,y,z,t) or (,,, ) Continuous Solutions Finite-Difference Finite-Volume Finite-Element Spectral Boundary Element Discrete Nodal Values Tridiagonal ADI SOR Gauss-Seidel Gaussian elimination
Discretization 1. Time derivatives 2. Spatial derivatives almost exclusively by finite-difference methods 2. Spatial derivatives FDM (Finite-Difference Methods) FVM (Finite-Volume Methods) FEM (Finite-Element Methods) Spectral Methods Boundary Element Methods, etc.
Converting Derivatives to Discrete Algebraic Equations Heat Equation Unsteady, one-dimensional Parabolic PDE Marching in time, elliptic in space The simplest system to illustrate both the “propagation” and “equilibrium” behaviors Analytic solution
Parabolic Equation Convective Transport Equation T = temperature, = T = concentration, = D T = vorticity, = T = momentum, = T = turbulent kinetic energy, = + t T = turbulent energy dissipation, = ( + t)/
Advection-Diffusion Convective Transport Equation Diffusion/convection of polluten in a river Diffusion of polluten in a still lake (u = 0)
Discretization Choose suitable step size and time increment Replace continuous information by discrete nodal values Construct discretization (algebraic) equations with suitable numerical methods Specify appropriate auxiliary conditions for discretization equations Classification of PDE is important Solve the system of “well-posed” equations by matrix solver
Convert PDE to algebraic equations Spatial Derivatives Finite-difference: Taylor-series expansion Finite-element: low-order shape function and interpolation function, continuous within each element Finite-volume: integral form of PDE in each control volume Spectral method: higher-order interpolation, continuous over the entire domain Spectral element: finite-element/spectral Panel method, Boundary element method Convert PDE to algebraic equations
Time Derivatives One-sided (forward or backward) differences Two-level schemes Three-level schemes Runge-Kutta mehtods Adams-Bashforth-Moulton predictor-corrector methods Usually no advantages in using higher-order integration formula unless the spatial discretization error can be improved to the same order
Finite-Difference Methods Replace derivatives by differences j-2 j-1 j j+1 j+2
Taylor series expansion Construction of finite-difference formula Numerical accuracy: discretization error xo x
Truncation Errors Taylor series Truncation error How to reduce truncation errors? (a) Reduce grid spacing, use smaller x = x-xo (b) Increase order of accuracy, use larger n
Finite-Differences xo = xj , x = xj+1 = xj + x xo x
3.2 Approximation to Derivatives Partial differential equations: dx, dt Finite-difference equations: x, t Time and spatial derivatives (i) Taylor series expansion (ii) General Technique – Methods of undetermined coefficients Discretization errors Numerical accuracy
3.2.1 Taylor series expansion Truncated Taylor series – truncation error n+1 t x x n j-1 j j+1 Truncation errors
Finite-Differences Forward difference Backward difference 1 Central differeance 1 2 12 1+2
General Technique Method of undetermined coefficients General expression for discretization formula 3-point symmetric 3-point asymmetric 4-point asymmetric 5-point symmetric j-2 j-1 j j+1 j+2
General Procedures Expand the functional values at xj-2, xj-1, xj+1, xj+2, etc. about point xj (uniform spacing) Can be generalized for non-uniform grids
General Procedures Method of undetermined coefficients Uniform or Non-uniform grid spacing
Method of Undetermined Coefficients
3-point Symmetric Formula for First Derivative For consistency Leading term of truncation error
3-point Asymmetric Formula
3-point Asymmetric Formula for First Derivative For consistency Leading term of truncation error
Taylor Series Expansion Uniform grid spacing
5-point Symmetric Formula
5-point Symmetric Formula for First Derivative Leading term of truncation error
5-point Symmetric Formula for Second Derivative Leading term of truncation error
3-point Symmetric Formula for First Derivative a = e = 0 Leading term of truncation error
3-point Symmetric Formula for Second Derivative a = e = 0 Leading term of truncation error
3-point Asymmetric Formula for First Derivative a = b = 0 Leading term of truncation error
3-point Asymmetric Formula for Second Derivative a = b = 0 Leading term of truncation error
Accuracy of the Discretization Process Numerical Accuracy - truncation error leading term (Tables 3.3 and 3.4) Example: Truncation error Ax = Re u x = Rc cell Reynolds number or cell Peclet number
Truncation Errors Slope: asymptotic rate-of-convergence
Higher-Order vs Low-Order Scheme Higher-order formulae Higher accuracy (for the same grid spacing) Less efficient (for the same number of elements) Less stable, may produce oscillatory solutions May not be more accurate for discontinuity or severe gradients Relatively little improvements for coarse-grid (large x) or lower-order (small m) solutions
Numerical Accuracy Cell Reynolds (or Peclet) number Consider exponential function as an example Require small Cell Reynolds number (Ax) or large m to achieve higher accuracy Increasing m is not very effective in comparison with reducing Ax
Higher-order formula is only marginally better Numerical Accuracy 1 x x x x Higher-order formula is only marginally better
Numerical Efficiency Overall efficiency Fast turnaround time Limitations in computer memory (I/O) and execution time It may not be feasible to use fine-grid all the time Lower-order formula together with finer grid may be more effective than higher-order formula with coarse grid Use non-uniform, adaptive grids
Use Non-uniform adaptive grid for efficient resolution of sharp gradients
First-derivative Second-derivative
Wave Representation Fourier analysis - another way to assess the numerical accuracy Many fluid flow phenomena exhibit a wave-like motion (e.g., turbulent eddies) The fluid flow may be decomposed in terms of their Fourier components Different discretization errors for long and short waves (different frequencies)
Significance of Grid Coarseness In general x <<min (minimum wavelength) for good resolution Direct Numerical Simulation (DNS) of turbulence – need to resolve the smallest length and time scales DNS: impractical for high-Re flows Non-uniform grid spacing: fine-grid in short wavelength regions only
Grid Resolution Too coarse Reasonable How to choose appropriate grid spacing? Grid-independent solutions Grid-refinement study Too coarse Reasonable
Laminar and Turbulent Flows average velocity Laminar (molecular action) accelerate when molecules moving upward, slow down when moving downward Produce drag (shear) Turbulent (Random 3D eddies) molecular action still present, random eddies increase transport Enhanced mixing (turbulent shear)
Flat plate boundary layer, U = 24 m/s, y = 0.57 mm
Low-Re larger High-Re smaller
Wave Representation u x Grid spacing x – adequate for mean flow But too coarse for turbulence u U x x x x x
Longer waves too coarse Shorter waves
Accuracy of Representing Waves Consider a progressive wave with propagation speed q q xj
Exact Derivatives Exact derivatives at xj
Central Difference Three-point symmetric formula Let = m(xj – qtn) and = mx
Central Difference Second derivative
Amplitude Ratio Amplitude ratio for mth-derivative First derivative Second derivative
function [x,y,dy,dy1,ddy,ddy1]=AmpRatio(npt,m) % Wave Representation of Finite Difference Formulae % lambda = wavelength; domain size = 2*lambda % m = wave number % npt = number of grid points per wavelength % Exact solution y=cos(mx) % Exact first derivative dy=-m*sin(mx) % Exact second derivative ddy=-m^2*cos(mx) lambda=2*pi/m; length=2*lambda; dx=length/npt; ip1=2*npt+1; x=-npt*dx:dx:npt*dx; y=cos(m*x); dy=-m*sin(m*x); ddy=-m^2*cos(m*x); figure(1); plot(x,y,'m-<',x,dy,'b-o',x,ddy,'r-s'); dy1=dy; ddy1=ddy; for i=2:ip1-1 dy1(i)=(y(i+1)-y(i-1))/(2*dx); ddy1(i)=(y(i+1)-2*y(i)+y(i-1))/dx^2; end dy1(1)=(y(2)-y(1))/dx; dy1(ip1)=(y(ip1)-y(ip1-1))/dx; ddy1(1)=(y(1)+y(3)-2*y(2))/dx^2; ddy1(ip1)=(y(ip1)+y(ip1-2)-2*y(ip1-1))/dx^2; ar1=dy1./dy; ar2=ddy1./ddy; figure(2); plot(x,dy,'b-d',x,dy1,'r-o'); figure(3); plot(x,ddy,'b-d',x,ddy1,'r-o'); figure(4); plot(x,ar1,'b-d',x,ar2,'m-o'); axis([-7 7 0 1]);
Amplitude Ratio attenuation Amplitude ratio for first-derivative Wavelength , wave number m = 2/ attenuation short waves
Wave Attenuation = 4 x = 2 x Numerical method acts like a low-pass filter: filtering out the high frequency compoents = 4 x x x x x = 2 x x x
Amplitude Ratio attenuation Amplitude ratio for second-derivative Wavelength , wave number m = 2/ attenuation short waves
Forward Difference First-derivative Amplitude reduction and phase error
Forward Difference q Amplitude Ratio Phase error = x/2 (phase lead) Amplitude ratio (in space) is better than that obtained by 3-point symmetric formula But not the overall accuracy (due to phase error in time) q
Backward Difference First-derivative Amplitude reduction and phase error
Backward Difference Amplitude Ratio Phase error = x/2 (phase lag) q
Accuracy of Higher-order Formula Five-point symmetric formula
Higher-order Formula 5-point symmetric formula for second-derivative
Amplitude Ratio Grid refinement more efficient than higher order for coarse grids
Finite-Difference Method Discretization - Construction of a structured grid Replace continuous derivatives by equivalent algebraic (finite-difference) expressions Rearrange the resulting equations to form banded matrices Solve for nodal values at discrete points Numerical Convergence – consistency and convergence
Conceptual Implementation Explicit – direct substitution Cannot cope with sudden change in boundary conditions unless t is small Time-marching, no need to invert matrix Boundary conditions lagged by one time step (propagation problem) Implicit – matrix inversion Time-dependent boundary conditions captured immediately
Finite-difference Solution Procedures
DIFF: Transient Heat Conduction Problems FTCS (Forward Time, Centered Space) PDE FDE T.E. O(t, x2)
Finite-Difference Formula FTCS scheme Explicit, time marching
Numerical solutions
DIFF: Heat Diffusion
FTCS Scheme for Heat Equation
Root-Mean-Square (rms) Error Note: tmax = 4999.00
Finite-difference Methods Unsteady 3D convective-transport equations Explicit, no matrix inversion needed Why do we still need to learn other methods?
Complex Geometry General Curvilinear Coordinates Pressure-Velocity coupling? Turbulence?
Finite-Difference: Parabolic Equations Chapter 30 Finite-Difference: Parabolic Equations
Heat Conduction Equation Conservation of Energy Balance of heat fluxes Apply Fourier’s law of heat conduction
Heat Equation: Parabolic PDE Heat transfer in a one-dimensional rod x = 0 x = a g1(t) g2(t)
t x Discretize the solution domain in space and time with x and t (l index) x space (i index)
Computational Molecule Explicit Euler Method
Initial and Boundary Conditions Explicit Euler method T(a, t) = g2(t) T(0, t) = g1(t) Initial conditions : T(x,0) = f(x)
Heat Equation t T(x,t) t x x Finite-difference tl+1 tl xi-1 xi xi+1 (i,l+1) t tl (i-1,l) (i,l) (i+1,l) x xi-1 xi xi+1 x Forward-difference Central-difference at time level j
Explicit Method Stability: Explicit Euler method for heat equation Rearrange Stability:
Domain of Influence
Explicit Euler Method Stable Unstable (negative coefficients)
Heat Equation: Explicit Euler Method Continued on next page
Heat Equation: Explicit Euler Method
Example: Heat Equation » [x,t,w]=Heat_Explicit; initial condition f(x) = 'x.^4' left boundary condition g1(t) = '0*t' right boundary condition g2(t) = 't.^0' length of the rod L = 1 total simulation time tmax = 1 grid spacing dx =0.1 time increment dt =0.05 diffusion coefficient k = 0.1 r = 0.5000 ( = 0.5)
Heat Equation: Explicit Euler Method = 0.5
Example: Explicit Euler Method Heat Equation (Parabolic PDE) k = 0.5, x = 0.25, t = 0.05 2 60e -2t 20e -t 1 1 2 3 4 20 + 40 x
Example Explicit Euler method First step: t = 0.05
20e -t 60e -2t Second step: t = 0.10 20 + 40 x 29.61 40 47.72 30 40 50 1 2 3 4 20 + 40 x
Heat Equation: Time-dependent BCs » [x,t,w]=Heat_explicit; initial condition f(x) = '20+40*x' left boundary condition g1(t) = '20*exp(-t)' right boundary condition g2(t) = '60*exp(-2*t)' length of the rod L = 1 total simulation time tmax = 1 grid spacing dx =0.1 time increment dt =0.05 diffusion coefficient k = 0.08 r = 0.4000 ( = 0.4)
Heat Equation: Time-dependent BCs = 0.4
Numerical Stability Stability for Explicit Euler Method It can be shown by Von Neumann analysis that Switch to Implicit method to avoid instability
Explicit Euler Method: Unstable Solutions » [x,t,w]=Heat_Explicit; initial condition f(x) = 'x.^4' left boundary condition g1(t) = '0*t' right boundary condition g2(t) = 't.^0' length of the rod L = 1 total simulation time tmax = 1 grid spacing dx =0.1 time increment dt =0.05 diffusion coefficient k = 0.2 r = 1.0000 ( = 1.0) Unstable !!
Explicit Euler Method: Stability = 1 Unstable !!
Simple Implicit Method Unconditionally Stable u(a, t) = g2(t) u(0, t) = g1(t) Initial conditions : u(x,0) = f(x)
Computational Molecules
Implicit Method t T(x,t) t x x Finite-difference tl+1 tl xi-1 xi xi+1 (i-1,l+1) (i,l+1) (i+1,l+1) tl+1 T(x,t) t tl (i,l) x xi-1 xi xi+1 x Forward-difference Central-difference at time level j+1
Simple Implicit Method Implicit Euler method for heat equation Tridiagonal matrix (Thomas algorithm) Unconditionally stable
Example: Simple Implicit Method Heat Equation (Parabolic PDE) k = 0.5, x = 0.25, t = 0.1 1 60e -2t 20e -t 1 2 3 4 20 + 40 x
Example Simple Implicit Method
20e -t 60e -2t Solve the tridiagonal matrix 20 + 40 x 28.96 38.51 46.19 1 20e -t 60e -2t 1 2 3 4 20 + 40 x
Heat Equation: Simple Implicit Method Continued on next page
Implicit Euler Method - continued
Simple Implicit Method » [x,t,zz,r]=heat_implicit initial condition f(x) = '20+40*x' left boundary condition g1(t) = '20*exp(-t)' right boundary condition g2(t) = '60*exp(-2*t)' length of the rod L = 1 total simulation time tmax = 1 grid spacing: dx = 0.25 time increment: dt = 0.1 diffusion coefficient k = 0.5 x = 0 0.2500 0.5000 0.7500 1.0000 t = Columns 1 through 7 0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 Columns 8 through 11 0.7000 0.8000 0.9000 1.0000 zz = 20.0000 30.0000 40.0000 50.0000 60.0000 18.0967 28.9552 38.5075 46.1943 49.1238 16.3746 27.2058 35.8502 41.1730 40.2192 14.8164 25.0434 32.5676 35.9885 32.9287 13.4064 22.7035 29.0758 31.0834 26.9597 12.1306 20.3544 25.6418 26.6366 22.0728 10.9762 18.1038 22.4183 22.7033 18.0717 9.9317 16.0132 19.4815 19.2789 14.7958 8.9866 14.1116 16.8595 16.3298 12.1138 8.1314 12.4067 14.5510 13.8096 9.9179 7.3576 10.8937 12.5386 11.6679 8.1201 r = 0.8000
Heat Equation: Simple Implicit Method Unconditionally stable » [x,t,zz,r]=Heat_Implicit; initial condition f(x) = '20+40*x' left boundary condition g1(t) = '20*exp(-t)' right boundary condition g2(t) = '60*exp(-2*t)' length of the rod L = 1 total simulation time tmax = 5 grid spacing: dx = 0.1 time increment: dt = 0.25 diffusion coefficient k = 0.08 r = 2.0000 » view(20,-30) Unconditionally stable
Simple Implicit Method Unconditionally stable = 2 Unconditionally stable
Crank-Nicolson Method
Crank-Nicolson method Simple Implicit Method: first-order in time Crank-Nicolson: second-order in time u(a, t) = g2(t) u(0, t) = g1(t) Initial conditions : u(x,0) = f(x)
Crank-Nicolson Method Crank-Nicolson method for heat equation Average between two time levels Temporal first derivative (central-difference at tl+1/2) Second-derivative – (average at midpoint)
Crank-Nicolson Method Crank-Nicolson method for heat equation Average between two time levels Tridiagonal matrix Unconditionally stable (neutrally stable) Oscillation may occur
Crank-Nicolson Method Dirichlet boundary conditions First node i = 0 Last node i = m+1
Example: Crank-Nicolson Method Heat Equation (Parabolic PDE) k = 0.5, x= 0.25, t = 0.1 1 60e -2t 20e -t 1 2 3 4 20 + 40 x
Example Crank-Nicolson method Tridiagonal matrix ( = 0.8)
20e -t 60e -2t Solve the tridiagonal matrix 20 + 40 x 29.42 39.30 47.43 1 20e -t 60e -2t 1 2 3 4 20 + 40 x
Heat Equation: Crank-Nicolson Method Continued on next page
Crank-Nicolson method - continued
Crank-Nicolson Method » [x,t,zz,r]=Heat_CN initial condition f(x) = '20+40*x' left boundary condition g1(t) = '20*exp(-t)' right boundary condition g2(t) = '60*exp(-2*t)' length of the rod L = 1 total simulation time tmax = 1 grid spacing: dx = 0.25 time increment: dt = 0.1 diffusion coefficient k = 0.5 x = 0 0.2500 0.5000 0.7500 1.0000 t = Columns 1 through 7 0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 Columns 8 through 11 0.7000 0.8000 0.9000 1.0000 zz = 20.0000 30.0000 40.0000 50.0000 60.0000 18.0967 29.4214 39.2998 47.4275 49.1238 16.3746 27.8828 36.9908 42.0772 40.2192 14.8164 25.6937 33.4986 36.5947 32.9287 13.4064 23.1695 29.6944 31.4175 26.9597 12.1306 20.6161 25.9565 26.7538 22.0728 10.9762 18.1911 22.4885 22.6592 18.0717 9.9317 15.9706 19.3755 19.1247 14.7958 8.9866 13.9817 16.6384 16.1080 12.1138 8.1314 12.2246 14.2636 13.5528 9.9179 7.3576 10.6858 12.2211 11.3998 8.1201 r = 0.8000
Crank-Nicolson Method Unconditionally stable » [x,t,zz,r]=Heat_CN; initial condition f(x) = '20+40*x' left boundary condition g1(t) = '20*exp(-t)' right boundary condition g2(t) = '60*exp(-2*t)' length of the rod L = 1 total simulation time tmax = 5 grid spacing: dx = 0.1 time increment: dt = 0.25 diffusion coefficient k = 0.08 r = 2.0000 » view(20,-30) Unconditionally stable
Crank-Nicolson method Unconditionally stable = 2 Unconditionally stable
One-Dimensional Diffusion Equation
Diffusion Equation Diffusion equation contains the dissipation mechanism for fluid flow with significant viscous or heat conduction effects Provide guidance for choosing numerical algorithms for viscous fluid flow
Explicit Methods FTCS scheme (Two-level scheme) Explicit time-marching
Explicit Methods Richardson and DuFort-Frankel schemes (Three-level scheme) Richardson DuFort-Frankel
Time derivative Spatial derivative Explicit Methods General Three-level schemes Numerical Consistency Time derivative Spatial derivative
Implicit Methods Fully-Implicit Scheme Need to solve a system of coupled algebraic equations at time level (n+1)
Implicit Methods Crank-Nicolson Scheme Generalized Three-Level Scheme
Implicit Methods Higher-Order Schemes Hybrid FD-FE three-level scheme Truncation error
Higher-Order Scheme for any combination of (s, , ) Truncation error Fourth-order scheme for any combination of (s, , )
General Three-Level Scheme Hybrid finite-difference/finite-element 12 n+1 n n1 Implicit 1+ 1 1 Explicit ( = 0) j1 j j+1
Active nodes for diffusion equation
General Three-Level Scheme Mass and difference operators
Explicit Three-Level Scheme Explicit Method ( = 0) (1) FTCS Scheme (2) Richardson Scheme (3) DuFort-Frankel Scheme (4) Fourth-order scheme
Explicit Three-Level Scheme Explicit Method ( = 0) Truncation error Fourth-order scheme
Von Neumann Analysis Explicit Three-level scheme Amplification factor
Numerical Stability Explicit Three-level scheme For 4th-order scheme
Implicit Three-Level Scheme Truncation error Fourth-order scheme
Implicit Three-Level Schemes (1) Fully-Implicit (2) Crank-Nicolson (3) Linear FEM/Imp (4) Linear FEM/C-N (5) 3-level Fully Implicit (6) 4th-order FDM (7) 4th-order Composite
Truncation Error Analysis Implicit three-level scheme (a) Difference operator
Difference Operator Therefore,
Truncation Error Analysis (b) Mass operator
Mass Operator Time derivative
Diffusion Equation Combine time and spatial derivatives Numerical consistency
Summary Implicit three-level scheme Explicit three-level scheme ( = 0) Fourth-order schemes Composite scheme (Independent of s)
Explicit Schemes - DIFEX
Exact Solution
Explicit schemes - DIFEX (s < 0.41 for = 1)
Implicit Schemes - DIFIM
Tridiagonal matrix system
Explicit Scheme - DIFEX Implicit Scheme - DIFIM
Implicit Schemes – DIFIM Numerical Accuracy (s = 1) FDM-2nd FEM-2nd FDM-4th FEM-4th Composite 0.3003? FDM-2nd FEM-2nd FDM-4th FEM-4th Composite Implicit Schemes – DIFIM
Numerical Accuracy S = 0.41: stability for explicit FDM-4th
7.3 Boundary and Initial Conditions Neumann boundary conditions
Explicit treatment of Neumann BCs 2nd 2nd 4th 4th 1st2nd2nd2nd Rate of convergence depends on the boundary conditions, not just the accuracy of discretization scheme
Implicit treatment of Neumann BCs 1st2nd2nd2nd It is important to maintain the same order of accuracy for discretization scheme and boundary conditions
7.4 Method of Lines (Semi-Discretization) Discretize the spatial term first Reduced to ODE in time Solve a system of ODEs by Runge-Kutta or multistep methods
Weighted-average of time-derivative and slope f Time Integration Linear multistep method (for time integration) One-step integration (m = 1) Euler scheme (1= 0 = 0 = 1, 1 = 0) Weighted-average of time-derivative and slope f Two-level scheme FTCS scheme
Crank-Nicolson Scheme One-step integration (m = 1) Trapezoid scheme (1= 0 = 1, 0 = 1 = 1/2) All two-level schemes are special cases of the one-step method
Two-Step Integration 3LFI Two-step integration (m = 2) General three-level schemes Explicit three-level scheme (2 = 0) Implicit three-level scheme (2 = 1) e.g, Three-level fully implicit scheme 3LFI
Classical 4th-order Runge-Kutta Method Most widely used one-step method weighted-average slope Error in eq.(7-53), p. 244
Classical 4th-order Runge-Kutta Method f * f *** f ** f n t n t n+1 t n+1/2