Presentation is loading. Please wait.

Presentation is loading. Please wait.

Solution Strategies ODEs and PDEs.

Similar presentations


Presentation on theme: "Solution Strategies ODEs and PDEs."— Presentation transcript:

1 Solution Strategies ODEs and PDEs

2 ODEs: Initial-Value Problems
Solution Strategies ODEs: Initial-Value Problems

3 Differential Equations
There are ordinary differential equations - functions of one variable And there are partial differential equations - functions of multiple variables

4 Order of differential equations
1st order (falling parachutist) 2nd order (mass-spring system with damping) etc.

5 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

6 Linear and Nonlinear ODEs
Linear: No multiplicative mixing of variables, no nonlinear functions Nonlinear: anything else

7 Example: Swinging Pendulum
nonlinear

8 Equation Linearization
Sometimes, the nonlinear ODE can be linearized Example: for small angles Nonlinear linear

9 Ordinary Differential Equations
ODEs show up everywhere in engineering Dynamics (Newton’s 2nd law) Heat conduction (Fourier’s law) Diffusion (Fick’s law)

10 Ordinary Differential Equations
Given the rate of change (derivative) of y w.r.t. x at every point

11 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 

12 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

13 Ordinary Differential Equations
Ordinary differential equations (ODEs) Initial value problems Numerical approximations New value = old value + slope × step size

14 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

15 Euler’s method (First-order Taylor Series Method)
Approximate the derivative by finite difference Local truncation error or

16 Euler’s Method Euler’s (Euler-Cauchy or point-slope) method
Use the slope at ti to predict yi+1

17 Euler’s method Straight line approximation y0 t0 h t1 h t2 h t3

18 Example: Euler’s Method
Analytic solution Euler method h = 0.50

19 Example: Euler’s Method

20 Euler’s method: y h = 0.25 1 h = 0.5 t 0.25 0.5 0.75 1.0

21 Euler’s Method (modified M-file)

22 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 >> H=plot(t,y,'r-o',tt,ye); >> set(H,'LineWidth',3,'MarkerSize',12) >> print -djpeg ode01.jpg

23 Euler’s Method (h = 0.1)

24 Euler’s Method (h = 0.05)

25 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”

26 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)

27 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

28 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

29 Heun’s Method Heun’s method is a predictor-corrector method Predictor
Corrector (may be applied iteratively)

30 Heun’s Method Iterate the corrector of Heun’s method to obtain an improved estimate Predictor Corrector

31 Heun’s Method with Iterative Correctors

32 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

33 Heun’s Method with Iterative Correctors Heun’s with 5 iterations
Exact Euler’s t

34 Example: Heun’s Method
First Step

35 Example: Heun’s Method
Second Step

36 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

37 Midpoint Method Improved Polygon or Modified Euler Method
Use the slope at midpoint to represent the average slope

38 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

39 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

40 Second-Order RK Methods
Taylor series expansion Compare to the second-order Taylor formula Three equations for four unknowns (a1, a2, k1, q11)

41 Second-Order RK Methods
Second-order version of Runge-Kutta Methods 3 equations for 4 unknowns

42 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

43 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

44 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

45 Midpoint (2nd-order RK) Method

46 Midpoint (2nd-order RK) Method
>> [t,y] = midpoint('example2_f',[0 pi],1,0.05*pi); step t y >> tt = 0:0.01*pi:pi; yy = example2_e(tt); >> H = plot(t,y,'r-o',tt,yy); >> set(H,'LineWidth',3,'MarkerSize',12);

47 Midpoint (RK2) Method

48 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

49 Third-Order Runge-Kutta Method
General form Weighted slope

50 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

51 Third-order Runge-Kutta Methods
Nystrom Method Nearly Optimum Method

52 Classical Third-order Runge-Kutta Method
Reduce to Simpson’s 1/3 rule for f = f(t)

53 3rd-Order Heun Method

54 Classical 4th-order Runge-Kutta Method
One-step method Reduce to Simpson’s 1/3 rule for f = f(t)

55 Classical 4th-order Runge-Kutta Method
ti ti + h/2 ti + h

56 Example: Classical 4th-order RK Method
First step, t = 0.5

57 Example: Classical 4th-order RK Method
Second step, t = 1.0

58 Fourth-Order Runge-Kutta Method

59 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 >> H=plot(x,y,'r-o',xx,yy); >> set(H,'LineWidth',3,'MarkerSize',12);

60 Fourth-Order Runge-Kutta Method

61 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

62 Numerical Accuracy Euler Midpoint Heun (iterative) RK4 h = 0.1

63 Numerical Accuracy Euler Midpoint Heun (iterative) RK4 h = 0.05

64 Butcher’s sixth-order Runge-Kutta Method

65 System of ODEs A system of simultaneous ODEs
n equations with n initial conditions

66 System of ODEs Bungee Jumper’s velocity and position
Two simultaneous ODEs

67 Nonlinear Pendulum R Second-order ODE W=mg

68 Second-Order ODE Convert to two first-order ODEs

69 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

70 Hand Calculations: Euler’s Method
Solve the following ODE from t = 0 to t = 1 with h = 0.5 Euler method

71 Euler’s Method for a System of ODEs
y is a column vector with n variables

72 Euler Method for a System of ODEs
function f = example5(t,y) % dy1/dt = f1 = -0.5 y1 % dy2/dt = f2 = *y *y2 % let y(1) = y1, y(2) = y2 % tspan = [0 1] % initial conditions y0 = [4, 6] f1 = -0.5*y(1); f2 = *y(1) - 0.3*y(2); f = [f1, f2]'; >> [t,y]=Euler_sys('example5',[0 1],[4 6],0.5); t y y y3 ... >> [t,y]=Euler_sys('example5',[0 1],[4 6],0.2); (h = 0.5) (h = 0.2)

73 Euler Method for Second-Order ODE
Nonlinear Pendulum function f = pendulum(t,y) % nonlinear pendulum d^2y/dt^ dy/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]';

74 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

75 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

76 Higher Order ODEs In general, nth-order ODE

77 System of First-Order ODE-IVPs
Example Convert to three first-order ODE-IVPs

78 Euler’s Method for Systems of First-Order ODEs
Example

79 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

80 Classical 4th-order Runge-Kutta Method for Systems of ODE-IVPs
2 equations Applicable for any number of equations

81 Hand Calculations: RK4 Method
Solve the following ODE from t = 0 to t = 1 with h = 0.5 Classical RK4 method

82 Continued: RK4 Method

83 4th-order Runge-Kutta Method for ODEs
Valid for any number of coupled ODEs

84 4th-order Runge-Kutta Method for ODEs
>> [t,y]=RK4_sys('example5',[0 10],[4 6],0.5); t y y y3 ...

85 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

86 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  

87 Example: More than 2 ODE-IVPs
function f = example(t, y) % solve y' = Ay = f, y0 = [ ]' % four first-order ODE-IVPs A = [ ]; y=[ y(1) y(2) y(3) y(4)]'; f = A*y;

88 4th-order Runge-Kutta Method for ODE-IVPs
Symbols: n = 20 Lines : n =100 » tspan=[0 2]; y0=[ ]; » [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);

89 ODEs: Adaptive Methods and Stiff Systems
Solution Strategies ODEs: Adaptive Methods and Stiff Systems

90 Adaptive Runge Kutta Method
Use small step size in high gradient region (abrupt change) automatic step size adjustment

91 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

92 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

93 Adaptive 4th-order RK Method
One full-step with h Two half-steps with h/2 Therefore, Two half-steps

94 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)

95 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 = 103) AbsTol: relative tolerance (default = 106)

96 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;

97 (a) RelTol = 103 (b) RelTol = 104
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 = 10 (b) RelTol = 104

98 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

99 Runge-Kutta Fehlberg Method
Fourth-order Fifth-order These coefficients were developed by Cash and Karp (1990). Also called Cash-Karp RK Method

100 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

101 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

102 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

103 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

104 Example Forcing function
Runge-Kutta-Fehlberg method with adaptive step size control t small step size around t = 2 solution t

105 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

106 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))];

107 Adaptive RK method : ode45
>> tspan=[0 20]; y0 = [1, 2]; >> [t,y] = ode45('predprey',tspan,y0); >> out = [t y] out =

108 Predator-Prey Model Time history of predator (fox) and prey (geese) populations

109 Predator-Prey Model State-space plot

110 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

111 Multistep Methods Comparison of one-step and multistep methods
One-step method Weighted-average slope Multistep method xi-2 xi-1 xi xi+1

112 One-Step and Multistep Methods
One-step Multistep

113 Heun’s Method Start with second-order method
Look at Heun’s method (Self-Starting) Euler predictor - O(h2) Trapezoid corrector - O(h3)

114 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

115 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)

116 Heun’s Method (a) 2nd-order predictor (b) 3rd-order corrector
Self-starting, need yi only

117 Truncation Errors Non-self-starting Heun method
Predictor truncation error Corrector truncation error

118 Modifiers Corrector Modifier Predictor Modifier (not used in textbook)
Error in textbook

119 Non-Self Starting Heun’s Method
So the sequence is Predict Adjust prediction Correct Converged? If not, correct again

120 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

121 Hand Calculations – First Step
Predictor: Corrector: First Step (i = 0) : need two initial conditions Predictor:

122 Hand Calculations – First Step
Corrector:

123 Hand Calculations – Second Step
Second Step (i = 1) : Predictor: Predictor Modifier:

124 Hand Calculations – Second Step
Corrector: Corrector Modifier:

125 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

126 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

127 Stability Example problem

128 Euler Explicit Method Stability criterion Region of absolute stability
Amplification factor

129 Unconditionally stable !
Euler Implicit Method Unconditionally stable !

130 Unconditionally stable
Stability Explicit Euler method Second-order Adams-Bashforth Second-order Adams-Moulton If a = 1000, then h  to ensure stability Unconditionally stable

131 Example Euler Explicit Euler Implicit

132 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

133 Stiff ODE – van del Pol equation
Van der Pol equation for electronic circuit Convert to two first-order ODEs

134 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)];

135 Nonstiff ODE – van del Pol equation
>> 20],[1 1],[], 1); >> H=plot(t,y(:,1),t,y(:,2),'m--'); >> legend('y1','y2',2);  = 1 ode45

136 Stiff ODE – van del Pol equation
>> 6000],[1 1],[], 1000); >> H=plot(t,y(:,1)); >> set(H,'LineWidth',3)  = 1000 ode23s

137 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

138 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];

139 Bungee jumper velocity Bungee jumper distance
>> [t,y] = 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

140 Solution Strategies PDEs

141 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

142 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.

143 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

144 Parabolic Equation Convective Transport Equation
T = temperature,  =  T = concentration,  = D T = vorticity,  =  T = momentum,  =  T = turbulent kinetic energy,  =  + t T = turbulent energy dissipation,  = ( + t)/

145 Advection-Diffusion Convective Transport Equation
Diffusion/convection of polluten in a river Diffusion of polluten in a still lake (u = 0)

146 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

147 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

148 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

149 Finite-Difference Methods
Replace derivatives by differences j-2 j-1 j j+1 j+2

150 Taylor series expansion
Construction of finite-difference formula Numerical accuracy: discretization error xo x

151 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

152 Finite-Differences xo = xj , x = xj+1 = xj + x xo x

153 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

154 3.2.1 Taylor series expansion
Truncated Taylor series – truncation error n+1 t x x n j-1 j j+1 Truncation errors

155 Finite-Differences Forward difference Backward difference 1
Central differeance 1 2 12 1+2

156 General Technique Method of undetermined coefficients
General expression for discretization formula 3-point symmetric 3-point asymmetric 4-point asymmetric 5-point symmetric j j j j j+2

157 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

158 General Procedures Method of undetermined coefficients
Uniform or Non-uniform grid spacing

159 Method of Undetermined Coefficients

160 3-point Symmetric Formula for First Derivative
For consistency Leading term of truncation error

161 3-point Asymmetric Formula

162 3-point Asymmetric Formula for First Derivative
For consistency Leading term of truncation error

163 Taylor Series Expansion
Uniform grid spacing

164 5-point Symmetric Formula

165 5-point Symmetric Formula for First Derivative
Leading term of truncation error

166 5-point Symmetric Formula for Second Derivative
Leading term of truncation error

167 3-point Symmetric Formula for First Derivative
a = e = 0 Leading term of truncation error

168 3-point Symmetric Formula for Second Derivative
a = e = 0 Leading term of truncation error

169 3-point Asymmetric Formula for First Derivative
a = b = 0 Leading term of truncation error

170 3-point Asymmetric Formula for Second Derivative
a = b = 0 Leading term of truncation error

171 Accuracy of the Discretization Process
Numerical Accuracy - truncation error leading term (Tables 3.3 and 3.4) Example: Truncation error Ax = Re u x = Rc cell Reynolds number or cell Peclet number

172

173

174 Truncation Errors Slope: asymptotic rate-of-convergence

175 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

176 Numerical Accuracy Cell Reynolds (or Peclet) number
Consider exponential function as an example Require small Cell Reynolds number (Ax) or large m to achieve higher accuracy Increasing m is not very effective in comparison with reducing Ax

177 Higher-order formula is only marginally better
Numerical Accuracy 1 x x x x Higher-order formula is only marginally better

178 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

179 Use Non-uniform adaptive grid for efficient resolution of sharp gradients

180 First-derivative Second-derivative

181 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)

182 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

183 Grid Resolution Too coarse Reasonable
How to choose appropriate grid spacing? Grid-independent solutions Grid-refinement study Too coarse Reasonable

184 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)

185 Flat plate boundary layer, U = 24 m/s, y = 0.57 mm

186 Low-Re larger  High-Re smaller 

187 Wave Representation u x Grid spacing x – adequate for mean flow
But too coarse for turbulence u U x x x x x

188 Longer waves too coarse Shorter waves

189 Accuracy of Representing Waves
Consider a progressive wave with propagation speed q q xj

190 Exact Derivatives Exact derivatives at xj

191 Central Difference Three-point symmetric formula
Let  = m(xj – qtn) and  = mx

192 Central Difference Second derivative

193 Amplitude Ratio Amplitude ratio for mth-derivative First derivative
Second derivative

194 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([ ]);

195 Amplitude Ratio attenuation Amplitude ratio for first-derivative
Wavelength , wave number m = 2/ attenuation short waves

196 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

197 Amplitude Ratio attenuation Amplitude ratio for second-derivative
Wavelength , wave number m = 2/ attenuation short waves

198 Forward Difference First-derivative
Amplitude reduction and phase error

199 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

200 Backward Difference First-derivative
Amplitude reduction and phase error

201 Backward Difference Amplitude Ratio Phase error = x/2 (phase lag) q

202 Accuracy of Higher-order Formula
Five-point symmetric formula

203 Higher-order Formula 5-point symmetric formula for second-derivative

204 Amplitude Ratio Grid refinement more efficient than higher order for coarse grids

205 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

206 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

207 Finite-difference Solution Procedures

208 DIFF: Transient Heat Conduction Problems
FTCS (Forward Time, Centered Space) PDE FDE T.E. O(t, x2)

209 Finite-Difference Formula
FTCS scheme Explicit, time marching

210 Numerical solutions

211 DIFF: Heat Diffusion

212

213

214

215 FTCS Scheme for Heat Equation

216 Root-Mean-Square (rms) Error
Note: tmax =

217 Finite-difference Methods
Unsteady 3D convective-transport equations Explicit, no matrix inversion needed Why do we still need to learn other methods?

218 Complex Geometry General Curvilinear Coordinates
Pressure-Velocity coupling? Turbulence?

219 Finite-Difference: Parabolic Equations
Chapter 30 Finite-Difference: Parabolic Equations

220 Heat Conduction Equation
Conservation of Energy Balance of heat fluxes Apply Fourier’s law of heat conduction

221 Heat Equation: Parabolic PDE
Heat transfer in a one-dimensional rod x = 0 x = a g1(t) g2(t)

222 t x Discretize the solution domain in space and time with x and t
(l index) x space (i index)

223 Computational Molecule Explicit Euler Method

224 Initial and Boundary Conditions
Explicit Euler method T(a, t) = g2(t) T(0, t) = g1(t) Initial conditions : T(x,0) = f(x)

225 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

226 Explicit Method Stability: Explicit Euler method for heat equation
Rearrange Stability:

227 Domain of Influence

228 Explicit Euler Method Stable Unstable (negative coefficients)

229 Heat Equation: Explicit Euler Method
Continued on next page

230 Heat Equation: Explicit Euler Method

231 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.5)

232 Heat Equation: Explicit Euler Method
 = 0.5

233 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 x

234 Example Explicit Euler method First step: t = 0.05

235 20e -t 60e -2t Second step: t = 0.10 20 + 40 x 29.61 40 47.72 30 40 50
1 2 3 4 x

236 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.4)

237 Heat Equation: Time-dependent BCs
 = 0.4

238 Numerical Stability Stability for Explicit Euler Method
It can be shown by Von Neumann analysis that Switch to Implicit method to avoid instability

239 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.0) Unstable !!

240 Explicit Euler Method: Stability
 = 1 Unstable !!

241 Simple Implicit Method Unconditionally Stable
u(a, t) = g2(t) u(0, t) = g1(t) Initial conditions : u(x,0) = f(x)

242 Computational Molecules

243 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

244 Simple Implicit Method
Implicit Euler method for heat equation Tridiagonal matrix (Thomas algorithm) Unconditionally stable

245 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 x

246 Example Simple Implicit Method

247 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 x

248 Heat Equation: Simple Implicit Method
Continued on next page

249 Implicit Euler Method - continued

250 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 = t = Columns 1 through 7 Columns 8 through 11 zz = r = 0.8000

251 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

252 Simple Implicit Method Unconditionally stable
 = 2 Unconditionally stable

253 Crank-Nicolson Method

254 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)

255 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)

256 Crank-Nicolson Method
Crank-Nicolson method for heat equation Average between two time levels Tridiagonal matrix Unconditionally stable (neutrally stable) Oscillation may occur

257 Crank-Nicolson Method
Dirichlet boundary conditions First node i = 0 Last node i = m+1

258 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 x

259 Example Crank-Nicolson method Tridiagonal matrix ( = 0.8)

260 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 x

261 Heat Equation: Crank-Nicolson Method
Continued on next page

262 Crank-Nicolson method - continued

263 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 = t = Columns 1 through 7 Columns 8 through 11 zz = r = 0.8000

264 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

265 Crank-Nicolson method Unconditionally stable
 = 2 Unconditionally stable

266 One-Dimensional Diffusion Equation

267 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

268 Explicit Methods FTCS scheme (Two-level scheme) Explicit time-marching

269 Explicit Methods Richardson and DuFort-Frankel schemes (Three-level scheme) Richardson DuFort-Frankel

270 Time derivative Spatial derivative
Explicit Methods General Three-level schemes Numerical Consistency Time derivative Spatial derivative

271 Implicit Methods Fully-Implicit Scheme
Need to solve a system of coupled algebraic equations at time level (n+1)

272 Implicit Methods Crank-Nicolson Scheme Generalized Three-Level Scheme

273 Implicit Methods Higher-Order Schemes Hybrid FD-FE three-level scheme
Truncation error

274 Higher-Order Scheme for any combination of (s, , ) Truncation error
Fourth-order scheme for any combination of (s, , )

275 General Three-Level Scheme
Hybrid finite-difference/finite-element  2  n+1 n n1 Implicit 1+ 1 1 Explicit ( = 0)  j j j+1

276 Active nodes for diffusion equation

277 General Three-Level Scheme
Mass and difference operators

278 Explicit Three-Level Scheme
Explicit Method ( = 0) (1) FTCS Scheme (2) Richardson Scheme (3) DuFort-Frankel Scheme (4) Fourth-order scheme

279 Explicit Three-Level Scheme
Explicit Method ( = 0) Truncation error Fourth-order scheme

280 Von Neumann Analysis Explicit Three-level scheme Amplification factor

281 Numerical Stability Explicit Three-level scheme For 4th-order scheme

282 Implicit Three-Level Scheme
Truncation error Fourth-order scheme

283 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

284 Truncation Error Analysis
Implicit three-level scheme (a) Difference operator

285 Difference Operator Therefore,

286 Truncation Error Analysis
(b) Mass operator

287 Mass Operator Time derivative

288 Diffusion Equation Combine time and spatial derivatives
Numerical consistency

289 Summary Implicit three-level scheme
Explicit three-level scheme ( = 0) Fourth-order schemes Composite scheme (Independent of s)

290

291 Explicit Schemes - DIFEX

292

293

294

295 Exact Solution

296

297 Explicit schemes - DIFEX
(s < 0.41 for  = 1)

298 Implicit Schemes - DIFIM

299

300

301 Tridiagonal matrix system

302

303

304 Explicit Scheme - DIFEX Implicit Scheme - DIFIM

305 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

306 Numerical Accuracy S = 0.41: stability for explicit FDM-4th

307 7.3 Boundary and Initial Conditions Neumann boundary conditions

308 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

309 Implicit treatment of Neumann BCs
1st2nd2nd2nd It is important to maintain the same order of accuracy for discretization scheme and boundary conditions

310 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

311 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

312 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

313 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

314 Classical 4th-order Runge-Kutta Method
Most widely used one-step method weighted-average slope Error in eq.(7-53), p. 244

315 Classical 4th-order Runge-Kutta Method
f * f *** f ** f n t n t n+1 t n+1/2


Download ppt "Solution Strategies ODEs and PDEs."

Similar presentations


Ads by Google