{
 "metadata": {
  "name": "",
  "signature": "sha256:94249011b6fa028e4fb13e0830b4dd171e4b428548b27716d80b6a2e4fc89f65"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 2. Process Economics"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example Problem 2.1, Page Number 22"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable Declaration\n",
      "Q = 500.0             #Heat TRansfer Area, m2\n",
      "QB =  80.0            #Base Size, m2\n",
      "CB =  3.28e4          #Base Cost, $\n",
      "CEIc = 441.9          #Current CE Index\n",
      "CEIp = 435.8          #Past CE Index\n",
      "M =  0.68             #Cost exponent\n",
      "fM = 2.9              #Factor for capital cost\n",
      "fPIP = 0.7\n",
      "fER = 0.4\n",
      "fINST = 0.2\n",
      "fELE = 0.1\n",
      "fUTIL = 0.5\n",
      "fOS = 0.2\n",
      "fBUILD = 0.2\n",
      "fSP = 0.1\n",
      "fDEC = 1.0\n",
      "fCONT =0.4\n",
      "fWS = 0.7\n",
      "\n",
      "#Calculations\n",
      "CE = CB*(Q/QB)**M\n",
      "CEc = CE*(CEIc/CEIp)\n",
      "CF1 = fM*(1+fPIP)*CEc + (fER + fINST + fELE + fUTIL + fOS + fBUILD + fSP + fDEC + fCONT + fWS)*CEc\n",
      "CF2 = fM*(1+fPIP)*CEc + (fER + fINST + fDEC + fCONT)*CEc\n",
      "#Results\n",
      "print 'Capital Cost of Carbon steel exchanger $%5.3e'%CE\n",
      "print CF1, CF2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example Problem 2.2, Page Number 22"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable Declaration\n",
      "Q = 500.0             #Heat TRansfer Area, m2\n",
      "QB =  80.0            #Base Size, m2\n",
      "CB =  3.28e4          #Base Cost, $\n",
      "CEIc = 441.9          #Current CE Index\n",
      "CEIp = 435.8          #Past CE Index\n",
      "M =  0.68             #Cost exponent\n",
      "fM = 2.9              #Factor for capital cost\n",
      "fPIP = 0.7\n",
      "\n",
      "#Calculations\n",
      "CE = CB*(Q/QB)**M\n",
      "CEc = CE*(CEIc/CEIp)\n",
      "Cpip = fM*fPIP*CEc\n",
      "#Results\n",
      "print 'Piping cost  $%5.3e'%Cpip"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example Problem 2.3, Page Number 24"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable Declaration\n",
      "Q = 1.5              #Heat TRansfer Area, m2\n",
      "QB =  0.5            #Base Size, m2\n",
      "H = 30.0             # Height of Packing, m\n",
      "CB =  1.8e4          #Base Cost for 5m height of pkg, $\n",
      "CEIc = 441.9         #Current CE Index\n",
      "CEIp = 435.8         #Past CE Index\n",
      "M =  1.7             #Cost exponent\n",
      "Cr = 0.1             #Cost of removing old packing\n",
      "Ca = 0.7             #Cost of adding new packing\n",
      "\n",
      "#Calculations\n",
      "CE = CB*(H/5.)*(Q/QB)**M\n",
      "CEc = CE*(CEIc/CEIp)\n",
      "Cp = CEc*(1.0+Cr+Ca)\n",
      "#Results\n",
      "print 'Cost of packing $%5.2e'%CE\n",
      "print 'Cost of packing corrected using cost indexes $%5.2e'%CEc\n",
      "print 'total Cost of Project $%5.2e'%Cp"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example Problem 2.4, Page Number 24"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable Declaration\n",
      "Ci = 1.0e6           #Cost of Distillation column in  Dollor\n",
      "n = 5.               #Number of years\n",
      "i = 0.05             #Interest rate in percent\n",
      "fi = 5.8             #Installation factor\n",
      "\n",
      "#Calculations\n",
      "CF = fi*Ci\n",
      "fA = i*(1.+i)**n/((1.+i)**n-1.)\n",
      "CAnnualized = CF*fA\n",
      "#Results\n",
      "print 'Cost of installed Equipment $%8.0f'%CF\n",
      "print 'Annulization factor $%5.4f'%fA\n",
      "print 'Annualized cost $%8.0f per year'%CAnnualized"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example Problem 2.5, Page Number 26"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import array,zeros\n",
      "from sympy import symbols, integrate\n",
      "from scipy.interpolate import interp1d\n",
      "from scipy.optimize import root\n",
      "\n",
      "#Variable Declaration\n",
      "P = array([41.0,10.0,3.0])     #Array of pressure for High medium and low pressures, barg bar gauge\n",
      "Ieff = 80.0                    #Isentropic efficiency of steam turbine\n",
      "Cfuel = 4.0e-9                 #Cost of fuel, $ per J\n",
      "Cele = 0.07                    #Cost of electricity, $ per (kWh)\n",
      "Tw = 100.0                     #Temperature of boiler feed water, \u00b0C\n",
      "Cpw = 4200.0                   #Specific heat of water, K/(kg.K)\n",
      "effSG = 85.0                   #Efficiency of Steam Generation\n",
      "Ts = 400.0                     #Temperature of superheated steam,\u00b0C                 \n",
      "Hs = 3212e3                    #Enthalpy of steam at 400 \u00b0C and 41 barg, J/kg\n",
      "Tref = 0.0                     #Reference Temperature,\u00b0C\n",
      "Qloss = 10.0                   #Distribution losses in percent\n",
      "\n",
      "#Calculations\n",
      "hw = Cpw*(Tw-Tref)             #Enthalpy of water at 100 \u00b0C, J/kg  \n",
      "dHs = Hs-hw\n",
      "#Cost of steam at 41.0 barg\n",
      "Csg41 = dHs*Cfuel*100*(1.0+Qloss/100)/effSG\n",
      "\n",
      "#Cost of steam at 10.0 barg\n",
      "Ss = 6747.0                    #Entropy of steam at 400 \u00b0C and 41 barg\n",
      "H10 = 2873000.0                #Enthalpy of steam at 10 barg\n",
      "S10 = 6747.0                   #Entropy of steam at 10 barg\n",
      "H10dash = Hs - Ieff*(Hs - H10)/100\n",
      "Pgen10 = Hs-H10dash            #Power gernerated per kg of steam to convert it to 10 barg from 41 barg steam\n",
      "\n",
      "#Value of power gerneration due to forrmation of 10 barg steam\n",
      "VP41t10 = Pgen10*Cele/(3600*1000)\n",
      "Csg10 = Csg41-VP41t10\n",
      "\n",
      "#Cost of steam at 3.0 barg\n",
      "H10 = 2941000.0               #Enthalpy of steam at 3.0 barg\n",
      "S10 = 6880.0                  #Entropy of steam at 3.0 barg\n",
      "H3 = 2732000.0                #Enthalpy of steam at 3.0 barg\n",
      "S3 = 6880.0                   #Entropy of steam at 3.0 barg\n",
      "H3dash = H10 -Ieff*(H10-H3)/100\n",
      "#Value of power gerneration due to forrmation of 3 barg steam\n",
      "Pgen3 = H10-H3dash            #Power gernerated per kg of steam to convert it to 3 barg from 10 barg steam\n",
      "VP10t3 = Pgen3*Cele/(3600*1000)\n",
      "Csg3 = Csg10-VP10t3\n",
      "\n",
      "#Results\n",
      "print 'Heat required to generate steam at 41 barg and 400\u00b0C from water: %8.1f J/kg'%dHs\n",
      "print 'Cost of Steam generation for steam at 41 barg and 400\u00b0C from water: $ %8.6f per kg ' %Csg41\n",
      "\n",
      "print 'Power geration when 41 barg steam is converted to 10 barg steam : %8.1f J/kg'%Pgen10\n",
      "print 'Value of when 41 barg steam is converted to 10 barg steam: $ %8.6f per kg ' %VP41t10\n",
      "print 'Cost of Steam generation for steam at 10 barg from 41 barg steam: $ %8.6f per kg ' %Csg10\n",
      "\n",
      "print 'Power geration when 10 barg steam is converted to 3 barg steam : %8.1f J/kg'%Pgen3\n",
      "print 'Value of when 10 barg steam is converted to 3 barg steam: $ %8.6f per kg ' %VP10t3\n",
      "print 'Cost of Steam generation for steam at 3 barg from 10 barg steam: $ %8.6f per kg' %Csg3"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example Problem 2.6, Page Number 28"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable Declaration\n",
      "Qc = 0.5e6           #Cooling load, W\n",
      "Tc = -20.0           #Cold Sink temperature, \u00b0C\n",
      "Th = 30.0            #Hot source temperature, \u00b0C\n",
      "dTmin = 5.0          #Minimum temperature difference, \u00b0C\n",
      "eff = 0.6\n",
      "Ce = 0.07            #Cost of electricity, $ per KWh\n",
      "Hours = 8000.0       #Hours of working per year\n",
      "\n",
      "#Calculations\n",
      "Th = Th + dTmin + 273.15\n",
      "Tc = Tc - dTmin + 273.15\n",
      "W = Qc/eff*((Th-Tc)/Tc)\n",
      "Cele = W*Ce*Hours\n",
      "\n",
      "#Results\n",
      "print 'Actual power required %6.0f W'%W\n",
      "print 'Cost of Electriciity $ %6.0f '%(Cele/1000)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example Problem 2.7, Page Number 30"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import array,zeros\n",
      "from sympy import symbols, integrate\n",
      "from scipy.interpolate import interp1d\n",
      "from scipy.optimize import root\n",
      "\n",
      "#Variable Declaration\n",
      "CP = 1.0e6                                  #Cost of Project, dollor\n",
      "ACFA = array([-10.,1.6,2.8,4.0,5.2,6.4])    #Annual Cash Flow for Project A\n",
      "ACFB = array([-10.,6.5,5.2,4.0,2.8,1.6])    #Annual Cash Flow for Project B\n",
      "ADCFA = zeros(len(ACFA))                    #Annual Discounted Cash Flow for Project A\n",
      "ADCFB = zeros(len(ACFB))                    #Annual Discounted Cash Flow for Project B\n",
      "Y = array([0,1,2,3,4,5])                    #Array containing disyear \n",
      "j = array([20.,25.,30.,35.,40.])            #Array containing Discounted Cash Flow Rate of Return in percent\n",
      "SADCFA = zeros(len(j))                      #Array containing Sum of Annual Discounted Cash Flow for Project A\n",
      "SADCFB = zeros(len(j))                      #Array containing Sum of Annual Discounted Cash Flow for Project B\n",
      "\n",
      "#Calculations\n",
      "\n",
      "ACFA = ACFA*1e6\n",
      "ACFB = ACFB*1e6\n",
      "NPVA = ACFA/(1.0 + i)**Y\n",
      "NPVB = ACFB/(1.0 + i)**Y\n",
      "\n",
      "print 'Project A:'\n",
      "for n in j:\n",
      "    k = sorted(j).index(n)\n",
      "    print 'Discounted Annual Cash Flow for DCFRR %2d'%n\n",
      "    for m in Y:\n",
      "        ADCFA[m] = ACFA[m]/(1. + n/100.0)**m\n",
      "        SADCFA[k] = SADCFA[k] + ADCFA[m]\n",
      "        print 'For year %2d is %8.0f'%(m,ADCFA[m])\n",
      "    print 'For DCFRR of %2d%% Net Present Value is %9.0f'%(n,SADCFA[k])  \n",
      "    print '---------------------------------------------'\n",
      "\n",
      "fA = interp1d(j, SADCFA)\n",
      "f = lambda x:fA(x)\n",
      "sol = root(f,21)\n",
      "DCFRRA = sol.x[0]\n",
      "print \n",
      "print 'Project B:'\n",
      "for n in j:\n",
      "    k = sorted(j).index(n)    \n",
      "    print 'Discounted Annual Cash Flow for DCFRR %2d'%n\n",
      "    for m in Y:\n",
      "        ADCFB[m] = ACFB[m]/(1. + n/100.0)**m\n",
      "        SADCFB[k] = SADCFB[k] + ADCFB[m]\n",
      "        ADCFB[m] = ACFB[m]/(1. + n/100.0)**m\n",
      "        print 'For year %2d is %8.0f'%(m, ADCFB[m])\n",
      "    print 'for DCFRR of %2d%% Net Present Value is %9.0f'%(n,SADCFB[k])  \n",
      "    print '---------------------------------------------'\n",
      "\n",
      "fB = interp1d(j, SADCFB)\n",
      "f = lambda x:fB(x)\n",
      "sol = root(f,35)\n",
      "DCFRRB = sol.x[0]\n",
      "\n",
      "#Results\n",
      "print 'Discounted Cash flow Rate of Return for Project A is: %4.2f%% and for Project B is %4.2f%%'%(DCFRRA,DCFRRB)\n",
      "if DCFRRA > DCFRRB:\n",
      "    print 'Discounted Cash flow Rate of Return for Project A is %4.2f%% > %4.2f%% for Project B, \\nhence project A should be preffered'%(DCFRRA,DCFRRB)\n",
      "else:\n",
      "    print 'Discounted Cash flow Rate of Return for Project A is %4.2f%% < %4.2f%% for Project B, \\nhence project B should be preffered'%(DCFRRA,DCFRRB)\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}