Fixing some issues in the coil simulation - still not working properly

This commit is contained in:
Chris Greening 2022-11-22 12:41:49 +00:00
parent fcc9c6727c
commit 8f5f43e80f

View file

@ -24,13 +24,13 @@
"# load up the simple spiral coil\n", "# load up the simple spiral coil\n",
"coil1 = parse_coil(f\"coils/coil_{COIL}_spiral.csv\")\n", "coil1 = parse_coil(f\"coils/coil_{COIL}_spiral.csv\")\n",
"plot_coil(f\"coils/coil_{COIL}_spiral.csv\")\n", "plot_coil(f\"coils/coil_{COIL}_spiral.csv\")\n",
"coil1 = slice_coil(coil1, 1)\n", "coil1 = slice_coil(coil1, 0.01)\n",
"coil1 = coil1.T\n", "coil1 = coil1.T\n",
"print(coil1.shape)\n", "print(coil1.shape)\n",
"\n", "\n",
"coil2 = parse_coil(f\"coils/coil_{COIL}_custom.csv\")\n", "coil2 = parse_coil(f\"coils/coil_{COIL}_custom.csv\")\n",
"plot_coil(f\"coils/coil_{COIL}_custom.csv\")\n", "plot_coil(f\"coils/coil_{COIL}_custom.csv\")\n",
"coil2 = slice_coil(coil2, 1)\n", "coil2 = slice_coil(coil2, 0.01)\n",
"coil2 = coil2.T\n", "coil2 = coil2.T\n",
"print(coil2.shape)" "print(coil2.shape)"
] ]
@ -145,6 +145,7 @@
"source": [ "source": [
"def B(x, y, z, m=0.185, l=0.003, d=0.01):\n", "def B(x, y, z, m=0.185, l=0.003, d=0.01):\n",
" d = d * 0.75\n", " d = d * 0.75\n",
" l = l * 0.75\n",
" # simulate multiple points in the cylinder and add them together to create a disk of field\n", " # simulate multiple points in the cylinder and add them together to create a disk of field\n",
" bx = 0\n", " bx = 0\n",
" by = 0\n", " by = 0\n",
@ -152,19 +153,19 @@
" for degrees in range(0, 360, 30):\n", " for degrees in range(0, 360, 30):\n",
" angle = np.deg2rad(degrees)\n", " angle = np.deg2rad(degrees)\n",
" x_, y_, z_ = dipole(\n", " x_, y_, z_ = dipole(\n",
" x + 0.9 * d / 2 * np.cos(angle),\n", " x + d / 2 * np.cos(angle),\n",
" y + 0.9 * d / 2 * np.sin(angle),\n", " y + d / 2 * np.sin(angle),\n",
" z - 0.9 * l / 2,\n", " z - l / 2,\n",
" m / (360 / 60),\n", " m / (360 / 30),\n",
" )\n", " )\n",
" bx += x_\n", " bx += x_\n",
" by += y_\n", " by += y_\n",
" bz += z_\n", " bz += z_\n",
" x_, y_, z_ = dipole(\n", " x_, y_, z_ = dipole(\n",
" x + 0.9 * d / 2 * np.cos(angle),\n", " x + d / 2 * np.cos(angle),\n",
" y + 0.9 * d / 2 * np.sin(angle),\n", " y + d / 2 * np.sin(angle),\n",
" z + 0.9 * l / 2,\n", " z + l / 2,\n",
" m / (360 / 60),\n", " m / (360 / 30),\n",
" )\n", " )\n",
" bx += x_\n", " bx += x_\n",
" by += y_\n", " by += y_\n",
@ -293,7 +294,7 @@
"def sweep_coil_circle(coil, coil_center_radius, theta):\n", "def sweep_coil_circle(coil, coil_center_radius, theta):\n",
" X = coil_center_radius * np.cos(np.deg2rad(theta))\n", " X = coil_center_radius * np.cos(np.deg2rad(theta))\n",
" Y = coil_center_radius * np.sin(np.deg2rad(theta)) - coil_center_radius\n", " Y = coil_center_radius * np.sin(np.deg2rad(theta)) - coil_center_radius\n",
" Z = -0.01\n", " Z = -0.002\n",
"\n", "\n",
" # loop through the locations and calculate the forces, sum up the force in the X direction for each location\n", " # loop through the locations and calculate the forces, sum up the force in the X direction for each location\n",
" Fx = []\n", " Fx = []\n",
@ -306,9 +307,9 @@
"\n", "\n",
" points = coil.copy()\n", " points = coil.copy()\n",
" for i in range(len(points)):\n", " for i in range(len(points)):\n",
" points[i][0] = points[i][0] / 1000 + x\n", " points[i][0] = points[i][0] / 100 + x\n",
" points[i][1] = points[i][1] / 1000 + y\n", " points[i][1] = points[i][1] / 100 + y\n",
" points[i][2] = points[i][2] / 1000 + z\n", " points[i][2] = points[i][2] / 100 + z\n",
" # feel the force\n", " # feel the force\n",
" Fx_, Fy_, Fz_ = calculate_forces_on_wire_points(points)\n", " Fx_, Fy_, Fz_ = calculate_forces_on_wire_points(points)\n",
" Fx.append(sum(Fx_))\n", " Fx.append(sum(Fx_))\n",
@ -333,14 +334,22 @@
" # points in meters (coil is in cm)\n", " # points in meters (coil is in cm)\n",
" [x / 100 for x, y, z, _ in points],\n", " [x / 100 for x, y, z, _ in points],\n",
" [y / 100 for x, y, z, _ in points],\n", " [y / 100 for x, y, z, _ in points],\n",
" label=\"coil\",\n", " label=\"coil2\",\n",
" color=\"blue\",\n", " color=\"blue\",\n",
")\n", ")\n",
"points = coil1.copy()\n",
"plt.plot(\n",
" # points in meters (coil is in cm)\n",
" [x / 100 for x, y, z, _ in points],\n",
" [y / 100 for x, y, z, _ in points],\n",
" label=\"coil1\",\n",
" color=\"red\",\n",
")\n",
"# make the aspect ratio equal\n", "# make the aspect ratio equal\n",
"plt.gca().set_aspect(\"equal\")\n", "plt.gca().set_aspect(\"equal\")\n",
"\n", "\n",
"Fx_1_curve, Fy_1_curve, Fz_1_curve = sweep_coil_circle(coil1, 20.5 / 1000, theta)\n", "Fx_1_curve, Fy_1_curve, Fz_1_curve = sweep_coil_circle(coil1, 20.5 / 1000, theta)\n",
"Fx_2_curve, Fy_2_curve, Fz_2_curve = sweep_coil_circle(coil2, 19.5 / 1000, theta)" "Fx_2_curve, Fy_2_curve, Fz_2_curve = sweep_coil_circle(coil2, 20.5 / 1000, theta)"
] ]
}, },
{ {