1

我是蟒蛇的新手。我正在做一个关于熔炉热建模的项目。为此,我需要首先使用以下公式获得炉内材料的密度分布:dm/dt = d(ρV)/dt = ∑m˙in - ∑m˙out + Rg。最初,我要解决 3 个网格点,这是我尝试过的代码。但我得到的输出并不令人满意。请帮忙。

我使用 numpy 和 matplotlib.pyplot 库编写了程序。

''' creating grids'''
gp = np.linspace(0, L, n)
rho = np.ones(n) * rho0
drhodt = np.empty(n)
t = np.arange(0, t_final, dt)
result = np.zeros((int(t_final/dt), n))

''' computation part'''
for j in range (1, len(t)):
    plt.clf()
    for i in range (1,n-1):
        rho[0] = rho1
        rho[n - 1] = rho2
        drhodt[i] = (V_r / V) * (rho[i-1] - rho[i] + Rg)
    rho = rho + drhodt*dt
    result[j] = rho
    print(result)

    ''' plotting the values'''
    plt.figure(1)
    plt.plot(gp, rho)
    plt.axis([0, L, 0, 3000])
    plt.xlabel('distance')
    plt.ylabel('density')
    plt.pause(0.01)
    plt.figure(2)
    plt.plot(t, result)
    plt.axis([0, t_final, 0, 3000])
    plt.xlabel('time')
    plt.ylabel('density')
plt.show()

'''

我期望代码的结果是密度与网格点和密度与时间的 2 个不同配置文件。但是在运行密度与时间曲线时,我收到了 3 条不需要的不同曲线的错误。我只需要一条曲线来描绘不同时间步长的密度。

4

1 回答 1

1

您的 3 个网格点是否到位?如果是这样,使用矩阵网格可以让您更好地了解正在发生的事情。下面是一个示例,说明如何使用显示空间网格及时步进的矩阵进行设置。第二个问题是 A 部分,b 部分和 c 部分是不同的方法,如果您有稳定性问题可以使用。这是我必须为数值方法做的作业

于 2019-10-10T15:40:32.727 回答