Example #1
0
    def setke(self, ke, unit="ev"):
        """
        Scale the velocity vector with the speed corresponding to the given kinetic energy.
        Reinitializes the object.
        
        Parameters
        -----------
        ke : float
            The kinetic energy of the particle (eV by default). Can be relativistic.
        unit : str, optional
            The unit of the energy. If "ev", electron volts, otherwise Joule.
        
        """

        # Calculate the current pitch angle
        mc = self.mass*c
        t,x,y,z,ppar = self.trajectory[-1]
        B = self.field.magB(self.trajectory[-1,:4])          
        gammasq_minus_1 = 2*self.mu*B/(mc*c) + (ppar/mc)**2
        if np.sqrt(gammasq_minus_1 + 1) - 1 < 1e-6:  # nonrelativistic
            ptot = np.sqrt(2*self.mass*self.mu*B + ppar**2) # total momentum
        else:  # relativistic
            ptot = np.sqrt(gammasq_minus_1)*mc  # total momentum
        pa_old = np.arccos(ppar/ptot)
        
        # Find the new speed corresponding to the given relativistic energy
        v_new = ru.speedfromKE(ke, self.mass, unit)  # new speed
        
        # Reinitialize the guiding center
        self.__init__(pos=[x,y,z], v=v_new, pa=pa_old, t0=t,
                      mass=self.mass, charge=self.charge, field=self.field )
Example #2
0
    def setke(self, ke, unit="ev"):
        """
        Scale the velocity vector with the speed corresponding to the given kinetic energy.
        Reinitializes the object.
        
        Parameters
        -----------
        ke : float
            The kinetic energy of the particle (eV by default). Can be relativistic.
        unit : str, optional
            The unit of the energy. If "ev", electron volts, otherwise Joule.
        
        """

        # Calculate the current pitch angle
        mc = self.mass*c
        t,x,y,z,ppar = self.trajectory[-1]
        B = self.field.magB(self.trajectory[-1,:4])          
        gammasq_minus_1 = 2*self.mu*B/(mc*c) + (ppar/mc)**2
        if np.sqrt(gammasq_minus_1 + 1) - 1 < 1e-6:  # nonrelativistic
            ptot = np.sqrt(2*self.mass*self.mu*B + ppar**2) # total momentum
        else:  # relativistic
            ptot = np.sqrt(gammasq_minus_1)*mc  # total momentum
        pa_old = np.arccos(ppar/ptot)
        
        # Find the new speed corresponding to the given relativistic energy
        v_new = ru.speedfromKE(ke, self.mass, unit)  # new speed
        
        # Reinitialize the guiding center
        self.__init__(pos=[x,y,z], v=v_new, pa=pa_old, t0=t,
                      mass=self.mass, charge=self.charge, field=self.field )
Example #3
0
 def setke(self,ke, unit="ev"):
     """
     Scale the velocity vector with the speed corresponding to the given kinetic energy.
     Reinitializes the object.
     
     Parameters
     -----------
     ke : float
         The kinetic energy of the particle (eV by default). Can be relativistic.
     unit : str, optional
         The unit of the energy. If "ev", electron volts, otherwise Joule.
     
     """
     assert ke > 0        
     s = ru.speedfromKE(ke, self.mass, unit)
     mom = self.trajectory[-1,4:]
     gm = np.sqrt(self.mass**2 + np.dot(mom,mom)/c**2) # gamma * m
     v = mom/gm # velocity
     v = v*(s/np.sqrt(np.dot(v,v)))
     self.__init__(self.pos, v, self.t0, self.mass, self.charge, self.field)
Example #4
0
 def setke(self, ke, unit="ev"):
     """
     Scale the velocity vector with the speed corresponding to the given kinetic energy.
     Reinitializes the object.
     
     Parameters
     -----------
     ke : float
         The kinetic energy of the particle (eV by default). Can be relativistic.
     unit : str, optional
         The unit of the energy. If "ev", electron volts, otherwise Joule.
     
     """
     assert ke > 0
     s = ru.speedfromKE(ke, self.mass, unit)
     mom = self.trajectory[-1, 4:]
     gm = np.sqrt(self.mass**2 + np.dot(mom, mom) / c**2)  # gamma * m
     v = mom / gm  # velocity
     v = v * (s / np.sqrt(np.dot(v, v)))
     self.__init__(self.pos, v, self.t0, self.mass, self.charge, self.field)