MATLAB Code For Potential Flow Around A PDF
MATLAB Code For Potential Flow Around A PDF
1
Assignment no. 2
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, two
dimensional potential flow over a rectangular cylinder of given dimensions is solved with
stream function formulation. Various iterative methods such as Jacobi method, Gauss Seidel
method, Jacobi method with relaxation, Gauss Seidel method with relaxation are used. Residue
for each method is calculated and their relative efficiency is compared in terms of number of
iterations required. Various graphs are obtained for each case. It’s found that Gauss Seidel
method with relaxation is the most efficient and fast compared to other methods.
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. Periodic boundary condition 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 30 elements.
3. Angular position is varied from 0 degree to 360 degree with 30 elements.
4. Total residue is set as convergence criteria.
5. Convergence is achieved when total residue goes beyond 0.001.
6. For Jacobi method with relaxation, relaxation factor is equal to 0.9.
7. For Gauss Seidel method with relaxation, relaxation factor is equal to 1.8.
Results –
1. Rate of Convergence
a) Jacobi Method –
a) Coefficient of pressure
b) Velocity magnitude –
c) Velocity Vector –
4. Jacobi method –
e) Stream function –
Observation –
1. For Jacobi method residue converges after 20031 iterations.
2. For Gauss Seidel method residue converges after 1012 iterations.
3. For Jacobi method with relaxation residue converges after 2021 iterations.
4. For Gauss Seidel method with relaxation residue converges after 110 iterations.
5. From stream function plot and velocity graph it can be seen that magnitude of the
velocity over the cylinder is symmetric with respect to the x – axis,
Discussion –
1. Convergence rate of residue largely depends upon the initial guess for the iterative
method. Here, initial guess is made as follows -
2. The Gauss Seidel method uses values calculated at previous grid points for calculating
values at the current grid point in the current iteration cycle. This is the reason for its
high convergence rate.
3. The convergence rate for relaxation methods depends upon the relaxation factor, for
given discretization there is an optimal value of relaxation factor for each method.
4. Under relaxation makes both the methods slow whereas effect is completely opposite
for over relaxation.
5. Relaxation factor for Jacobi method is kept around 0.9 for maximum efficiency.
Whereas for Gauss Seidel method it is kept around 1.8 for maximum efficiency.
6. The optimal value of relaxation factor for Jacobi method lies in the interval of 0.9 to 1
and for Gauss Seidel method it lies in the interval of 1.8 to 1.9.
7. The difference between the velocities calculated numerically and theoretically is
maximum at 90 degree and 270 degree. But on the most of the surface they are in
good agreement with sufficient accuracy.
Conclusion –
1. Rate of convergence for above mentioned methods follows the order –
Gauss Seidel method with relaxation > Gauss Seidel method > Jacobi method > Jacobi with relaxation
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 –
%% Defining constants
Vinf = 1;
d1 = 1;
din = d1/2;
d2 = 20*d1;
dout = d2/2;
%%
n = 30; % length of R
R = linspace(din,dout,n); % variation in R
dR = R(4) - R(3);
dt = theta(4) - theta(3);
%% Calculating x and y co-ordinates and intializing xi = stream function
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
xi(n,j) = Vinf*y(n,j) + 20;
end
XI = xi;
total_residue = 10;
k = 0 ;
tic
while abs(total_residue)>10^(-3)
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);
XI(:,m) = XI(:,1);
% residue calculation
total_residue = 0;
for j = 2:m - 1
for i = 2:n - 1
end
end
for i = 2:n - 1
end
residue(:,m) = residue(:,1);
for j = 1:m
for i = 2:n-1
end
end
toc
k = k+1;
if mod(k,10)==0
hold on
plot(k,total_residue,'.');
xlabel('iteration')
ylabel('residue')
axis tight
title('convergence of residue')
grid on
drawnow;
xi = XI;
end
end
for j = 1:m
for i = 1:n
end
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
end
for j = 1:m
end
for j = 1:m
for i = 1:n
Cp(i,j) = 1-(U(i,j)/Vinf)^2;
end
end
figure;
pcolor(x,y,Cp);
colorbar
shading interp;
axis equal
title('coefficient of pressure')
axis tight
grid on
figure;
quiver(x,y,U_x,U_y);
axis equal
title('velocity vector')
axis tight
grid on
figure;
plot(theta,U(1,:),'-o')
hold on
plot(theta,V(1,:),'-o')
hold off
axis tight
grid on
ylabel('velocity')
xlabel('angle in radians')
figure;
contour(x,y,XI,50);
shading interp;
colormap jet
axis equal
axis equal
title('stream function')
axis tight
grid on
figure;
pcolor(x,y,U);
colorbar
shading interp;
axis equal
title('Velocity magnitude')
axis tight
grid on
Vinf = 1;
d1 = 1;
din = d1/2;
d2 = 20*d1;
dout = d2/2;
%%
n = 30; % length of R
dR = R(4) - R(3);
dt = theta(4) - theta(3);
xi = zeros(n,m);
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
xi(n,j) = Vinf*y(n,j) + 20;
end
XI = xi;
total_residue = 10;
k = 0;
tic
while abs(total_residue)>10^(-3)
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
% at periodic boundary
for i = 2:n-1
c(i,1) = 1/(R(i)*dt^2);
d(i,1) = 1/(R(i)*dt^2);
XI(:,m) = XI(:,1);
xi = XI;
% residue calculation
total_residue = 0;
for j = 2:m - 1
for i = 2:n - 1
end
end
for i = 2:n - 1
residue(:,m) = residue(:,1);
for j = 1:m
for i = 2:n-1
end
end
toc
k = k+1;
if mod(k,1)==0
hold on
plot(k,total_residue,'.');
xlabel('iteration')
ylabel('residue')
axis tight
title('convergence of residue')
grid on
drawnow;
end
total_residue
end
%% velocity from analytical solution
for j = 1:m
for i = 1:n
end
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
end
for j = 1:m
end
for j = 1:m
for i = 1:n
Cp(i,j) = 1-(U(i,j)/Vinf)^2;
end
end
figure;
pcolor(x,y,Cp);
colorbar
shading interp;
axis equal
title('coefficient of pressure')
axis tight
grid on
figure;
quiver(x,y,U_x,U_y);
axis equal
title('velocity vector')
axis tight
grid on
figure;
plot(theta,U(1,:),'-o')
hold on
plot(theta,V(1,:),'-o')
hold off
axis tight
grid on
ylabel('velocity')
xlabel('angle in radians')
figure;
contour(x,y,XI,50);
shading interp;
colormap jet
axis equal
title('stream function')
axis tight
grid on
figure;
pcolor(x,y,U);
colorbar
shading interp;
axis equal
title('coefficient of pressure')
axis tight
grid on
%% Defining constants
Vinf = 1;
d1 = 1;
din = d1/2;
d2 = 20*d1;
dout = d2/2;
%%
n = 30; % length of R
R = linspace(din,dout,n); % variation in R
dR = R(4) - R(3);
dt = theta(4) - theta(3);
k = 0;
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
XI = xi;
total_residue = 10;
tic;
while abs(total_residue)>10^(-3)
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
% at periodic boundary
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);
total_residue = 0;
for j = 2:m - 1
for i = 2:n - 1
end
end
for i = 2:n - 1
end
residue(:,m) = residue(:,1);
for j = 1:m
for i = 2:n-1
end
end
toc;
k = k+1;
if mod(k,1)==0
hold on
plot(k,total_residue,'.');
xlabel('iteration')
ylabel('residue')
axis tight
title('convergence of residue')
grid on
drawnow;
total_residue
end
xi = XI;
end
%% velocity from analytical solution
for j = 1:m
for i = 1:n
end
end
%% Extracting the radial and tangential velocity from the stream function
for j = 2:m-1
for i = 1:n
U_r(i,j) = (1/R(i))*((XI(i,j+1) - XI(i,j-1))/(2*dt));
end
end
for i = 1:n
end
for j = 1:m
for i = 2:n-1
end
end
for j = 1:m
end
for j = 1:m
for i = 1:n
Cp(i,j) = 1-(U(i,j)/Vinf)^2;
end
end
figure;
pcolor(x,y,Cp);
colorbar
shading interp;
axis equal
title('coefficient of pressure')
axis tight
grid on
figure;
quiver(x,y,U_x,U_y);
axis equal
title('velocity vector')
axis tight
grid on
figure;
plot(theta,U(1,:),'-o')
hold on
plot(theta,V(1,:),'-o')
hold off
axis tight
grid on
ylabel('velocity')
xlabel('angle in radians')
figure;
contour(x,y,XI,50);
shading interp;
colormap jet
axis equal
axis equal
title('stream function')
axis tight
grid on
figure;
pcolor(x,y,U);
colorbar
shading interp;
axis equal
title('coefficient of pressure')
axis tight
grid on
%% Defining constants
Vinf = 1;
d1 = 1;
din = d1/2;
d2 = 20*d1;
dout = d2/2;
%%
n = 30; % length of R
R = linspace(din,dout,n); % variation in R
dR = R(4) - R(3);
dt = theta(4) - theta(3);
w = 0.9; % relaxation factor
k = 0;
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
XI = xi;
total_residue = 10;
tic;
while abs(total_residue)>10^(-3)
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
% at periodic boundary
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);
total_residue = 0;
for j = 2:m - 1
for i = 2:n - 1
end
end
for i = 2:n - 1
end
residue(:,m) = residue(:,1);
for j = 1:m
for i = 2:n-1
total_residue = total_residue + residue(i,j);
end
end
toc;
k = k+1;
if mod(k,1)==0
hold on
plot(k,total_residue,'.');
xlabel('iteration')
ylabel('residue')
axis tight
title('convergence of residue')
grid on
drawnow;
total_residue
end
xi = XI;
end
%% velocity from analytical solution
for j = 1:m
for i = 1:n
end
%% Extracting the radial and tangential velocity from the stream function
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
end
for j = 1:m
end
for j = 1:m
for i = 1:n
end
end
figure;
pcolor(x,y,Cp);
colorbar
shading interp;
axis equal
title('coefficient of pressure')
axis tight
grid on
figure;
quiver(x,y,U_x,U_y);
axis equal
title('velocity vector')
axis tight
grid on
figure;
plot(theta,U(1,:),'-o')
hold on
plot(theta,V(1,:),'-o')
hold off
axis tight
grid on
ylabel('velocity')
xlabel('angle in radians')
figure;
contour(x,y,XI,50);
shading interp;
colormap jet
axis equal
axis equal
title('stream function')
axis tight
grid on
figure;
pcolor(x,y,U);
colorbar
shading interp;
axis equal
title('coefficient of pressure')
axis tight
grid on