{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 05:First law applied to Flow Processes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex5.1:pg-97"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 5.1\n",
      "\n",
      " The rate of work input is  116.0  kW\n",
      "\n",
      " The ratio of the inlet pipe diameter and outet pipe diameter is  0.0  \n"
     ]
    }
   ],
   "source": [
    "# Part(a)\n",
    "import math\n",
    "V1 = 0.95 # Inlet volume flow rate in m**3/kg\n",
    "\n",
    "P1 = 100 # Pressure at inlet in kPa\n",
    "\n",
    "v1 = 7 # velocity of flow at inlet in m/s\n",
    "\n",
    "V2 = 0.19 # Exit volume flow rate in m**3/kg\n",
    "\n",
    "P2 = 700 # Pressure at exit in kPa \n",
    "\n",
    "v2 = 5 # velocity of flow at exit in m/s\n",
    "\n",
    "w = 0.5 # mass flow rate in kg/s\n",
    "\n",
    "u21 = 90  # change in internal energy in kJ/kg\n",
    "\n",
    "Q = -58  # Heat transfer in kW\n",
    "\n",
    "W =  - w*( u21 + (P2*V2-P1*V1) + ((v2**2-v1**2)/2) ) + Q  # W = dW/dt  \n",
    "\n",
    "print \"\\n Example 5.1\"\n",
    "\n",
    "print \"\\n The rate of work input is \",abs(W) ,\" kW\"\n",
    "\n",
    "#The answers given in textbook is wrong\n",
    "\n",
    "# Part (b)\n",
    "\n",
    "A = (v2/v1)*(V1/V2)  # A = A1/A2\n",
    "\n",
    "d_ratio = math.sqrt(A)  # d = d1/d2\n",
    "\n",
    "print \"\\n The ratio of the inlet pipe diameter and outet pipe diameter is \",d_ratio ,\" \"\n",
    "\n",
    "#The answers vary due to round off error\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex5.2:pg-98"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 5.2\n",
      "\n",
      " The internal energy decreases by  20.0  kJ\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "V1 = 0.37 # volume flow rate at inlet in m**3/kg\n",
    "\n",
    "P1 = 600# Inlet pressure in kPa\n",
    "\n",
    "v1 = 16 # Inlet velocity of flow in m/s\n",
    "\n",
    "V2 = 0.62 # volume flow rate at exit in m**3/kg \n",
    "\n",
    "P2 = 100# Exit pressure in kPa\n",
    "\n",
    "v2 = 270 # Exit velocity of flow in m/s\n",
    "\n",
    "Z1 = 32 # Height of inlet port from datum in m\n",
    "\n",
    "Z2 = 0 #Height of exit port from datum in m\n",
    "\n",
    "g = 9.81  # Acceleration due to gravity\n",
    "\n",
    "Q = -9  # Heat transfer in kJ/kg\n",
    "\n",
    "W = 135  # Work transfer in kJ/kg\n",
    "\n",
    "U12 = (P2*V2-P1*V1) + ((v2**2-v1**2)/2000) + (Z2-Z1)*g*1e-3 + W - Q  # Change in internal energy in kJ\n",
    "\n",
    "\n",
    "\n",
    "print \"\\n Example 5.2\"\n",
    "\n",
    "print \"\\n The internal energy decreases by \",round(U12) ,\" kJ\"\n",
    "\n",
    "#The answers vary due to round off error\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex5.3:pg-99"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 5.3\n",
      "\n",
      " The steam flow rate is  53.5854836932  Kg/s\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "P1 = 4 # Boiler pressure in MPa\n",
    "\n",
    "t1 = 400 # Exit temperature at boiler in degree Celsius\n",
    "\n",
    "h1 = 3213 # Enthalpy at boiler exit in kJ/kg\n",
    "\n",
    "V1 = 0.073 # specific volume at boiler exit in m**3/kg\n",
    "\n",
    "P2 = 3.5 # Pressure at turbine end in MPa\n",
    "\n",
    "t2 = 392 # Turbine exit temperature in degree Celsius\n",
    "\n",
    "h2 = 3202 # Enthalpy at turbine exit in kJ/kg\n",
    "\n",
    "V2 = 0.084 # specific volume at turbine exit in m**3/kg\n",
    "\n",
    "Q = -8.5 # Heat loss from pipeline in kJ/kg\n",
    "\n",
    "v1 = math.sqrt((2*(h1-h2+Q)*1e3)/(1.15**2-1)) # velocity of flow in m/s\n",
    "\n",
    "A1 = (math.pi/4)*0.2**2 # Area of pipe in m**2\n",
    "\n",
    "w = (A1*v1)/V1 # steam flow rate in Kg/s\n",
    "\n",
    "\n",
    "\n",
    "print \"\\n Example 5.3\"\n",
    "\n",
    "print \"\\n The steam flow rate is \",w ,\" Kg/s\"\n",
    "\n",
    "#The answers vary due to round off error\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex5.4:pg-100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 5.4\n",
      "\n",
      " The amount of heat that should be supplied is  703.880549402  Kg/h\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "h1 = 313.93 # Enthalpy of water at heater inlet in kJ/kg\n",
    "\n",
    "h2 = 2676 # Enthalpy of hot water at temperature 100.2 degree Celsius\n",
    "\n",
    "h3 = 419 #Enthalpy of water at heater inlet in kJ/kg\n",
    "\n",
    "w1 = 4.2 # mass flow rate in kg/s\n",
    "\n",
    "\n",
    "\n",
    "print \"\\n Example 5.4\"\n",
    "\n",
    "w2 = w1*(h3-h1)/(h2-h3)# Steam rate  \n",
    "\n",
    "print \"\\n The amount of heat that should be supplied is \",w2*3600 ,\" Kg/h\"\n",
    "\n",
    "\n",
    "\n",
    "#The answers vary due to round off error\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex5.5:pg-100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 5.5\n",
      "\n",
      " The rate of heat transfer to the air in the heat exchanger is  1577.85  kJ/s\n",
      "\n",
      " The power output from the turbine assuming no heat loss is  298  kW\n",
      "\n",
      " The velocity at the exit of the nozzle is  552.358579186  m/s\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "t1 = 15 # Heat exchanger inlet temperature in degree Celsius\n",
    "\n",
    "t2 = 800 # Heat exchanger exit temperature in degree Celsius\n",
    "\n",
    "t3 = 650 # Turbine exit temperature in degree Celsius\n",
    "\n",
    "t4 = 500 # Nozzle exit temperature in degree Celsius\n",
    "\n",
    "v1 = 30 # Velocity of steam at heat exchanger inlet in m/s\n",
    "\n",
    "v2 = 30# Velocity of steam at turbine inlet in m/s\n",
    "\n",
    "v3 = 60 # Velocity of steam at nozzle inlet in m/s\n",
    "\n",
    "w = 2 # mass flow rate in kg/s\n",
    "\n",
    "cp = 1005 # Specific heat capacity of air in kJ/kgK\n",
    "\n",
    "\n",
    "\n",
    "print \"\\n Example 5.5\"\n",
    "\n",
    "Q1_2 = w*cp*(t2-t1) # rate of heat transfer\n",
    "\n",
    "print \"\\n The rate of heat transfer to the air in the heat exchanger is \",Q1_2/1e3 ,\" kJ/s\"\n",
    "\n",
    "\n",
    "\n",
    "W_T = w*( ((v2**2-v3**2)/2) + cp*(t2-t3)) # power output from the turbine\n",
    "\n",
    "print \"\\n The power output from the turbine assuming no heat loss is \",W_T/1000 ,\" kW\"\n",
    "\n",
    "v4 = math.sqrt( (v3**2) + (2*cp*(t3-t4)) ) # velocity at the exit of the nozzle\n",
    "\n",
    "print \"\\n The velocity at the exit of the nozzle is \",v4 ,\" m/s\"\n",
    "\n",
    "#The answers vary due to round off error\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex5.6:pg-102"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 5.6\n",
      "\n",
      " Velocity of exhaust gas is  541.409855832  m/s\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "ha = 260  # Enthalpy of air in kJ/kg\n",
    "\n",
    "hg = 912  # Enthalpy of gas in kJ/kg\n",
    "\n",
    "Va = 270  # Velocity of air in m/s\n",
    "\n",
    "wf = 0.0190  # mass of fuel in Kg\n",
    "\n",
    "wa = 1 # mass of air in Kg\n",
    "\n",
    "Ef = 44500  # Chemical energy of fuel in kJ/kg\n",
    "\n",
    "Q = 21  # Heat loss from the engine in kJ/kg\n",
    "\n",
    "\n",
    "\n",
    "print \"\\n Example 5.6\"\n",
    "\n",
    "Eg = 0.05*wf*Ef/(1+wf)  # As 5% of chemical energy is not released in reaction\n",
    "\n",
    "wg = wa+wf # mass of flue gas\n",
    "\n",
    "Vg = math.sqrt(2000*(((ha+(Va**2*0.001)/2+(wf*Ef)-Q)/(1+wf))-hg-Eg)) \n",
    "\n",
    "\n",
    "\n",
    "print \"\\n Velocity of exhaust gas is \",Vg ,\" m/s\"\n",
    "\n",
    "#Answer given in textbook is wrong\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex5.8:pg-103"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 5.8\n",
      "\n",
      " The rate at which air flows out of the tank is  0.85  kg/h\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "# Given that\n",
    "\n",
    "V = 0.12 # Volume of tank in m**3\n",
    "\n",
    "p = 1 # Pressure in MPa\n",
    "\n",
    "T = 150 # Temperature in degree centigrade\n",
    "\n",
    "P = 0.1 # Power to peddle wheel in kW\n",
    "\n",
    "print \"\\n Example 5.8\"\n",
    "\n",
    "u0 = 0.718*273 # Internal energy at 0 degree Celsius\n",
    "\n",
    "# Function for internal energy of gas\n",
    "\n",
    "def f1(t):\n",
    "    u = u0+(0.718*t)\n",
    "    pv = 0.287*(273+t)\n",
    "    return (u,pv)\n",
    "       \n",
    "U,PV=f1(T)\n",
    "       \n",
    "       \n",
    "hp = U+PV # At 150 degree centigrade\n",
    "m_a = P/hp\n",
    "       \n",
    "print \"\\n The rate at which air flows out of the tank is \",round(m_a*3600,2) ,\" kg/h\"\n",
    "\n",
    "#The answers vary due to round off error\n",
    "\n",
    "\n",
    "\n"
   ]
  }
 ],
 "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.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}