{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 5: Airfoils, Wings and Other Aerodynamic shapes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Required height of car:  37.1 m\n"
     ]
    }
   ],
   "source": [
    "# -*- coding: utf8 -*-\n",
    "from __future__ import division\n",
    "#Example: 5.1\n",
    "''' A car of mass 1100 kg drives with a velocity such that it has a kinetic energy of 400 kJ (see\n",
    "Fig. 5.4). Find the velocity. If the car is raised with a crane, how high should it be lifted in\n",
    "the standard gravitational field to have a potential energy that equals the kinetic energy? '''\n",
    "\n",
    "#Variable Declaration: \n",
    "m = 1100 \t\t#Mass of car in kg\n",
    "ke = 400 \t\t#Kinetic energy of car in kJ\n",
    "g = 9.807 \t\t#Acc. due to gravity in m/s**2\n",
    "\n",
    "#Calculations:\n",
    "V = (2*ke*1000/m)**0.5 #Velocity of car in m/s\n",
    "H = ke*1000/(m*g) \t#Height to which the car should be lifted so that its potential energy equals its kinetic energy\n",
    "\n",
    "#Results:\n",
    "print \"Required height of car: \", round(H,1),\"m\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5.2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Change in internal energy is:  3590.0 KJ\n"
     ]
    }
   ],
   "source": [
    "# -*- coding: utf8 -*-\n",
    "from __future__ import division\n",
    "#Example: 5.2\n",
    "'''A tank containing a fluid is stirred by a paddle wheel. The work input to the paddle wheel\n",
    "is 5090 kJ. The heat transfer from the tank is 1500 kJ. Consider the tank and the fluid\n",
    "inside a control surface and determine the change in internal energy of this control mass.  '''\n",
    "\n",
    "#Variable Declaration: \n",
    "W = -5090 \t\t#Work input to paddle wheel in kJ\n",
    "Q = -1500 \t\t#Heat transfer from tank in kJ\n",
    "\n",
    "#Calculations:\n",
    "dU = Q-W \t\t#Change in internal energy in kJ\n",
    "\n",
    "#Results:\n",
    "print \"Change in internal energy is: \",round(dU),\"KJ\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "When stone is about to enter state 2, dKE:  1.0 KJ and dPE : -1.0 KJ\n",
      "When stone has just come to rest in the bucket i.e. state 3, W = 0, dPE = 0, dKE1: -1.0 J and dU : 1.0 J\n",
      "When stone has entered state 4, dPE = 0, W3 = 0,dKE = 0, dU:  -1.0 J Q3:  -1.0 J\n"
     ]
    }
   ],
   "source": [
    "# -*- coding: utf8 -*-\n",
    "from __future__ import division\n",
    "#Example: 5.3\n",
    "''' Consider a stone having a mass of 10 kg and a bucket containing 100 kg of liquid water.\n",
    "Initially the stone is 10.2 m above the water, and the stone and the water are at the same\n",
    "temperature, state 1. The stone then falls into the water.\n",
    "Determine \u0003U, \u0003KE, \u0003PE, Q, and W for the following changes of state, assuming\n",
    "standard gravitational acceleration of 9.806 65 m/s2.\n",
    "a. The stone is about to enter the water, state 2.\n",
    "b. The stone has just come to rest in the bucket, state 3.\n",
    "c. Heat has been transferred to the surroundings in such an amount that the stone and\n",
    "water are at the same temperature, T1, state 4. '''\n",
    "\n",
    "#Variable Declaration: \n",
    "g = 9.806 \t\t#Acceleration due to gravity in m/s**2\n",
    "m = 10 \t\t#Mass of stone in kg\n",
    "H1 = 10.2 \t\t#Initial height of stone above water in metres\n",
    "H2 = 0 \t\t#Final height in metres\n",
    "\n",
    "#Calculations:\n",
    "dKE1 = -m*g*(H2-H1) #Change in kinetic energy when stone enters state 2 in J\n",
    "dPE1 = -1 \t\t#Change in potential energy when stone enters state 2 in J\n",
    "dPE2 = 0 \t\t#Change in potential energy when stone enters state 3 in JQ2 = 0 \t\t#no heat transfer when stone enters state 3 in J\n",
    "W2 = 0 \t\t#no work done when stone enters state 3 in J\n",
    "dKE2 = -1 \t\t#Change in kinetic energy when stone enters state 3\n",
    "dU2 = -dKE2 \t#Change in internal energy when stone enters state 3 in J\n",
    "dKE3 = 0 \t\t#Change in kinetic energy when stone enters state 4\n",
    "dPE = 0 \t\t#Change in potential energy when stone enters state 4 in J\n",
    "W3 = 0 \t\t#No work done when stone enters state 4 in J\n",
    "dU3 = -1 \t\t#Change in internal energy when stone enters state 4 in J\n",
    "Q3 = dU3 \t\t#Heat transfer when stone enters state 4 in J\n",
    "\n",
    "#Results:\n",
    "print \"When stone is about to enter state 2, dKE: \",round(dKE1/1000,2),\"KJ and dPE :\",round(dPE1,2),\"KJ\"\n",
    "print \"When stone has just come to rest in the bucket i.e. state 3, W = 0, dPE = 0, dKE1:\",round(dKE2,2),\"J and dU :\",round(dU2,2),\"J\"\n",
    "print \"When stone has entered state 4, dPE = 0, W3 = 0,dKE = 0, dU: \",round(dU3,2),\"J Q3: \",round(Q3,2),\"J\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Specific volume for water is:  0.06474 m**3/Kg\n",
      "Therefore ,this state is in the two phase region with quality:  0.6456\n"
     ]
    }
   ],
   "source": [
    "# -*- coding: utf8 -*-\n",
    "from __future__ import division\n",
    "#Example: 5.4\n",
    "'''Determine the missing property (P, T, or x) and v forwater at each of the following states:\n",
    "a. T = 300◦C, u = 2780 kJ/kg\n",
    "b. P = 2000 kPa, u = 2000 kJ/kg'''\n",
    "\n",
    "#Variable Declaration: \n",
    "T1 = 300 \t\t#Given temp. in Celsius\n",
    "u1 = 2780 \t\t#Given specific internal enrgy in kJ/kg\n",
    "P2 = 2000 \t\t#Given pressure in kPa\n",
    "u2 = 2000 \t\t#Given specific intrernal energy in kJ/kg\n",
    "uf = 906.4 \t\t#in kJ/kg\n",
    "ug = 2600.3 \t#in kJ/kg \n",
    "vf = 0.001177 \t#in m**3/kg \n",
    "vg = 0.099627 \t#in m**3/kg\n",
    "\n",
    "#Calculation:\n",
    "x2 = (u2-906.4)/(ug-uf) \n",
    "v2 = vf+x2*(vg-vf)#Specific volume for water in m**3/kg\n",
    "\n",
    "#Result:\n",
    "print \"Specific volume for water is: \",round(v2,5),\"m**3/Kg\"\n",
    "print \"Therefore ,this state is in the two phase region with quality: \",round(x2,4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "By interplotation we find that for steam, if vg = 0.09831 m**3/kg then pressure is 2.03 MPa\n",
      "Heat transfer for the process is:  104932.6 KJ\n"
     ]
    }
   ],
   "source": [
    "# -*- coding: utf8 -*-\n",
    "from __future__ import division\n",
    "#Example: 5.5\n",
    "'''A vessel having a volume of 5 m3 contains 0.05 m3 of saturated liquid water and 4.95 m3\n",
    "of saturated water vapor at 0.1 MPa. Heat is transferred until the vessel is filled with\n",
    "saturated vapor. Determine the heat transfer for this process.'''\n",
    "\n",
    "#Variable Declaration: \n",
    "Vliq = 0.05 \t\t#Volume of saturated liquid in m**3\n",
    "vf = 0.001043 \t\t#in m**3/kg\n",
    "Vvap = 4.95 \t\t#Volume of saturated water vapour in m**3\n",
    "vg = 1.6940 \t\t#in m**3/kg\n",
    "u1liq = 417.36 \t\t#Specific internal energy of liquid in kJ/kg\n",
    "u1vap = 2506.1 \t\t#Specific internal energy of vapors in kJ/kg\n",
    "V = 5 \t\t      #Total volume in m**3\n",
    "u2 = 2600.5 \t\t#Specific internal energy at final state in kJ/kg\n",
    "\n",
    "#Calculation:\n",
    "m1liq = Vliq/vf \t\t#Mass of liquid in kg\n",
    "m1vap = Vvap/vg \t\t#Mass of vapors in kg\n",
    "U1 = m1liq*u1liq+m1vap*u1vap #Total internal energy in kJ\n",
    "m = m1liq+m1vap \t\t#Total mass in kg\n",
    "v2 = V/m \t\t      #Final specific volume in m**3/kg\n",
    "U2 = m*u2 \t\t      #Internal energy at final state in kJ\n",
    "Q = U2-U1 \t\t      #Heat transfer for the process in kJ\n",
    "\n",
    "print 'By interplotation we find that for steam, if vg = 0.09831 m**3/kg then pressure is 2.03 MPa'\n",
    "print \"Heat transfer for the process is: \",round(Q,2),\"KJ\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5.6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Work done for the process:  91.0 KJ\n",
      "Heat transfer:  771.1 KJ\n"
     ]
    }
   ],
   "source": [
    "# -*- coding: utf8 -*-\n",
    "from __future__ import division\n",
    "#Example: 5.6\n",
    "'''A cylinder fitted with a piston has a volume of 0.1 m3 and contains 0.5 kg of steam at 0.4\n",
    "MPa. Heat is transferred to the steam until the temperature is 300◦C, while the pressure\n",
    "remains constant.'''\n",
    "\n",
    "#Variable Declaration: \n",
    "V1 = 0.1 \t\t      #Volume of cylinder in m**3\n",
    "m = 0.5 \t\t      #Mass of steam in kg\n",
    "vf = 0.001084 \t\t#m**3/kg\n",
    "vfg = 0.4614 \t\t#m**3/kg\n",
    "hf = 604.74 \t\t#kJ/kg\n",
    "hfg = 2133.8\t\t#kJ/kg\n",
    "h2 = 3066.8 \t\t#Final specific heat enthalpy in kJ/kg\n",
    "P = 400 \t\t      #Pressure inside cylinder in kPa\n",
    "v2 = 0.6548 \t\t#Specific enthalpy in m**3/kg\n",
    "\n",
    "#Calculation:\n",
    "v1 = V1/m \t\t      #Specific volume of steam in m**3/kg\n",
    "x1 = (v1-vf)/vfg \t\t#Quality\n",
    "h1 = hf+x1*hfg \t\t#Initial specific enthalpy in kJ/kg\n",
    "Q = m*(h2-h1) \t\t#Heat transfer for this process in kJ\n",
    "W = m*P*(v2-v1) \t\t#Work done for the process in kJ\n",
    "\n",
    "#Result:\n",
    "print \"Work done for the process: \",round(W), \"KJ\"\n",
    "print \"Heat transfer: \",round(Q,1), \"KJ\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5.8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Change in specific heat enthalpy if ideal gas tables are used is:  1267.0 KJ/Kg\n",
      "If empirical equations are used:  1241.64 KJ/Kg\n",
      "If specific heat is assumed to be constant and using its value at T1:  1106.4 KJ/Kg\n",
      "If specific heat is assumed to be constant at its value at (T1+T2)/2:  1292.0 KJ/Kg\n"
     ]
    }
   ],
   "source": [
    "# -*- coding: utf8 -*-\n",
    "from __future__ import division\n",
    "#Example: 5.8\n",
    "'''Calculate the change of enthalpy as 1 kg of oxygen is heated from 300 to 1500 K. Assume\n",
    "ideal-gas behavior.'''\n",
    "from sympy import symbols,integrate\n",
    "\n",
    "#Variable Declaration: \n",
    "h1 = 273.2 \t\t#Specific heat enthalpy for oxygen at 300 K\n",
    "h2 = 1540.2 \t#Specific heat enthalpy for oxygen at 1500 K\n",
    "T1 = 300 \t\t#Initial temperature in K\n",
    "T2 = 1500 \t\t#Final temparature in K\n",
    "x = symbols('x')\n",
    "\n",
    "#Calculation:\n",
    "Cp = 0.88-0.00001*x+0.54*x**2-0.33*x**3 #Expression for constant pressure specific heat enthalpy for oxygen\n",
    "dh1 = h2-h1 \t#This change in specific heat enthalpy is calculated using ideal gas tables \n",
    "dh2 = 1000*integrate(Cp,(x,T1/1000,T2/1000)) #Using empirical equation\n",
    "dh3 = 0.922*(T2-T1) #It is claculated if we assume specific heat enthalpy to be constant and uses its value at 300K\n",
    "dh4 = 1.0767*(T2-T1)#It is claculated if we assume specific heat enthalpy to be constant and uses its value at 900K i.e mean of initial and final temperature\n",
    "\n",
    "#Result:\n",
    "print \"Change in specific heat enthalpy if ideal gas tables are used is: \",round( dh1,2),\"KJ/Kg\"\n",
    "print \"If empirical equations are used: \",round( dh2,2),\"KJ/Kg\"\n",
    "print \"If specific heat is assumed to be constant and using its value at T1: \",round(dh3,2),\"KJ/Kg\"\n",
    "print \"If specific heat is assumed to be constant at its value at (T1+T2)/2: \",round(dh4),\"KJ/Kg\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5.9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Heat transfer for the above process is:  -4.21 KJ\n"
     ]
    }
   ],
   "source": [
    "# -*- coding: utf8 -*-\n",
    "from __future__ import division\n",
    "#Example: 5.9\n",
    "'''A cylinder fitted with a piston has an initial volume of 0.1 m3 and contains nitrogen at 150\n",
    "kPa, 25◦C. The piston is moved, compressing the nitrogen until the pressure is 1 MPa and\n",
    "the temperature is 150◦C. During this compression process heat is transferred from the\n",
    "nitrogen, and the work done on the nitrogen is 20 kJ. Determine the amount of this heat\n",
    "transfer.'''\n",
    "\n",
    "#Variable Declaration: \n",
    "P = 150 \t\t#Pressure of nitrogen in cylinder in kPa\n",
    "V = 0.1 \t\t#Initial volume of cylinder in m**3\n",
    "T1 = 25 \t\t#Initial temperature of nitrogen in celsius\n",
    "T2 = 150 \t\t#Final tempareture of nitrogen in celsius\n",
    "R = 0.2968 \t\t#In kJ/kg-K\n",
    "Cv = 0.745 \t\t#Constant volume specific heat for nitrogen in kJ/kg-K\n",
    "W = -20 \t\t#Work done on nitrogen gas in kJ\n",
    "\n",
    "#Calculation:\n",
    "m = P*V/(R*(T1+273))#Mass of nitrogen in kg\n",
    "Q = m*Cv*(T2-T1)+W #Heat transfer during the process in kJ\n",
    "\n",
    "#Result:\n",
    "print \"Heat transfer for the above process is: \",round( Q,2),\"KJ\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5.10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Rate of increase of internal energy is:  246.0 J/s\n"
     ]
    }
   ],
   "source": [
    "# -*- coding: utf8 -*-\n",
    "from __future__ import division\n",
    "#Example: 5.10\n",
    "'''During the charging of a storage battery, the current i is 20 A and the voltage e is 12.8\n",
    "V. The rate of heat transfer from the battery is 10 W. At what rate is the internal energy\n",
    "increasing?'''\n",
    "\n",
    "#Variable Declaration: \n",
    "W = -12.8*20 \t#Power consumed in  J/s\n",
    "Q = -10 \t\t#Heat transfer rate from battery in J/s\n",
    "\n",
    "#Calculation:\n",
    "r = Q-W \t\t#Rate of increase of internal energy\n",
    "\n",
    "#Result:\n",
    "print \"Rate of increase of internal energy is: \",round( r,2),\"J/s\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5.11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Rate of change of temperature is:  0.0828 K/s\n",
      "Time taken to reach a temperature of T:  11.0 min\n"
     ]
    }
   ],
   "source": [
    "# -*- coding: utf8 -*-\n",
    "from __future__ import division\n",
    "#Example: 5.11\n",
    "'''A 25-kg cast-iron wood-burning stove, shown in Fig. 5.12, contains 5 kg of soft pine wood\n",
    "and 1 kg of air. All the masses are at room temperature, 20◦C, and pressure, 101 kPa. The\n",
    "wood now burns and heats all the mass uniformly, releasing 1500W. Neglect any air flow\n",
    "and changes in mass of wood and heat losses. Find the rate of change of the temperature\n",
    "(dT/dt) and estimate the time it will take to reach a temperature of 75◦C.'''\n",
    "\n",
    "#Variable Declaration: \n",
    "Q = 1500 \t\t#Power produced by burning wood in J/s\n",
    "mair = 1 \t\t#Mass of air in kg\n",
    "mwood = 5 \t\t#Mass of soft pine wood in kg \n",
    "miron = 25 \t\t#Mass of cast iron in kg\n",
    "Cvair = 0.717 \t#Constant volume specific heat for air in kJ/kg\n",
    "Cwood = 1.38 \t#Constant volume specific heat for wood in kJ/kg\n",
    "Ciron = 0.42 \t#Constant volume specific heat for iron in kJ/kg\n",
    "\n",
    "#Calculations:\n",
    "dT = 75-20 \t\t#Increase in temperature in Celsius\n",
    "T = (Q/1000)/(mair*Cvair+mwood*Cwood+miron*Ciron) \t#Rate of change of temperature in K/s\n",
    "dt = (dT/T)/60 \t#in minutes\n",
    "\n",
    "#Results:\n",
    "print \"Rate of change of temperature is: \",round(T,4),\"K/s\"\n",
    "print \"Time taken to reach a temperature of T: \",round(dt),\"min\""
   ]
  }
 ],
 "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
}
