Course 1: Fluid Mechanics and Energy Conversion Discretization Methods in Fluid Dynamics Mayank Behl B-tech. 3rd Year Department of Chemical Engineering Indian Institute of Technology Delhi 3/8/2007 Supervisor: Dr. G.Biswas Indian Institute of Technology Kanpur Indo-German Winter Academy 1 OUTLINE 1. 2. 3. 4. 5. 6. 3/8/2007 Basics of PDE Mathematical Overview of fluid flow Need For Computational Methods Basic Discretization Methods in use Finite Difference Method Fluid Flow Modeling Indo-German Winter Academy 2 Partial differential equations (PDEs) are used to formulate and solve problems related to any phenomena that is distributed in space and time : Heat flow ∂φ ∂φ ∂ φ ∂ φ ∂ φ A +D +E + Fφ = G ( x, y ) +B +C ∂ x ∂ y ∂ x ∂ y ∂ x ∂ y Fluid flow propagation of sound electrodynamics, Elasticity……. 2 2 2 2 2 Most of the fluid and related transport phenomena can be modeled using PDEs 3/8/2007 Indo-German Winter Academy 3 Classification of PDEs ∂ 2φ ∂ 2φ ∂ 2φ ∂φ ∂φ +C 2 + D +E A 2 +B + Fφ = G ( x , y ) ∂x∂y ∂x ∂y ∂x ∂y If A,B,C,D… all constants or f(x,y) Linear PDE If any of A,B,C,D… contains Φ, Φ’ etc Non-linear PDE B2 – 4AC<0 Elliptic equation B.V.P. B2 – 4AC=0 Parabolic equation I.B.V.P; B2 – 4AC>0 3/8/2007 Hyperbolic equation ∂2φ ∂2φ + = 0 2 2 ∂x ∂y ∂φ ∂ 2φ =α ∂t ∂x 2 ∂ 2φ = β ∂t 2 Indo-German Winter Academy 2 ∂ 2φ ∂x 2 Irrotational flows steady Heat Transfer Unsteady viscous flows Vibration problems 4 Boundary conditions Dirchlet Boundary condition: Neumann Boundary condition: Mixed Boundary condition: φ = φ1 (r ) Given boundary temperature ∂φ = φ 2 (r ) ∂n Given boundary heat flux ∂φ aφ + b = φ3 (r ) ∂n Boundary heat flux dependent on boundary temperature 3/8/2007 Indo-German Winter Academy 5 Mathematical description of flows; Governing Equations of Fluid Dynamics Equation of continuity: a differential mass balance ∂ρu ∂ρv ∂ρw ∂ρ + + =− ∂x ∂y ∂z ∂t Δz ∂ρ In vector notation: ∇ ⋅ [ρ u] = − ∂t For constant density of the fluid: 3/8/2007 Δy (x,y,z) Δx ∇⋅u = 0 Indo-German Winter Academy 6 Governing Equations of Fluid Dynamics (2) ∂ Equation of motion: ρu + ∇ ⋅ ρuu = −∇p − ∇ ⋅ τ + ρg ∂t for incompressible, Newtonian Fluids , under laminar flow: ⎛∂ ⎞ ρ ⎜ u + u ⋅ ∇u ⎟ = −∇p + μ ∇ 2 u + ρg ⎝ ∂t ⎠ Navier-Stokes Equation 3/8/2007 Indo-German Winter Academy 7 The Navier-Stokes equations ∂u ∂u ∂u ∂u 1 ∂p μ ⎛ ∂2u ∂2u ∂2u ⎞ + ⎜⎜ 2 + 2 + 2 ⎟⎟ + gx +u +v + w = − ∂t ∂x ∂y ∂z ρ ∂x ρ ⎝ ∂x ∂y ∂z ⎠ 1 ∂p μ ⎛ ∂2v ∂2v ∂2v ⎞ ∂v ∂v ∂v ∂v + ⎜⎜ 2 + 2 + 2 ⎟⎟ + g y +u +v + w = − ρ ∂y ρ ⎝ ∂x ∂y ∂z ⎠ ∂z ∂x ∂y ∂t (Non linear PDEs) 1 ∂p μ ⎛ ∂2 w ∂2 w ∂2 w⎞ ∂w ∂w ∂w ∂w + ⎜⎜ 2 + 2 + 2 ⎟⎟ + gz +u +v + w = − ρ ∂z ρ ⎝ ∂x ∂y ∂z ⎠ ∂z ∂x ∂y ∂t Solution??? In general, Analytical Solution Not Possible 3/8/2007 Indo-German Winter Academy 8 Approaches to Fluid Dynamical Problems 1. Simplifications of the governing equations Æ AFD: Analytical Fluid Dynamic 2. Experiments on scale models Æ EFD: Experimental Fluid Dynamics 3. Discretize governing equations and solve by computers Æ CFD Computational Fluid Dynamics CFD is the simulation of fluids engineering system using modeling and numerical methods 3/8/2007 Indo-German Winter Academy 9 Need for Discretization methods ¾ In general, no analytical solution exist for non-linear models One of the way out is to approximate the solutions using Numerical methods ¾ Advent of digital computer and advanced improvements in computer resources ¾ Basis for CFD, which can provide unlimited details of results ¾Substantially more cost effective and more rapid than EFD ¾ability to study systems under hazardous conditions 3/8/2007 Indo-German Winter Academy 10 Various Discretization Techniques ¾ Finite Difference Method (focused in this lecture) ¾ Finite Volume Method ¾ Finite Element Method 3/8/2007 Indo-German Winter Academy 11 Discretization Methods Finite Difference Method (focused in this lecture) 1.Governing equations in differential formÆ domain with gridÆ replacing the partial derivatives by approximations in terms of node values of the functionsÆ one algebraic equation per grid nodeÆ linear algebraic equation system. 2. Applied to structured grids Finite Volume Method 1. Governing equations in integral formÆ solution domain is subdivided into a finite number of contiguous control volumesÆ conservation equation applied to each CV. 2. Computational node locates at the centroid of each CV. 3. Applied to any type of grids, especially complex geometries Finite Element Method 1. Solution domain is subdivided into a finite number OF ELEMENTS, the governing equation is solved for each element and then overall solution is obtained by “assembly”. 2. Equations are multiplied by a weight function before integrated over the entire domain. 3/8/2007 Indo-German Winter Academy 12 Basics aspects of Discretization methods ► Consistency A discretization method is said to be consistent if it can be shown that the difference between PDEs and its finite difference (FDE) vanishes as the mesh is refined. Truncation error (TE): Difference between the discretized equation and the exact one O(∆x); O(∆t) LimmeshÆ0 (TE) 0 O(∆t/∆x) ►Convergence: solution of the discretized equations tends to the exact solution of the differential equation as the grid spacing tends to zero. 3/8/2007 Indo-German Winter Academy 13 Basics aspects of Discretization methods Stability : Differencing Method should not magnify the errors that appear in the course off numerical solution process ε n+1 i n i ε ≤1 Conservation: 1. The numerical scheme should on both local and global basis respect the conservation laws. 2. Automatically satisfied for control volume method, either individual control volume or the whole domain. 3. Errors due to non-conservation are in most cases appreciable only on relatively coarse grids, but hard to estimate quantitatively 3/8/2007 Indo-German Winter Academy 14 Finite Difference Method Replacing the derivatives of governing PDE with finite, algebraic differences quotients. It involves following steps: Grid generation defining geometric domain Discretization of governing equation using Taylor series approximation. Solution of simultaneous algebraic equations. 3/8/2007 Indo-German Winter Academy φφi,ji,j φi-1,j φi-1,j φi+1,j φi+1,j Δy Δx Discrete grid points 15 Finite Difference Method:grids Grids Structured grid all nodes have the same number of elements around it only for simple domains Unstructured grid for all geometries irregular data structure 3/8/2007 Indo-German Winter Academy 16 Finite Difference, approximation of the first derivative ►Taylor Series Expansion: Any continuous differentiable function, in the vicinity of xi , can be expressed as a Taylor series: ⎛ ∂Φ ⎞ ( x − xi ) Φ ( x ) = Φ ( xi ) + ( x − xi )⎜ ⎟ + 2! ⎝ ∂x ⎠ i 2 ⎛ ∂ 2 Φ ⎞ ( x − xi ) ⎜⎜ 2 ⎟⎟ + 3! ⎝ ∂x ⎠ i ⎛ ∂Φ ⎞ Φi +1 − Φi xi +1 − xi − ⎜ ⎟ = x x − x 2 ∂ ⎝ ⎠i i +1 i 3 ⎛ ∂ 3Φ ⎞ ( x − xi ) ⎜⎜ 3 ⎟⎟ + ... + n! ⎝ ∂x ⎠ i ⎛ ∂ 2Φ ⎞ ( xi +1 − xi ) ⎜⎜ 2 ⎟⎟ − 6 ⎝ ∂x ⎠ i 2 n ⎛ ∂ nΦ ⎞ ⎜⎜ n ⎟⎟ + H ⎝ ∂x ⎠ i ⎛ ∂ 3Φ ⎞ ⎜⎜ 3 ⎟⎟ + H ⎝ ∂x ⎠ i ►Higher order derivatives are unknown and can be dropped when the distance between grid points is small 3/8/2007 Xi+1- Xi is small Indo-German Winter Academy 17 ►By writing Taylor series at different nodes, x i-1, x i+1, or both x i-1 and x i+1, we can have: order of accuracy ⎛ ∂Φ ⎞ Φ i +1 − Φ i ⎜ ⎟ ≈ xi +1 − xi ⎝ ∂x ⎠i Forward Difference Scheme-FDS O(∆x) ⎛ ∂Φ ⎞ Φ i − Φ i −1 ⎜ ⎟ ≈ ∂ x xi − xi −1 ⎝ ⎠i Backward Difference Scheme-BDS O(∆x) Φ i +1 − Φ i −1 ⎛ ∂Φ ⎞ ≈ ⎜ ⎟ xi +1 − xi −1 ⎝ ∂x ⎠ i Central Difference Scheme-CDS O(∆x)² 3/8/2007 Indo-German Winter Academy 18 Finite Difference, approximation of the second derivative Geometrically, the second derivative is the slope of the line tangent to the curve representing the first derivative. ⎛ ∂ 2Φ ⎞ ⎜⎜ 2 ⎟⎟ ⎝ ∂x ⎠i ⎛ ∂Φ ⎞ ⎛ ∂Φ ⎞ − ⎜ ⎟ ⎜ ⎟ ⎝ ∂x ⎠i +1 ⎝ ∂x ⎠i ≈ xi +1 − xi Estimate the outer derivative by FDS, and estimate the inner derivatives using BDS, we get ⎛ ∂ 2 Φ ⎞ Φ i +1 ( xi − xi −1 ) + Φ i −1 ( xi +1 − xi ) − Φ i ( xi +1 − xi −1 ) ⎜⎜ 2 ⎟⎟ ≈ (xi +1 − xi )2 (xi − xi −1 ) ⎝ ∂x ⎠i For equidistant spacing of the points: ⎛ ∂ 2Φ ⎞ Φ − 2Φ i + Φ i −1 ⎜⎜ 2 ⎟⎟ ≈ i +1 (Δx )2 ⎝ ∂x ⎠ i 3/8/2007 Higher-order approximations for the second derivative can be derived by including more data points, such as xi-2, and xi+2, even xi-3, and xi+3 Indo-German Winter Academy 19 Discretization using Explicit Method Consider unsteady viscous flow ∂Φ ∂ 2Φ =α ∂t ∂x 2 Φ in +1 − Φ in Φ n i +1 − 2Φ n i + Φ n i −1 =α Δt (Δx )2 The Only unkown :Φin+1 Explicit method , values at time n+1 computed from values at time n Advantages: solution algorithm is simple i.e. - direct computation without solving system of algebraic equation - few number of operations per time step Disadvantage: strong conditions on out time the step calculations for stability over Requires many time steps to carry 3/8/2007 a given time interval Indo-German Winter Academy 20 Implicit Method Crank-Nicholson Method ∂u ∂ 2u =α 2 ∂t ∂x uin+1 − uin u n i+1 + uin++11 − 2u n i − 2uin+1 + u n i−1 + uin−+11 =α 2 Δt 2(Δx) values at time n+1 computed using the unknown values at time n+1 Second order accurate in time and space O(∆t)2,O(∆x)2 to be solved simultaneously at all the grid points as a system of algebraic equations Unconditionally stable rearranging the above equation as follows…. 3/8/2007 Indo-German Winter Academy 21 3/8/2007 Indo-German Winter Academy 22 Ax = C This generates a Tridiagonal Matrix system which can be solved using Thomas algorithm. However, for higher dimensional flows, matrix system obtained are much more complex and require substantially more computer time 3/8/2007 Indo-German Winter Academy 23 Alternating Direction Implicit Method (ADI) for 2-D Flows ⎛ ∂ 2u ∂ 2u ⎞ ∂u = α ⎜⎜ 2 + 2 ⎟⎟ ∂t ∂y ⎠ ⎝ ∂x Each time increment is executed into two steps: First step uin,+j1/ 2 − uin, j Δt / 2 ⎛ uin+1, j − 2uin, j + uin−1, j uin,+j1+1/ 2 − 2uin,+j1/ 2 + uin,+j1−1/ 2 ⎞ ⎟ = α⎜ + 2 2 ⎜ ⎟ Δy (Δx) ⎝ ⎠ Second step uin, +j 1 − uin, +j 1/ 2 Δt / 2 3/8/2007 ⎛ uin++11, j − 2uin, +j 1 + uin−+11, j uin, +j +11/ 2 − 2uin, +j 1/ 2 + uin, +j −11/ 2 ⎞ ⎟ = α⎜ + 2 2 ⎜ ⎟ Δy (Δx ) ⎝ ⎠ Indo-German Winter Academy 24 First direction Y Second direction X ADI method results in Tridiagonal Equations (for 2-d flow systems) if it is applied along the dimension that is implicit. Thus on first step it is applied along Y axis and on second step along on X axis 3/8/2007 Indo-German Winter Academy 25 Implicit method Advantages: Stability can be maintained over larger time steps Disadvantages More computation time per time step, every time step requires solving a system of equations. Truncation error is often large , since larger time steps are employed. Overall, a more involved procedure 3/8/2007 Indo-German Winter Academy 26 Error and Stability analysis Numerical solution is influenced by following: Discretization errors or Truncation errors: Analytical Solution (A) – exact Finite Difference Solution (D) =A–D Computational Round-Off Error (e) ε=Numerical Solution (N) – exact Finite Difference Solution (D) N=D+ε By definition, N,D follow the Discretized Equation Thus, ε should also follow the equation: ε in +1 − ε in Δt 3/8/2007 =α ε n i +1 − 2ε n i + ε n i −1 (Δx )2 Indo-German Winter Academy 27 Errors and Stability Analysis (Cont.) Substituting the value of εm(x,t) in the F.D.E., 3/8/2007 Indo-German Winter Academy 28 Stability: Differencing Method should not magnify the errors that appear in the course off numerical solution process ε in +1 ≤1 n εi For stability: Von Neumann Stability Analysis : assuming error distribution follows Fourier series in space domain and exponential in time ε ( x, t ) = ε at ∑ ε ik m x m Putting an individual term in FD equation and using the above stability criteria α (Δt ) 1 ≤ 2 2 (Δx) 3/8/2007 Indo-German Winter Academy 29 Fluid Flow Modeling Using Finite Difference Method Nonlinear Fluid Flow equations involve: time dependent multiple variables Convective terms Diffusive terms Sample fluid flow equation : Burger’s Equation ⎛ ∂ 2ζ ∂u ∂ζ +u = ν ⎜⎜ 2 ∂t ∂x ⎝ ∂x Inviscid Burger’s Equation 3/8/2007 ⎞ ⎟⎟ ⎠ ∂ζ ∂u +u =0 ∂t ∂x Indo-German Winter Academy 30 Properties of Fluid Flow Equations Effect of Finite Difference method on properties of fluid flow equations Conservative Property: To maintain the integral conservation relation of continuum in finite difference representation. It depends on the form of continuum equation being discretized. ∂ ∂ζ Conservative form: = − (uζ ) ∂t Non-conservative form: 3/8/2007 ∂x ∂ζ ∂ζ = −u ∂t ∂x Indo-German Winter Academy 31 Integrating the CONSERVATIVE FORM ζ in +1 − ζ in ∫ Δt I2 ∑ζ i = I1 n +1 i Δx = α ∫ I2 Δx − ∑ ζ Δx i = I1 Δt (uζ ) n i +1 − (uζ ) n i −1 Δx 2Δx I2 n i = n n n n ( u ζ − u ζ ∑ i +1 i +1 i −1 i −1 ) i = I1 2 = (uζ ) I1 −1 / 2 − (uζ ) I 2 +1 / 2 I1 3/8/2007 Indo-German Winter Academy I2 32 Week Conservative Form in Fluid Flow Conservative form of advective part is of prime importance for fluid flow modeling. Navier Stokes in week conservative form: ∂u ∂u2 ∂uv ∂uw 1 ∂p μ ⎛ ∂2u ∂2u ∂2u ⎞ + =− + ⎜⎜ 2 + 2 + 2 ⎟⎟ + gx + + ∂t ∂x ∂y ∂z ρ ∂x ρ ⎝ ∂x ∂y ∂z ⎠ ∂v ∂uv ∂v2 ∂vw 1 ∂p μ ⎛ ∂2v ∂2v ∂2v ⎞ =− + ⎜⎜ 2 + 2 + 2 ⎟⎟ + g y + + + ∂t ∂x ∂y ∂z ρ ∂y ρ ⎝ ∂x ∂y ∂z ⎠ 1 ∂p μ ⎛ ∂2 w ∂2w ∂2 w⎞ ∂w ∂uw ∂vw ∂w2 + ⎜⎜ 2 + 2 + 2 ⎟⎟ + gz =− + + + ρ ∂z ρ ⎝ ∂x ∂y ∂z ⎠ ∂t ∂x ∂y ∂z 3/8/2007 Indo-German Winter Academy 33 Discretizing Fluid Flow equations using Upwind Scheme Upwind Scheme of discretization is necessary for convection dominated flows ∂ζ ∂ζ = −u ∂t Backward Differencing Scheme ζ in +1 − ζ in Δt ζ in +1 − ζ in 3/8/2007 for u>0 uζ n i − uζ n i −1 =− Δx Forward Differencing Scheme Δt ∂x for u<0 uζ n i +1 − uζ n i =− Δx Indo-German Winter Academy 34 Why use Upwind scheme Upwind Scheme of discretization is necessary for convection dominated flows for obtaining numerically stable results Central Difference Scheme applied to highly convective flows give unconditionally Unstable Results CDS: FDS: 3/8/2007 ζ in +1 − ζ in uζ n i +1 − uζ n i −1 =0 + 2Δxn Δtn n +1 n ζ i − ζ i uζ i +1 − uζ i = 0, u > 0 + Δt Δx Indo-German Winter Academy Violates Von Neumann Stability Criteria 35 Why use Upwind scheme For unsteady, convection-diffusion eqn. ζ CDS: −ζ uζ − uζ + Δt 2Δx n +1 i n n i i +1 n i −1 =ν ζ − 2ζ + ζ n n i +1 i Δx n i −1 2 ∂ζ ⎛ ⎛ u Δt ⎞ ⎞ + uζ = ⎜ν − ⎜ ⎟ ⎟ζ ∂t ⎝ 2 ⎠⎠ ⎝ 2 x xx ⎛ ⎛ u Δt ⎞ ⎞ ⎜ν − ⎜ ⎟⎟ ≥ 0 ⎝ 2 ⎠⎠ ⎝ 2 ⎛ 1 u Δt ⎞ uΔx ⎞ ν ⎜1 − ⎛⎜ ⎟≥0 ⎟ ⎝ 2 ⎝ Δx ⎠ ν ⎠ ν ⎛⎜1 − C * Re ⎞⎟ ≥ 0 ⎝ 1 2 Re ≤ 3/8/2007 ⎠ 2 C Indo-German Winter Academy ⎛ uΔx ⎞ Re = ⎜ ⎟ ⎝ ν ⎠ Δx CELL Reynold’s No. 36 Upwind Scheme and Transportive Property ∂ζ ∂ (u ζ = − ∂x ∂t using upwind scheme (u > 0) ⇒ ) ζ in+1 − ζ in Δt uζ n i − uζ n i −1 =− Δx let a perturbati on δ in ζ occurs at m th location • Then for at a downstream location (m + 1) ζ mn ++11 − ζ mn +1 0 − uδ uδ =+ At (m+1) location Δt Δx Δx which follows the rationale for the transport ive proprerty =− • At (m) location ζ mn +1 − ζ mn uδ − 0 uδ At (m) location =− Δt Δx Δx perturbati on being transport ed out of the region =− • At (m - 1) location ζ mn +−11 − ζ mn −1 0−0 =0 Δt Δx no perturbation carried upstream 3/8/2007 =− At (m-1) location Indo-German Winter Academy 37 Problems of Using Forward Time Central Space method (FTCS) At (m - 1) location ζ mn −+11 − ζ mn −1 Δt =− uδ − 0 uδ =− ≠0 2Δx 2Δx Which indicates that Transportive Property is violated Hence, only upwind method maintains unidirectional flow of information. 3/8/2007 Indo-German Winter Academy 38 Upwind Method and Artificial Viscosity(1/2) ⎛ ∂ 2ζ ∂u ∂ζ +u = ν ⎜⎜ 2 ∂t ∂x ⎝ ∂x ζ in +1 − ζ in Δt ζ in +1 − ζ in Δt 3/8/2007 ⎞ ⎟⎟ ⎠ uζ n i − uζ n i −1 =− Δx uζ n i +1 − uζ n i =− Δx Indo-German Winter Academy 39 Upwind Method and Artificial Viscosity (2/2) <1 For algorithm’s stability, artificial viscosity will necessarily be present Source of inaccuracy 3/8/2007 ve > 0 Indo-German Winter Academy 40 Upwind Differencing Method Advantages and Limitations Upwind effect necessary to maintain transportive property of flow equations Although space centered differences (CDS) are more accurate than upwind scheme (as indicated by Taylor Series expansion), the whole system is more realistically modeled using Upwind Differencing Scheme. Leads to Artificial viscosity or “false diffusion” which is a cause of inaccuracy. v >0 e Plausible Improvement: Higher order Upwind Method 3/8/2007 Indo-German Winter Academy 41 Second Upwind Differencing Scheme Let us consider where 3/8/2007 Indo-German Winter Academy 42 Considering momentum equation ζ ≡u Here a factor η is introduced which expresses a weighted average of central and upwind differencing 3/8/2007 Indo-German Winter Academy 43 Here 0<η<1 For η=0, above equation becomes centered in space For η=1, above equation follows full upwind Hence, η brings about an upwind bias in the difference quotient Accuracy of the differencing scheme can be adjusted using η value Second upwind formulation possesses both the conservative and transportive property 3/8/2007 Indo-German Winter Academy 44 Summary Finite Difference methods discretizes the differential form of governing equation using Taylor Series expansion. The partial derivatives of governing PDE are replaced with finite, algebraic differences quotients at the corresponding nodes. Leads to linear algebraic equation system, with one algebraic equation per grid node. Best Suited for Structured Grids only. Flow equation properties can be maintained using simple schemes like upwind differencing. Discretization methods provide more cost effective and more rapid approach for solving Fluid Flow problems as compared to experimental methods 3/8/2007 Indo-German Winter Academy 45 Summary Finite Difference Approach FD Approaches Can Be Divided Into Various Categories Depending Upon Type of PDE Being Solved: 1.Elliptic PDE: Algebraic System, Gauss Siedel 2.One-dimensional Parabolic PDE A) Explicit B) Implicit 3. Two-dimensional Parabolic PDE ADI Method 3/8/2007 Indo-German Winter Academy 46 Acknowledgement This lecture has been inspired by the study material provided by Prof. G.Biswas 3/8/2007 Indo-German Winter Academy 47 References Chapra and Canale, “Numerical Methods for Engineers”,4th Ed., Tata McGraw-Hill. Som and Biswas, “Introduction to Fluid Mechanics and Fluid Machines”, Tata McGraw-Hill Anderson.J; “Computational Fluid Dynamics” 3/8/2007 Indo-German Winter Academy 48 Thank you ! 3/8/2007 Indo-German Winter Academy 49