- #1
nn2e11
- 3
- 1
Hello,
Python,CFD and PF newbie here.
I am using Spyder (Python 3.5) and I managed to plot my streamfunction in cartesian coordinates.
I tried transforming and plotting in polar coordinates but I am not sure that what i have done is correct.
I am not even sure what the plot should look like :/
When I run the code the result is: [See attached picture]
The code is this:
Thank you in advance :)
Python,CFD and PF newbie here.
I am using Spyder (Python 3.5) and I managed to plot my streamfunction in cartesian coordinates.
I tried transforming and plotting in polar coordinates but I am not sure that what i have done is correct.
I am not even sure what the plot should look like :/
When I run the code the result is: [See attached picture]
The code is this:
Python:
import numpy
from matplotlib import pyplot
from matplotlib import cm
N=1000
r_min, r_max = 0,1
theta_min, theta_max = 0,2*numpy.pi
r=numpy.linspace(r_min,r_max,N)
theta=numpy.linspace(theta_min, theta_max,N)
X,Y=numpy.meshgrid(r*numpy.cos(theta),r*numpy.sin(theta))
kappa = 1
r_doublet, theta_doublet=0,0
def velocity_doublet(strength, rd, thetad, X, Y):
u = - strength/(2*numpy.pi)*((X-rd*numpy.cos(thetad))**2-(Y-rd*numpy.sin(thetad))**2)/((X-rd*numpy.cos(thetad))**2+(Y-rd*numpy.sin(thetad))**2)**2
v = - strength/(2*numpy.pi)*2*(X-rd*numpy.cos(thetad))*(Y-rd*numpy.sin(thetad))/((X-rd*numpy.cos(thetad))**2+(Y-rd*numpy.sin(thetad))**2)**2
return u, v
def stream_function_doublet(strength, rd, thetad, X, Y):
psi = - strength/(2*numpy.pi)*(Y-rd*numpy.sin(thetad))/((X-rd*numpy.cos(thetad))**2+(Y-rd*numpy.sin(thetad))**2)
return psi
# computes the velocity field on the mesh grid
u_doublet, v_doublet = velocity_doublet(kappa, r_doublet, theta_doublet, X, Y)
# computes the stream-function on the mesh grid
psi_doublet = stream_function_doublet(kappa, r_doublet, theta_doublet, X, Y)
#pyplot.streamplot(X, Y, u_doublet, v_doublet,
#density=2, linewidth=1, arrowsize=1, arrowstyle='->')
#pyplot.scatter(r_doublet, theta_doublet, color='#CD2305', s=80, marker='.');
#ax = pyplot.subplot(111, polar=True)
#ax.plot(X,Y, u_doublet,v_doublet, color='r', ls='none', marker='.')
u_inf = 1.0 # the speed of the freestream
u_freestream = u_inf * numpy.ones((N, N), dtype=float)
v_freestream = numpy.zeros((N, N), dtype=float)
psi_freestream = u_inf * Y
u = u_freestream + u_doublet
v = v_freestream + v_doublet
psi = psi_freestream + psi_doublet
ax = pyplot.subplot(111, polar=True)
pyplot.scatter(r_doublet*numpy.cos(theta_doublet), r_doublet*numpy.sin(theta_doublet), color='b', s=500, marker='o')
ax.contour(X,Y, psi, levels=[-1,1,N], colors='#CD2305',linestyles='solid')