{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 2 Electric Fields"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.8.5 pgno:65"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum field =  4.20643156401 V/m per volt\n"
     ]
    }
   ],
   "source": [
    "#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",
    "\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*10**10)\n",
    "print\"Maximum field = \",E,\"V/m per volt\"\n",
    "#Answers vary due to round off error"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.8.6 pgno:66"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Part a\t\n",
      "Equivalent radius =  0.088741 m \n",
      "Charge per bundle = 0.000005 uC/m \n",
      "Charge per sunconducter = 0.000002 uC/m \n",
      "\tPart b\n",
      "\tSub part 1\t\n",
      "Maximum feild = 2607466.950170 V/m \t\n",
      "Maximum feild = 2412255.520745 V/m \t\n",
      "Maximum feild = 2509861.235457 V/m \t\n",
      "\tSub part 2\t\n",
      "EO1 = 2597956.835582 V/m \t\n",
      "EO2 = 2597429.477437 V/m \t\n",
      "EI1 = 2402709.212726 V/m \t\n",
      "EI2 = 2402258.056301 V/m \t\n",
      "\tPart c\t\n",
      "The average of the maximum gradient = 2597693.156510 V/m \t\n"
     ]
    }
   ],
   "source": [
    "#calculation based on figure 2.32\n",
    "from math import log\n",
    "from math import pi\n",
    "\n",
    "#(a)Charge on each bundle\n",
    "print\"Part a\\t\"\n",
    "req = (0.0175*0.45)**0.5\n",
    "print\"Equivalent radius =  %f m \"%req\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 = %f uC/m \"%Q #micro C/m\n",
    "print\"Charge per sunconducter = %f 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 = %f V/m \\t\"%MF\n",
    "MSF = (q/(2*pi*e0))*((1/r)-(1/R)) # maximum surface feild\n",
    "print\"Maximum feild = %f V/m \\t\"%MSF\n",
    "ASF = (q/(2*pi*e0))*(1/r) # Average surface feild\n",
    "print\"Maximum feild = %f V/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 = %f V/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 = %f V/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 = %f V/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 = %f V/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 = %f V/m \\t\"%Eavg\n",
    "\n",
    "\n",
    "#Answers might vary due to round off error"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.8.7 pgno:69"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Electric Feild = 30015596280.410564 V/m \t\n"
     ]
    }
   ],
   "source": [
    "#Electric feild induced at x\n",
    "from math import pi\n",
    "\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 = %f V/m \\t\"%E\n",
    "#Answers might vary due to round off error"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.8.8 pgno:70"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Thickness of graded design= 4.242641 cm \n",
      "Curve = 62.426407 cm**2 \n",
      "V1 = 47402.906725 cm**3 \n",
      "Thickness of regular design = 14.684289 cm \n",
      "V2 = 8619.450000 cm**3 \n"
     ]
    }
   ],
   "source": [
    "#Calculate the volume of the insulator\n",
    "#Thinkness of graded design\n",
    "from math import e\n",
    "from math import pi\n",
    "\n",
    "V = 150*(2)**0.5\n",
    "Ebd = 50\n",
    "T = V/Ebd\n",
    "print\"\\nThickness of graded design= %f 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 = %f cm**2 \"%zr\n",
    "#Volume of graded design V1\n",
    "V1 = 4*pi*zr*(zr-r)\n",
    "print\"V1 = %f 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 = %f cm \"%t\n",
    "#Volume of regular design V2\n",
    "V2 = pi*((2+t)**2-4)*10\n",
    "print\"V2 = %f cm**3 \"%round(V2,2)#unit not mentioned in textbook\n",
    " \n",
    "#Answers may vary due to round off error"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.8.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: \n",
      "[[   3.6568     -326.5       ]\n",
      " [-261.92857143    4.37537287]]\n"
     ]
    }
   ],
   "source": [
    "#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",
    "\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: \\n\",-Phi24\n",
    "#Answers may vary due to round of error  "
   ]
  }
 ],
 "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.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
