#

# ExB_Filter_Exercise_1.py

#

# This file is used to calculate

# the Cartesian components of the acceleration of

# a charged particle through

# an E x B velocity filter.

#

# Here, it is assumed that the axis of the filter

# is aligned with the z-axis, that the magnetic field

# is along the +x-direction, and that the electric field

# is along the -y-direction.

#

# By:

# Ernest R. Behringer

# Department of Physics and Astronomy

# Eastern Michigan University

# Ypsilanti, MI 48197

# (734) 487-8799 (Office)

# ebehringe@emich.edu

#

# Last updated:

#

# 20110309 = March 9, 2011 ERB Initial writing in Matlab.

# 20160616 ERB conversion from Matlab.

#

from numpy import sqrt

import time

#

# Initialize parameter values

#

q = 1.60e-19 # particle charge [C]

m = 7.0*1.67e-27 # particle mass [kg]

KE_eV = 100.0 # particle kinetic energy [eV]

Ex = 0.0 # Ex = electric field in the +x direction [N/C]

Ey = -105.0 # Ey = electric field in the +y direction [N/C]

Ez = 0.0 # Ez = electric field in the +z direction [N/C]

Bx = 0.002 # Bx = magnetic field in the +x direction [T]

By = 0.0 # By = magnetic field in the +x direction [T]

Bz = 0.0 # Bz = magnetic field in the +x direction [T]

D = 2.0 # D = diameter of the exit aperture [mm]

L = 0.25 # L = length of the crossed field region [mm]

u = [1.0,1.0,100.0]/sqrt(10002.0) # direction of the velocity vector

# Derived quantities

qoverm = q/m # charge to mass ratio [C/kg]

KE = KE_eV*1.602e-19 # particle kinetic energy [J]

vmag = sqrt(2.0*KE/m) # particle velocity magnitude [m/s]

v1x = vmag*u[0] # v1x = x-component of the initial velocity [m/s]

v1y = vmag*u[1] # v1y = y-component of the initial velocity [m/s]

v1z = vmag*u[2] # v1z = z-component of the initial velocity [m/s]

#

# Calculate the Cartesian components of the acceleration

#

a_x = qoverm*(Ex + v1y*Bz - v1z*By)

a_y = qoverm*(Ey + v1z*Bx - v1x*Bz)

a_z = qoverm*(Ez + v1x*By - v1y*Bx)

print ("The magnitude of the initial velocity is %.3e"%vmag," m/s.") ##Frem:Added brackets

print ("The x-component of the acceleration is %.3e"%a_x," m/s$^2$.") #Frem:Added brackets

print ("The y-component of the acceleration is %.3e"%a_y," m/s$^2$.") #Frem:Added brackets

print ("The z-component of the acceleration is %.3e"%a_z," m/s$^2$.") #Frem:Added brackets

time.sleep(10)##Frem:Added Time to prevent the program from closing too fast