Chapter 9 - One Dimensional Transient Heat Conduction

Exa 9.1 Page 174

In [1]:
from __future__ import division
from numpy import arange,zeros
print "the values of Temp measured from centre at the gap of .2 cm are"
alpha=10**-5 ;  delta_t=.1 ; delta_x=10**-3           #given data
m=alpha*delta_t/(delta_x**2)
a=[0]
for i in range(2,5):
    a.append(m)                               #sub-diagonal

b=[(-2*m-1)/2]
for i in range(2,5):
    b.append(-2*m-1)                               #diagonal
c=[]
for i in range(1,4):
    c.append(m)                               #super-diagonal
x=[]
for i in range(1,5):
    x.append(20)                              #initial temperature
y=[]
for t in arange(0.1,3.2,.1):
    for i in range(1,5):
        y.append(x[i-1])
    #TDMA method
    d=[-.5*y[0],
    -y[1],
    -y[2],
    -y[3]-300]
    i=1 ; n=4
    Beta=[b[i-1]]
    Gamma=[d[i-1]/Beta[i-1]]
    i1=i+1
    for j in range(i1,n+1):
        Beta.append(b[j-1]-a[j-1]*c[j-2]/Beta[j-2])
        Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])
    x=zeros(n)
    x[-1]=Gamma[n-1]
    n1=n-i
    for k in range(1,n1+1):
        j=n-k
        x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]
    
for i in range(1,5):
    print x[i-1]                                 #solution of temperature

print "-----------------"

print "----------END---------"
the values of Temp measured from centre at the gap of .2 cm are
31.914893617
37.8723404255
61.7021276596
127.234042553
-----------------
----------END---------

Exa 9.2 Page 175

In [1]:
from __future__ import division
from numpy import zeros
delta_t=1 ;  delta_x=.05 ; alpha=10**-5
t1=alpha*delta_t/delta_x**2
a=[0]
for i in range(2,10):
    a.append(-t1)

b=[]
for i in range(1,10):
    b.append(1+2*t1)

c=[]
for i in range(1,9):
    c.append(-t1)


t=1 ; tf=3000
x=[]
for i in range(1,10):
    x.append(300)

e1=425
print "time when centre temp is 425 K in secs. is"
y=zeros(10)
for t in range(1,tf+1):
    for i in range(1,10):
        y[i-1]=x[i-1]
    d=zeros(9)
    d[0]=y[0]+1.7
    d[8]=y[8]+2.4
    
    for i in range(2,9):
        d[i-1]=y[i-1]
    
    i=1 ; n=9
    Beta=[b[i]]
    Gamma=[d[i-1]/Beta[i-1]]
    i1=i+1
    
    for j in range(i1,n+1):
        Beta.append(b[j-1]-a[j-1]*c[j-2]/Beta[j-2])
        Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])
    x=zeros(n)
    x[-1]=Gamma[n-1]
    n1=n-i
    for k in range(1,n1+1):
        j=n-k
        x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]
    
    if abs(x[4]-e1)>0 and abs(x[4]-e1)<.1:
        print t
        break
    

print "the values of temp. at req. time is"
for i in range(1,10):
    print x[i-1]
time when centre temp is 425 K in secs. is
2860
the values of temp. at req. time is
415.830778173
409.161921067
407.289372709
412.10629054
424.920334418
446.302352324
475.988566837
512.861107143
555.026826929

Exa 9.3 Page 176

In [2]:
from __future__ import division
from numpy import zeros,arange
delta_t=.1 ; delta_r=.001 ;alpha=10**-5              #given data
t1=alpha*delta_t/delta_r**2
a=[0,
.5*t1,.75*t1,.833*t1]                #sub-diagonal
b=[-4*t1-1]
for i in range(2,5):
    b.append(-2*t1-1)                             #main diagonal

c=[4*t1,1.5*t1,1.25*t1]                 #super-diagonal
x=[]
for i in range(1,5):
    x.append(20)

print "T1,T2,T2 & T4 at time interval of .1 sec is"
y=zeros(5)
d=zeros(5)
for t in arange(.1,2.2,.1):
    for i in range(1,5):
        y[i-1]=x[i-1]          #TDMA Method
    
    d[3]=-y[3]-7*t1*300/6
    for i in range(1,4):
        d[i-1]=-y[i-1]
    
    i=1 ; n=4
    Beta=[b[i-1]]
    Gamma=[d[i-1]/Beta[i-1]]
    i1=i+1
    for j in range(i1,n+1):
        Beta.append(b[j-1]-a[j-1]*c[j-2]/Beta[j-2])
        Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])
    x=zeros(n)
    x[-1]=Gamma[n-1]
    n1=n-i
    for k in range(1,n1+1):
        j=n-k
        x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]
    
    print x[3],x[2],x[1],x[0]
    print "--------------------"
T1,T2,T2 & T4 at time interval of .1 sec is
145.908706385 81.3038645321 55.3676141531 48.2940913225
--------------------
203.484090902 137.507282499 102.483825782 91.6458788902
--------------------
234.561182928 180.311474047 146.967547978 135.90321416
--------------------
253.657260062 211.777427681 183.93231189 174.326492344
--------------------
266.42505656 234.835425713 212.930038344 205.209329144
--------------------
275.387525045 251.785736583 235.049836974 229.081735408
--------------------
281.845998761 264.286279996 251.687473273 247.1663257
--------------------
286.564174449 273.5252396 264.112294324 260.723100599
--------------------
290.035348701 280.36239094 273.35699646 270.830217288
--------------------
292.598329474 285.425737959 280.222548126 278.344081958
--------------------
294.494232563 289.176912624 285.316278945 283.921839548
--------------------
295.898007646 291.956531063 289.093561344 288.059216985
--------------------
296.937902328 294.016445785 291.893904508 291.126967003
--------------------
297.708431547 295.543088011 293.969705086 293.40115747
--------------------
298.279442258 296.674544089 295.50832191 295.086889022
--------------------
298.702624888 297.513124139 296.648729623 296.336361503
--------------------
299.01626097 298.134643482 297.49397346 297.262451069
--------------------
299.248712123 298.595288596 298.12044287 297.94884451
--------------------
299.420994656 298.936700895 298.584761024 298.457577721
--------------------
299.548683446 299.189742715 298.928897257 298.83463335
--------------------
299.643321393 299.377287795 299.183958571 299.114093527
--------------------

Exa 9.4 Page 178

In [3]:
from __future__ import division
from numpy import zeros,arange
delta_t=.1 ; delta_r=.001 ; alpha=10**-5
t1=alpha*delta_t/delta_r**2

a=[0,0,.5,.667]
b=[-7*t1]
for i in range(2,):
    b.append(-3)

x=[6,2,1.5]
x=[]
for i in range(1,5):
    x.append(20)

print "T1,T2,T2 & T4 at time interval of .1 sec is"
y=zeros(4) ; d=zeros(4)
for t in arange(.1,1.5,.1):
    for i in range(1,5):
        y[i-1]=x[i-1]
    
    d[3]=-y[3]-400
    for i in range(1,4):
        d[i-1]=-y[i-1]
    
    i=1 ; n=4
    Beta=[b[i]]
    Gamma=[d[i-1]/Beta[i-1]]
    i1=i+1
    for j in range(i1,n+1):
        Beta.append(b[j-2]-a[j-1]*c[j-2]/Beta[j-2])
        Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])
    x=zeros(n)
    x[-1]=Gamma[n-1]
    n1=n-i
    for k in range(1,n1+1):
        j=n-k
        x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]
    
print x[3],x[2],x[1],x[0]
print "-------------------"
T1,T2,T2 & T4 at time interval of .1 sec is
257.170280019 171.439218947 42.8591053357 85.7098332796
-------------------

Exa 9.5 Page 184

In [4]:
from __future__ import division
from math import pi
from numpy import arange,zeros
R=.326 ; D=3*10^-7
delta_t=1 ;  delta_r=.0326 ; conc_ini=10/(1.33*pi*R**3)
t1=D*delta_t/delta_r**2
print "the initial conc. of drug is",conc_ini
a=[0]
for i in range(2,11):
    a.append(-(1-1/(i-1)))

b=[591.4]
for i in range(2,11):
    b.append(3544.5)

c=[-1]
for i in range(2,10):
    c.append(-(1+1/(i-1)))
x=[]
for i in range(1,11):
    x.append(conc_ini)
#y=[]
y=zeros(10)
d=zeros(10)
Beta=zeros(10)
Gamma=zeros(10)
x=zeros(10)
print "Conc. at centre at t=3hr, 12 hr, 24 hr,48 hr is"
for t in arange(1,172800+delta_t,delta_t):
    for i in range(1,11):
        y[i-1]=x[i-1]
    d[0]=y[0]*590.4
    for i in range(2,11):
        d[i-1]=3542.5*y[i-1]
    
    i=1 ; n=10
    Beta[i-1]=b[i-1]
    Gamma[i-1]=d[i-1]/Beta[i-1]
    i1=i+1
    for j in range(i1,n+1):
        Beta[j-1]=b[j-1]-a[j-1]*c[j-2]/Beta[j-2]
        Gamma[j-1]=(d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1]
    
    x[n-1]=Gamma[n-1]
    n1=n-i
    for k in range(1,n1+1):
        j=n-k
        x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]
    
    if t==10800 or t==43200 or t==86400 or t==172800:
        print x[5]
    
the initial conc. of drug is 69.0789433935
Conc. at centre at t=3hr, 12 hr, 24 hr,48 hr is
0.0
0.0
0.0
0.0