In [1]:

```
#Unsteady State Diffusion in a Slab of Agar
#Variable declaration
c0 = 0.1 #Concentration of Urea in slab (kg.mol/m3)
c1 = 0. #Concentration of Urea in water (kg.mol/m3)fficient bution
tk = 10.16 #thickness of slab in mm
DAB = 4.72e-10 #Diffusivity of urea in m2/s
t = 10 #Time in hr
kc = inf
xa = 0.0 #Location at centre
xb = 2.54 #Distance from surface in mm
#Calculation
K = 1. #Equilibrium distribution coefficient since aqueous solution and ouside solution have very simillar properties
x1 = tk/(1000*2)
X = DAB*(t*3600)/x1**2
n = xa/x1
m = DAB/(K*kc*x1)
#from fig 5.3-5
X = 0.658
Y =0.275
#Calculation for part (a)
ca1 = (c1/K) - Y*(c1/K - c0)
x = (tk/2 - xb)/1000
n = xb/x1
#from fig 5.3-5
Y = 0.172
ca2 = (c1/K) - Y*(c1/K - c0)
#Calculation for part (b)
X = X/(0.5**2)
#from fig 5.3-5
Y = 0.0020
cb = (c1/K) - Y*(c1/K - c0)
#Result
print 'Part a'
print "The concentration at x=0 ",ca1,"kmol/m3"
print "The concentration at 2.54 mm ",ca2,"kmol/m3"
print 'Part b'
print 'The concentration at the mid-point of the slab %4.1e'%(cb),"kmol/m3"
```

In [6]:

```
#Unsteady-State Diffusion in Semi-Infinite Slab
from math import sqrt
#Variable declaration
c0 = 1.e-2 #Concentration of solute A in slab (kg.mol A/m3)
c1 = 0.1 #Concentration of solute A in moving fluid (kg.mol A/m3)
Kc = 2.e-7 #Convective coeffcient (m/s)
K = 2. #Equilibrium distribution coefficient
x1 = 0.0 #Location where cetre lies
x2 = 0.01 #LOcation from the centre, m
t = 3.e4 #Given time (s)
DAB = 4.e-9 #Diffusivity in the solid (m2/s)
cb = 3.48e-2 #Value taken from the Fig. 7.1-3b
#Calculation
absc = x2/sqrt(DAB*t)
param = K*Kc*sqrt(DAB*t)/DAB
# from fig 5.3-3 1-Y = 0.26
ord = 0.26
Y = 1.-ord
cs = (1 - Y)*(c1/K - c0) + c0
# At surface
absc = x1/2*sqrt(DAB*t)
#from fig 5.3-3 1-Y = 0.62 at x=0 and absc
ord =0.62
Y = 1 - ord
ca = (1 - Y)*(c1/K - c0) + c0
CLi = K*cb
#Result
print "The concentration of solid at surface (x=0) is ",cs,"kmol/m3"
print 'The concentration of solid at (x=0.01m) is %5.2e'%(ca),"kmol/m3"
```

In [17]:

```
#Vaporizing A and Convective Mass Trasfer
from math import log
# Variable declaration
P = 2. #Total Pressure over the nevaporating surface (atm)
Pa1 = 0.2 #Partial vapour pressure of A over the surface (atm)
Pa2 = 0. #Partial vapour pressure of B over the surface (atm)
Kydash = 6.78e-5
# Calculation
Ya1 = Pa1/P
Ya2 = Pa2/P
Yb1 = 1. - Ya1
Yb2 = 1. - Ya2
Ybm = (Yb2 - Yb1)/log(Yb2/Yb1)
ky = Kydash/Ybm #eqn A
kg1 = ky/(P*101325) #eqn B
kg2 = ky/P #eqn C
Na = ky*(Ya1 - Ya2) #eqn 1
pa1 = Pa1*101325.
pa2 = Pa2*101325.
Na1 = kg1*(pa1-pa2) #eqn 2
Na2 = kg2*(Pa1-Pa2) #eqn 3
#Result
print 'The calculated value of ky is %5.3e kgmol/s.m2.molfrac from #eqn A'%(ky)
print 'The calculated value of kg is %5.3e kgmol/s.m2.Pa #eqn B'%(kg1)
print 'The calculated value of kg is %5.3e kgmol/s.m2.atm #eqn C'%(kg2)
print 'The calculated value of the Flux is %5.3e kgmol/s.m2 #eqn 1'%(Na)
print 'The calculated value of the Flux is %5.3e kgmol/s.m2 from #eqn 2'%(Na1)
print 'The calculated value of the Flux is %5.3e kgmol/s.m2 from #eqn 3'%(Na2)
```

In [17]:

```
#Mass Transfer Inside a Tube
# Variable declaration
Dab = 6.92e-6 #Diffusivity of solid (m2/s)
Pai = 74. #Vapor pressure of A (Pa)
R = 8314.3 #Gas constant in (Pa.m3/(K.Kmol))
T = 318. #Temperature in (K)
Cao = 0.0 #Inlet concentration (kg.mol A/m3)
mu = 1.932e-5 #Viscosity of air (Pa.s)
Rho = 1.114 #Density of air (kg/m3)
D = 0.02 #Diameter of the tube (m)
L = 1.1 #Length of the tube (m)
V = 0.8 #Velocity of fluid (m/s)
# Calculation
Cai = Pai/(R*T)
Nsc = mu/(Rho*Dab)
Nre = D*V*Rho/mu
#Hence the flow is laminar
abscisa = Nre*Nsc*D*pi/(4*L) #From fig 7.3-2
ordinate = 0.55
Ca = Cao + ordinate*(Cai-Cao)
#Result
print 'Schmidt Number %4.3f'%Nsc
print 'Reynolds Number %4.1f'%Nre
print 'Concentration of Napthalene in exit Air: %5.3e' %(Ca),"kmol/m3"
```

In [18]:

```
#Mass Transfer from a Flat Plate
# Variable declaration
L = 0.244 #Length of the flat plate (m)
V = 0.061 #Velocity of water (m/s)
mu = 8.71e-4 #Viscosity of water (Pa.s)
Rho = 996. #Density of water (kg/m3)
Dab = 1.245e-9 #Diffusivity of benzoic acid (m2/s)
Ca1 = 2.948e-2 #Initial concentration (kg.mol A/m3)
Ca2 = 0. #Final concentration (kg.mol A/m3)
# Calculation
Nsc = mu/(Rho*Dab)
Nre = L*V*Rho/mu
Jd = 0.99*Nre**-0.5
Kcd = Jd*V/Nsc**(2./3.)
#Since the solution is very dilute
Xbm = 1.
Kc = Kcd
Na = Kc*(Ca1 - Ca2)/Xbm
#Result
print 'Schmidt Number %4.3f'%Nsc
print 'Reynolds Number %4.3e'%Nre
print 'Mass Transfer Coefficient %5.2e m/s'%(Kc)
print 'Flux of A through liquid:%5.3e kmol/(s.m2)'%(Na)
```

In [23]:

```
#Mass Transfer from a Sphere
from math import pi
#Variable declaration SI units
Tdeg = 45 #Temperature in deg C
v = 0.305 #Velocity of air m/s
dp = 0.0254 #Diameter of the sphere m
Dab = 6.92e-6 #Diffusivity of napthalene in air (m2/s)
pa0 = 0.555 #Vapor pressure of solid napthalene mm Hg
mu = 1.93e-5 #Viscosity of air (Pa.s)
rho = 1.113 #Density of air (kg/m3)
R = 8314 #Gas constant (Pa.m3/K.Kmol)
P = 760 #Atmospheric pressure in mm Hg
#Calculation
Tk = Tdeg+ 273
Nsc = mu/(Dab*rho)
Nre = dp*v*rho/mu
Nsh = 2 + 0.552*Nre**0.53*Nsc**(1./3)
kcd = Nsh*Dab/dp
kGd = kcd/(R*Tk)
# For dilute solutions kgd = kg, ybm = 1
kG = kGd
pa1 = pa0/P
pa1 = pa1*101325
pa2 = 0.0 #for pure air
Na = kG*(pa1-pa2)
A = pi*dp**2
Ae = Na*A
#Result
print "Results in SI units"
print 'Schmidt Number %4.3f'%Nsc
print 'Reynolds Number %4.0f'%Nre
print 'Mass transfer coefficient kcd= %5.3e' %(kcd),"m/s"
print 'Mass transfer coefficient KGd= %5.3e' %(kGd),"kmol/(s.m2)"
print "Flux of Napthalene evaporation", round(Na,10),"kmol/(s.m2)"
print 'Total amount evaporated: %5.3e kmol/s'%Ae
print
#Calculation
R = 0.73
#Unit conversion to English units
mu = mu*2.4191e3 #Viscosity of air (lbm/(ft.h))
Dab = Dab*3.875e4 #Diffusivity of napthalene in air (ft2/h)
dp = dp*3.2808 #Diameter of the sphere ft
rho = rho/16.0185 #Density of air (lbm/ft3)
v = v*3600*3.2808 #Velocity of air ft/h
T = Tk*1.8 #Temperature in Rankine
Nsc = mu/(Dab*rho)
Nre = dp*v*rho/mu
Nsh = 2 + 0.552*Nre**0.53*Nsc**(1./3)
#print Nsc, Nre, Nsh
kcd = Nsh*Dab/dp
kGd = kcd/(R*T)
# For dilute solutions kgd = kg, ybm = 1
kG = kGd
pa1 = pa0/P
pa2 = pa2/P #for pure air
Na = kG*(pa1-pa2)
A = pi*dp**2
Ae = Na*A
#Result
print "Results in English units"
print 'Schmidt Number %4.3f'%Nsc
print 'Reynolds Number %4.0f'%Nre
print 'Mass transfer coefficient kcd=%5.1f' %(kcd),"ft/h"
print 'Mass transfer coefficient KGd= %6.5f' %(kGd),"lbmol/(h.ft2)"
print 'Flux of Napthalene evaporation %5.2e'%(Na),"lbmol/(h.ft2)"
print 'Total amount evaporated: %5.3e lbmol/h'%Ae
```

In [29]:

```
#Mass Transfer of a Liquid in a Packed Bed
from scipy.optimize import root
from math import pi,log
#Variable declaration
Tdeg = 26.1 #Temperature in deg C
Q = 5.514e-7 #Flowrate of benzoic acid (m3/s)
d = 0.006375 #Diameter of sphere (m)
As = 0.01198 #Total surface area of the sphere m2
epsilon = 0.436 #Void fraction
Dt = 0.0667 #Diameter of the tower in m
Cai = 2.948e-2 #Inlet concentration (kg.mol A/m3)
Ca1 = 0.0
kce = 4.665e-6 #Experimental value of the mass transfer coefficient in m2/s
mu261 = 0.8718e-3 #Viscosity of solution at 26.1 deg C (Pa.s)
rho261 = 996.7 #Density of the solution in (kg/m3)
mu250 = 0.8940e-3 #Viscosity of solution at 25 deg C (Pa.s)
Dab = 1.21e-9 #DIffusivity of benzoic acid (m2/s)
#Calculation
Tk = Tdeg + 273
#Dab ~ T/mu
Dab261 = Dab*(Tk/298)*(mu250/mu261)
At = pi*Dt**2/4
v = Q/At
Nsc = mu261/(rho261*Dab261)
Nre = d*v*rho261/mu261
Jd = (1.09/epsilon)*Nre**(-2./3)
kcd = Jd*v/Nsc**(2./3)
f = lambda x:Q*(x-Ca1)-As*kcd*(((Cai-Ca1)-(Cai-x))/log((Cai-Ca1)/(Cai-x)))
sol = root(f,1e-3)
Ca2 = sol.x[0]
#Result
print 'Schmidt Number %4.1f'%Nsc
print 'Reynolds Number %4.3f'%Nre
print 'Mass Transfer Coefficient:%5.2e m/s This compares with expt. value of %5.3e m/s'%(kcd,kce)
print 'Concentration of Benzoic acid in Water:%5.3e'%(Ca2),"kgmol/m3"
```

In [32]:

```
#Mass Transfer from Air Bubbles in Fermentation
# Variable declaration
P = 1.0 #Absolute pressure of bubbles, atm
d = 100e-6 #Diameter of bubbles, m
Ca1 = 2.26e-4 #Solubility of O2 in water, kmol O2/m3
D = 3.25e-9 #Diffusivity of O2 in water, m2/s
mu37 = 6.947e-4 #Viscosity of water at 37 °C, Pa.s
rhow = 994 #density of water at 37 °C, kg/m3
rhoa = 1.13 #Density of air at 37 °C, kg/m3
g = 9.806 #Gravitational acceleration (m/s2)
Ca2 = 0.0
#Calculations
Nsc = mu37/(rhow*D)
delP = rhow-rhoa
kld = 2*D/d + 0.31*Nsc**(-2./3)*(delP*mu37*g/rhow**2)**(1./3)
kl = kld
Na = kl*(Ca1-Ca2)
#Result
print 'Schmidt Number %4.1f'%Nsc
print 'Maximum rate of absorption per unit area is %3.2e kmol O2/m2' %Na
```

In [33]:

```
#Diffusion of Chemical Reaction at Boundary
from scipy.optimize import root
from math import log
#Variable Declaration
Pa1 = 101.32 #Partial pressure of gas A (kPA)
d = 2.e-3 #Distance between point A and B (m)
Pt = 101.32 #Total pressure (kPa)
T = 300. #Temperature in K
Dab = 0.15e-4 #Diffusivity of gas A (m2/s)
K1 = 5.63e-3
R =8314.
#Calculation
#Calculation for part (a)
c = Pt*1000./(R*T)
xa1 = Pa1*1000./(Pt*1000.)
xa2 = 0./ Pt
Na = c*Dab*log((1+xa1)/(1+xa2))/d
#Calculation for part (b)
f = lambda z: z - c*Dab/d*log((1+xa1)/(1+z/(c*K1)))
sol = root(f,0.00005)
Nb = sol.x[0]
xa2b = Nb/(c*K1)
#Result
print 'a) The calculated value of flux for instantaneous rate of reaction is %4.3e kgmol A/s.m2'%(Na)
print 'b) The calculated value of flux for slow reaction is %5.3e kgmol A/s.m2'%(Nb)
print 'c) The fraction of A in liquid for slow reaction is %4.3f'%(xa2b)
```

In [34]:

```
#Reaction and Unsteady State Diffusion
from math import erf, sqrt,pi,e
#Variable Declaration
P = 101.32 #Pressure in (kPa)
k = 35. #First order reaction (1/s)
Dab = 1.5e-9 #Diffusivity of CO2 in (m2/s)
s = 2.961e-7 #Solubility of CO2 (kg mol/m3.Pa)
t = 0.01 #Time for which surface is exposed to gas (s)
#Calculations
Ca0 = s*P*1000.
Q = Ca0*sqrt(Dab/k)*((k*t+0.5)*erf(sqrt(k*t)) + sqrt(k*t/pi)*e**(-k*t))
#Results
print 'CO2 absorbed on the surface %5.3e kgmolCO2/m2'%(Q)
```

In [38]:

```
#Diffusion of A Through Nondiffusing B and C
from math import log
#Variable Declaration
P = 1. #Total presure in (atm)
P_SI = 1.01325e5 #Total pressure in (Pa)
T = 298. #Temperature in (K)
z1 = 0. #Starting point (m)
z2 = 0.005 #End point (m)
pa1 = 0.4 #Initial Partial pressure of methane (atm)
pb1 = 0.4 #Initial Partial pressure of argon (atm)
pc1 = 0.2 #Initial Partial pressure of helium (atm)
pa2 = 0.1 #Final Partial pressure of methane (atm)
pb2 = 0.6 #Final Partial pressure of argon (atm)
pc2 = 0.3 #Final Partial pressure of helium (atm)
Dab = 2.02e-5 #Binary Diffusivities (m2/s)
Dac = 6.75e-5 #Binary Diffusivities (m2/s)
Dbc = 7.29e-5 #Binary Diffusivities (m2/s)
R = 82.06e-3 #Gas constant (atm.m3/Kmol.K)
R_SI = 8314 #Gas constant (Pa.m3/Kmol.K)
#Calculations
xb_1 = pb1/(1-pa1)
xb_2 = pb2/(1 - pb1)
xc_ = pc1/(1 - pa1)
Dam = 1/((xb_1/Dab)+(xc_/Dac))
pi1 = P - pa1
pi2 = P - pa2
pim = (pi2-pi1)/log(pi2/pi1)
pim_SI = pim*(1.01325e5)
pa1_SI = pa1*(1.01325e5)
pa2_SI = pa2*(1.01325e5)
Na_SI = Dam*P_SI*(pa1_SI - pa2_SI)/(R_SI*T*(z2-z1)*pim_SI)
Na = Dam*P*(pa1 - pa2)/(R*T*(z2-z1)*pim)
#Results
print 'The flux calculated is NA= %5.2e kgmol A/(s.m2) using Pa pressure units'%Na_SI
print 'The flux calculated is NA= %5.2e kgmol A/(s.m2) using atm pressure units'%Na
```

In [69]:

```
#Knudsen Diffusion of Hydrogen
#Variable Declaration
P = 1.01325e4 #Total pressure in (Pa)
T = 373. #Temperature in (K)
r = 60. #Radius of the pore in (angstorm)
Ma = 2.016
#Calculations
r_SI = r*1.e-10 #Radius in(m)
Dka = 97.*r_SI*(T/Ma)**0.5
#Results
print 'The calculated Knudsen Diffusivity is %4.2e m2/s'%(Dka)
```

In [44]:

```
#Transition-Region Diffusion of He and N2
from math import sqrt
#Variable Declaration
T = 298. #Temperature of gas (K)
r = 2.5e-6 #Radius of the capillary (m)
L = 0.01 #Length of the capillary (m)
P = 1.013e4 #Total Pressure of the gas mixture (Pa)
xa1 = 0.8 #Mole fraction of N2 at one end
xa2 = 0.2 #Mole fraction of N2 at another end
Dab = 6.98e-5 #Molecular Diffusivty at one atmosphere (m2/s)
Ma = 28.02 #Molecular weight of nitrogen
Mb = 4.003
R = 8314.
#Calculations
Dabc = Dab/0.1 #Molecular Diffusivity at 0.1 (m2/s)
Dka = 97.0*r*(T/Ma)**.5
NbbyNa = -sqrt(Ma/Mb)
alpha = 1. + NbbyNa
Na = Dabc*P/(alpha*R*T*L)*log( (1. - alpha*xa2 + Dabc/Dka)/(1. - alpha*xa1 + Dabc/Dka))
Dnad = 1./(1./Dabc + 1./Dka)
Naf = Dnad*P*(xa1 - xa2)/(R*T*L) #Eqn A
xAav = (xa1 + xa2)/2.
Dacc = 1./( 1./Dka + (1. - alpha*xAav)/Dabc)
Nacc = Dacc*P*(xa1 - xa2)/(R*T*L) #Eqn B
#Results
print 'The flux at steady state is NA= %5.2e kg mol/s.m2'%(Na)
print 'The approximate flux at steady state using two different equations\nA) %5.2e kgmol/(s.m2) by Eqn A and'%(Naf)
print 'B) %5.2e kgmol/(s.m2) by eqn B' %(Nacc)
```

In [86]:

```
#Numerical Solution for Unsteady-State Diffusion with a Distribution Coefficient
import numpy as np
import copy
import matplotlib.pyplot as plt
#Variable Declaration
t = 0.004 #Thickness of the material (m)
Dab = 1.e-9 #Diffusivity of material (m2/s)
ca = 6.e-3 #Concentration of fluid (kg mol A/m3)
K = 1.5 #Distribution coefficient
delx = 0.001
M = 2.
tmax = 2500
xm = np.arange(1,5,1)
c = np.array([1.e-3,1.25e-3,1.5e-3,1.75e-3,2.e-3])
n = np.array([1,2,3,4,5])
#Calculations
plt.plot(n,c, 'bo-')
plt.xlabel('Node number, n')
plt.ylabel('concentration c, kgmol/m3')
delt = delx**2/(2*Dab)
m = tmax/int(delt)
Ccal = [0,0,0,0,0]
t = 0
print "After",t,"s"
for i in range(len(n)):
print "At ",i+1,'th node, the value of concentration is %6.3e kgmol/m3'%c[i]
for i in range(1,6,1):
t = delt*i
#print c
for j in range(len(c)):
if j==0:
if i == 1:
Ccal[j]= (ca/K+c[j])/2
else:
Ccal[j]= ca/K
elif j>=1 and j<(len(c)-1):
Ccal[j]=(c[j-1]+c[j+1])/2.
#print c[j-1], c[j+1], Ccal[j]
else:
Ccal[j]=c[j-1]
c = copy.copy(Ccal)
print "After",t,"s"
for i in range(len(n)):
print "At ",i+1,'th node, the value of concentration is %6.3e kgmol/m3'%c[i]
#Results
plt.plot(n,c,'ro-')
print 'The results are different than book because for first iteration at second node\nThe value of c(0,1)= 1e-3 is taken as 2.5e-3, which is wrong substitution'
```