{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f4419154",
   "metadata": {},
   "source": [
    "# Magnetic field of a charged wire\n",
    "- Börge Göbel"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9342fb0f",
   "metadata": {},
   "source": [
    "![hand](figure_05_hand.svg)\n",
    "\n",
    "https://upload.wikimedia.org/wikipedia/commons/3/3e/Manoderecha.svg"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f402257f",
   "metadata": {},
   "source": [
    "Using the Maxwell equations of magnetostatics (in their integral form) one can derive the vector potential of a current density distribution \\\\( \\vec{j}(\\vec{r}) \\\\)\n",
    "\n",
    "\\\\( \n",
    "\\vec{A}(\\vec{r})=\\frac{\\mu_0}{4\\pi}\\int\\frac{\\vec{j}(\\vec{r}')}{|\\vec{r}-\\vec{r}'|}\\,\\mathrm{d}V'\\\\\n",
    "\\\\)\n",
    "\n",
    "from which we can calculate the magnetic field \n",
    "\n",
    "\\\\( \n",
    "\\vec{B}(\\vec{r})=\\nabla\\times\\vec{A}(\\vec{r})\\\\\n",
    "\\\\)\n",
    "\n",
    "For more details on these equations, please consider my course: \"Electrodynamics based on Maxwell equations\" https://www.udemy.com/course/electrodynamics/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ce2064a4",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "73703056",
   "metadata": {},
   "source": [
    "### Straight wire\n",
    "\n",
    "- along z axis\n",
    "- very long: length \\\\( [-l_0,l_0]\\\\) (we will only consider the xy plane, because all other planes will behave equally)\n",
    "- very thin: radius \\\\(r_0\\\\) (basically non-zero only for x = 0, y = 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5274b866",
   "metadata": {},
   "outputs": [],
   "source": [
    "mu0 = 1\n",
    "\n",
    "# straight wire\n",
    "j0 = 1 # Ampere / meter^2\n",
    "r0 = 0.001 # m\n",
    "l0 = 1000 # m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "42789278",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "4794fa59",
   "metadata": {},
   "source": [
    "__Analytical solution:__\n",
    "\n",
    "\\\\( \\vec{A}(\\vec{r}) = \\frac{\\mu_0}{2\\pi}jF\\log\\frac{2l_0}{\\sqrt{x^2+y^2}}\\vec{e}_z\\\\)\n",
    "\n",
    "For more details on these equations, please consider my course: \"Electrodynamics based on Maxwell equations\" https://www.udemy.com/course/electrodynamics/\n",
    "\n",
    "![derivation_wire](figure_05_derivation_wire.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e197330e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "bc0da924",
   "metadata": {},
   "source": [
    "__We can calculate the magnetic field__\n",
    "\n",
    "\\\\( \n",
    "\\vec{B}(\\vec{r})=\\nabla\\times\\vec{A}(\\vec{r})=\\begin{pmatrix}\n",
    "\\frac{\\partial}{\\partial y}A_z(\\vec{r}) - \\frac{\\partial}{\\partial z}A_y(\\vec{r})\\\\\n",
    "\\frac{\\partial}{\\partial z}A_x(\\vec{r}) - \\frac{\\partial}{\\partial x}A_z(\\vec{r})\\\\\n",
    "\\frac{\\partial}{\\partial x}A_y(\\vec{r}) - \\frac{\\partial}{\\partial y}A_x(\\vec{r})\\\\\n",
    "\\end{pmatrix}=\\begin{pmatrix}\n",
    "\\frac{\\partial}{\\partial y}A_z(\\vec{r})\\\\\n",
    " - \\frac{\\partial}{\\partial x}A_z(\\vec{r})\\\\\n",
    "\\frac{\\partial}{\\partial x}A_y(\\vec{r}) - \\frac{\\partial}{\\partial y}A_x(\\vec{r})\\\\\n",
    "\\end{pmatrix}\\\\\n",
    "\\\\)\n",
    "\n",
    "Since the vector potential only changes in the xy plane and is considered to be constant along z (for infinite \\\\(l_0\\\\)), we know\n",
    "\\\\( \n",
    "\\frac{\\partial }{\\partial z} A_x(\\vec{r}) = \\frac{\\partial }{\\partial z} A_y(\\vec{r}) = 0\n",
    "\\\\)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e55454f2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "baf9bf8f",
   "metadata": {},
   "source": [
    "__Analytical solution:__\n",
    "\n",
    "\\\\( \\vec{B}(\\vec{r}) = \\frac{\\mu_0}{2\\pi}jF\\frac{1}{\\sqrt{x^2+y^2}}\\begin{pmatrix}-y\\\\x\\\\0\\end{pmatrix}\\\\)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "86215d89",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "c501d3d6",
   "metadata": {},
   "source": [
    "![hand](figure_05_hand.svg)\n",
    "\n",
    "https://upload.wikimedia.org/wikipedia/commons/3/3e/Manoderecha.svg"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
