{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 2 Electric Fields"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2_5 pgno:65"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum field =  V/m per volt 42064315640.1\n"
     ]
    }
   ],
   "source": [
    "#Chapter 2, Example 5, page 65\n",
    "#Calculate the maximum field at the sphere surface\n",
    "#Calulating Field at surface E based on figure 2.31 and table 2.3\n",
    "from math import pi\n",
    "Q1 = 0.25\n",
    "e0 = 8.85418*10**-12 #Epselon nought\n",
    "RV1= ((1/0.25**2)+(0.067/(0.25-0.067)**2)+(0.0048/(0.25-0.067)**2))\n",
    "RV2= ((0.25+0.01795+0.00128)/(0.75-0.067)**2)\n",
    "RV= RV1+RV2\n",
    "E = (Q1*RV)/(4*pi*e0)\n",
    "print\"Maximum field =  V/m per volt\",E\n",
    "\n",
    "#Answers vary due to round off error\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2_6 pgno:66"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#Chapter 2, Exmaple 6, page 66\n",
    "#calculation based on figure 2.32\n",
    "\n",
    "#(a)Charge on each bundle\n",
    "print\"Part a\\t\"\n",
    "req = (0.0175*0.45)**0.5\n",
    "print\"Equivalent radius =  m \", req\n",
    "from math import log\n",
    "from math import pi\n",
    "V = 400*10**3 #Voltage\n",
    "H = 12. #bundle height in m\n",
    "d = 9. #pole to pole spacing in m\n",
    "e0 = 8.85418*10**-12 #Epselon nought\n",
    "Hd = ((2*H)**2+d**2)**0.5#2*H**2 + d**2\n",
    "Q = V*2*pi*e0/(log((2*H/req))-log((Hd/d)))\n",
    "q = Q/2\n",
    "print\"Charge per bundle =  uC/m \",Q #micro C/m\n",
    "print\"Charge per sunconducter =  uC/m \",q #micro C/m\n",
    "\n",
    "#(b part i)Maximim & average surface feild\n",
    "print\"\\tPart b\"\n",
    "print\"\\tSub part 1\\t\"\n",
    "r = 0.0175 #subconductor radius\n",
    "R = 0.45 #conductor to subconductor spacing\n",
    "MF = (q/(2*pi*e0))*((1/r)+(1/R)) # maximum feild\n",
    "print\"Maximum feild =  kV/m \\t\",MF\n",
    "MSF = (q/(2*pi*e0))*((1/r)-(1/R)) # maximum surface feild\n",
    "print\"Maximum feild =  kV/m \\t\",MSF\n",
    "ASF = (q/(2*pi*e0))*(1/r) # Average surface feild\n",
    "print\"Maximum feild =  kV/m \\t\",ASF\n",
    "\n",
    "#(b part ii) Considering the two sunconductors on the left\n",
    "print\"\\tSub part 2\\t\"\n",
    "#field at the outer point of subconductor #1 \n",
    "drO1 = 1/(d+r)\n",
    "dRrO1 = 1/(d+R+r)\n",
    "EO1 =  MF -((q/(2*pi*e0))*(drO1+dRrO1))\n",
    "print\"EO1 =  kV/m \\t\",EO1\n",
    "#field at the outer point of subconductor #2 \n",
    "drO2 = 1/(d-r)\n",
    "dRrO2 = 1/(d-R-r)\n",
    "EO2 =  MF -((q/(2*pi*e0))*(dRrO2+drO2))\n",
    "print\"EO2 =  kV/m \\t\",EO2\n",
    "\n",
    "#field at the inner point of subconductor #1 \n",
    "drI1 = 1/(d-r)\n",
    "dRrI1 = 1/(d+R-r)\n",
    "EI1 =  MSF -((q/(2*pi*e0))*(drI1+dRrI1))\n",
    "print\"EI1 =  kV/m \\t\",EI1\n",
    "#field at the inner point of subconductor #2 \n",
    "drI2 = 1/(d+r)\n",
    "dRrI2 = 1/(d-R+r)\n",
    "EI2 =  MSF -((q/(2*pi*e0))*(dRrI2+drI2)) \n",
    "print\"EI2 =  kV/m \\t\",EI2\n",
    "\n",
    "#(part c)Average of the maximim gradient\n",
    "print\"\\tPart c\\t\"\n",
    "Eavg = (EO1+EO2)/2\n",
    "print\"The average of the maximum gradient =  kV/m \\t\",Eavg\n",
    "\n",
    "\n",
    "#Answers might vary due to round off error\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2_7 pgno:69"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Electric Feild =  V/m \t30015596280.4\n"
     ]
    }
   ],
   "source": [
    "#Chapter 2, Exmaple 7, page 69\n",
    "#Electric feild induced at x\n",
    "from math import pi\n",
    "e0 = 8.85418*10**-12 #Epselon nought\n",
    "q = 1 # C/m\n",
    "C = (q/(2*pi*e0))\n",
    "#Based on figure 2.33\n",
    "E = C-(C*(1./3.+1./7.))+(C*(1+1./5.+1./9.))+(C*(1./5.+1./9.))-(C*(1./3.+1./7.))\n",
    "print\"Electric Feild =  V/m \\t\",E\n",
    "\n",
    "#Answers might vary due to round off error\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2_8 pgno:70"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Thickness of graded design=  cm  4.24264068712\n",
      "Curve =  cm**2  62.4264068712\n",
      "V1 =  cm**3  47402.906725\n",
      "Thickness of regular design =  cm  14.684289433\n",
      "V2 =  cm**3  861.944682812\n"
     ]
    }
   ],
   "source": [
    "#Chapter 2, Exmaple 8, page 70\n",
    "#Calculate the volume of the insulator\n",
    "#Thinkness of graded design\n",
    "from math import e\n",
    "from math import pi\n",
    "V = 150*(2)**0.5\n",
    "Ebd = 50\n",
    "T = V/Ebd\n",
    "print\"\\nThickness of graded design=  cm \",T\n",
    "#Based on figure 2.24\n",
    "r = 2 # radius of the conductor\n",
    "l = 10 #length of graded cylinder; The textbook uses 10 instead of 20\n",
    "zr = l*(T+r)\n",
    "print\"Curve =  cm**2 \",zr\n",
    "#Volume of graded design V1\n",
    "V1 = 4*pi*zr*(zr-r)\n",
    "print\"V1 =  cm**3 \",V1 #Unit is wrong in the textbook\n",
    "#Thickness of regular design as obtained form Eq.2.77\n",
    "pow = V/(2*Ebd)\n",
    "t = 2*(e**pow-1)\n",
    "print\"Thickness of regular design =  cm \",t\n",
    "#Volume of regular design V2\n",
    "V2 = pi*((2+t)**2-4)\n",
    "print\"V2 =  cm**3 \",V2#unit not mentioned in textbook\n",
    " \n",
    "#Answers may vary due to round off error\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2_11 pgno:75"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The values of Phi2 and Phi4 are: [[  -3.6568      326.5       ]\n",
      " [ 261.92857143   -4.37537287]]\n"
     ]
    }
   ],
   "source": [
    "#Chapter 2, Exmaple 11, page 75\n",
    "#Calculate the potential within the mesh\n",
    "#Based on figure 2.38(b)\n",
    "#equations are obtained using Eq.2.46\n",
    "import numpy\n",
    "from numpy import linalg\n",
    "A1 = 1/2*(0.54+0.16)\n",
    "A2 = 1/2*(0.91+0.14)\n",
    "S = numpy.matrix([[0.5571, -0.4571, -0.1],[-0.4751, 0.828, 0.3667],[-0.1, 0.667, 0.4667]])\n",
    "#By obtaining the elements of the global stiffness matrix(Sadiku,1994)\n",
    "#and by emplying the Eq.2.49(a)\n",
    "S1 = numpy.matrix([[1.25, -0.014],[-0.014, 0.8381]])\n",
    "S2 = numpy.matrix([[-0.7786, -0.4571],[-0.4571, -0.3667]])\n",
    "Phi13 = numpy.matrix([[0], [10]])\n",
    "val1 = S2*Phi13\n",
    "Phi24 = val1/S1\n",
    "print\"The values of Phi2 and Phi4 are:\",Phi24\n",
    "\n",
    "#Answers may vary due to round of error  \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "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
}