{
 "metadata": {
  "name": "",
  "signature": "sha256:445dec12235c400efa979dcf04faa2911a77ac6433ec8e786b9205e0e8fdeeb4"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 3 : The balance equation and mass balance"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 3.4 page no : 88\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "\n",
      "# variables\n",
      "V=15.;                        #gal volume of gasoline\n",
      "t=2.;                         #min\n",
      "rho_water=62.3;               #lbm/ft^3\n",
      "sg=0.72;                      #specific gravity\n",
      "\n",
      "# calculation and Result\n",
      "q=(15/2.0)*(0.1336/60)        #ft^3/s vol. flow rate\n",
      "print \"volumetric flow rate is %f ft^3/s\"%q\n",
      "m=q*sg*rho_water              #lbm/s\n",
      "print \"Mass flow rate is %f lbm/s\"%m\n",
      "d=1.;                         #in diameter of pipe\n",
      "a=((math.pi)*d**2/4.0)/144.0;    #ft^2 area of pipe\n",
      "v_avg=q/a                     #ft/s\n",
      "print \"The average velocity is %f ft/s\"%v_avg"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "volumetric flow rate is 0.016700 ft^3/s\n",
        "Mass flow rate is 0.749095 lbm/s\n",
        "The average velocity is 3.061886 ft/s\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.5 page no : 90\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "\n",
      "# variables\n",
      "d1=2.;                       #ft diameter of pipe at position 1\n",
      "a1=(math.pi)/4*d1**2;        #ft^2\n",
      "v1=50.;                      #ft/s vel of gas at position 1\n",
      "rho1=2.58;                   #lbm/ft^3 density of gas at position 1\n",
      "d2=3.;                       #ft diameter of pipe at position 2\n",
      "\n",
      "# calculation\n",
      "a2=(math.pi)/4*d2**2;\n",
      "rho2=1.54;                   #lbm/ft^3 density at position 2\n",
      "v2=(rho1/rho2)*(a1/a2)*v1    #ft/s\n",
      "\n",
      "# result\n",
      "print \"Velocity is %f ft/s\"%v2\n",
      "m=rho1*v1*a1                 #lbm/s mass flow rate\n",
      "print \"The mass flow rate is %f lbm/s\"%m"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Velocity is 37.229437 ft/s\n",
        "The mass flow rate is 405.265452 lbm/s\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.6 page no : 91\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "\n",
      "# variables\n",
      "d1=0.25;                      #m diameter of pipe at position 1\n",
      "v1=2.;                        #m/s velocity\n",
      "rho=998.2;                    #kg/m^3  density of water\n",
      "a1=(math.pi)/4*d1**2;         #m^2\n",
      "d2=0.125                      #m diameter of pipe at position 2\n",
      "\n",
      "# calculation\n",
      "a2=(math.pi)/4*d2**2;         #m^2\n",
      "m=rho*a1*v1                   #kg/s mass flow rate\n",
      "\n",
      "# result\n",
      "print \"Mass flow rate is %f kg/s\"%m\n",
      "q=m/rho                       #m^3/s volumetric flow rate\n",
      "print \"The volumetric flow rate is %f m^3/s\"%q\n",
      "v2=(a1/a2)*v1                 #m/s velocity\n",
      "print \"Velocity of water is %f m/s\"%v2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Mass flow rate is 97.998056 kg/s\n",
        "The volumetric flow rate is 0.098175 m^3/s\n",
        "Velocity of water is 8.000000 m/s\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.7 page no : 92\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "\n",
      "# variables\n",
      "p_initial=1.;                        #atm pressure initially\n",
      "p_final=0.0001;                      #atm pressure finally\n",
      "V=10.;                               #ft^3 volume of system\n",
      "q=1.;                                #ft^3/min vol. flow rate\n",
      "\n",
      "# calculation\n",
      "t=(V/q)*math.log(p_initial/p_final)  #min\n",
      "\n",
      "# result\n",
      "print \"The time required is %f min\"%t"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The time required is 92.103404 min\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.8 page no : 93\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# variables\n",
      "m_in=0.0001;                      #lbm/min\n",
      "q_out=1.;                         #ft^3/min\n",
      "rho_sys=m_in/q_out                #lbm/ft^3\n",
      "rho_air=0.075;                    #lbm/ft^3\n",
      "p_initial=1.;                     #atm\n",
      "\n",
      "# calculation\n",
      "p_steady=p_initial*(rho_sys/rho_air)          #atm\n",
      "\n",
      "# result\n",
      "print \"The steady state pressure is %f atm\"%p_steady"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The steady state pressure is 0.001333 atm\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.9 page no : 94\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "\n",
      "# variables\n",
      "d=3.;                          #m diameter of tank\n",
      "a=(math.pi)*d**2/4;            #m^2\n",
      "d_in=0.1;                      #m inner diameter of inflow pipe\n",
      "d_out=0.2;                     #m\n",
      "v_in=2.0;                      #m/s\n",
      "v_out=1.0;                     #m/s\n",
      "\n",
      "# calculation\n",
      "q_in=((math.pi)*d_in**2/4.0)*v_in;                #m^3/s\n",
      "q_out=((math.pi)*d_out**2/4.0)*v_out;             #m^3/s\n",
      "\n",
      "#let D represent d/dt\n",
      "DV=q_in-q_out;                 #m^3/s\n",
      "\n",
      "# result\n",
      "if DV>1:\n",
      "    print \"The water level in tank is rising\"\n",
      "elif DV<1:\n",
      "    print \"The water level in tank is falling\"\n",
      "else:\n",
      "    print \"No accumulation\"\n",
      "#let h be the height of water in tank\n",
      "Dh=DV/a                       #m/s \n",
      "print \"The rate of level of water is rising or falling in a cylindrical tank is %f m/s\"%Dh"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The water level in tank is falling\n",
        "The rate of level of water is rising or falling in a cylindrical tank is -0.002222 m/s\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.11 page no : 97\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# variables\n",
      "q=5/8.0;                     #kg/hr mass evaporation rate of benzene\n",
      "c=1.3*10**(-6);              #kg/m^3 concentration of benzene\n",
      "\n",
      "# calculation\n",
      "Q=q/c/3600.0                 #m^3/s\n",
      "\n",
      "# result\n",
      "print \"The flow rate of ventilation air supply is %f m^3/s\"%Q"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The flow rate of ventilation air supply is 133.547009 m^3/s\n"
       ]
      }
     ],
     "prompt_number": 8
    }
   ],
   "metadata": {}
  }
 ]
}