%matplotlib inline
import pylab as pl
pl.rcParams['figure.figsize'] = (12.0, 9.0)
pl.style.use("ggplot")
import rapt
from numpy import pi
Initialize the field object
f = rapt.fields.DoubleDipole()
g = rapt.GuidingCenter(pos=(0, -10*rapt.Re,0),
v = rapt.utils.speedfromKE(1e5, rapt.m_el), # electron kinetic energy 100keV
pa = 80,
mass = rapt.m_el,
charge = -rapt.e,
field = f)
g.advance(200)
pl.plot(g.gettheta()/pi*180, 90-g.getphi()/pi*180)
pl.xlabel("longitude")
pl.ylabel("latitude")
pl.title("Electron at 10 Re");
pl.plot(g.gett(), g.getke())
[<matplotlib.lines.Line2D at 0x7f81a82e99e8>]
How well do a GuidingCenter
trajectory agree with a Particle
initialized with the same conditions?
Not that the Particle corresponding to a GuidingCenter does not start at the same position in space, but it must be shifted by the gyroradius. The init
method of the Particle class takes this into account.
g = rapt.GuidingCenter(pos=(0, -10*rapt.Re,0),
v = rapt.utils.speedfromKE(1e6, rapt.m_el),
pa = 80,
mass = rapt.m_el,
charge = -rapt.e,
field = f)
p = rapt.Particle() # create the Particle object without specifying any parameters
p.init(g) # Initialize the Particle object using the existing GuidingCenter object
g.advance(10)
p.advance(10)
pl.plot(g.gettheta()/pi*180, 90-g.getphi()/pi*180)
pl.plot(p.gettheta()/pi*180, 90-p.getphi()/pi*180)
pl.xlabel("longitude")
pl.ylabel("latitude")
pl.title("Electron particle and guiding-center trajectories");
Similarly, a GuidingCenter can be initialized with an existing Particle object.
g2 = rapt.GuidingCenter()
g2.init(p) # initialized with the last state of p
g2.advance(10)
g.advance(10) # Compare with the original GuidingCenter
pl.plot(g.gettheta()/pi*180, 90-g.getphi()/pi*180,"x-") # Original guiding center marked with x
pl.plot(p.gettheta()/pi*180, 90-p.getphi()/pi*180)
pl.plot(g2.gettheta()/pi*180, 90-g2.getphi()/pi*180,"o-") # New guiding center marked with o
pl.xlabel("longitude")
pl.ylabel("latitude")
pl.title("Electron particle and guiding-center trajectories");