In this article we’ll discuss how to integrate particle velocities in kinetic plasma simulations. This particle push is an extremely important part of the simulation process. It’s basically the engine that drives these codes. It results in the simulation macroparticles advancing to new positions in response to the forces acting on them. Our previous article on the particle in cell method briefly introduced this concept as well as the leapfrog method used to perform the integration. Here we expand on this topic.
First, let’s take a look at the governing equations. They are simply the definition of velocity
This second equation is basically Newton’s Second Law, with the force being the Lorentz Force. Of course, additional forces, such as gravitational, centripetal, and magnetic pressure force may also be present. Whether these are to be included will depend on the details of your problem, and the relative magnitude of the forces. However, generally the Lorentz force dominates, and the remaining forces are neglected. Our goal is to integrate this system in time.
v x B = 0 case
We will start by looking at the case where the second term in the Lorentz force drops out. This implies that either there is no magnetic field, or the particle motion is in direction parallel to the magnetic field line. We will discuss how to push particles in presence of magnetic field (v x B rotation) in the second part of this article. Here we have
Forward Difference Scheme
Integration of this equation appears to be trivial. We could take the velocity at some time “n” and use it to move the particle by a finite distance.
and implement it as (Equation 1):
/*grab electric field at current position*/
/*get new velocity at n+1*/
v2 = v + q/m*E*dt;
v2 = v + q/m*E*dt;
x2 = x + v*dt;
x2 = x + v*dt;
/*copy n+1 velocity to n*/
This solution is simple, but unfortunately, incorrect. To see why, let’s look at an even simpler example: a one dimensional oscillator around x. In plasma physics, such a solution could correspond to an electron oscillating around a stationary ion at the fundamental plasma frequency. Position, as a function of time, is given by . The analytical solution for velocity and acceleration is, and , respectively. We have an expression for acceleration. We want to integrate it, numerically, and retrieve the original expression. As a little aside, from the acceleration expression we see that the electric field for an oscillating particle is .
The forward difference method is implemented in the attached Excel spreadsheet. Excel can be quite handy for algorithm prototyping if you don’t have access to tools such as Matlab or it’s free clone, Octave. However, be careful of a bug in the Excel equation evaluator. Excel does not use correct operator precedence with powers, and -5^2 evaluates to 25, instead the correct -25. Such expressions need to be written as -(5^2).
Solution is plotted below in Figures 1a) and 1b). The first curve shows position versus time. The theoretical curve is shown in blue. We can see that the particle indeed oscillates between 1 and -1. What’s important is to note that the magnitude of the wave does not change over time. This is definitely not the case with the numerically obtained red dashed curve! Although the system is oscillating at the original frequency, the amplitude keeps increasing. This means that the particle is getting farther and farther from the center. In other words, the particle is gaining energy. But this is completely non-physical; this energy increase is purely numerical. Figure 1b) shows the same result on a velocity/position phase plot. Phase plots like these can often give us additional insight into the problem beyond the standard position vs time plots. In this case, the correct solution is an ellipse with the axis parallel to the coordinate system. Clearly, it should not be a spiral, as is the case for the numerical scheme.
What’s interesting is that this scheme will not give the correct result despite of how small a time step you use. Try it.
We can prove this analytically. The standard approach is to assume that the solution varies from one time step to another by a linear amplification factor g. We can then write
For stability, we want the magnitude of g to be less than or equal to 1. Otherwise the value of x will continue to grow and the solution will not converge. To solve for g, we rewrite Equation 1 in a matrix form as
One solution is the trivial solution, x=0 and v=0. But that’s not of much interest. Instead, we want to compute the null space (or kernel). You can check for yourself that this is analogous to solving for zero determinant, , or . The magnitude, regardless of how small a time step is selected. Hence, the upward difference method is inherently unstable.
The problem with the Forward Difference method arises from the fact that it uses velocity at time “n” to push the particle from “n” to “n+1″. What makes more physical sense is to use the average velocity, the velocity that would exist at time “n+1/2″. This is the premise of the leapfrog method. Velocity and position integration leap over each other, being displaced by half a time step. This is illustrated in Figure 2 below (this same figure was used in the article on the particle in cell method). In our implementation, particle positions exist at the integral time steps, while velocity exists at the half times. This introduces little difficulty into particle loading, since source sampling will result in velocity and position at the same time step. The usual method is integrate the velocity (but not position) of all newly loaded particles backwards through -0.5dt. The implementation then follows:
/*sample new particle*/
[x,v] = SampleParticle();
/*move velocity back by 0.5dt*/
E = EvalE(x);
v = v - 0.5*q/m*E*dt;
/*update velocity and position*/
E = EvalE(x);
v = v + q/m*E*dt;
x = x + v*dt;
Implementation of this method is shown in Figure 3. This time, the analytical expression is restored.
Figure 2. Schematic of the leapfrog method. Position is evaluated at integral time steps, while velocity is evaluated at half times.
We can compute the stability condition for the Leapfrog method using error analysis similar to what was done for the Forward method.
The characteristic equation obtained by setting the determinant to zero is . Using the quadratic formula, we obtain the solution to be
The system is stable only if the expression under the square root is less than 0. Then . Magnitude of this complex number is given by the complex conjugate, which in this case equals to 1. The system is therefore stable and neutral. In terms of the time step required, we obtain that for the Leapfrog Method, .
Don't forget to take a look at Part 2 for full implementation of particle push, including E and B fields.
integration.xlsx (numerical integration the harmonic oscillator)
Toshiki Tajima, Computational Plasma Physics, Westview Press, 2004.