{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 1 - General Introduction"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1: pg 11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 1.1\n",
      "The Work done is (MJ) =  0.98\n"
     ]
    }
   ],
   "source": [
    "#pg 11\n",
    "#calculate the work done\n",
    "print 'Example 1.1'\n",
    "\n",
    "# Given values\n",
    "P = 700.;   #pressure,[kN/m**2]\n",
    "V1 = .28;   #initial volume,[m**3]\n",
    "V2 = 1.68;   #final volume,[m**3]\n",
    "\n",
    "#solution\n",
    "\n",
    "W = P*(V2-V1);# # Formula for work done at constant pressure is, [kJ]\n",
    "\n",
    "#results\n",
    "print 'The Work done is (MJ) = ',W*10**-3\n",
    "\n",
    "#End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2: pg 13"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 1.2\n",
      "The new volume of the gas is (m^3) =  0.0355\n"
     ]
    }
   ],
   "source": [
    "#pg 13\n",
    "#calculate the new volume\n",
    "print 'Example 1.2'\n",
    "\n",
    "#Given values\n",
    "P1 = 138.;  # initial pressure,[kN/m**2]\n",
    "V1 = .112;  #initial volume,[m**3]\n",
    "P2 = 690; #  final pressure,[kN/m**2]\n",
    "Gama=1.4; #  heat capacity ratio\n",
    "\n",
    "#  solution\n",
    "\n",
    "#  since gas is following, PV**1.4=constant,hence\n",
    "\n",
    "V2 =V1*(P1/P2)**(1/Gama); #   final volume, [m**3] \n",
    "\n",
    "#results\n",
    "print 'The new volume of the gas is (m^3) = ',round(V2,4)\n",
    "\n",
    "#End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3: pg 15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 1.3\n",
      "Final Volume (m^3) =  0.077\n",
      "The Work done by gas during expansion is (kJ) =  37.2\n"
     ]
    }
   ],
   "source": [
    "#pg 15\n",
    "#calculate the work done by gas\n",
    "print 'Example 1.3'\n",
    "\n",
    "# Given values\n",
    "P1 = 2070;  #  initial pressure,  [kN/m^2]\n",
    "V1 = .014;  #  initial volume,  [m^3]\n",
    "P2 = 207.;  #  final pressure, [kN/m^2]\n",
    "n=1.35;  #  polytropic index\n",
    "\n",
    "#  solution\n",
    "\n",
    "#  since gas is following PV^n=constant\n",
    "#  hence \n",
    "\n",
    "V2 = V1*(P1/P2)**(1/n);  # final volume,  [m^3]\n",
    "\n",
    "#  calculation of workdone\n",
    "\n",
    "W=(P1*V1-P2*V2)/(1.35-1);  # using work done formula for polytropic process, [kJ]\n",
    "\n",
    "#results\n",
    "print 'Final Volume (m^3) = ',round(V2,3)\n",
    "print 'The Work done by gas during expansion is (kJ) = ',round(W,1)\n",
    "\n",
    "#End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4: pg 17"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 1.4\n",
      " The final pressure (kN/m^2) =  800.0\n",
      " Work done on the gas (kJ) =  -11.64\n"
     ]
    }
   ],
   "source": [
    "#pg 17\n",
    "#calculate the final pressure and work done\n",
    "print 'Example 1.4'\n",
    "import math\n",
    "\n",
    "#  Given values\n",
    "P1 = 100;  #  initial pressure, [kN/m^2]\n",
    "V1 = .056;  #  initial volume,  [m^3]\n",
    "V2 = .007;  #  final volume,  [m^3]\n",
    "\n",
    "#  To know  P2\n",
    "#  since process is hyperbolic so, PV=constant\n",
    "#  hence\n",
    "\n",
    "P2 = P1*V1/V2;  #  final pressure, [kN/m^2]\n",
    "\n",
    "# calculation of workdone\n",
    "W = P1*V1*math.log(V2/V1); #  formula for work done in this process, [kJ]\n",
    "\n",
    "#results\n",
    "print ' The final pressure (kN/m^2) = ',P2\n",
    "print ' Work done on the gas (kJ) = ',round(W,2)\n",
    "\n",
    "#End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5: pg 21"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 1.5\n",
      "The heat required (kJ) =  191.25\n"
     ]
    }
   ],
   "source": [
    "#pg 21\n",
    "#calculate the heat required\n",
    "print 'Example 1.5'\n",
    "\n",
    "#  Given values\n",
    "m = 5.; #  mass,  [kg]\n",
    "t1 = 15.; #  inital temperature, [C]\n",
    "t2 = 100.; #  final temperature, [C]\n",
    "c = 450.; #  specific heat capacity, [J/kg K]\n",
    "\n",
    "#  solution\n",
    "\n",
    "#  using heat transfer equation,[1]\n",
    "Q = m*c*(t2-t1); #  [J]\n",
    "#results\n",
    "print 'The heat required (kJ) = ',round(Q*10**-3,2)\n",
    "\n",
    "#End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6: pg 22"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 1.6\n",
      "Required heat transfer to accomplish the change (kJ) =  1814.4\n"
     ]
    }
   ],
   "source": [
    "#pg 22\n",
    "print 'Example 1.6'\n",
    "\n",
    "#Calculate the required heat transfer \n",
    "#  Given values\n",
    "m_cop = 2.; #  mass of copper vessel, [kg]\n",
    "m_wat = 6.; #  mass of water, [kg]\n",
    "c_wat = 4.19; #  specific heat capacity of water,  [kJ/kg K]\n",
    "\n",
    "t1 = 20.; #  initial temperature, [C]\n",
    "t2 = 90.; #  final temperature, [C]\n",
    "\n",
    "# From the table of average specific heat capacities\n",
    "c_cop = .390;  # specific heat capacity of copper,[kJ/kg k]\n",
    "\n",
    "# solution\n",
    "Q_cop = m_cop*c_cop*(t2-t1); #  heat required by copper vessel, [kJ]\n",
    "\n",
    "Q_wat = m_wat*c_wat*(t2-t1); #  heat required by water, [kJ]\n",
    "\n",
    "# since there is no heat loss,so total heat transfer is sum of both\n",
    "Q_total = Q_cop+Q_wat ; #  [kJ]\n",
    "\n",
    "#results\n",
    "print 'Required heat transfer to accomplish the change (kJ) = ',Q_total\n",
    "\n",
    "#End"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7: pg 22"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 1.7\n",
      "The final temperature is  (C) =  56.9\n"
     ]
    }
   ],
   "source": [
    "#pg 22\n",
    "print('Example 1.7');\n",
    "#calculate the final temperature\n",
    "\n",
    "#  Given values\n",
    "m = 10.; #  mass of iron casting, [kg]\n",
    "t1 = 200.; #  initial temperature, [C]\n",
    "Q = -715.5; #  [kJ], since heat is lost in this process\n",
    "\n",
    "# From the table of average specific heat capacities\n",
    "c = .50; #  specific heat capacity of casting iron, [kJ/kg K]\n",
    "\n",
    "#  solution\n",
    "#  using heat equation\n",
    "#  Q = m*c*(t2-t1)\n",
    "\n",
    "t2 = t1+Q/(m*c); # [C]\n",
    "\n",
    "#results\n",
    "print 'The final temperature is  (C) = ',t2\n",
    "\n",
    "# End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8: pg 23"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 1.8\n",
      "The specific heat capacity of the liquid is  (kJ/kg K) =  2.1\n"
     ]
    }
   ],
   "source": [
    "#pg 23\n",
    "#calculate the specific heat capacity\n",
    "print('Example 1.8');\n",
    "# Given values\n",
    "m = 4.; #  mass of the liquid, [kg]\n",
    "t1 = 15.; #  initial temperature, [C]\n",
    "t2 = 100.; #  final temperature, [C]\n",
    "Q = 714.; #  [kJ],required heat to accomplish this change\n",
    "\n",
    "#  solution\n",
    "#  using heat equation\n",
    "#  Q=m*c*(t2-t1)\n",
    "\n",
    "#  calculation of c\n",
    "c=Q/(m*(t2-t1)); #  heat capacity, [kJ/kg K] \n",
    "\n",
    "#results\n",
    "print 'The specific heat capacity of the liquid is  (kJ/kg K) = ',c\n",
    "\n",
    "#End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 9: pg 27"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 1.9\n",
      "The power output of the engine is  (kJ) =  48.7\n",
      "The energy rejected by the engine is (MJ/min) =  11.7\n"
     ]
    }
   ],
   "source": [
    "#pg 27\n",
    "#calculate the energy rejected by the engine\n",
    "print('Example 1.9');\n",
    "\n",
    "\n",
    "#  Given values\n",
    "m_dot = 20.4; #  mass flowrate of petrol, [kg/h]\n",
    "c = 43.; #  calorific  value of petrol, [MJ/kg]\n",
    "n = .2; #  Thermal efficiency of engine\n",
    "\n",
    "#  solution\n",
    "m_dot = 20.4/3600; # [kg/s]\n",
    "c = 43*10**6; #  [J/kg]\n",
    "\n",
    "#  power output\n",
    "P_out = n*m_dot*c; #  [W]\n",
    "\n",
    " \n",
    "#  power rejected\n",
    "\n",
    "P_rej = m_dot*c*(1-n); #  [W]\n",
    "P_rej = P_rej*60*10**-6; #  [MJ/min]\n",
    "\n",
    "#results\n",
    "print 'The power output of the engine is  (kJ) = ',round(P_out*10**-3,1)\n",
    "print 'The energy rejected by the engine is (MJ/min) = ',round(P_rej,1)\n",
    "\n",
    "#End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10: pg 28"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 1.10\n",
      "Thermal efficiency of the plant =  0.173\n"
     ]
    }
   ],
   "source": [
    "#pg 28\n",
    "print('Example 1.10');\n",
    "#calculate the thermal efficiency\n",
    "\n",
    "\n",
    "#  Given values\n",
    "m_dot = 3.045; #  use of coal, [tonne/h]\n",
    "c = 28; # calorific value of the coal, [MJ/kg]\n",
    "P_out = 4.1; #  output of turbine, [MW]\n",
    "\n",
    "#  solution\n",
    "m_dot = m_dot*10**3/3600; # [kg/s]\n",
    "\n",
    "P_in = m_dot*c; #  power input by coal, [MW]\n",
    "\n",
    "n = P_out/P_in; #  thermal efficiency formula\n",
    "\n",
    "#results\n",
    "print 'Thermal efficiency of the plant = ',round(n,3)\n",
    "\n",
    "#End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11: pg 29"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 1.11\n",
      "The power output of the engine (kW) =  12.5\n"
     ]
    }
   ],
   "source": [
    "#pg 29\n",
    "#calculate the power output of the engine\n",
    "print('Example 1.11');\n",
    "\n",
    "\n",
    "#  Given values\n",
    "v = 50.; #  speed, [km/h]\n",
    "F = 900.; #  Resistance to the motion of a car\n",
    "\n",
    "#  solution\n",
    "v = v*10**3/3600; #  [m/s]\n",
    "Power = F*v; #  Power formula, [W]\n",
    "\n",
    "print 'The power output of the engine (kW) = ',Power*10**-3\n",
    " \n",
    "#  End"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 12: pg 31"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 1.12\n",
      "The power output from the engine (kW) =  15.79\n"
     ]
    }
   ],
   "source": [
    "#pg 31\n",
    "#calculate the power output from the engine\n",
    "\n",
    "print('Example 1.12');\n",
    "\n",
    "#  Given values\n",
    "V = 230.; #  volatage, [volts]\n",
    "I = 60.; #  current, [amps]\n",
    "n_gen = .95; #  efficiency of generator\n",
    "n_eng = .92; #  efficiency of engine\n",
    "\n",
    "#  solution\n",
    "\n",
    "P_gen = V*I; #  Power delivered by generator, [W]\n",
    "P_gen=P_gen*10**-3; #  [kW]\n",
    "\n",
    "P_in_eng=P_gen/n_gen;#Power input from engine,[kW]\n",
    "\n",
    "P_out_eng=P_in_eng/n_eng;#Power output from engine,[kW]\n",
    "\n",
    "#results\n",
    "print 'The power output from the engine (kW) = ',round(P_out_eng,2)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 13: pg 32"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 1.13\n",
      "The current taken by heater (amps) =  17.4\n"
     ]
    }
   ],
   "source": [
    "#pg 32\n",
    "#calculate the current taken by heater\n",
    "print('Example 1.13');\n",
    "\n",
    "\n",
    "\n",
    "#  Given values\n",
    "V = 230.; # Voltage, [volts]\n",
    "W = 4.; #  Power of heater, [kW]\n",
    "\n",
    "#  solution\n",
    "\n",
    "#  using equation P=VI\n",
    "I = W/V; #  current, [K amps]\n",
    "#results\n",
    "print 'The current taken by heater (amps) = ',round(I*10**3,1)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 14: pg 32"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 1.14\n",
      "Mass of coal burnt by the power station in 1 hour (tonne) =  218.0\n"
     ]
    }
   ],
   "source": [
    "#pg 32\n",
    "#calculate the mass of coal burnt\n",
    "print('Example 1.14');\n",
    "\n",
    "#  Given values\n",
    "P_out = 500.; #  output of power station, [MW]\n",
    "c = 29.5; #  calorific value of coal, [MJ/kg]\n",
    "r=.28; \n",
    "\n",
    "#  solution\n",
    "\n",
    "#  since P represents only 28 percent of energy available from coal\n",
    "P_coal = P_out/r; #  [MW]\n",
    " \n",
    "m_coal = P_coal/c; #  Mass of coal used, [kg/s]\n",
    "m_coal = m_coal*3600; #  [kg/h]\n",
    "\n",
    "#After one hour\n",
    "m_coal = m_coal*1*10**-3; #  [tonne]\n",
    "#results\n",
    "print 'Mass of coal burnt by the power station in 1 hour (tonne) = ',round(m_coal,0)\n",
    "\n",
    "#  End\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
}