2.29 Numerical Fluid Mechanics Spring 2015 – Lecture 13 REVIEW Lecture 12: • Grid-Refinement and Error estimation – Estimation of the order of convergence and of the discretization error – Richardson’s extrapolation and Iterative improvements using Roomberg’s algorithm • Fourier Error Analysis – Provide additional information to truncation error: indicates how well Fourier mode solution, i.e. wavenumber and phase speed, is represented • Effective wavenumber: ei kx i kx j i keff e x j (for CDS, 2nd order, keff sin(k x ) ) x • Effective wave speed (for linear convection eqn., f c f 0 , integrating in time exactly): num. k df dt f knum. (t ) c i keff f numerical ( x, t ) k t f k (0) ei kx i keff t k x f k (0) ei k (x ceff t ) (with eff 2.29 Numerical Fluid Mechanics ceff eff keff k c i keff c i k ceff ) PFJL Lecture 13, 1 2.29 Numerical Fluid Mechanics Spring 2015 – Lecture 13 REVIEW Lecture 12, Cont’d: • Stability – Heuristic Method: trial and error n – Energy Method: Find a quantity, l2 norm j , and then aim to show that it j remains bounded for all n. 2 • Example: for c t c 0 we obtained 0 1 t x x – Von Neumann Method (Introduction), also called Fourier Analysis Method/Stability • Hyperbolic PDEs and Stability – 2nd order wave equation and waves on a string • Characteristic finite-difference solution (review) c t • Stability of C – C (CDS in time/space, explicit): C 1 x • Example: Effective numerical wave numbers and dispersion 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 2 FINITE DIFFERENCES – Outline for Today • Fourier Analysis and Error Analysis – Differentiation, definition and smoothness of solution for ≠ order of spatial operators • Stability – Heuristic Method – Energy Method – Von Neumann Method (Introduction) : 1st order linear convection/wave eqn. • Hyperbolic PDEs and Stability – Example: 2nd order wave equation and waves on a string • Effective numerical wave numbers and dispersion – CFL condition: • Definition • Examples: 1st order linear convection/wave eqn., 2nd order wave eqn., other FD schemes – Von Neumann examples: 1st order linear convection/wave eqn. – Tables of schemes for 1st order linear convection/wave eqn. • Elliptic PDEs – FD schemes for 2D problems (Laplace, Poisson and Helmholtz eqns.) 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 3 References and Reading Assignments • Lapidus and Pinder, 1982: Numerical solutions of PDEs in Science and Engineering. Section 4.5 on “Stability”. • Chapter 3 on “Finite Difference Methods” of “J. H. Ferziger and M. Peric, Computational Methods for Fluid Dynamics. Springer, NY, 3rd edition, 2002” • Chapter 3 on “Finite Difference Approximations” of “H. Lomax, T. H. Pulliam, D.W. Zingg, Fundamentals of Computational Fluid Dynamics (Scientific Computation). Springer, 2003” • Chapter 29 and 30 on “Finite Difference: Elliptic and Parabolic equations” of “Chapra and Canale, Numerical Methods for Engineers, 2014/2010/2006.” 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 4 Von Neumann Stability • Widely used procedure • Assumes initial error can be represented as a Fourier Series and considers growth or decay of these errors • In theoretical sense, applies only to periodic BC problems and to linear problems – Superposition of Fourier modes can then be used • Again, use, f ( x, t ) k f k (t ) e i kx but for the error: ( x, t ) (t ) e i x • Being interested in error growth/decay, consider only one mode: ( t ) e i x e t e i x where is in general complex and function of : ( ) t • Strict Stability: The error will not to grow in time if e 1 – in other words, for t = nΔt, the condition for strict stability can be written: e t 1 or for e t , 1 von Neumann condition Norm of amplification factor ξ smaller or equal to1 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 5 Evaluation of the Stability of a FD Scheme Von Neumann Example • Consider again: c 0 t x • A possible FD formula (“upwind” scheme) (t = nΔt, x = jΔx) which can be rewritten: jn1 (1 ) jn jn1 with jn 1 jn t c jn jn1 x 0 n+1 t c t x j-1 j n x • Consider the Fourier error decomposition (one mode) and discretize it: ( x, t ) (t ) ei x e t ei x nj e nt ei jx • Insert it in the FD scheme, assuming the error mode satisfies the FD (strictly valid for linear eq. only): nj 1 (1 ) nj nj 1 e ( n1) t ei jx (1 ) e nt ei jx e nt ei ( j 1) x • Cancel the common term (which is nj e nt ei jx ) in (linear) eq. and obtain: e t (1 ) ei x 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 6 Evaluation of the Stability of a FD Scheme von Neumann Example • The magnitude of e t is then obtained by multiplying ξ with its complex conjugate: e i x e i x (1 ) e (1 ) e 1 2 (1 ) 1 2 ei x ei x x Since cos( x ) and 1 cos( x) 2sin 2 ( ) 2 2 x 2 1 2 (1 ) 1 cos( x) 1 4 (1 )sin 2 ( ) 2 2 i x i x • Thus, the strict von Neumann stability criterion gives 1 1 4 (1 )sin 2 ( Since sin 2 ( x 2 ) 0 x 2 ) 1 1 cos( x) 0 we obtain the same result as for the energy method: c t 1 (1 ) 0 0 1 x 2.29 Numerical Fluid Mechanics c t ( ) x Equivalent to the CFL condition PFJL Lecture 13, 7 Partial Differential Equations Hyperbolic PDE: B2 - 4 A C > 0 (from Lecture 10) Examples: 2 2u 2 u (1) c t 2 x 2 u u (2) c 0 t x u (3) (U ) u g t Wave equation, 2nd order Sommerfeld Wave/radiation equation, 1st order Unsteady (linearized) inviscid convection (Wave equation first order) (4) (U ) u g Steady (linearized) inviscid convection • Allows non-smooth solutions • Information travels along characteristics, e.g.: – For (3) above: t d xc U(x c (t )) dt – For (4), along streamlines: d xc U ds • Domain of dependence of u(x,T) = “characteristic path” • e.g., for (3), it is: xc(t) for 0< t < T 0 • Finite Differences, Finite Volumes and Finite Elements 2.29 • Upwind schemes Numerical Fluid Mechanics x, y PFJL Lecture 13, 8 Partial Differential Equations Hyperbolic PDE - Example (from Lecture 10) Waves on a String 2u ( x, t ) t 2 2u ( x , t ) c 0 x L, 0 t x 2 Initial Conditions 2 Boundary Conditions t uL,t) u0,t) Wave Solutions u(x,0), ut(x,0) x Typically Initial Value Problems in Time, Boundary Value Problems in Space Time-Marching Solutions: Implicit schemes generally stable Explicit sometimes stable under certain conditions 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 9 Partial Differential Equations Hyperbolic PDE - Example (from Lecture 10) Wave Equation 2u ( x, t ) t 2 2u ( x , t ) c x 2 2 0 x L, 0 t t Discretization: Finite Difference Representations (centered) uL,t) u0,t) j+1 j j-1 i-1 i i+1 u(x,0), ut(x,0) x Finite Difference Representations 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 10 Partial Differential Equations Hyperbolic PDE - Example (from Lecture 10) t Introduce Dimensionless Wave Speed Explicit Finite Difference Scheme uL,t) u0,t) j+1 j j-1 Stability Requirement: C i-1 i i+1 c t 1 Courant-Friedrichs-Lewy condition (CFL condition) x u(x,0), ut(x,0) x Physical wave speed must be smaller than the largest numerical wave speed, or, Time-step must be less than the time for the wave to travel to adjacent grid points: c 2.29 Numerical Fluid Mechanics x t or t x c PFJL Lecture 13, 11 Partial Differential Equations Hyperbolic PDE - Example Start of Integration: Euler and Higher Order Starters Given ICs: t 1st order Euler Starter But, second derivative in x at t = 0 is known from IC: From Wave Equation uL,t) u0,t) Higher order Taylor Expansion +k Higher Order Self Starter j=2 -2 i-1 i i+1 u(x,0)=f(x) , ut(x,0)=g(x) j=1 x General idea: use the PDE itself to get higher order integration 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 12 2 u ( x, t ) t 2 c2 2 u ( x, t ) x 2 Waves on a String 0 x L, 0 t Initial condition L=10; T=10; c=1.5; N=100; h=L/N; M=400; k=T/M; C=c*k/h Lf=0.5; x=[0:h:L]'; t=[0:k:T]; %fx=['exp(-0.5*(' num2str(L/2) '-x).^2/(' num2str(Lf) ').^2)']; %gx='0'; fx='exp(-0.5*(5-x).^2/0.5^2).*cos((x-5)*pi)'; gx='0'; %Zero first time derivative at t=0 f=inline(fx,'x'); g=inline(gx,'x'); waveeq.m n=length(x); m=length(t); u=zeros(n,m); % Second order starter u(2:n-1,1)=f(x(2:n-1)); for i=2:n-1 u(i,2) = (1-C^2)*u(i,1) + k*g(x(i)) +C^2*(u(i-1,1)+u(i+1,1))/2; end % CDS: Iteration in time (j) and space (i) for j=2:m-1 for i=2:n-1 u(i,j+1)=(2-2*C^2)*u(i,j) + C^2*(u(i+1,j)+u(i-1,j)) - u(i,j-1); end end 2.29 figure(1) plot(x,f(x)); a=title(['fx = ' fx]); set(a,'FontSize',16); figure(2) wavei(u',x,t); a=xlabel('x'); set(a,'Fontsize',14); a=ylabel('t'); set(a,'Fontsize',14); a=title('Waves on String'); set(a,'Fontsize',16); colormap; Numerical Fluid Mechanics PFJL Lecture 13, 13 Waves on a String, Longer simulation: Effects of dispersion and effective wavenumber/speed L=10; T=10; c=1.5; N=100; h=L/N; % Horizontal resolution (Dx) M=400; % Test: increase duration of simulation, to see effect of %dispersion and effective wavenumber/speed (due to 2nd order) %T=100;M=4000; k=T/M; % Time resolution (Dt) C=c*k/h % Try case C>1, e.g. decrease Dx or increase Dt Lf=0.5; waveeq.m x=[0:h:L]'; t=[0:k:T]; %fx=['exp(-0.5*(' num2str(L/2) '-x).^2/(' num2str(Lf) ').^2)']; %gx='0'; fx='exp(-0.5*(5-x).^2/0.5^2).*cos((x-5)*pi)'; gx='0'; f=inline(fx,'x'); g=inline(gx,'x'); n=length(x); m=length(t); u=zeros(n,m); %Second order starter u(2:n-1,1)=f(x(2:n-1)); for i=2:n-1 u(i,2) = (1-C^2)*u(i,1) + k*g(x(i)) +C^2*(u(i-1,1)+u(i+1,1))/2; end %CDS: Iteration in time (j) and space (i) for j=2:m-1 for i=2:n-1 u(i,j+1)=(2-2*C^2)*u(i,j) + C^2*(u(i+1,j)+u(i-1,j)) - u(i,j-1); end end 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 14 Wave Equation d’Alembert’s Solution 2 u ( x, t ) t 2 Wave Equation 2u ( x , t ) c x 2 2 t 0 x L, 0 t Solution Periodicity Properties F u0,t) G uL,t) F Proof u(x,0)=f(x) , ut(x,0)=g(x) 2.29 Numerical Fluid Mechanics PFJL Lecture 13, x 15 Hyperbolic PDE Method of Characteristics t Explicit Finite Difference Scheme First 2 Rows known uL,t) u0,t) G j+1 F j j-1 Characteristic Sampling Exact Discrete Solution 2.29 u(x,0)=f(x) , ut(x,0)=g(x) Numerical Fluid Mechanics PFJL Lecture 13, x 16 Hyperbolic PDE Method of Characteristics Let’s proof the following FD scheme is an exact Discrete Solution t D’Alembert’s Solution with C=1 uL,t) u0,t) G j+1 F j j-1 Proof u(x,0)=f(x) , ut(x,0)=g(x) 2.29 Numerical Fluid Mechanics PFJL Lecture 13, x 17 Courant-Fredrichs-Lewy Condition (1920’s) • Basic idea: the solution of the Finite-Difference (FD) equation can not be independent of the (past) information that determines the solution of the corresponding PDE • In other words: The “Numerical domain of dependence of FD scheme must include the mathematical domain of dependence of the corresponding PDE” time CFL NOT satisfied PDE dependence 2.29 time u ( x, t ) space Numerical “stencil” Numerical Fluid Mechanics CFL satisfied u ( x, t ) space PFJL Lecture 13, 18 CFL: Linear convection (Sommerfeld Eqn) Example Determine domain of dependence of PDE and of FD scheme • PDE: u( x, t ) u( x, t ) c 0 t x Characteristics: If dx c x c t and du 0 u cst dt Solution of the form: u( x, t ) F ( x ct ) • FD scheme. For our Upwind discretization, with t = nΔt, jn 1 jn t dt 1 dx c t Slope of Upwind scheme: x Slope of characteristic: => CFL condition: x 0 CFL NOT satisfied True solution is outside of numerical domain of influence x = jΔx : j j-1 n CFL satisfied True solution is within numerical domain of influence t 1 x c c t 1 x 2.29 c jn jn1 n+1 © Springer. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/fairuse. Source: Figure 2.1 from Durran, D. Numerical Methods for Wave Equations in Geophysical Fluid Dynamics. Springer, 1998. Numerical Fluid Mechanics PFJL Lecture 13, 19 CFL: 2nd order Wave equation Example Determine domain of dependence of PDE and of FD scheme • PDE, second order wave eqn example: 2u ( x, t ) t 2 2u ( x , t ) c x 2 2 0 x L, 0 t – As seen before: u( x, t ) F ( x ct ) G( x ct ) slope of characteristics: dt 1 dx c • FD scheme: discretize: t = nΔt, x = jΔx – CD scheme (CDS) in time and space (2nd order), explicit u nj 1 2u nj u nj 1 t 2 c 2 u nj 1 2u nj u nj 1 x 2 u nj 1 (2 2C 2 )u nj C 2 (u nj 1 u nj 1 ) u nj 1 where C = ct x – We obtain from the respective slopes: t c t 1 x 2.29 Full line case: CFL satisfied n Dotted lines case: c and Δt too big, Δx too small (CFL NOT satisfied) Numerical Fluid Mechanics j x PFJL Lecture 13, 20 CFL Condition: Some comments • CFL is only a necessary condition for stability • Other (sufficient) stability conditions are often more restrictive – For example: if u( x, t ) u( x, t ) c 0 t x is discretized as u( x, t ) u( x, t ) c 0 t CD,2nd order in t x CD,4th order in x – One obtains from the CFL: c t 2 x – While a Von Neumann analysis leads: c t 0.728 Five grid-points stencil: (-1,8,0,-8,1) / 12 See Taylor tables in previous lecture and eqn. sheet x • For equations that are not purely hyperbolic or that can change of type (e.g. as diffusion term increases), CFL condition can at times be violated locally for a short time, without leading to global instability further in time 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 21 von Neumann Examples • Forward in time (Euler), centered in space, Explicit jn1 jn t c jn1 jn1 2x 0 jn 1 jn C n ( j 1 jn1 ) 2 – Von Neumann: insert ( x, t ) (t ) ei x e t ei x nj e nt ei jx nj 1 nj C n C ( j 1 nj 1 ) et 1 ei x ei x 1 Ci sin( x ) 2 2 • Taking the norm: 2 e t 1 Ci sin( x) 1 Ci sin( x) 1 C 2 sin 2 ( x) 1 for C 0 ! 2 • Unconditionally Unstable • Implicit scheme (backward in time, centered in space) jn 1 jn jn11 jn11 C n 1 ( j 1 nj 11 ) et 1 et Ci sin( x ) 2 t 2x 2 1 1 2 e t 1 for C 0 ! 2 2 1 Ci sin( x ) 1 Ci sin( x ) 1 C sin ( x ) c 0 nj 1 nj • Unconditionally Stable 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 22 Stability of FD schemes for ut + b uy = 0 (t denoted x below) Table showing various finite difference forms removed due to copyright restrictions. Please see Table 6.1 in Lapidus, L., and G. Pinder. Numerical Solution of Partial Differential Equations in Science and Engineering. Wiley-Interscience, 1982. 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 23 Stability of FD schemes for ut + b uy = 0, Cont. Table showing various finite difference forms removed due to copyright restrictions. Please see Table 6.1 in Lapidus, L., and G. Pinder. Numerical Solution of Partial Differential Equations in Science and Engineering. Wiley-Interscience, 1982. 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 24 Partial Differential Equations Elliptic PDE (from Lecture 9) Laplace Operator Examples: Laplace Equation – Potential Flow ϕ Poisson Equation • Potential Flow with sources • Steady heat conduction in plate + source ϕ Helmholtz equation – Vibration of plates U u 2u Steady Convection-Diffusion • Smooth solutions (“diffusion effect”) • Very often, steady state problems • Domain of dependence of u is the full domain D(x,y) => “global” solutions • Finite differ./volumes/elements, boundary integral methods (Panel methods) 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 25 Partial Differential Equations Elliptic PDE - Example (from Lecture 9) y u(x,b) = f2(x) Equidistant Sampling Discretization ua,y)=g2(y) u0,y)=g1(y) j+1 j j-1 Finite Differences i-1 i i+1 u(x,0) = f1(x) x Dirichlet BC 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 26 Partial Differential Equations Elliptic PDE - Example (from Lecture 9) Discretized Laplace Equation y u(x,b) = f2(x) Finite Difference Scheme Boundary Conditions ua,y)=g2(y) u0,y)=g1(y) j+1 j j-1 i i i-1 i i+1 u(x,0) = f1(x) Global Solution Required 2.29 Numerical Fluid Mechanics x PFJL Lecture 13, 27 Elliptic PDEs Laplace Equation, Global Solvers u1,2 p7 p8 p9 p4 p5 p6 p1 u2,1 p2 p3 Dirichlet BC Leads to Ax = b, with A block-tridiagonal: A = tri { I , T , I } u5,2 u5,2 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 28 Ellipticic PDEs Neumann Boundary Conditions Neumann (Derivative) Boundary Condition given y Finite Difference Scheme u(x,b) = f2(x) Finite Difference Scheme at i = n Derivative BC: Finite Difference uxa,y) given u0,y)=g1(y) j Boundary Finite Difference Scheme at i = n u un 1, j 2x un 1, j un , j 1 un , j 1 4un , j 0 x n i-1 i i+1 u(x,0) = f1(x) x Leads to a factor 2 (a matrix 2 I in A) for points along boundary 2.29 Numerical Fluid Mechanics PFJL Lecture 13, 29 MIT OpenCourseWare http://ocw.mit.edu 2.29 Numerical Fluid Mechanics Spring 2015 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.