Computer Aided Design Lecture 5 Finite Difference

Dr./ Ahmed Nagib Elmekawy (1707-1783)

• In 1768, Leonhard Euler introduced the finite difference technique based on Taylor expansion.

2 Lewis Fry Richardson (1881-1953) • In 1922, Lewis Fry Richardson developed the first numerical weather prediction system. • Division of space into grid cells and the finite difference approximations of Bjerknes's "primitive differential equations.” • His own attempt to calculate weather for a single eight-hour period took six weeks and ended in failure. • His model's enormous calculation requirements led Richardson to propose a solution he called the “forecast-factory.” • The "factory" would have filled a vast stadium with 64,000 people. • Each one, armed with a mechanical calculator, would perform part of the calculation. • A leader in the center, using colored signal lights and telegraph communication, would coordinate the forecast. 3 1930s to 1950s

• Earliest numerical solution: for flow past a cylinder (1933). • A.Thom, ‘The Flow Past Circular Cylinders at Low Speeds’, Proc. Royal Society, A141, pp. 651-666, London, 1933 • Kawaguti obtained a solution for flow around a cylinder, in 1953 by using a mechanical desk calculator, working 20 hours per week for 18 months, citing: “a considerable amount of labour and endurance.” • M. Kawaguti, ‘Numerical Solution of the NS Equations for the Flow Around a Circular Cylinder at Reynolds Number 40’, Journal of Phy. Soc. Japan, vol. 8, pp. 747-757, 1953.

4 1960s and 1970s • During the 1960s the theoretical division at Los Alamos contributed many numerical methods that are still in use today, such as the following methods: • Particle-In-Cell (PIC). • Marker-and-Cell (MAC). • Vorticity-Streamfunction Methods. • Arbitrary Lagrangian-Eulerian (ALE). • k- turbulence model. • During the 1970s a group working under D. Brian Spalding, at Imperial College, London, develop: • Parabolic flow codes (GENMIX). • Vorticity-Streamfunction based codes. • The SIMPLE algorithm and the TEACH code. • The form of the k- equations that are used today. • Upwind differencing. • ‘Eddy break-up’ and ‘presumed pdf’ combustion models. • In 1980 Suhas V. Patankar publishes Numerical Heat Transfer and Fluid Flow, probably the most influential book on CFD to date.

5 1980s and 1990s • Previously, CFD was performed using academic, research and in-house codes. When one wanted to perform a CFD calculation, one had to write a program. • This is the period during which most commercial CFD codes originated that are available today: • (UK and US). • CFX (UK and Canada). • Fidap (US). • Polyflow (Belgium). • Phoenix (UK). • Star CD (UK). • Flow 3d (US). • ESI/CFDRC (US). • SCRYU (Japan). • and more, see www.cfdreview.com.

6 Navier-Stokes Equation Derivation

• Refer to • Ch. 3 and Appendix A of • Jiyuan Tu, Computational Fluid -A Practical Approach, Second Edition, 2013. • Ch. 2 • Wendt, Anderson, Computational Fluid Dynamics - An Introduction, 3rd edition 2009.

7 LAGRANGIAN AND EULERIAN DESCRIPTIONS Kinematics: The study of motion. Fluid kinematics: The study of how fluids flow and how to describe fluidmotion. There are two distinct ways to describe motion: Lagrangian and Eulerian Lagrangian description: To follow the path of individual objects. This method requires us to track the position and velocity of each individual fluid parcel (fluid particle) and take to be a parcel of fixedidentity.

With a small number of objects, such In the Lagrangian description, one as billiard balls on a pool table, must keep track of the position and individual objects can be tracked. velocity of individual particles. 4

8 • A more common method is Eulerian description of fluid motion. • In the Eulerian description of fluid flow, a finite volume called a flow domain or control volume is defined, through which fluid flows in and out. • Instead of tracking individual fluid particles, we define field variables, functions of space and time, within the control volume. • The field variable at a particular location at a particular time is the value of the variable for whichever fluid particle happens to occupy that location at that time. • For example, the pressure field is a scalar field variable. We define the velocity field as a vector field variable.

Collectively, these (and other) field variables define the flow field. The velocity field can be expanded in Cartesian coordinates as

9

9 • In the Eulerian description we don’t really care what happens to individual fluid particles; rather we are concerned with the pressure, velocity, acceleration, etc., of whichever fluid particle happens to be at the location of interest at the time of interest. • While there are many occasions in which the Lagrangian description is useful, the Eulerian description In the Eulerian description, one is often more convenient for fluid defines field variables, such as mechanics applications. the pressure field and the velocity field, at any location • Experimental measurements are and instant in time. generally more suited to the Eulerian description.

1 0

10 CONSERVATION OF MASS—THE CONTINUITY EQUATION

The net rate of change of mass withinthe control volume is equal to the rate at which mass flows into the control volume minus the rate at which mass flows out of the control volume.

To derive a differential conservation equation, we imagine shrinking a control volume to size.

1 1

11 12 13

Conservation of Mass: Alternative forms • Use on term

    V = u i + v j + w k         = i + j + k x y z Conservation of Mass: Cylindrical coordinates

• There are many problems which are simpler to solve if the equations are written in cylindrical-polar coordinates • Easiest way to convert from Cartesian is to use vector form and definition of divergence in cylindrical coordinates Conservation of Mass: Cylindrical coordinates Conservation of Mass: Special Cases • Steady compressible flow

(u) (v) (w) + + = 0 Cartesian x y z

Cylindrical Conservation of Mass: Special Cases • Incompressible flow

 = , and hence     V = u i + v j + w k         = i + j + k x y z u v w + + = 0 Cartesian x y z

Cylindrical Conservation of Mass • In general, continuity equation cannot be used by itself to solve for flow field, however it can be used to 1. Determine if a velocity field represents a flow. 2.ExampleFind missing velocity component For an incompressible flow u = x2 + y 2 + z 2 v = xy + yz + z w = ? Determine : w , required to satisfy the continuity equation. z 2 Solution : w = −3xz − + c(x, y) 2 Conservation of Momentum Types of forces: 1. Surface forces: include all forces acting on the boundaries of a medium though direct contact such as pressure, friction,…etc. 2. Body forces are developed without physical contact and distributed over the volume of the fluid such as gravitational and electromagnetic. • The force F acting on A may be resolved into two components, one normal and the other tangential to the area. 2 4

If the differential fluid element is a material element, it moves with the flow and ’s second law applies directly. Body Forces

Positive components of the stress tensor in Cartesian coordinates on the positive (right, top, and front) faces of an infinitesimal rectangular control volume. The blue dots indicate the center of each face. Positive components on the negative (left, bottom, and back) faces are in the opposite direction of those shown here.

25 Stresses (forces per unit area) Surface of Surface of constant x constant -x

Double subscript notation for stresses. • First subscript refers to the surface • Second subscript refers to the direction • Use  for normal stresses and  for tangential stresses 27 28 29 30 31 32 33 Complete Navier–Stokes equations

34 3 5

Newtonian versus Non-Newtonian Fluids

Rheology: The study of the deformation of flowing fluids. Newtonian fluids: Fluids for which the shear stress is linearly proportional to the shear strain rate. Non-Newtonian fluids: Fluids for which the shear stress is not linearly related to the shear strain rate. Viscoelastic: A fluid that returns (either fully or partially) to its original shape after the applied stress is released. Rheological behavior of fluids—shear stress as a function of shear strain rate. Some non-Newtonian fluids are called shear thinning fluids or pseudoplastic fluids, because the In some fluids a finite stress called the more the fluid is sheared, the less yield stress is required before the viscous it becomes. fluid begins to flow at all; such fluids Plastic fluids are those in whichthe are called Bingham plastic fluids. shear thinning effect is extreme. 36 3 7

Derivation of the Navier–Stokes Equation for Incompressible, Isothermal Flow

The incompressible flow approximation implies constant density, and the isothermal approximation implies constant viscosity. 38 Navier-Stokes Equations u u u u p  u 2   ( + u + v + w ) = g − + [(2 − .V )] t x y z x x x x 3 x-  v u  w u + [( + )]+ [( + )] (a) momentum y x y z x z v v v v p  v u ( + u + v + w ) = g y − + [( + )] t x y z y x x y y-  v 2    v w momentum + [(2 − .V )]+ [( + )] (b) y y 3 z z y w w w w p  w u ( + u + v + w ) = g z − + [( + )] t x y z z x x z z-  v w  w 2   momentum + [( + )]+ [(2 − .V )] (c) y z y z z 3 Navier-Stokes Equations • For incompressible fluids, constant µ: • Continuity equation: .V = 0  u 2    v u  w u [(2 − .V )]+ [( + )]+ [( + )] = x x 3 y x y z x z  u  v u  w u { [(2 )]+ [( + )]+ [( + )]} = x x y x y z x z  2u  2u  2u  2u  2v  2w ( + + ) + ( + + ) = x2 y 2 z 2 x2 xy xz  2u  2u  2u  u v w ( + + ) +  ( + + ) = x2 y 2 z 2 x x y z  2u  2u  2u ( + + ) = 2u x2 y 2 z 2 Navier-Stokes Equations • For incompressible flow with constant dynamic viscosity:

Du p  2u  2u  2u • x- momentum  = g − + ( + + ) (a) Dt x x x2 y 2 z 2

Dv p  2v  2v  2v • Y- momentum  = g − + ( + + ) (b) Dt y y x2 y 2 z 2

Dw p  2w  2w  2w • z-momentum  = g − + ( + + ) (c) Dt z z x2 y 2 z 2 • In vector form, the three equations are given by:  DV    = g − p + 2V Incompressible NSE Dt written in vector form Navier-Stokes Equations u u u u p  u 2   ( + u + v + w ) = g − + [(2 − .V )] t x y z x x x x 3 x-momentum  v u  w u + [( + )]+ [( + )] (a) y x y z x z v v v v p  v u ( + u + v + w ) = g y − + [( + )] t x y z y x x y y-momentum  v 2    v w + [(2 − .V )]+ [( + )] (b) y y 3 z z y w w w w p  w u ( + u + v + w ) = g z − + [( + )] t x y z z x x z z-momentum  v w  w 2   + [( + )]+ [(2 − .V )] (c) y z y z z 3 Navier-Stokes Equations • For incompressible fluids, constant µ: • Continuity equation: .V = 0  u 2    v u  w u [(2 − .V )]+ [( + )]+ [( + )] = x x 3 y x y z x z  u  v u  w u { [(2 )]+ [( + )]+ [( + )]} = x x y x y z x z  2u  2u  2u  2u  2v  2w ( + + ) + ( + + ) = x2 y 2 z 2 x2 xy xz  2u  2u  2u  u v w ( + + ) +  ( + + ) = x2 y 2 z 2 x x y z  2u  2u  2u ( + + ) = 2u x2 y 2 z 2 Navier-Stokes Equations • For incompressible flow with constant dynamic viscosity:

Du p  2u  2u  2u • x- momentum  = g − + ( + + ) (a) Dt x x x2 y 2 z 2

Dv p  2v  2v  2v • Y- momentum  = g − + ( + + ) (b) Dt y y x2 y 2 z 2

Dw p  2w  2w  2w • z-momentum  = g − + ( + + ) (c) Dt z z x2 y 2 z 2 • In vector form, the three equations are given by:  DV    = g − p + 2V Incompressible NSE Dt written in vector form Navier-Stokes Equation • The Navier-Stokes equations for incompressible flow in vector form:

Incompressible NSE written in vector form

• This results in a closed system of equations! • 4 equations (continuity and 3 momentum equations) • 4 unknowns (u, v, w, p) • In addition to vector form, incompressible N-S equation can be written in several other forms including: • Cartesian coordinates • Cylindrical coordinates • Tensor notation Euler Equations • For inviscid flow (µ = 0) the momentum equations are given by:

u u u u p • x- momentum ( + u + v + w ) = g − (a) t x y z x x

v v v v p • Y- momentum ( + u + v + w ) = g − (b) t x y z y y

w w w w p • z-momentum ( + u + v + w ) = g − (c) t x y z z z • In vector form, the three equations are given by:  DV   = g − p Euler equations Dt written in vector form Differential Analysis of Fluid Flow Problems

• Now that we have a set of governing partial differential equations, there are 2 problems we can solve • Calculate pressure (P) for a known velocity field • Calculate velocity (U, V, W) and pressure (P) for known geometry, boundary conditions (BC), and initial conditions (IC) • There are about 80 known exact solutions to the NSE • Solutions can be classified by type or geometry, for example: 1. Couette shear flows 2. Steady duct/pipe flows (Poisseulle flow) Exact Solutions of the NSE Procedure for solving continuity and NSE 1. Set up the problem and geometry, identifying all relevant dimensions and parameters 2. List all appropriate assumptions, approximations, simplifications, and boundary conditions 3. Simplify the differential equations as much as possible 4. Integrate the equations 5. Apply BCs to solve for constants of integration 6. Verify results • Boundary conditions are critical to exact, approximate, and computational solutions. ▪ BC’s used in analytical solutions are • No-slip boundary condition • Interface boundary condition Summary of Fluid Dynamic Equations in CFD Analysis

49 3D Compressible Navier–Stokes Equations C.E. in conservative form

Complete Navier–Stokes equations in conservation form

50 3D Compressible Navier–Stokes Equations C.E. in conservative form

By expanding  (u) (v) (w) + + + = 0 t x y z

51 3D Compressible Navier–Stokes Equations Momentum Equations in conservative form

52 3D Compressible Navier–Stokes Equations when expanded using Stokes’ hypothesis (λ= - 2/3 μ) gives

53 3D Incompressible Navier–Stokes Equations Continuity Equation

휕푢 휕푣 휕푤 + + = 0 휕푥 휕푦 휕푧

휕푢 휕푢 휕푢 휕푢 휕푝 휕2푢 휕2푢 휕2푢 휌 + 푢 + 푣 + 푤 = 휌푔 − + 휇 + + X-Momentum 휕푡 휕푥 휕푦 휕푧 푥 휕푥 휕푥2 휕푦2 휕푧2

휕푣 휕푣 휕푣 휕푣 휕푝 휕2푣 휕2푣 휕2푣 Y-Momentum 휌 + 푢 + 푣 + 푤 = 휌푔푦 − + 휇 + + 휕푡 휕푥 휕푦 휕푧 휕푦 휕푥2 휕푦2 휕푧2 휕푤 휕푤 휕푤 휕푤 휕푝 휕2푤 휕2푤 휕2푤 Z-Momentum 휌 + 푢 + 푣 + 푤 = 휌푔푧 − + 휇 2 + 2 + 2 휕푡 휕푥 휕푦 휕푧 휕푧 휕푥 휕푦 54 휕푧 2D Incompressible Navier–Stokes Equations Continuity Equation 휕푢 휕푣 + = 0 휕푥 휕푦 X-Momentum 휕푢 휕푢 휕푢 휕푝 휕2푢 휕2푢 휌 + 푢 + 푣 = 휌푔 − + 휇 + 휕푡 휕푥 휕푦 푥 휕푥 휕푥2 휕푦2 Y-Momentum 휕푣 휕푣 휕푣 휕푝 휕2푣 휕2푣 휌 + 푢 + 푣 = 휌푔 − + +휇 + 휕푡 휕푥 휕푦 푦 휕푦 휕푥2 휕푦2 55 Euler Equations Continuity Equation

휕푢 휕푣 휕푤 + + = 0 휕푥 휕푦 휕푧

휕푢 휕푢 휕푢 휕푢 휕푝 X-Momentum 휌 + 푢 + 푣 + 푤 = 휌푔 − 휕푡 휕푥 휕푦 휕푧 푥 휕푥 휕푣 휕푣 휕푣 휕푣 휕푝 휌 + 푢 + 푣 + 푤 = 휌푔 − Y-Momentum 휕푡 휕푥 휕푦 휕푧 푦 휕푦

휕푤 휕푤 휕푤 휕푤 휕푝 Z-Momentum 휌 + 푢 + 푣 + 푤 = 휌푔푧 − 휕푡 휕푥 휕푦 휕푧 휕푧 56 Poisson Equation 휕2푢 휕2푢 + = 푓 푥, 푦 휕푥2 휕푦2

휕2휓 휕2휓 or + = 푓 푥, 푦 휕푥2 휕푦2

Laplace Equation 휕2푢 휕2푢 + = 0 휕푥2 휕푦2

2 2 or 휕 휓 휕 휓 2 + 2 = 0 휕푥 휕푦 57 2D Viscous Burgers’ Equation (Convection)

휕푢 휕푢 휕푢 휕2푢 휕2푢 + 푢 + 푣 = 휐 + 휕푡 휕푥 휕푦 휕푥2 휕푦2

휕푣 휕푣 휕푣 휕2푣 휕2푣 + 푢 + 푣 = 휐 + 휕푡 휕푥 휕푦 휕푥2 휕푦2 2D Heat Equation (Diffusion)

휕푢 휕2푢 휕2푢 = 휐 + 휕푡 휕푥2 휕푦2

58 2D Inviscid Burgers’ Equation (Convection)

휕푢 휕푢 휕푢 + 푢 + 푣 = 0 휕푡 휕푥 휕푦 휕푣 휕푣 휕푣 + 푢 + 푣 = 0 휕푡 휕푥 휕푦 2D Wave Equation (Linear Convection)

휕푢 휕푢 휕푢 + 푐 + 푐 = 0 휕푡 휕푥 휕푦

59 1D Viscous Burgers’ Equation 휕푢 휕푢 휕2푢 + 푢 = 휐 휕푡 휕푥 휕푥2 1D Heat Equation (Diffusion) 휕푢 휕2푢 = 휐 휕푡 휕푥2 1D Inviscid Burgers’ Equation (Convection) 휕푢 휕푢 + 푢 = 0 휕푡 휕푥 1D Wave Equation (Linear Convection) 휕푢 휕푢 + 푐 = 0 휕푡 휕푥 60 Basics of Finite Difference Formulations

Refer to Ch. 2 Hoffmann, A., Chiang, S., Computational Fluid Dynamics for Engineers, Vol. I, 4th ed., Engineering Education System, 2000. Ch. 3, 4 and 5 Pletcher, R. H., Tannehill, J. C., Anderson, D., Computational and Heat Tranfer, 3rd ed., CRC Press, 2011. Ch. 5 Wendt, Anderson, Computational Fluid Dynamics - An Introduction, 3rd edition 2009. Discretization methods (Finite Difference)

• First step in obtaining a numerical solution is to discretize the geometric domain→ to define a numerical grid • Each node has one unknown and needs one algebraic equation, which is a relation between the variable value at that node and those at some of the neighboring nodes. • The approach is to replace each term of the PDE at the particular node by a finite- difference approximation. • Numbers of equations and unknowns must be equal Discretization (Grid Generation) • Numerical solutions can give answers at only discrete points in the domain, called grid points.

• If the PDEs are totally replaced by a system of algebraic equations which can be solved for the values of the flow-field variables at the discrete points only, in this sense, the original PDEs have been discretized. • Moreover, this method of discretization is called the method of finite differences. Taylor’s series expansion • A partial replaced with a suitable algebraic is called finite difference. • Most finite-difference representations of are based on Taylor’s series expansion. • Taylor’s series expansion: Consider a of x, namely, f(x), with all derivatives defined at x. Then, the value of f at a location x+Δx can be estimated from a expanded about point x, that is, f 1  2 f 1 3 f 1  n f f (x + x) = f (x) + x + (x)2 + (x)3 +...+ (x)n +... x 2! x 2 3! x3 n! x n f 1  2 f 1 3 f 1  n f f (x ) = f (x ) + (x − x ) + (x − x )2 + (x − x )3 +...+ (x − x )n +... i+1 i x i+1 i 2! x 2 i+1 i 3! x3 i+1 i n! x n i+1 i

• In general, to obtain more accuracy, additional higher-order terms must be included. Taylor’s series expansion f (x ) f (x )  f (x ) + f (x )(x − x ) + i (x − x )2 + i+1 i i i+1 i 2! i+1 i f (n) (x ) + i (x − x )n + R n! i+1 i n

(xi+1-xi)= Δx step size (define first) f (x ) f (x )  f (x ) + f (x )x + i x 2 + i+1 i i 2! (n)  n f (xi ) n (x) n + x + Rn = f (xi ) +  f (xi ) n! 1 n!

• The term, Rn, accounts for all terms from (n+1) to infinity, Truncation error. Taylor’s series expansion

푥푖+1 − 푥푖 = ∆푥 = ℎ Truncation Error

• Need to determine f n+1(x), to do this you need f'(x).

• If we knew f(x), there wouldn’t be any need to perform the Taylor series expansion.

• However, R=O(Δxn+1), (n+1)th order, the order of truncation error is Δxn+1.

• O(Δx), halving the step size will halve the error.

• O(Δx2), halving the step size will quarter the error. Forward, Backward and Central Differences:

(1) Forward difference:

Neglecting higher-order terms, we can get f (x − x )2  2 f (x − x )3 3 f f (x ) = f (x ) + ( ) (x − x ) + i+1 i ( ) + i+1 i ( ) i+1 i x i i+1 i 2! x 2 i 3! x3 i (x − x )n  n f +...+ i+1 i ( ) +... n! x n i f Solve for ( ) , we get x i Finite Differences: Recall the Definition of a derivative:

휕푦 푦 − 푦 = lim 2 1 휕푥 ∆푥→0 푥2 − 푥1 휕푦 푦 − 푦 = lim 2 1 휕푥 ∆푥→0 ∆푥 Finite Differences: Recall the Definition of a derivative: 휕푢 푢 푥 +∆푥 −푢 푥 = lim 푖 푖 휕푥 ∆푥 푥푖 ∆푥→0

푥 Forward, Backward and Central Differences:

(1) Backward difference:

푥 Forward, Backward and Central Differences:

(2) Forward difference:

푥 Forward, Backward and Central Differences:

(3) Central difference:

푥 74 (1) Forward difference:

2 2 3 3 f f (xi+1) − f (xi ) (xi+1 − xi )  f (xi+1 − xi )  f ( )i = − ( 2 )i − ( 3 )i x (xi+1 − xi ) 2!(xi+1 − xi ) x 3!(xi+1 − xi ) x n n (xi+1 − xi )  f −...− ( n )i −... n!(xi+1 − xi ) x f f − f x  2 f x 2 3 f x n−1  n f ( ) = i+1 i − ( ) − ( ) −...− ( ) −... x i x 2 x 2 i 6 x3 i n! x n i f − f = i+1 i + O(x) (a) x • This equation is known as the first forward difference approximation of  f of order (Δx). x • It is obvious that as the step size decreases, the error term is reduced and therefore the accuracy of the approximation is increased. (2) Backward difference Taylor series expansion: Neglecting higher-order terms, we can get

f (x − x )2  2 f (x − x )3 3 f f (x ) = f (x ) − ( ) (x − x ) + i i−1 ( ) − i i−1 ( ) i−1 i x i i i−1 2! x 2 i 3! x3 i (x − x )n  n f   (x)n   n f +...+ (−1)n i i−1 ( ) +... = f (x) + (−1)n n i    n n! x n=1  n!  x f Solve for ( ) , we get x i

2 2 3 f f (xi ) − f (xi−1) (xi − xi−1)  f (xi − xi−1 )  f ( )i = + ( 2 )i − ( 3 )i x (xi − xi−1) 2 x 6 x (x − x )n−1  n f f − f +...+ (−1)n i i−1 ( ) +.. = i i−1 + O(x) (b) n! x n i x (2) Backward difference

• which represents the of the function at B using the values of the function at points A and B, as shown in Figure 2-2. • Equation (2-6) is the first backward difference approximation

f of of order (Δx). x Figure 2-2. Illustration of grid points used in Equation (2-6). (3) Central difference: f f − f x 2 f x2 3 f x n−1 n f ( ) = i+1 i − ( ) − ( ) −...− ( ) −... x i x 2 x 2 i 6 x3 i n! xn i f − f = i+1 i + O(x) (a) x f f − f x  2 f x 2 3 f (x)n−1  n f ( ) = i i−1 + ( ) − ( ) +...+ (−1)n ( ) +.. x i x 2 x 2 i 6 x3 i n! x n i f − f = i i−1 + O(x) (b) x • Adind (a)+(b) and neglecting higher-order terms, we canf get f − f + f − f x 2 3 f 2( ) = i+1 i i i−1 − + HOT x i x 3 x3 f f − f ( ) = i+1 i−1 + O(x)2 (c) x i 2x (3) Central difference:

• which represents the slope of the function f at point B using the values of the function at pointsf A and C, as shown in Figure 2-3. x • This representation of is known as the central difference approximation of order (Δx)2• Truncation error: The higher-order term neglecting in Eqs. (a), (b), (c) constitute the truncation error.

f f − f Forward: ( ) = i+1 i + O(x) x i x

f f − f Backward: ( ) = i i−1 + O(x) x i x

f fi+1 − fi−1 2 Central: ( )i = + O(x) x 2x Second derivatives: f (x)2  2 f (x)3 3 f (x)n  n f f = f + ( ) x + ( ) + ( ) +...+ ( ) +... i+1 i x i 2! x 2 i 3! x3 i n! x n i f (x)2  2 f (x)3 3 f (x)n  n f f = f − ( ) (x) + ( ) − ( ) +...+ (−1)n ( ) +... i−1 i x i 2! x 2 i 3! x3 i n! x n i

if  x i =  x i + 1 =  x , then (a)+(b) becomes

* Central difference:  2 f f + f = 2 f + (x)2 ( ) + O(x)4 + HOT i+1 i−1 i x 2 i  2 f f − 2 f + f ( ) = i+1 i i−1 + O(x)2 x 2 i (x)2 Second derivatives: f (x)2  2 f (x)3 3 f (x)n  n f f = f + ( ) x + ( ) + ( ) +...+ ( ) +... i+1 i x i 2! x 2 i 3! x3 i n! x n i f (2x)2  2 f (2x)3 3 f (2x)n  n f f = f + ( )2x + ( ) + ( ) +...+ ( ) +... i+2 i x 2! x 2 i 3! x3 n! x n

If  x i =  x i + 1 =  x , then (b)-2(a) becomes (2x)2  2 f (x)2  2 f (2x)3 3 f (x)3 3 f f − 2 f = f − 2 f + ( ) − 2 ( ) + ( ) − 2 ( ) + HOT i+2 i+1 i i 2! x 2 i 2! x 2 i 3! x3 3! x3

 2 f f − 2 f + f = x 2 ( ) + O(x)3 i+2 i+1 i x 2 i * Forward difference:  2 f f − 2 f + f ( ) = i+2 i+1 i + O(x) x 2 i (x)2 Second derivatives: f (x)2 2 f (x)3 3 f (x)n n f f = f − ( ) (x) + ( ) − ( ) +...+ (−1)n ( ) +... i−1 i x i 2! x2 i 3! x3 i n! xn i f (2x)2  2 f (2x)3 3 f (2x)n  n f f = f − ( )2x + ( ) − ( ) +...+ ( ) +... i−2 i x 2! x 2 i 3! x3 n! x n

If  x i =  x i + 1 =  x , then (b)-2(a) becomes (2x)2  2 f (x)2  2 f (2x)3 3 f (x)3 3 f f − 2 f = f − 2 f + ( ) − 2 ( ) − ( ) + 2 ( ) + HOT i−2 i−1 i i 2! x 2 i 2! x 2 i 3! x3 3! x3

 2 f f − 2 f + f = x 2 ( ) + O(x)3 i−2 i−1 i x 2 i * Backward difference:  2 f f − 2 f + f ( ) = i i−1 i−2 + O(x) x 2 i (x)2 1-D Wave equation

휕푢 휕푢 + 푐 = 0 휕푡 휕푥 By applying Forward in time and central in space (FTCS)

푢푛+1 − 푢푛 푢푛 − 2푢푛 + 푢푛 푖 푖 + 푐 푖+1 푖 푖−1 = 0 ∆푡 ∆푥 By rearranging

∆푡 푢푛+1 = 푢푛 + 푐 × 푢푛 − 2푢푛 + 푢푛 푖 푖 ∆푥 푖+1 푖 푖−1

84 1-D Wave equation

∆푡 푢푛+1 = 푢푛 + 푐 × 푢푛 − 2푢푛 + 푢푛 푖 푖 ∆푥 푖+1 푖 푖−1 Assume initial conditions of

푢 = 2 @ 0.5 ≤ 푥 ≤ 1 푢 = 1 @ 푒푣푒푟푦푤ℎ푒푟푒 푒푙푠푒

Assume Boundary conditions 푢 = 1 @ 푥 = 0, 2

85 ∆푡 푢푛+1 = 푢푛 + 푐 × 푢푛 − 2푢푛 + 푢푛 1-D Wave equation 푖 푖 ∆푥 푖+1 푖 푖−1

I.C. 푢 = 2 @ 0.5 ≤ 푥 ≤ 1 푢 = 1 @ 푒푣푒푟푦푤ℎ푒푟푒 푒푙푠푒

B.C. 푢 = 1 @ 푥 = 0, 2

86 1-D Inviscid Burgers’ equation

휕푢 휕푢 + 푢 = 0 휕푡 휕푥 By applying Forward in time and central in space (FTCS)

푢푛+1 − 푢푛 푢푛 − 2푢푛 + 푢푛 푖 푖 + 푢푛 푖+1 푖 푖−1 = 0 ∆푡 푖 ∆푥

By rearranging ∆푡 푢푛+1 = 푢푛 + 푐 × 푢푛 × 푢푛 − 2푢푛 + 푢푛 푖 푖 ∆푥 푖 푖+1 푖 푖−1

87 1-D Inviscid Burgers’ equation

∆푡 푢푛+1 = 푢푛 + 푐 × 푢푛 × 푢푛 − 2푢푛 + 푢푛 푖 푖 ∆푥 푖 푖+1 푖 푖−1 Assume initial condition of

푢 = 2 @ 0.5 ≤ 푥 ≤ 1 푢 = 1 @ 푒푣푒푟푦푤ℎ푒푟푒 푒푙푠푒

Assume Boundary condition 푢 = 1 @ 푥 = 0, 2

88 1-D Inviscid Burgers’ equation ∆푡 푢푛+1 = 푢푛 + 푐 × 푢푛 × 푢푛 − 2푢푛 + 푢푛 푖 푖 ∆푥 푖 푖+1 푖 푖−1 I.C. 푢 = 2 @ 0.5 ≤ 푥 ≤ 1 푢 = 1 @ 푒푣푒푟푦푤ℎ푒푟푒 푒푙푠푒

B.C. 푢 = 1 @ 푥 = 0, 2

89 1-D Diffusion equation

휕푢 휕2푢 = 휐 휕푡 휕푦2 By applying Forward in time and central in space (FTCS)

푢푛+1 − 푢푛 푢푛 − 2푢푛 + 푢푛 푖 푖 = 휐 푖+1 푖 푖−1 ∆푡 ∆푥 2 By rearranging

∆푡 푢푛+1 = 푢푛 + 휐 × 푢푛 − 2푢푛 + 푢푛 푖 푖 ∆푥 2 푖+1 푖 푖−1

90 1-D Diffusion equation 휕푢 휕2푢 = 휐 휕푡 휕푦2 By applying Forward in time and central in space (FTCS)

푢푛+1 − 푢푛 푢푛 − 2푢푛 + 푢푛 푖 푖 = 휐 푖+1 푖 푖−1 ∆푡 ∆푥 2 By rearranging ∆푡 푢푛+1 = 푢푛 + 휐 × 푢푛 − 2푢푛 + 푢푛 푖 푖 ∆푥 2 푖+1 푖 푖−1

푛+1 푛 푛 푛 푛 푢푖 = 푢푖 + 푑 × 푢푖+1 − 2푢푖 + 푢푖−1 91 Application to FTCS-Explicit scheme for the parabolic model equation

92 Application to FTCS-Explicit scheme for the parabolic model equation

93 Programming Assignment Consider a fluid bounded by two parallel plates extended to infinity such that no end effects are encountered. The walls and the fluid are initially at rest. Now, the lower wall is suddenly accelerated in the x-direction. The Navier-Stokes equations for this problem may be expressed as: 휕푢 휕2푢 = 휐 휕푡 휕푦2 It is required to compute 푢 푡, 푦 .

94 Programming Assignment 1 Assume initial conditions of 푢 = 푢표 @ 푦 = 0 푢 = 0 @ 0 < 푦 ≤ ℎ where h is the distance between the two plates and equals 40 mm. Assume Boundary conditions 푢 = 푢표 @ 푦 = 0 푢 = 0 @ 푦 = ℎ 2 Take 휐=0.000217 m /s, 푢표 =40 m/s, max time of 1.08 sec. Assume 40 nodes in y direction 95 Programming Assignment 1 Apply FTCS scheme. Calculate and plot the velocity distribution by using Matlab by using the following time steps: ❑ dt = 0.002 sec ❑ dt = 0.00232 sec ❑ dt = 0.003 sec

Bonus points will be given to the student who • Creates a video of the development of the flow speed with

time. 96