In [1]:

```
import math
print"Introduction to heat transfer by S.K.Som, Chapter 4, Example 1"
#Diameter of apple in m
d = 100*(10**(-3));
#radius in m
r = d/2;
#Thermal conductivity of apple in W/(m*K)
k = 0.6;
#Heat transfer coefficient in W/(m**2*Â°C)
h = 10;
#Caculating characteristic dimension in m
Lc = (((((4*math.pi)*r)*r)*r)/3)/(((4*math.pi)*r)*r);
#Biot number
print"Biot number is"
Bi = (h*Lc)/k
print"Bi=",Bi
if Bi<0.1:
print"Problem is suitable for lumped parameter analysis"
else:
print"Problem is not suitable for lumped parameter analysis"
```

In [3]:

```
import math
print"Introduction to heat transfer by S.K.Som, Chapter 4, Example 2"
#Diameter of sphere in m
d = 1.5*(10**(-3));
#radius in m
r = d/2;
#Thermal conductivity of sphere in W/(m*Â°C)
k = 40.0;
#Density in kg/m**3
rho = 8000.0;
#Specific heat in J/(Kg*K)
c = 300.0;
#Heat transfer coefficient in W/(m**2*Â°C)
h = 75.0;
#Time constant in sec
tc = ((rho*c)*(((((4*math.pi)*r)*r)*r)/3))/((((h*4)*math.pi)*r)*r);
print"Time constant in seconds is"
print"tc=",tc
#Using eq. 4.4
#Given fraction is 0.01 (1 percent)
#Required time in sec
t = (-8)*math.log(0.01);
print"Time required in seconds"
print"t=",t
```

In [4]:

```
import math
print"Introduction to heat transfer by S.K.Som, Chapter 4, Example 3"
#Heat transfer coefficient in W/(m**2*K)
h = 30;
#Thermal conductivity of sphere in W/(m*K)
k = 250;
#Biot number for lumped parameter analysis is 0.1
Bi = 0.1;
#Characteristic dimension of a cube is (a/6) where a is the side of cube in metre
#Maximum dimension in metre
a = ((6*k)*Bi)/h;
print"Maximum dimension in metre for lumped parameter analysis"
print"a=",a
```

In [5]:

```
from scipy.integrate import quad
import math
print"Introduction to heat transfer by S.K.Som, Chapter 4, Example 4"
#Diameter of glass in m
d = 50*(10**(-3));
#radius in m
r = d/2;
#Height of milk in glass in m
H = 0.1;
#Initial temperature of milk in Â°C
T = 80.0;
#Cold water temperature in Â°C
Tf = 25.0;
#Heat transfer coefficient in W/(m**2*Â°C)
h = 100.0;
#Thermal conductivity of milk in W/(m*K)
k = 0.6;
#Density of milk in kg/m**3
rho = 900.0;
#Specific heat in J/(Kg*K)
c = 4.2*(10**3);
#Since the milk temperature is always maintained as constant.
#Therefore it can be assumed as lumped paramteter analysis.
#Time constant n seconds
tcs = (((((rho*c)*math.pi)*r)*r)*H)/(((h*math.pi)*d)*H);
#Time constant in minutes
tc = tcs/60;
#Calculating from eq. 4.3 time taken to cool milk from 80Â°C to 30Â°C
t = -tc*math.log((30.0-Tf)/(T-Tf));
print"Time required to cool milk in minutes"
t
#Energy transferred during cooling
E = (((h*math.pi)*d)*H)*quad(lambda t:(80.0-25.0)*math.e*(-t/472.5),0,60.0*t)[0];
print"Energy required for cooling in KJ"
E = E/1000.0
print "E=",E
```

In [6]:

```
import math
print"Introduction to heat transfer by S.K.Som, Chapter 4, Example 5"
#Thermal conductivity of wall in W/(m*K)
k = 0.6;
#Thermal diffusivity in m**2/s
alpha = 5*(10**(-7));
#Thickness in m
L = 0.15;
#Initial temperature in Â°C
Ti = 30;
#Temperature of hot gas in Â°C
Tinfinity = 780;
#Heat transfer coefficient in W/(m**2*K)
h = 20;
#Surface temperaute to be achieved in Â°C
To = 480;
#Dimensionless temperature ratio
z = (To-Tinfinity)/(Ti-Tinfinity);
#Biot number
Bi = (h*L)/k;
#For this value of (1/Bi) and dimensionless temp. ratio
#From Fig. 4.11 Fourier number is
Fo = 0.6;
#Time required in seconds
t = ((Fo*L)*L)/alpha;
print"Time required in hours"
t = t/3600
print"t=",t
#From fig. 4.13, for this Bi and Fo*Bi*Bi, we have ratio of heats as
#Q/Qi=0.69
#Heat transfer in J
Q = ((((0.69*k)*2)*L)*(Tinfinity-Ti))/alpha;
print"Heat transfer rate in MJ"
Q = Q/(10**6)
print"Q=",Q
```

In [7]:

```
import math
print"Introduction to heat transfer by S.K.Som, Chapter 4, Example 6"
#Thickness of plate in m
L = 0.2;
#Initial temperature in Â°C
Ti = 530;
#Heat transfer coefficient in W/(m**2*K)
h = 500;
#Given distance in m
x = L-20*(10**(-3));
#Temperature of surrounding in Â°C
Tinfinity = 30;
#Given time in seconds
t = 225;
#Thermal conductivity of aluminium in W/(m*K)
k = 200;
#Thermal diffusivity in m**2/s
alpha = 8*(10**(-5));
#Biot number
Bi = (h*L)/k;
#Fourier number
Fo = (alpha*t)/(L*L);
#From fig. 4.11, at this Fo and (1/Bi), we have dimensionless temperature
#ratio to be 0.7
#From fig. 4.12 for this (1/Bi) and (x/L), we have another dimensionless
#temperature to be 0.93
#Temperature in Â°C
T = Tinfinity+(0.93*0.7)*(Ti-Tinfinity);
print"Temperature at this distance in Â°C"
print"T=",T
#From fig. 4.13, for this Bi and Fo*Bi*Bi, we have ratio of heats as
#Q/Qi=0.4
#Heat transfer in J
Q = (((0.4*k)*L)*(Ti-Tinfinity))/alpha;
print"Heat transfer rate in MJ"
Q = Q/(10**6)
print"Q=",Q
```

In [8]:

```
import math
print"Introduction to heat transfer by S.K.Som, Chapter 4, Example 7"
#Radius in m
ro = 0.15;
#Initial temperature in Â°C
Ti = 530;
#Temperature of surrounding in Â°C
Tinfinity = 30;
#Heat transfer coefficient in W/(m**2*K)
h = 380;
#Thermal conductivity of aluminium in W/(m*K)
k = 200;
#Thermal diffusivity in m**2/s
alpha = 8.5*(10**(-5));
#Given radius at which temperature has to be find out in m
r = 0.12;
#Given time in seconds
t = 265;
#Fourier number
Fo = (alpha*t)/(ro**2);
#Biot number
Bi = (h*ro)/k;
#From fig. 4.15, at this fourier number,Fo and (1/Bi), we have dimensionless temperature
#ratio to be 0.6
#From fig. 4.16 for this (1/Bi) and (r/ro), we have another dimensionless
#temperature to be 0.9
#Temperature in Â°C
T = Tinfinity+(0.9*0.6)*(Ti-Tinfinity);
print"Temperature at this radius in Â°C"
print"T=",T
#From fig. 4.17, for this Bi and Fo*Bi*Bi, we have ratio of heats as
#Q/Qi=0.4
#Heat transfer per metre in J/m
Q = (((((0.4*k)*math.pi)*ro)*ro)*(Ti-Tinfinity))/alpha;
print"Heat transfer rate per unit length in MJ/m"
Q = Q/(10**6)
print"Q=",Q
```

In [9]:

```
import math
print"Introduction to heat transfer by S.K.Som, Chapter 4, Example 8"
#Radius in m
ro = 0.05;
#Initial temperature in Â°C
Ti = 530;
#Temperature of surrounding in Â°C
Tinfinity = 30;
#Heat transfer coefficient in W/(m**2*K)
h = 500;
#Thermal conductivity of aluminium in W/(m*K)
k = 50;
#Thermal diffusivity in m**2/s
alpha = 1.5*(10**(-5));
#Required centre temperature to achieve in Â°C
To = 105;
#Dimensionless temperature
z = (To-Tinfinity)/(Ti-Tinfinity);
#Biot number
Bi = (h*ro)/k;
#For this value of (1/Bi) and dimensionless temp. ratio
#From Fig. 4.19 Fourier number is
Fo = 1.5;
#Time required in seconds
t = ((Fo*ro)*ro)/alpha;
print"Time required in minutes"
t = t/60
print"t=",t
```

In [10]:

```
import math
print"Introduction to heat transfer by S.K.Som, Chapter 4, Example 9"
#Thermal conductivity of aluminium in W/(m*K)
k = 198;
#Length in m
L = 0.18;
#Breadth in m
b = 0.104;
#Initial temperature in Â°C
Ti = 730;
#Temperature of surrounding in Â°C
Tinfinity = 30;
#Heat transfer coefficient in W/(m**2*K)
h = 1100;
#Thermal diffusivity in m**2/s
alpha = 8.1*(10**(-5));
#Given time in seconds
t = 100;
#Bar can be considered to be an intersection of two infinite plates of
#thickness L1 and L2 in m
L1 = L/2;
L2 = b/2;
#For plate 1
#Fourier number
Fo1 = (alpha*t)/(L1**2);
#Biot number
Bi1 = (h*L1)/k;
#From fig. 4.11, at this Fo and (1/Bi), we have dimensionless temperature
#ratio to be 0.7
#For plate 2
#Fourier number
Fo2 = (alpha*t)/(L2**2);
#Biot number
Bi2 = (h*L2)/k;
#From fig. 4.11, at this Fo and (1/Bi), we have dimensionless temperature
#ratio to be 0.47
#Therefore combined dimensionless temperature ratio is multiply of two
z = 0.47*0.7;
#Temperature in Â°C
T = Tinfinity+z*(Ti-Tinfinity);
print"Tempearture of bar in Â°C"
print"T=",T
```

In [13]:

```
import math
print"Introduction to heat transfer by S.K.Som, Chapter 4, Example 10"
#An iron beam of rectangular cross section of size length,L=300mm by breadth,B=200 mm is used in the construction of a building
#Initially the beam is at a uniform temprature(Ti) of 30Â°C.
#Due to an accidental fire,the beam is suddenly exposed to hot gases at temprature,Tinf=730Â°C,with a convective heat transfer coefficient(h) of 100 W/(m**2*K)
#To determine the time required for the centre plane of the beam to reach a temprature(To) of 310Â°C.
To=310;
Tinf=730;
Ti=30;
#Take thermal conductivity k=73W/(m*K) and thermal diffusivity of the beam alpha=2.034*10**-5m**2/s
alpha=2.034*10**-5;
k=73;
h=100;
#The rectangular iron beam can be considered as an intersection of an infinite plate 1 having thickness 2*L1=300mm and a second infinite plate 2 of thickness 2*L2=200mm
L1=0.15;#in metre
L2=0.10;#in metre
#Here the faactor X=((To-Tinf)/(Ti-Tinf))
print"The factor((To-Tinf)/(Ti-Tinf)) is "
X=((To-Tinf)/(Ti-Tinf))
#Therefore we can write 0.6=((To-Tinf)/(Ti-Tinf))plate 1 *((To-Tinf)/(Ti-Tinf))plate2
#A straight forward solution is not possible.We have to adopt an iterative method of solution
#At first ,a value of time(t) is assumed to determine the centre-line temprature of the beam.The value of t at which((To-Tinf)/(Ti-Tinf))beam =0.6 is satisfied
#Let us first assume time, t=900s
t=900;
print"For plate 1"
#For plate1 Biot number Bi1=h*L1/k
Bi1=h*L1/k
Y=1/Bi1
#Fourier number(Fo1) is
Fo1=alpha*t/L1**2
#At Fo=0.814 and (1/Bi)=4.87...We read from graphs A=((To-Tinf)/(Ti-Tinf))plate1= 0.85
A=0.85;
print"A=",A
print"For plate 2"
#For plate1 Biot number Bi2=h*L2/k
Bi2=h*L2/k
Y=1/Bi2
#Fourier number(Fo2) is
Fo2=alpha*t/L2**2
#At Fo=1.83 and (1/Bi)=7.3...We read from graphs B=((To-Tinf)/(Ti-Tinf))plate2= 0.8
B=0.8;
print"B=",B
#Therefore ((To-Tinf)/(Ti-Tinf))plate1*((To-Tinf)/(Ti-Tinf))plate2=A*B
T=A*B
#Since the calculated value of 0.68 is greater than the required value of 0.60 and Tinf>To>Ti,The assume dvalue of t is less.
#So let us take time,t=1200s for the second iteration
t=1200;
print"For plate 1"
#For plate1 Biot number Bi1=h*L1/k
Bi1=h*L1/k
Y=1/Bi1
#Fourier number (Fo1)
Fo1=alpha*t/L1**2
#At Fo=1.08 and (1/Bi)=4.87...We read from graphs A=((To-Tinf)/(Ti-Tinf))plate1= 0.83
A=0.83;
print"A=",A
print"For plate 2"
#For plate1 Biot number Bi2=h*L2/k
Bi2=h*L2/k
Y=1/Bi2
#Fourier number (Fo2)
Fo2=alpha*t/L2**2
#At Fo=2.44 and (1/Bi)=7.3...We read from graphs B=((To-Tinf)/(Ti-Tinf))plate2= 0.72
B=0.72;
print"B=",B
#Therefore ((To-Tinf)/(Ti-Tinf))plate1*((To-Tinf)/(Ti-Tinf))plate2=A*B
T=A*B
print"The calculated value is very close to the required value of 0.6.Hence the time required for the centre of the beam to reach 310Â°C is nearly 1200s or 20 minutes."
print"T=",T
```

In [14]:

```
import math
print"Introduction to heat transfer by S.K.Som, Chapter 4, Example 11"
#A large slab wrought-iron is at a uniform temprature of Ti=550Â°C.
#The temprature of one surface is suddenly changed to Tinf=50Â°C
Tinf=50;
Ti=550;
#For slab conductivity(k=60W/(m*K)),Thermal diffusivity(alpha=1.6*10**-5m**2/s)
#To calculate the time(t) required for the temprature to reach T=255Â°C at a depth of 80mm
k=60;
T=255;
alpha=1.6**10-5;
#Similarity parameter,eta=x/(2*(alpha*t)**0.5)=(10/t**0.5)
#((T-Tinf)/(Ti-Tinf))=erf(10/t**0.5)...where erf is the error function.
#Let ((T-Tinf)/(Ti-Tinf))=X
X=((T-Tinf)/(Ti-Tinf));
#This implies erf(10/t**0.5)=0.41
#We read from the table the value of eta(=10/t**0.5)=0.38....corresponding to erf(eta)=0.41
#Therefore 10/t**0.5=0.38...this implies t=(10/0.38)**2
print"The time required for the temprature to reach 255Â°C at a depth of 80mm, in minutes is"
t=(10/0.38)**2/60
print"T=",T
```

In [15]:

```
import math
import scipy
print"Introduction to heat transfer by S.K.Som, Chapter 4, Example 12"
#A large block of nickel steel conductivity(k=20W/(m*K)),thermal diffusivity(alpha=0.518*10-5 m**2/s) is at uniform temprature(Ti) of 30Â°C.
Ti=30.0;
k=20.0;
alpha=0.518*10.0**-5.0;
#One surface of the block is suddenly exposed to a constant surface heat flux(qo) of 6MW/m**2.
qo=6*10**6;#in W/m**2
#To determine the temprature at a depth(x) of 100mm after a time(t) of 100 seconds.
t=100.0;
x=0.1;#in metre
#Similarity parameter,eta=x/(4*alpha*t)
eta=x/((4.0*alpha*t)**0.5)
#E is gaussian error function
print"gaussian error function is "
E=scipy.special.erf(eta)
print"E=",E
#The equation to determine temprature is T-Ti=((2*qo(alpha*t/math.pi)**0.5)/(k))*e**((-x**2)/(4*alpha*t))-((qo*x)/(k))*erf(x/(2.0*(alpha*t)**0.5))
#Above equation can also be written as T=Ti+((2*qo(alpha*t/math.pi)**0.5)/(k))*e**((-x**2)/(4*alpha*t))-((qo*x)/(k))*erf(x/(2.0*(alpha*t)**0.5))
print"The temprature at a depth(x) of 100mm after a time(t) of 100 seconds,in Â°C is"
T=Ti+((2*qo*(alpha*t/math.pi)**0.5)/(k))*math.e**((-x**2.0)/(4*alpha*t))-((qo*x)/(k))*scipy.special.erf(x/(2*(alpha*t)**0.5))
print"T=",T
#NOTE:The answer in the book is incorrect(Calculation mistake)
```

In [2]:

```
import math
import numpy
print"Introduction to heat transfer by S.K.Som, Chapter 4, Example 14"
#Nodal distance Deltax in m
deltax = 0.1;
#Time in seconds
t = 25*60;
#timestep deltaT in seconds
deltaT = 500;
#Number of increment
n = t/deltaT;
#Temperature raised in Â°C
To = 580.0;
#Using Eq. 4.114 for interior grid points, table 4.8 for exterior node
#Using Eq. 4.125a to 4.125f are written in matrix form
#Coefficient matrix A is
A = [[-3,1,0,0,0,0],[1,-3,1,0,0,0],[0,1,-3,1,0,0],[0,0,1,-3,1,0],[0,0,0,1,-3,1],[0,0,0,0,2,-3]]
#Coefficient matrix B is
B = [-600,-20,-20,-20,-20,-20];
#Temperature matrix is transpose of [T2 T3 T4 T5 T6 T7] where
#T2 to T7 are temperature in Â°C
#From Eq. 4.126
#Temperature distribution after one time step
T = numpy.linalg.inv(A)*B;
print"Temperature distribution after 25 mins in Â°C"
print"T=",T
```