Python Forum
Heat equation (not stationary)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Heat equation (not stationary)
#9
Thank you ! For having helped me; here is the code corrected and working for those who may need it in a future.
(There were several errors : The "for" had no way to be stopped and two errors on incrementation )

I'm gonna change it now to respond to my problem, nevertheless I believe that I will no more need your help for this, so Thank You !



## TIPE

#Importation

import matplotlib.pyplot as plt

#Numeric values

rho=2500
le=1.4e-3
ce=4186
rhoe=1000
h=10
e=5e-3

#Coefficients for thermal dependency

conduc0=-11.91
conduc1=87.6e-3
conduc2=-145e-6

capa0=-243e3
capa1=2e3
capa2=-2

#Functions for thrmal dependency

def conduc(T, coeff1=conduc1, coeff2=conduc2): #Thermal conductivity
        return (conduc0 + conduc1*T + conduc2*T**2)

def capa(T, coeff3=capa1, coeff4=capa2): #Thermal capacity per mass
       return (capa0 + coeff3*T + coeff4*T**2)

#Parameters of discreditation

N=50
dt=1000000
dr=e/N+1

#Initial parameters

T_start=90
T_ext=20 

#Function

def résolution(M,coeff1,coeff2,coeff3,coeff4):
       '''Stop at time_max=M*dt, return the list of Temperatures at the interface with the water at every time'''

       Interface_water=[T_start]
       Time = [elt for elt in range(M)]
       L = [ [T_start] + N*[T_ext] ] #List where every temperature calculated will remain

       for l_row in L:
              Temperature=[]

              #Calculation at the interface water (i=0)
              Temperature.append( l_row[0] + conduc(l_row[0])*dr*dt / (dr*rho*capa(l_row[0]) - le*rhoe*ce) /dr/dr * (l_row[1] - l_row[0]) )

              #Calculation in the mug (i from 1 to N)
              for i in range(1, N):
                     Num = conduc(l_row[i]) * dt #Numerator
                     Den = rho * capa(l_row[i]) * dr**2 #Denominator
                     Temperature.append( l_row[i] + (l_row[i+1] + l_row[i-1] - 2*l_row[i]) * Num / Den )
                     # T_i + ( T_i+1 + T_i-1 - 2 * T_i ) * Num/Den

              #Calculation at the interface air (i=N+1)
              Temperature.append( l_row[N] + dt / (dr*rho*capa(l_row[N])) * ( h*(T_ext - l_row[N]) + conduc(l_row[N])/dr * (l_row[N-1] - l_row[N]) ) )


              L.append(Temperature)
              Interface_water.append(Temperature[0])

              if len(Interface_water)>=M : #Stop "for"
                     Droite=len(Time)*[55]
                     plt.plot(Time, Droite)
                     plt.plot(Time, Interface_water)
                     return (Interface_water, L)


#Execution

print(résolution(100))
Reply


Messages In This Thread
Heat equation (not stationary) - by Zulian - May-13-2017, 07:19 AM
RE: Heat equation (not stationary) - by volcano63 - May-13-2017, 08:56 AM
RE: Heat equation (not stationary) - by Zulian - May-13-2017, 09:01 AM
RE: Heat equation (not stationary) - by volcano63 - May-13-2017, 09:03 AM
RE: Heat equation (not stationary) - by Zulian - May-13-2017, 03:03 PM
RE: Heat equation (not stationary) - by Zulian - May-14-2017, 12:54 PM
RE: Heat equation (not stationary) - by volcano63 - May-14-2017, 04:03 PM
RE: Heat equation (not stationary) - by Ofnuts - May-15-2017, 06:33 AM
RE: Heat equation (not stationary) - by Zulian - May-15-2017, 02:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  animating 2d heat map schniefen 0 1,380 Nov-20-2022, 10:00 PM
Last Post: schniefen
  Heat equation HugoL 1 33,578 Mar-07-2017, 05:22 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020