May-15-2017, 02:19 PM
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 !
(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))