{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 17 : Power System Synchronous Stability"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17.1, Page No 542"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "H=9.0\n",
      "G=20.0\t\t# machine Rating(MVA)\n",
      "KE=H*G\n",
      "\n",
      "#Calculations\n",
      "print(\"(a)K.E stored in the rotor =%.0f MJ  \" %KE)\n",
      "Pi=25000*.735\n",
      "PG=15000.0\n",
      "Pa=(Pi-PG)/(1000.0)\n",
      "f=50.0\n",
      "M=G*H/(math.pi*f)\n",
      "a=Pa/M\n",
      "print(\"(b) The accelerating power =%.3f MW \" %Pa)\n",
      "print(\"Acceleration =%.3f rad/sec_2\" %a)\n",
      "t=15.0/50\n",
      "dele=math.sqrt(5.89)*t/2\n",
      "Del=dele**2\n",
      "k=2.425*math.sqrt(Del)*60/4*math.pi\n",
      "speed=1504.2\n",
      "\n",
      "#Results\n",
      "print(\"(c)Rotor speed at the end of 15 cycles = %.1f r.p.m\" %speed)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)K.E stored in the rotor =180 MJ  \n",
        "(b) The accelerating power =3.375 MW \n",
        "Acceleration =2.945 rad/sec_2\n",
        "(c)Rotor speed at the end of 15 cycles = 1504.2 r.p.m\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17.2, Page No 545"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "V1=1.1\n",
      "V2=1\n",
      "X=.5\n",
      "cosdo=0.8\n",
      "G=1.0\n",
      "H=3.0\n",
      "f=50.0\n",
      "\n",
      "#Calculations\n",
      "M=G*H/(math.pi*f)\n",
      "dPe=V1*V2*cosdo/X\n",
      "fn=(((dPe)/M)**.5)/6.28\n",
      "sind0=0.75\n",
      "d0=math.degrees(math.asin(sind0))\n",
      "dPe2=V1*V2*math.cos(math.radians(d0))/X\n",
      "fn2=(((dPe2)/M)**.5)/6.28\n",
      "\n",
      "#Results\n",
      "print(\"(i)fn=%.2f Hz \" %fn)\n",
      "print(\"(i)fn(Hz)=%.2f Hz \" %fn2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(i)fn=1.53 Hz \n",
        "(i)fn(Hz)=1.39 Hz \n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17.3, Page No 551"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "a=0.25\t\t#sindo=.25\n",
      "do=math.degrees(math.asin(a))\t#\n",
      "b=0.5\t\t#sindc=.5\n",
      "\n",
      "#Calculations\n",
      "dc=math.degrees(math.asin(b))\n",
      "c=math.cos(math.radians(do))+.5*do*math.pi/180.0\n",
      "dm=dc\n",
      "e=1\n",
      "while e >.0001 :\n",
      "    dm=dm+.1\n",
      "    e=abs(c-(((.5*dm*math.pi)/180)+math.cos(math.radians(dm))))\n",
      "\t\n",
      "#Results\n",
      "print(\"dm approximately found to be %d degree\" %dm)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "dm approximately found to be 46 degree\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17.4 Page No 551"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "sindo=.5\n",
      "d0=math.degrees(math.asin(sindo))*math.pi/180.0\n",
      "r1=.2\n",
      "r2=.75\n",
      "\n",
      "#Calculations\n",
      "sindm=.5/.75\n",
      "d=math.degrees(math.asin(sindm))\n",
      "cosdm=math.cos(math.radians(d))\n",
      "dm=math.pi*(180-(math.degrees(math.asin(sindm))))/180\n",
      "Dc=((.5*(dm-d0))-(r2*cosdm)-(r1*math.cos(math.radians(d0))))/(r2-r1)\n",
      "dc=math.degrees(math.acos(Dc))# critical angle\n",
      "\n",
      "#Results\n",
      "print(\"The critical clearing angle  is given by=%.2f degrees\" %dc)#Answers don't match due to difference in rounding off of digits"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The critical clearing angle  is given by=70.33 degrees\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17.5, Page No 552"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "ZA=0.375\n",
      "ZB=0.35\n",
      "ZC=0.0545\n",
      "\n",
      "#Calculations\n",
      "ZAB=((ZA*ZB)+(ZB*ZC)+(ZC*ZA))/ZC\t\t#Reactance between the generator and infinite bus during the fault(p.u)\n",
      "Zgbf=complex(0.3)+ complex(0.55/2) + complex(.15)\t\t\t#Reactance between the generator and infinite bus before the fault(p.u)\n",
      "Zgb=complex(0.3)+ complex(0.55) + complex(.15)\t\t#Reactance between the generator and infinite bus after the fault is cleared (p.u)\n",
      "Pmaxo=1.2*1.0/abs(Zgbf)# Maximum power output Before the fault(p.u)\n",
      "Pmax1=1.2*1.0/abs(ZAB)# Maximum power output during the fault(p.u)\n",
      "Pmax2=1.2*1.0/abs(Zgb)# Maximum power output after the fault(p.u)\n",
      "r1=Pmax1/Pmaxo\n",
      "r2=Pmax2/Pmaxo\n",
      "Ps=1.0\n",
      "sindo=Ps/Pmaxo\n",
      "do=math.degrees(math.asin(sindo))\n",
      "d0=math.degrees(math.asin(sindo))*math.pi/180\n",
      "sindm=1/Pmax2\n",
      "cosdm=math.cos(math.radians((math.degrees(math.asin(sindm)))))\n",
      "Dm=math.pi*(180-(math.degrees(math.asin(sindm))))/180\n",
      "Dc=(((sindo*(Dm-d0))-(r2*cosdm))-(r1*math.cos(math.radians(do))))/(r2-r1)\n",
      "dc=math.degrees(math.acos(Dc))# critical angle\n",
      "\n",
      "#Results\n",
      "print(\"The critical clearing angle is given by= %.1f \" %dc)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The critical clearing angle is given by= 48.7 \n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17.6, Page No 558"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "Pm=complex(0.12) + complex(0.035) + ((complex(.25)*complex(0.3))/complex(0.55))\n",
      "Pm1=0\n",
      "Pm2=1.1*1/.405\n",
      "r1=0\n",
      "\n",
      "#Calculations\n",
      "r2=2.716/3.775\n",
      "d0=(math.degrees(math.asin(1/3.775)))\n",
      "dM=(180-math.degrees(math.asin(1/2.716)))\n",
      "do=d0*math.pi/180\n",
      "dm=dM*math.pi/180\n",
      "dc=math.degrees(math.acos((((dm-do)*math.sin(math.radians(d0)))-(r1*math.cos(math.radians(d0)))+(r2*math.cos(math.radians(dM))))/(r2-r1)))\n",
      "\n",
      "#Results\n",
      "print(\"dc=%.2f\" %dc)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "dc=90.61\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17.7 Page No 572"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "Pc=0\n",
      "V=0.98\n",
      "\n",
      "#Calculations\n",
      "Qc=V**2*((1/.4)-(1/1.1))/2\n",
      "R=V**2*((1/.4)+(1/1.1))/2\n",
      "Q=-(.98**2*((1.1-.4)/.44)/2) + (.98**2)*1.5/(2*.44)\n",
      "\n",
      "#Results\n",
      "print(\"(i)Q=%.2f MVAr\" %(abs(Q)*100))\n",
      "P=0.25\n",
      "Q2=-((1.637**2)-(.25**2))**.5 + .7639\n",
      "print(\"(ii)Q=%.4f p.u\" %Q2)\n",
      "Q3=-((1.637**2)-(.5**2))**.5 + .7639\n",
      "print(\"(iii)Q=%.4f p.u\" %Q3)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(i)Q=87.31 MVAr\n",
        "(ii)Q=-0.8539 p.u\n",
        "(iii)Q=-0.7949 p.u\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17.10 Page No 583"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "Pm=3.0\n",
      "r1Pm=1.2\n",
      "r2Pm=2\n",
      "H=3\n",
      "f=60\n",
      "Dt=.02\n",
      "Pe=1.5\n",
      "Do=math.degrees(math.asin(1.5/3))\n",
      "do=Do/57.33\n",
      "wo=0\n",
      "d=0\n",
      "K10=0\n",
      "\n",
      "#Calculations\n",
      "l10=62.83*(1.5-1.2*math.sin(do))*.02\n",
      "K20=(377.5574-376.992)*.02\n",
      "l20=62.83*(1.5-1.2*math.sin(do))*.02\n",
      "K30=(377.5574-376.992)*.02\n",
      "l30=62.83*(1.5-1.2*math.sin(.5296547))*.02\n",
      "K40=l30*0.02\n",
      "l40=62.83*(1.5-1.2*math.sin(.5353094))*.02\n",
      "d1=.53528\n",
      "Dwo=(3*1.13094+2*1.123045+1.115699)/6\n",
      "w1=wo+Dwo\n",
      "d1=.53528\n",
      "print(\"Runga-Kutta method-\\n\")\n",
      "print(\"w1=%.6f \\nd1=%.5f\\n\" %(w1,d1))\n",
      "d7=1.026\n",
      "w7=6.501\n",
      "wp=376.992+6.501\n",
      "K17=(wp-376.992)*0.02\n",
      "l17=62.83*(1.5-1.2*math.sin(1.026))*.02\n",
      "K27=(6.501+.297638)*0.02\n",
      "l27=62.83*(1.5-1.2*math.sin(1.09101))*.02\n",
      "K37=(6.501+.2736169)*0.02\n",
      "l37=62.83*(1.5-1.2*math.sin(1.0939863))*.02\n",
      "K47=(6.501+.545168)*0.02\n",
      "l47=62.83*(1.5-1.2*math.sin(1.16149))*.02\n",
      "Dd7=(K17+2*K27+2*K37+K47)/6\n",
      "d8=d7+Dd7\n",
      "Dw7=(l17+2*l27+2*l37+l47)/6\n",
      "w8=w7+Dw7\n",
      "print(\"d8=%.5f rad.\\nw8=%.4frad/sec\\n\\n\" %(d8,w8))\n",
      "print(\"using Euler`s Modified Method-\\n\")\n",
      "d0=0\n",
      "d10=.524\n",
      "w=62.83*(1.5-1.2*math.sin(.524))\n",
      "d11=d10+0\n",
      "w11=w*.02\n",
      "d=1.13094\n",
      "dav=(0+d)/2\n",
      "wav=(56.547+56.547)/2\n",
      "d01=.524+.56547*.02\n",
      "w11=0+56.547*0.02\n",
      "\n",
      "#Results\n",
      "print(\"d01=%.4f\\nw11=%.5f\" %(d01,w11))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Runga-Kutta method-\n",
        "\n",
        "w1=1.125768 \n",
        "d1=0.53528\n",
        "\n",
        "d8=1.16165 rad.\n",
        "w8=7.0479rad/sec\n",
        "\n",
        "\n",
        "using Euler`s Modified Method-\n",
        "\n",
        "d01=0.5353\n",
        "w11=1.13094\n"
       ]
      }
     ],
     "prompt_number": 8
    }
   ],
   "metadata": {}
  }
 ]
}