{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 2 - Systems"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1: pg 39"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 2.1\n",
      "The Change in total energy is, del_E (kJ) =  1100\n",
      "Since del_E is positive, so there is an increase in total energy\n",
      "There is mistake in the book's results unit\n"
     ]
    }
   ],
   "source": [
    "print 'Example 2.1'\n",
    "#calculate the Change in total energy\n",
    "\n",
    "#  Given values\n",
    "Q = 2500; # Heat transferred into the system, [kJ]\n",
    "W = 1400; #  Work transferred from the system,  [kJ]\n",
    "\n",
    "# solution\n",
    "\n",
    "#  since process carried out on a closed system, so using equation [4]\n",
    "del_E = Q-W; #  Change in total energy, [kJ]\n",
    "\n",
    "# results\n",
    "\n",
    "print 'The Change in total energy is, del_E (kJ) = ',del_E\n",
    "\n",
    "if del_E >= 0:\n",
    "    print 'Since del_E is positive, so there is an increase in total energy'\n",
    "else:\n",
    "    print 'Since del_E is negative, so there is an decrease in total energy'\n",
    "\n",
    "\n",
    "print \"There is mistake in the book's results unit\"\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2: pg 39"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 2.2\n",
      "The Heat transfer is, Q (kJ) =  -700.0\n",
      "Since Q < 0, so heat is transferred from the system\n"
     ]
    }
   ],
   "source": [
    "print 'Example 2.2'\n",
    "#calculate the heat transfer\n",
    "\n",
    "#  Given values\n",
    "del_E = 3500.; # Increase in total energy of the system, [kJ]\n",
    "W = -4200.; # Work transfer into the system, [kJ]\n",
    "\n",
    "# solution\n",
    "#  since process carried out on a closed system, so using equation [3]\n",
    "Q = del_E+W;# [kJ]\n",
    "\n",
    "# results\n",
    "print 'The Heat transfer is, Q (kJ) = ',Q\n",
    "\n",
    "if Q >=0:\n",
    "    print 'Since Q > 0, so heat is transferred into the system'\n",
    "else:\n",
    "    print 'Since Q < 0, so heat is transferred from the system'\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3: pg 40"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 2.3\n",
      "The Work done is, W (kJ/kg) =  250\n",
      "Since W > 0, so Work done by the engine per kilogram of working substance\n"
     ]
    }
   ],
   "source": [
    "print 'Example 2.3'\n",
    "#calculate the Work done\n",
    "\n",
    "\n",
    "#  Given values\n",
    "Q = -150; # Heat transferred out of the system, [kJ/kg]\n",
    "del_u = -400; # Internal energy decreased ,[kJ/kg]\n",
    "\n",
    "#  solution\n",
    "#  using equation [3],the non flow energy equation\n",
    "#  Q=del_u+W\n",
    "W = Q-del_u; #  [kJ/kg]\n",
    "\n",
    "# results\n",
    "print 'The Work done is, W (kJ/kg) = ',W\n",
    "\n",
    "if W >=0:\n",
    "      print 'Since W > 0, so Work done by the engine per kilogram of working substance'\n",
    "else:\n",
    "      print 'Since W < 0, so Work done on the engine per kilogram of working substance'\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4: pg 44"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 2.4\n",
      "workdone is, W (kJ/kg) =  550.6875\n",
      "Since W>0, so Power is output from the system\n",
      "The power output from the system is (kW) =  2202.75\n"
     ]
    }
   ],
   "source": [
    "print 'Example 2.4'\n",
    "#calculate the power output and workdone\n",
    "#  Given values\n",
    "m_dot = 4.; #  fluid flow rate, [kg/s]\n",
    "Q = -40.;  #  Heat loss to the surrounding, [kJ/kg]\n",
    "\n",
    "#  At inlet \n",
    "P1 = 600.;  # pressure  ,[kn/m**2]\n",
    "C1 = 220.;  # velocity  ,[m/s]\n",
    "u1 = 2200.;  # internal energy,  [kJ/kg]\n",
    "v1 = .42; # specific volume, [m**3/kg]\n",
    "\n",
    "#  At outlet\n",
    "P2 = 150.; # pressure, [kN/m**2]\n",
    "C2 = 145.;  # velocity,  [m/s]\n",
    "u2 = 1650.;  # internal energy,  [kJ/kg]\n",
    "v2 = 1.5;  # specific volume,  [m**3/kg]\n",
    "\n",
    "#  solution\n",
    "#  for steady flow energy equation for the open system is given by\n",
    "#  u1+P1*v1+C1**2/2+Q=u2+P2*v2+C2**2/2+W\n",
    "#  hence\n",
    "\n",
    "W = (u1-u2)+(P1*v1-P2*v2)+(C1**2/2-C2**2/2)*10**-3+Q; # [kJ/kg]\n",
    "\n",
    "P_out = W*m_dot; # power out put from the system, [kW]\n",
    "\n",
    "# results\n",
    "print 'workdone is, W (kJ/kg) = ',W\n",
    "\n",
    "if W >= 0:\n",
    "      print 'Since W>0, so Power is output from the system'\n",
    "else:\n",
    "      print 'Since W<0, so Power is input to the system'\n",
    "\n",
    "#  Hence\n",
    "\n",
    "print 'The power output from the system is (kW) = ',P_out\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5: pg 45"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 2.5\n",
      "The temperature rise of the lead is (C) =  104.6\n"
     ]
    }
   ],
   "source": [
    "print 'Example 2.5'\n",
    "#calculate the temperature rise\n",
    "\n",
    "\n",
    "#  Given values\n",
    "del_P = 154.45; # pressure difference across the die, [MN/m**2]\n",
    "rho = 11360.; # Density of the lead, [kg/m**3]\n",
    "c = 130; # specific heat capacity of the lead, [J/kg*K]\n",
    "\n",
    "#  solution\n",
    "#  since there is no cooling and no externel work is done, so energy balane becomes\n",
    "#  P1*V1+U1=P2*V2+U2 ,so\n",
    "#  del_U=U2-U1=P1*V1-P2*V2\n",
    "\n",
    "#  also, for temperature rise, del_U=m*c*t, where, m is mass; c is specific heat capacity; and t is temperature rise\n",
    "\n",
    "#  Also given that lead is incompressible, so V1=V2=V and assuming one m**3 of lead\n",
    "\n",
    "#  using above equations\n",
    "t = del_P/(rho*c)*10**6 ;# temperature rise [C]\n",
    "\n",
    "# results \n",
    "print 'The temperature rise of the lead is (C) = ',round(t,1)\n",
    "\n",
    "#  End\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6: pg 46"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 2.6\n",
      "(a) The inlet area is, A1 (m^2) =  0.0425\n",
      "(b) The exit velocity is, C2 (m/s) =  171.71\n",
      "(c) The power developed by the turbine system is (kW) =  671.88\n"
     ]
    }
   ],
   "source": [
    "print 'Example 2.6'\n",
    "#calculate the power developed, exit velocity and inlet area\n",
    "\n",
    "#  Given values\n",
    "m_dot = 4.5; # mass flow rate of air, [kg/s]\n",
    "Q = -40.; # Heat transfer loss, [kJ/kg]\n",
    "del_h = -200.; # specific enthalpy reduce, [kJ/kg]\n",
    "\n",
    "C1 = 90; # inlet velocity, [m/s]\n",
    "v1 = .85; # inlet specific volume, [m**3/kg]\n",
    "\n",
    "v2 = 1.45; #  exit specific volume, [m**3/kg]\n",
    "A2 = .038;  #  exit area of turbine, [m**2]\n",
    "\n",
    "#  solution\n",
    "\n",
    "#  part (a)\n",
    "#  At inlet, by equation[4], m_dot=A1*C1/v1\n",
    "A1 = m_dot*v1/C1;#inlet area, [m**2]\n",
    "print '(a) The inlet area is, A1 (m^2) = ',A1\n",
    "\n",
    "#  part (b), \n",
    "#  At outlet, since mass flow rate is same, so m_dot=A2*C2/v2, hence\n",
    "C2 = m_dot*v2/A2; # Exit velocity,[m/s]\n",
    "print '(b) The exit velocity is, C2 (m/s) = ',round(C2,2)\n",
    "\n",
    "#  part (c)\n",
    "#  using steady flow equation, h1+C1**2/2+Q=h2+C2**2/2+W\n",
    "W = -del_h+(C1**2/2-C2**2/2)*10**-3+Q; #  [kJ/kg]\n",
    "\n",
    "#  Hence power developed is\n",
    "P = W*m_dot;#  [kW]\n",
    "print '(c) The power developed by the turbine system is (kW) = ',round(P,2)\n",
    "\n",
    "#  End\n",
    "\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.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}