{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 4 : Material Balances Involving Chemical Reactions"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.1   Page 116"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Percentage conversion =  89.2001241751\n",
      "  Percentage yield of MCA =  92.8448972013\n",
      "  selectivity of MCA =  12.976039592\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "# Variables \n",
    "\n",
    "# basis one day operation\n",
    "# Cl2 is the limiting component\n",
    "n1 = 4536./71               #[kmol] Cl2 charged\n",
    "\n",
    "# 1mol MCA requires 1 mol Cl2, so\n",
    "n2 = 5000/94.5              # [kmol] Cl2 used for MCA production\n",
    "\n",
    "# Calculation \n",
    "# 1 mol DCA requires 2 mol of Cl2\n",
    "n3 = 263*2./129             #[kmol] Cl2 used for DCA production\n",
    "n4 = n2+n3                  # total Cl2 used\n",
    "a = n4*100/n1               # conversion %age\n",
    "b = n2*100/n4               # yield % of MCA\n",
    "s = n2/n3\n",
    "\n",
    "# Result\n",
    "print \"Percentage conversion = \",a\n",
    "print \"  Percentage yield of MCA = \",b\n",
    "print \"  selectivity of MCA = \",s\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.2   Page 117"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a  Yield of OT =  72.8790087464\n",
      "   b  Excess quantity of iron powder =  11.8367346939\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "# Variables \n",
    "m = 700.                        #[kg] ONT charged to reactor (basis)\n",
    "m1 = 505*.99                    # [kg] OT produced\n",
    "\n",
    "# Calculation \n",
    "m2 = (4*137.*500)/(4.*107)      #[kg] ONT required\n",
    "m3 = m*.98                      # [kg] ONT reacted\n",
    "n1 = m1*100/m3                  # yield of OT\n",
    "m4 = (9*56*m)/(4.*137)          # [kg] theoretical iron reqiurement\n",
    "m5 = 800*.9                     #[kg] iron charged\n",
    "E = (m5-m4)*100/m4              # excess iron\n",
    "\n",
    "# Result\n",
    "print \"a  Yield of OT = \",n1\n",
    "print \"   b  Excess quantity of iron powder = \",E\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.3  Page 118"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a  \n",
      " Analysis of charge: \n",
      "Component           mass percent\n",
      "Chlorobenzene          46.62004662\n",
      "HNO3                   32.520979021\n",
      "H2SO4                  47.1272727273\n",
      "H2O                    20.3517482517\n",
      "b  \n",
      "Percent conversion of Chloro benzene is  93.71\n",
      "c  \n",
      " Composition of product stream :\n",
      "Component           mass percent\n",
      "  CB                     1.46820564496\n",
      "  p-NCB                  20.2112955666\n",
      "  o-NCB                  10.4118795343\n",
      "  HNO3                   30.6231751009\n",
      "  H2SO4                  23.595862041\n",
      "  H2O                    13.6895821123\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "\n",
    "# Variables \n",
    "\n",
    "print \"a  \"\n",
    "m = 100.                        #kg chlorobenzene (basis)\n",
    "m1 = 106.5*.655                 #kg HNO3 \n",
    "m2 = 108*.936                   # kg H2SO4\n",
    "\n",
    "# Calculation and Result\n",
    "m3 = 106.5*.345 +108*.064       #kg water\n",
    "M = m1+m2+m3\n",
    "print \" Analysis of charge: \" \n",
    "print \"Component           mass percent\"\n",
    "print \"Chlorobenzene         \",m*100/M\n",
    "print \"HNO3                  \",m1*100/M\n",
    "print \"H2SO4                 \",m2*100/M\n",
    "print \"H2O                   \",m3*100/M\n",
    "print \"b  \"\n",
    "# (b)\n",
    "# total charge mass is constant\n",
    "m4 = 314.5*.02                  #[kg] unreacted CB in the product\n",
    "m5 = 100-m4                     # [kg] CB that reacted\n",
    "c = m5*100./100                 # conversion of CB\n",
    "print \"Percent conversion of Chloro benzene is \",c\n",
    "print \"c  \"\n",
    "# (c)\n",
    "m6 = 63*c/112.5                 #[kg] HNO3 consumed\n",
    "m7 = m1-m6                      # unreacted HNO3\n",
    "m7 = 157.5*c/112.5              # [kg] total NCB produced\n",
    "m8 = m7*.66                     #[kg] p-NCB\n",
    "m9 = m7*.34                     #[kg] o-NCB\n",
    "m10 = 18*c/112.5                #[kg] water produced\n",
    "m11 = m10+m3                    # total water in product\n",
    "m12 = m4+m8+m9+m7+m2+m11\n",
    "print \" Composition of product stream :\"\n",
    "print \"Component           mass percent\"\n",
    "print \"  CB                    \",m4*100/m12\n",
    "print \"  p-NCB                 \",m8*100/m12\n",
    "print \"  o-NCB                 \",m9*100/m12\n",
    "print \"  HNO3                  \",m7*100/m12\n",
    "print \"  H2SO4                 \",m2*100/m12\n",
    "print \"  H2O                   \",m11*100/m12"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.4   Page 119"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a   Conversion percent of ethanol =  21.7435446009\n",
      "b   Yield of acetaldehyde =  94.0298507463\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "# Variables \n",
    "n=100.                          #[kmol] outgoing gas from 2nd scrubber\n",
    "n1=.852*n                       #[kmol] N2\n",
    "n2=21*n1/79.                    #[kmol] O2\n",
    "n3=n2-2.1                       # [kmol] reacted O2\n",
    "# O2 balance\n",
    "# O2 consumed in rxn (ii),(iii),(v) - O2 produced by rxn (iv) = 20.55 kmol\n",
    "# let a,b,c be ethanol reacted (ii),(iii),(iv) and d be H2 reacted in (v)\n",
    "\n",
    "# Calculation \n",
    "# CO balance\n",
    "a=2.3/2                         #kmol\n",
    "\n",
    "#CO2 balance \n",
    "b = .7/2\n",
    "\n",
    "#CH4 balance\n",
    "c=2.6/2\n",
    "\n",
    "#O2 balance\n",
    "d = 41.1-a-3*b+c\n",
    "\n",
    "#H2 balance\n",
    "e = 7.1 +c+d                    #kmol (total H2 produced)\n",
    "f = e-(3*b + 3*a)               #kmol  (H2 produced in (i) = ethanol reacted in (i))\n",
    "g = f+a+b+c                     # total ethanol reacted\n",
    "h = 2*(n1+n2)                   # total ethanol entering\n",
    "c1 = g*100/h\n",
    "\n",
    "# Result\n",
    "print \"a   Conversion percent of ethanol = \",c1\n",
    "y = f*100/g\n",
    "print \"b   Yield of acetaldehyde = \",y\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.5   Page 121"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Amount of lime required =  218.736  mg/l.\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "# Variables \n",
    "v = 1.                      #[l] water (basis)\n",
    "# 1 mol (100mg) CaCO3 gives 1 mol (56) Cao\n",
    "# use table 3.3 and eg 3.9\n",
    "\n",
    "# Calculation \n",
    "x = 56*390.6/100            #[mg/l] lime produced\n",
    "\n",
    "# Result\n",
    "print \"Amount of lime required = \",x,\" mg/l.\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  Example 4.5   Page 121"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x =  64.3747773424\n",
      " and y =  35.6252226576\n",
      "Amount of steam required =  36.5874599216  kmol\n"
     ]
    }
   ],
   "source": [
    "from numpy import array, linalg\n",
    "\n",
    "# solution \n",
    "\n",
    "# Variables \n",
    "m=100.                  #[kmol] (basis) dry mixed gas\n",
    "# x = kmol of water gas\n",
    "# y =kmol of producer gas\n",
    "# overall material balance : \n",
    "# x+y = 100   (i)\n",
    "\n",
    "#r2 =.43x+.25y # H2 formed by shift rxn\n",
    "#r2=.51x+.25y # H2 entering with water and producer gas\n",
    "#r = r1+r2 # taoal H2 \n",
    "#/n =.02x+.63y # N2 entering\n",
    "#N2:H2=1:3\n",
    "# ==> x-1.807y = 0(ii)\n",
    "#solving (i) and (ii)\n",
    "A = array([[1, 1],[1, -1.807]])\n",
    "d = array([100,0])\n",
    "\n",
    "# Calculation \n",
    "x = linalg.solve(A,d)\n",
    "s = .43*x[0]+.25*x[1]               # steam req.\n",
    "\n",
    "# Result\n",
    "print \"x = \",x[0]\n",
    "print \" and y = \",x[1]\n",
    "print \"Amount of steam required = \",s,\" kmol\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.7   Page 123"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a   NaOH required =  135.842696629  kg   \n",
      "b   amount of glycerine liberated =  10.3370786517  kg.\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "# Variables \n",
    "m = 100.                        #[kg] Tallow\n",
    "\n",
    "# Calculation \n",
    "m1 = 3*403*m/890.               # [kg]\n",
    "m2 = 92*m/890.\n",
    "\n",
    "# Result\n",
    "print \"a   NaOH required = \",m1,\" kg   \\nb   amount of glycerine liberated = \",m2,\" kg.\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.8    Page 124"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a   The fraction of S burnt =  0.0712504453153\n",
      "b   percentage of excess air over the amount req. for S oxidising to SO2 =  20.4488778055\n",
      "c   volume of dry air =  43.3707633304  m**3/s   \n",
      "d   volume of burner gases =  53815.0344364  m**3/s.\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "# Variables \n",
    "n = 100.                        #[kmol] SO3 free gas basis\n",
    "n1 = 16.5                       #[kmol] SO2\n",
    "n2 = 3.                         #[kmol] O2\n",
    "n3 = 80.5                       #[kmol] N2\n",
    "\n",
    "\n",
    "# Calculation \n",
    "# S + O2 = SO2\n",
    "# S + 3/2 O2 = SO3\n",
    "n4 = (21/79.)*80.5               #[kmol] O2 supplied\n",
    "n5 = n4-n1-n2                   #  [kmol] Unaccounted O2\n",
    "\n",
    "# O2 used in 2nd eq is m5\n",
    "n6 = (2./3)*n5                  #[kmol] SO3 produced\n",
    "n7 = n1+n6                      # sulphur burnt\n",
    "m7 = n7*32                      #[kg]\n",
    "f1 = n6/n7                      # fraction of SO3 burnt\n",
    "\n",
    "# O2 req. for complete combustion of S = n7\n",
    "n8 = n4-n7                      #[kmol] excess O2\n",
    "p1 = n8*100/n7                  # %age of excess air\n",
    "n9 = n4+n3                      #[kmol/s] air supplied\n",
    "F1 = n9*.3/n7                   # air supply rate\n",
    "v = 22.414*(303.15/273.15)*(101.325/100)                #[m**3/kmol] sp. vol of air\n",
    "V1 = F1*v                       #[m**3/s] flow rate of fresh air\n",
    "n10 = n+n7                      #[kmol] total gas from burner\n",
    "n11 = n10*.3/m7                 # [kmol/s] gas req. for .3 kg/s S\n",
    "V2 = 220414*1073.15*n11/273.15  # flowrate of burner gases\n",
    "\n",
    "# Result\n",
    "print \"a   The fraction of S burnt = \",f1\n",
    "print \"b   percentage of excess air over the amount req. for S oxidising to SO2 = \",p1\n",
    "print \"c   volume of dry air = \",V1,\" m**3/s   \\nd   volume of burner gases = \",V2,\" m**3/s.\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.9   Page 125"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a   theoretical H2 required =  11.434  Nm**3/100kg soyabean oil\n",
      "b   actual H2 required =  52.95\n",
      "c   Iodine value for soyabean oil =  129.5\n",
      "d   Iodine value of hardened fat =  69.2\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "# Variables \n",
    "m = 100.                        #[kg] soya fatty acid (basis)\n",
    "\n",
    "# use table 4.6\n",
    "M1 = m/.3597                    # M(avg) of soya fatty acid\n",
    "\n",
    "\n",
    "# Calculation \n",
    "#3 mol of fatty acid + 1 mol of glycerol = 1 mol triglyceride + 3 mol of water\n",
    "M2 = M1*3+92.09-3*18.02         # Mavg of soyabean oil\n",
    "q1 = M2*m/(M1*3)                # soyabean oil per 100kg fatty acid\n",
    "\n",
    "# based on reactions occuring\n",
    "q2 = .0967+.1822*2+.0241*3      # kmol H2 req. per 100 kg soya fatty acid\n",
    "q3 = .5101                      # kmol H2 req. per 100 kg soyabean oil\n",
    "q4 = 11.434                     # Nm**3/100kg soyabean oil\n",
    "# x = linoleic acid converted to oleic acid\n",
    "# y = oleic acid converted to stearic acid\n",
    "q5 = 282.46*6.7/278.43  \n",
    "#q6 = 282.46*x/280.15 = 1.00717x [kg] oleic acid by linoleic acid\n",
    "#q7 = 284.48*y/282.46 = 1.00715y [kg] stearic acid by oleic acid\n",
    "#q8 = 100.097 + .00717x + .00715y  total fatty acid\n",
    "#stearic balance : -.00105x + 1.00611y = 10.8142    (i)\n",
    "#linoleic balance : 1.0019x + .00019y = 48.4975     (ii)\n",
    "# solving (i) and (ii) we get\n",
    "x = 48.5                        #kg\n",
    "y = 10.8                        #kg\n",
    "M3 = 100.52/.3596               # Mavg of fatty acid\n",
    "H2req1 = .5334-.2864            # per 100kg fatty acid\n",
    "H2req = 52.95                   #Nm**3/t \n",
    "I2s = 129.5                     #kg I2 per 100 kg soyabean oil # for soyabean oil\n",
    "I2h = 69.2                      #kg I2 per 100 kg of fat\n",
    "\n",
    "# Result\n",
    "print \"a   theoretical H2 required = \",q4,\" Nm**3/100kg soyabean oil\"\n",
    "print \"b   actual H2 required = \",H2req\n",
    "print \"c   Iodine value for soyabean oil = \",I2s\n",
    "print \"d   Iodine value of hardened fat = \",I2h\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.10   Page 128"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Composition of exit gas stream :   CH3OH =  1.25\n",
      "  HCHO =  111.375\n",
      "  CO2 =  8.786\n",
      "  CO =  0.99\n",
      "  H2 =  1.98\n",
      "  CH4 =  0.619\n",
      "  CH32O =  0.99\n",
      "  O2 =  212.713\n",
      "  N2 =  -1058.09347048\n",
      "  H2O =  153.667\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "# Variables \n",
    "\n",
    "F1 = 4000.                      #kg/h methanol (basis)\n",
    "F2 = F1/32                      #kmol/h\n",
    "F3 = F2/.084                    #kmol/h gaseous mix flowrate\n",
    "F4 = F2-F3                      #kmol/h flow of wet air\n",
    "n1 = .011*29/18.                # kmol/kmol dry air \n",
    "F5 = F4/(1+n1)                  # kmol/h dry air flowrate\n",
    "O2 = F5*.21                     #kmol/h\n",
    "N2 = F5-O2                      #kmol/h\n",
    "Mreacted1 = F2*.99              #kmol/h\n",
    "Munreacted1 = F2-Mreacted1      #kmol/h\n",
    "\n",
    "# Calculation \n",
    "# reaction (i)\n",
    "Mreacted2 = Mreacted1*.9        #kmol/h\n",
    "HCHOproduced1 = 111.375\n",
    "O2consumed1 = 111.375/2\n",
    "H2Oproduced1 = 111.375\n",
    "\n",
    "# for rxn ii to iv\n",
    "Mconsumed = Mreacted1*.1\n",
    "\n",
    "#rxn (ii)\n",
    "CH3OHreacted1 = Mconsumed*.71\n",
    "O2consumed2 = 8.786*1.5\n",
    "CO2produced = 8.786\n",
    "H2Oproduced2 = 8.786*2\n",
    "\n",
    "#rxn(iii)\n",
    "CH3OHreacted2 = 12.375*.08\n",
    "COproduced = .99\n",
    "H2produced = 2*.99\n",
    "\n",
    "#rxn(iv)\n",
    "CH3OHreacted3 = 12.375*.05\n",
    "CH4produced = .619\n",
    "O2produced = .619/2\n",
    "\n",
    "#rxn(v)\n",
    "CH3OHreacted4 = 12.375-CH3OHreacted1-CH3OHreacted2-CH3OHreacted3\n",
    "DMEproduced = 1.98/2\n",
    "H2Oproduced3 = 1.98/2\n",
    "O2 = 281.27-O2consumed1-O2consumed2+O2produced\n",
    "H2O = 23.73+H2Oproduced1+H2Oproduced2+H2Oproduced3\n",
    "\n",
    "# Result\n",
    "print \"Composition of exit gas stream :   CH3OH = \",Munreacted1\n",
    "print \"  HCHO = \",HCHOproduced1\n",
    "print \"  CO2 = \",CO2produced\n",
    "print \"  CO = \",COproduced\n",
    "print \"  H2 = \",H2produced\n",
    "print \"  CH4 = \",CH4produced\n",
    "print \"  CH32O = \",DMEproduced\n",
    "print \"  O2 = \",O2\n",
    "print \"  N2 = \",N2\n",
    "print \"  H2O = \",H2O\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.11   Page 132"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a   percentage of cinder remained in cinder =  4.28571428571 .   \n",
      "b   percentage of S burnt to form SO3 =  9.9912948486    \n",
      "c   volumetric flow rate of air =  17.2460430576  m**3/s   \n",
      "d   volumetric flow rate of roaster gases =  44.246401399  m**3/s \n",
      "f  Amount of 98 percent acid strength produced =  409.643136  t/d.\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "# Variables \n",
    "m = 100.                #kg pyrites (basis)\n",
    "\n",
    "#(a)\n",
    "print \"a  \",\n",
    "S1 = 42.                #kg\n",
    "i1 = 58.                #kg  inerts\n",
    "\n",
    "# Calculation \n",
    "# 8 moll S = 3 mol O2 in Fe2O3\n",
    "m1 = 3*32*42./8.*32     #kg O2 converted to Fe2O3\n",
    "m2 = i1+m1              # mass of SO3 free cinder\n",
    "\n",
    "#2.3 kg S is in 100kg cinder\n",
    "m3 = 100-(2.3*80./32)\n",
    "m4 = (100./m3)*m2\n",
    "m5 = m4*.023            #kg  S in cinder\n",
    "p1 = 1.8*100/42.\n",
    "\n",
    "# Result\n",
    "print \"percentage of cinder remained in cinder = \",p1,\".   \\nb  \",\n",
    "\n",
    "#(b)\n",
    "m6 = 100.               #kmol SO3 free roaster gas (basis)\n",
    "m7 = 7.12               #kmol O2 as SO2\n",
    "m8 = 10.6               #O2\n",
    "m9 = 100-m8-m7          #N2\n",
    "m10 = (21/79.)*m9       # O2 entering roaster along N2\n",
    "m11 = m7+m8+(3*7.12/8)  # accounted O2\n",
    "m12 = m10-m11           # unaccounted O2\n",
    "m13 = (8/15.)*m12        # SO3 formed\n",
    "m14 = m13+m7            # S burnt\n",
    "p2 = (m13/m14)*100.\n",
    "print \"percentage of S burnt to form SO3 = \",p2,\"   \\nc  \",\n",
    "\n",
    "# (c)\n",
    "# basis 100kg pyrite\n",
    "m15 = 37.81/32          # SO2 formed\n",
    "m16 = (m9+m10)*1.181/m7 # air supplied\n",
    "\n",
    "# 4 kg pyrite is roasted\n",
    "m17 = m16*4/100.        #kmol/s  total air supplied\n",
    "v1 = m17*24.957 \n",
    "print \"volumetric flow rate of air = \",v1,\" m**3/s   \\nd  \",\n",
    "# (d)\n",
    "m18 = (100.455*m17)/(m9+m10)        # roaster gases\n",
    "v2 = m18*66.386\n",
    "print \"volumetric flow rate of roaster gases = \",v2,\" m**3/s \\nf \",\n",
    "#(f)\n",
    "m19 = 4.838*10**-2*.98 # SO3 absorbed in absorber\n",
    "# SO3 + H2O = H2SO4\n",
    "m20 = (m19*98*24*3600)/(.98*1000)   #[t/d]\n",
    "print \"Amount of 98 percent acid strength produced = \",m20,\" t/d.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.12   Page 136"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a   \n",
      "Total cinder produced =  79.398250005 kg  \n",
      "Composition of cinder :  ZnO =  14.2073921971 kg  \n",
      "Fe2O3 =  44.97581 kg  \n",
      "S as FeS2 =  1.57 kg  \n",
      "S as SO3 =  4.64504780785 kg  \n",
      "inerts =  14.0 kg   \n",
      "b  \n",
      "percentage of S left in cinder =  6.57552394194\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "\n",
    "# Variables \n",
    "# basis 100kg mixed charge = 75 kg pyrite + 25kg ZnS\n",
    "# pyrites\n",
    "m1 = 75*.92                 #[kg]  FeS2\n",
    "G1 = 75-m1                  # gangue\n",
    "# 4FeS2 + 11O2 = 2Fe2O3 + 8SO2\n",
    "# 4FeS2 + 15O2 = 2Fe2O3 + 8SO3\n",
    "#Zn ore\n",
    "m2 = 25*.68                 # ZnS\n",
    "I1 = 25-m2                  # inerts\n",
    "\n",
    "# Calculation \n",
    "# 2ZnS + 3 O2 = 2 ZnO + 2 SO2\n",
    "I2 = I1+6                   # total inerts\n",
    "# new basis : 100kg cinder \n",
    "m3 = 3.5*.7                 # S as SO3\n",
    "m4 = 3.5-m3                 # S as FeS2\n",
    "m5 = 100-m3-m4              # S free cinder\n",
    "m6 = (81.4/97.4)*17         # ZnO\n",
    "\n",
    "# FeS2 reacted = x\n",
    "# (FeS2 in cinder/S free cinder) = (69-x)/(28.2+.667x) = 1.969/91.906\n",
    "# solving this we get\n",
    "x = 67.43                   #kg\n",
    "m7 = m6 + .667*x + 14       # S free cinder\n",
    "m8 = 69-x                   # FeS2 in cinder\n",
    "m9 = 6.125*m7/m5            # SO3\n",
    "m10 = .667*x                # Fe2O3\n",
    "m11 = m6+m10+m8+m9+I2\n",
    "\n",
    "# Result\n",
    "print \"a   \"\n",
    "print \"Total cinder produced = \",m11,\"kg  \\nComposition of cinder :  ZnO = \",m6,\\\n",
    "\"kg  \\nFe2O3 = \",m10,\"kg  \\nS as FeS2 = \",m8,\"kg  \\nS as SO3 = \",m9,\"kg  \\ninerts = \",I2,\"kg   \\nb  \"\n",
    "S1 = (64./120)*69 + (32./97.4)*17           #[kg]  S charged to burner\n",
    "S2 = .035*79.63                             # S in cinder\n",
    "p = S2*100/S1\n",
    "print \"percentage of S left in cinder = \",p"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.13   Page 138"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mass of 0.5 percnt NaOH required to be added to raise the pH =  170.21 g.\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "# Variables\n",
    "m1 = 1200*1.2               #[kg] mass of reactants\n",
    "pOH1 = 14-6                 #pOH of reactants\n",
    "pOH = 14-9                  #pOH of final mass\n",
    "# ROWs = 1/sigma(Wi/ROWsi)\n",
    "#Ms = mass of .5% NaOH required\n",
    "#ROWs = density of final solution\n",
    "\n",
    "# Calculation \n",
    "#ROWs = 1/{((m1*10**3*1)/(((m1*10**3+Ms)*1.2)+(Ms/((m1*10**3+Ms)*1.005))}    (i)\n",
    "#balance of OH- ions\n",
    "#1200*10**-8 +Ms*10**-1.15/(1.005*10**-5) = (1200*1.2*10**3+Ms)*10**-5/ROWs*10**-5      (ii)\n",
    "#solving (i) and (ii)\n",
    "Ms = 170.21                 #g\n",
    "ROWs = 1.2016               #[kg/l]\n",
    "\n",
    "# Result\n",
    "print \"Mass of 0.5 percnt NaOH required to be added to raise the pH = \",Ms,\"g.\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.14  Page 140"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[  1.05810000e+03   1.25000000e+00   2.12724501e+02   1.53665988e+02\n",
      "   1.12037218e+02   8.45438500e+00   9.69022000e-01   1.93804400e+00\n",
      "   8.52651283e-14   9.90000000e-01   1.12037218e+02   8.45438500e+00\n",
      "   9.69022000e-01   3.09375000e-01   9.90000000e-01]\n"
     ]
    }
   ],
   "source": [
    "from numpy import array, linalg\n",
    "# solution \n",
    "# Variables \n",
    "# using equations of example 4.10\n",
    "\n",
    "# soving 4.10 by linear model method\n",
    "M = array([[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n",
    "            [0 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,1 ,2],\n",
    "            [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, .5, 1.5, 0, -.5, 0],\n",
    "            [0 ,0 ,0 ,1 ,0 ,0, 0, 0, 0, 0, -1, -2 ,0 ,0 ,-1],\n",
    "            [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0],\n",
    "            [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 0],\n",
    "            [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0],\n",
    "            [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, -2, 0, 0],\n",
    "            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0],\n",
    "            [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1],\n",
    "            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2],\n",
    "            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, .5, 1.5, 0, -.5, 0],\n",
    "            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -2, 0, 0, -1],\n",
    "            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],\n",
    "            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2]])\n",
    "V = array([1058.1,125,281.27,23.73,0,0,0,0,0,0,.99*125,.2437*281.27,-5.4756*23.73,.61875,1.98])\n",
    "\n",
    "# Calculation \n",
    "X = linalg.lstsq(M,V)\n",
    "\n",
    "# Result\n",
    "print (X[0])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.15   Page 143"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a   Amount of Cu lberated =  6693.21656216\n",
      "b   Current efficiency of the cell =  94.872173058  percent.\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "# Variables\n",
    "# basis = 1.12 M63 O2 at NTP\n",
    "m1 = 1.12*1000*32/22.4                      #[g] O2\n",
    "m2 = m1/8.                                  # g eq  O2\n",
    "\n",
    "# Calculation \n",
    "#at cathode : Cu++ +2e = Cu\n",
    "#at anode : SO4-- - 2e = SO4\n",
    "eqwtCu = 63.5/2\n",
    "depositedCu = eqwtCu*m2\n",
    "E = (1130*18000.)/96485                     #faradays  Total energy passed to cell\n",
    "libCu = (1130*18000*eqwtCu)/96485.          #[g]  theoritical liberation of Cu\n",
    "eff = (depositedCu/libCu)*100.              # current efficiency\n",
    "\n",
    "# Result\n",
    "print \"a   Amount of Cu lberated = \",libCu\n",
    "print \"b   Current efficiency of the cell = \",eff,\" percent.\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.16   Page 144"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a   Current efficiency of the cell =  95.6846807485  percent.   \n",
      "b   Cl2 produced =  456.26375  kg/day  H2 produced =  12.8535211268  kg/day  \n",
      "c   loss of water =  627.391756664  kg/day\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "\n",
    "# Variables \n",
    "# basis : 1day operation\n",
    "# NaCl = Na+ + Cl-\n",
    "#H2O = H+ + OH-\n",
    "#Na+ + OH- = NaOH\n",
    "#H+ + e = (1/2)H2\n",
    "#Cl- - e = (1/2)Cl2\n",
    "E = (15000.*3600*24)/96485                      # faraday/day   Total energy passed thrrough cell\n",
    "NaOH = (15000*3600*24*40)/(96485*1000.)         #[kg/day] theoretical NaOH\n",
    "eff = (514.1/NaOH)*100                          # current efficiency\n",
    "Cl2 = (35.5/40)*514.1\n",
    "H2 = (456.3*2)/(35.5*2)\n",
    "\n",
    "# Calculation \n",
    "#40 g NaOH = 58.5g NaCl\n",
    "consNaCl = (58.5/40)*514.1                      # NaCl consumed\n",
    "Tliquor = 514.1/.11                             #[kg/day]  total cell liquor\n",
    "remNaCl = 514.1*1.4\n",
    "totalNaCl = consNaCl+remNaCl\n",
    "Fbrine = totalNaCl/.266                         #feed rate of brine\n",
    "consH2O = (18./40)*514.1\n",
    "lossH2O = Fbrine-Tliquor-consH2O\n",
    "\n",
    "# Result\n",
    "print \"a   Current efficiency of the cell = \",eff,\n",
    "print \" percent.   \\nb   Cl2 produced = \",Cl2,\n",
    "print \" kg/day  H2 produced = \",H2,\n",
    "print \" kg/day  \\nc   loss of water = \",lossH2O,\" kg/day\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.17   Page 146"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a   recycle feed rate =  338.589  kmol/s   \n",
      "b   purge gas rate =  7.90009519163  kmol/s   \n",
      "c   mass rate of NH3 =  779.467550624  kg/s\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "\n",
    "# Variables \n",
    "#M = mix feed rate, F = fresh feed rate , R = recycle stream\n",
    "# using fig 4.3\n",
    "# N2 balance\n",
    "# a = 24.75M/(.25M+7.5M)    (i)\n",
    "# P = (4.15M + 17.75a)/M     (ii)\n",
    "# .585M -1.775a +(4.15M+17.75a)/M = 100  (iii)\n",
    "#solving (i,) (ii), (iii)\n",
    "M = 438.589                             #[kmol/s]  \n",
    "\n",
    "# Calculation \n",
    "a = (24.75*M)/((.25*M)+7.5)             #kmol/s\n",
    "P = (4.15*438.589+17.75*92.662)/M       #kmol/s\n",
    "R = M-100                               # kmol/s\n",
    "r = R/100                               # recycle ratio\n",
    "NH3 = (.585*M-2.275*a)*17.0305          #kg/s\n",
    "\n",
    "# Result\n",
    "print \"a   recycle feed rate = \",R,\" kmol/s   \\nb   purge gas rate = \",P,\\\n",
    "\" kmol/s   \\nc   mass rate of NH3 = \",NH3,\" kg/s\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.18   Page 149"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mixed feed rate =  457.011  kmol/s \n",
      "Recycle stream =  350.771  kmol/s \n",
      "Recovered H2 stream =  6.24106025284  kmol/s \n",
      "Fresh feed rate =  99.9989397472  kmol/s \n",
      "Recycle ratio =  350.833411264  kmol/kmol of fresh feed.\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "\n",
    "# Variables \n",
    "# given\n",
    "# (.1*M*R1)/(.415M+1.775a) + (.1125a*P)/(.415M + 1.775a) + 1 = .1M    \n",
    "# R1*(.315M-1.225a)/(.415M + 1.775a) = .9M-4a\n",
    "# M = 100 + R1 + (2.25a*p)/(.415M + 1.775a)\n",
    "# .1M*P/(.415M + 1.775a) - (.1125a*P)/(.415M1.775a)\n",
    "#solving them\n",
    "M = 457.011                             # kmol/s\n",
    "R1 = 350.771                            # kmol/s\n",
    "P = 10.368                              # kmol/s\n",
    "a = 96.608                              # kmol/s\n",
    "\n",
    "# Calculation \n",
    "R2 = 2.25*96.608*10.369/(.415*457.011 + 1.775*96.608)           # kmol/s\n",
    "F = M -R1 - R2\n",
    "\n",
    "# Result\n",
    "print \"Mixed feed rate = \",M,\" kmol/s \\nRecycle stream = \",R1,\\\n",
    "\" kmol/s \\nRecovered H2 stream = \",R2,\" kmol/s \\nFresh feed rate = \",F,\\\n",
    "\" kmol/s \\nRecycle ratio = \",R1+R2/F,\" kmol/kmol of fresh feed.\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.19   Page 153"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "48.4197432526  percent of total raw water is passed through the H ion exchanger.\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "# Variables \n",
    "m1 = (50/35.5)*312                      #[mg/l]  Cl2 expressed as equivalent CaCO3\n",
    "m2 = (50/48)*43.2                       #[mg/l]  Sulphates as equivalent CaCO3\n",
    "A = m1+m2                               #[mg/l as CaCO3]    EMA in raw water\n",
    "M1 = 550.                               # alkalinity of raw water\n",
    "M2 = 50.                                # alkalinity of blend water\n",
    "\n",
    "# Calculation \n",
    "#let 100 l of raw water enters both ion exchangers\n",
    "# balancing neutrilasion\n",
    "x = 100.*(M1-M2)/(A+M1)                 # raw water inlet to H2 ion echanger\n",
    "\n",
    "# Result\n",
    "print x,\" percent of total raw water is passed through the H ion exchanger.\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.20    Page 155"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Increase in capacity =  95.8492338978  percent.\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "# Variables \n",
    "m1 = 1488.1                             #kmol/h gas mix to reactor1 (basis)\n",
    "m2 = m1*.0625                           # CH3OH\n",
    "m3 = m1-m2                              # ambient air flow\n",
    "m4 = m3/1.01772                         # dry air flow rate\n",
    "m5 = m3-m4                              # moisture\n",
    "m6 = m2*.99                             # CH3OH conversion in R1\n",
    "m7 = m2-m6                              # unreacted CH3OH\n",
    "\n",
    "# Calculation \n",
    "#rxn i\n",
    "m8 = m7*.9                              # CH3OH reacted = HCHO produced = H2O produced\n",
    "m9 = m8/2                               # O2 consumed \n",
    "m10 = m6-m8                             # CH3OH reacted in rxn ii to v\n",
    "\n",
    "#rxn ii\n",
    "m11 = m10*.71                           # CH3OH reacted = CO2 produced\n",
    "m12 = m11*1.5                           # O2 consumed\n",
    "m13 = 2*m11                             # H2O produced\n",
    "\n",
    "#rxn iii\n",
    "m14 = m10*.08                           # CH3OH reacted = CO produced\n",
    "m15 = 2*m14                             # H2 produced\n",
    "\n",
    "#rxn iv\n",
    "m16 = m10*.05                           # Ch3OH reacted = CH4 produced\n",
    "m17 = m16/2                             # O2 produced\n",
    "\n",
    "#rxn v\n",
    "m18 = m10-m16-m14-m11                   # CH3OH reacted\n",
    "m19 = m18/2                             # (CH3)2O = H2O produced\n",
    "\n",
    "m20 = 287.87-m9-m12+m17                 # O2 in R1 exit stream\n",
    "m21 = m5+m8+m13+m19                     # H2O in R1\n",
    "m = m7+m8+m11+m14+m15+m16+m19+m20+1082.93+m21\n",
    "\n",
    "# R2\n",
    "# x kmol/h CH3OH is added b/w reactors\n",
    "# (m7+x)/(m+x) = .084 solving it\n",
    "x = 140.548                             #[kmol/h]\n",
    "m22 = x+m7                              # CH3OH entering R2\n",
    "m23 = m22*.99                           #CH3OH reacted\n",
    "m24 = m22-m23                           # CH3OH unreacted\n",
    "\n",
    "#rxn i\n",
    "m25 = m23*.9                            # CH3OH reacted = HCHO produced = H2O produced\n",
    "m26 = m25/2                             # O2 consumed\n",
    "m27 = m23 - m25                         # CH3OH reacted in rxn ii to v\n",
    "\n",
    "#rxn ii\n",
    "m28 = m27*.71                           # CH3OH reacted = CO2 produced\n",
    "m29 = m28*1.5                           # O2 consumed\n",
    "m30 = m28*2                             # H2O produced\n",
    "\n",
    "#rxn iii\n",
    "m31 = m27*.08                           # CH3OH reacted = CO produced\n",
    "m32 = m31*2                             # H2 produced\n",
    "\n",
    "#rxn iv\n",
    "m33 = m27*.05                           # Ch3OH reacted = CH4 produced\n",
    "m34 = m33/2                             # O2 produced\n",
    "\n",
    "#rxn v\n",
    "m35 = m27-m28-m31-m33                   # CH3OH reacted\n",
    "m36 = m35/2                             # (CH3)2O = H2O produced\n",
    "\n",
    "m37 = m20 - m26-m29+m34                 # O2 in R2 exit stream\n",
    "m38 = m21+m25+m36                       # H2O in R2\n",
    "m39 = 92.07+m25                         # HCHO in R2\n",
    "m40 = m24+m39+m28+m31+m32+m33+m36+m37+m38+1082.93\n",
    "\n",
    "m41 = m39*30                            # kg/h   HCHO produced\n",
    "m42 = m41/.37                           # bottom sol floe rate\n",
    "c = (m42-9030.4)*100/9030.4             # increase in capacity\n",
    "\n",
    "# Result\n",
    "print \"Increase in capacity = \",c,\" percent.\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 4.21   Page 159"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a   Mass of slag made =  633.285714286  kg.   \n",
      "b   Mass of ore required =  1696.42857143  kg.   \n",
      "c   Composition of slag :  SiO2 =  273.571428571  kg  Al2O3 =  135.714285714  kg  CaO =  224.0  kg.    \n",
      "d    Volume of air to be supplied =  3569.53115079  m**3.\n"
     ]
    }
   ],
   "source": [
    "# solution \n",
    "\n",
    "# Variables \n",
    "# basis 1 tonne of pig iron\n",
    "coke = 1000.                        #kg\n",
    "flux = 400.                         #kg\n",
    "Fe1 = 1000*.95                      # Fe in pig iron\n",
    "\n",
    "# Calculation and  Result\n",
    "Fe2 = (112/160.)*.8                 # Fe available per kg of ore\n",
    "ore = Fe1/Fe2                       # kg\n",
    "Si = .014*1000                      #kg  #Si in pig iron\n",
    "si1 = (60/28.)*14                   # silica present in pig iron\n",
    "si2 = ore*.12                       # silica in ore\n",
    "si3 = .1*coke                       # silica in coke\n",
    "si4 = si2+si3-si1                   # silica in slag\n",
    "alumina = ore*.08                   # Al2O3 in ore = Al2O3 in slag\n",
    "CaO = flux*(56/100.)\n",
    "slag = si4+alumina+CaO\n",
    "print \"a   Mass of slag made = \",slag,\" kg.   \\nb   Mass of ore required = \",ore,\\\n",
    "\" kg.   \\nc   Composition of slag :  SiO2 = \",si4,\" kg  Al2O3 = \",alumina,\" kg  CaO = \",CaO,\" kg.    \\nd  \",\n",
    "C = .9*coke+(12/100.)*flux-36       # total C available\n",
    "\n",
    "# CO:CO2 = 2:1\n",
    "C1 = C/3                            # C converted to CO2\n",
    "C2 = 2*C/3                          # C converted to CO\n",
    "O21 = C1*(32/12.)+C2*(16./12)       # O2 required for CO and CO2 formation\n",
    "O22 = (32/28.)*Si                   # O2 from SiO2\n",
    "O23 = ore*(.8*48/160)               # O2 from Fe2O3\n",
    "O24 = flux*(32/100.)                # O2 from CaCO3\n",
    "O25 = O21-O22-O23-O24               #kg O2 to be supplied\n",
    "O26 = O25/32                        #kmol\n",
    "air = O26/.21                       #kmol\n",
    "V = air*22.414                      #m**3\n",
    "print \" Volume of air to be supplied = \",V,\" m**3.\""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
