%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%% Pressure for Ideal Flow Around a Cylinder %%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% flow velocity at large distance
U=1;

% radius of the cylinder
r_0=1;

% do not set a value for the circulation if it is already set by the user
if exist('cons') ~= 1
    cons=0
end

% do not set a value for r_max if it is already set by the user
if exist('r_max') ~= 1
    r_max=3
end

% compute suitable mesh points in polar and Cartesian coordinates
[th,r]=meshgrid([-.001:5:360]*pi/180,[r_0-.0001:.05:r_max]);
[x,y]=pol2cart(th,r);

% compute the velocity components
v_r=U*(1-1./r.^2).*cos(th);
v_th=-U*(1+1./r.^2).*sin(th)-cons./r;

% compute the pressure from Bernoulli
p=.5*(U^2-v_r.^2-v_th.^2);

% plot the pressure, including the zero pressure line that goes to infinity
contour(x,y,p,floor(min(min(p))):.2:ceil(max(max(p))))
