簡體   English   中英

如何通過取 3 個網格點為熔爐的質量平衡方程編寫 python 代碼? 我需要 plot 密度配置文件

[英]how do I write a python code for mass balance equation for a furnace by taking 3 grid points? i need to plot the density profile

我是 python 的新手。 我正在做一個關於熔爐熱建模的項目。 為此,我需要首先使用以下公式獲得爐內材料的密度分布:dm/dt = d(ρV)/dt = ∑m˙in - ∑m˙out + Rg。 最初,我要解決 3 個網格點,這是我嘗試過的代碼。 但我得到的 output 並不令人滿意。 請幫忙。

我使用 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 條不需要的不同曲線的錯誤。 我只需要一條曲線來描繪不同時間步長的密度。

您的 3 個網格點在 position 中嗎? 如果是這樣,使用矩陣網格可以讓您更好地了解正在發生的事情。 下面是一個示例,說明如何使用顯示空間網格及時步進的矩陣進行設置。 這是第二個問題,A 部分、b 部分和 c 是不同的方法,如果您有穩定性問題可以使用。 這是我必須為數值方法做的作業

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM