Simple MATLAB Code for solving Navier-Stokes Equation (Finite Difference Method, Explicit Scheme)

July 16, 2017 | Author: Muhammad_Noman_Hasan | Category: Navier–Stokes Equations, Differential Equations, Mathematical Objects, Civil Engineering, Equations
Share Embed Donate


Short Description

This is a simple MATLAB Code for solving Navier-Stokes Equation with Finite Difference Method using explicit scheme....

Description

Solving Navier – Stokes Equation: Finite Difference Method (FDM) The Navier – Stokes Equation In physics, the Navier – Stokes equations, named after Claude-Louis Navier and George Gabriel Stokes, describe the motion of fluid substances. These equations arise from applying Newton's second law to fluid motion, together with the assumption that the fluid stress is the sum of a diffusing viscous term (proportional to the gradient of velocity) and a pressure term - hence describing viscous flow. The general form of Navier – Stokes equation in vector expression is     v       v.v   p  T  f  t        Here, T is the deviatoric stress tensor, f is the body force. Replacing T with  2 v , the equation yields     v       v.v   p   2 v  f  t   

Continuity Equation u u  0 x y Momentum Equation (x - dir)   2u  2u  u u u 1 p u v     2  2  ;  = kinematic viscosity t x y y   x  x Momentum Equation (y - dir)   2v  2v  v v v 1 p u v     2  2  t x y  y  x y  The Pressure – Poisson equation (Poisson equation for pressure) is a derived equation to relate the pressure with momentum equation. It has been derived using the continuity equation as constrain for momentum equation. Adding the partial derivative of x – momentum w.r.t. x and the partial derivative of y – momentum w.r.t. y and then applying the continuity equation yields the Pressure – Poisson equation. Hence, Pressure Equation (Pressure – Poisson Equation) 2    u v   u  2 2 p 2 p u v  v              2    x 2 y 2 y x  y    t  x y   x  Derivation of Pressure Equation Let’s take the partial derivative of x – momentum w.r.t. x   u  u u  2u v u  2u    2u  2u  1 2 p u 2  v    2  2    t  x  x x x x y xy x  x y   x 2 Email: [email protected] Source: Computational Fluid Dynamics, ME 702 (Online Material) - Dr. Lorena A Barba, Professor, Department of Mechanical Engineering, Boston University Acknowledgement: Boston University – for sharing the course content at BU You Tube Channel (http://www.youtube.com/user/bu)

Solving Navier – Stokes Equation: Finite Difference Method (FDM) Now take the partial derivative of y – momentum w.r.t. y   v  u v  2 v v v  2v    2v  2v  1 2 p u  v 2     2  2    t  y  y x xy y y y y  x y   y 2 Let’s add last two equations. Now, the L.H.S. of the added equation, 2

 2u  2v   u v   u  u v  2u  2 v v u  v   u u v  v              x 2 xy x y  y  xy y 2 t  x y   x  y x 2

2

  u v   u  u v   u v  v u  v    u v        u      v    t  x y   x  y x x  x y  x y  y  y  x y  2

Using the continuity equation and keeping the continuity part associated with time derivative,   u v   u  u v  v  L.H.S         2   t  x y   x  y x  y  2

2

Now, for the R.H.S     2u  2u     2 v  2 v   1  2 p 2 p    2  2      2  2    2  2    x y   x  x y  y  x y   

  3u  3u  3v  3v  1  2 p 2 p             x 2 y 2   x3 xy 2 x 2 y y 3 



  3u  3v   3u 1  2 p 2 p   3v             x 2 y 2   x3 x 2 y xy 2 y 3 

  2  u v   2  u v   1  2 p 2 p     2  2     2     2    y    x  x  x y  y  x y  

Again, using the continuity equation, 1  2 p 2 p  R.H.S    2  2  y    x Now, combining both hand sides, 2

1   2 p  2 p    u v   u  u v  v    2  2       2   y  t  x y   x  y x  y    x 2    u v   u  2 2 p 2 p u v  v    2  2           2    x y y x  y    t  x y   x  2

This is similar to the Poisson equation  2 p   f .

Email: [email protected] Source: Computational Fluid Dynamics, ME 702 (Online Material) - Dr. Lorena A Barba, Professor, Department of Mechanical Engineering, Boston University Acknowledgement: Boston University – for sharing the course content at BU You Tube Channel (http://www.youtube.com/user/bu)

Solving Navier – Stokes Equation: Finite Difference Method (FDM) Finite Difference Discretization of Navier – Stokes Equation Let’s discretize the Navier – Stokes equation taking 1st order forward difference for time discretization, 1st  order backward difference for 1st order space derivative ( v ), 2nd order central difference for 2nd order  space derivative (  2 v ) and 1st order central difference for pressure discretization, Discretized Navier – Stokes equation in x – direction n n  uin1, j  2uijn  uin1, j uin, j 1  2uijn  uin, j 1  uijn 1  uijn u n  uin1, j u n  uin, j 1 1 pi 1, j  pi 1, j n ij n ij  uij  vij        2x t x y x 2 y 2   Discretized Navier – Stokes equation in y – direction n n  vin1, j  2uijn  vin1, j vin, j 1  2vijn  vin, j 1  vijn 1  vijn v n  vin1, j v n  vin, j 1 1 pi 1, j  pi 1, j n ij n ij  uij  vij       2y  t x y x 2 y 2   For discretized pressure equation, let’s take 2nd order central difference for pressure and 1st order central difference in space. Hence, the discretized pressure equation is – 2  1  un  un vin, j 1  vin, j 1   uin1, j  uin1, j     i 1, j i 1, j          n n n n n n  2 t x y x 2 2        pi 1, j  2 pij  pi 1, j pi , j 1  2 pij  pi , j 1           2 x 2 y 2   uin, j 1  uin, j 1   vin1, j  vin1, j   vin, j 1  vin, j 1    2         2y 2y 2x        By transposing,

 t  1  t   t  uijn 1  uijn  uijn  uijn  uin1, j     vijn  uijn  uin, j 1      pin1, j  pin1, j     x   2x   y     t    t     uin1, j  2uijn  uin1, j   2    uin, j 1  2uijn  uin, j 1   2    x   y     t  1  t   t  vijn 1  vijn  uijn  vijn  vin1, j     vijn  vijn  vin, j 1      pin, j 1  pin, j 1     x   y    2y    t    t     vin1, j  2vijn  vin1, j   2    vin, j 1  2vijn  vin, j 1   2    x   y      pin1, j  pin1, j  y 2    pin, j 1  pin, j 1  x 2      uin1, j  uin1, j vin, j 1  vin, j 1  x 2 y 2 n     pij    2 2 2x 2y 2  x 2  y 2     2  x  y  t     x 2 y 2   uin1, j  uin1, j     2  x 2  y 2    2x  

2

  uin, j 1  uin, j 1   vin1, j  vin1, j   2    2y 2x   

  vin, j 1  vin, j 1      2y   

2

   

Email: [email protected] Source: Computational Fluid Dynamics, ME 702 (Online Material) - Dr. Lorena A Barba, Professor, Department of Mechanical Engineering, Boston University Acknowledgement: Boston University – for sharing the course content at BU You Tube Channel (http://www.youtube.com/user/bu)

Solving Navier – Stokes Equation: Finite Difference Method (FDM) MATLAB Code for Solution – Explicit Scheme Case 1: Cavity Flow Let’s consider a square domain for the cavity flow problem with arm length of 2 units. For all the walls, except the top wall, no slip condition has been considered. The top wall has been considered as free stream. Initial Condition:

y

u  0; v  0; p  0 ; for all (x,y)

ux,2 = 1 vx,2 = 0

px,2 = 0

(0, 2)

(2, 2)

Boundary Condition: Bottom Wall : u x ,0  0 , vx ,0  0 , Left Wall

: u0, y  0 , v0, y  0 ,

p y

y 0

p x

x 0

0

: u0,2  0 , v0,2  0 ,

Top Wall

: u x ,2  1 , vx ,2

x

0

u0,y = 0

u2,y = 0

v0,y = 0

v2,y = 0

0

p 0 x x  2  0 , px ,2  0

Right Wall

p

p x

0

ux,0 = 0 vx,0 = 0 (0, 0)

p y

x 0

(2, 0)

Case 1: MATLAB Code for Cavity Flow %%%%%%%%%%%%%%%%%%%%%%

Start of the code

%%%%%%%%%%%%%%%%%%%%%%

clc clear all close all %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % Initial Condition % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

nx ny nt nit

= = = =

21; 21; 10; 10;

vis rho Lx Ly

= = = =

0.1; 1.0; 2; 2;

% % % % % % % % %

number of nodes in x-direction number of nodes in y-direction number of time steps number of artificial time steps ..... ...... for pressure Viscosity Density Length in x-direction Length in y-direction

Email: [email protected] Source: Computational Fluid Dynamics, ME 702 (Online Material) - Dr. Lorena A Barba, Professor, Department of Mechanical Engineering, Boston University Acknowledgement: Boston University – for sharing the course content at BU You Tube Channel (http://www.youtube.com/user/bu)

Solving Navier – Stokes Equation: Finite Difference Method (FDM) dx dy dt x y u v p un vn pn

= = = = = = = = = = =

Lx/(nx-1); Ly/(ny-1); 0.01; 0:dx:Lx; 0:dy:Ly; zeros(ny,nx); zeros(ny,nx); zeros(ny,nx); zeros(ny,nx); zeros(ny,nx); zeros(ny,nx);

b

= zeros(ny,nx);

% % % % % % % % % % %

grid spacing in x-direction grid spacing in y-direction time step size node x-ordinates node y-ordinates nodal velocity x-component nodal velocity y-component nodal pressure time marched velocity x-direction time marched velocity x-direction temporary pressure for calculation

% nodal source term value from pressure

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % Boundary Condition % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% [y,x] = meshgrid(y,x); u(ny,:) = 1; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % Calculation % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% uT(:,:,1) = u(:,:); vT(:,:,1) = v(:,:); pT(:,:,1) = p(:,:); for it = 1:nt+1 for i = 2:nx-1 for j = 2:ny-1

% loop over time % this i,j loop is for calculating the ... % ... body force from pressure equation

b(j,i) = rho*(((((u(j,i+1)-u(j,i-1))/(2*dx))+... ((v(j+1,i)-v(j-1,i))/(2*dy)))*(1/dt))+((u(j,i+1)... - u(j,i-1))/(2*dx)).^2+(2*((u(j,i+1)... -u(j,i-1))/(2*dy))*((v(j+1,i)-v(j-1,i))/(2*dx)))... +((v(j+1,i)-v(j-1,i))/(2*dy)).^2); end end for iit = 1:nit+1 pn = p; for i = 2:nx-1 for j = 2:ny-1 p(j,i) = ((p(j,i+1)+p(j,i-1))*(dy^2)... +(p(j+1,i)+p(j-1,i))*(dx^2))/(2*(dx^2+dy^2))... +(b(j,i)*dx^2*dy^2)/(2*(dx^2+dy^2)); end end p(:,1) = p(:,2); p(:,nx) = p(:,nx-1); p(1,:) = p(2,:); p(ny,:) = p(ny-1,:); end Email: [email protected] Source: Computational Fluid Dynamics, ME 702 (Online Material) - Dr. Lorena A Barba, Professor, Department of Mechanical Engineering, Boston University Acknowledgement: Boston University – for sharing the course content at BU You Tube Channel (http://www.youtube.com/user/bu)

Solving Navier – Stokes Equation: Finite Difference Method (FDM) un = u;

vn = v; % assigning velocity values to nth-time values % to calculate (n+1)th-time values

for i = 2:nx-1 % this i,j loop is for calculating velocity for j = 2:ny-1 u(j,i) = un(j,i)-un(j,i)*(un(j,i)-un(j,i-1))*(dt/dx)... -vn(j,i)*(un(j,i)-un(j-1,i))*(dt/dy)... -(1/rho)*(p(j,i+1)-p(j,i-1))*(dt/(2*dx))... +(vis/rho)*((un(j,i+1)-(2*un(j,i))+un(j,i-1))*... (dt/dx^2)+(un(j+1,i)-(2*un(j,i))+un(j-1,i))*(dt/dy^2)); v(j,i) = vn(j,i)-un(j,i)*(vn(j,i)-vn(j,i-1))*(dt/dx)... -vn(j,i)*(vn(j,i)-vn(j-1,i))*(dt/dy)... -(1/rho)*(p(j+1,i)-p(j-1,i))*(dt/(2*dy))... +(vis/rho)*((vn(j,i+1)-(2*vn(j,i))+vn(j,i-1))*... (dt/dx^2)+(vn(j+1,i)-(2*vn(j,i))+vn(j-1,i))*(dt/dy^2)); end end %%%%%%%%%%%%%%%%%%%%%%

Surface Plotting

%%%%%%%%%%%%%%%%%%%%%%

figure(1) surf(x,y,u') title('Surface Plot: Velocity Component, u'); xlabel('x - ordinate'); ylabel('y - ordinate'); zlabel('Velocity component, u'); figure(2) surf(x,y,v') title('Surface Plot: Velocity Component, v'); xlabel('x - ordinate'); ylabel('y - ordinate'); zlabel('Velocity component, v'); figure(3) surf(x,y,sqrt(u.^2+v.^2)') title('Surface Plot: Velocity Field, U'); xlabel('x - ordinate'); ylabel('y - ordinate'); zlabel('Velocity component, v'); figure(4) surf(x,y,p') title('Surface Plot: Pressure, P'); xlabel('x - ordinate'); ylabel('y - ordinate'); zlabel('Pressure, p'); %%%%%%%%%%%%%%%%%%%%%%

Contour Plotting

%%%%%%%%%%%%%%%%%%%%%%

figure(5) contourf(x,y,u',10) title('Contour: Velocity Component, u'); xlabel('x - ordinate'); ylabel('y - ordinate'); Email: [email protected] Source: Computational Fluid Dynamics, ME 702 (Online Material) - Dr. Lorena A Barba, Professor, Department of Mechanical Engineering, Boston University Acknowledgement: Boston University – for sharing the course content at BU You Tube Channel (http://www.youtube.com/user/bu)

Solving Navier – Stokes Equation: Finite Difference Method (FDM) figure(6) contourf(x,y,v',10) title('Contour: Velocity Component, v'); xlabel('x - ordinate'); ylabel('y - ordinate'); figure(7) contourf(x,y,sqrt(u.^2+v.^2)') title('Surface Plot: Velocity Field, U'); xlabel('x - ordinate'); ylabel('y - ordinate'); zlabel('Velocity component, v'); figure(8) contourf(x,y,p',10) title('Contour: Pressure, P'); xlabel('x - ordinate'); ylabel('y - ordinate');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% u(:,1) = 0; u(:,nx) = 0; u(1,:) = 0; u(ny,:) = 1; v(:,1) = 0; v(:,nx) = 0; v(1,:) = 0; v(ny,:) = 0; end

%%%%%%%%%%%%%%%%%%%%%%%

End of the code

Fig.1: Surface plot for velocity x – component

%%%%%%%%%%%%%%%%%%%%%%%

Fig.2: Contour plot for velocity x – component

Email: [email protected] Source: Computational Fluid Dynamics, ME 702 (Online Material) - Dr. Lorena A Barba, Professor, Department of Mechanical Engineering, Boston University Acknowledgement: Boston University – for sharing the course content at BU You Tube Channel (http://www.youtube.com/user/bu)

Solving Navier – Stokes Equation: Finite Difference Method (FDM)

Fig.3: Surface plot for velocity y – component

Fig.4: Contour plot for velocity y – component

Fig.5: Surface plot for velocity field, U

Fig.6: Contour plot for velocity field, U

Fig.7: Surface plot for pressure, p

Fig.8: Contour plot for pressure, p

Email: [email protected] Source: Computational Fluid Dynamics, ME 702 (Online Material) - Dr. Lorena A Barba, Professor, Department of Mechanical Engineering, Boston University Acknowledgement: Boston University – for sharing the course content at BU You Tube Channel (http://www.youtube.com/user/bu)

Solving Navier – Stokes Equation: Finite Difference Method (FDM) Case 2: Channel Flow Let’s consider a square domain for the channel flow problem with arm length of 2 units. For the top and bottom wall, no slip condition has been considered. The side walls have been considered as periodic. Initial Condition: p

y

u  0; v  0; p  0 ; for all (x,y)

y

(0, 2)

Boundary Condition: Bottom Wall : u x ,0  0 , vx ,0

Top Wall

y 0

p x

x 0

p  0, x

x 2

: u0, y  0 , v0, y  0 , : u0,2  0 , v0,2

0

: u x ,2  0 , vx ,2  0 ,

p y

0

x

p

0

u0,y = 0

u2,y = 0

v0,y = 0

v2,y = 0 ux,0 = 0 vx,0 = 0

0 (0, 0)

0

p y

x

0

Periodic

Right Wall

p

(2, 2)

ux,2 = 0 vx,2 = 0

Periodic

Left Wall

p  0, y

0

x 0

(2, 0)

y2

Case 2: Channel Flow %%%%%%%%%%%%%%%%%%%%%%

Start of the code

%%%%%%%%%%%%%%%%%%%%%%

clc clear all close all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % Initial & Boundary Condition % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% nx ny nt nit

= = = =

21; 21; 10; 10;

vis rho Lx Ly

= = = =

0.1; 1.0; 2; 2;

dx dy

= Lx/(nx-1); = Ly/(ny-1);

%

% number of nodes in x-direction % number of nodes in y-direction % number of time steps % number of artificial time steps ..... % ...... for pressure % Viscosity % Density % Length in x-direction % Length in y-direction % grid spacing in x-direction % grid spacing in y-direction

Email: [email protected] Source: Computational Fluid Dynamics, ME 702 (Online Material) - Dr. Lorena A Barba, Professor, Department of Mechanical Engineering, Boston University Acknowledgement: Boston University – for sharing the course content at BU You Tube Channel (http://www.youtube.com/user/bu)

Solving Navier – Stokes Equation: Finite Difference Method (FDM) dt

= 0.01;

% time step size

x y u v p un vn pn

= = = = = = = =

% % % % % % % %

b f [y,x]

= zeros(ny,nx); = ones(ny,nx); = meshgrid(y,x);

0:dx:Lx; 0:dy:Ly; zeros(ny,nx); zeros(ny,nx); zeros(ny,nx); zeros(ny,nx); zeros(ny,nx); zeros(ny,nx);

node x-ordinates node y-ordinates nodal velocity x-component nodal velocity y-component nodal pressure time marched velocity x-direction time marched velocity x-direction temporary pressure for calculation

% nodal body force term from pressure % nodal source term

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % Calculation % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for it = 1:nt+1 for i = 2:nx-1 for j = 2:ny-1

% loop over time % this i,j loop is for calculating the ... % ... body force from pressure equation

b(j,i) = rho*(((((u(j,i+1)-u(j,i-1))/(2*dx))+... ((v(j+1,i)-v(j-1,i))/(2*dy)))*(1/dt))+((u(j,i+1)... - u(j,i-1))/(2*dx)).^2+(2*((u(j,i+1)... -u(j,i-1))/(2*dy))*((v(j+1,i)-v(j-1,i))/(2*dx)))... +((v(j+1,i)-v(j-1,i))/(2*dy)).^2); end end for iit = 1:nit+1 pn = p; for i = 2:nx-1 for j = 2:ny-1 p(j,i) = ((p(j,i+1)+p(j,i-1))*(dy^2)... +(p(j+1,i)+p(j-1,i))*(dx^2))/(2*(dx^2+dy^2))... +(b(j,i)*dx^2*dy^2)/(2*(dx^2+dy^2)); end end p(:,1) = p(:,2); p(:,nx) = p(:,nx-1); p(1,:) = p(2,:); p(ny,:) = p(ny-1,:); end un = u;

vn = v;

% this i,j loop is for calculating velocity for i = 2:nx-1 for j = 2:ny-1 u(j,i) = un(j,i)-un(j,i)*(un(j,i)-un(j,i-1))*(dt/dx)... -vn(j,i)*(un(j,i)-un(j-1,i))*(dt/dy)... -(1/rho)*(p(j,i+1)-p(j,i-1))*(dt/(2*dx))... +(vis/rho)*((un(j,i+1)-(2*un(j,i))+un(j,i-1))*... (dt/dx^2)+(un(j+1,i)-(2*un(j,i))+un(j-1,i))... *(dt/dy^2))+(f(j,i)*dt); Email: [email protected] Source: Computational Fluid Dynamics, ME 702 (Online Material) - Dr. Lorena A Barba, Professor, Department of Mechanical Engineering, Boston University Acknowledgement: Boston University – for sharing the course content at BU You Tube Channel (http://www.youtube.com/user/bu)

Solving Navier – Stokes Equation: Finite Difference Method (FDM) v(j,i) = vn(j,i)-un(j,i)*(vn(j,i)-vn(j,i-1))*(dt/dx)... -vn(j,i)*(vn(j,i)-vn(j-1,i))*(dt/dy)... -(1/rho)*(p(j+1,i)-p(j-1,i))*(dt/(2*dy))... +(vis/rho)*((vn(j,i+1)-(2*vn(j,i))+vn(j,i-1))*... (dt/dx^2)+(vn(j+1,i)-(2*vn(j,i))+vn(j-1,i))*(dt/dy^2)); end end %%%%%%%%%%%%%%%%%%%%%%

Surface Plotting

%%%%%%%%%%%%%%%%%%%%%%

figure(1) surf(x,y,u') title('Surface Plot: Velocity Component, u'); xlabel('x - ordinate'); ylabel('y - ordinate'); zlabel('Velocity component, u'); figure(2) surf(x,y,v') title('Surface Plot: Velocity Component, v'); xlabel('x - ordinate'); ylabel('y - ordinate'); zlabel('Velocity component, v'); figure(3) surf(x,y,sqrt(u.^2+v.^2)') title('Surface Plot: Velocity Field, U'); xlabel('x - ordinate'); ylabel('y - ordinate'); zlabel('Velocity component, v'); figure(4) surf(x,y,p') title('Surface Plot: Pressure, P'); xlabel('x - ordinate'); ylabel('y - ordinate'); zlabel('Pressure, p'); %%%%%%%%%%%%%%%%%%%%%%

Contour Plotting

%%%%%%%%%%%%%%%%%%%%%%

figure(5) contourf(x,y,u',10) title('Contour: Velocity Component, u'); xlabel('x - ordinate'); ylabel('y - ordinate'); figure(6) contourf(x,y,v',10) title('Contour: Velocity Component, v'); xlabel('x - ordinate'); ylabel('y - ordinate'); figure(7) contourf(x,y,sqrt(u.^2+v.^2)') title('Surface Plot: Velocity Field, U'); xlabel('x - ordinate'); ylabel('y - ordinate'); Email: [email protected] Source: Computational Fluid Dynamics, ME 702 (Online Material) - Dr. Lorena A Barba, Professor, Department of Mechanical Engineering, Boston University Acknowledgement: Boston University – for sharing the course content at BU You Tube Channel (http://www.youtube.com/user/bu)

Solving Navier – Stokes Equation: Finite Difference Method (FDM) zlabel('Velocity component, v'); figure(8) contourf(x,y,p',10) title('Contour: Pressure, P'); xlabel('x - ordinate'); ylabel('y - ordinate'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% u(:,1) = 0; u(:,nx) = 0; u(1,:) = 0; u(ny,:) = 0; v(:,1) = 0; v(:,nx) = 0; v(1,:) = 0; v(ny,:) = 0; end

%%%%%%%%%%%%%%%%%%%%%%%

End of the code

%%%%%%%%%%%%%%%%%%%%%%%

Fig.1: Surface plot for velocity x – component

Fig.2: Contour plot for velocity x – component

Fig.3: Surface plot for velocity y – component

Fig.4: Contour plot for velocity y – component

Email: [email protected] Source: Computational Fluid Dynamics, ME 702 (Online Material) - Dr. Lorena A Barba, Professor, Department of Mechanical Engineering, Boston University Acknowledgement: Boston University – for sharing the course content at BU You Tube Channel (http://www.youtube.com/user/bu)

Solving Navier – Stokes Equation: Finite Difference Method (FDM)

Fig.5: Surface plot for velocity field, U

Fig.6: Contour plot for velocity field, U

Fig.7: Surface plot for pressure, p

Fig.8: Contour plot for pressure, p

NOTE:

1. The discretization method is unstable. 2. The methods used in discretization can not deal with non-linearity. 3. This is just a simple demonstration of Navier–Stokes equation solving code.

Email: [email protected] Source: Computational Fluid Dynamics, ME 702 (Online Material) - Dr. Lorena A Barba, Professor, Department of Mechanical Engineering, Boston University Acknowledgement: Boston University – for sharing the course content at BU You Tube Channel (http://www.youtube.com/user/bu)

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF