Doublet + Uniform Flow // Streamfunction Polar Plot Help

In summary: CD2305', s=80, marker='o')pyplot.streamplot(X, Y, u_doublet, v_doublet,density=2, linewidth=1, arrowsize=1, arrowstyle='->')pyplot.title('Flow around a doublet in polar coordinates', fontsize=16)pyplot.xlabel('$θ$', fontsize=16)pyplot.ylabel('$r$', fontsize=16);In summary, the conversation is about a user who is new to Python, CFD, and PF trying to plot a streamfunction in both cartesian and polar coordinates using Spyder. They have successfully plotted it in cartesian coordinates, but are unsure if their plot in
  • #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:

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')
Thank you in advance :)
 

Attachments

  • PPlot.PNG
    PPlot.PNG
    6.7 KB · Views: 874
Technology news on Phys.org
  • #2
Welcome to PF!

THe computer is your friend and you can use it to help you debug your problem sometimes.

Have you tried plotting it in XY coordinates to compare it to your polar plot?
 
  • Like
Likes nn2e11
  • #3
Thank you for your reply.

Yes, everything worked fine in Cartesian coordinates. I cannot seem to find anything online either, as a reference plot at least.

Please see here for the X,Y. The upper plot is the doublet prior to applying the uniform flow. the bottom plot is the superposition of the two.
Cartesian.jpg
 
Last edited by a moderator:
  • #4
I think i got it right this time. In case someone finds it useful, I have attached the code below.

It produces the following polar plot which I think makes sense(?).
cpp.jpg


Python:
import numpy
from matplotlib import pyplot
from matplotlib import cm

N=50
kappa = 1
r_doublet, theta_doublet=0,0
u_inf = 2.0  # the speed of the freestream
r_min, r_max = 0,1.025*numpy.sqrt(kappa/(2*numpy.pi*u_inf))
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(theta,r)def velocity_doublet(strength, rd, thetad, X,Y):
    Q=numpy.sqrt(strength/(2*numpy.pi*u_inf))
    V_r = u_inf*numpy.cos(X-thetad)*(1-(Q/(Y-rd))**2)
    V_theta = -u_inf*numpy.sin(X-thetad)*(1+(Q/(Y-rd))**2)
  
    return V_r, V_theta

def stream_function_doublet(strength, rd, thetad, X,Y):
    Q=numpy.sqrt(strength/(2*numpy.pi*u_inf))
    psi = u_inf*Y*numpy.sin(X-thetad)*(1-(Q/(Y-rd))**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.figure(figsize=(10, 10))
ax=pyplot.subplot(111, polar=True)
ax.set_rmax(r_max)
ax.set_rmin(r_min)
ax.grid(True) 
minpsi=numpy.nanmin(psi_doublet)
maxpsi=numpy.nanmax(psi_doublet)
avgpsi=(minpsi+maxpsi)*0.5
ax.contourf(X,Y, psi_doublet, levels=numpy.linspace(numpy.nanmin(psi_doublet), numpy.nanmax(psi_doublet),N),cmap=cm.Spectral)
contf = pyplot.contourf(X, Y, psi_doublet, levels=numpy.linspace(minpsi, maxpsi, N), extend='both',cmap=cm.jet)
cbar = pyplot.colorbar(contf)
cbar.set_label('$Ψ$', fontsize=16)
cbar.set_ticks([minpsi,0.75*minpsi,0.5*minpsi,0.25*minpsi,avgpsi,0.25*maxpsi,0.5*maxpsi,0.75*maxpsi, maxpsi])
 
Last edited by a moderator:
  • Like
Likes Pepper Mint

Related to Doublet + Uniform Flow // Streamfunction Polar Plot Help

1. What is the concept of doublet + uniform flow in fluid mechanics?

Doublet + uniform flow is a combination of two fundamental flow patterns in fluid mechanics. A doublet refers to a pair of equal and opposite point sources or sinks placed next to each other. Uniform flow, on the other hand, is a flow pattern in which the velocity remains constant in both magnitude and direction. Combining these two flow patterns results in a flow field that resembles the flow around a circular cylinder.

2. How is the streamfunction used to represent doublet + uniform flow?

The streamfunction is a mathematical function used to represent the flow field of a fluid. In the case of doublet + uniform flow, the streamfunction is plotted in polar coordinates, with the center of the circle representing the location of the doublet and the radius representing the distance from the center. The shape and orientation of the streamlines around the doublet can be visualized by observing the contour lines of the streamfunction plot.

3. What is the purpose of using a polar plot to represent doublet + uniform flow?

A polar plot is a graphical representation that is particularly useful for visualizing flow fields with circular symmetry, such as doublet + uniform flow. The polar plot allows for a clear visualization of the flow pattern around the doublet, as well as the overall flow behavior at different distances from the doublet. It also makes it easier to compare the flow field with different parameters, such as the strength of the doublet or the uniform flow velocity.

4. How does the strength of the doublet affect the streamlines in doublet + uniform flow?

The strength of the doublet, represented by the magnitude of the point source or sink, has a significant impact on the flow field. A stronger doublet will result in more tightly curved streamlines, while a weaker doublet will produce more widely spaced streamlines. This can be observed in the polar plot by looking at the spacing and curvature of the contour lines of the streamfunction plot.

5. What practical applications does doublet + uniform flow have?

Doublet + uniform flow is a common flow pattern used to model the flow around objects with circular cross-sections, such as airfoils, wings, and cylinders. It is also used in various engineering applications, such as in the design of turbines and propellers, as well as in the analysis of fluid flow in pipes and channels. Understanding the behavior of doublet + uniform flow is crucial in many fields, including aerodynamics, hydrodynamics, and fluid mechanics.

Back
Top