{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 3 : The general property balance"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.1 - Page No :65\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "# Variables\n",
      "a = 0.0006;  \t\t #[m**2] - area\n",
      "l = 0.1;  \t\t\t #[m] - length\n",
      "\n",
      "# (a) using the fourier law\n",
      "deltax = 0.1;  \t\t #[m] - thickness of copper block\n",
      "T2 = 100.;  \t\t #[degC] - temp on one side of copper block\n",
      "T1 = 0.;  \t\t\t #[degC] - temp on other side of the copper block\n",
      "k = 380.;  \t\t\t #[W/mK] - thermal conductivity\n",
      "\n",
      "# Calculations\n",
      "# using the formula (q/A)*deltax = -k*(T2-T1)\n",
      "g = -k*(T2-T1)/deltax;\n",
      "print \" a) The steady state heat flux across the copper block is q/A = %5.1e J*m**-2*sec**-1 \"%(g);\n",
      "\n",
      "# (b)\n",
      "V = a*l; \t\t\t #[m**3] - volume\n",
      "# using the overall balance equation with the accumulation and generation term\n",
      "Qgen = 1.5*10**6;  \t\t\t #[j*m**-3*sec**-1]\n",
      "SIx = (g*a-Qgen*V)/a;\n",
      "\n",
      "# Results\n",
      "print \" b) the flux at face 1 is %5.1e j*m**-2*sec**-1;the negative sign indicates that the \\\n",
      "\\nheat flux is from right to left negative x direction\"%(SIx);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " a) The steady state heat flux across the copper block is q/A = -3.8e+05 J*m**-2*sec**-1 \n",
        " b) the flux at face 1 is -5.3e+05 j*m**-2*sec**-1;the negative sign indicates that the \n",
        "heat flux is from right to left negative x direction\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.2 - Page No :68\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from sympy import *\n",
      "\n",
      "# Variables\n",
      "x = Symbol('x')\n",
      "SIx2 = -3.8*10**5;  \t\t #[j*m**-2*sec**-1] - flux at x = 0.1,i.e through face2\n",
      "Qgen = 1.5*10**6;  \t\t\t #[j*m**-3*sec**-1] - uniform generation in the volume\n",
      "T2 = 100+273.15;  \t\t\t #[K] temperature at face 2\n",
      "x2 = 0.1;  \t\t\t         #[m]\n",
      "k = 380.;  \t\t\t         #[W/mK] - thermal conductivity\n",
      "\n",
      "# Calculations\n",
      "# using the equation der(SIx)*x = SIx+c1;where c1 is tyhe constant of integration\n",
      "c1 = (Qgen*x2)-SIx2;\n",
      "SIx = Qgen*x-c1;\n",
      "\n",
      "# Results\n",
      "print \"SIx = \",SIx\n",
      "print \" where SIx is in units of J m**-2 sec**-1 and x is in units of m\"\n",
      "\n",
      "# using the equation -k*T = der(SIx)*x**2-c1*x+c2;where c2 is the constant of integration\n",
      "c2 = -k*T2-(Qgen*(x2)**2)/2+c1*x2;\n",
      "T = -(Qgen/k)*x**2+(c1/k)*x-(c2/k);\n",
      "print \"T = \",T\n",
      "print \" where T is in units of kelvin K\"\n",
      "\n",
      "\n",
      "# Answer may vary because of rouding error."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "SIx =  1500000.0*x - 530000.0\n",
        " where SIx is in units of J m**-2 sec**-1 and x is in units of m\n",
        "T =  -3947.36842105263*x**2 + 1394.73684210526*x + 253.413157894737\n",
        " where T is in units of kelvin K\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.3 - Page No :69\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "import math \n",
      "from sympy import *\n",
      "\n",
      "\n",
      "# Variables\n",
      "# given\n",
      "x = Symbol('x')\n",
      "t = Symbol('t')\n",
      "hf1 = -270.;  \t\t\t #[J/sec] - heat flow at face 1\n",
      "hf2 = -228.;  \t\t\t #[J/sec] - heat flow at face2\n",
      "Qgen = 1.5*10**6;  \t\t #[J*m**-3*sec**-1] generation per unit volume per unit time\n",
      "v = 6*10**-5;  \t\t\t #[m**3] volume\n",
      "Cp = 0.093;  \t\t\t #[cal*g**-1*K**-1] heat capacity of copper\n",
      "sp = 8.91;  \t\t\t #specific gravity of copper\n",
      "a = 0.0006;  \t\t\t #[m**2] - area\n",
      "\n",
      "# Calculation and Results\n",
      "# (a) using the overall balance\n",
      "acc = hf1-hf2+Qgen*v;\n",
      "print \"a) the rate of accumulation is %d J/sec \"%(acc);\n",
      "\n",
      "# (b) \n",
      "SIx1 = hf1/a;\n",
      "SIx2 = hf2/a;\n",
      "x1 = 0.;\n",
      "\n",
      "# solving for the constant of integration c1 in the equation [del(p*cp*T)/delt-der(SIx)]*x = -SIx+c1;\n",
      "c1 = 0+SIx1;\n",
      "x2 = 0.1;\n",
      "g = (-(SIx2)+c1)/x2+Qgen;\n",
      "SIx = c1-(g-Qgen)*x;\n",
      "print \"SI(x) = \",\"(b)\",SIx\n",
      "\n",
      "# solving for constant of integration c3 in the equation p*cp*T = g*t+c3\n",
      "T2 = 100+273.15;\n",
      "t2 = 0;\n",
      "p = sp*10**3;  \t\t\t #[kg/m**3] - density\n",
      "cp = Cp*4.1840;  \t\t\t #[J*kg**-1*K**-1]\n",
      "c3 = p*cp*T2-g*t2;\n",
      "T = (g*(10**-3)/(p*cp))*t+c3/(p*cp);\n",
      "print \"Relationship between T and t at x=0.1m is T = \",T\n",
      "\n",
      "# solving for constant of integration c2 in the equation -k*T = der(SIx)*x**2-c1*x+c2\n",
      "k = 380.;  \t\t\t #[w/m**1*K**1]\n",
      "x2 = 0.1;\n",
      "c2 = k*T+(3.5*10**5)*x2**2-(4.5*10**5)*x2;\n",
      "\n",
      "def T(t,x):\n",
      "    return (-(3.5*10**5)*x**2+(4.5*10**5)*x+87.7*t+1.00297*10**5)/k;\n",
      "\n",
      "# at face 1;\n",
      "x1 = 0.;\n",
      "t1 = 60.;  \t\t\t #[sec]\n",
      "T1 = T(t1,x1);\n",
      "print \"Temperature profile as a function of x and t is T = %.2f K, at face 1\"%T1\n",
      "\n",
      "# at face 2\n",
      "x2 = 0.1;\n",
      "t2 = 60.;  \t\t\t # [sec]\n",
      "T2 = T(t2,x2);\n",
      "print \"Temperature at face 2  = %.0f K ,at face 2\"%T2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "a) the rate of accumulation is 48 J/sec \n",
        "SI(x) =  (b) 700000.0*x - 450000.0\n",
        "Relationship between T and t at x=0.1m is T =  0.230747847543697*t + 373.15\n",
        "Temperature profile as a function of x and t is T = 277.79 K, at face 1\n",
        "Temperature at face 2  = 387 K ,at face 2\n"
       ]
      }
     ],
     "prompt_number": 6
    }
   ],
   "metadata": {}
  }
 ]
}