Você está na página 1de 13

Solving Navier Stokes Equation: Finite Difference Method (FDM)

Email: noman.becker@gmail.com

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

| |
c
+ V = V +V +
|
|
c
\ .



Here, T is the deviatoric stress tensor,

is the body force. Replacing T with

2
v V

, the equation yields

2
.
v
v v p v f
t

| |
c
+ V = V + V +
|
|
c
\ .





Continuity Equation
0
u u
x y
c c
+ =
c c


Momentum Equation (x - dir)
2 2
2 2
1 u u u p u u
u v
t x y x x y
q

| | c c c c c c
+ + = + +

c c c c c c
\ .
|
; q = kinematic viscosity

Momentum Equation (y - dir)
2 2
2 2
1 v v v p v v
u v
t x y y x y
q

| | c c c c c c
+ + = + +
|
c c c c c c
\ .


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
2
2 2
2 2
2
p p u v u u v v
x y t x y x y x y

(
| | | c c c c c c c c c | |
+ = + + + + (
| |
c c c c c c c c c
\ .
( \ . \

|
|
.


Derivation of Pressure Equation

Lets take the partial derivative of x momentum w.r.t. x
2 2 2 2
2 2
1 u u u u v u u p u u
u v
t x x x x x y x y x x x y
q

| | c c c c c c c c c c c c | |
+ + + + = + +
| |
c c c c c c c c c c c c c
\ .
\ .
2
2 2

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

2 2 2 2
2 2 2
1 v u v v v v v p v v
u v
t y y x x y y y y y y x y
q

| | | | c c c c c c c c c c c c
+ + + + = + +
| |
c c c c c c c c c c c c c
\ . \ .
2
2


Lets add last two equations. Now, the L.H.S. of the added equation,

2
2
2
2
2
2
2
2
u u v
u u
x x y
u u u v v u v
t x
v v
v
x y y
v
x y x y y y x
c c
+
| | | | c c c c c c c | |
+ + + + + +
| | |
c c c c c c c
c c
+
c c
\ .
\ . \
c c
+
c c
.
c c c c


2
2
u u v v u v
t x y x x
u v
u
x x
u v
x y
u v
v
y x y y y y
| | c c c | | | | c c c c c c c | |
= + + + + + +
| |
c c
+
c c
| | c c c
+

c
+
| |
c c c c c c c
\ .
\ .
c c c
\
c c
\ \ .
|
. .


Using the continuity equation and keeping the continuity part associated with time derivative,
L.H.S
2
2
2
u v u u v v
t x y x y x y
| | | c c c c c c c | |
= + + + +
| |
c c c c c c c
\ .
\ . \
|
|
.


Now, for the R.H.S

2 2 2 2 2 2
2 2 2 2 2 2
1 p p u u v
x y x x y y x y
q

( | | | | | c c c c c c c c
+ + + + +
( | |
c c c c c c c c
\ . \ . \
v |
|
.

2 2 3 3 3 3
2 2 3 2 2 3
1 p p u u v v
x y x x y x y
q

| | | c c c c c c
= + + + + +
|
c c c c c c c c
\ . \
y
|
|
.


3 2 2
2 2
3 3
2 3
3
3 2
1 p p
x y
u v
x x y y
u v
x y
q

c c
+
| | | c c
= + + +
|
c c
c
c c c
\ . \
c
+
c c
|
|
.
c

2 2
2
2
2 2
2
2
1 u v u v
y
p p
x x y x y y x
q

( | | | | | c c
= + + +
( |
c c c
+
c c c
|
c c
\ . \
c
\ .
c c
+
c c

c
|
|
.


Again, using the continuity equation,
R.H.S
2 2
2 2
1 p p
x y
| | c c
= +
|
c c
\ .


Now, combining both hand sides,

2
2
2 2
2 2
1
2
p p u v u u v v
x y t x y x y x y
| | | | | c c c c c c c c c | |
+ = + + + +
| | |
c c c c c c c c c
\ .
\ . \ \ .
|
|
.


2
2
2 2
2 2
2
p p u v u u v v
x y t x y x y x y

(
| | | c c c c c c c c c | |
+ = + + + + (
| |
c c c c c c c c c
\ .
( \ . \

|
|
.


This is similar to the Poisson equation
2
p f V = .


Email: noman.becker@gmail.com
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)

Email: noman.becker@gmail.com
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)

inite Difference Discretization of Navier Stokes Equation

F

st
Lets discretize the Navier Stokes equation taking 1 order forward difference for time discretization, 1
st

order backward difference for 1
st
order space derivative ( v V

), 2
nd
order central difference for 2
nd
order
space derivative (
2
v V

) and 1
st
order central difference for pressure discretization,

Discretized Navier Stokes equation in x direction
1
1, , 1
1
n n n n n n n
ij ij ij i j ij i j i n n
u u u u u u p
+


1, 1, 1, 1, , 1 , 1
2 2
2 2
2
n n n n n n n
j i j i j ij i j i j ij i j
ij ij
p u u u u u u
u v
t x y x x y
q

+ + +
| | + +
+ + = + +
|
|
A A A A A A
\ .


iscretized Navier Stokes equation in y direction D
1
1, , 1
1
n n n n n n n
ij ij ij i j ij i j i n n
v v v v v v p
+
+

1, 1, 1, 1, , 1 , 1
2 2
2 2
2
n n n n n n n
j i j i j ij i j i j ij i j
ij ij
p v u v v v v
u v
t x y y x y
q

+ +
| | + +
+ + = + +
|
|
A A A A A A
\ .


or discretized pressure equation, lets take 2
nd
order central difference for pressure and 1
st
order central F
difference in space. Hence, the discretized pressure equation is
2
1, 1, , 1 , 1 1, 1,
1, 1, , 1 , 1
2 2
, 1 , 1 1, 1, , 1 ,
1
n
i j
u
+
|
| |
2 2 2
2 2
2
2 2
n n n n n
i j i j i j i j i j
n n n n n n
i j ij i j i j ij i j
n n n n n
i j i j i j i j i j i
u v v u u
t x y x
p p p p p p
x y
u u v v v v
y x

+ +
+ +
+ + +
| | |
+ +
| |
|
| |
A A A A
\ . + +
\ . \ .
+ =
A A
| || |
+ +
| |
| |
A A
\ .\ .
(
(
(
(
2
1
2
n
j
y

(
| |
( |
|
A
(
\ .


y transposing, B

( ) ( ) ( )
( )
1
1, , 1 1, 1,
1, 1, , 1 2
1
2
2 2
n n n n n n n n n n
ij ij ij ij i j ij ij i j i j i j
n n n n
i j ij i j i j
t t t
u u u u u v u u p p
x y x
t
u u u u u
x

q
+
+
+ +
| | A A A | | | |
=
| | |
A A A
\ . \ .
\ .
A | |
+ + +
|
A
\ .
( )
, 1 2
n n
ij i j
t
u
y

( | | A
+
( |
A
\ .

( ) ( ) ( )
( )
1
1, , 1 , 1 , 1
1, 1, , 1 2
1
2
2 2
n n n n n n n n n n
ij ij ij ij i j ij ij i j i j i j
n n n n
i j ij i j i j
t t t
v v u v v v v v p p
x y y
t
v v v v v
x

q
+
+
+ +
| | | | A A A | |
=
| | |
A A A
\ .
\ . \ .
A | |
+ + +
|
A
\ .
( )
, 1 2
n n
ij i j
t
v
y

( | | A
+
( |
A
\ .

( )( ) ( )( )
( ) ( )
( )
2 2
2 2
1, 1, , 1 , 1
1, 1, , 1 , 1
2 2 2 2
2
2 2
1, 1,
2 2
2 2 2 2

2 2
n n n n
n n n n
i j i j i j i j
i j i j i j i j n
ij
n n
i j i j
p p y p p x
u u v v
x y
p
x y x y x y t
u u
x y
x x y

+ +
+ +
+
( | |
+ A + + A | |
A A
| ( = +
|
|
|
A A A + A A + A A
(
\ .
\ .
| |
| |
A A
| +
|
|
|
A A + A
\ .
\ .
+
2
, 1 , 1 1, 1, , 1 , 1
2
2 2 2
n n n n n n
i j i j i j i j i j i j
u u v v v v
y x y
+ + +
(
| || | |
(
+ +
| |
| |
A A A (
\ .\ . \


|
|
|
.


Solving Navier Stokes Equation: Finite Difference Method (FDM)

Email: noman.becker@gmail.com

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)

(0, 0)
y
(2
u
x,2
= 1
x
, 2) v
x,2
= 0
u
0,y
= 0
v
0,y
0
u
x,0
= 0

=
v
x,0
= 0
u
2,y
= 0
v
2,y
0

=
p
x,2
= 0

0
p
y
c
=
c

0
p
x
c
=
c
0
p
x
c
=
c
(2, 0)
(0, 2)
ATLAB Code for Solution Explicit Scheme M

Case 1: Cavity Flow

Lets consider a square domain for the cavity flow problem with arm length of 2 units. For all the walls,
itial Condition
except the top wall, no slip condition has been considered. The top wall has been considered as free stream.

In :
; for all (x,y)

oundary Condition

0; 0; 0 v p = = = u
B :
Wall ,

Bottom :
,0
0
x
u = ,
,0
0
x
v =
0
0
y
p
y
=
c
=
c

Left Wall :
0,
0
y
u = ,
0,
0
y
v = ,
0
0
x
p
x
=
c
=
c

Right Wall , :
0,2
0 u = ,
0,2
0 v =
2
0
x
p
x
=
c
=
c

Top Wall ,


ase 1: MATLAB Code for Cavity Flow
:
,2
1
x
u = ,
,2
0
x
v =
,2
0
x
p =


C

%%%%%%%%%%%%%%%%%%%%%% Start of the code %%%%%%%%%%%%%%%%%%%%%%
all

= 21; % number of nodes in x-direction
.....
-direction

c cl
clear
close all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Initial Condition %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


nx
ny = 21; % number of nodes in y-direction
nt = 10; % number of time steps
ime steps nit = 10; % number of artificial t
% ...... for pressure
vis = 0.1; % Viscosity
rho = 1.0; % Density
x Lx = 2; % Length in
Ly = 2; % Length in y-direction


Solving Navier Stokes Equation: Finite Difference Method (FDM)

Email: noman.becker@gmail.com
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)

dx = Lx/(nx-1); % grid spacing in x-direction
omponent
ction

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
(:,:,1) = u(:,:);
:nt+1 % loop over time
for calculating the ...
j,i) = rho*(((((u(j,i+1)-u(j,i-1))/(2*dx))+...
1)...
r
-1
(j,i+1)+p(j,i-1))*(dy^2)...
+dy^2))...
p(:,2); p(:,nx) = p(:,nx-1);

dy = Ly/(ny-1); % grid spacing in y-direction
dt = 0.01; % time step size
x = 0:dx:Lx; % node x-ordinates
y = 0:dy:Ly; % node y-ordinates
u = zeros(ny,nx); % nodal velocity x-c
v = zeros(ny,nx); % nodal velocity y-component
p = zeros(ny,nx); % nodal pressure
ocity x-dire un = zeros(ny,nx); % time marched vel
vn = zeros(ny,nx); % time marched velocity x-direction
pn = zeros(ny,nx); % temporary pressure for calculation

= zeros(ny,nx); % nodal source term value from pressure b


% %
% Boundary Condition %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

,x] = meshgrid(y,x); [y
u(ny,:) = 1;

%% %%%
% %
% Calculation %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

uT
vT(:,:,1) = v(:,:);
pT(:,:,1) = p(:,:);

for it = 1
for i = 2:nx-1 % this i,j loop is
for j = 2:ny-1 % ... body force from pressure equation

b(
((v(j+1,i)-v(j-1,i))/(2*dy)))*(1/dt))+((u(j,i+
- u(j,i-1))/(2*dx)).^2+(2*((u(j,i+1)...
2*dx)))... -u(j,i-1))/(2*dy))*((v(j+1,i)-v(j-1,i))/(
+((v(j+1,i)-v(j-1,i))/(2*dy)).^2);
end
end

iit = 1:nit+1 fo
pn = p;
:nx-1 for i = 2
for j = 2:ny
p(j,i) = ((p
+(p(j+1,i)+p(j-1,i))*(dx^2))/(2*(dx^2
+(b(j,i)*dx^2*dy^2)/(2*(dx^2+dy^2));
end
end
) = p(:,1
p(1,:) = p(2,:); p(ny,:) = p(ny-1,:);
end
Solving Navier Stokes Equation: Finite Difference Method (FDM)

Email: noman.becker@gmail.com
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)

= u; vn = v; % assigning velocity values to n
th
-time values

r i = 2:nx-1 % this i,j loop is for calculating velocity
..
2));
j,i) = vn(j,i)-un(j,i)*(vn(j,i)-vn(j,i-1))*(dt/dx)...
*...
2));
%%%%%%%%%%%%%%%%% Surface Plotting %%%%%%%%%%%%%%%%%%%%%%
gure(1)
)
Plot: Velocity Component, u');
t, u');
gure(2)
)
rt(u.^2+v.^2)')
y Field, U');
t, v');
gure(4)
)
Plot: Pressure, P');
y,u',10)
ity Component, u');

un
% to calculate (n+1)
th
-time values

fo
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^

v(
-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^
end
end

%%% %%

fi
surf(x,y,u'
title('Surface
xlabel('x - ordinate');
ylabel('y - ordinate');
zlabel('Velocity componen

fi
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,sq
title('Surface Plot: Velocit
xlabel('x - ordinate');
ylabel('y - ordinate');
zlabel('Velocity componen

fi
surf(x,y,p'
title('Surface
xlabel('x - ordinate');
ylabel('y - ordinate');
zlabel('Pressure, p');

%%%%%%%%%%%%%%%%%%%%%% Contour Plotting %%%%%%%%%%%%%%%%%%%%%%

figure(5)
contourf(x,
title('Contour: Veloc
xlabel('x - ordinate');
ylabel('y - ordinate');
Solving Navier Stokes Equation: Finite Difference Method (FDM)

Email: noman.becker@gmail.com
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)

gure(6)
y,v',10)
ity Component, v');
gure(7)
y,sqrt(u.^2+v.^2)')
y,p',10)
ure, P');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

:,1) = 0; u(:,nx) = 0; u(1,:) = 0; u(ny,:) = 1;
%%%%%%%%%%%%%%%%%%%%%%% End of the code %%%%%%%%%%%%%%%%%%%%%%%



fi
contourf(x,
title('Contour: Veloc
xlabel('x - ordinate');
ylabel('y - ordinate');

fi
contourf(x,
title('Surface Plot: Velocity Field, U');
xlabel('x - ordinate');
ylabel('y - ordinate');
zlabel('Velocity component, v');

figure(8)
contourf(x,
title('Contour: Press
xlabel('x - ordinate');
ylabel('y - ordinate');




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






Fig.1: Surface plot for velocity x component Fig.2: Contour plot for velocity x component






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: noman.becker@gmail.com
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)

Email: noman.becker@gmail.com
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)


ase 2: Channel Flow C

Lets consider a square domain for the channel flow problem with arm length of 2 units. For the top and
itial Condition
bottom wall, no slip condition has been considered. The side walls have been considered as periodic.

In :
; for all (x,y)

oundary Condition

0; 0; 0 v p = = = u
B :
Wall ,

Bottom :
,0
0
x
u = ,
,0
0
x
v =
0
0
y
p
y
=
c
=
c

Left Wall :
0,
0
y
u = ,
0,
0
y
v = ,
0
0
x
p
x
=
c
=
c

Right Wall , :
0,2
0 u = ,
0,2
0 v =
2
0
x
p
x
=
c
=
c

Top Wall , :
,2
0
x
u = ,
,2
0
x
v =
2
0
y
p
y
=
c
=
c



ase 2: Channel Flow


C

%%%%%%%%%%%%%%%%%%%%%% Start of the code %%%%%%%%%%%%%%%%%%%%%%
all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
....
-direction
tion
x
(2, 2)
(0, 0)
y
u
x,2
= 0

c cl
clear
close all



% %
% Initial & Boundary Condition
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

= 21; % number of nodes in x-direction nx
ny = 21; % number of nodes in y-direction
nt = 10; % number of time steps
ime steps . nit = 10; % number of artificial t
% ...... for pressure
vis = 0.1; % Viscosity
rho = 1.0; % Density
x Lx = 2; % Length in
Ly = 2; % Length in y-direction

x = Lx/(nx-1); % grid spacing in x-direc d
dy = Ly/(ny-1); % grid spacing in y-direction
v
x,2
= 0
u
0,y
= 0
v
0,y
0
u
x,0
= 0

=
v
x,0
= 0
u
2,y
= 0
v
2,y
0

=
0
p
y
c
=
c

0
p
x
c
=
c
0
p
x
c
=
c
(2, 0)
(0, 2)
0
p
y
c
=
c

P
e
r
i
o
d
i
c

P
e
r
i
o
d
i
c

Solving Navier Stokes Equation: Finite Difference Method (FDM)

Email: noman.becker@gmail.com
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)

= 0:dx:Lx; % node x-ordinates
= zeros(ny,nx); % nodal body force term from pressure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
= 1:nt+1 % loop over time
for calculating the ...
1)...
:nx-
(j,i+1)+p(j,i-1))*(dy^2)...
+dy^2))...
= u; vn = v;
r i = 2:nx-1 % this i,j loop is for calculating velocity
..
dt = 0.01; % time step size

x
y = 0:dy:Ly; % node y-ordinates
u = zeros(ny,nx); % nodal velocity x-component
v = zeros(ny,nx); % nodal velocity y-component
p = zeros(ny,nx); % nodal pressure
un = zeros(ny,nx); % time marched velocity x-direction
vn = zeros(ny,nx); % time marched velocity x-direction
pn = zeros(ny,nx); % temporary pressure for calculation

b
f = ones(ny,nx); % nodal source term
[y,x] = meshgrid(y,x);


% %
% Calculation %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for it
for i = 2:nx-1 % this i,j loop is
for j = 2:ny-1 % ... 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+
- 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;
1 for i = 2
for j = 2:ny-1
p(j,i) = ((p
+(p(j+1,i)+p(j-1,i))*(dx^2))/(2*(dx^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

fo
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);

Solving Navier Stokes Equation: Finite Difference Method (FDM)

Email: noman.becker@gmail.com
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)

j,i) = vn(j,i)-un(j,i)*(vn(j,i)-vn(j,i-1))*(dt/dx)...
*...
2));
% %%%%%%%%%%%%%%%%% Surface Plotting %%%%%%%%%%%%%%%%%%%%%%
figure(1)
)
Plot: Velocity Component, u');
t, u');
)
Plot: Velocity Component, v');
t, v');
gure(3)
rt(u.^2+v.^2)')
y Field, U');
t, v');
gure(4)
)
Plot: Pressure, P');
Contour Plotting %%%%%%%%%%%%%%%%%%%%%%

y,u',10)
ity Component, u');
gure(6)
y,v',10)
ity Component, v');
gure(7)
y,sqrt(u.^2+v.^2)')
eld, U');
v(
-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^
end
end

%% %%


surf(x,y,u'
title('Surface
xlabel('x - ordinate');
ylabel('y - ordinate');
zlabel('Velocity componen

gure(2) fi
surf(x,y,v'
title('Surface
xlabel('x - ordinate');
ylabel('y - ordinate');
zlabel('Velocity componen

fi
surf(x,y,sq
title('Surface Plot: Velocit
xlabel('x - ordinate');
ylabel('y - ordinate');
zlabel('Velocity componen

fi
surf(x,y,p'
title('Surface
xlabel('x - ordinate');
ylabel('y - ordinate');
zlabel('Pressure, p');

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

figure(5)
contourf(x,
title('Contour: Veloc
xlabel('x - ordinate');
ylabel('y - ordinate');

fi
contourf(x,
title('Contour: Veloc
xlabel('x - ordinate');
ylabel('y - ordinate');

fi
contourf(x,
title('Surface Plot: Velocity Fi
xlabel('x - ordinate');
ylabel('y - ordinate');
Solving Navier Stokes Equation: Finite Difference Method (FDM)

Email: noman.becker@gmail.com
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)

t, v');
gure(8)
y,p',10)

:,1) = 0; u(:,nx) = 0; u(1,:) = 0; u(ny,:) = 0;

zlabel('Velocity componen

fi
contourf(x,
title('Contour: Pressure, P');
xlabel('x - ordinate');
ylabel('y - ordinate');

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

u(
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

Solving Navier Stokes Equation: Finite Difference Method (FDM)

Email: noman.becker@gmail.com
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)



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

OTE




N :
1. The discretization method is unstable.
not deal with non-linearity.
g code.

2. The methods used in discretization can
3. This is just a simple demonstration of NavierStokes equation solvin

Você também pode gostar