极坐标图马格纳斯效应未显示正确数据

Polar plot Magnus effect not showing correct data

我想在极坐标图上绘制绕旋转圆柱体流动的速度方程。 (方程式来自 Andersen 的 "Fundamentals of Aerodynamics"。)您可以在 for 循环语句中看到两个方程式。

我不能大声喊出设法将计算出的数据表示到极坐标图上。我已经尝试了我的每一个想法,但一无所获。我确实检查了数据,这个似乎完全正确,因为它的行为应该如此。

这是我最后一次尝试的代码:

import numpy as np
import matplotlib.pyplot as plt


RadiusColumn = 1.0
VelocityInfinity = 10.0
RPM_Columns         = 0.0#
ColumnOmega         = (2*np.pi*RPM_Columns)/(60)#rad/s
VortexStrength      = 2*np.pi*RadiusColumn**2 * ColumnOmega#rad m^2/s

NumberRadii = 6
NumberThetas = 19

theta = np.linspace(0,2*np.pi,NumberThetas)
radius = np.linspace(RadiusColumn, 10 * RadiusColumn, NumberRadii)


f = plt.figure()
ax = f.add_subplot(111, polar=True)

for r in xrange(len(radius)):
    for t in xrange(len(theta)):


        VelocityRadius = (1.0 - (RadiusColumn**2/radius[r]**2)) * VelocityInfinity * np.cos(theta[t])
        VelocityTheta = - (1.0 + (RadiusColumn**2/radius[r]**2))* VelocityInfinity * np.sin(theta[t]) - (VortexStrength/(2*np.pi*radius[r]))
        TotalVelocity = np.linalg.norm((VelocityRadius, VelocityTheta))


        ax.quiver(theta[t], radius[r], theta[t] + VelocityTheta/TotalVelocity, radius[r] + VelocityRadius/TotalVelocity)


plt.show()

如您所见,我现在将 RPM 设置为 0。这意味着流量应该从左到右,并且在水平轴上是对称的。 (流体应该在两侧以相同的方式绕过圆柱体。)但是结果看起来更像这样:

这完全是胡说八道。似乎有一个涡度,即使设置了 none!更奇怪的是,当我只显示从 0 到 pi/2 的数据时,流程发生了变化!

正如您从代码中看到的那样,我曾尝试使用单位向量,但显然这不是可行的方法。我将不胜感激任何有用的输入。

谢谢!

基本问题是极坐标 Axes 对象的 .quiver 方法仍然需要笛卡尔坐标中的矢量分量,因此您需要自己将 theta 和径向分量转换为 x 和 y :

for r in range(len(radius)):
    for t in range(len(theta)):

        VelocityRadius = (1.0 - (RadiusColumn**2/radius[r]**2)) * VelocityInfinity * np.cos(theta[t])
        VelocityTheta = - (1.0 + (RadiusColumn**2/radius[r]**2))* VelocityInfinity * np.sin(theta[t]) - (VortexStrength/(2*np.pi*radius[r]))
        TotalVelocity = np.linalg.norm((VelocityRadius, VelocityTheta))

        ax.quiver(theta[t], radius[r],
                  VelocityRadius/TotalVelocity*np.cos(theta[t])
                  - VelocityTheta/TotalVelocity*np.sin(theta[t]),
                  VelocityRadius/TotalVelocity*np.sin(theta[t])
                  + VelocityTheta/TotalVelocity*np.cos(theta[t]))
    
plt.show()

但是,您可以通过使用矢量化大大改进您的代码:您不需要遍历每个点来获得您需要的内容。所以相当于你的代码,但更清晰:

def pol2cart(th,v_th,v_r):
    """convert polar velocity components to Cartesian, return v_x,v_y"""

    return v_r*np.cos(th) - v_th*np.sin(th), v_r*np.sin(th) + v_th*np.cos(th)


theta = np.linspace(0, 2*np.pi, NumberThetas, endpoint=False)
radius = np.linspace(RadiusColumn, 10 * RadiusColumn, NumberRadii)[:,None]

f = plt.figure()
ax = f.add_subplot(111, polar=True)

VelocityRadius = (1.0 - (RadiusColumn**2/radius**2)) * VelocityInfinity * np.cos(theta)
VelocityTheta = - (1.0 + (RadiusColumn**2/radius**2))* VelocityInfinity * np.sin(theta) - (VortexStrength/(2*np.pi*radius))
TotalVelocity = np.linalg.norm([VelocityRadius, VelocityTheta],axis=0)

VelocityX,VelocityY = pol2cart(theta, VelocityTheta, VelocityRadius)

ax.quiver(theta, radius, VelocityX/TotalVelocity, VelocityY/TotalVelocity)

plt.show()

几个显着变化:

  • 我将 endpoint=False 添加到 theta:因为你的函数在 2*pi 中是周期性的,你不需要绘制端点两次。请注意,这意味着当前您有更多 visible 箭头;如果您想要原始行为,我建议您将 NumberThetas 减一。
  • 我在radius中添加了[:,None]:这将使它成为一个二维数组,所以稍后在速度定义中的操作将为您提供二维数组:不同的列对应不同的角度,不同的行对应不同的半径。 quiver 与数组值输入兼容,因此只需调用 quiver 即可。
  • 由于速度现在是 2d 数组,我们需要在本质上是 3d 数组上调用 np.linalg.norm,但如果我们指定要处理的轴,这将按预期工作。
  • 我定义了 pol2cart 辅助函数来完成从极坐标到笛卡尔分量的转换;这不是必需的,但这样对我来说似乎更清楚。

最后的评论:我建议选择较短的变量名,并且不要使用 CamelCase。这可能也会使您的编码速度更快。