Example #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)
Example #2
0
    def __init__(self,
                 pos=[],
                 v=None,
                 t0=0,
                 pa=None,
                 mass=None,
                 charge=None,
                 field=None):
        """
        Object constructor.
        
        Parameters
        ----------
        pos: list or array
            The initial position (x,y,z) of the particle, in meters.
        v: float
            The initial speed of the particle, in m/s.
        t0: float
            The time of simulation at the beginning (seconds).
        pa: float
            The initial pitch angle, in degrees
        mass: float
            The mass of the particle, in kg.
        charge: float
            The charge of the particle, in Coulombs.
        field: Field object
            The field object that provides electric and magnetic field vectors and
            related quantities.
        """
        self.pos = pos  # initial position array
        self.v = v  # speed of the particle
        self.t0 = t0
        self.tcur = t0  # current time
        self.mass = mass  # mass of the particle
        self.charge = charge  # charge of the particle
        self.field = field  # the field object
        self.isequatorial = False
        if not field.static:
            raise RuntimeError(
                "BounceCenter does not work with nonstatic fields or electric fields."
            )
            return None
        # The initial pitch angle:
        self.pa = pa

        if not (pos == [] or v == None
                or pa == None):  # if initial state is given explicitly
            self.trajectory = np.concatenate(([t0], pos))
            self.trajectory = np.reshape(self.trajectory, (1, 4))
            # the first invariant value (constant)
            self.mu = ru.magnetic_moment(t0, pos, self.v * np.cos(self.pa),
                                         self.v, field, mass)
            assert self.mu > 0
Example #3
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)
Example #4
0
 def __init__(self, pos=[], v=None, t0=0, pa=None, mass=None, charge=None, field=None):
     """
     Object constructor.
     
     Parameters
     ----------
     pos: list or array
         The initial position (x,y,z) of the particle, in meters.
     v: float
         The initial speed of the particle, in m/s.
     t0: float
         The time of simulation at the beginning (seconds).
     pa: float
         The initial pitch angle, in degrees
     mass: float
         The mass of the particle, in kg.
     charge: float
         The charge of the particle, in Coulombs.
     field: Field object
         The field object that provides electric and magnetic field vectors and
         related quantities.
     """
     self.pos = pos  # initial position array
     self.v = v    # speed of the particle
     self.t0 = t0
     self.tcur = t0     # current time
     self.mass = mass  # mass of the particle
     self.charge = charge  # charge of the particle
     self.field = field  # the field object
     self.isequatorial = False
     if not field.static:
         raise RuntimeError("BounceCenter does not work with nonstatic fields or electric fields.")
         return None
     # The initial pitch angle:
     self.pa = pa
     
     if not (pos==[] or v==None or pa==None): # if initial state is given explicitly
         self.trajectory = np.concatenate(([t0], pos))
         self.trajectory = np.reshape(self.trajectory, (1,4))
         # the first invariant value (constant)
         self.mu = ru.magnetic_moment(t0, pos, self.v*np.cos(self.pa), self.v, field, mass)
         assert self.mu>0
Example #5
0
    def __init__(self, pos=[], v=0, pa=None, ppar=None, t0=0, mass=None, charge=None, field=None):
        """
        Object constructor.
        
        Parameters
        ----------
        pos: list or array
            The initial position (x,y,z) of the particle, in meters.
        v: float
            The initial speed of the particle, in m/s.
        pa: float
            The initial pitch angle, in degrees (not needed if ppar is given)
        ppar: float
            The initial parallel momentum, in kg m/s (not needed if pa is given)
        t0: float
            The time of simulation at the beginning (seconds), ignored for fields that do not depend on time.
        mass: float
            The mass of the particle, in kg.
        charge: float
            The charge of the particle, in Coulombs.
        field: Field object
            The field object that provides electric and magnetic field vectors and related quantities.
        
        See Also
        --------
        init
        
        Notes
        -----
        All parameters above are optional. The object can be initialized with
        an empty parameter set if it is going to be initialized differently
        (e.g. with `init` method)
        
        
        """
        # pos: initial position (array of 3)
        # v: initial speed (scalar)
        # pa: initial pitch angle
        # ppar = initial parallel momentum
        #     (N.B. Either pa or ppar should be provided. If both given, pa is used.)
        # t0: initial time
        # mass: particle mass in kg
        # charge: particle charge in C
        # field: The field object
    
        self.pos = pos  # initial position array
        self.v = v

        self.t0 = t0 # initial time
        self.tcur = t0    # current time
        self.mass = mass  # mass of the particle
        self.charge = charge  # charge of the particle
        self.field = field
        self.trajectory = np.zeros((1,5))
        self.check_adiabaticity = False
        # The object can be initialized two ways:
        # Either by specifying the initial conditions,
        # or by an empty call, to be initialized later by another object.
        # We consider the call empty when pos and v are not specified.
        
        if not (pos==[] or v==0): # if initial state is given explicitly
            gamma = 1/np.sqrt(1-(v/c)**2)
            if pa != None:
                vpar = 0 if pa==90 else v * np.cos(pa*np.pi/180)
                ppar = gamma*mass*vpar

            self.mu = ru.magnetic_moment(self.tcur, self.pos, ppar/(mass*gamma),
                                         self.v, self.field, self.mass)
            self.trajectory[0,0] = t0
            self.trajectory[0,1:4] = pos[:]
            self.trajectory[0,4] = ppar
Example #6
0
    def __init__(self, pos=[], v=0, pa=None, ppar=None, t0=0, mass=None, charge=None, field=None):
        """
        Object constructor.
        
        Parameters
        ----------
        pos: list or array
            The initial position (x,y,z) of the particle, in meters.
        v: float
            The initial speed of the particle, in m/s.
        pa: float
            The initial pitch angle, in degrees (not needed if ppar is given)
        ppar: float
            The initial parallel momentum, in kg m/s (not needed if pa is given)
        t0: float
            The time of simulation at the beginning (seconds), ignored for fields that do not depend on time.
        mass: float
            The mass of the particle, in kg.
        charge: float
            The charge of the particle, in Coulombs.
        field: Field object
            The field object that provides electric and magnetic field vectors and related quantities.
        
        See Also
        --------
        init
        
        Notes
        -----
        All parameters above are optional. The object can be initialized with
        an empty parameter set if it is going to be initialized differently
        (e.g. with `init` method)
        
        
        """
        # pos: initial position (array of 3)
        # v: initial speed (scalar)
        # pa: initial pitch angle
        # ppar = initial parallel momentum
        #     (N.B. Either pa or ppar should be provided. If both given, pa is used.)
        # t0: initial time
        # mass: particle mass in kg
        # charge: particle charge in C
        # field: The field object
    
        self.pos = pos  # initial position array
        self.v = v

        self.t0 = t0 # initial time
        self.tcur = t0    # current time
        self.mass = mass  # mass of the particle
        self.charge = charge  # charge of the particle
        self.field = field
        self.trajectory = np.zeros((1,5))
        self.check_adiabaticity = False
        # The object can be initialized two ways:
        # Either by specifying the initial conditions,
        # or by an empty call, to be initialized later by another object.
        # We consider the call empty when pos and v are not specified.
        
        if not (pos==[] or v==0): # if initial state is given explicitly
            gamma = 1/np.sqrt(1-(v/c)**2)
            if pa != None:
                vpar = 0 if pa==90 else v * np.cos(pa*np.pi/180)
                ppar = gamma*mass*vpar

            self.mu = ru.magnetic_moment(self.tcur, self.pos, ppar/(mass*gamma),
                                         self.v, self.field, self.mass)
            self.trajectory[0,0] = t0
            self.trajectory[0,1:4] = pos[:]
            self.trajectory[0,4] = ppar