{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

Quarter Waveplate

\n", "

\n", "The polarizing effect of a quarter plate by delaying the waves. \n", "(Runs rather slowly.)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": true }, "outputs": [ { "data": { "text/html": [ "

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "if (typeof Jupyter !== \"undefined\") { window.__context = { glowscript_container: $(\"#glowscript\").removeAttr(\"id\")};}else{ element.textContent = ' ';}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# QuarterWaveMod.ipynb: polarizing effect of quarter wave plate \n", "\n", "\"\"\"From \"COMPUTATIONAL PHYSICS\" & \"COMPUTER PROBLEMS in PHYSICS\" \n", "by RH Landau, MJ Paez, and CC Bordeianu (deceased). Copyright R Landau, \n", "Oregon State Unv, MJ Paez, Univ Antioquia, C Bordeianu (deceased), \n", "Univ Bucharest, 2020. Please respect copyright & acknowledge our work.\"\"\"\n", "\n", "% matplotlib inline\n", "\n", "from vpython import *\n", "import numpy as np\n", "\n", "xmax = 401; ymax = 100; zmax = 100\n", "scene = canvas(width = 800, height = 500,\n", " title = 'Ey : in cyan, Ex : in yellow. Propagation with periodic boundary conditions',\n", " forward = vec(-0.8,-0.3,-0.7),range = 300)\n", "Exfield = curve(color = color.yellow,radius = 1.5,display = scene)\n", "Eyfield = curve(color = color.cyan,radius = 1.5,display = scene)\n", "vplane = curve(pos = [(-xmax,ymax,0),(xmax,ymax,0),(xmax,-ymax,0),(-xmax,-ymax,0),\n", " (-xmax,ymax,0)],color = color.cyan)\n", "zaxis = curve(pos = [(-xmax,0,0),(xmax,0,0)],color = color.magenta)\n", "hplane = curve(pos = [(-xmax,0,zmax,0),(xmax,0,zmax,0),(xmax,0,-zmax,0),(-xmax,0,-zmax),\n", " (-xmax,0,zmax)],color = color.magenta)\n", "ball1 = sphere(pos = vec(xmax+30, 0,0), color = color.black, radius = 2) #for offset\n", "plate = box(pos = vec(-100,0,0),height = 2*zmax,width = 2*ymax,length = 0.5*xmax,\n", " color = vec(1.0,0.6,0.0),opacity = 0.4)\n", "ts = 2 # for old and new time\n", "beta = 0.01\n", "Ex = np.zeros((xmax,ts),float) # init E (gaussian), 201 points, ts = 0 old, ts = 1 new\n", "Ey = np.zeros((xmax,ts),float) \n", "Hx = np.zeros((xmax,ts),float)\n", "Hy = np.zeros((xmax,ts),float)\n", "Hyy = np.zeros((xmax,ts),float) # artificial field used left of plate\n", "Exx = np.zeros((xmax,ts),float) \n", "Eyy = np.zeros((xmax,ts),float) # used left of plate and boundary conds\n", "Hxx = np.zeros((xmax,ts),float) \n", "Exlabel1 = label( text = 'Ey', pos = vec(-xmax-10, 50,0), box = 0 )\n", "Exlabel2 = label( text = 'Ey', pos = vec(xmax+10, 50,0), box = 0 )\n", "Eylabel = label( text = 'Ex', pos = vec(-xmax-10, 0,50), box = 0 )\n", "zlabel = label( text = 'Z', pos = vec(xmax+10, 0,0), box = 0 ) #to shift figure\n", "polfield = arrow(display = scene)\n", "polfield2 = arrow(display = scene)\n", "ti = 0 # t = 0: initial position, t = 1. next time iteration" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [ "def inifields():\n", " kar = arange(xmax)\n", " phx = 0.5*np.pi\n", " Hyy[:xmax,0] = 0.1*np.cos(-2*np.pi*kar/100.0) # used for boundary conditions no plot\n", " Exx[:xmax,0] = 0.1*np.cos(-2*np.pi*kar/100.0) # used for bc and incident fields no plot\n", " Eyy[:xmax,0] = 0.1*np.cos(-2*np.pi*kar/100.0) # these fields are not plotted\n", " Hxx[:xmax,0] = 0.1*np.cos(-2*np.pi*kar/100.0) # not plotted\n", " Ey[:xmax,0] = 0.1*np.cos(-2*np.pi*kar/100.0)\n", " Hx[:xmax,0] = 0.1*np.cos(-2*np.pi*kar/100.0)\n", " \n", "def iniExHy():\n", " k = arange(101) \n", " Ex[:101,0] = 0.1*np.cos(-2*np.pi*k/100.0)\n", " Hy[:101,0] = 0.1*np.cos(-2*np.pi*k/100.0)\n", " kk = arange(101,202) # inside plate, delay lambda/4\n", " Ex[101:202,0] = 0.1*np.cos(-2*np.pi*kk/100.0-0.005*np.pi*(kk-101)) # pi/2 phase\n", " Hy[101:202,0] = 0.1*np.cos(-2*np.pi*kk/100.0-0.005*np.pi*(kk-101))\n", " kkk = arange(202,xmax) # after the plate, phase diff pi/2\n", " Ex[202:xmax,0] = 0.1*np.cos(-2*np.pi*kkk/100.0-0.5*np.pi)\n", " Hy[202:xmax,0] = 0.1*np.cos(-2*np.pi*kkk/100.0-0.5*np.pi)\n", "\n", " def plotfields(ti): # screen coordinates\n", " Exfield.clear()\n", " Eyfield.clear()\n", " for k in range(0,xmax):\n", " Exfield.append(pos = vec(2*k-xmax,800*Ey[k,ti],0))\n", " Exfield.visible = True \n", " Eyfield.append(pos = vec(2*k-xmax,0 ,800*Ex[k,ti] ))# world to screen coords.\n", " Eyfield.visible = True \n", " ti = 1\n", " \n", "inifields() #initial time\n", "iniExHy()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "deletable": true, "editable": true, "scrolled": true }, "outputs": [], "source": [ "# plot initial fields \n", "j = 0\n", "end = 0\n", "\n", "while end <5:\n", " #for nn in range(0,700):\n", " rate(3000) # Exx,Eyy,Hxx,Hyy unperturbed, sincronized fields\n", " Exx[1:xmax-1,1] = Exx[1:xmax-1,0] + beta*(Hyy[0:xmax-2,0]-Hyy[2:xmax,0]) # Maxwell Eq 1\n", " Eyy[1:xmax-1,1] = Eyy[1:xmax-1,0] + beta*(Hxx[0:xmax-2,0]-Hxx[2:xmax,0]) # Maxwell Eq 2\n", " Hyy[1:xmax-1,1] = Hyy[1:xmax-1,0] + beta*(Exx[0:xmax-2,0]-Exx[2:xmax,0]) # Maxwell Eq 2\n", " Hxx[1:xmax-1,1] = Hxx[1:xmax-1,0] + beta*(Eyy[0:xmax-2,0]-Eyy[2:xmax,0])\n", " Ex[1:xmax-1,1] = Ex[1:xmax-1,0] + beta*(Hy[0:xmax-2,0]-Hy[2:xmax,0]) # \n", " Ey[1:xmax-1,1] = Ey[1:xmax-1,0] + beta*(Hxx[0:xmax-2,0]-Hxx[2:xmax,0]) # unperturbed\n", " Hy[1:xmax-1,1] = Hy[1:xmax-1,0] + beta*(Ex[0:xmax-2,0]-Ex[2:xmax,0]) # Maxwell Eq 2 \n", " Hx[1:xmax-1,1] = Hx[1:xmax-1,0] + beta*(Eyy[0:xmax-2,0]-Eyy[2:xmax,0]) # unperturbed\n", " polfield.pos = vec(-280,0,0)\n", " polfield.axis = vec(0,700*Exx[60,1],700*Eyy[60,1])\n", " polfield2.pos = vec(380,0,0)\n", " polfield2.axis = vec(0,700*Ex[360,1],700*Ey[360,1]) \n", " Exx[0,1] = Exx[0,0] + beta*(Hyy[xmax-2,0]-Hyy[1,0]) #periodic boundary\n", " Eyy[0,1] = Eyy[0,0] + beta*(Hxx[xmax-2,0]-Hxx[1,0]) \n", " Hyy[0,1] = Hyy[0,0] + beta*(Exx[xmax-2,0]-Exx[1,0]) #periodic bond.cond x = 0 = 100\n", " Hxx[0,1] = Hxx[0,0] + beta*(Eyy[xmax-2,0]-Eyy[1,0]) \n", " Hyy[xmax-1,1] = Hyy[xmax-1,0]+ beta*(Exx[xmax-2,0]-Exx[1,0]) #last\n", " Hxx[xmax-1,1] = Hxx[xmax-1,0]+ beta*(Eyy[xmax-2,0]-Eyy[1,0]) #last\n", " Exx[xmax-1,1] = Exx[xmax-1,0]+ beta*(Hyy[xmax-2,0]-Hyy[1,0]) #conditions for first \n", " Eyy[xmax-1,1] = Eyy[xmax-1,0]+ beta*(Hxx[xmax-2,0]-Hxx[1,0])\n", " Ex[0,1] = Exx[0,0] + beta*(Hyy[xmax-2,0]-Hyy[1,0]) #periodic boundary\n", " Ey[0,1] = Eyy[0,0] + beta*(Hxx[xmax-2,0]-Hxx[1,0]) \n", " Hy[0,1] = Hyy[0,0] + beta*(Exx[xmax-2,0]-Exx[1,0]) #periodic bond.cond x = 0 = 100\n", " Hx[0,1] = Hxx[0,0] + beta*(Eyy[xmax-2,0]-Eyy[1,0]) \n", " Hy[xmax-1,1] = Hy[xmax-1,0]+ beta*(Ex[xmax-2,0]-Ex[xmax-100,0])\n", " Hx[xmax-1,1] = Hx[xmax-1,0]+ beta*(Ey[xmax-2,0]-Ey[1,0]) #last\n", " Ex[xmax-1,1] = Ex[xmax-1,0]+ beta*(Hy[xmax-2,0]-Hy[xmax-100,0])\n", " Ey[xmax-1,1] = Ey[xmax-1,0]+ beta*(Hxx[xmax-2,0]-Hxx[1,0])\n", " if j%6 == 0:\n", " plotfields(0) # plot fields after\n", " k = arange(101,202)\n", " Ex[101:202,1] = 0.1*np.cos(-2*np.pi*k/100-0.005*np.pi*(k-101)+2*np.pi*j/4996.004)\n", " Hy[101:202,1] = 0.1*np.cos(-2*np.pi*k/100-0.005*np.pi*(k-101)+2*np.pi*j/4996.004)\n", " Exx[:xmax,0] = Exx[:xmax,1] # for next iteration in time\n", " Eyy[:xmax,0] = Eyy[:xmax,1]\n", " Hyy[:xmax,0] = Hyy[:xmax,1] # old field = new field\n", " Hxx[:xmax,0] = Hxx[:xmax,1] \n", " Ex[:xmax,0] = Ex[:xmax,1] \n", " Ey[:xmax,0] = Ey[:xmax,1]\n", " Hx[:xmax,0] = Hx[:xmax,1]\n", " Hy[:xmax,0] = Hy[:xmax,1]\n", " \n", " if j%4996 == 0:\n", " j = 0\n", " end += 1\n", " j = j+1" ] } ], "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.13" } }, "nbformat": 4, "nbformat_minor": 2 }