{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 13:One Dimensional Compressible Fluid Flow"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 13.1;pg no: 525"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 13.1, Page:525  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 13 Example 1\n",
      "mass flow rate(m)=rho*A*C\n",
      "so rho*C=4*m/(%pi*d^2)\n",
      "so rho=165.79/C\n",
      "now using perfect gas equation,p=rho*R*T\n",
      "T=P/(rho*R)=P/((165.79/C)*R)\n",
      "C/T=165.79*R/P\n",
      "so C=1.19*T\n",
      "we know,C^2=((2*y*R)/(y-1))*(To-T)\n",
      "C^2=(2*1.4*287)*(300-T)/(1.4-1)\n",
      "C^2=602.7*10^3-2009*T\n",
      "C^2+1688.23*C-602.7*10^3=0\n",
      "solving we get,C=302.72 m/s and T=254.39 K\n",
      "using stagnation property relation,\n",
      "To/T=1+(y-1)*M^2/2\n",
      "so M= 0.947\n",
      "stagnation pressure,Po in bar= 0.472\n",
      "so mach number=0.947,stagnation pressure=0.472 bar,velocity=302.72 m/s\n"
     ]
    }
   ],
   "source": [
    "#cal of mach number,stagnation pressure,velocity\n",
    "#intiation of all variables\n",
    "# Chapter 13\n",
    "import math\n",
    "print\"Example 13.1, Page:525  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 13 Example 1\")\n",
    "To=(27+273);#stagnation temperature in K\n",
    "P=0.4*10**5;#static pressure in pa\n",
    "m=3000/3600;#air flowing rate in kg/s\n",
    "d=80*10**-3;#diameter of duct in m\n",
    "R=287;#gas constant in J/kg K\n",
    "y=1.4;#expansion constant\n",
    "print(\"mass flow rate(m)=rho*A*C\")\n",
    "print(\"so rho*C=4*m/(%pi*d^2)\")\n",
    "4*m/(math.pi*d**2)\n",
    "print(\"so rho=165.79/C\")\n",
    "print(\"now using perfect gas equation,p=rho*R*T\")\n",
    "print(\"T=P/(rho*R)=P/((165.79/C)*R)\")\n",
    "print(\"C/T=165.79*R/P\")\n",
    "165.79*R/P\n",
    "print(\"so C=1.19*T\")\n",
    "print(\"we know,C^2=((2*y*R)/(y-1))*(To-T)\")\n",
    "print(\"C^2=(2*1.4*287)*(300-T)/(1.4-1)\")\n",
    "print(\"C^2=602.7*10^3-2009*T\")\n",
    "print(\"C^2+1688.23*C-602.7*10^3=0\")\n",
    "print(\"solving we get,C=302.72 m/s and T=254.39 K\")\n",
    "C=302.72;\n",
    "T=254.39;\n",
    "print(\"using stagnation property relation,\")\n",
    "print(\"To/T=1+(y-1)*M^2/2\")\n",
    "M=math.sqrt(((To/T)-1)/((y-1)/2))\n",
    "print(\"so M=\"),round(M,3)\n",
    "M=0.947;#approx.\n",
    "Po=P*(1+(y-1)*M**2/2)/10**5\n",
    "print(\"stagnation pressure,Po in bar=\"),round(Po,3)\n",
    "print(\"so mach number=0.947,stagnation pressure=0.472 bar,velocity=302.72 m/s\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 13.2;pg no: 525"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 13.2, Page:525  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 13 Example 2\n",
      "mach number,M_a=(1/sin(a))=sqrt(2)\n",
      "here,P/Po=0.25/1.01=0.2475.Corresponding to this P/Po ratio the mach number and T/To can be seen from air table as M=1.564 and T/To=0.6717\n",
      "T=To*0.6717 in K\n",
      "and C_max=M*sqrt(y*R*T) in m/s\n",
      "corresponding to mach number(M_a=1.414)as obtained from experimental observation,the T/To can be seen from air table and it comes out as (T/To)=0.7145\n",
      "so T=0.7145*To in K\n",
      "and C_av=M_a*sqrt(y*R*T) in m/s\n",
      "ratio of kinetic energy= 0.869\n",
      "so ratio of kinetic energy=0.869\n"
     ]
    }
   ],
   "source": [
    "#cal of ratio of kinetic energy\n",
    "#intiation of all variables\n",
    "# Chapter 13\n",
    "import math\n",
    "print\"Example 13.2, Page:525  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 13 Example 2\")\n",
    "To=(273.+1100.);#stagnation temperature in K\n",
    "a=45.;#mach angle over exit cross-section in degree\n",
    "Po=1.01;#pressure at upstream side of nozzle in bar\n",
    "P=0.25;#ststic pressure in bar\n",
    "y=1.4;#expansion constant \n",
    "R=287.;#gas constant in J/kg K\n",
    "print(\"mach number,M_a=(1/sin(a))=sqrt(2)\")\n",
    "M_a=math.sqrt(2)\n",
    "M_a=1.414;#approx.\n",
    "print(\"here,P/Po=0.25/1.01=0.2475.Corresponding to this P/Po ratio the mach number and T/To can be seen from air table as M=1.564 and T/To=0.6717\")\n",
    "M=1.564;\n",
    "print(\"T=To*0.6717 in K\")\n",
    "T=To*0.6717\n",
    "print(\"and C_max=M*sqrt(y*R*T) in m/s\")\n",
    "C_max=M*math.sqrt(y*R*T)\n",
    "print(\"corresponding to mach number(M_a=1.414)as obtained from experimental observation,the T/To can be seen from air table and it comes out as (T/To)=0.7145\")\n",
    "print(\"so T=0.7145*To in K\")\n",
    "T=0.7145*To\n",
    "print(\"and C_av=M_a*sqrt(y*R*T) in m/s\")\n",
    "C_av=M_a*math.sqrt(y*R*T)\n",
    "print(\"ratio of kinetic energy=\"),round(((1./2.)*C_av**2)/((1./2.)*C_max**2),3)\n",
    "print(\"so ratio of kinetic energy=0.869\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 13.3;pg no: 526"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 13.3, Page:526  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 13 Example 3\n",
      "From bernoulli equation,Po-P=(1/2)*rho*C^2\n",
      "so Po=P+(1/2)*rho*C^2 in N/m^2\n",
      "speed indicator reading shall be given by mach no.s\n",
      "mach no.,M=C/a=C/sqrt(y*R*T)\n",
      "using perfect gas equation,P=rho*R*T\n",
      "so T=P/(rho*R)in K\n",
      "so mach no.,M 0.95\n",
      "considering compressibility effect,Po/P=(1+(y-1)*M^2/2)^(y/(y-1))\n",
      "so stagnation pressure,Po=P*((1+(y-1)*M^2/2)^(y/(y-1)))in N/m^2\n",
      "also Po-P=(1+k)*(1/2)*rho*C^2\n",
      "substitution yields,k= 0.2437\n",
      "so compressibility correction factor,k=0.2437\n"
     ]
    }
   ],
   "source": [
    "#cal of mach no,compressibility correction factor\n",
    "#intiation of all variables\n",
    "# Chapter 13\n",
    "import math\n",
    "print\"Example 13.3, Page:526  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 13 Example 3\")\n",
    "C=300.;#aircraft flying speed in m/s\n",
    "P=0.472*10**5;#altitude pressure in Pa\n",
    "rho=0.659;#density in kg/m^3\n",
    "y=1.4;#expansion constant\n",
    "R=287.;#gas constant in J/kg K\n",
    "print(\"From bernoulli equation,Po-P=(1/2)*rho*C^2\")\n",
    "print(\"so Po=P+(1/2)*rho*C^2 in N/m^2\")\n",
    "Po=P+(1/2)*rho*C**2\n",
    "print(\"speed indicator reading shall be given by mach no.s\")\n",
    "print(\"mach no.,M=C/a=C/sqrt(y*R*T)\")\n",
    "print(\"using perfect gas equation,P=rho*R*T\")\n",
    "print(\"so T=P/(rho*R)in K\")\n",
    "T=P/(rho*R)\n",
    "M=C/math.sqrt(y*R*T)\n",
    "print(\"so mach no.,M\"),round(M,2)\n",
    "M=0.947;#approx.\n",
    "print(\"considering compressibility effect,Po/P=(1+(y-1)*M^2/2)^(y/(y-1))\")\n",
    "print(\"so stagnation pressure,Po=P*((1+(y-1)*M^2/2)^(y/(y-1)))in N/m^2\")\n",
    "Po=P*((1+(y-1)*M**2/2)**(y/(y-1)))\n",
    "print(\"also Po-P=(1+k)*(1/2)*rho*C^2\")\n",
    "k=((Po-P)/((1./2.)*rho*C**2))-1.\n",
    "print(\"substitution yields,k=\"),round(k,4)\n",
    "print(\"so compressibility correction factor,k=0.2437\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 13.4;pg no: 527"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 13.4, Page:527  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 13 Example 4\n",
      "we know that,Po/P=(1+(y-1)*M^2/2)^((y)/(y-1))\n",
      "so M= 1.897\n",
      "so mach number,M=1.89\n"
     ]
    }
   ],
   "source": [
    "#cal of mach number\n",
    "#intiation of all variables\n",
    "# Chapter 13\n",
    "import math\n",
    "print\"Example 13.4, Page:527  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 13 Example 4\")\n",
    "Po=2;#total pressure in bar\n",
    "P=0.3;#static pressure in bar\n",
    "y=1.4;#expansion constant\n",
    "print(\"we know that,Po/P=(1+(y-1)*M^2/2)^((y)/(y-1))\")\n",
    "M=math.sqrt((math.exp(math.log(Po/P)/(y/(y-1)))-1)/((y-1)/2))\n",
    "print(\"so M=\"),round(M,3)\n",
    "print(\"so mach number,M=1.89\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 13.5;pg no: 527"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 13.5, Page:527  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 13 Example 5\n",
      "actual static pressure(P)=1+0.3 in bar\n",
      "It is also given that,Po-P=0.6,\n",
      "so Po=P+0.6 in bar\n",
      "air velocity,ao=sqrt(y*R*To)in m/s\n",
      "density of air,rho_o=Po/(R*To)in \n",
      "considering air to be in-compressible,\n",
      "Po=P+rho_o*C^2/2\n",
      "so C in m/s= 235.13\n",
      "for compressible fluid,Po/P=(1+(y-1)*M^2/2)^(y/(y-1))\n",
      "so M=sqrt((exp(log(Po/P)/(y/(y-1)))-1)/((y-1)/2))\n",
      "compressibility correction factor,k\n",
      "k=(M^2/4)+((2-y)/24)*M^4\n",
      "stagnation temperature,To/T=1+((y-1)/2)*M^2\n",
      "so T=To/(1+((y-1)/2)*M^2) in K\n",
      "density,rho=P/(R*T) in kg/m^3\n",
      "substituting Po-P=(1/2)*rho*C^2(1+k)\n",
      "C in m/s= 250.94\n",
      "so C=250.95 m/s\n"
     ]
    }
   ],
   "source": [
    "#cal of air stream velocity\n",
    "#intiation of all variables\n",
    "# Chapter 13\n",
    "import math\n",
    "print\"Example 13.5, Page:527  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 13 Example 5\")\n",
    "To=305.;#stagnation temperature of air stream in K\n",
    "y=1.4;#expansion constant\n",
    "R=287.;#gas constant in J/kg K\n",
    "print(\"actual static pressure(P)=1+0.3 in bar\")\n",
    "P=1.+0.3\n",
    "print(\"It is also given that,Po-P=0.6,\")\n",
    "print(\"so Po=P+0.6 in bar\")\n",
    "Po=P+0.6\n",
    "print(\"air velocity,ao=sqrt(y*R*To)in m/s\")\n",
    "ao=math.sqrt(y*R*To)\n",
    "print(\"density of air,rho_o=Po/(R*To)in \")\n",
    "rho_o=Po*10.**5/(R*To)\n",
    "print(\"considering air to be in-compressible,\")\n",
    "print(\"Po=P+rho_o*C^2/2\")\n",
    "C=math.sqrt((Po-P)*10.**5*2./rho_o)\n",
    "print(\"so C in m/s=\"),round(C,2)\n",
    "print(\"for compressible fluid,Po/P=(1+(y-1)*M^2/2)^(y/(y-1))\")\n",
    "print(\"so M=sqrt((exp(log(Po/P)/(y/(y-1)))-1)/((y-1)/2))\")\n",
    "M=math.sqrt((math.exp(math.log(Po/P)/(y/(y-1)))-1)/((y-1)/2))\n",
    "M=0.7567;#approx.\n",
    "print(\"compressibility correction factor,k\")\n",
    "print(\"k=(M^2/4)+((2-y)/24)*M^4\")\n",
    "k=(M**2/4.)+((2.-y)/24.)*M**4\n",
    "print(\"stagnation temperature,To/T=1+((y-1)/2)*M^2\")\n",
    "print(\"so T=To/(1+((y-1)/2)*M^2) in K\")\n",
    "T=To/(1+((y-1)/2)*M**2)\n",
    "print(\"density,rho=P/(R*T) in kg/m^3\")\n",
    "rho=P*10**5/(R*T)\n",
    "print(\"substituting Po-P=(1/2)*rho*C^2(1+k)\")\n",
    "C=math.sqrt((Po-P)*10.**5/((1./2.)*rho*(1.+k)))\n",
    "print(\"C in m/s=\"),round(C,2)\n",
    "print(\"so C=250.95 m/s\")"
   ]
  }
 ],
 "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.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}