{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Electromagnetism" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*Running Sage Math and sagemanifolds with jupyter notebooks tip*: First, I've found that compiling from the github source the development Sage Math version (see my notes on this under the \"Computers\" section of my [wordpress blog](https://ernestyalumni.wordpress.com)) works with sagemanifolds and either installing sagemanifolds into the binary that you unpack out (the click, download, double click), \"breaks\" Sage and so that it doesn't run. Also, following the Sage Math instructions on their website for building from the source didn't work for me (!!!???). \n", "\n", "As a tip on how to run this jupyter notebook and have sagemanifolds available, you'd want to be in the working directory you desire (e.g. `Propulsion/EM`). But yet your Sage Math build is somewhere else (e.g. `/home/topolo/Public/sage`). Do this out of the working directory you're currently working out of:\n", "`/home/topolo/Public/sage/sage -n jupyter`\n", "\n", "For the rationale, or the math, and how the math corresponds directly to the Sage Math code here, you're going to want to look at [Gravity_Notes_grande.pdf](https://github.com/ernestyalumni/Gravite/blob/master/LaTeXetpdfs/Gravity_Notes_grande.pdf) in my Gravite repository, and in there, the $\\mathbb{R}^3$ section, because I define the charts and atlases for Euclidean space $\\mathbb{R}^3$ as a *smooth manifold*. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "%display latex" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "M = Manifold(4,'M',r'M')\n", "cart_ch = M.chart('t x y z')\n", "U = M.open_subset('U',coord_def={cart_ch: (cart_ch[1]<0, cart_ch[2]!=0)})\n", "cart_ch_U = cart_ch.restrict(U)\n", "sph_ch = U.chart(r't:(-oo,oo):t rh:(0,+oo):\\rho th:(0,pi):\\theta ph:(0,2*pi):\\phi')\n", "t, rh,th,ph = [sph_ch[i[0]] for i in M.index_generator(1)]\n", "transit_sph_to_cart = sph_ch.transition_map(cart_ch_U, \n", " [t,rh*sin(th)*cos(ph),rh*sin(th)*sin(ph),rh*cos(th)])\n", "Sphnorm = sqrt(sum([cart_ch_U[i]**2 for i in range(1,4)]))\n", "transit_sph_to_cart.set_inverse( cart_ch[0], Sphnorm, \n", " atan2(sqrt( sum([ cart_ch_U[i]**2 for i in range(1,3)])),cart_ch_U[3]),\n", " atan2(cart_ch_U[2],cart_ch_U[1]))\n", "cyl_ch = U.chart(r't:(-oo,oo):t r:(0,+oo) phi:(0,2*pi):\\phi z:(-oo,oo):z')\n", "t, r,phi,z = [cyl_ch[i[0]] for i in M.index_generator(1)]\n", "transit_cyl_to_cart = cyl_ch.transition_map(cart_ch_U, [t,r*cos(phi),r*sin(phi),z])\n", "transit_cyl_to_cart.set_inverse(cart_ch_U[0], sqrt(cart_ch_U[1]**2+cart_ch_U[2]**2), \n", " atan2( cart_ch_U[2],cart_ch_U[1]), cart_ch_U[3])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note the mostly positive (-+++) convention I use for the Minkowski metric." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "g = M.lorentzian_metric('g')\n", "g[0,0] = -1 \n", "for i in range(1,4): g[i,i] = 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Electric Field" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def make_E(ch):\n", " \"\"\"\n", " make_E = make_E(ch)\n", " make_E creates a time-INDEPENDENT electric field as a 1-form\n", " \n", " INPUT/PARAMETER\n", " ch = sagemanifold chart\n", " \"\"\"\n", " Ecomplst = []\n", " for i in range(1,4):\n", " Earglst = ['E'+str(i),] + list(ch[1:])\n", " Ecomplst.append( function(Earglst[0])(*Earglst[1:]) )\n", " Ecomplst = [0,]+Ecomplst\n", " E = ch.domain().diff_form(1)\n", " E[ch.frame(),:,ch] = Ecomplst\n", " return E\n", "\n", "def make_Et(ch):\n", " \"\"\"\n", " make_Et = make_Et(ch)\n", " make_Et creates a time-DEPENDENT electric field as a 1-form\n", " \n", " INPUT/PARAMETER\n", " ch = sagemanifold chart\n", " \"\"\"\n", " Ecomplst = []\n", " for i in range(1,4):\n", " Earglst = ['E'+str(i),] + list(ch[:])\n", " Ecomplst.append( function(Earglst[0])(*Earglst[1:]) )\n", " Ecomplst = [0,]+Ecomplst\n", " E = ch.domain().diff_form(1)\n", " E[ch.frame(),:,ch] = Ecomplst\n", " return E" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Examples of using `make_E`, `make_Et` and displaying the results" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "E1(x, y, z) dx + E2(x, y, z) dy + E3(x, y, z) dz\n" ] }, { "data": { "text/html": [ "" ], "text/plain": [ "E1(t, rh, th, ph) drh + E2(t, rh, th, ph) dth + E3(t, rh, th, ph) dph" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "print make_E(cart_ch).display()\n", "make_Et(sph_ch).display(sph_ch.frame(),sph_ch)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Magnetic Field" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Programming note: `make_B` and `make_Bt` " ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def make_B(ch):\n", " \"\"\"\n", " make_B = make_B(ch)\n", " make_B creates a time-INDEPENDENT magnetic field as a 2-form\n", " \n", " INPUT/PARAMETER\n", " ch = sagemanifold chart\n", " \"\"\"\n", " B = ch.domain().diff_form(2)\n", " farglst = list(ch[1:]) # function argument list, e.g. (x,y,z)\n", "\n", " B[ch.frame(),1,2,ch] = function('B_12')(*farglst)\n", " B[ch.frame(),2,3,ch] = function('B_23')(*farglst)\n", " B[ch.frame(),3,1,ch] = function('B_31')(*farglst)\n", "\n", " return B\n", "\n", "def make_Bt(ch):\n", " \"\"\"\n", " make_Bt = make_Bt(ch)\n", " make_Bt creates a time-DEPENDENT electric field as a 2-form\n", " \n", " INPUT/PARAMETER\n", " ch = sagemanifold chart\n", " \"\"\"\n", " B = ch.domain().diff_form(2)\n", " farglst = list(ch[:]) # function argument list, e.g. (x,y,z)\n", "\n", " B[ch.frame(),1,2,ch] = function('B_12')(*farglst)\n", " B[ch.frame(),2,3,ch] = function('B_23')(*farglst)\n", " B[ch.frame(),3,1,ch] = function('B_31')(*farglst)\n", "\n", " return B" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "B_12(t, x, y, z) dx/\\dy - B_31(t, x, y, z) dx/\\dz + B_23(t, x, y, z) dy/\\dz\n" ] }, { "data": { "text/html": [ "" ], "text/plain": [ "B_12(r, phi, z) dr/\\dphi - B_31(r, phi, z) dr/\\dz + B_23(r, phi, z) dphi/\\dz" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "print make_Bt(cart_ch).display()\n", "make_B(cyl_ch).display(cyl_ch.frame(),cyl_ch)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Notice that the orientation is correct (with the right hand rule)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Electromagnetic field 2-form" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "-E1(t, x, y, z) dt/\\dx - E2(t, x, y, z) dt/\\dy - E3(t, x, y, z) dt/\\dz + B_12(t, x, y, z) dx/\\dy - B_31(t, x, y, z) dx/\\dz + B_23(t, x, y, z) dy/\\dz" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "EM_F = make_Bt(cart_ch) + make_Et(cart_ch).wedge(cart_ch.coframe()[0] )\n", "EM_F.display()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 0 -E1(t, x, y, z) -E2(t, x, y, z) -E3(t, x, y, z)]\n", "[ E1(t, x, y, z) 0 B_12(t, x, y, z) -B_31(t, x, y, z)]\n", "[ E2(t, x, y, z) -B_12(t, x, y, z) 0 B_23(t, x, y, z)]\n", "[ E3(t, x, y, z) B_31(t, x, y, z) -B_23(t, x, y, z) 0]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "EM_F[:]" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[[[0, 0, 0, 0],\n", " [0, 0, d(B_12)/dt - d(E1)/dy + d(E2)/dx, -d(B_31)/dt - d(E1)/dz + d(E3)/dx],\n", " [0, -d(B_12)/dt + d(E1)/dy - d(E2)/dx, 0, d(B_23)/dt - d(E2)/dz + d(E3)/dy],\n", " [0, d(B_31)/dt + d(E1)/dz - d(E3)/dx, -d(B_23)/dt + d(E2)/dz - d(E3)/dy, 0]],\n", " [[0, 0, -d(B_12)/dt + d(E1)/dy - d(E2)/dx, d(B_31)/dt + d(E1)/dz - d(E3)/dx],\n", " [0, 0, 0, 0],\n", " [d(B_12)/dt - d(E1)/dy + d(E2)/dx,\n", " 0,\n", " 0,\n", " d(B_12)/dz + d(B_23)/dx + d(B_31)/dy],\n", " [-d(B_31)/dt - d(E1)/dz + d(E3)/dx,\n", " 0,\n", " -d(B_12)/dz - d(B_23)/dx - d(B_31)/dy,\n", " 0]],\n", " [[0, d(B_12)/dt - d(E1)/dy + d(E2)/dx, 0, -d(B_23)/dt + d(E2)/dz - d(E3)/dy],\n", " [-d(B_12)/dt + d(E1)/dy - d(E2)/dx,\n", " 0,\n", " 0,\n", " -d(B_12)/dz - d(B_23)/dx - d(B_31)/dy],\n", " [0, 0, 0, 0],\n", " [d(B_23)/dt - d(E2)/dz + d(E3)/dy,\n", " d(B_12)/dz + d(B_23)/dx + d(B_31)/dy,\n", " 0,\n", " 0]],\n", " [[0, -d(B_31)/dt - d(E1)/dz + d(E3)/dx, d(B_23)/dt - d(E2)/dz + d(E3)/dy, 0],\n", " [d(B_31)/dt + d(E1)/dz - d(E3)/dx,\n", " 0,\n", " d(B_12)/dz + d(B_23)/dx + d(B_31)/dy,\n", " 0],\n", " [-d(B_23)/dt + d(E2)/dz - d(E3)/dy,\n", " -d(B_12)/dz - d(B_23)/dx - d(B_31)/dy,\n", " 0,\n", " 0],\n", " [0, 0, 0, 0]]]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "EM_F.exterior_der()[:]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And so \n", "$ dF = \\left[\\left[\\left[0, 0, 0, 0\\right], \\left[0, 0, \\frac{\\partial\\,B_{12}}{\\partial {t}} - \\frac{\\partial\\,E_{1}}{\\partial y} + \\frac{\\partial\\,E_{2}}{\\partial x}, -\\frac{\\partial\\,B_{31}}{\\partial {t}} - \\frac{\\partial\\,E_{1}}{\\partial z} + \\frac{\\partial\\,E_{3}}{\\partial x}\\right], \\left[0, -\\frac{\\partial\\,B_{12}}{\\partial {t}} + \\frac{\\partial\\,E_{1}}{\\partial y} - \\frac{\\partial\\,E_{2}}{\\partial x}, 0, \\frac{\\partial\\,B_{23}}{\\partial {t}} - \\frac{\\partial\\,E_{2}}{\\partial z} + \\frac{\\partial\\,E_{3}}{\\partial y}\\right], \\left[0, \\frac{\\partial\\,B_{31}}{\\partial {t}} + \\frac{\\partial\\,E_{1}}{\\partial z} - \\frac{\\partial\\,E_{3}}{\\partial x}, -\\frac{\\partial\\,B_{23}}{\\partial {t}} + \\frac{\\partial\\,E_{2}}{\\partial z} - \\frac{\\partial\\,E_{3}}{\\partial y}, 0\\right]\\right], \\left[\\left[0, 0, -\\frac{\\partial\\,B_{12}}{\\partial {t}} + \\frac{\\partial\\,E_{1}}{\\partial y} - \\frac{\\partial\\,E_{2}}{\\partial x}, \\frac{\\partial\\,B_{31}}{\\partial {t}} + \\frac{\\partial\\,E_{1}}{\\partial z} - \\frac{\\partial\\,E_{3}}{\\partial x}\\right], \\left[0, 0, 0, 0\\right], \\left[\\frac{\\partial\\,B_{12}}{\\partial {t}} - \\frac{\\partial\\,E_{1}}{\\partial y} + \\frac{\\partial\\,E_{2}}{\\partial x}, 0, 0, \\frac{\\partial\\,B_{12}}{\\partial z} + \\frac{\\partial\\,B_{23}}{\\partial x} + \\frac{\\partial\\,B_{31}}{\\partial y}\\right], \\left[-\\frac{\\partial\\,B_{31}}{\\partial {t}} - \\frac{\\partial\\,E_{1}}{\\partial z} + \\frac{\\partial\\,E_{3}}{\\partial x}, 0, -\\frac{\\partial\\,B_{12}}{\\partial z} - \\frac{\\partial\\,B_{23}}{\\partial x} - \\frac{\\partial\\,B_{31}}{\\partial y}, 0\\right]\\right], \\left[\\left[0, \\frac{\\partial\\,B_{12}}{\\partial {t}} - \\frac{\\partial\\,E_{1}}{\\partial y} + \\frac{\\partial\\,E_{2}}{\\partial x}, 0, -\\frac{\\partial\\,B_{23}}{\\partial {t}} + \\frac{\\partial\\,E_{2}}{\\partial z} - \\frac{\\partial\\,E_{3}}{\\partial y}\\right], \\left[-\\frac{\\partial\\,B_{12}}{\\partial {t}} + \\frac{\\partial\\,E_{1}}{\\partial y} - \\frac{\\partial\\,E_{2}}{\\partial x}, 0, 0, -\\frac{\\partial\\,B_{12}}{\\partial z} - \\frac{\\partial\\,B_{23}}{\\partial x} - \\frac{\\partial\\,B_{31}}{\\partial y}\\right], \\left[0, 0, 0, 0\\right], \\left[\\frac{\\partial\\,B_{23}}{\\partial {t}} - \\frac{\\partial\\,E_{2}}{\\partial z} + \\frac{\\partial\\,E_{3}}{\\partial y}, \\frac{\\partial\\,B_{12}}{\\partial z} + \\frac{\\partial\\,B_{23}}{\\partial x} + \\frac{\\partial\\,B_{31}}{\\partial y}, 0, 0\\right]\\right], \\left[\\left[0, -\\frac{\\partial\\,B_{31}}{\\partial {t}} - \\frac{\\partial\\,E_{1}}{\\partial z} + \\frac{\\partial\\,E_{3}}{\\partial x}, \\frac{\\partial\\,B_{23}}{\\partial {t}} - \\frac{\\partial\\,E_{2}}{\\partial z} + \\frac{\\partial\\,E_{3}}{\\partial y}, 0\\right], \\left[\\frac{\\partial\\,B_{31}}{\\partial {t}} + \\frac{\\partial\\,E_{1}}{\\partial z} - \\frac{\\partial\\,E_{3}}{\\partial x}, 0, \\frac{\\partial\\,B_{12}}{\\partial z} + \\frac{\\partial\\,B_{23}}{\\partial x} + \\frac{\\partial\\,B_{31}}{\\partial y}, 0\\right], \\left[-\\frac{\\partial\\,B_{23}}{\\partial {t}} + \\frac{\\partial\\,E_{2}}{\\partial z} - \\frac{\\partial\\,E_{3}}{\\partial y}, -\\frac{\\partial\\,B_{12}}{\\partial z} - \\frac{\\partial\\,B_{23}}{\\partial x} - \\frac{\\partial\\,B_{31}}{\\partial y}, 0, 0\\right], \\left[0, 0, 0, 0\\right]\\right]\\right] = 0 $\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ 0 B_23(t, x, y, z) B_31(t, x, y, z) B_12(t, x, y, z)]\n", "[-B_23(t, x, y, z) 0 E3(t, x, y, z) -E2(t, x, y, z)]\n", "[-B_31(t, x, y, z) -E3(t, x, y, z) 0 E1(t, x, y, z)]\n", "[-B_12(t, x, y, z) E2(t, x, y, z) -E1(t, x, y, z) 0]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "EM_F.hodge_dual(g)[:]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As a reminder, the Minkowski metric is a *Lorentzian metric* (not a Riemannian metric, which, in `sagemanifolds`, translates into using the lorentzian_metric module/function, not the riemannian_metric module/function) and is given by $g$:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[-1 0 0 0]\n", "[ 0 1 0 0]\n", "[ 0 0 1 0]\n", "[ 0 0 0 1]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g[:]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$d*F$ (for $d*F = 4 \\pi * J$)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[[[0, 0, 0, 0],\n", " [0,\n", " 0,\n", " d(B_23)/dy - d(B_31)/dx + d(E3)/dt,\n", " -d(B_12)/dx + d(B_23)/dz - d(E2)/dt],\n", " [0,\n", " -d(B_23)/dy + d(B_31)/dx - d(E3)/dt,\n", " 0,\n", " -d(B_12)/dy + d(B_31)/dz + d(E1)/dt],\n", " [0,\n", " d(B_12)/dx - d(B_23)/dz + d(E2)/dt,\n", " d(B_12)/dy - d(B_31)/dz - d(E1)/dt,\n", " 0]],\n", " [[0,\n", " 0,\n", " -d(B_23)/dy + d(B_31)/dx - d(E3)/dt,\n", " d(B_12)/dx - d(B_23)/dz + d(E2)/dt],\n", " [0, 0, 0, 0],\n", " [d(B_23)/dy - d(B_31)/dx + d(E3)/dt, 0, 0, d(E1)/dx + d(E2)/dy + d(E3)/dz],\n", " [-d(B_12)/dx + d(B_23)/dz - d(E2)/dt,\n", " 0,\n", " -d(E1)/dx - d(E2)/dy - d(E3)/dz,\n", " 0]],\n", " [[0,\n", " d(B_23)/dy - d(B_31)/dx + d(E3)/dt,\n", " 0,\n", " d(B_12)/dy - d(B_31)/dz - d(E1)/dt],\n", " [-d(B_23)/dy + d(B_31)/dx - d(E3)/dt, 0, 0, -d(E1)/dx - d(E2)/dy - d(E3)/dz],\n", " [0, 0, 0, 0],\n", " [-d(B_12)/dy + d(B_31)/dz + d(E1)/dt, d(E1)/dx + d(E2)/dy + d(E3)/dz, 0, 0]],\n", " [[0,\n", " -d(B_12)/dx + d(B_23)/dz - d(E2)/dt,\n", " -d(B_12)/dy + d(B_31)/dz + d(E1)/dt,\n", " 0],\n", " [d(B_12)/dx - d(B_23)/dz + d(E2)/dt, 0, d(E1)/dx + d(E2)/dy + d(E3)/dz, 0],\n", " [d(B_12)/dy - d(B_31)/dz - d(E1)/dt, -d(E1)/dx - d(E2)/dy - d(E3)/dz, 0, 0],\n", " [0, 0, 0, 0]]]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "EM_F.hodge_dual(g).exterior_der()[:]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As a reminder, if you wanted the LaTeX code, use the `latex` function in Sage Math like such:" ] }, { "cell_type": "code", "execution_count": 78, "metadata": { "collapsed": false }, "outputs": [], "source": [ "latex( EM_F.hodge_dual(g).exterior_der()[:] ); # delete the semi-colon ; and you can get the LaTeX code-I suppress it" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And so \n", "$d*F = \\left[\\left[\\left[0, 0, 0, 0\\right], \\left[0, 0, i \\, \\frac{\\partial\\,B_{23}}{\\partial y} - i \\, \\frac{\\partial\\,B_{31}}{\\partial x} + i \\, \\frac{\\partial\\,E_{3}}{\\partial {t}}, -i \\, \\frac{\\partial\\,B_{12}}{\\partial x} + i \\, \\frac{\\partial\\,B_{23}}{\\partial z} - i \\, \\frac{\\partial\\,E_{2}}{\\partial {t}}\\right], \\left[0, -i \\, \\frac{\\partial\\,B_{23}}{\\partial y} + i \\, \\frac{\\partial\\,B_{31}}{\\partial x} - i \\, \\frac{\\partial\\,E_{3}}{\\partial {t}}, 0, -i \\, \\frac{\\partial\\,B_{12}}{\\partial y} + i \\, \\frac{\\partial\\,B_{31}}{\\partial z} + i \\, \\frac{\\partial\\,E_{1}}{\\partial {t}}\\right], \\left[0, i \\, \\frac{\\partial\\,B_{12}}{\\partial x} - i \\, \\frac{\\partial\\,B_{23}}{\\partial z} + i \\, \\frac{\\partial\\,E_{2}}{\\partial {t}}, i \\, \\frac{\\partial\\,B_{12}}{\\partial y} - i \\, \\frac{\\partial\\,B_{31}}{\\partial z} - i \\, \\frac{\\partial\\,E_{1}}{\\partial {t}}, 0\\right]\\right], \\left[\\left[0, 0, -i \\, \\frac{\\partial\\,B_{23}}{\\partial y} + i \\, \\frac{\\partial\\,B_{31}}{\\partial x} - i \\, \\frac{\\partial\\,E_{3}}{\\partial {t}}, i \\, \\frac{\\partial\\,B_{12}}{\\partial x} - i \\, \\frac{\\partial\\,B_{23}}{\\partial z} + i \\, \\frac{\\partial\\,E_{2}}{\\partial {t}}\\right], \\left[0, 0, 0, 0\\right], \\left[i \\, \\frac{\\partial\\,B_{23}}{\\partial y} - i \\, \\frac{\\partial\\,B_{31}}{\\partial x} + i \\, \\frac{\\partial\\,E_{3}}{\\partial {t}}, 0, 0, i \\, \\frac{\\partial\\,E_{1}}{\\partial x} + i \\, \\frac{\\partial\\,E_{2}}{\\partial y} + i \\, \\frac{\\partial\\,E_{3}}{\\partial z}\\right], \\left[-i \\, \\frac{\\partial\\,B_{12}}{\\partial x} + i \\, \\frac{\\partial\\,B_{23}}{\\partial z} - i \\, \\frac{\\partial\\,E_{2}}{\\partial {t}}, 0, -i \\, \\frac{\\partial\\,E_{1}}{\\partial x} - i \\, \\frac{\\partial\\,E_{2}}{\\partial y} - i \\, \\frac{\\partial\\,E_{3}}{\\partial z}, 0\\right]\\right], \\left[\\left[0, i \\, \\frac{\\partial\\,B_{23}}{\\partial y} - i \\, \\frac{\\partial\\,B_{31}}{\\partial x} + i \\, \\frac{\\partial\\,E_{3}}{\\partial {t}}, 0, i \\, \\frac{\\partial\\,B_{12}}{\\partial y} - i \\, \\frac{\\partial\\,B_{31}}{\\partial z} - i \\, \\frac{\\partial\\,E_{1}}{\\partial {t}}\\right], \\left[-i \\, \\frac{\\partial\\,B_{23}}{\\partial y} + i \\, \\frac{\\partial\\,B_{31}}{\\partial x} - i \\, \\frac{\\partial\\,E_{3}}{\\partial {t}}, 0, 0, -i \\, \\frac{\\partial\\,E_{1}}{\\partial x} - i \\, \\frac{\\partial\\,E_{2}}{\\partial y} - i \\, \\frac{\\partial\\,E_{3}}{\\partial z}\\right], \\left[0, 0, 0, 0\\right], \\left[-i \\, \\frac{\\partial\\,B_{12}}{\\partial y} + i \\, \\frac{\\partial\\,B_{31}}{\\partial z} + i \\, \\frac{\\partial\\,E_{1}}{\\partial {t}}, i \\, \\frac{\\partial\\,E_{1}}{\\partial x} + i \\, \\frac{\\partial\\,E_{2}}{\\partial y} + i \\, \\frac{\\partial\\,E_{3}}{\\partial z}, 0, 0\\right]\\right], \\left[\\left[0, -i \\, \\frac{\\partial\\,B_{12}}{\\partial x} + i \\, \\frac{\\partial\\,B_{23}}{\\partial z} - i \\, \\frac{\\partial\\,E_{2}}{\\partial {t}}, -i \\, \\frac{\\partial\\,B_{12}}{\\partial y} + i \\, \\frac{\\partial\\,B_{31}}{\\partial z} + i \\, \\frac{\\partial\\,E_{1}}{\\partial {t}}, 0\\right], \\left[i \\, \\frac{\\partial\\,B_{12}}{\\partial x} - i \\, \\frac{\\partial\\,B_{23}}{\\partial z} + i \\, \\frac{\\partial\\,E_{2}}{\\partial {t}}, 0, i \\, \\frac{\\partial\\,E_{1}}{\\partial x} + i \\, \\frac{\\partial\\,E_{2}}{\\partial y} + i \\, \\frac{\\partial\\,E_{3}}{\\partial z}, 0\\right], \\left[i \\, \\frac{\\partial\\,B_{12}}{\\partial y} - i \\, \\frac{\\partial\\,B_{31}}{\\partial z} - i \\, \\frac{\\partial\\,E_{1}}{\\partial {t}}, -i \\, \\frac{\\partial\\,E_{1}}{\\partial x} - i \\, \\frac{\\partial\\,E_{2}}{\\partial y} - i \\, \\frac{\\partial\\,E_{3}}{\\partial z}, 0, 0\\right], \\left[0, 0, 0, 0\\right]\\right]\\right]$" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[-d(E1)/dx - d(E2)/dy - d(E3)/dz,\n", " d(B_12)/dy - d(B_31)/dz - d(E1)/dt,\n", " -d(B_12)/dx + d(B_23)/dz - d(E2)/dt,\n", " -d(B_23)/dy + d(B_31)/dx - d(E3)/dt]" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "EM_F.hodge_dual(g).exterior_der().hodge_dual(g)[:] " ] }, { "cell_type": "code", "execution_count": 81, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "\\left[\\frac{\\partial\\,E_{1}}{\\partial x} + \\frac{\\partial\\,E_{2}}{\\partial y} + \\frac{\\partial\\,E_{3}}{\\partial z}, -\\frac{\\partial\\,B_{12}}{\\partial y} + \\frac{\\partial\\,B_{31}}{\\partial z} + \\frac{\\partial\\,E_{1}}{\\partial {t}}, \\frac{\\partial\\,B_{12}}{\\partial x} - \\frac{\\partial\\,B_{23}}{\\partial z} + \\frac{\\partial\\,E_{2}}{\\partial {t}}, \\frac{\\partial\\,B_{23}}{\\partial y} - \\frac{\\partial\\,B_{31}}{\\partial x} + \\frac{\\partial\\,E_{3}}{\\partial {t}}\\right]" ] }, "execution_count": 81, "metadata": {}, "output_type": "execute_result" } ], "source": [ "latex(EM_F.hodge_dual(g).exterior_der().hodge_dual(g)[:]); \n", "# delete the semi-colon ; and you can get the LaTeX code-I suppress it" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And so \n", "$*d*F = \\left[\\frac{\\partial\\,E_{1}}{\\partial x} + \\frac{\\partial\\,E_{2}}{\\partial y} + \\frac{\\partial\\,E_{3}}{\\partial z}, -\\frac{\\partial\\,B_{12}}{\\partial y} + \\frac{\\partial\\,B_{31}}{\\partial z} + \\frac{\\partial\\,E_{1}}{\\partial {t}}, \\frac{\\partial\\,B_{12}}{\\partial x} - \\frac{\\partial\\,B_{23}}{\\partial z} + \\frac{\\partial\\,E_{2}}{\\partial {t}}, \\frac{\\partial\\,B_{23}}{\\partial y} - \\frac{\\partial\\,B_{31}}{\\partial x} + \\frac{\\partial\\,E_{3}}{\\partial {t}}\\right]$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Current 1-form, Current conservation, and the other side (Right-Hand Side (RHS)) of $d*F$" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def make_J(ch):\n", " \"\"\"\n", " make_J = make_J(ch)\n", " make_J creates a time-INDEPENDENT current as a 1-form\n", " \n", " INPUT/PARAMETER\n", " ch = sagemanifold chart\n", " \"\"\"\n", " Jcomplst = []\n", " for i in range(1,4):\n", " Jarglst = ['j'+str(i),] + list(ch[1:])\n", " Jcomplst.append( function(Jarglst[0])(*Jarglst[1:]) )\n", " Jcomplst = [-function('rho')(*list(ch[1:])),] +Jcomplst\n", " J = ch.domain().diff_form(1)\n", " J[ch.frame(),:,ch] = Jcomplst\n", " return J\n", "\n", "\n", "def make_Jt(ch):\n", " \"\"\"\n", " make_Jt = make_Jt(ch)\n", " make_Jt creates a time-DEPENDENT current as a 1-form\n", " \n", " INPUT/PARAMETER\n", " ch = sagemanifold chart\n", " \"\"\"\n", " Jcomplst = []\n", " for i in range(1,4):\n", " Jarglst = ['j'+str(i),] + list(ch[:])\n", " Jcomplst.append( function(Jarglst[0])(*Jarglst[1:]) )\n", " Jcomplst = [-function('rho')(*list(ch[:])),]+Jcomplst\n", " J = ch.domain().diff_form(1)\n", " J[ch.frame(),:,ch] = Jcomplst\n", " return J\n", " " ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-rho(t, x, y, z) dt + j1(t, x, y, z) dx + j2(t, x, y, z) dy + j3(t, x, y, z) dz\n" ] }, { "data": { "text/html": [ "" ], "text/plain": [ "-rho(t, r, phi, z) dt + j1(t, r, phi, z) dr + j2(t, r, phi, z) dphi + j3(t, r, phi, z) dz" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "print make_Jt(cart_ch).display() # these are examples of displaying the 4-current as 1-form in \n", " # Cartesian and cylindrical coordinates\n", "make_Jt(cyl_ch).display(cyl_ch.frame(),cyl_ch)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "-rho(t, x, y, z) dt + j1(t, x, y, z) dx + j2(t, x, y, z) dy + j3(t, x, y, z) dz" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_Jt(cart_ch).hodge_dual(g).hodge_dual(g).display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So here, I had successfully shown that $*d*F = **J$ or $*d*F = 4\\pi ** J$ (in cgs units), thus recovering Gauss's law and Ampere's law." ] }, { "cell_type": "code", "execution_count": 115, "metadata": { "collapsed": false }, "outputs": [], "source": [ "latex( make_Jt(cart_ch).hodge_dual(g).hodge_dual(g)[:]);\n", "# delete the semi-colon ; and you can get the LaTeX code-I suppress it" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$\\boxed{ \\left[\\frac{\\partial\\,E_{1}}{\\partial x} + \\frac{\\partial\\,E_{2}}{\\partial y} + \\frac{\\partial\\,E_{3}}{\\partial z}, -\\frac{\\partial\\,B_{12}}{\\partial y} + \\frac{\\partial\\,B_{31}}{\\partial z} + \\frac{\\partial\\,E_{1}}{\\partial {t}}, \\frac{\\partial\\,B_{12}}{\\partial x} - \\frac{\\partial\\,B_{23}}{\\partial z} + \\frac{\\partial\\,E_{2}}{\\partial {t}}, \\frac{\\partial\\,B_{23}}{\\partial y} - \\frac{\\partial\\,B_{31}}{\\partial x} + \\frac{\\partial\\,E_{3}}{\\partial {t}}\\right] = \\left[\\rho\\left({t}, x, y, z\\right), -j_{1}\\left({t}, x, y, z\\right), -j_{2}\\left({t}, x, y, z\\right), -j_{3}\\left({t}, x, y, z\\right)\\right] }$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Current conservation is easily calculated, $*d*J=0$:" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "M --> R\n", "(t, x, y, z) |--> -d(j1)/dx - d(j2)/dy - d(j3)/dz - d(rho)/dt" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_Jt(cart_ch).hodge_dual(g).exterior_der().hodge_dual(g).display(cart_ch)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Lorentz Force" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def make_beta(ch):\n", " \"\"\"\n", " make_beta = make_beta(ch)\n", " make_beta creates a time-INDEPENDENT velocity field\n", " \n", " INPUT/PARAMETER\n", " ch = sagemanifold chart\n", " \"\"\"\n", " betacomplst = []\n", " for i in range(1,4):\n", " betaarglst = ['beta'+str(i),] + list(ch[1:])\n", " betacomplst.append( function(betaarglst[0])(*betaarglst[1:]) )\n", " betacomplst = [1,]+betacomplst\n", " beta = ch.domain().vector_field()\n", " beta[ch.frame(),:,ch] = betacomplst\n", " return beta\n", "\n", "def make_betat(ch):\n", " \"\"\"\n", " make_betat = make_betat(ch)\n", " make_betat creates a time-DEPENDENT velocity field\n", " \n", " INPUT/PARAMETER\n", " ch = sagemanifold chart\n", " \"\"\"\n", " betacomplst = []\n", " for i in range(1,4):\n", " betaarglst = ['beta'+str(i),] + list(ch[:])\n", " betacomplst.append( function(betaarglst[0])(*betaarglst[1:]) )\n", " betacomplst = [1,]+betacomplst\n", " beta = ch.domain().vector_field()\n", " beta[ch.frame(),:,ch] = betacomplst\n", " return beta" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "d/dt + beta1(x, y, z) d/dx + beta2(x, y, z) d/dy + beta3(x, y, z) d/dz" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_beta(cart_ch).display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For interior products, you're going to have to dig into how sagemanifolds implements Tensor products, tensor contractions, and the use of index notation, as sagemanifolds doesn't have a \"stand-alone\" interior product function. From my [EuclideanManifold.py](https://github.com/ernestyalumni/Propulsion/blob/master/Learn/EuclideanManifold.py) implementation in sagemanifolds, look at my curl function (`def curl`) as a template for implementing interior products. " ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "(-B_12(t, x, y, z)*beta2(t, x, y, z) + B_31(t, x, y, z)*beta3(t, x, y, z)) dx + (B_12(t, x, y, z)*beta1(t, x, y, z) - B_23(t, x, y, z)*beta3(t, x, y, z)) dy + (-B_31(t, x, y, z)*beta1(t, x, y, z) + B_23(t, x, y, z)*beta2(t, x, y, z)) dz" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "betaeg = make_betat(cart_ch)\n", "Beg = make_Bt(cart_ch)\n", "(betaeg['^i']*Beg['_ij']).display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So we now have a prescription on how to implement both the **interior product** and the **curl** of 2 \"vectors\" - \n", "if you want this:\n", "\n", "$-i_{\\mathbf{\\beta}} B$ which is the differential form version of $\\mathbf{\\beta} \\times B$ (curl), then do this in sagemanifolds:\n", "\n", "`-betaeg['^i']*Beg['_ij']`" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false }, "outputs": [], "source": [ "q = var('q',domain=\"real\") # define a single charge variable in Sage Math" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": false }, "outputs": [], "source": [ "LorentzForce1form = make_Et(cart_ch) - make_beta(cart_ch)['^i']*make_Bt(cart_ch)['_ij']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can multiply this differential 1-form with Sage Math variables." ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false }, "outputs": [], "source": [ "LorentzForce1form = q * LorentzForce1form" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The 1-form version of the Lorentz Force $F$ is given by the following, and keep in mind that we integrate 1-forms, we don't integrate vectors (because it goes back to how we transport vectors along a curve, and 1-forms either abscond, circumvent, this problem or is the most natural way to do integration on manifolds): " ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "(q*B_12(t, x, y, z)*beta2(x, y, z) - q*B_31(t, x, y, z)*beta3(x, y, z) + q*E1(t, x, y, z)) dx + (-q*B_12(t, x, y, z)*beta1(x, y, z) + q*B_23(t, x, y, z)*beta3(x, y, z) + q*E2(t, x, y, z)) dy + (q*B_31(t, x, y, z)*beta1(x, y, z) - q*B_23(t, x, y, z)*beta2(x, y, z) + q*E3(t, x, y, z)) dz" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LorentzForce1form.display() " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And so \n", "$f = \\left( q B_{12}\\left({t}, x, y, z\\right) \\beta_{2}\\left(x, y, z\\right) - q B_{31}\\left({t}, x, y, z\\right) \\beta_{3}\\left(x, y, z\\right) + q E_{1}\\left({t}, x, y, z\\right) \\right) \\mathrm{d} x + \\left( -q B_{12}\\left({t}, x, y, z\\right) \\beta_{1}\\left(x, y, z\\right) + q B_{23}\\left({t}, x, y, z\\right) \\beta_{3}\\left(x, y, z\\right) + q E_{2}\\left({t}, x, y, z\\right) \\right) \\mathrm{d} y + \\left( q B_{31}\\left({t}, x, y, z\\right) \\beta_{1}\\left(x, y, z\\right) - q B_{23}\\left({t}, x, y, z\\right) \\beta_{2}\\left(x, y, z\\right) + q E_{3}\\left({t}, x, y, z\\right) \\right) \\mathrm{d} z$" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "## More \"combinations\": $F \\wedge *F$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$F \\wedge * F$" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": false }, "outputs": [], "source": [ "FwedgestarF = EM_F.wedge(EM_F.hodge_dual(g))" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "(B_12(t, x, y, z)^2 + B_23(t, x, y, z)^2 + B_31(t, x, y, z)^2 - E1(t, x, y, z)^2 - E2(t, x, y, z)^2 - E3(t, x, y, z)^2) dt/\\dx/\\dy/\\dz" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "FwedgestarF.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$E\\cdot B$" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "(B_23(t, x, y, z)*E1(t, x, y, z) + B_31(t, x, y, z)*E2(t, x, y, z) + B_12(t, x, y, z)*E3(t, x, y, z)) dx/\\dy/\\dz" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Eteg = make_Et(cart_ch)\n", "Bteg = make_Bt(cart_ch)\n", "EdotB = Eteg.wedge( Bteg)\n", "EdotB.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Poynting Vector\n", "\n", "Try\n", "$E \\wedge *B$" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "(-B_31(t, x, y, z)*E1(t, x, y, z) + B_23(t, x, y, z)*E2(t, x, y, z)) dt/\\dx/\\dy + (-B_12(t, x, y, z)*E1(t, x, y, z) + B_23(t, x, y, z)*E3(t, x, y, z)) dt/\\dx/\\dz + (-B_12(t, x, y, z)*E2(t, x, y, z) + B_31(t, x, y, z)*E3(t, x, y, z)) dt/\\dy/\\dz" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(Eteg.wedge( Bteg.hodge_dual(g))).display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "SageMath 7.2.rc0", "language": "", "name": "sagemath" }, "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 }