0% found this document useful (0 votes)
52 views3 pages

Fluid Matlab

This document contains MATLAB code to simulate and visualize various combinations of uniform flow, sources, sinks, and free vortices. It prompts the user to input flow parameters and plots streamlines and velocity vectors for each scenario. These include uniform flow with a source or free vortex, combinations of sources/sinks with free vortices, and flow over a rotating or stationary cylinder.

Uploaded by

Omar Shady
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views3 pages

Fluid Matlab

This document contains MATLAB code to simulate and visualize various combinations of uniform flow, sources, sinks, and free vortices. It prompts the user to input flow parameters and plots streamlines and velocity vectors for each scenario. These include uniform flow with a source or free vortex, combinations of sources/sinks with free vortices, and flow over a rotating or stationary cylinder.

Uploaded by

Omar Shady
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

disp('------------------------uniform + source------------------------')

xx=linspace(-0.5,0.5,50);
yy=linspace(-0.5,0.5,50);
alpha = input('enter the angle \n');
U = input('please enter the velocity \n');
[x,y]=meshgrid(xx,yy);
r=sqrt((x.^2)+(y.^2));
theta = atan2(y./r,x./r);
m=input('enter the strength m (postive if source and negative if sink) \
n');
streamline = (y.*U*cosd(alpha)-x.*U*sind(alpha))+((m.*theta)./(2.*pi));
[dx,dy]=gradient(streamline);
contourf(x,y,streamline,50)
hold on
quiver(x,y,dx,dy);
streamslice(x,y,dx,dy,2)

colorbar
if m>=0
title('source')
else
title('sink')
end
hold off

disp('------------------------uniform + free vortex------------------------')


xx=linspace(-0.5,0.5,50);
yy=linspace(-0.5,0.5,50);
[x,y]=meshgrid(xx,yy);
alpha = input('enter the angle \n');
U = input('please enter the velocity \n');
r=sqrt((x.^2)+(y.^2));
teta = atan2(y./r,x./r);
k=input('enter the vorticity strength (positive if counter clockwise and
negative if clockwise) \n');
streamline = (-k.*log(r)) + (y.*U*cosd(alpha)-x.*U*sind(alpha));
[dx,dy]= gradient(streamline);
contourf(x,y,streamline,50)
hold on
quiver(x,y,dx,dy);
streamslice(x,y,dx,dy,2)
colorbar
if k>0
title('Counter clockwise')
else
title('clockwise')
end
hold off

disp('------------------------source + free vortex------------------------')


xx=linspace(-0.5,0.5,50);
yy=linspace(-0.5,0.5,50);
[x,y]=meshgrid(xx,yy);
r=sqrt((x.^2)+(y.^2));
theta = atan2(y./r,x./r);
m=input('enter the strength m (positive) \n');
k=input('enter the vorticity strength \n');
streamline = -k.*log(r) + ((m.*theta)./(2.*pi));
[dx,dy]= gradient(streamline);
contourf(x,y,streamline,50)
streamslice(x,y,dx,dy,2)
hold on
quiver(x,y,dx,dy);
colorbar
if k>0
title('Counter clockwise')
else
title('clockwise')
end
hold off

disp('------------------------sink + free vortex------------------------')


xx=linspace(-0.5,0.5,50);
yy=linspace(-0.5,0.5,50);
[x,y]=meshgrid(xx,yy);
r=sqrt((x.^2)+(y.^2));
theta = atan2(y./r,x./r);
m=input('enter the strength m (negative) \n');
k=input('enter the vorticity strength \n');
streamline = -k.*log(r) + ((m.*theta)./(2.*pi));
[dx,dy]= gradient(streamline);
contourf(x,y,streamline,50)
hold on
quiver(x,y,dx,dy);
streamslice(x,y,dx,dy,2)
colorbar
if k>0
title('Counter clockwise')
else
title('clockwise')
end
hold off

disp('------------------------source + sink------------------------')
xx=linspace(-0.5,0.5,50);
yy=linspace(-0.5,0.5,50);
[x,y]=meshgrid(xx,yy);
r=sqrt((x.^2)+(y.^2));
theta = atan2(y./r,x./r);
m=input('enter the strength (positive) \n');
g=input('enter the strength (negative) \n');
streamline = ((m.*theta)./(2.*pi)) + ((g.*theta)./(2.*pi)) ;
[dx,dy]=gradient(streamline);
contourf(x,y,streamline,50)
hold on
quiver(x,y,dx,dy);
streamslice(x,y,dx,dy,2)
colorbar
hold off
clc;
clear all;

disp('------------------------flow over rotating


cylinder------------------------')
U = input('please enter the velocity \n');
k = input('please enter k');
M=input('enter the vorticity strength \n');
[X1,Y1] = meshgrid(-30:0.1:30,-30:0.1:30);
streamline = U*Y1-k*Y1./(X1.^2+Y1.^2)-(M/(2*pi))*log(sqrt(X1.^2+Y1.^2));
figure (1)
A='on';
B=2;
C=10;
contourf(X1,Y1,streamline,'k','textstep',B,'levelstep',C);
clc;
clear all;

disp('------------------------flow over cylinder------------------------')


U = input('please enter the velocity \n');
k = input('please enter k');
[X1,Y1] = meshgrid(-30:0.1:30,-30:0.1:30);
streamline = U*Y1-k*Y1./(X1.^2+Y1.^2);
figure (1)
A='on';
B=2;
C=10;
contourf(X1,Y1,streamline,'k','textstep',B,'levelstep',C);

You might also like