{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Chapter 11: Compressible Flow"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 11.1 Page no 420"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total change in enthalpy for 10 kg air =  180.0 kcal\n"
     ]
    }
   ],
   "source": [
    "# Example 11.1\n",
    "\n",
    "from math import *\n",
    "\n",
    "from __future__ import division\n",
    "\n",
    "# Given\n",
    "\n",
    "T1 = 273 + 15          # temperature in K\n",
    "\n",
    "T2 = 273 + 90          # temperature in K\n",
    "\n",
    "Cp = 0.24              # cp for air in kcal/kgK\n",
    "\n",
    "# Solution\n",
    "\n",
    "dh = Cp*(T2-T1)        # enthalpy per kg of air\n",
    "\n",
    "H = 10*dh              # total enthallpy of 10 kg air\n",
    "\n",
    "print \"Total change in enthalpy for 10 kg air = \",round(H,0),\"kcal\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 11.2 Page no 420"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total change in enthalpy of 10 Kg of air = -0.255 kcal/K\n"
     ]
    }
   ],
   "source": [
    "# Example 11.2\n",
    "\n",
    "from math import *\n",
    "\n",
    "from __future__ import division\n",
    "\n",
    "# Given\n",
    "\n",
    "T1 = 273 + 15          # temperature in K\n",
    "\n",
    "T2 = 273 + 90          # temperature in K\n",
    "\n",
    "P1 = 40 + 101.3        # pressure in abs\n",
    "\n",
    "P2 = 360 + 101.3       # presure in abs\n",
    "\n",
    "Cv = 0.171             # Specific volume Coefficient of air\n",
    "\n",
    "k = 1.4                # gas constant\n",
    "\n",
    "# solution\n",
    "\n",
    "dS = Cv*log((T2/T1)**k*(P2/P1)**(1-k))\n",
    "\n",
    "S = 10*dS\n",
    "\n",
    "print \"Total change in enthalpy of 10 Kg of air =\",round(S,3),\"kcal/K\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 11.3 Page no 421"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Final temperature if air =  320.2 F\n",
      "Total work done on 10 slugs =  330.0 Btu\n"
     ]
    }
   ],
   "source": [
    "# Example 11.3\n",
    "\n",
    "from math import *\n",
    "\n",
    "from __future__ import division\n",
    "\n",
    "\n",
    "P1 = 10                  # pressure in psia\n",
    "\n",
    "P2 = 30                  # pressure in psia\n",
    "\n",
    "T1 = 460+110             # temperature in R\n",
    "\n",
    "k =1.4                   # gas constant\n",
    "\n",
    "T2 = T1*(P2/P1)**((k-1)/k)\n",
    "\n",
    "t2 = T2-460              # final temperature of air\n",
    "\n",
    "print \"Final temperature if air = \",round(t2,1),\"F\"\n",
    "\n",
    "Cv = 0.157               # coefficient of air \n",
    "\n",
    "W = Cv*(T2-T1)           # work done per unit mass of oxygen\n",
    "\n",
    "Tw = 10*W                # total work done on 10 slugs\n",
    "\n",
    "print \"Total work done on 10 slugs = \",round(Tw,0),\"Btu\" \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 11.4 Page no 426"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Speed of sound in water = 1483.0 m/s\n",
      "Speed of sound in ethly alcohol = 1238.0 m/s\n",
      "Speed of sound in Air = 343.0 m/s\n"
     ]
    }
   ],
   "source": [
    "# Example 11.4\n",
    "\n",
    "from math import *\n",
    "\n",
    "from __future__ import division\n",
    "\n",
    "# Given\n",
    "\n",
    "# for water\n",
    "\n",
    "S =1           # specific gravity\n",
    "\n",
    "rho = S*1000   # density in kg/m**3\n",
    "\n",
    "bta = 2.2*10**9 # Bulk modulus of elasticity\n",
    "\n",
    "# ethly alcohol\n",
    "\n",
    "S1 =0.79           # specific gravity\n",
    "\n",
    "rho2 = S1*1000   # density in kg/m**3\n",
    "\n",
    "bta2 = 1.21*10**9 # Bulk modulus of elasticity\n",
    "\n",
    "# for air\n",
    "\n",
    "k = 1.4             # gas constant for air\n",
    "\n",
    "R = 287             # universal gas constant\n",
    "\n",
    "T = 273+20          # temperature in K\n",
    "\n",
    "# Solution\n",
    "\n",
    "C1 = sqrt(bta/rho)\n",
    "\n",
    "C2 = sqrt(bta2/rho2)\n",
    "\n",
    "print \"Speed of sound in water =\",round(C1,0),\"m/s\"\n",
    "\n",
    "print \"Speed of sound in ethly alcohol =\",round(C2,0),\"m/s\"\n",
    "\n",
    "C3 = sqrt(k*R*T)\n",
    "\n",
    "print \"Speed of sound in Air =\",round(C3,0),\"m/s\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example 11.5 Page no 431"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.753305702898\n",
      "Pressure at downstream =  3.03 psia\n",
      "Temperature at downstream =  157.3 F\n",
      "Velocity downstream =  463.02 ft/s\n"
     ]
    }
   ],
   "source": [
    "# Example 11.5\n",
    "\n",
    "from math import *\n",
    "\n",
    "from __future__ import division\n",
    "\n",
    "# Given\n",
    "\n",
    "P1 = 1.5        # pressure in psia\n",
    "\n",
    "T1 = 40 + 460   # temperature in R\n",
    "\n",
    "k = 1.4         # gas constant\n",
    "\n",
    "R = 1716        # universal gas constant in ft.lb/slug R\n",
    "\n",
    "V1 = 1500       # velocity in ft/s\n",
    "\n",
    "# Solution\n",
    "\n",
    "c1 = sqrt(k*R*T1)\n",
    "\n",
    "M1 = V1/c1\n",
    "\n",
    "M2 = sqrt((2+(k-1)*M1**2)/(2*k*M1**2-(k-1)))\n",
    "print M2\n",
    "\n",
    "P2 = P1*((1+k*M1**2)/(1+k*M2**2))\n",
    "\n",
    "print \"Pressure at downstream = \",round(P2,2),\"psia\"\n",
    "\n",
    "T2 = T1*((1+0.5*(k-1)*M1**2)/(1+0.5*(k-1)*M2**2))\n",
    "\n",
    "t2 = T2-460\n",
    "\n",
    "print \"Temperature at downstream = \",round(t2,1),\"F\"\n",
    "V2 = M2*sqrt(k*R*t2)\n",
    "\n",
    "print \"Velocity downstream = \",round(V2,2),\"ft/s\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  }
 ],
 "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.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}