School of Mechanical Aerospace and Civil EngineeringExplicit vs. Implicit Treatments We consider the generic time-dependent problem ∂φ = f (t, φ(t)) ∂t Unsteady Problems Integrating with respect to time, over one time step, gives Introduction to CFD Finite volume methods Pressure-velocity coupling Solving sets of linear equations Unsteady problems Turbulence and other physical modelling Body-fitted coordinate systems t+∆t Z φ(n+1) = φ(n) + Z t f (t, φ(t)) dt (3) f (t, φ(t)) dt (4) t or Contents: Finite difference methods t+∆t ∂φ dt = ∂t Z T. J. Craft George Begg Building, C41 Numerical solution of equations (2) t+∆t t where the superscript (n) denotes a quantity evaluated at time t, and (n + 1) at time t + ∆t. Reading: J. Ferziger, M. Peric, Computational Methods for Fluid Dynamics H.K. Versteeg, W. Malalasekara, An Introduction to Computational Fluid Dynamics: The Finite Volume Method S.V. Patankar, Numerical Heat Transfer and Fluid Flow Notes: http://cfd.mace.manchester.ac.uk/tmcfd - People - T. Craft - Online Teaching Material The problem is then how to approximate the integral on the right hand side. If we approximate the integral using the value of f at the initial time, t, then we obtain φ(n+1) = φ(n) + f (t, φ(n) )∆t (5) This is a fully explicit method. Once we have values at time step n, equation (5) can be applied in a simple explicit fashion to obtain the value of φ at time step n + 1. - p. 3 Overview If the integral is approximated using the value of the integrand at the final time, t + ∆t, then we have φ(n+1) = φ(n) + f (t + ∆t, φ(n+1) )∆t (6) In considering the discretization of fluid flow problems so far we have considered only steady-state situations. This has meant we have only discretized spatial derivatives. This is a fully implicit method. It cannot be solved in a simple pointwise fashion, since values of φ(n+1) appear on both the left and right hand sides. In a general case it will thus often require an iterative solution procedure to obtain φ(n+1) . In this lecture we consider how to handle unsteady flow problems, and any additional complications this might introduce. The Navier-Stokes momentum equations (for incompressible flow) now become „ « ∂(Ui Uj ) ∂Ui 1 ∂P ∂ ∂Ui ν + =− + ∂t ∂xj ρ ∂xi ∂xj ∂xj Another alternative is to approximate the integral using a weighted average of the initial and final values of f . (1) When considering how to discretize the time derivatives, we need to recognise a major difference between space and time coordinates. In the case of an equally weighted average the integral is evaluated using the trapezium rule: φ(n+1) = φ(n) + Most real fluid flow problems are (at least to some extent) elliptic in nature – meaning that any forcing introduced has an effect in all directions. However, the time dependence is purely parabolic – any forcing affects only the future, never the past. ” ∆t “ f (t, φ(n) ) + f (t + ∆t, φ(n+1) 2 (7) Again, this is an implicit scheme, and will typically require an iterative procedure to obtain φ(n+1) . To reflect this, solution methods tend to advance in time in a ‘marching’ manner. Initial values are provided at time t = 0 and the solution method proceeds by advancing in time in a step-by-step manner. - p. 2 - p. 4 time dependent problem. xi x In a fully explicit scheme. 6 . However. φ(n+1/2) ) + − 2 2! „ ∂2φ ∂t2 « 3 + O((∆t) ) (11) t+∆t/2 . φ(n+1/2) ) + 2 2! „ ∂2φ ∂t2 « ∆t (∆t)2 /4 f (t + ∆t/2. Zone of Influence Hence we have φ(n+1) = φ(n) + ∆tf (t.p. consider a 1-D spatial. a time step of 2∆t were taken. The flow conditions at some point xi influence an increasingly wide region of the flow as time progresses.p. The fully implicit scheme of equation (6) can also be shown to be first order accurate. . x t Zone of dependence Hence the total error associated with use of the scheme is proportional to ∆t. 3 + O((∆t) ) (12) t+∆t/2 An examination of the stability of different schemes will be covered in the following sections when applying them to unsteady convection/diffusion problems. φ(n) ) + O((∆t)2 ) (8) From this we can see that equation (5) shows a truncation error proportional to (∆t)2 over a single time step. φ(t)) + O((∆t)2 ) « Another important issue with temporal discretization schemes is that of stability. however. since the value of φ at time t(n) is determined purely from its values at time t(n−1) . the number of time steps that must be performed for a given simulated time is proportional to 1/∆t. 7 t For example. Combining these expansions gives φ(n+1) − φ(n) = ∆t f (t + ∆t/2. 8 . t. so over a fixed time integration the scheme is second order. φ(n+1/2) ) + O((∆t)3 ) (13) The truncation error over a single time step is thus proportional to (∆t)3 . dominated by convective effects. we can identify a region of the flow that has an influence on conditions at the point xi at any time t. 5 The trapezium approximation of equation (7) can be shown to be second order accurate.p.p. if a 3-point spatial stencil was employed. and the scheme is referred to as first order accurate. not all the relevant flow information at time t − 2∆t would be included in the discretization. since „ « „ « ∆t ∂φ (∆t)2 /4 ∂ 2 φ φ(t + ∆t) = φ(t + ∆t/2) + + + O((∆t)3 ) (9) 2 ∂t t+∆t/2 2! ∂t2 t+∆t/2 « „ « „ (∆t)2 /4 ∂ 2 φ ∆t ∂φ + + O((∆t)3 ) (10) φ(t) = φ(t + ∆t/2) − 2 ∂t t+∆t/2 2! ∂t2 t+∆t/2 Hence (n+1) φ (n) φ (n+1/2) =φ (n+1/2) =φ ∆t (∆t)2 /4 + f (t + ∆t/2.∆t t-2 ∆t x If. so the scheme could be expected to be stable. and the scheme would likely be unstable. Explicit schemes in particular are prone to instabilities if too large a time step is employed. Hence stability often imposes a limit on the time step that can be used in a calculation. then for the problem shown in the figure this would cover the zone of dependence at time t − ∆t. .Accuracy of Temporal Schemes Stability of Temporal Schemes By expanding φ as a Taylor series expansion about time t we can examine the accuracy of the fully explicit scheme: φ(t + ∆t) = φ(t) + ∆t „ ∂φ ∂t « t (∆t)2 + 2! „ ∂2φ ∂t2 = φ(t) + ∆t f (t. we need to ensure that the spatial stencil does contain all the relevant flow information at time t(n−1) . 3 + O((∆t) ) t t To see why this should be. xi Equally. The difference between solutions for φ at successive time steps (using some appropriate norm) is then ” X “ (n+1) (n) ξk ak || ||φ(n+1) − φ(n) || = || − ξk (20) k . If one assumes there are no forcing terms. Hence to analyse stability we consider φ as being represented by a combination of Fourier modes of the form X (n) φj = ξkn exp(ikj∆x) (22) k where i = (17) √ −1.p. 12 .Time Stepping for Steady Problems Stability Analysis As indicated earlier. The stability of the scheme is therefore particularly important in these cases. If we further assume that the eigenvectors of A form a basis.p. 11 Using the discretized equation to relate this difference to that at the previous timestep leads to X X (n) (n−1) (n) (n−1) ||φ(n+1) −φ(n) || = ||A(φ(n) −φ(n−1) )|| = ||A (ξk −ξk )ak || = || αk (ξk −ξk )ak || k k (21) where αk is the eigenvalue corresponding to eigenvector ak Hence the difference between the solutions at successive timesteps gets smaller (corresponding to a stable solution) if all the eigenvalues of the matrix A are less than unity. on a uniform grid. In some cases the solution to a steady flow problem is obtained by introducing a time derivative term and solving the unsteady problem. the stability of a temporal discretization is often an important issue. φ(t)) (15) ∂t ∂xj ∂xj ∂xj If we consider the 1-D problem with constant velocity U and diffusivity Γ then the differential equation becomes ∂φ ∂φ ∂2φ (16) = −U +Γ 2 ∂t ∂x ∂x Using central differences to approximate spatial derivatives then leads to 13 1 0 2 0 (n) (n) (n) (n) (n) φi+1 − 2φi + φi−1 φi+1 − φi−1 (n+1) (n) A5 A+ Γ@ φi = φi + ∆t 4−U @ 2∆x (∆x)2 (n+1) Given initial conditions the calculation can then proceed.p. then the discretized equation for φ can be written in the form (18) φ(n+1) = A φ(n) In a solution procedure such as the above. 9 The Explicit Euler Scheme For simplicity we consider the time dependent convection/diffusion problem for some variable φ: „ « ∂ ∂φ ∂ ∂φ + (Uj φ) = Γ ∂t ∂xj ∂xj ∂xj (14) The explicit Euler method is obtained by moving all terms except ∂φ/∂t to the right hand side and applying the fully explicit formulation examined earlier: „ « ∂ ∂ ∂φ ∂φ =− (Uj φ) + Γ ≡ f (t.p. rather than by accuracy considerations. . the index j denotes the spatial position and superscript (n) the time level. the eigenvectors can be expressed as combinations of Fourier modes with sines and cosines. A method that is frequently used to explore stability issues is the Von-Neumann stability analysis. evaluating φi pointwise manner. In such cases the accuracy of the time discretization is not crucial (since the time derivative will be zero at the end of the calculation). since the time-step size that can be applied may well be limited by this. For the simplified problem being considered. marching the solution to a steady state. then φ can be written in terms of these: X (n) φ(n) = ξk ak (19) k where ak are the eigenvectors of A and (n) ξk the associated coefficients. and one typically wants to take rather large time steps. in a simple . particularly with explicit schemes. the time-stepping is effectively playing a similar role to under-relaxation. Broadly. We then examine whether the (complex) coefficient ξk associated with the Fourier mode k is less than or greater than unity in magnitude. which was considered earlier in the context of solving steady-state problems in a segregated fashion. 10 . we interpret a stable scheme to be one that leads to a bounded solution if the original differential equation would have done so. Two limiting cases can be considered: The second is that the cell Peclet number (met in earlier lectures) should be less than 2. the time step has to be reduced by a factor of four. we have ξ2 = 1 + „ U ∆t sin(k∆x) ∆x «2 (27) so |ξ| is always greater than unity and the scheme is unconditionally unstable! In the absence of convection we have „ «2 2Γ∆t [cos(k∆x) − 1] ξ2 = 1 + (∆x)2 or (28) ξ = „ Γ∆t 1−4 (∆x)2 «2 (n+1) φi = „ 1− 2Γ∆t U ∆t − (∆x)2 ∆x « (n) φi + Γ∆t (n) φ + (∆x)2 i+1 „ Γ∆t U ∆t + (∆x)2 ∆x « (n) φi−1 (32) To ensure the coefficients remain positive. When there is no diffusion. 13 . . If the grid spacing is halved. when we have 2 If we retain the explicit Euler time discretization.Substituting the form ξ n exp(ikj∆x) into the discretized equation (17) leads to « „ » „ «– exp(ik∆x) − 2 + exp(−ik∆x) exp(ik∆x) − exp(−ik∆x) + Γ∆t ξ n+1 = ξ n 1 − U ∆t 2∆x (∆x)2 (23) or Another way of examining stability and boundedness is to write the discretized equation as « « « „ „ „ 2Γ∆t U ∆t U ∆t Γ∆t Γ∆t (n+1) (n) (n) (n) φ φ φi−1 = 1− + − + + (30) φi i i+1 (∆x)2 (∆x)2 2∆x (∆x)2 2∆x Suppose that φ represents some scalar quantity that cannot physically be negative. 15 Upwinding Convection Terms In the absence of diffusion. and the scheme is conditionally stable. . The restriction Γ∆t/(∆x)2 < 1/2 can impose a rather serious constraint on the time step for practical calculations. Γ∆t U ∆t [exp(ik∆x) − exp(−ik∆x)] + [exp(ik∆x) + exp(−ik∆x) − 2] ξ =1− 2∆x (∆x)2 2Γ∆t U ∆t sin(k∆x) + =1−i [cos(k∆x) − 1] ∆x (∆x)2 (24) (25) (n) (n) (n) If any of the coefficients associated with φi . we now need The maximum value of ξ 2 thus occurs when cos(k∆x) = −1. but now use the first order upwind scheme to discretize the convective terms.p. 14 . Note that this is the condition found earlier to be sufficient for the centred convection scheme to be bounded. for example. When there is no convection.p. the discretized equation for the above unsteady convection/diffusion problem (assuming U > 0) becomes 1 0 1 0 (n) (n) (n) (n) (n) φi − φi−1 φi+1 − 2φi + φi−1 (n+1) (n) A A + Γ∆t @ (31) = φi − U ∆t @ φi ∆x (∆x)2 (29) 1− 2Γ∆t U ∆t − >0 (∆x)2 ∆x or ∆t < 1 (2Γ)/(∆x)2 + U/∆x For the case of negligible diffusion this limit becomes Thus |ξ| < 1 provided that Γ∆t/(∆x)2 < 1/2. and represents the ratio of the time step to the time required for a disturbance to be convected across the cell.p. U ∆t <1 ∆x or ∆t < ∆x U The quantity U ∆t/∆x is known as the Courant Number. To ensure all coefficients are positive requires The magnitude of ξ (or rather ξ 2 ) is thus given by ξ2 = „ 2Γ∆t 1+ [cos(k∆x) − 1] (∆x)2 «2 + „ U ∆t sin(k∆x) ∆x «2 1− 2Γ∆t >0 (∆x)2 or Γ∆t < 1/2 (∆x)2 and Γ∆t U ∆t − >0 (∆x)2 2∆x U ∆x <2 Γ or (26) The first of these conditions is the same as found by the Von-Neumann analysis. φi+1 or φi−1 take a negative value then it is possible that (n+1) φi could become negative. leading to an unbounded solution.p. 16 . the solution is unconditionally stable (although as in the steady case. .18. 20 . for a purely convective flow.3 < x < 0. An advantage of the scheme is that if marching to a steady state solution.p. Boundary conditions are ∂T /∂x = 0 at x = 0 and x = 1. One drawback of the scheme is that one has to solve a large coupled system of equations at each time step (using one of the matrix solution techniques examined in an earlier lecture).7 T = 0 otherwise Since there will typically be a large number of time steps.p.p.0. the use of central differencing for convection can lead to oscillations if the cell Peclet number is too large). leading to the same limit on ∆t. employing an efficient solver is crucial.36. This is a particular problem in flows where the time scales are fairly large. It is worth noting that the exact stability conditions obtained above relate to the rather simplified problem currently considered.2. Stability is achieved provided the Courant number is less than unity. 0. or where time stepping is used to march to a steady state solution (and an accurate resolution of the transient stage is not required). if a time accurate solution is required. the introduction of upwinding for the convective flux leads to conditional stability of the explicit Euler method. The Implicit Euler Scheme One of the drawbacks of explicit schemes is that the restriction on the time step. very large time steps can be used in a stable fashion. on rearranging: „ « « « „ „ (n) φ 1 2Γ Γ Γ U U (n+1) (n+1) (n+1) φi φi+1 − φi−1 = i + + + − − 2 2 2 ∆t (∆x) 2∆x (∆x) 2∆x (∆x) ∆t (34) . 0. with a central difference approximation for convective fluxes.p. although the limits found above are generally good guidelines. 0. If the convection and diffusion terms (and other sources) are evaluated at the new time level n + 1. 17 Unsteady Convection/Diffusion Example Note that this results in a similar tri-diagonal system to that met in the equivalent steady problem. we arrive at the implicit Euler method. The 1-D unsteady convection/diffusion problem ∂T ∂2T ∂T +U =Γ 2 ∂t ∂x ∂x Von-Neumann analysis can again be used to confirm the stability of the scheme.The Von-Neumann analysis can also be applied to this case. Thus. 19 Since the introduction of the time discretization does not alter the sign of the coefficients. In real fluid flow problems the precise criteria may be different.54 and 0. . to ensure stability. on the interval 0 < x < 1 with U = 0. 18 . Note that this condition implies that ∆t should be sufficiently small so that a fluid element cannot travel more than one grid cell length in each time step. can often result in very small time steps having to be used. Computed profiles of T shown at t = 0. For the unsteady convection/diffusion problem. the discretized equation now becomes 0 1 1 0 (n+1) (n+1) (n+1) (n+1) (n+1) φi+1 − 2φi + φi−1 φi+1 − φi−1 (n+1) (n) @ A A @ + Γ∆t (33) = φi − U ∆t φi 2∆x (∆x)2 or. However. Central spatial differencing. Initial conditions are ( 1 for 0. but with an additional (positive) term in the diagonal element and the additional (n) source term φi /∆t. accuracy considerations may still lead to a rather small time step because of the first order truncation error.2 and Γ = 0.72. Both time schemes applied with central differencing for spatial derivatives.p. the second order accuracy means that larger time steps can usually be taken than with the first order schemes. . with central differencing for convective terms. 24 . As seen earlier. 23 Other Time Discretization Schemes The schemes presented above are not the only ones available in many CFD codes. n and n − 1. although in practice it can produce oscillations or become unstable for rather large time steps. . However.p. in most general purpose finite volume schemes the underlying approximations are second order. However.p. They do also illustrate many of the considerations regarding accuracy and stability that should be borne in mind when choosing which scheme to use for a particular problem. for some applications or purposes it may be appropriate. For the unsteady convection/diffusion problem. Higher order schemes can be constructed by employing a larger time stencil – for example by evaluating terms at time levels n + 1. we now get 0 1 0 1 (n+1) (n+1) (n+1) (n+1) (n+1) + φi−1 U ∆t @ φi+1 − φi−1 A Γ∆t @ φi+1 − 2φi (n+1) (n) A = φi − + φi 2 2∆x 2 (∆x)2 0 1 0 1 (n) (n) (n) (n) (n) U ∆t @ φi+1 − φi−1 A Γ∆t @ φi+1 − 2φi + φi−1 A + − (35) 2 2∆x 2 (∆x)2 or „ 1 Γ + ∆t (∆x)2 Crank-Nicolson „ « « U U Γ Γ (n+1) (n+1) − φ φi−1 + + i+1 4∆x 2(∆x)2 4∆x 2(∆x)2 „ „ „ « « « U 1 U Γ Γ Γ (n) (n) (n) = φi + − φi+1 + φi−1 − + + 2 2 2 ∆t (∆x) 4∆x 2(∆x) 4∆x 2(∆x) « (n+1) φi − „ Implicit Euler − (36) The scheme is again implicit. so requires a matrix system solution at each time step. However. . although they are some of the more widely-used ones.The Crank-Nicolson Scheme Unsteady Convection/Diffusion Example When considering generic temporal discretizations we noted that approximating the time integral between t and t + ∆t via the trapezium rule resulted in a second order scheme. so there may be little point in employing a temporal discretization of higher order than this. 21 Von-Neumann analysis shows the scheme to be unconditionally stable. 22 . Such a scheme applied to partial differential equations is known as the Crank-Nicolson Scheme. Considering the same problem as in the earlier example. the requirement to store more time levels does increase the overall storage (and hence memory) requirements. whilst retaining acceptable temporal accuracy.p. In some cases additional stability can be gained from including influences from more than two time levels.