Exemple #1
0
 def mu(self):
     """Return a 1-d array of the magnetic moment values along the trajectory."""
     out = []
     for row in self.trajectory:
         t, r, mom = row[0], row[1:4], row[4:]
         gm = np.sqrt(self.mass**2 + np.dot(mom,mom)/c**2) # gamma * mass
         v = mom/gm
         rgc, vp, spd = ru.guidingcenter(t, r, v, self.field, self.mass, self.charge)
         out.append(ru.magnetic_moment(t, rgc, vp, spd, self.field, self.mass))
     return np.array(out)
Exemple #2
0
 def guidingcenter(self):
     """Return a 2-d array of guiding center positions corresponding to particle positions."""
     out = []
     for row in self.trajectory:
         t,r,mom = row[0], row[1:4], row[4:]
         gm = np.sqrt(self.mass**2 + np.dot(mom,mom)/c**2) # gamma * mass
         v = mom/gm
         rgc, vp, spd = ru.guidingcenter(t, r, v, self.field, self.mass, self.charge)
         out.append(list(rgc)+[vp,spd])
     return np.array(out)
Exemple #3
0
 def init(self, p):
     """
     Initialize a Particle using the state of another Particle or GuidingCenter object.
     
     Parameters
     -----------
     p : Particle or GuidingCenter object.
         The object that is used to initialize the current GuidingCenter.
     
     Notes
     -----
     Takes the last state (position and momentum) of the given `Particle`
     or `GuidingCenter`, sets the initial conditions of self to match them,
     and runs `__init__` again. Therefore, all existing data is erased.
     
     """
     from rapt import Particle # Import here to avoid circular imports. 
     if isinstance(p, GuidingCenter):
         B = p.field.magB(p.trajectory[-1,:4])            
         gamma = np.sqrt(1 + 2*p.mu*B/(p.mass*c*c) + (p.trajectory[-1,4]/p.mass/c)**2)
         if gamma-1 < 1e-6: # nonrelativistic
             v = np.sqrt(2*p.mu*B/p.mass + (p.trajectory[-1,4]/p.mass)**2)
         else:
             v = c * np.sqrt(1-1/gamma**2)
         self.__init__(pos = p.trajectory[-1,1:4],
                       v = v,
                       ppar = p.trajectory[-1,4],
                       t0 = p.trajectory[-1,0],
                       mass = p.mass, 
                       charge = p.charge,
                       field = p.field)
         self.check_adiabaticity = p.check_adiabaticity
             
     elif isinstance(p, Particle):
         mom = p.trajectory[-1,4:]
         gm = np.sqrt(p.mass**2 + np.dot(mom,mom)/c**2) # gamma * m
         vel = mom/gm # velocity
         pos, vp, v = ru.guidingcenter(p.trajectory[-1,0],
                                       p.trajectory[-1,1:4],
                                       vel, 
                                       p.field, 
                                       p.mass,
                                       p.charge)
         gamma = 1 / np.sqrt(1-(v/c)**2)
         self.__init__(pos = pos,
                       v = v,
                       ppar = p.mass*gamma*vp,
                       t0 = p.trajectory[-1,0],
                       mass = p.mass, 
                       charge = p.charge,
                       field = p.field)
         self.check_adiabaticity = p.check_adiabaticity
     else:
         raise(ValueError, "Particle or GuidingCenter objects required.")
Exemple #4
0
 def init(self, p):
     """
     Initialize a Particle using the state of another Particle or GuidingCenter object.
     
     Parameters
     -----------
     p : Particle or GuidingCenter object.
         The object that is used to initialize the current GuidingCenter.
     
     Notes
     -----
     Takes the last state (position and momentum) of the given `Particle`
     or `GuidingCenter`, sets the initial conditions of self to match them,
     and runs `__init__` again. Therefore, all existing data is erased.
     
     """
     from rapt import Particle # Import here to avoid circular imports. 
     if isinstance(p, GuidingCenter):
         B = p.field.magB(p.trajectory[-1,:4])            
         gamma = np.sqrt(1 + 2*p.mu*B/(p.mass*c*c) + (p.trajectory[-1,4]/p.mass/c)**2)
         if gamma-1 < 1e-6: # nonrelativistic
             v = np.sqrt(2*p.mu*B/p.mass + (p.trajectory[-1,4]/p.mass)**2)
         else:
             v = c * np.sqrt(1-1/gamma**2)
         self.__init__(pos = p.trajectory[-1,1:4],
                       v = v,
                       ppar = p.trajectory[-1,4],
                       t0 = p.trajectory[-1,0],
                       mass = p.mass, 
                       charge = p.charge,
                       field = p.field)
         self.check_adiabaticity = p.check_adiabaticity
             
     elif isinstance(p, Particle):
         mom = p.trajectory[-1,4:]
         gm = np.sqrt(p.mass**2 + np.dot(mom,mom)/c**2) # gamma * m
         vel = mom/gm # velocity
         pos, vp, v = ru.guidingcenter(p.trajectory[-1,0],
                                       p.trajectory[-1,1:4],
                                       vel, 
                                       p.field, 
                                       p.mass,
                                       p.charge)
         gamma = 1 / np.sqrt(1-(v/c)**2)
         self.__init__(pos = pos,
                       v = v,
                       ppar = p.mass*gamma*vp,
                       t0 = p.trajectory[-1,0],
                       mass = p.mass, 
                       charge = p.charge,
                       field = p.field)
         self.check_adiabaticity = p.check_adiabaticity
     else:
         raise(ValueError, "Particle or GuidingCenter objects required.")
Exemple #5
0
 def guidingcenter(self):
     """Return a 2-d array of guiding center positions corresponding to particle positions."""
     out = []
     for row in self.trajectory:
         t, r, mom = row[0], row[1:4], row[4:]
         gm = np.sqrt(self.mass**2 +
                      np.dot(mom, mom) / c**2)  # gamma * mass
         v = mom / gm
         rgc, vp, spd = ru.guidingcenter(t, r, v, self.field, self.mass,
                                         self.charge)
         out.append(list(rgc) + [vp, spd])
     return np.array(out)
Exemple #6
0
 def mu(self):
     """Return a 1-d array of the magnetic moment values along the trajectory."""
     out = []
     for row in self.trajectory:
         t, r, mom = row[0], row[1:4], row[4:]
         gm = np.sqrt(self.mass**2 +
                      np.dot(mom, mom) / c**2)  # gamma * mass
         v = mom / gm
         rgc, vp, spd = ru.guidingcenter(t, r, v, self.field, self.mass,
                                         self.charge)
         out.append(
             ru.magnetic_moment(t, rgc, vp, spd, self.field, self.mass))
     return np.array(out)