ursmooth
ursmooth

Reputation: 311

Potential flow, define theta in matlab

I have made this matlab script for a potential flow around a cylinder and I would like to add a point source. See the definition of point source in picture. How can you define theta in matlab? And plot this its streamlines Psi?

enter image description here

clear
% make axes
xymax = 2;
x = linspace(-xymax,xymax,100);
y = linspace(-xymax,xymax,100);
% note that x and y don't include 0
[xmesh,ymesh] = meshgrid(x,y);
x_c=0;
y_c=0;
q=1;
U=1
 r = sqrt((xmesh-x_c).^2+(ymesh-y_c).^2);
sin_th= ((ymesh-y_c)./r)

%(ymesh-y_c)./r = sin(teta)
%(xmesh-x_c)./r = cos(teta)



psi1 = -q./r.*((ymesh-y_c)./r);
psi2 = r.*sin_th;

 psi=psi1+psi2;

figure
contour(xmesh,ymesh,psi,[-xymax:.25:xymax],'-b');

Upvotes: 1

Views: 885

Answers (1)

FluidMechanics12
FluidMechanics12

Reputation: 11

To plot the streamlines in potential flow you are correct that you have to plot contour lines of constant stream function.

In the case of a point source, if you are plotting in cartesian coordinates in MATLAB you have to convert theta to cartesian coordinates using arctangent as follows: theta = arctan(y/x). In MATLAB use the function atan2 which will limit the number of discontinuities to between -PI and PI: https://www.mathworks.com/help/matlab/ref/atan2.html

Your code should read: psi2 = ( m/(2*PI) ) * atan2(y,x)

For more information on plotting elements of potential flow in 2D cartesian coordinates, see more information here:

https://potentialflow.com/flow-elements

https://potentialflow.com/equations

Upvotes: 1

Related Questions