我需要完成一项任务,而我却有点不知所措。我不知道解算器出了什么问题,也不知道如何可视化数据。 我的任务是模拟二维平板上的热扩散。它必须有两个加热器,在板的中间有两个孔。bc总是为零。在
我的问题是: 如何使模拟运行在时间上?我问这个是因为当我这样画的时候,它显示了一个盘子上的加热器,但是所有的热量都集中在它们身上。另一个问题是,如何将结果可视化为视频或图片? 这是我的密码。谢谢您。在
import numpy as np
import matplotlib.pyplot as plt
dt=0.1
dx=0.1
L=50 #length of the plate
Ly=np.linspace(0,L,50)
B=50 #width of the plate
Bx=np.linspace(0,B,50)
M=np.zeros([L,B]) #matrix
#heating device shaped like X
Gr=np.eye(10)*2000
for iGr in range(10):
Gr[iGr,-iGr-1]=2000
#implementing heaters to matrix
M[20:30,10:20]=Gr
M[20:30,30:40]=Gr
t=0
#wannabe solver
while t<10:
t=0.1+t
for j in range(1,L-1):
for i in range(1,B-1):
if 24<j<28:
if 29<i<32:
k=0
elif 23<i<20: # holes for liquid
k=0
else:
break
else:
k=0.5
break
M[i,j]=M[i,j]+k*((dt)/dx**2)*(M[i,j+1]-2*M[i,j]+M[i,j-1])+k*((dt)/dx**2)*(M[i+1,j]-2*M[i,j]+M[i-1,j])
plt.pcolormesh(M)
plt.colorbar()
plt.show()
这可能会让你开始。我不熟悉你们的热传递函数(或一般的热传递函数),所以我用了不同的。在
下面的代码为每个步骤
dt
计算M,并将其附加到一个列表MM
。在然后我们使用
FuncAnimation
来逐步检查MM
的元素(回想一下,MM
的元素是矩阵M
的快照)并显示它们。在当然,你得把传递函数修正成你自己的。在
这段代码产生类似this animation(注意,它是3M,太大了,不能嵌入到答案中)
压缩版本:
相关问题 更多 >
编程相关推荐