{
 "metadata": {
  "name": "",
  "signature": "sha256:2bebadfad4a18ede042a136ada8984e181f57290a23ad4ed8003a1f83445a447"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 25: Machine\u2013Network Interactions"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 25.4, Page 893"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "\n",
      " #Initializing  the  variables\n",
      "Pa_P1  =  -200;                                                      #  From  previous  Question\n",
      "Q  =  1.4311  ;                                                        #  From  previous  questions.\n",
      "\n",
      " #Calculations\n",
      "DpSys  =  Pa_P1  +  98.9*Q**2;\n",
      "print \"System Operating point (m^3/s):\",round(DpSys,2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "System Operating point (m^3/s): 2.55\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 25.7, Page 906"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "import sympy\n",
      "from sympy import solve,symbols\n",
      "   \n",
      "\n",
      " #Initializing  the  variables\n",
      "Vo  =  25.3;                                                            #Outlet  velocity\n",
      "D  =  10  ;                                                                #  Mean  hydraulic  diameter\n",
      "f  =  0.008;                                                            #  friction  factor\n",
      "X  =  1000;                                                              #  Length  of  road\n",
      "P  =  12600;                                                            #  Absorbing  power\n",
      "Va  =  300;                                                              #  Tunnel  air  flow\n",
      "K1  =  0.96;\n",
      "K2  =  0.9;\n",
      "T  =  590;                                                                #Thrust\n",
      "rho  =  1.2;                                                            #  Air  density  \n",
      "\n",
      " #Calculations\n",
      "alpha  =  (1/D)**2;\n",
      "A  =  math.pi*D**2/4;                                                    #  Area  of  tunnel\n",
      "Vt  =  Va/A;\n",
      "W  =  Vo/Vt;                                                            #Omega\n",
      "E  =  (1-alpha*W);\n",
      "C  =  (1-alpha*W)*(1-E)**2  +  E**2  -  1;\n",
      " #  Manipulating  equation  25.20;\n",
      "LHS  =  f*X*(E+1)**2/D  +  C  +  1  ;\n",
      "\n",
      "n1  =  symbols('n1')\n",
      "result=solve(K1*(2*((alpha*W**2 + (1-alpha)*E**2-1)+(n1-1)*(alpha*W*(W-1)-C/2)))-LHS)\n",
      "\n",
      "n=result[0]\n",
      "\n",
      "\n",
      " #  Alternative  approach  using  equation  25.22\n",
      "n2  =  (rho*((4*f*X*Vt**2)/(2*D)    +  1.5*Vt**2/2))*A/(K1*K2*T);  \n",
      "Pt  =  round(n2)*P;\n",
      "\n",
      "print \"Number of fans required    :\",round(n2)\n",
      "print \"Total  power consumed (KW) :\",Pt/1000"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Number of fans required    : 6.0\n",
        "Total  power consumed (KW) : 75.6\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 25.8, Page 907"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "import sympy\n",
      "from sympy import solve,symbols\n",
      " #Initializing  the  variables\n",
      "f  =  0.008;\n",
      "T  =  290;\n",
      "L  =  750;\n",
      "Dt  =  9;                                                                  #  Diameter  Tunnel\n",
      "Df  =  0.63;                                                            #  Diameter  fan\n",
      "K1  =  0.98;\n",
      "K2  =  0.92;\n",
      "Vo  =  27.9;\n",
      "n  =  10;\n",
      "A=math.pi*Dt**2/4\n",
      "rho=1.2\n",
      "X=750\n",
      " #Calculations\n",
      "alpha  =  (Df/Dt)**2;\n",
      " #  equation  25.20  becomes  when  E  =  1  nad  C  =  0\n",
      "W=symbols('W')\n",
      "omega  =  solve(2*K1*  (alpha*W**2  +(n-1)*alpha*W*(W-1))  -  4*f*L/Dt  -1)\n",
      "  \n",
      "\n",
      "for i in range(1,len(omega)):  #  since  omega  is  always  positive  and  real\n",
      "    if omega[i]>0:\n",
      "        w  =  round(omega[i],1);\n",
      "Vt  =  Vo/w;\n",
      "\n",
      "# by equation 25.22\n",
      "VT=(n*(K1*K2*T)/(A*(rho*((4*f*X)/(2*Dt)    +  1.5/2))))**0.5\n",
      "print \"Tunnel Velocity  (m/s) :\",round(VT,2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Tunnel Velocity  (m/s) : 4.05\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 25.9, Page 914"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "\n",
      "\n",
      " #Initializing  the  variables\n",
      "Ws  =  0.45;\n",
      "Ks  =  3.2;\n",
      "H  =  152;\n",
      "h  =  0;\n",
      "Hatm  =  10.3;\n",
      "Pv  =  350;                             #vapour  pressure\n",
      "g  =  9.81;\n",
      "rho  =  1000;\n",
      "     \n",
      " #Calculations\n",
      "Ht1  =  152*(Ws/Ks)**(4/3);     # the value of Ht1 is 11.12 and in book it is taken as 11.2 so there will be a difference in final answer\n",
      "Hvap  = round(Pv/(rho*g),3);\n",
      "Z  =  Hatm  -h  -Hvap  -Ht1;\n",
      "print \"Elevation of pump (m):\",round(Z,3)\n",
      "    "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Elevation of pump (m): -0.851\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 25.11, Page 927"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "import sympy\n",
      "from sympy import symbols,solve\n",
      "import numpy as np\n",
      "   \n",
      "\n",
      " #Initializing  the  variables\n",
      "Co  =  0;\n",
      "Qc  =  0.0024;\n",
      "V  =  5400;\n",
      "c  =  10;\n",
      " #Calculations\n",
      "#####--------------------PART(A)-----------------#######\n",
      "n1=symbols('n1')\n",
      "def partA(n1):\n",
      "    Ci = 10;\n",
      "    # t = infinity so e^(-nt) = 0\n",
      "    Q=10000*Qc/(c-Co)\n",
      "    n1 = Q*3600/V;    \n",
      "    return n1\n",
      "ans=partA(n1)\n",
      "\n",
      "print \"Part(A) : number of air changes per hour if the garage is in continuous use and the maximum permissible concentration of carbon monoxide is 0.1 per cent. :\",ans,\"\\n\"\n",
      "\n",
      "#####--------------------PART(B)-----------------#######\n",
      "n=symbols('n')\n",
      "def   partB(n):\n",
      "    Ci  =  0;         \n",
      "    n=[1.5,1.2,0.9,1.0]    \n",
      "    t=1      #  time  in  hours\n",
      "    error=[]\n",
      "    mini=100\n",
      "    ans=0\n",
      "    for i in range(4):    \n",
      "        Q  =  V/3600;           \n",
      "        A  =   10000*Qc/Q;                                                            # as Co=0 \n",
      "        error.append(abs((A*(1-math.e**(-n[i]*t))/c)-n[i]));\n",
      "        if(error[i]<mini):\n",
      "            mini=error[i]\n",
      "            ans=n[i]\n",
      "    return ans       \n",
      "ans=partB(n)\n",
      "print \"Part(B) : number of air changes per hour if this maximum level is reached after 1 hour and the garage is out of use :\",ans,'\\n'\n",
      "  \n",
      "#####--------------------PART(C)-----------------#######\n",
      "c=symbols('c')\n",
      "def   partC(c):\n",
      "    Ci  =  0;\n",
      "    n  =  1;   \n",
      "    t = 0.333333                         #  20  minutes  in  hours\n",
      "    Q  =  V*n/3600;\n",
      "    y  =    (Co  +  10000*Qc/Q)*(1-math.e**(-n*t)) + Ci*math.e**(-n*t) ;  \n",
      "    return y\n",
      "ans=partC(c)\n",
      "print \"Part(C) :the concentration after 20 minutes (Parts per 10000) :\",round(ans,3),'\\n'\n",
      "#####--------------------PART(D)-----------------#######\n",
      "t=symbols('t')\n",
      "def   partD(t):\n",
      "    Ci  =  10;\n",
      "    n  =  1;  \n",
      "    c  =  0.1;\n",
      "    t=np.log(100) \n",
      "    return round(t,2)\n",
      "ans=partD(t)    \n",
      "print \"Part(D) : time necessary to run the ventilation system at the rate calculated in (b) to reduce the concentration to 0.001 per cent (in hours) :\",ans,\"hours\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part(A) : number of air changes per hour if the garage is in continuous use and the maximum permissible concentration of carbon monoxide is 0.1 per cent. : 1.6 \n",
        "\n",
        "Part(B) : number of air changes per hour if this maximum level is reached after 1 hour and the garage is out of use : 1.0 \n",
        "\n",
        "Part(C) :the concentration after 20 minutes (Parts per 10000) : 4.535 \n",
        "\n",
        "Part(D) : time necessary to run the ventilation system at the rate calculated in (b) to reduce the concentration to 0.001 per cent (in hours) : 4.61 hours\n"
       ]
      }
     ],
     "prompt_number": 3
    }
   ],
   "metadata": {}
  }
 ]
}