In [1]:

```
#Membrane Diffusion and Liquid Film Resistances
#Variable declaration
C1 = 3.e-2 #The concentration of solute A (mol.kg/m3)
L = 3.e-5 #Thickness of the membrane (m)
K = 1.5 #The distribution coefficient
Dab = 7.e-11 #The distribution coefficient
C2 = 0.5e-2 #Concentration on the other side (mol.kg/m3)
kc2 = 2.02e-5 #Mass transfer cofficient (m/s)
#Calculation
#Part (a) is therotical
#Calculation for part (b)
#p_M = D_ab*K/L
pM = Dab*K/L
#N_a = (C_1 - C_2)/(1/p_M + 1/k_c2)
Na = (C1 - C2)/(1/pM + 1/kc2)
#To calculate C_2i
#N_a = k_c2*(C_2i - C_2)
#C_2i = N_a/k_c2 + C_2
C2i = Na/kc2 + C2
#K = C_2is/C_2i
#C_2is = K*C_2i
C2is = K*C2i
#Result
print 'The flux at the interface membrane is %5.3e kg.mol/s.m2'%(Na)
print 'The concentration at the interface membrane is %5.3e kg.mol/m3'%(C2is)
```

In [8]:

```
#Dialysis to Remove Urea from Blood
#Variable declaration
kc1 = 1.25e-5 #Estimated blood side mass transfer cofficient (m/s)
kc2 = 3.33e-5 #Estimated aqueous side mass transfer cofficient (m/s)
pM = 8.73e-6 #Permeability of the membrane (m/s)
c1 = 200. #Concentration of urea in blood (g/m3)
c2 = 0. #Concentration of urea in dialyzing fluid (g/m3)
t = 3600. #Time given for blood removal (sec)
A = 2. #Area of membrane (m2)
#Calculation
Na = (c1 - c2)/(1/kc1 + 1/pM + 1/kc2)
R = Na*t*A
#Result
print 'The flux of urea through membrane %5.2e g/(m2.s)'%(Na)
print 'The rate of removal of urea from membrane is %5.3f g Urea/h'%(R)
```

In [2]:

```
#Design of Membrane Unit for Complete Mixing
#Variable declaration
qf = 1.e4 #Feed flow rate (STP/s)
xf = 0.5 #Mole fraction of A in feed
x0 = 0.25 #The desired composition of the reject
t = 2.54e-3 #Thickness of membrane (cm)
ph = 80. #Pressure on feed side (cm Hg)
pl = 20. #Pressure on permeate side (cm Hg)
PA = 50e-10 #Permeability of A (cm3(STP).cm/s.cm2.cmHg)
PB = 5e-10 #Permeability of B (cm3(STP).cm/s.cm2.cmHg)
#Calculation
alpha = PA/PB
a = 1 - alpha
b = (ph/pl)*(1 - x0) - 1 + alpha*(ph/pl)*x0 + alpha
c = -alpha*x0*(ph/pl)
yp = (-b + sqrt(b**2 - 4*a*c))/(2*a)
#x_0 = (x_f - theta*Y_p)/(1 - theta)
theta = (x0 - xf)/(x0- yp)
Am = theta*qf*yp/((PA/t)*(ph*x0-pl*yp))
#Result
print 'The membrane area calculated is %5.3e cm2 or %5.3e m2'%(Am, Am/1e4),""
```

In [3]:

```
#Membrane Design for Seperation of Air
#Variable declaration
qf = 1.e6 #Feed flow rate (STP/s)
t = 1.e-3 #Thickness of membrane (cm)
ph = 190. #Pressure on feed side (cm Hg)
p1 = 19. #Pressure on permeate side (cm Hg)
PA = 500e-10 #Permeability of A (cm3(STP).cm/s.cm2.cmHg)
xf = 0.209 #Mole fraction of A in feed
alpha = 10. #oxygen permeability divided by nitrogen permeability
theta = 0.2 #Fraction cut
t = 2.54e-3 #Thickness of membrane (cm)
#Calculation
a1 = theta + p1/ph - (p1/ph)*theta - alpha*theta - alpha*(p1/ph) + alpha*theta*(p1/ph)
b1 = 1 - theta - xf - (p1/ph) + (p1/ph)*theta + alpha*theta + alpha*(p1/ph) - alpha*theta*(p1/ph) + alpha*xf
c1 = -alpha*xf
yp = (-b1 + sqrt(b1**2 - 4*a1*c1))/(2*a1)
x0 = (xf - theta*yp)/(1 - theta)
Am = theta*qf*yp/((PA/t)*(ph*x0 - p1*yp))
#Result
print "The permeate composition is ",round(yp,4)
print "The reject composition is ",round(x0,4)
print 'The area of membrane is %5.3e cm2'%(Am)
```

In [4]:

```
#Effect of Feed Composition on Minimum Reject Concentration
#Variable declaration
qf = 1.e4 #Feed flow rate (STP/s)
xf = 0.5 #Mole fraction of A in feed
x0 = 0.25 #The desired composition of the reject
t = 2.54e-3 #Thickness of membrane (cm)
ph = 80. #Pressure on feed side (cm Hg)
pl = 20. #Pressure on permeate side (cm Hg)
PA = 50e-10 #Permeability of A (cm3(STP).cm/s.cm2.cmHg)
PB = 5e-10 #Permeability of B (cm3(STP).cm/s.cm2.cmHg)
#Calculations
# for xf = 0.5
alpha = PA/PB
xoM =xf*(1+(alpha-1)*pl/ph*(1-xf))/(alpha*(1-xf)+xf)
print "Reject Concentration for xf = 0.50:",round(xoM,4)
# for xf = 0.65
xf = 0.65
alpha = PA/PB
xoM =xf*(1+(alpha-1)*pl/ph*(1-xf))/(alpha*(1-xf)+xf)
print "Reject Concentration for xf = 0.65:",round(xoM,4)
```

In [5]:

```
#Design of Membrane Unit for Multicomponenet Mixture
#Variable declaration
qf = 1.e4 #Feed flow rate (STP/s)
xfA = 0.25 #Mole fraction of A in feed
xfB = 0.55 #Mole fraction of B in feed
xfC = 0.20 #Mole fraction of A in feed
x0 = 0.25 #The desired composition of the reject
t = 2.54e-3 #Thickness of membrane (cm)
ph = 300. #Pressure on feed side (cm Hg)
pl = 30. #Pressure on permeate side (cm Hg)
PA = 200e-10 #Permeability of A (cm3(STP).cm/s.cm2.cmHg)
PB = 50e-10 #Permeability of B (cm3(STP).cm/s.cm2.cmHg)
PC = 25e-10 #Permeability of C (cm3(STP).cm/s.cm2.cmHg)
theta = 0.25 #Fraction to be permeated
#Calculations
qp = theta*qf
ypA = 0.501
eR = 1.
while abs(eR) >= 0.000001:
Am = qp*ypA*t/(PA*(ph/(1-theta)*(xfA-theta*ypA)-pl*ypA))
ypB = ph*xfB/((1-theta)*(qp*t/(PB*Am)+theta*ph/(1-theta)+pl))
ypC = ph*xfC/((1-theta)*(qp*t/(PC*Am)+theta*ph/(1-theta)+pl))
syp = ypA + ypB + ypC
eR = 1.- syp
ypA = ypA + eR/3.4
ypA = ypA - eR/3.4
xoA = xfA/(1-theta)-theta*ypA/(1-theta)
xoB = xfB/(1-theta)-theta*ypB/(1-theta)
xoC = xfC/(1-theta)-theta*ypC/(1-theta)
sxo = xoA + xoB + xoC
print "Permeate compositions are yoA, yoB, yoC"
print round(ypA,4), round(ypB,4), round(ypC,4),"respectively for A,B,C"
print "Reject compositions are xoA, xoB, xoC"
print round(xoA,4), round(xoB,4), round(xoC,4),"respectively for A,B,C"
print 'Membrane area %10.4e'%(Am),"cm2"
```

In [97]:

```
#Design of Membrane Unit Using Cross Flow
import numpy as np
from scipy.interpolate import interp1d
from scipy.integrate import quad, simps
from scipy.optimize import root
from math import sqrt
#Variable declaration
qf = 1.e6 #Feed flow rate (STP/s)
t = 1e-3 #Thickness of membrane (cm)
ph = 190. #Pressure on feed side (cm Hg)
pl = 19. #Pressure on permeate side (cm Hg)
PA = 500e-10 #Permeability of A (cm3(STP).cm/s.cm2.cmHg)
xf = 0.209 #Mole fraction of A in feed
alpha = 10. #oxygen permeability divided by nitrogen permeability
theta = 0.2 #Fraction cut
tk = 2.54e-3 #Thickness of membrane (cm)
x0 = np.array([0.1190,0.1420,0.1642,0.1870,0.2090])
#Calculation
np.set_printoptions(precision=3)
sorted(x0)
thetas = np.zeros((len(x0)))
u = np.zeros(len(x0))
iI = np.zeros(len(x0))
fi = np.zeros((len(x0)))
Fi = np.zeros((len(x0)))
yp = np.zeros((len(x0)))
iF = xf/(1.-xf)
D = 0.5*((1.-alpha)*pl/ph+alpha)
F = -0.5*((1.-alpha)*pl/ph-1.)
E = alpha/2.-D*F
R = 1./(2*D-1.)
S = (alpha*(D-1.)+F)/((2.*D-1.)*(alpha/2.-F))
T = 1./(1-D-E/F)
uf = -D*iF+sqrt(D**2*iF**2+2.*E*iF+F**2)
print ' thetas[j] x yp Fi '
for j in range(len(x0)):
i = iI[j] = x[j]/(1.-x[j])
u = -D*i+sqrt((D*i)**2 + 2*E*i + F**2)
k1 = ((uf-E/D)/(u-E/D))**R
k2 = ((uf-alpha+F)/(u-alpha+F))**S
k3 = ((uf-F)/(u-F))**T
k0 = (1-xf)/(1-x[j])
thetas[j] = 1.- k0*k1*k2*k3
fi[j] = (D*i-F) + sqrt(D**2*i**2 + 2*E*i+F**2)
Fi[j] =(1-thetas[j])*(1-x0[j])/((fi[j]-i)*(1./(1.+ i)-(pl/ph)*(1./(1.+fi[j]))))
if thetas[j]==0.0:
f = lambda y: y/(1-y) - alpha*(x0[j]-pl*y/ph)/((1-x0[j])-pl*(1-y)/ph)
sol = root(f,0.6)
yp[j] = sol.x[0]
else:
yp[j] = (xf-x0[j]*(1.0-thetas[j]))/thetas[j]
print '%8.5f %8.5f %8.5f %8.5f '%(thetas[j], x0[j], yp[j],Fi[j])
Fun = interp1d(iI,Fi)
I = quad(Fun,iI[0],iI[len(x0)-1])[0]
Am = tk*qf/(ph*PA/alpha)*I
#Result
#Part A
print "PART A"
print 'Reject composition x0: %4.3f'%x0[0]
print 'Permeate composition yp: %4.3f'%yp[0]
print 'Total Membrane Area: %6.4e cm2'%(Am)
#Part B
print "PART B"
print 'For PART B of Example 13.4-2 The permeate composition was 0.5068 as compared to %4.3f for cross flow' %yp[len(x0)-1]
print 'For PART B of Example 13.4-2 The area of membrane was 3.2314e+08 cm2 as compared to %5.4e cm2 \nfor cross flow'%(Am)
```

In [7]:

```
#Calculation of Osmotic Pressure of Salt Solution
#Variable declaration
T = 298.5 #Temperature of solution (k)
Rho = 997. #Density of the solution (kg/m3)
m = 0.1 #Moles of NaCl present (g.mol)
R = 82.057e-3 #Gas constant
#Calculations
n = (2*m)*1.e-3
Vm = 1/Rho
Pi = n*R*T/(Vm)
#Result
print "The calculated osmotic pressure is ",round(Pi,2),"atm"
```

In [14]:

```
#Experimental Determination of Membrane Permeability
#Variable declaration
R = 82.057e-3 #Gas constant
c1 = 10.0 #KgNaCl/m3 solution at inlet
c2 = 0.39 #Concentration of salt in outlet, KgNaCl/m3 solution
rho1 = 1004 #Density of inlet solution, Kg/m3
rho2 = 997.0 #Density of outlet solution, Kg/m3
delP = 54.42 #Pressure difference across membrane, atm
A = 2.0e-3 #Area of membrane, m2
V = 1.92e-8 #Flow rate of product, m3solution/s
MW = 58.45 #Molecular Wt of NaCl
#Calculations
Nw = V*rho2/A
Ns = Nw*c2/rho2
C1 = c1*1000/((rho1-c1)*MW) #molNaCL/kgwater in inlet water
pi1 = 7.80 #from table 13.9-1 obtained by interpolation,atm
cw2 = rho2-c2
C2 = c2*1000/((cw2)*MW) #molNaCL/kgwater in outgoing water
pi2 = 0.32 #from table 13.9-1 obtained by interpolation, atm
delpi = pi1-pi2
Aw = Nw/(delP-delpi)
As = Ns/(c1-c2)
R = (c1-c2)/c1
B = Aw/(As*cw2)
R = B*(delP-delpi)/(1+B*(delP-delpi))
#Result
print 'Solvent Permeability constant Aw =%6.4e kg solvent/(m2.s.atm)'%(Aw)
print 'Solute Permeability constant As=%6.4e m/s'%(As)
print "Solute Rejection R=", round(R,4)
```

In [8]:

```
#Prediction of Performance in a Reverse-Osmosis Unit
#Variable declaration
c1 = 2.5 #Concentration of NaCl (kg NaCl/m3)
rho1 = 999. #Density of the solution (kg/m3)
Aw = 4.81e-4 #Permeability constant for water (kg/s.m2)
As = 4.42e-7 #Permeabilty constant for NaCl solute (kg/s.m2)
delP = 27.2 #Pressure drop across the membrane (atm)
c2 = 0.1 #Assumed Concentration of Product solution (kg NaCl/m3)
rho2 = 997. #Density of the product solution (kg/m3)
MW = 58.45 #Molecular weight of NaCl
#Calculations
cw2 = rho2
C1 = (c1*1000)/((rho1-c1)*MW) #molNaCL/kgwater in inlet water
pi1 = 1.97 #from table 13.9-1 obtained by interpolation,atm
C2 = c2*1000/((rho2-c2)*MW) #molNaCL/kgwater in outgoing water
pi2 = 0.08 #from table 13.9-1 obtained by interpolation, atm
delpi = pi1-pi2
Nw = Aw*(delP - delpi)
B = Aw/(As*cw2)
R = B*(delP - delpi)/(1. + B*(delP - delpi))
c2 = c1 - R*c1
Ns = As*(c1-c2)
#Result
print 'Water flux through membrane Nw= %6.4e kg Water/(m2.s)'%(Nw)
print 'Solute flux through membrane Ns=%6.4e kg NaCl/(m2.s)'%(Ns)
print 'Solute Rejection rate is R=%4.3f' %(R)
```