Solving the Heat Diffusion Equation (1D PDE) in Python

Solving the Heat Diffusion Equation (1D PDE) in Python

https://www.youtube.com/watch?v=6-2Wzs0sXd8

import numpy as np
import matplotlib.pyplot as plt


L = 0.1  #Grosor de la pared en metros
n = 10   #Numero de nodos utilizados   
T0 = 20  #Temperatura inicial
T1s = 40 #Temperatura superficial en cara 1
T2s = 20 #Temperatura superficial en cara 2
dx = L/n
alpha = 0.000000054713 #Difusividad termica K/(Rho*C_p) 
t_final = 1800  #Tiempo final en segundos
dt = 60


x = np.linspace(dx/2, L-dx/2, n)

T = np.ones(n)*T0
dTdt = np.empty(n)

t = np.arange(0, t_final, dt)


for j in range(1,len(t)):
    plt.clf()
    for i in range(1, n-1):
        dTdt[i] = alpha*(-(T[i]-T[i-1])/dx**2+(T[i+1]-T[i])/dx**2)
    dTdt[0] = alpha*(-(T[0]-T1s)/dx**2+(T[1]-T[0])/dx**2)
    dTdt[n-1] = alpha*(-(T[n-1]-T[n-2])/dx**2+(T2s-T[n-1])/dx**2)
    T = T + dTdt*dt
    plt.figure(1)
    plt.plot(x,T)
    plt.axis([0, L, 0, 50])
    plt.xlabel('Distance (m)')
    plt.ylabel('Temperature (C)')
    plt.show()
    plt.pause(0.01)

上图开始迭代,下图迭代完成

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值