MATLAB Code For Solving 2 D Viscous Flow
MATLAB Code For Solving 2 D Viscous Flow
1 ∂ 2ω ∂ 2ω
∂ω ∂ω ∂ω
+u +v = + 2 (1)
∂t ∂x ∂y Re ∂x2 ∂y
1
As a result of the change of variables, we have been able to separate the
mixed elliptic-parabolic 2-D incompressible Navier-Stokes equations into one
parabolic equation (the vorticity transport equation) and one elliptic equa-
tion (the Poisson equation). These equations are normally solved sequentially
using a time-marching procedure, which is described by the following steps:
1. Specify initial values for ω and ψ at time t = 0. (Take ω = 0 and
ψ = 0)
2. Iterate for new ψ values at all points by solving the Poisson equation
using new ω at interior points.
3. Determine values of ω on the boundaries using ψ and ω values at inte-
rior points.
4. Solve the vorticity transport equation for ω at each interior grid point
at time t + ∆t
5. Find the velocity components
6. Return to Step 2
2 Discretization
1. Use second-order central differencing for Poisson’s equation.
2. Use an explicit time difference scheme for VTE
3. Use second-order central differencing for diffusion term in VTE.
4. For convection terms use upwind scheme
(a) The first derivative can be written as
∂u ui+1 − ui−1 ui+1 − 2ui + ui−1
= +α
∂x 2∆x ∆x2
i.e., central differencing plus second-order artificial diffusion
(b) α = −∆x/2 makes it
∂u ui − ui−1
=
∂x ∆x
2
(c) α = ∆x/2 makes it
∂u ui+1 − ui
=
∂x ∆x
(d) Then the first order upwind for convection can be written as
3 Boundary Condition
1. Refer the figure
2. ABC is the cylinder, FED is the outer boundary, AF and CD are the
periodic boundary condition
3
6. On the wall, use
2(ψi,1 − ψi,2 )
ωi,1 =
∆r2
where in (i, j) the first index varies along the wall and the second
normal to the wall. Then, index i varies along the wall and index 1
stands for point on the wall.
4 Problem
1. Solve viscous flow around a circular cylinder at a Reynolds number of
200.
4
(a) Use the following methods to solve the equation
i. Gauss-Seidel method with relaxation
(b) Since you are solving unsteady flow there would vortex shedding
from the cylinder. Show the results.
5
Assignment no. 3
Vasu Bansode
SC15B009
Department of Aerospace engineering
Indian Institute of Space Science and Technology, Thiruvananthapuram-695547
_____________________________________________________________________________
Abstract –
Computational fluid dynamics provide efficient way to solve complex flow problems. Here, 2-
D incompressible Navier Stokes equation for flow over a rectangular cylinder is solved using
Gauss Seidel method with relaxation as an iterative method for Re = 200. Various plots are
displayed at the end of the report.
Theory –
The vorticity-stream function approach has been one of the most popular methods for solving
the 2-D incompressible Navier-Stokes equations. In this approach, a change of variables is
made that replaces the velocity components with the vorticity and the stream function . The
vorticity vector is defined as –
Where, V is the velocity vector. In 2-D case has only one component which is perpendicular
to the xy plane.
As a result of the change of variables, we have been able to separate the mixed elliptic-parabolic
2-D incompressible Navier-Stokes equations into one parabolic equation (the vorticity transport
equation) and one elliptic equation (the Poisson equation). These equations are normally solved
sequentially using a time-marching procedure.
Variables –
1. Diameter of cylinder = 1 m
2. Free stream velocity = 1 m/s
Boundary Conditions-
1. Physical domain is from 0.5 m to 10 m.
2. No penetration boundary condition on the cylinder surface i.e. ψ = constant = 20
3. On the outer boundary we have ψ = Vinf y +20 where y is the co-ordinate of the point
on the boundary.
4. On the outer boundary
5. On the cylinder wall
Where in (i, j) the 1st index varies along the wall and the second normal to the wall. Then,
index i varies along the wall and index j stands for point on the wall.
6. Periodic boundary conditions for both and at y = 0 since the domain is multiply
connected.
Problem Scheme-
1. The problem is solved in the cylindrical co-ordinates.
2. Radial distance is discretised into 40 elements.
3. Angular position is varied from 0 degree to 360 degree with 40 elements.
4. Time is discretised into 1000 elements from 0 to 100 sec.
5. Total residue is set as convergence criteria.
6. Convergence is achieved when total residue goes beyond 0.01.
7. For Gauss Seidel method with relaxation, relaxation factor is equal to 1.93.
8. Second-order central differencing for Poisson's equation.
9. An explicit time difference scheme for VTE.
10. For convection terms use upwind scheme.
Results –
Results are shown at the end of 100 seconds.
1. Vorticity –
2. Velocity vector –
3. Velocity magnitude –
4. Stream function –
Observation –
2-D incompressible Navier-Stokes equation produces vortex shedding as result of viscosity in
the fluid. Vortex Shedding is periodic in nature and its frequency depends on geometry of the
body, velocity and Reynolds number. A non dimensional number which relates these properties
and parameters is Strouhal number.
Conclusion –
Vortex shedding is observed from the solution which is immediate consequence of the
flow vorticity. The computation time required is very large and can be reduced by
using better iterative solutions. Vortex frequency can be calculated more accurately by
allowing sufficient time.
Acknowledgement –
I greatly thank you to Dr. Manoj Nair for giving us this assignment and helping us to get
a deep insight into the subject. I also appreciate the help provided by Mr. Arun Govind
Neelan throughout the work.
Appendix –
%% Initial conditions
Vinf = 1;
D1 = 1;
Din = D1/2;
D2 = 20*D1;
Dout = D2/2;
%%
n = 40; % length of R
nu = 1/200; % 1/Re
R = linspace(Din,Dout,n); % divisons in R
t = linspace(0,100,1000); % divison in t
for j = 1:m
for i = 1:n
x(i,j) = R(i)*cos(theta(j));
y(i,j) = R(i)*sin(theta(j));
end
end
xi(1,:) = 20;
for j = 1:m
end
%% Main program
W = w;
XI = xi;
for k = 1:length(t) - 1
total_residue = 10;
while abs(total_residue)>10^(-2)
for j = 2:m - 1
for i = 2:n - 1
c(i,j) = 1/(R(i)*dt^2);
d(i,j) = 1/(R(i)*dt^2);
end
end
for i = 2:n-1
c(i,1) = 1/(R(i)*dt^2);
d(i,1) = 1/(R(i)*dt^2);
end
XI(:,m) = XI(:,1);
% calculating residue
xi = XI;
end
for j = 2:m-1
for i = 1:n
end
end
for i = 1:n
end
for j = 1:m
for i = 2:n-1
U_t(i,j) = -(XI(i+1,j) - XI(i-1,j))/(2*dR);
end
end
for j = 1:m
end
for j = 1:m
for i = 1:n
end
end
% Vorticity calculations
for j = 2:m - 1
for i = 2:n - 1
end
end
for i = 2:n-1
end
W(:,m) = W(:,1);
W(n,:) = 0;
w = W;
hold on
grid on
xlabel('time')
ylabel('velocity')
% change following lines to program lines and make above lines comment lines
% for plotting flow over cylinder.
%plot(theta,U(1,:),'-o')
%axis tight
%grid on
%xlabel('theta in radians')
%ylabel('velocity')
drawnow;
end
for j = 2:m-1
for i = 1:n
end
end
for i = 1:n
end
for j = 1:m
for i = 2:n-1
end
for j = 1:m
end
for i = 1:n
end
end
figure;
contour(x,y,W,5000);
shading interp;
colorbar
colormap(jet(15));
hold on
fill(Din*cos(linspace(0,2*pi)),Din*sin(linspace(0,2*pi)),color);
hold off
axis equal
axis tight
grid on
drawnow;
title('vorticity')
figure;
quiver(x,y,U_x,U_y);
axis equal
grid on
axis tight
drawnow
title('velocity vector')
figure;
contour(x,y,XI,5000);
shading interp;
colorbar
colormap(jet(15));
hold on
fill(Din*cos(linspace(0,2*pi)),Din*sin(linspace(0,2*pi)),color);
hold off
axis equal
axis tight
grid on
drawnow;
title('streamline')
figure;
contour(x,y,U,5000);
shading interp;
colorbar
colormap(jet(15));
hold on
fill(Din*cos(linspace(0,2*pi)),Din*sin(linspace(0,2*pi)),color);
hold off
axis equal
axis tight
grid on
drawnow;
title('velocity magnitude')