{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 7: First Law of Thermodynamics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 7.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Energy dissipated from the brakes (ft lbf) =  4.00e+05\n",
      "press enter key to exit\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#An automobile with a mass of 3000 lb comes over the top of a hill 50 ft high\n",
    "#with a velocity of 50 mph. Brakes are applied at the instant the automobile \n",
    "#reaches the top, and it comes to rest at the bottom of the hill. How much \n",
    "#energy is dissipated from the brakes?\n",
    "import math\n",
    "#initialisation of variables\n",
    "m= 3000 \t\t\t\t\t\t\t\t\t\t\t#lb\n",
    "Z1= 50 \t\t\t\t\t\t\t\t\t\t\t\t#ft\n",
    "V1= 50 \t\t\t\t\t\t\t\t\t\t\t\t#mph\n",
    "gc= 32.2 \t\t\t\t\t\t\t\t\t\t\t#ft/lbf s^2\n",
    "V2= 0 \t\t\t\t\t\t\t\t\t\t\t\t#mph\n",
    "g= 32.2 \t\t\t\t\t\t\t\t\t\t\t#ft/s^2\n",
    "Z2= 0 \t\t\t\t\t\t\t\t\t\t\t\t#ft\n",
    "#CALCULATIONS\n",
    "V1= V1*(73.3/50.) \t\t\t\t\t\t\t\t\t#Velocity\n",
    "Q2= ((m*(V2*V2-V1*V1))/(2*gc))+((m*g)/gc)*(Z2-Z1)\n",
    "#RESULTS\n",
    "print '%s %.2e' % ('Energy dissipated from the brakes (ft lbf) = ',-Q2)\n",
    "raw_input('press enter key to exit')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 7.2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "From keenan and keyes steam tables\n",
      "Temperature of the steam in the tank (C) =  453.40\n",
      "press enter key to exit\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Steam at a pressure of 13 bar and a temperature of 300C flows adiabatically \n",
    "#and with negligible velocity into an evacuated tank. Using a closed system\n",
    "#analysis, determine the temperature of the steam in the tank reaches line\n",
    "#pressure.\n",
    "#initialisation of variables\n",
    "P= 15 \t\t\t\t\t\t#bar\n",
    "T= 300 \t\t\t\t\t\t#C\n",
    "h1= 3043.1 \t\t\t\t\t#J/gm\n",
    "#CALCULATIONS\n",
    "u2= h1 \n",
    "print '%s' %('From keenan and keyes steam tables')\n",
    "T= 453.4  \t\t\t\t\t#C temperature\n",
    "#RESULTS\n",
    "print '%s %.2f' % ('Temperature of the steam in the tank (C) = ',T)\n",
    "raw_input('press enter key to exit')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 7.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Heat transferred to the tank (Btu) =  267.00\n",
      "press enter key to exit\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#A 10 lb mass of air at 120F is contained in a rigid tank. How much heat\n",
    "#is transferred to the tank to raise the air temperature of 275 F?\n",
    "#initialisation of variables\n",
    "m= 10 \t\t\t\t\t\t\t#lbf\n",
    "T= 120 \t\t\t\t\t\t\t#F\n",
    "T1= 275 \t\t\t\t\t\t#F\n",
    "u1= 98.9 \t\t\t\t\t\t#Btu/lbm\n",
    "u2= 125.6 \t\t\t\t\t\t#Btu/lbm\n",
    "#CALCULATIONS\n",
    "Q= m*(u2-u1) \t\t\t\t\t#Heat transferred\n",
    "#RESULTS\n",
    "print '%s %.2f' % ('Heat transferred to the tank (Btu) = ',Q)\n",
    "raw_input('press enter key to exit')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 7.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum theotrical power that can be devoloped (J/s) =  1.00e+05\n",
      "press enter key to exit\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Fluid enters a turbine with a velocity of 1 m/s and an enthalpy of 2000 j/gm;\n",
    "#it leaves with a velocity of 60 m/s and enthalpy of 1800 J/gm. Heat losses\n",
    "#are 500 J/s, and the flow rate is 0.5 kg/s. If the inlet of the turbine is \n",
    "#3 m higher than the outlet, what is the maximum theoretical power\n",
    "# that can be developed?\n",
    "#initialisation of variables\n",
    "v0= 1 \t\t\t\t\t\t\t\t\t\t\t\t\t#m/s\n",
    "vi= 60 \t\t\t\t\t\t\t\t\t\t\t\t\t#m/s\n",
    "Q= -500 \t\t\t\t\t\t\t\t\t\t\t\t#J/s\n",
    "m= 500 \t\t\t\t\t\t\t\t\t\t\t\t\t#gm/s\n",
    "hi= 2000 \t\t\t\t\t\t\t\t\t\t\t\t#J/gm\n",
    "h0= 1800 \t\t\t\t\t\t\t\t\t\t\t\t#J/gm\n",
    "zi= 3 \t\t\t\t\t\t\t\t\t\t\t\t\t#m\n",
    "z0= 0 \t\t\t\t\t\t\t\t\t\t\t\t\t#m\n",
    "g= 9.8 \t\t\t\t\t\t\t\t\t\t\t\t\t#m/s^2\n",
    "gc= 1000. \t\t\t\t\t\t\t\t\t\t\t\t#gm m/Ns^2\n",
    "#CALCULATIONS\n",
    "W= Q+m*((hi-h0)+(vi*vi-v0*v0)/(2*gc)+(g/gc)*(zi-z0)) \t#Work\n",
    "#RESULTS\n",
    "print '%s %.2e' % ('Maximum theotrical power that can be devoloped (J/s) = ',W)\n",
    "raw_input('press enter key to exit')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 7.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Required steam flow rate (gm/s) =  36.36\n",
      "press enter key to exit\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#To produce 0.3 lt/s hot water at 82 C, low pressure steam at 2.4 bar and \n",
    "#80 percent quality is mixed with a stream of water at 16 C. What is the \n",
    "#required steam flow rate?\n",
    "#initialisation of variables\n",
    "m= 0.3 \t\t\t\t\t\t\t\t#lt/s\n",
    "T= 82 \t\t\t\t\t\t\t\t#C\n",
    "P= 2.4 \t\t\t\t\t\t\t\t#bar\n",
    "p= 80.\n",
    "Tw= 800 \t\t\t\t\t\t\t#C\n",
    "h1= 67.19 \t\t\t\t\t\t\t#J/gm\n",
    "h3= 343.3 \t\t\t\t\t\t\t#J/gm\n",
    "hf= 529.65 \t\t\t\t\t\t\t#J/gm\n",
    "hfg= 2185.4 \t\t\t\t\t\t#J/gm\n",
    "v3= 1.0305 \t\t\t\t\t\t\t#cm^3/gm\n",
    "V3= 300 \t\t\t\t\t\t\t#cm^3/s\n",
    "#CALCULATIONS\n",
    "h2= hf+(p/100.)*hfg\t\t\t\t\t#Enthalpy at 2\n",
    "m3= V3/v3 \t\t\t\t\t\t\t#Mass at 3\n",
    "m2= (m3*(h3-h1))/(h2-h1) \t\t\t#Mass at 2\n",
    "#RESULTS\n",
    "print '%s %.2f' % ('Required steam flow rate (gm/s) = ',m2)\n",
    "raw_input('press enter key to exit')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 7.6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Difference between the enthalpies of the system in the two phases ((h2-h1) J/gm) =  1.00\n",
      "press enter key to exit\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Latent heat of transforation can be defined as the ratio of heat absorbed\n",
    "#to the mass which undergoes a change of phase(L=Q/m). Show that the heat of \n",
    "#transformation for any phase change equals the difference between the \n",
    "#enthalphies of the system in the two phases.\n",
    "#initialisation of variables\n",
    "h2= 2 \t\t\t\t\t#J/gm\n",
    "h1= 1 \t\t\t\t\t#J/gm\n",
    "#CALCULATIONS\n",
    "L= h2-h1 \t\t\t\t#Difference between enthalpies\n",
    "#RESULTS\n",
    "print '%s %.2f' % ('Difference between the enthalpies of the system in the two phases ((h2-h1) J/gm) = ',L)\n",
    "raw_input('press enter key to exit')"
   ]
  }
 ],
 "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
}
