You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123 lines
7.7 KiB
123 lines
7.7 KiB
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import numpy as np\n",
|
|
"import scipy.constants as sc"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class Ion:\n",
|
|
" def __init__(self,position, charge, mass, v_z):\n",
|
|
" self.position = position\n",
|
|
" self.charge = charge\n",
|
|
" self.m = mass\n",
|
|
" self.v_z = v_z\n",
|
|
" self.F = np.zeros(3)\n",
|
|
"\n",
|
|
"class infiniteLengthQuadrupole:\n",
|
|
" def __init__(self,R,r_0):\n",
|
|
" self.R = R\n",
|
|
" self.r_0 = r_0\n",
|
|
" self.pPole = np.zeros(4)\n",
|
|
" self.pPole[0] = [r_0/np.sqrt(2),r_0/np.sqrt(2)]\n",
|
|
" self.pPole[1] = [-r_0/np.sqrt(2),r_0/np.sqrt(2)]\n",
|
|
" self.pPole[2] = [-r_0/np.sqrt(2),-r_0/np.sqrt(2)]\n",
|
|
" self.pPole[3] = [r_0/np.sqrt(2),-r_0/np.sqrt(2)]\n",
|
|
" self.rodsPseudoQ = np.zeros(4)\n",
|
|
" self.K = 1 / (4 * np.pi * sc.epsilon_0)\n",
|
|
" \n",
|
|
" def phi_0(U, V, f, t):\n",
|
|
" return U + V * np.sin(2 * np.pi * f * t)\n",
|
|
" \n",
|
|
" def calcNewIonPos(U,V,f,ion,t_s):\n",
|
|
" \n",
|
|
" # check if ion has left the r_0 boundary\n",
|
|
" if np.abs(ion.p) >= r_0:\n",
|
|
" return None\n",
|
|
" \n",
|
|
" signLUT = [1,-1,1,-1]\n",
|
|
" index = 0;\n",
|
|
" \n",
|
|
" for Q in rodsPseudoQ:\n",
|
|
" # calculate the pseudo charge points of the quadrupole\n",
|
|
" Q = signLUT[index] * phi_0(U,V,f)/2 * K * R\n",
|
|
" index = index + 1\n",
|
|
" \n",
|
|
" # calculate force on ion\n",
|
|
" r_v = pPole[index] - ion.position\n",
|
|
" ion.F += K * ion.charge * Q * r_v / (np.abs(r_v)**3)\n",
|
|
" \n",
|
|
" newPosition = t_s**2 * 1 / ion.m * ion.F + ion.position\n",
|
|
"\n",
|
|
" return newPosition"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"ename": "ValueError",
|
|
"evalue": "setting an array element with a sequence.",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
|
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
|
|
"\u001b[0;31mTypeError\u001b[0m: float() argument must be a string or a number, not 'list'",
|
|
"\nThe above exception was the direct cause of the following exception:\n",
|
|
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
|
|
"\u001b[0;32m<ipython-input-11-719575a9fd46>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;31m# quadrupole\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mquad\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0minfiniteLengthQuadrupole\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m5E-3\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m15E-3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mn\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1000\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0mion\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mposition\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mquad\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcalcNewIonPos\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1000\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mion\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mt_s\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0;32m<ipython-input-10-8caf849c398b>\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, R, r_0)\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mr_0\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mr_0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpPole\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mzeros\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 14\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpPole\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mr_0\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mr_0\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 15\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpPole\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mr_0\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mr_0\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpPole\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mr_0\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mr_0\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0;31mValueError\u001b[0m: setting an array element with a sequence."
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"t_s = 1E-6\n",
|
|
"\n",
|
|
"# coffein atom 524.50002164 dalton (8.709527e-25 kg)\n",
|
|
"ion = Ion([0,0,0], sc.e, 8.709527e-25,0)\n",
|
|
"\n",
|
|
"# quadrupole\n",
|
|
"quad = infiniteLengthQuadrupole(5E-3,15E-3)\n",
|
|
"for n in range(0,1000,1):\n",
|
|
" ion.position = quad.calcNewIonPos(0,1000,ion,t_s)\n",
|
|
" print(ion.position)\n",
|
|
" "
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"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.7.3"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|