# Simulating charge deflection in magnetic field

1. Nov 14, 2004

### brian0918

I eventually want to simulate cosmic ray propagation in a random magnetic field, but will start with a particle of some charge in a uniform field.

In order to simulate it, what I think needs to be done is to create a 3d array of points, with a value for the magnetic field magnitude and direction (all the same in a uniform field) at each point, and then define one of the points as being the starting point for a charge with a specific velocity and direction.

Does this sound like the right way to go so far?

So as the charge moves through the uniform magnetic field, it should trace out a circular path, correct?

I'm having trouble understanding a few things:

How is the particle's position and velocity defined in a discrete array of points such as this? Because the magnetic force is only evaluated (and thus only applied) if a particle hits one of the points, it seems like i could assign a path for the particle that would avoid most of the points in the array, thus giving an inaccurate result. Is this making any sense? I'm really confused about this.

How does the magnetic field vector at a given point in the array actually change the particle's direction? According to F=qVxB, the force will be perpendicular to the direction of the velocity, but it seems like the force is instantaneous, so the acceleration is instantaneous. How is the new direction of the velocity determined at this point?

Thanks.

2. Nov 14, 2004

### Tide

I don't think you would want to set up an array for all "points" in space. Rather, you deal with individual particles and compute their trajectories. If the magnetic field is uniform then you can explicitly write the trajectories and it becomes a simple matter of "plotting" them. Otherwise, you may have to resort to numerical solutions for the trajectories.

You accomplish that by finite differences and it will look something like this for each particle:

$$\vec v_{i+1} = \vec v_i + q \vec v_i \times \vec B(\vec x_i) \Delta t$$

$$\vec x_{i+1} = \vec x_i + \vec v_i \Delta t$$

That's the basic idea but you will have to refine the process since numerical errors tend to grow rather quickly. A good text on numerical methods will provide what you need.

3. Nov 14, 2004

### brian0918

How could this be done with a randomly distributed magnetic field, though?

The goal is to simulate cosmic ray propagation in the intergalactic magnetic field, which I don't think can simply be written down as B = ....

Thanks.

Last edited: Nov 14, 2004
4. Nov 14, 2004

### Tide

Whatever the magnetic field is the particle trajectories will be dictated by the Lorentz force. I think that before you proceed you should try to develop a clearer idea of exactly what it is that you want to accomplish. Also, what do you mean when you say "randomly distributed magnetic field?" You'll certainly require some knowledge of the fields before attempting any kind of simulation.

5. Nov 14, 2004

### brian0918

I've just been told that the magnetic field will be randomly distributed. I don't know what that means either. My first thought was that it would have to be done as I originally stated, with random vectors at points in an array, but that doesn't seem right.

In the equations you give, $$\Delta t$$ is a constant, correct? A timestep, I guess. Aren't the units on the velocity equation incorrect? Should the second term be divided by the mass of the particle?

Also, the magnitude of the velocity doesn't change, only the direction, correct? Does that agree with your iterative velocity equation?

Last edited: Nov 14, 2004
6. Nov 14, 2004

### Tide

brian,

Yes, the mass should appear there! I was focussing on the form you would use for numerical integration of the equations of motion. Also, the time step would ordinarily be a constant.

7. Nov 14, 2004

### brian0918

How could I fix the velocity equation so that the magnitude remains constant, but the direction changes? Would it work if I used the velocity equation you give, divide it by its magnitude, and multiply that unit vector by the original velocity's magnitude?

So, based on your equation, it would be $$\Vec v_{new} = |\Vec v_{i}| * (\Vec v_{i+1} / |\Vec v_{i+1}|)$$

8. Nov 14, 2004

### Tide

The Lorentz force itself will assure that the speed remains constant. You don't have to do anything special. However, since it is a numerical solution, you may use the fact that the speed is constant as a check on your algorithm! If you find the speed of your simulated particle changing then something is amiss with your algorithm.

9. Nov 14, 2004

### brian0918

But, in your velocity equation, you have v_i being added to another vector that isn't zero, so the direction and magnitude will change. For example, if v_i = <1,0,0> and the VxB part gives <0,1,0>, the new vector is <1,1,0> and its magnitude is no longer 1 but sqrt2.

10. Nov 14, 2004

### Tide

First, realize that those are vector equations. Also, the vxB part does NOT give <0 1 0>. You neglected the magnitude of the quantity including the delta t part - which is presumed "small!" Obviously, each component of the velocity will change with time but the speed will not.