{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 12 - Nozzles"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1: pg 361"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 12.1\n",
      " (a) The throat area is (mm^2) =  255.0\n",
      " (b) The exit area is (mm^2) =  344.0\n",
      " (c) The Mach number at exit is  =  1.49\n"
     ]
    }
   ],
   "source": [
    "#pg 361\n",
    "print('Example 12.1');\n",
    "\n",
    "#  aim : To determine the\n",
    "#  (a) throat area\n",
    "#   (b) exit area\n",
    "#   (c) Mach number at exit\n",
    "from math import sqrt\n",
    "# Given values\n",
    "P1 = 3.5;# inlet pressure of air, [MN/m**2]\n",
    "T1 = 273+500;# inlet temperature of air, [MN/m**2]\n",
    "P2 = .7;# exit pressure, [MN/m**2]\n",
    "m_dot = 1.3;# flow rate of air, [kg/s]\n",
    "Gamma = 1.4;# heat capacity ratio\n",
    "R = .287;# [kJ/kg K]\n",
    "\n",
    "# solution\n",
    "# given expansion may be considered to be adiabatic and to follow the law PV**Gamma=constant\n",
    "# using ideal gas law\n",
    "v1 = R*T1/P1*10**-3;# [m**3/kg]\n",
    "Pt = P1*(2/(Gamma+1))**(Gamma/(Gamma-1));# critical pressure, [MN/m**2]\n",
    "\n",
    "#  velocity at throat is\n",
    "Ct = sqrt(2*Gamma/(Gamma-1)*P1*10**6*v1*(1-(Pt/P1)**(((Gamma-1)/Gamma))));# [m/s]\n",
    "vt = v1*(P1/Pt)**(1/Gamma);# [m**3/kg]\n",
    "# using m_dot/At=Ct/vt\n",
    "At = m_dot*vt/Ct*10**6;# throat area, [mm**2]\n",
    "print ' (a) The throat area is (mm^2) = ',round(At)\n",
    "\n",
    "# (b)\n",
    "#  at exit\n",
    "C2 = sqrt(2*Gamma/(Gamma-1)*P1*10**6*v1*(1-(P2/P1)**(((Gamma-1)/Gamma))));# [m/s]\n",
    "v2 = v1*(P1/P2)**(1/Gamma);# [m**3/kg]\n",
    "A2 = m_dot*v2/C2*10**6;# exit area, [mm**2]\n",
    "\n",
    "print ' (b) The exit area is (mm^2) = ',round(A2)\n",
    "\n",
    "#  (c)\n",
    "M = C2/Ct;\n",
    "print ' (c) The Mach number at exit is  = ',round(M,2)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2: pg 362"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 12.2\n",
      " The increase in pressure is (MN/m^2) =  2.44\n",
      " Increase in temperature is (K) =  358.0\n",
      " Increase in internal energy is  (kJ/kg) =  257.0\n",
      "there is minor variation in result due to rounding off error\n"
     ]
    }
   ],
   "source": [
    "#pg 362\n",
    "print('Example 12.2');\n",
    "\n",
    "#  aim : To determine the increases in pressure, temperature and internal energy per kg of air\n",
    "\n",
    "#  Given values\n",
    "T1 = 273.;# [K]\n",
    "P1 = 140.;# [kN/m**2]\n",
    "C1 = 900.;# [m/s]\n",
    "C2 = 300.;# [m/s]\n",
    "cp = 1.006;# [kJ/kg K]\n",
    "cv =.717;# [kJ/kg K]\n",
    "\n",
    "# solution\n",
    "R = cp-cv;# [kJ/kg K]\n",
    "Gamma = cp/cv;# heat capacity ratio\n",
    "#  for frictionless adiabatic flow, (C2**2-C1**2)/2=Gamma/(Gamma-1)*R*(T1-T2)\n",
    "\n",
    "T2 =T1-((C2**2-C1**2)*(Gamma-1)/(2*Gamma*R))*10**-3; #  [K]\n",
    "T_inc = T2-T1;# increase in temperature [K]\n",
    "\n",
    "P2 = P1*(T2/T1)**(Gamma/(Gamma-1));# [MN/m**2]\n",
    "P_inc = (P2-P1)*10**-3;# increase in pressure,[MN/m**2]\n",
    "\n",
    "U_inc = cv*(T2-T1);#  Increase in internal energy per kg,[kJ/kg]\n",
    "#results\n",
    "print ' The increase in pressure is (MN/m^2) = ',round(P_inc,2)\n",
    "print ' Increase in temperature is (K) = ',round(T_inc)\n",
    "print ' Increase in internal energy is  (kJ/kg) = ',round(U_inc)\n",
    "\n",
    "print 'there is minor variation in result due to rounding off error'\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3: pg 364"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 12.3\n",
      " (a) The throat area is (mm^2) =  2888.0\n",
      "      The exit area is (mm^2) =  4282.0\n",
      " (b) The Degree of undercooling at exit is (C) =  10.3\n",
      " There is some rounding mistake in the book so answer is not matching\n"
     ]
    }
   ],
   "source": [
    "#pg 364\n",
    "print('Example 12.3');\n",
    "from math import sqrt\n",
    "# aim : To determine the \n",
    "#  (a) throat and exit areas\n",
    "#   (b) degree of undercooling at exit\n",
    "# Given values\n",
    "P1 = 2.;# inlet pressure of air, [MN/m**2]\n",
    "T1 = 273.+325;# inlet temperature of air, [MN/m**2]\n",
    "P2 = .36;# exit pressure, [MN/m**2]\n",
    "m_dot = 7.5;# flow rate of air, [kg/s]\n",
    "n = 1.3;# polytropic index\n",
    "\n",
    "# solution\n",
    "# (a)\n",
    "#  using steam table\n",
    "v1 = .132;# [m**3/kg]\n",
    "# given expansion following law PV**n=constant\n",
    "\n",
    "Pt = P1*(2/(n+1))**(n/(n-1));# critical pressure, [MN/m**2]\n",
    "\n",
    "#velocity at throat is\n",
    "Ct = sqrt(2*n/(n-1)*P1*10**6*v1*(1-(Pt/P1)**(((n-1)/n))));# [m/s]\n",
    "vt = v1*(P1/Pt)**(1/n);# [m**3/kg]\n",
    "# using m_dot/At=Ct/vt\n",
    "At = m_dot*vt/Ct*10**6;# throat area, [mm**2]\n",
    "print ' (a) The throat area is (mm^2) = ',round(At)\n",
    "\n",
    "# at exit\n",
    "C2 = sqrt(2*n/(n-1)*P1*10**6*v1*(1-(P2/P1)**(((n-1)/n))));# [m/s]\n",
    "v2 = v1*(P1/P2)**(1/n);# [m**3/kg]\n",
    "A2 = m_dot*v2/C2*10**6;# exit area, [mm**2]\n",
    "\n",
    "print '      The exit area is (mm^2) = ',round(A2)\n",
    "\n",
    "#  (b)\n",
    "T2 = T1*(P2/P1)**((n-1)/n);#outlet temperature, [K]\n",
    "t2 = T2-273;#[C]\n",
    "#  at exit pressure saturation temperature is\n",
    "ts = 139.9;# saturation temperature,[C]\n",
    "Doc = ts-t2;# Degree of undercooling,[C]\n",
    "print ' (b) The Degree of undercooling at exit is (C) = ',round(Doc,1)\n",
    "\n",
    "print' There is some rounding mistake in the book so answer is not matching'\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4: pg 365"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 12.4\n",
      " (a) The throat velocity is (m/s) =  548.0\n",
      "      The exit velocity is  (m/s) =  800.0\n",
      " (b) The throat area is (mm^2) =  3213.0\n",
      "      The throat area is (mm^2) =  6050.0\n"
     ]
    }
   ],
   "source": [
    "#pg 365\n",
    "print('Example 12.4');\n",
    "from math import sqrt\n",
    "# aim : To determine the \n",
    "#  (a) throat and exit velocities\n",
    "#  (b) throat and exit areas\n",
    "\n",
    "# Given values\n",
    "P1 = 2.2;# inlet pressure, [MN/m^2]\n",
    "T1 = 273+260;# inlet temperature, [K]\n",
    "P2 = .4;# exit pressure,[MN/m^2]\n",
    "eff = .85;# efficiency of the nozzle after throat\n",
    "m_dot = 11;# steam flow rate in the nozzle, [kg/s]\n",
    "\n",
    "# solution\n",
    "# (a)\n",
    "# assuming steam is following same law as previous question 12.3\n",
    "Pt = .546*P1;# critical pressure,[MN/m^2]\n",
    "# from Fig. 12.6\n",
    "h1 = 2940;# [kJ/kg]\n",
    "ht = 2790;# [kJ/kg]\n",
    "\n",
    "Ct = sqrt(2*(h1-ht)*10**3);# [m/s]\n",
    "\n",
    "#  again from Fig. 12.6\n",
    "h2_prime = 2590;# [kJ/kg]\n",
    "# using eff = (ht-h2)/(ht-h2_prime)\n",
    "\n",
    "h2 = ht-eff*(ht-h2_prime); # [kJ/kg]\n",
    "\n",
    "C2 = sqrt(2*(h1-h2)*10**3);# [m/s]\n",
    "\n",
    "# (b)\n",
    "# from chart\n",
    "vt = .16;# [m^3/kg]\n",
    "v2 = .44;# [m^3/kg]\n",
    "#  using m_dot*v=A*C\n",
    "At = m_dot*vt/Ct*10**6;# throat area, [mm^2]\n",
    "\n",
    "A2 = m_dot*v2/C2*10**6;# throat area, [mm^2]\n",
    "#results\n",
    "print ' (a) The throat velocity is (m/s) = ',round(Ct)\n",
    "print '      The exit velocity is  (m/s) = ',C2\n",
    "print ' (b) The throat area is (mm^2) = ',round(At)\n",
    "print '      The throat area is (mm^2) = ',A2\n",
    "\n",
    "#  End\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
}