pcb-stator-coil-generator/simulations/simulate_coil.ipynb
2022-11-19 08:24:27 +00:00

162 lines
3.9 KiB
Text

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import biot_savart_v4_3 as bs\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"bs.plot_coil(\"coil-4-top-1.csv\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"bs.plot_coil(\"coil-4-bottom-1.csv\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for i in range(0, 12):\n",
" bs.write_target_volume(\n",
" f\"coil-4-top-{i}.csv\",\n",
" f\"targetvol-top-{i}.vol\",\n",
" (6, 6, 1),\n",
" (-3, -3, -0.5),\n",
" 0.1,\n",
" 0.1,\n",
" )\n",
" bs.write_target_volume(\n",
" f\"coil-4-bottom-{i}.csv\",\n",
" f\"targetvol-bottom-{i}.vol\",\n",
" (6, 6, 1),\n",
" (-3, -3, -0.5),\n",
" 0.1,\n",
" 0.1,\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# read in the results\n",
"top = [bs.read_target_volume(f\"targetvol-top-{i}.vol\") for i in range(0, 12)]\n",
"bottom = [bs.read_target_volume(f\"targetvol-bottom-{i}.vol\") for i in range(0, 12)]\n",
"\n",
"# add all the results together into one volume\n",
"volume = top[0] + bottom[0]\n",
"for i in range(1, 12):\n",
" volume += top[i]\n",
" volume += bottom[i]\n",
"\n",
"print(volume.shape)\n",
"\n",
"# reads the volume we created\n",
"bs.plot_fields(volume, (60, 60, 10), (0, 0, 0), 1, which_plane=\"z\", level=6)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib as plt\n",
"\n",
"# get a slice of the volume at z=6\n",
"slice = [volume[50, :, :, i].T for i in range(3)]\n",
"x_contour = slice[0]\n",
"y_contour = slice[1]\n",
"z_contour = slice[2]\n",
"\n",
"print(x_contour.shape)\n",
"print(y_contour.shape)\n",
"print(z_contour.shape)\n",
"\n",
"x = np.arange(0, 61, 1)\n",
"y = np.arange(0, 11, 1)\n",
"xG, yG = np.meshgrid(x, y)\n",
"# do a quiver plot of the x and the z components - we won't worry about y\n",
"plt.pyplot.quiver(xG, yG, y_contour, z_contour)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = plt.pyplot.figure()\n",
"ax = fig.add_subplot(111)\n",
"\n",
"# Plot the streamlines with an appropriate colormap and arrow style\n",
"# color = 2 * np.log(np.hypot(x_contour, z_contour))\n",
"ax.streamplot(\n",
" x,\n",
" y,\n",
" y_contour,\n",
" z_contour,\n",
" linewidth=1,\n",
" cmap=plt.cm.inferno,\n",
" density=2,\n",
" arrowstyle=\"->\",\n",
" arrowsize=1.5,\n",
")\n",
"\n",
"ax.set_xlabel(\"$x$\")\n",
"ax.set_ylabel(\"$y$\")\n",
"# ax.set_xlim(-2,2)\n",
"# ax.set_ylim(-2,2)\n",
"ax.set_aspect(\"equal\")\n",
"fig.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.7 ('venv': venv)",
"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.10.7"
},
"vscode": {
"interpreter": {
"hash": "1ce20143987840b9786ebb5907032c9c3a8efacbb887dbb0ebc4934f2ad26cb3"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}