{
 "metadata": {
  "name": "",
  "signature": "sha256:53f38691736e17bfc88c47ccfeb3fb1c72de31c9b0bf6a81cf8dd2ed8dca8405"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 7 : Ideal Gases"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.3  Page No : 125"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "from scipy.integrate import quad\n",
      "\n",
      "#Given\n",
      "P1 = 15.0;#initial pressure in Kgf/cm**2\n",
      "P2 = 1.0;#final pressure in Kgf/cm**2\n",
      "V1 = 0.012;#initial volume in m**3\n",
      "V2 = 0.06;#final volume in m**3\n",
      "T1 = 420.0;#initial temperature in K\n",
      "M = 28.0;#molecular weight of the gas\n",
      "Cp = 0.25;#specific heat at consmath.tant pressure in Kcal/Kg K\n",
      "R = 1.98;#gas consmath.tant in Kcal/Kg mole K\n",
      "R2 = 848.0;#gas consmath.tant in mKgf/Kgmole K\n",
      "#Cv = a+0.0005*T1; Specific heat at consmath.tant volume\n",
      "\n",
      "#To Calculate the final temperature of the ideal gas, work done in an open and closed system,internal energy change for the process\n",
      "#(a)Calculation of final temperature\n",
      "#Umath.sing ideal gas law:(P*V)/(R*T)\n",
      "T2 = (P2*V2*T1)/(P1*V1);\n",
      "print \"a)The final temperature is %d K\"%(T2);\n",
      "\n",
      "#(b)Calculation of work in an open and closed system\n",
      "#From equation 7.22(page no 147): P1*(V1**n)=P2*(V2**n)\n",
      "n = (math.log(P2/P1))/(math.log(V1/V2));\n",
      "#From equation 7.25(page no 149)\n",
      "W = ((P1*V1)-(P2*V2))/(n-1)*10**4;#work in mKgf\n",
      "W1 = W/427;#Work in Kcal\n",
      "print \" b)The work in a closed system is %f Kcal\"%(W1);\n",
      "Ws = n*W1;#from equation 7.28(page no 149)\n",
      "print \"    The work in an open system is %f Kcal\"%(Ws);\n",
      "\n",
      "#(c)Calculation of internal energy change\n",
      "R1 = R/M;#gas consmath.tant in Kcal/Kg\n",
      "Cv = Cp-R1;#specific heat at consmath.tant volume in Kcal/Kg K\n",
      "a = Cv-(0.0005*T1);\n",
      "m = (P1*10**4*V1*M)/(R2*T1);#mass of gas in Kg\n",
      "def y(T):\n",
      "    val = m*(a+(0.0005*T));\n",
      "    return val\n",
      "del_E = quad(y,T1,T2)[0];#internal energy change in Kcal/Kg\n",
      "del_E1 = M*del_E;#internal energy change in Kcal/Kgmole\n",
      "print \" c)The internal energy change for the process is %f Kcal/Kgmole\"%(del_E1);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "a)The final temperature is 140 K\n",
        " b)The work in a closed system is 4.117022 Kcal\n",
        "    The work in an open system is 6.927326 Kcal\n",
        " c)The internal energy change for the process is -121.245283 Kcal/Kgmole\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.5  Page No : 126"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "import numpy\n",
      "\n",
      "#Given\n",
      "P1 = 1.0;#Initial pressure of air in atm\n",
      "T1 = 15+273.0;#Initial temperature in K\n",
      "P2 = 5.0;#Final pressure of air in atm\n",
      "T2 = 15+273.0;#Final temperature in K\n",
      "Cv = 5.0;#specific heat of air at consmath.tant volume in Kcal/Kgmole K\n",
      "Cp = 7.0;#specific heat of air at consmath.tant pressure in Kcal/Kgmole K\n",
      "R = 0.082;#gas consmath.tant in atm-m**3/Kgmole K\n",
      "R1 = 2.0;#gas consmath.tant in Kcal/Kgmole K\n",
      "#From the P-V diagram given in page no 155:\n",
      "#Line 12 represents Isothermal process\n",
      "#Line b2,c2 & 1a represent Isometric process\n",
      "#Line a2 & 1c represent Isobaric process\n",
      "#Line 1b reprsent Adiabatic process\n",
      "\n",
      "#To find Approx Value\n",
      "def approx(V,n):\n",
      "    A=numpy.around([V*10**n])[0]/10**n;\n",
      "    return A\n",
      "\n",
      "#To Compute del_H, del_E, Q, W, del_S for the processes given above.\n",
      "#To indicate the quantities that are state functions \n",
      "#To verify that the work required in an isothermal process is less than that in an adiabatic process\n",
      "\n",
      "#Basis:1 Kgmole of air\n",
      "V1 = (R*T1)/P1;#Initial volume in cubic meter\n",
      "V2 = (R*T2)/P2;#Final volume in cubic meter\n",
      "\n",
      "#(i)Isothermal path 12\n",
      "#Equations 7.7 to 7.9 will be used (page no 145)\n",
      "del_E_12 = Cv*(T2-T1);\n",
      "del_H_12 = Cp*(T2-T1);\n",
      "W_12 = R1*T1*math.log(P1/P2);\n",
      "Q_12 = W_12;\n",
      "del_S_12 = approx((R1*math.log(P1/P2)),4);\n",
      "print \"i)For isothermal process or path 12 change in internal energy is %f\"%(del_E_12);\n",
      "print \"   For isothermal process or path 12 change in enthalpy is %f\"%(del_H_12);\n",
      "print \"   For isothermal process or path 12 heat released is %f Kcal\"%(Q_12);\n",
      "print \"   For isothermal process or path 12 work is %f Kcal\"%(W_12);\n",
      "print \"   For isothermal process or path 12 change in entropy is %f Kcal/Kgmole K\"%(del_S_12);\n",
      "\n",
      "#(ii)Path 1a2 = 1a(isometric)+a2(isobaric)\n",
      "#Equation 7.1 to 7.6 will be used (page no 144 & 145)\n",
      "Pa = P2;\n",
      "Ta = (Pa/P1)*T1;#in K\n",
      "Q_1a = Cv*(Ta-T1);\n",
      "del_E_1a = Q_1a;\n",
      "del_H_1a = Cp*(Ta-T1);\n",
      "W_1a = 0;# Consmath.tant volume process\n",
      "del_E_a2 = Cv*(T2-Ta);\n",
      "del_H_a2 = Cp*(T2-Ta);\n",
      "Q_a2 = del_H_a2;\n",
      "W_a2 = P2*(V2-V1)*((10**4*1.03)/427);\n",
      "del_H_1a2 = del_H_1a+del_H_a2;\n",
      "del_E_1a2 = del_E_1a+del_E_a2;\n",
      "Q_1a2 = Q_1a+Q_a2;\n",
      "W_1a2 = W_1a+W_a2;\n",
      "del_S_1a = Cv*math.log(Ta/T1);\n",
      "del_S_a2 = Cp*math.log(T2/Ta);\n",
      "del_S_1a2 = approx((del_S_1a+del_S_a2),4);\n",
      "print \"ii)For path 1a2 change in internal energy is %f\"%(del_E_1a2);\n",
      "print \"   For path 1a2 change in enthalpy is %f\"%(del_H_1a2);\n",
      "print \"   For path 1a2 heat released is %f Kcal\"%(Q_1a2);\n",
      "print \"   For path 1a2 work is %f Kcal\"%(W_1a2);\n",
      "print \"   For path 1a2 change in entropy is %f Kcal/Kgmole K\"%(del_S_1a2);\n",
      "\n",
      "#(iii)Path 1b2 = 1b(adiabatic)+b2(isometric)\n",
      "#From equation 7.11 (page no 146)\n",
      "y = Cp/Cv;\n",
      "Tb = T1*((V1/V2))**(y-1);\n",
      "#From equation 7.1 to 7.3,7.10 & 7.21,(page no 144,146,147)\n",
      "Q_1b = 0;#adiabatic process\n",
      "del_E_1b = Cv*(Tb-T1);\n",
      "del_H_1b = Cp*(Tb-T1);\n",
      "W_1b = -1*del_E_1b;\n",
      "Q_b2 = Cv*(T1-Tb);\n",
      "del_H_b2 = Cp*(T1-Tb);\n",
      "W_b2 = 0;#consmath.tant volume prcess\n",
      "del_E_b2 = Cv*(T2-Tb);\n",
      "del_H_1b2 = del_H_1b+del_H_b2;\n",
      "del_E_1b2 = del_E_1b+del_E_b2;\n",
      "W_1b2 = W_1b+W_b2;\n",
      "Q_1b2 = Q_1b+Q_b2;\n",
      "del_S_1b2 = approx((Cv*math.log(T1/Tb)),4);\n",
      "print \"iii)For path 1b2 change in internal energy is %f\"%(del_E_1b2);\n",
      "print \"   For path 1b2 change in enthalpy is %f\"%(del_H_1b2);\n",
      "print \"   For path 1b2 heat released is %f Kcal\"%(Q_1b2);\n",
      "print \"   For path 1b2 work is %f Kcal\"%(W_1b2);\n",
      "print \"   For path 1b2 change in entropy is %f Kcal/Kgmole K\"%(del_S_1b2);\n",
      "\n",
      "#(iv)Path 1c2 = 1c(isobaric)+c2(isometric);\n",
      "Pc = P1;\n",
      "Vc = V2;\n",
      "Tc = (Pc/P2)*T2;\n",
      "del_E_1c = Cv*(Tc-T1);\n",
      "Q_1c = Cp*(Tc-T1);\n",
      "del_H_1c = Q_1c;\n",
      "W_1c = P1*(Vc-V1)*((10**4*1.03)/427);\n",
      "del_E_c2 = Cv*(T2-Tc);\n",
      "Q_c2 = del_E_c2;\n",
      "del_H_c2 = Cp*(T2-Tc);\n",
      "W_c2 = 0.0;#consmath.tant volume process\n",
      "del_E_1c2 = del_E_1c+del_E_c2;\n",
      "del_H_1c2 = del_H_1c+del_H_c2;\n",
      "Q_1c2 = Q_1c+Q_c2;\n",
      "W_1c2 = W_1c+W_c2;\n",
      "del_S_1c = Cp*math.log(Tc/T1);\n",
      "del_S_c2 = Cv*math.log(T2/Tc);\n",
      "del_S_1c2 = approx((del_S_1c+del_S_c2),4);\n",
      "print \"iv)For path 1c2 change in internal energy is %f\"%(del_E_1c2);\n",
      "print \"   For path 1c2 change in enthalpy is %f\"%(del_H_1c2);\n",
      "print \"   For path 1c2 heat released is %f Kcal\"%(Q_1c2);\n",
      "print \"   For path 1c2 work is %f Kcal\"%(W_1c2);\n",
      "print \"   For path 1c2 change in entropy is %f Kcal/Kgmole K\"%(del_S_1c2);\n",
      "\n",
      "#Determination of state & path functions\n",
      "if((del_E_12 == del_E_1a2)&(del_E_12 == del_E_1b2)&(del_E_12 == del_E_1c2)):\n",
      "    print \" del_E is a state function\";\n",
      "else:\n",
      "    print \" del_E is a path function\";\n",
      "if((del_H_12 == del_H_1a2)&(del_H_12 == del_H_1b2)&(del_H_12 == del_H_1c2)):\n",
      "    print \" del_H is a state function\";\n",
      "else:\n",
      "    print \" del_H is a path function\";\n",
      "if(del_S_12 == del_S_1a2)&(del_S_12 == del_S_1b2)&(del_S_12 == del_S_1c2):\n",
      "    print \" del_S is a state function\";\n",
      "else:\n",
      "    print \" del_S is a path function\";\n",
      "if((Q_12 == Q_1a2)&(Q_12 == Q_1b2)&(Q_12 == Q_1c2)):\n",
      "    print \" Q is a state function\";\n",
      "else:\n",
      "    print \" Q is a path function\";\n",
      "if((W_12 == W_1a2)&(W_12 == W_1b2)&(W_12 == W_1c2)):\n",
      "    print \" W is a state function\";\n",
      "else:\n",
      "    print \" W is a path function\";\n",
      "\n",
      "#Comparison of work required by isothermal & adiabatic process\n",
      "if(-(W_12)<-(W_1b2)):\n",
      "    print \"  Work required by isothermal process is less than the work required by an adiabatic process\";\n",
      "else:\n",
      "    print \" Statement is incorrect\";\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i)For isothermal process or path 12 change in internal energy is 0.000000\n",
        "   For isothermal process or path 12 change in enthalpy is 0.000000\n",
        "   For isothermal process or path 12 heat released is -927.036238 Kcal\n",
        "   For isothermal process or path 12 work is -927.036238 Kcal\n",
        "   For isothermal process or path 12 change in entropy is -3.218900 Kcal/Kgmole K\n",
        "ii)For path 1a2 change in internal energy is 0.000000\n",
        "   For path 1a2 change in enthalpy is 0.000000\n",
        "   For path 1a2 heat released is -2304.000000 Kcal\n",
        "   For path 1a2 work is -2278.639813 Kcal\n",
        "   For path 1a2 change in entropy is -3.218900 Kcal/Kgmole K\n",
        "iii)For path 1b2 change in internal energy is 0.000000\n",
        "   For path 1b2 change in enthalpy is 0.000000\n",
        "   For path 1b2 heat released is -1301.261672 Kcal\n",
        "   For path 1b2 work is -1301.261672 Kcal\n",
        "   For path 1b2 change in entropy is -3.218900 Kcal/Kgmole K\n",
        "iv)For path 1c2 change in internal energy is 0.000000\n",
        "   For path 1c2 change in enthalpy is 0.000000\n",
        "   For path 1c2 heat released is -460.800000 Kcal\n",
        "   For path 1c2 work is -455.727963 Kcal\n",
        "   For path 1c2 change in entropy is -3.218900 Kcal/Kgmole K\n",
        " del_E is a state function\n",
        " del_H is a state function\n",
        " del_S is a state function\n",
        " Q is a path function\n",
        " W is a path function\n",
        "  Work required by isothermal process is less than the work required by an adiabatic process\n"
       ]
      }
     ],
     "prompt_number": 3
    }
   ],
   "metadata": {}
  }
 ]
}