{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# Chapter 04:Unsteady conduction"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.1:pg-137"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Introduction to heat transfer by S.K.Som, Chapter 4, Example 1\n",
      "Biot number is\n",
      "Bi= 0.277777777778\n",
      "Problem is not suitable for lumped parameter analysis\n"
     ]
    }
   ],
   "source": [
    " \n",
    "\n",
    " \n",
    " \n",
    "import math\n",
    " \n",
    "print\"Introduction to heat transfer by S.K.Som, Chapter 4, Example 1\"\n",
    "#Diameter of apple in m\n",
    "d = 100*(10**(-3));\n",
    "#radius in m\n",
    "r = d/2;\n",
    "#Thermal conductivity of apple in W/(m*K)\n",
    "k = 0.6;\n",
    "#Heat transfer coefficient in W/(m**2*°C)\n",
    "h = 10;\n",
    "#Caculating characteristic dimension in m\n",
    "Lc = (((((4*math.pi)*r)*r)*r)/3)/(((4*math.pi)*r)*r);\n",
    "#Biot number\n",
    "print\"Biot number is\"\n",
    "Bi = (h*Lc)/k\n",
    "print\"Bi=\",Bi\n",
    "if Bi<0.1:\n",
    "  print\"Problem is suitable for lumped parameter analysis\"\n",
    "else:\n",
    "  print\"Problem is not suitable for lumped parameter analysis\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.2:pg-138 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Introduction to heat transfer by S.K.Som, Chapter 4, Example 2\n",
      "Time constant in seconds is\n",
      "tc= 8.0\n",
      "Time required in seconds\n",
      "t= 36.8413614879\n"
     ]
    }
   ],
   "source": [
    " \n",
    " \n",
    "  \n",
    " \n",
    "import math\n",
    " \n",
    "print\"Introduction to heat transfer by S.K.Som, Chapter 4, Example 2\"\n",
    "#Diameter of sphere in m\n",
    "d = 1.5*(10**(-3));\n",
    "#radius in m\n",
    "r = d/2;\n",
    "#Thermal conductivity of sphere in W/(m*°C)\n",
    "k = 40.0;\n",
    "#Density in kg/m**3\n",
    "rho = 8000.0;\n",
    "#Specific heat in J/(Kg*K)\n",
    "c = 300.0;\n",
    "#Heat transfer coefficient in W/(m**2*°C)\n",
    "h = 75.0;\n",
    "#Time constant in sec\n",
    "tc = ((rho*c)*(((((4*math.pi)*r)*r)*r)/3))/((((h*4)*math.pi)*r)*r);\n",
    "print\"Time constant in seconds is\"\n",
    "print\"tc=\",tc\n",
    "#Using eq. 4.4\n",
    "#Given fraction is 0.01 (1 percent)\n",
    "#Required time in sec\n",
    "t = (-8)*math.log(0.01);\n",
    "print\"Time required in seconds\"\n",
    "print\"t=\",t\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.3:pg-138"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Introduction to heat transfer by S.K.Som, Chapter 4, Example 3\n",
      "Maximum dimension in metre for lumped parameter analysis\n",
      "a= 5.0\n"
     ]
    }
   ],
   "source": [
    " \n",
    " \n",
    "  \n",
    " \n",
    "import math\n",
    " \n",
    "print\"Introduction to heat transfer by S.K.Som, Chapter 4, Example 3\"\n",
    "#Heat transfer coefficient in W/(m**2*K)\n",
    "h = 30;\n",
    "#Thermal conductivity of sphere in W/(m*K)\n",
    "k = 250;\n",
    "#Biot number for lumped parameter analysis is 0.1\n",
    "Bi = 0.1;\n",
    "#Characteristic dimension of a cube is (a/6) where a is the side of cube in metre\n",
    "#Maximum dimension in metre\n",
    "a = ((6*k)*Bi)/h;\n",
    "print\"Maximum dimension in metre for lumped parameter analysis\"\n",
    "print\"a=\",a\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.4:pg-146"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Introduction to heat transfer by S.K.Som, Chapter 4, Example 4\n",
      "Time required to cool milk in minutes\n",
      "Energy required for cooling in KJ\n",
      "E= -319.013666564\n"
     ]
    }
   ],
   "source": [
    " \n",
    "from scipy.integrate  import quad\n",
    "import math\n",
    "print\"Introduction to heat transfer by S.K.Som, Chapter 4, Example 4\"\n",
    "#Diameter of glass in m\n",
    "d = 50*(10**(-3));\n",
    "#radius in m\n",
    "r = d/2;\n",
    "#Height of milk in glass in m\n",
    "H = 0.1;\n",
    "#Initial temperature of milk in °C\n",
    "T = 80.0;\n",
    "#Cold water temperature in °C\n",
    "Tf = 25.0;\n",
    "#Heat transfer coefficient in W/(m**2*°C)\n",
    "h = 100.0;\n",
    "#Thermal conductivity of milk in W/(m*K)\n",
    "k = 0.6;\n",
    "#Density of milk in kg/m**3\n",
    "rho = 900.0;\n",
    "#Specific heat in J/(Kg*K)\n",
    "c = 4.2*(10**3);\n",
    "#Since the milk temperature is always maintained as constant.\n",
    "#Therefore it can be assumed as lumped paramteter analysis.\n",
    "#Time constant n seconds\n",
    "tcs = (((((rho*c)*math.pi)*r)*r)*H)/(((h*math.pi)*d)*H);\n",
    "#Time constant in minutes\n",
    "tc = tcs/60;\n",
    "#Calculating from eq. 4.3 time taken to cool milk from 80°C to 30°C\n",
    "t = -tc*math.log((30.0-Tf)/(T-Tf));\n",
    "print\"Time required to cool milk in minutes\"\n",
    "t\n",
    "#Energy transferred during cooling\n",
    "E = (((h*math.pi)*d)*H)*quad(lambda t:(80.0-25.0)*math.e*(-t/472.5),0,60.0*t)[0];\n",
    "print\"Energy required for cooling in KJ\"\n",
    "E = E/1000.0\n",
    "print \"E=\",E\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.5:pg-159"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Introduction to heat transfer by S.K.Som, Chapter 4, Example 5\n",
      "Time required in hours\n",
      "t= 7.5\n",
      "Heat transfer rate in MJ\n",
      "Q= 186.3\n"
     ]
    }
   ],
   "source": [
    " \n",
    " \n",
    "  \n",
    " \n",
    "import math\n",
    " \n",
    "print\"Introduction to heat transfer by S.K.Som, Chapter 4, Example 5\"\n",
    "#Thermal conductivity of wall in W/(m*K)\n",
    "k = 0.6;\n",
    "#Thermal diffusivity in m**2/s\n",
    "alpha = 5*(10**(-7));\n",
    "#Thickness in m\n",
    "L = 0.15;\n",
    "#Initial temperature in °C\n",
    "Ti = 30;\n",
    "#Temperature of hot gas in °C\n",
    "Tinfinity = 780;\n",
    "#Heat transfer coefficient in W/(m**2*K)\n",
    "h = 20;\n",
    "#Surface temperaute to be achieved in °C\n",
    "To = 480;\n",
    "#Dimensionless temperature ratio\n",
    "z = (To-Tinfinity)/(Ti-Tinfinity);\n",
    "#Biot number\n",
    "Bi = (h*L)/k;\n",
    "#For this value of (1/Bi) and dimensionless temp. ratio\n",
    "#From Fig. 4.11 Fourier number is\n",
    "Fo = 0.6;\n",
    "#Time required in seconds\n",
    "t = ((Fo*L)*L)/alpha;\n",
    "print\"Time required in hours\"\n",
    "t = t/3600\n",
    "print\"t=\",t\n",
    "#From fig. 4.13, for this Bi and Fo*Bi*Bi, we have ratio of heats as\n",
    "#Q/Qi=0.69\n",
    "#Heat transfer in J\n",
    "Q = ((((0.69*k)*2)*L)*(Tinfinity-Ti))/alpha;\n",
    "print\"Heat transfer rate in MJ\"\n",
    "Q = Q/(10**6)\n",
    "print\"Q=\",Q\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.6:pg-166"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Introduction to heat transfer by S.K.Som, Chapter 4, Example 6\n",
      "Temperature at this distance in °C\n",
      "T= 355.5\n",
      "Heat transfer rate in MJ\n",
      "Q= 100.0\n"
     ]
    }
   ],
   "source": [
    " \n",
    " \n",
    "  \n",
    " \n",
    "import math\n",
    " \n",
    "print\"Introduction to heat transfer by S.K.Som, Chapter 4, Example 6\"\n",
    "#Thickness of plate in m\n",
    "L = 0.2;\n",
    "#Initial temperature in °C\n",
    "Ti = 530;\n",
    "#Heat transfer coefficient in W/(m**2*K)\n",
    "h = 500;\n",
    "#Given distance in m\n",
    "x = L-20*(10**(-3));\n",
    "#Temperature of surrounding in °C\n",
    "Tinfinity = 30;\n",
    "#Given time in seconds\n",
    "t = 225;\n",
    "#Thermal conductivity of aluminium in W/(m*K)\n",
    "k = 200;\n",
    "#Thermal diffusivity in m**2/s\n",
    "alpha = 8*(10**(-5));\n",
    "#Biot number\n",
    "Bi = (h*L)/k;\n",
    "#Fourier number\n",
    "Fo = (alpha*t)/(L*L);\n",
    "#From fig. 4.11, at this Fo and (1/Bi), we have dimensionless temperature\n",
    "#ratio to be 0.7\n",
    "#From fig. 4.12 for this (1/Bi) and (x/L), we have another dimensionless\n",
    "#temperature to be 0.93\n",
    "#Temperature in °C\n",
    "T = Tinfinity+(0.93*0.7)*(Ti-Tinfinity);\n",
    "print\"Temperature at this distance in °C\"\n",
    "print\"T=\",T\n",
    "#From fig. 4.13, for this Bi and Fo*Bi*Bi, we have ratio of heats as\n",
    "#Q/Qi=0.4\n",
    "#Heat transfer in J\n",
    "Q = (((0.4*k)*L)*(Ti-Tinfinity))/alpha;\n",
    "print\"Heat transfer rate in MJ\"\n",
    "Q = Q/(10**6)\n",
    "print\"Q=\",Q\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.7:pg-171"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Introduction to heat transfer by S.K.Som, Chapter 4, Example 7\n",
      "Temperature at this radius in °C\n",
      "T= 300.0\n",
      "Heat transfer rate per unit length in MJ/m\n",
      "Q= 33.2639222145\n"
     ]
    }
   ],
   "source": [
    " \n",
    " \n",
    "  \n",
    " \n",
    "import math\n",
    " \n",
    "print\"Introduction to heat transfer by S.K.Som, Chapter 4, Example 7\"\n",
    "#Radius in m\n",
    "ro = 0.15;\n",
    "#Initial temperature in °C\n",
    "Ti = 530;\n",
    "#Temperature of surrounding in °C\n",
    "Tinfinity = 30;\n",
    "#Heat transfer coefficient in W/(m**2*K)\n",
    "h = 380;\n",
    "#Thermal conductivity of aluminium in W/(m*K)\n",
    "k = 200;\n",
    "#Thermal diffusivity in m**2/s\n",
    "alpha = 8.5*(10**(-5));\n",
    "#Given radius at which temperature has to be find out in m\n",
    "r = 0.12;\n",
    "#Given time in seconds\n",
    "t = 265;\n",
    "#Fourier number\n",
    "Fo = (alpha*t)/(ro**2);\n",
    "#Biot number\n",
    "Bi = (h*ro)/k;\n",
    "#From fig. 4.15, at this fourier number,Fo and (1/Bi), we have dimensionless temperature\n",
    "#ratio to be 0.6\n",
    "#From fig. 4.16 for this (1/Bi) and (r/ro), we have another dimensionless\n",
    "#temperature to be 0.9\n",
    "#Temperature in °C\n",
    "T = Tinfinity+(0.9*0.6)*(Ti-Tinfinity);\n",
    "print\"Temperature at this radius in °C\"\n",
    "print\"T=\",T\n",
    "#From fig. 4.17, for this Bi and Fo*Bi*Bi, we have ratio of heats as\n",
    "#Q/Qi=0.4\n",
    "#Heat transfer per metre in J/m\n",
    "Q = (((((0.4*k)*math.pi)*ro)*ro)*(Ti-Tinfinity))/alpha;\n",
    "print\"Heat transfer rate per unit length in MJ/m\"\n",
    "Q = Q/(10**6)\n",
    "print\"Q=\",Q\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.8:pg-174"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Introduction to heat transfer by S.K.Som, Chapter 4, Example 8\n",
      "Time required in minutes\n",
      "t= 4.16666666667\n"
     ]
    }
   ],
   "source": [
    " \n",
    " \n",
    "  \n",
    " \n",
    "import math\n",
    "\n",
    "print\"Introduction to heat transfer by S.K.Som, Chapter 4, Example 8\"\n",
    "#Radius in m\n",
    "ro = 0.05;\n",
    "#Initial temperature in °C\n",
    "Ti = 530;\n",
    "#Temperature of surrounding in °C\n",
    "Tinfinity = 30;\n",
    "#Heat transfer coefficient in W/(m**2*K)\n",
    "h = 500;\n",
    "#Thermal conductivity of aluminium in W/(m*K)\n",
    "k = 50;\n",
    "#Thermal diffusivity in m**2/s\n",
    "alpha = 1.5*(10**(-5));\n",
    "#Required centre temperature to achieve in °C\n",
    "To = 105;\n",
    "#Dimensionless temperature\n",
    "z = (To-Tinfinity)/(Ti-Tinfinity);\n",
    "#Biot number\n",
    "Bi = (h*ro)/k;\n",
    "#For this value of (1/Bi) and dimensionless temp. ratio\n",
    "#From Fig. 4.19 Fourier number is\n",
    "Fo = 1.5;\n",
    "#Time required in seconds\n",
    "t = ((Fo*ro)*ro)/alpha;\n",
    "print\"Time required in minutes\"\n",
    "t = t/60\n",
    "print\"t=\",t\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.9:pg-177"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Introduction to heat transfer by S.K.Som, Chapter 4, Example 9\n",
      "Tempearture of bar in °C\n",
      "T= 260.3\n"
     ]
    }
   ],
   "source": [
    " \n",
    " \n",
    "  \n",
    " \n",
    "import math\n",
    " \n",
    "print\"Introduction to heat transfer by S.K.Som, Chapter 4, Example 9\"\n",
    "#Thermal conductivity of aluminium in W/(m*K)\n",
    "k = 198;\n",
    "#Length in m\n",
    "L = 0.18;\n",
    "#Breadth in m\n",
    "b = 0.104;\n",
    "#Initial temperature in °C\n",
    "Ti = 730;\n",
    "#Temperature of surrounding in °C\n",
    "Tinfinity = 30;\n",
    "#Heat transfer coefficient in W/(m**2*K)\n",
    "h = 1100;\n",
    "#Thermal diffusivity in m**2/s\n",
    "alpha = 8.1*(10**(-5));\n",
    "#Given time in seconds\n",
    "t = 100;\n",
    "#Bar can be considered to be an intersection of two infinite plates of\n",
    "#thickness L1 and L2 in m\n",
    "L1 = L/2;\n",
    "L2 = b/2;\n",
    "#For plate 1\n",
    "#Fourier number\n",
    "Fo1 = (alpha*t)/(L1**2);\n",
    "#Biot number\n",
    "Bi1 = (h*L1)/k;\n",
    "#From fig. 4.11, at this Fo and (1/Bi), we have dimensionless temperature\n",
    "#ratio to be 0.7\n",
    "#For plate 2\n",
    "#Fourier number\n",
    "Fo2 = (alpha*t)/(L2**2);\n",
    "#Biot number\n",
    "Bi2 = (h*L2)/k;\n",
    "#From fig. 4.11, at this Fo and (1/Bi), we have dimensionless temperature\n",
    "#ratio to be 0.47\n",
    "#Therefore combined dimensionless temperature ratio is multiply of two\n",
    "z = 0.47*0.7;\n",
    "#Temperature in °C\n",
    "T = Tinfinity+z*(Ti-Tinfinity);\n",
    "print\"Tempearture of bar in °C\"\n",
    "print\"T=\",T\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.10:pg-180"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Introduction to heat transfer by S.K.Som, Chapter 4, Example 10\n",
      "The factor((To-Tinf)/(Ti-Tinf)) is \n",
      "For plate 1\n",
      "A= 0.85\n",
      "For plate 2\n",
      "B= 0.8\n",
      "For plate 1\n",
      "A= 0.83\n",
      "For plate 2\n",
      "B= 0.72\n",
      "The calculated value is very close to the required value of 0.6.Hence the time required for the centre of the beam to reach 310°C is nearly 1200s or 20 minutes.\n",
      "T= 0.5976\n"
     ]
    }
   ],
   "source": [
    " \n",
    " \n",
    "  \n",
    " \n",
    "import math\n",
    " \n",
    "print\"Introduction to heat transfer by S.K.Som, Chapter 4, Example 10\"\n",
    "#An iron beam of rectangular cross section of size length,L=300mm by breadth,B=200 mm is used in the construction of a building\n",
    "#Initially the beam is at a uniform temprature(Ti) of 30°C.\n",
    "#Due to an accidental fire,the beam is suddenly exposed to hot gases at temprature,Tinf=730°C,with a convective heat transfer coefficient(h) of 100 W/(m**2*K)\n",
    "#To determine the time required for the centre plane of the beam to reach a temprature(To) of 310°C.\n",
    "To=310;\n",
    "Tinf=730;\n",
    "Ti=30;\n",
    "#Take thermal conductivity k=73W/(m*K) and thermal diffusivity of the beam alpha=2.034*10**-5m**2/s \n",
    "alpha=2.034*10**-5; \n",
    "k=73; \n",
    "h=100; \n",
    "#The rectangular iron beam can be considered as an intersection of an infinite plate 1 having thickness 2*L1=300mm and a second infinite plate 2 of thickness 2*L2=200mm \n",
    "L1=0.15;#in metre\n",
    "L2=0.10;#in metre\n",
    "#Here the faactor X=((To-Tinf)/(Ti-Tinf))\n",
    "print\"The factor((To-Tinf)/(Ti-Tinf)) is \"\n",
    "X=((To-Tinf)/(Ti-Tinf))\n",
    "#Therefore we can write 0.6=((To-Tinf)/(Ti-Tinf))plate 1 *((To-Tinf)/(Ti-Tinf))plate2\n",
    "#A straight forward solution is not possible.We have to adopt an iterative method of solution \n",
    "#At first ,a value of time(t) is assumed to determine the centre-line temprature of the beam.The value of t at which((To-Tinf)/(Ti-Tinf))beam =0.6 is satisfied\n",
    "#Let us first assume time, t=900s\n",
    "t=900;\n",
    "print\"For plate 1\"\n",
    "#For plate1 Biot number Bi1=h*L1/k \n",
    "Bi1=h*L1/k  \n",
    "Y=1/Bi1\n",
    "#Fourier number(Fo1) is\n",
    "Fo1=alpha*t/L1**2\n",
    "#At Fo=0.814 and (1/Bi)=4.87...We read from graphs  A=((To-Tinf)/(Ti-Tinf))plate1= 0.85\n",
    "A=0.85;\n",
    "print\"A=\",A\n",
    "print\"For plate 2\"\n",
    "#For plate1 Biot number Bi2=h*L2/k \n",
    "Bi2=h*L2/k  \n",
    "Y=1/Bi2\n",
    "#Fourier number(Fo2) is\n",
    "Fo2=alpha*t/L2**2\n",
    "#At Fo=1.83 and (1/Bi)=7.3...We read from graphs  B=((To-Tinf)/(Ti-Tinf))plate2= 0.8\n",
    "B=0.8;\n",
    "print\"B=\",B\n",
    "#Therefore ((To-Tinf)/(Ti-Tinf))plate1*((To-Tinf)/(Ti-Tinf))plate2=A*B\n",
    "T=A*B\n",
    "#Since the calculated value of 0.68 is greater than the required value of 0.60 and Tinf>To>Ti,The assume dvalue of t is less.\n",
    "#So let us take time,t=1200s for the second iteration\n",
    "t=1200;\n",
    "print\"For plate 1\"\n",
    "#For plate1 Biot number Bi1=h*L1/k \n",
    "Bi1=h*L1/k  \n",
    "Y=1/Bi1\n",
    "#Fourier number (Fo1)\n",
    "Fo1=alpha*t/L1**2\n",
    "#At Fo=1.08 and (1/Bi)=4.87...We read from graphs  A=((To-Tinf)/(Ti-Tinf))plate1= 0.83\n",
    "A=0.83;\n",
    "print\"A=\",A\n",
    "print\"For plate 2\"\n",
    "#For plate1 Biot number Bi2=h*L2/k \n",
    "Bi2=h*L2/k  \n",
    "Y=1/Bi2\n",
    "#Fourier number (Fo2)\n",
    "Fo2=alpha*t/L2**2\n",
    "#At Fo=2.44 and (1/Bi)=7.3...We read from graphs  B=((To-Tinf)/(Ti-Tinf))plate2= 0.72\n",
    "B=0.72;\n",
    "print\"B=\",B\n",
    "#Therefore ((To-Tinf)/(Ti-Tinf))plate1*((To-Tinf)/(Ti-Tinf))plate2=A*B\n",
    "T=A*B\n",
    "print\"The calculated value is very close to the required value of 0.6.Hence the time required for the centre of the beam to reach 310°C is nearly 1200s or 20 minutes.\" \n",
    "print\"T=\",T\n",
    " \n",
    " \n",
    " \n",
    " \n",
    " \n",
    " \n",
    " \n",
    " \n",
    " \n",
    " \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.11:pg-182"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Introduction to heat transfer by S.K.Som, Chapter 4, Example 11\n",
      "The time required for the temprature to reach 255°C at a depth of 80mm, in minutes is\n",
      "T= 255\n"
     ]
    }
   ],
   "source": [
    " \n",
    " \n",
    "  \n",
    " \n",
    "import math\n",
    " \n",
    "print\"Introduction to heat transfer by S.K.Som, Chapter 4, Example 11\"\n",
    "#A large slab wrought-iron is at a uniform temprature of Ti=550°C.\n",
    "#The temprature of one surface is suddenly changed to Tinf=50°C\n",
    "Tinf=50;\n",
    "Ti=550; \n",
    "#For slab conductivity(k=60W/(m*K)),Thermal diffusivity(alpha=1.6*10**-5m**2/s)\n",
    "#To calculate the time(t) required for the temprature to reach T=255°C at a depth of 80mm\n",
    "k=60;\n",
    "T=255;\n",
    "alpha=1.6**10-5;\n",
    "#Similarity parameter,eta=x/(2*(alpha*t)**0.5)=(10/t**0.5)\n",
    "#((T-Tinf)/(Ti-Tinf))=erf(10/t**0.5)...where erf is the error function.\n",
    "#Let ((T-Tinf)/(Ti-Tinf))=X\n",
    "X=((T-Tinf)/(Ti-Tinf));\n",
    "#This implies erf(10/t**0.5)=0.41\n",
    "#We read from the table the value of eta(=10/t**0.5)=0.38....corresponding to erf(eta)=0.41\n",
    "#Therefore 10/t**0.5=0.38...this implies t=(10/0.38)**2\n",
    "print\"The time required for the temprature to reach 255°C at a depth of 80mm, in minutes is\"\n",
    "t=(10/0.38)**2/60\n",
    "print\"T=\",T\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.12:pg-186"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Introduction to heat transfer by S.K.Som, Chapter 4, Example 12\n",
      "gaussian error function is \n",
      "E= 0.998109069322\n",
      "The temprature at a depth(x) of 100mm after a time(t) of 100 seconds,in °C is\n",
      "T= -29851.5095103\n"
     ]
    }
   ],
   "source": [
    " \n",
    "import math\n",
    "import scipy \n",
    "print\"Introduction to heat transfer by S.K.Som, Chapter 4, Example 12\"\n",
    "#A large block of nickel steel conductivity(k=20W/(m*K)),thermal diffusivity(alpha=0.518*10-5 m**2/s) is at uniform temprature(Ti) of 30°C.\n",
    "Ti=30.0;\n",
    "k=20.0;\n",
    "alpha=0.518*10.0**-5.0;\n",
    "#One surface of the block is suddenly exposed to a constant surface heat flux(qo) of 6MW/m**2.\n",
    "qo=6*10**6;#in W/m**2\n",
    "#To determine the temprature at a depth(x) of 100mm after a time(t) of 100 seconds.\n",
    "t=100.0;\n",
    "x=0.1;#in metre\n",
    "#Similarity parameter,eta=x/(4*alpha*t)\n",
    "eta=x/((4.0*alpha*t)**0.5)\n",
    "#E is gaussian error function\n",
    "print\"gaussian error function is \"\n",
    "E=scipy.special.erf(eta)\n",
    "print\"E=\",E\n",
    "#The equation to determine temprature is T-Ti=((2*qo(alpha*t/math.pi)**0.5)/(k))*e**((-x**2)/(4*alpha*t))-((qo*x)/(k))*erf(x/(2.0*(alpha*t)**0.5))\n",
    "#Above equation can also be written as T=Ti+((2*qo(alpha*t/math.pi)**0.5)/(k))*e**((-x**2)/(4*alpha*t))-((qo*x)/(k))*erf(x/(2.0*(alpha*t)**0.5))\n",
    "print\"The temprature at a depth(x) of 100mm after a time(t) of 100 seconds,in °C is\"\n",
    "T=Ti+((2*qo*(alpha*t/math.pi)**0.5)/(k))*math.e**((-x**2.0)/(4*alpha*t))-((qo*x)/(k))*scipy.special.erf(x/(2*(alpha*t)**0.5))\n",
    "print\"T=\",T\n",
    "#NOTE:The answer in the book is incorrect(Calculation mistake)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex4.14:pg-187 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Introduction to heat transfer by S.K.Som, Chapter 4, Example 14\n",
      "Temperature distribution after 25 mins in °C\n",
      "[[  2.29192547e+02   2.91925466e+00   1.11801242e+00   4.34782609e-01\n",
      "    1.86335404e-01   6.21118012e-02]\n",
      " [  8.75776398e+01   8.75776398e+00   3.35403727e+00   1.30434783e+00\n",
      "    5.59006211e-01   1.86335404e-01]\n",
      " [  3.35403727e+01   3.35403727e+00   8.94409938e+00   3.47826087e+00\n",
      "    1.49068323e+00   4.96894410e-01]\n",
      " [  1.30434783e+01   1.30434783e+00   3.47826087e+00   9.13043478e+00\n",
      "    3.91304348e+00   1.30434783e+00]\n",
      " [  5.59006211e+00   5.59006211e-01   1.49068323e+00   3.91304348e+00\n",
      "    1.02484472e+01   3.41614907e+00]\n",
      " [  3.72670807e+00   3.72670807e-01   9.93788820e-01   2.60869565e+00\n",
      "    6.83229814e+00   8.94409938e+00]]\n"
     ]
    }
   ],
   "source": [
    " \n",
    "import math\n",
    "import numpy\n",
    " \n",
    "print\"Introduction to heat transfer by S.K.Som, Chapter 4, Example 14\"\n",
    "#Nodal distance Deltax in m\n",
    "deltax = 0.1;\n",
    "#Time in seconds\n",
    "t = 25*60;\n",
    "#timestep deltaT in seconds\n",
    "deltaT = 500;\n",
    "#Number of increment\n",
    "n = t/deltaT;\n",
    "#Temperature raised in °C\n",
    "To = 580.0;\n",
    "#Using Eq. 4.114 for interior grid points, table 4.8 for exterior node\n",
    "#Using Eq. 4.125a to 4.125f are written in matrix form\n",
    "#Coefficient matrix A is\n",
    "A = [[-3,1,0,0,0,0],[1,-3,1,0,0,0],[0,1,-3,1,0,0],[0,0,1,-3,1,0],[0,0,0,1,-3,1],[0,0,0,0,2,-3]]\n",
    "#Coefficient matrix B is\n",
    "B = [-600,-20,-20,-20,-20,-20];\n",
    "#Temperature matrix is transpose of [T2 T3 T4 T5 T6 T7] where\n",
    "#T2 to T7 are temperature in °C\n",
    "#From Eq. 4.126\n",
    "#Temperature distribution after one time step\n",
    "T = numpy.linalg.inv(A)*B;\n",
    "\n",
    " \n",
    "print\"Temperature distribution after 25 mins in °C\"\n",
    "print T\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
}