{
 "metadata": {
  "name": "",
  "signature": "sha256:762c657ca63f4bd96f109e4e82b32740084456d360cd020253f718b992f3cd8d"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 4 : Conduction of heat in the unsteady state"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.1 page : 58"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "# Variables\n",
      "b = 9.;                                   # Thickness of the wall in ft\n",
      "A = 5.;                                   # Area of wall \n",
      "k = 0.44;                                # Thermal conductivity in Btu/hr-ft-degF\n",
      "Cp = .202;                               # Specific heat in Btu/lbm-degF\n",
      "rho = 136.;                               # Density in lb/ft**3\n",
      "\n",
      "\n",
      "# Calculations and Results\n",
      "\n",
      "def derivative(f):\n",
      "    def df(x, h=0.1e-5):\n",
      "        return ( f(x+h/2) - f(x-h/2) )/h\n",
      "    return df\n",
      "\n",
      "def templength(x):             # Temperature function in terms of length                                                  \n",
      "    return  90 - 80*x +16*x**2 +32*x**3 -25.6*x**4;\n",
      "\n",
      "tgo  =  derivative(templength)(0);        # Temperature gradient at x = 0ft\n",
      "tgl  =  derivative(templength)(9./12);     # Temperature gradient at x = 9/12ft\n",
      "\n",
      "qo  =  -k*A*tgo;                         # Heat entering per unit time in Btu/hr\n",
      "print \"Heat entering per unit time is %.2f Btu/hr \"%(qo);\n",
      "ql  =  -k*A*tgl;                         # Heat coming out per unit time in Btu/hr\n",
      "print \" Heat coming per unit time is %.2f Btu/hr \"%(ql);\n",
      "q3  =  qo-ql;                            #Heat energy stored in Btu/hr\n",
      "print \" Heat energy stored in wall is %.2f Btu/hr \"%(q3);\n",
      "\n",
      "a = k/(rho*Cp);                               # Thermal diffusivity\n",
      "def doublederivative(y):           # Derivative of tempearture with respect to length in degF/ft\n",
      "  return  -80+32*y+96*y**2-102.4*y**3;\n",
      "\n",
      "timeder0 = a*derivative(doublederivative)(0);  # derivative of temperature  wrt time at x = 0 in degF\n",
      "print \" Time derivative of temperature wrt time at x = 0ft is %.2f degF/hr\"%(timeder0);\n",
      "timeder1 = a*derivative(doublederivative)(9./12);      # derivative of temperature wrt time at x = 9/12 in degF \n",
      "print \" Time derivative of temperature wrt time at x = 9/12ft is %.2f degF/hr\"%(timeder1);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat entering per unit time is 176.00 Btu/hr \n",
        " Heat coming per unit time is 99.44 Btu/hr \n",
        " Heat energy stored in wall is 76.56 Btu/hr \n",
        " Time derivative of temperature wrt time at x = 0ft is 0.51 degF/hr\n",
        " Time derivative of temperature wrt time at x = 9/12ft is 0.05 degF/hr\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.2 page :60"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "# Variables\n",
      "b = 9.;                                 # thickness of the wall in ft\n",
      "A = 5.;                                 # area of wall in ft**2\n",
      "k = 0.44;                               # Thermal conductivity in Btu/hr-ft-degF\n",
      "Cp = .202;                              # Specific heat in Btu/lbm-degF\n",
      "rho = 136.;                              # density in lb/ft**3\n",
      "\n",
      "# Calculations and Results\n",
      "def derivative(f):\n",
      "    def df(x, h=0.1e-5):\n",
      "        return ( f(x+h/2) - f(x-h/2) )/h\n",
      "    return df\n",
      "\n",
      "def templength(x):\n",
      "    return  90 - 8*x-80*x**2; \n",
      "\n",
      "\n",
      "tgo  =  derivative(templength)(0);      # temperature gradient at x = 0ft\n",
      "tgl  =  derivative(templength)(9./12);    # temperature gradient at x = 9/12ft\n",
      "\n",
      "qo  =  -k*A*tgo;                        # Heat entering per unit time in Btu/hr\n",
      "print \"Heat entering per unit time is %.2f Btu/hr \"%(qo);\n",
      "ql  =  -k*A*tgl;                        # Heat coming out per unit time in Btu/hr\n",
      "print \" Heat coming per unit time is %.2f Btu/hr \"%(ql);\n",
      "q3  =  qo-ql;                           #Heat energy stored in Btu/hr\n",
      "print \" Heat energy stored in wall is %.2f Btu/hr \"%(q3);\n",
      "\n",
      "a = k/(rho*Cp);                         # Thermal diffusivity in ft**2/hr\n",
      "def doublederivative(y):     # derivative of tempearture with respect to length in degF/ft\n",
      "  return  -8-160*y;\n",
      "\n",
      "timeder0 = a*derivative(doublederivative)(0);         # derivative of temperature  wrt time at x = 0 in degF\n",
      "print \" Time derivative of temperature wrt time at x = 0ft is %.2f degF/hr\"%(timeder0);\n",
      "timeder1 = a*derivative(doublederivative)(9./12);      # derivative of temperature wrt time at x = 9/12 in degF \n",
      "print \" Time derivative of temperature wrt time at x = 9/12ft is %.2f degF/hr\"%(timeder1);\n",
      "print \" Teperature at each part of wall decreases equally\";\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat entering per unit time is 17.60 Btu/hr \n",
        " Heat coming per unit time is 281.60 Btu/hr \n",
        " Heat energy stored in wall is -264.00 Btu/hr \n",
        " Time derivative of temperature wrt time at x = 0ft is -2.56 degF/hr\n",
        " Time derivative of temperature wrt time at x = 9/12ft is -2.56 degF/hr\n",
        " Teperature at each part of wall decreases equally\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.3 page : 65"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "# Variables\n",
      "t  =  10.;              # time elapsed in hr\n",
      "Ti =  70.;              # tempearature of wall initially in degF\n",
      "Ts  =  1500.;           # temperature of surface when suddenly changed in degF\n",
      "a  =  0.03;            # thermal diffusivity in ft**2/hr\n",
      "k  =  0.5;             # thermal conductivity in Btu/hr-ft-degF\n",
      "A  =  10.;              # area of wall in sq ft\n",
      "x  =  7./12;            # distance from surface where tempearture is to be found in ft\n",
      "f  =  x/(2*math.sqrt(a*t)); \n",
      "# From gaussian error function table erf can be found\n",
      "errorf  =  0.55;       # Referred from table\n",
      "\n",
      "# Calculations and Results\n",
      "T  =  Ts+(Ti-Ts)*errorf;\n",
      "print \"Temperaure at a distance of 7/12ft from surface is %.1f degF \"%(T);\n",
      "q  =  -k*A*(Ti-Ts)*math.exp(-x**2/(4*a*t))/math.sqrt(t*math.pi*a);   # heat flow rate at a distance\n",
      "qtot  =  -k*A*(Ti-Ts)*2*math.sqrt(t/(math.pi*a));              # total heat flowing after 10 hrs in Btu\n",
      "print \" Heat flowing at a distance of 7/12 ft from surface is %d Btu/hr\"%(q); \n",
      "print \" Total heat flow after 10hrs is %.f Btu\"%(qtot);\n",
      "\n",
      "# note : book answer are wrong."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Temperaure at a distance of 7/12ft from surface is 713.5 degF \n",
        " Heat flowing at a distance of 7/12 ft from surface is 5546 Btu/hr\n",
        " Total heat flow after 10hrs is 147299 Btu\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.4 page :67"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "d  =  16./12;                # Diameter of sphere in ft\n",
      "t  =  20./60;                # Time elapsed in hr\n",
      "a  =  0.31;                 # thermal diffusivity of steel in ft**2/hr\n",
      "Ti  =  80.;                  # Temperature of steel sphere initially in degF\n",
      "Ts  =  1200.;                 # Temperature of surface suddenly changed in degF\n",
      "\n",
      "# Calculations \n",
      "s  =  4*a*t/d**2;            # A parameter \n",
      "# From table the value of F(s) can be known \n",
      "Fs = 0.20;              \n",
      "Tc  =  Ts+(Ti-Ts)*Fs;       # Tempearture at the center of sphere in degF\n",
      "\n",
      "# Results\n",
      "print \"The tempearture at the center of steel sphere after 20 mins is %d degF\"%(Tc);  \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The tempearture at the center of steel sphere after 20 mins is 976 degF\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.5 page : 69"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "# Variables\n",
      "t  =  24.;                        # Time period of tempearture wave in hr\n",
      "k  =  0.6;                       # Thermal conductivity of wall in Btu/hr-ft-degF\n",
      "Cp  =  0.2;                      # Specific heat capacity of wall in Btu/lb-degF\n",
      "y  =  110.;                       # specific gravity in lb/ft**3\n",
      "x  =  8./12;                      # distance from surface in ft\n",
      "\n",
      "# Calculations \n",
      "a  =  k/(y*Cp);                   # Thermal diffusivity in ft**2/hr\n",
      "n = 1./t;                         # frequency in /hr\n",
      "delr  =  x/(2*math.sqrt(a*math.pi*n));     # Time lag in hr\n",
      "\n",
      "# Results\n",
      "print \"Time lag of the temperature at a point 8 in from surface is %.1f hr\"%delr;\n",
      "\n",
      "# book answer is wrong."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Time lag of the temperature at a point 8 in from surface is 5.6 hr\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.6 page : 69"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "# Variables\n",
      "T1 = -15.;                                 # Min temperature at surface in degF\n",
      "T2 = 25.;                                  # Max temperature at surface in degF\n",
      "t = 24.;                                   # time gap in hrs\n",
      "k = 1.3;                                  # thermal conductivity in Btu/hr-ft-degF\n",
      "Cp = 0.4;                                 # heat capacity in lb/ft-degF\n",
      "y = 126.1;                                # specific gravity in lb/ft**3\n",
      "n = 1./t;                                  # frequency in /hr         \n",
      "Tm = (T1+T2)/2;\n",
      "a = k/(y*Cp);                             # thermal diffusivity in ft**2\n",
      "\n",
      "# Calculations and Results\n",
      "x1 = 2;\n",
      "x2 = 6;\n",
      "th0 = (T1-T2)/2;\n",
      "th1 = th0*-math.exp(-x1*math.sqrt(math.pi*n/a));        # temperature range at 2 ft depth\n",
      "th2 = th0*-math.exp(-x2*math.sqrt(math.pi*n/a));        # temperature range at 6 ft depth \n",
      "print \"Amplitude of tempearture at 2ft deep is %.2f degF\"%(th1);\n",
      "print \" Amplitude of tempearture at 6ft deep is %.2f degF\"%(th2);\n",
      "print \" At a depth of 2ft , temperature varies from 4.78 degF to 5.22 degF and \\\n",
      "at a depth of 6 ft, temperature remains constant at 5 degF\"\n",
      "delr1 = x1/2*math.sqrt(1/(a*math.pi*n));          # time lag at 2 ft depth\n",
      "delr2 = x2/2*math.sqrt(1/(a*math.pi*n));          # time lag at 6 ft depth\n",
      "print \" Lag of temperature wave at a depth 2 ft is %.1f hr \"%(delr1);\n",
      "print \" Lag of temperature wave at a depth 6 ft is %.1f hr \"%(delr2);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Amplitude of tempearture at 2ft deep is 0.22 degF\n",
        " Amplitude of tempearture at 6ft deep is 0.00 degF\n",
        " At a depth of 2ft , temperature varies from 4.78 degF to 5.22 degF and at a depth of 6 ft, temperature remains constant at 5 degF\n",
        " Lag of temperature wave at a depth 2 ft is 17.2 hr \n",
        " Lag of temperature wave at a depth 6 ft is 51.6 hr \n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.7 page : 70"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "# Variables\n",
      "T1 = 10.;                                 # Min temperature at surface in degF\n",
      "T2 = -10.;                                # Max temperature at surface in degF\n",
      "t1 = 24.;\n",
      "t2 = 5.;                                  # Time gap in hrs\n",
      "k = 0.3;                                 # Thermal conductivity in Btu/hr-ft-degF\n",
      "Cp = 0.47;                               # Heat capacity in lb/ft-degF\n",
      "y = 100.;                                 # Specific gravity in lb/ft**3\n",
      "n1 = 1/t1;                               # Frequency in /hr         \n",
      "Tm = (T1+T2)/2;a = k/(y*Cp);               # thermal diffusivity in ft**2\n",
      "n = 1./t1;                                # Frequency in /sec\n",
      "x1 = 1.;\n",
      "x2 = 1.;\n",
      "\n",
      "# Calculations and Results                                  # Depth in ft\n",
      "th0 = (T1-T2)/2;th1 = th0*math.exp(-x1*math.sqrt(math.pi*n/a));        # temperature range at 2 ft depth\n",
      "th2 = th0*math.exp(-x2*math.sqrt(math.pi*n/a));        # Temperature range at 6 ft depth \n",
      "print \"Amplitude of tempearture at 2ft deep is %.2f degF\"%(th1);\n",
      "delr1 = x1/2*math.sqrt(1/(a*math.pi*n));          # Time lag at 2 ft depth\n",
      "print \" Lag of temperature wave at a depth 2 ft is %.1f hr \"%(delr1);\n",
      "# To calculate the temperature at a depth of 1 ft , 5 hr after the srface temperature reaches the minimum temperature \n",
      "r = 3/(4*n);                            # Time at which minimum surface temperature occurs for the first time in hr\n",
      "r1 = r+5;                               # Time ar which temperature is to be found out in degF\n",
      "th3 = th0*math.exp(-x1*math.sqrt(math.pi*n/a))*math.sin(2*math.pi*r1/24-4.53);\n",
      "Tr = Tm+th3;                            # Temperature to be found out in degF\n",
      "print \" The temperaure at 1 ft depth is %.2f degF \"%(Tr);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Amplitude of tempearture at 2ft deep is 0.11 degF\n",
        " Lag of temperature wave at a depth 2 ft is 17.3 hr \n",
        " The temperaure at 1 ft depth is 0.11 degF \n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.8 page : 72"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "# Variables\n",
      "a = 0.02;                             # thermal diffusivity in ft**2/hr\n",
      "M = 4.;                                # the value of 4 is selected for M\n",
      "\n",
      "# Calculations and Results\n",
      "x = 9./12;                             # thickness of wall in ft\n",
      "delx = 1.5/12;\n",
      "delr = delx**2/(a*M);                     # at time interval the heat transfeered will change the temperature of math.sink from tb2 to tb2o\n",
      "print \"The time interval is to be of %.3f hr \"%(delr);\n",
      "\n",
      "t1o = 370; \n",
      "t2o = 435; \n",
      "t3o = 480; \n",
      "t4o = 485; \n",
      "t5o = 440; \n",
      "t6o = 360; \n",
      "t7o = 250;\n",
      " \n",
      "# tempetaures at different positions at wall in degF initially\n",
      "# we know qo = Z*delx*dely*rho*Cp(tb2'-tb2)/delr    So on solving equations we get tb2' = (tb1+tb3+ta2+tc2)/4\n",
      "# using above formula, temperaures at different positions as shown below can be calculated in degF\n",
      "\n",
      "ta = [370, 430, 470, 473, 431, 352, 250];\n",
      "tb = [370, 425, 461, 462, 422, 346, 250]; \n",
      "tc = [370, 420, 452, 452, 413, 341, 250];\n",
      "td = [370, 415, 444, 442, 404, 336, 250];\n",
      "print \" The temperatures at different positions 0.78 hr after, are as follows \"\n",
      "for i in range(7):\n",
      "    print \" The temperature at point %d is %d degF \"%(i,td[i]);\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The time interval is to be of 0.195 hr \n",
        " The temperatures at different positions 0.78 hr after, are as follows \n",
        " The temperature at point 0 is 370 degF \n",
        " The temperature at point 1 is 415 degF \n",
        " The temperature at point 2 is 444 degF \n",
        " The temperature at point 3 is 442 degF \n",
        " The temperature at point 4 is 404 degF \n",
        " The temperature at point 5 is 336 degF \n",
        " The temperature at point 6 is 250 degF \n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.9 page : 73"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "a = 0.53;                             # thermal diffusivity in ft**2/hr\n",
      "M = 4.;                                # the value of 4 is selected for M\n",
      "x = 6./12;                             # thickness of wall in ft\n",
      "delx = 2./12;\n",
      "delr = delx**2/(a*M);                  # at time interval the heat transfeered will change the temperature of math.sink from tb2 to tb2o\n",
      "print \"the time interval is to be of %.3f hr \"%(delr);\n",
      "\n",
      "# the temperature is consmath.tant in the whole wall initiallt 100 degF and afterwards it changes to 1000 degF. \n",
      "# we know qo = Z*delx*dely*rho*Cp(tb2'-tb2)/delr    So on solving equations we get tb2' = (tb1+tb3+ta2+tc2)/4\n",
      "# using above formula we can calculate the different temperatures as given below in degF\n",
      "\n",
      "ta = [100, 550, 775, 888, 944];\n",
      "tb = [100, 550, 775, 888, 944];\n",
      "tc = [100, 550, 775, 888, 944];\n",
      "td = [100, 550, 775, 888, 944];\n",
      "print \" the temperatures at different positions 0.052 hr after, are as follows \"\n",
      "print \" the temperature at point a is %d degF \"%ta[4]\n",
      "print \" the temperature at point a is %d degF \"%tb[4]\n",
      "print \" the temperature at point a is %d degF \"%tc[4];\n",
      "print \" the temperature at point a is %d degF \"%td[4]\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "the time interval is to be of 0.013 hr \n",
        " the temperatures at different positions 0.052 hr after, are as follows \n",
        " the temperature at point a is 944 degF \n",
        " the temperature at point a is 944 degF \n",
        " the temperature at point a is 944 degF \n",
        " the temperature at point a is 944 degF \n"
       ]
      }
     ],
     "prompt_number": 16
    }
   ],
   "metadata": {}
  }
 ]
}