lunes, 23 de junio de 2025

Python para ingenieros mecanicos, Ecuacion de transferencia de calor

Matemáticamente hablando, el problema que ahora nos enfrentamos es el siguiente:

dónde

es una constante llamada difusividad térmica o conductividad térmica y es diferente según los diferentes materiales. Al utilizar el método de separación de variables, podemos encontrar la solución que necesitamos y aplicando las condiciones iniciales para encontrar una solución particular y

Nuestra solución se parece a esto:

Ahora solo necesitamos evaluar nuestra función en cada X y T. Recuerde que si u (x, y) es diferenciable, entonces:

sostiene. Podemos tirar el último término y aproximar nuestra función utilizando la relación anterior, ya que las derivadas parciales de U deben existe y podemos obtenerlas fácilmente. Pensando en ello, el segundo término también es inútil, ya que no nos estamos moviendo a lo largo del eje x, por lo tanto, nos queda lo siguiente:

>>import numpy as np
>>from numpy import pi
>>import matplotlib.pyplot as plt
>>import matplotlib.animation as animation

>>fig = plt.figure()
>>fig.set_dpi(100)
>>ax1 = fig.add_subplot(1,1,1)

>>#Diffusion constant
>>k = 2

>>#Scaling factor (for visualisation purposes)
>>scale = 5

>>#Length of the rod (0,L) on the x axis
>>L = pi

>>#Initial contitions u(0,t) = u(L,t) = 0. Temperature at x=0 and x=L is fixed
>>x0 = np.linspace(0,L+1,10000)
>>t0 = 0
>>temp0 = 5  #Temperature of the rod at rest (before heating)

>>#Increment
>>dt = 0.01

>>#Heat function
>>def u(x,t):
>>    return temp0 + scale*np.exp(-k*t)*np.sin(x)

>>#Gradient of u
>>def grad_u(x,t):
                               #du/dx              #du/dt
>>    return scale*np.array([np.exp(-k*t)*np.cos(x),-k*np.exp(-k*t)*np.sin(x)])

>>a = []
>>t = []

>>for i in range(500):
>>    value = u(x0,t0) + grad_u(x0,t0)[1]*dt
>>    t.append(t0)
>>    t0 = t0 + dt
>>    a.append(value)

>>k = 0
>>def animate(i):         #The plot shows the temperature evolving with time
>>    global k            #at each point x in the rod
>>    x = a[k]            #The ends of the rod are kept at temperature temp0
>>    k += 1              #The rod is heated in one spot, then it cools down
>>    ax1.clear()
>>    plt.plot(x0,x,color='red',label='Temperature at each x')
>>    plt.plot(0,0,color='red',label='Elapsed time '+str(round(t[k],2)))
>>    plt.grid(True)
>>    plt.ylim([temp0-2,2.5*scale])
>>    plt.xlim([0,L])
>>    plt.title('Heat equation')
>>    plt.legend()
    
>>anim = animation.FuncAnimation(fig,animate,frames=360,interval=20)
>>plt.show()

No hay comentarios.:

Publicar un comentario

Entradas recientes

Thinkcspy 7.7 Condicionales encadenados

  7.7.  Condicionales encadenados  Python proporciona una forma alternativa de escribir selecciones anidadas como la que se muestra en la se...

Entradas Populares