{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 5 Principles of Convection"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 5.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the increase in static pressure between sections 1 and 2 is: 61.88  kPa\n"
     ]
    }
   ],
   "source": [
    "#Example 5.1\n",
    "# water flow in a diffuser  \n",
    "\n",
    "#VARIABLE DECLARATION\n",
    "Tw = 20 \t\t\t# [degree celcius] water temperature \n",
    "m_dot = 8 \t\t\t# [kg/s] water flow rate \n",
    "d1 = 0.03 \t\t\t#[m] diameter at section 1\n",
    "d2 = 0.07 \t\t\t# [m] diameter at section 2\n",
    "\n",
    "#CALCULATION\n",
    "import math\n",
    "A1 = math.pi*d1**(2)/4 \t\t# [square meter] cross-sectional area at section 1\n",
    "A2 = math.pi*d2**(2)/4 \t\t# [square meter] cross-sectional area at section  2\n",
    "gc = 1 \t\t\t\t# [m/s**(2)] acceleration due to gravity\n",
    "rho = 1000 \t\t\t# [kg/cubic m] density of water at 20 degree celcius\n",
    "\n",
    "\t# calculate the velocities from the mass-continuity relation\n",
    "u1 = m_dot/(rho*A1) \t\t# [m/s]\n",
    "u2 = m_dot/(rho*A2) \t\t# [m/s]\n",
    "\t# the pressure difference is obtained by Bernoulli equation(5-7a)\n",
    "p2_minus_p1 = rho*(u1**(2)-u2**(2))/(2*gc)\t # [Pa] \n",
    "\n",
    "#RESULTS\n",
    "print\"the increase in static pressure between sections 1 and 2 is:\",round(p2_minus_p1/1000,2),\" kPa\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 5.2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The static temperature is: 529.0 K\n",
      "Static pressure is: 0.5 MPa\n",
      "Mach number is: 0.651\n"
     ]
    }
   ],
   "source": [
    "#Example Number 5.2\n",
    "# isentropic expansion of air \n",
    "\n",
    "# Variable declaration\n",
    "\n",
    "Ta = 300.0+273.0\t \t\t# [K] air temperature\n",
    "Pa = 0.7 \t\t\t\t# [MPa] pressure of air\n",
    "u2 = 300 \t\t\t\t# [m/s] final velocity\n",
    "gc = 1 \t\t\t\t\t# [m/s^(2)] acceleration due to gravity\n",
    "Y = 1.4 \t\t\t\t# gama value for air \n",
    "Cp = 1005 \t\t\t\t# [J/kg degree celsius]\n",
    "\t#the initial velocity is small and the process is adiabatic. in terms of \t\ttemperature \n",
    "\n",
    "\n",
    "#Calculation\n",
    "\n",
    "T2 = Ta-u2**(2)/(2*gc*Cp) \n",
    "\n",
    "#Result\n",
    "print \"The static temperature is:\",round(T2,1),\"K\" \n",
    "\n",
    "\t# we may calculate the pressure difference from the isentropic relation \n",
    "\n",
    "p2 = Pa*((T2/Ta)**(Y/(Y-1))) \n",
    "\n",
    "print \"Static pressure is:\",round(p2,1),\"MPa\"\n",
    "\n",
    "\t# the velocity of sound at condition 2 is \n",
    "a2 = (20.045*(T2**(0.5))) \t\t# [m/s] \n",
    "\t#so that the mach no. is \n",
    "M2 = u2/a2 \n",
    "print \"Mach number is:\",round(M2,3) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 5.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The heat transfered in first case of the plate is 81.2 W\n",
      "and the heat transfered in second case of the plate is: 114.8 W\n"
     ]
    }
   ],
   "source": [
    "#Example Number 5.4\n",
    "#Calculate the heat transfereed in first 20 cm of the plate and the first 40 cm of the  plate\n",
    "\n",
    "# Variable declaration\n",
    "\n",
    "\t# total heat transfer over a certain length of the plate is desired, so we \t\twish to calculate average heat transfer coefficients. \n",
    "\t# for this purpose we use equations (5-44) and (5-45), evaluating the \t\tproperties at the film temperature :\n",
    "Tp = 60+273.15 \t\t\t\t# [K] plate temperature \n",
    "Ta = 27+273.15 \t\t\t\t# [K] air temperature\n",
    "Tf = (Tp+Ta)/2 \t\t\t\t# [K]\n",
    "u = 2 \t\t\t\t\t# [m/s] air velocity\n",
    "\n",
    "\t# from appendix A the properties are \n",
    "\n",
    "v = 17.36*(10**(-6)) \t\t\t# [square meter/s] kinematic viscosity\n",
    "x1 = 0.2 \t\t\t\t# [m] distance from the leading edge of plate\n",
    "x2 = 0.4 \t\t\t\t# [m] distance from the leading edge of plate\n",
    "k = 0.02749 \t\t\t\t# [W/m K] heat transfer coefficient\n",
    "Pr = 0.7 \t\t\t\t# prandtl number\n",
    "Cp = 1006 \t\t\t\t# [J/kg K]\n",
    "\n",
    "\t# at x = 0.2m\n",
    "\n",
    "#Calculation\n",
    "\n",
    "Re_x1 =(u*x1/v) \t\t\t\t# reynolds number\n",
    "Nu_x1 = 0.332*(Re_x1**(0.5))*(Pr**(0.333)) \t# nusselt number\n",
    "hx1 = Nu_x1*k/x1 \t\t\t\t# [W/square meter K] \n",
    "\n",
    "\t# the average value of the heat transfer coefficient is twice this value, or\n",
    "\n",
    "h_bar1 = 2*hx1 \t\t\t\t\t# [W/square meter K] \n",
    "\n",
    "\t# the heat flow is \n",
    "\n",
    "A1 = x1*1 \t\t\t\t\t# [square meter] area for unit depth\n",
    "q1 = h_bar1*A1*(Tp-Ta) \t\t\t\t# [W]\n",
    "\n",
    "\t# at x = 0.4m\n",
    "\n",
    "Re_x2 = u*x2/v \t\t\t\t\t# reynolds number\n",
    "Nu_x2 = 0.332*Re_x2**(0.5)*Pr**(0.333) \t\t# nusselt number\n",
    "hx2 = Nu_x2*k/x2 \t\t\t\t# [W/square meter K] \n",
    "\n",
    "\t# the average value of the heat transfer coefficient is twice this value, or\n",
    "\n",
    "h_bar2 = 2*hx2 \t\t\t\t\t# [W/square meter K] \n",
    "\t# the heat flow is \n",
    "A2 = x2*1 \t\t\t\t\t# [square meter] area for unit depth\n",
    "q2 = h_bar2*A2*(Tp-Ta) \t\t\t\t# [W] \n",
    "\n",
    "#Result\n",
    " \n",
    "print\"The heat transfered in first case of the plate is\",round(q1,2),\"W\"\n",
    "print\"and the heat transfered in second case of the plate is:\",round(q2,1),\"W\" "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 5.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average temperature difference along the plate is: 241.0  degree celsius\n",
      "Temperature difference at the trailing edge is: 365.3 degree celsius\n"
     ]
    }
   ],
   "source": [
    "#Example Number 5.5\n",
    "# Calculate the av temperature difference along the plate & Temperature diff at the trailing edge\n",
    "\n",
    "#Variable declaration\n",
    "\n",
    "u = 5 \t\t\t\t\t# [m/s] air velocity\n",
    "l = 0.6 \t\t\t\t# [m] plate length\n",
    "Ta = 27+273.15 \t\t\t\t# [K] temperature of airstream\n",
    "\n",
    "\t# properties should be evaluated at the film temperature, but we do not know \tthe plate temperature so for an initial calculation we take the properties at \tthe free-stream conditions of\n",
    "\n",
    "v = 15.69*10**(-6)\t \t\t#[square meter/s] kinematic viscosity\n",
    "k = 0.02624 \t\t\t\t#[W/m deg celsius] heat transfer coefficient\n",
    "Pr = 0.7 \t\t\t\t# prandtl number\n",
    "Re_l = l*u/v \t\t\t\t# reynolds number\n",
    "P = 1000 \t\t\t\t# [W] power of heater\n",
    "qw = P/l**(2) \t\t\t\t# [W/square meter] heat flux per unit area \n",
    "\n",
    "\t# from equation (5-50) the average temperature difference is \n",
    "\n",
    "#Calculation\n",
    "\n",
    "Tw_minus_Tinf_bar = qw*l/(0.6795*k*(Re_l)**(.5)*(Pr)**(0.333)) \t # [degree celsius]\n",
    "\n",
    "\t# now, we go back and evaluate properties at \n",
    "Tf = (Tw_minus_Tinf_bar+Ta+Ta)/2 \t# [degree celsius]\n",
    "\n",
    "\t# and obtain\n",
    "\n",
    "v1 = 28.22*10**(-6) \t\t\t# [square meter/s] kinematic viscosity\n",
    "k1 = 0.035 \t\t\t\t# [W/m deg celsius] heat transfer coefficient\n",
    "Pr1 = 0.687 \t\t\t\t# prandtl number\n",
    "Re_l1 = l*u/v1 \t\t\t\t# reynolds number\n",
    "Tw_minus_Tinf_bar1 = qw*l/(0.6795*k1*(Re_l1)**(0.5)*(Pr1)**(0.333)) #[degree celsius]\n",
    "\n",
    "\t# at the end of the plate(x = l = 0.6m) the temperature difference is obtained \tfrom equation (5-48) and (5-50) with the constant of 0.453\n",
    "\n",
    "Tw_minus_Tinf_x_equal_l = Tw_minus_Tinf_bar1*0.6795/0.453 \t# [degree celsius]\n",
    "\n",
    "#Result\n",
    "\n",
    "print \"Average temperature difference along the plate is:\",round(Tw_minus_Tinf_bar),\" degree celsius\"\n",
    "print \"Temperature difference at the trailing edge is:\",round(Tw_minus_Tinf_x_equal_l,1),\"degree celsius\" "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 5.7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average value of the convection coefficient is 219.1 W/sq meter degree celsius\n",
      " and the heat lost by the plate is 350.6 W\n"
     ]
    }
   ],
   "source": [
    "#Example Number 5.7\n",
    "# Calculate the heat lost by the plate\n",
    "\n",
    "# Variable declaration\n",
    "\n",
    "u = 1.2 \t\t\t# [m/s] oil velocity\n",
    "l = 0.2 \t\t\t# [m] plate length as well as width (square) \n",
    "To = 20+273.15 \t\t\t# [K] temperature of engine oil\n",
    "Tu = 60+273.15 \t\t\t# [K] uniform temperature of plate   \n",
    "\t# First we evaluate the film temperature \n",
    "T = (To+Tu)/2 \t\t\t# [K]\n",
    "\t# and obtain the properties of engine oil are \n",
    "rho = 876 \t\t\t# [kg/cubic meter] density of oil\n",
    "v = 0.00024 \t\t\t# [square meter/s] kinematic viscosity\n",
    "k = 0.144 \t\t\t# [W/m degree celsius] heat transfer coefficient\n",
    "Pr = 2870 \t\t\t# prandtl number\n",
    "\t# at the trailing edge of the plate the reynolds number is \n",
    "\n",
    "#Calculation\n",
    "\n",
    "Re = l*u/v \t\t\t# reynolds number\n",
    "\n",
    "\n",
    "\n",
    "\t# because the prandtl no. is so large we will employ equation(5-51) for the \t\tsolution. \n",
    "\n",
    "\t# we see that hx varies with x in the same fashion as in equation(5-44) , i.e. \thx is inversely proportional to the square root of x ,\n",
    "\t# so that we get the same solution as in equation(5-45) for the average heat \t\ttransfer coefficient. \n",
    "\n",
    "\t# evaluating equation(5-51) at x = 0.2m gives\n",
    "\n",
    "Nux = (0.3387*(Re**(1.0/2.0))*(Pr**(1.0/3.0)))/((1+(0.0468/Pr)**(2.0/3.0))**(1.0/4.0))\n",
    "\n",
    "\n",
    "hx = Nux*k/l \t\t\t# [W/sq m degree celsius]  heat transfer coefficient\n",
    "\n",
    "\t# the average value of the convection coefficient is \n",
    "\n",
    "h = 2*hx \t\t\t# [W/square meter degree celsius]  \n",
    "\n",
    "\t# so that total heat transfer is \n",
    "\n",
    "A = l**(2) \t\t\t# [square meter] area of the plate \n",
    "q = h*A*(Tu-To) \t\t#[W] \n",
    "\n",
    "print \"Average value of the convection coefficient is\",round(h,1),\"W/sq meter degree celsius\"\n",
    "print \" and the heat lost by the plate is\",round(q,1),\"W\" "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 5.8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Drag force exerted on the first 0.4 m of the plate is 5.45 mN\n"
     ]
    }
   ],
   "source": [
    "#Example Number 5.8\n",
    "# Compute the drag force on the first 40 cm of the plate  \n",
    "\n",
    "# Variable declaration\n",
    "\n",
    "\n",
    "\t# data is used from example 5.4 \n",
    "\t# we use equation (5-56) to compute the friction coefficient and then \t\tcalculate the drag force .\n",
    "\t# an average friction coefficient is desired, so st_bar*pr**(2/3) = Cf_bar/2\n",
    "\n",
    "p = 101325 \t\t\t# [Pa] pressure of air\n",
    "x = 0.4\t\t\t\t#[m] drag force is computed on first 0.4 m of the \t\t\t                  plate \n",
    "R = 287 \t\t\t# []\n",
    "Tf = 316.5 \t\t\t# [K]\n",
    "u = 2 \t\t\t\t# [m/s] air velocity\n",
    "Cp = 1006 \t\t\t# [J/kg K]\n",
    "Pr = 0.7 \t\t\t# prandtl no.\n",
    "rho = p/(R*Tf) \t\t\t# [kg/cubic meter] density at 316.5 K \n",
    "h_bar = 8.698 \t\t\t# [W/square meter K]  heat transfer coefficient\n",
    "\n",
    "\n",
    "#Calculation\n",
    "\t# for the 0.4m length\n",
    "\n",
    "st_bar = h_bar/(rho*Cp*u) \n",
    "\n",
    "\t# then from equation (5-56)\n",
    "\n",
    "Cf_bar = st_bar*Pr**(2.0/3.0)*2 \n",
    "\n",
    "\t# the average shear stress at the wall is computed from equation(5-52)\n",
    "\n",
    "tau_w_bar = Cf_bar*rho*u**(2)/2 \t# [N/square meter]\n",
    "A = x*1 \t\t\t\t# [square meter] area per unit length \n",
    "\n",
    "\t# the drag force is the product of this shear stress and the area,\n",
    "\n",
    "D = tau_w_bar*A \t\t\t# [N] \n",
    "\n",
    "#Result\n",
    "\n",
    "print \"Drag force exerted on the first 0.4 m of the plate is\",round(D*1000,2),\"mN\" \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 5.9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nul_bar is 2175.0\n",
      "Heat transfer from plate is 2369.0 W\n"
     ]
    }
   ],
   "source": [
    "#Example Number 5.9\n",
    "# Calculate the heat transfer from the plate\n",
    "\n",
    "# Variable declaration\n",
    "\n",
    "p = 101320.0 \t\t\t\t# [Pa] pressure of air\n",
    "R = 287.0 \t\t\t\t# []\n",
    "Ta = 20+273 \t\t\t\t# [K] temperature of air \n",
    "u = 35 \t\t\t\t\t# [m/s] air velocity\n",
    "L = 0.75 \t\t\t\t# [m] length of plate \n",
    "Tp = 60+273 \t\t\t\t# [K] plate temperature \n",
    "\n",
    "\n",
    "\t\t# we evaluate properties at the film temperature \n",
    "\n",
    "#Calculations\n",
    "\n",
    "Tf = (Ta+Tp)/2 \t\t\t\t# [K]\n",
    "\n",
    "\n",
    "rho = (p/(R*Tf)) \t\t\t# [kg/cubic meter]\n",
    "\n",
    "\n",
    "mu = 1.906*(10**(-5)) \t\t\t# [kg/m s] viscosity  \n",
    "k = 0.02723 \t\t\t\t# [W/m degree celsius]\n",
    "Cp = 1007 \t\t\t\t# [J/kg K]\n",
    "Pr = 0.7 \t\t\t\t# prandtl no.\n",
    "\n",
    "\t\t# the reynolds number is \n",
    "\n",
    "Rel = (rho*u*L)/mu \n",
    "Rel=round(Rel)\n",
    "\n",
    "\t\t# and the boundary layer is turbulent because the reynolds number is \t\t\tgreater than 5*10**(5).\n",
    "\t\t# therefore, we use equation(5-85) to calculate the average heat \t\t\ttransfer over the plate:\n",
    "\n",
    "Nul_bar = (Pr**(1.0/3.0))*(0.037*(Rel**(0.8))-871) \n",
    "\n",
    "print \"Nul_bar is\",round(Nul_bar)\n",
    "A = L*1 \t\t\t\t# [square meter] area of plate per unit depth\n",
    "h_bar = Nul_bar*k/L  \t\t\t# [W/square meter degree celsius]\n",
    "q = h_bar*A*(Tp-Ta) \t\t\t# [W] heat transfer from plate\n",
    "\n",
    "#Result\n",
    "\n",
    "print \"Heat transfer from plate is\",round(q),\"W\" "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exa 5.10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Turbulent-boundary-layer thickness at the end of the plate from the leading edge of the plate is 16.5 mm\n",
      "Turbulent-boundary-layer thickness at the end of the plate from the transition point at Re_crit = 5*10**(5) is 9.9  mm\n"
     ]
    }
   ],
   "source": [
    "#Example Number 5.10\n",
    "# Calculate turbulent-boundary-layer thickness at the end of plate   \n",
    "\n",
    "# Variable declaration\n",
    "\n",
    "\t\t# we have to use the data from example 5.8 and 5.9\n",
    "Rel = 1.553*10**6 \t\t\t\t\t# from previous example\n",
    "L = 0.75 \t\t\t\t\t\t# [m] length of plate\n",
    "\t\t# it is a simple matter to insert this value in equations(5-91) and \t\t(5-95) \talong with\n",
    "x = L \t\t\t\t\t\t\t# [m]\n",
    "\t\t# turbulent-boundary-layer thickness are\n",
    "\t\t# part a.  from the leading edge of the plate \n",
    "\n",
    "#Calculation\n",
    "\n",
    "del_a = x*0.381*Rel**(-0.2) \t\t\t\t# [m] \n",
    "\t\t# part b   from the transition point at Recrit = 5*10**(5)\n",
    "\n",
    "del_b = x*0.381*Rel**(-0.2)-10256*Rel**(-1) \t\t# [m]\n",
    "\n",
    "#Result\n",
    "\n",
    "print \"Turbulent-boundary-layer thickness at the end of the plate from the leading edge of the plate is\",round(del_a*1000,1),\"mm\" \n",
    "print \"Turbulent-boundary-layer thickness at the end of the plate from the transition point at Re_crit = 5*10**(5) is\",round(del_b*1000,1),\" mm\""
   ]
  }
 ],
 "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
}