• No results found

Practical and computational considerations

Chapter 2 Computational methods: Particle-In-Cell codes and higher

2.1.4 Practical and computational considerations

This gives the total field experienced by the particle as

Fi = 1 2Fj−1  1 2+ xj− xi ∆x 2 +Fj 3 4 − (xj− xi)2 (∆x)2 ! +Fj+1  1 2− xj− xi ∆x 2 (2.15)

For the third order splines used in EPOCH, these three terms have a different form and there are an additional two terms corresponding to Fj−2 and Fj+2. The same

procedure is used to extract particle quantities such as density and current to the grid. With the exception of some of the resolution testing simulations discussed in chapter3, all the PIC results shown in this thesis use third order splines.

Figure 2.2: Schematic of the first order tophat (blue) and second order triangular (red) shape functions used in the EPOCH PIC code. This figure has been reproduced from page 21 of the most recent EPOCH developers manual (at the time of writing).

2.1.4 Practical and computational considerations

Due to the nature of explicit finite difference schemes, the time-step must be chosen such that the CFL condition is satisfied in order to maintain stability. The CFL

condition in a 3D PIC code is:

∆t < (∆x)

2+ (∆y)2+ (∆z)21/2

c , (2.16)

where ∆x etc are the grid spacings in their respective grid directions, and c is the speed of light. In this work, only one dimension is considered, so Eq. 2.16 can be simplified. In practice, EPOCH implements this condition automatically, but it is the responsibility of the user to choose an appropriate grid spacing. A further time step restriction arises from the need to resolve the plasma frequency ωpe. EPOCH

selects the most restrictive of these timesteps, which in an MCF plasma, is usually that specified by the CFL condition. The user just needs to make sure it is small enough to resolve the physics of interest. Another serious issue one must consider when running a PIC code is the resolution of the Debye length λD within a warm

plasma

λD =

r 0kbTe

nee2

. (2.17)

If λD is not resolved by the grid spacing, the code will exponentially heat, increasing

the Debye length until it equals the width of the cell ∆x (which is specified by the user). This exponential heating is due to the acceleration of particles by a restoring electric field which is produced by charge density fluctuations resulting from the thermal noise. The relative change to a particles velocity is larger for plasma par- ticle with lower thermal speeds, and can cause serious problems, particularly if the growth rate of the physics under study is large, because the exponential heating may dominate the plasma dynamics in the initial stage of the simulation. For simulations using periodic boundary conditions, the resolution between successive modes in k- space is ∆k = π/L. If the modes of interest in a simulation are very close together in wavenumber space, one requires a small ∆k, hence a large simulation domain L, so as to resolve the relevant physics. For a given L, to resolve λD we require the

number of grid cells nx to be at least L/λD. For a plasma such as that found in the

centre of a tokamak, where ne is large, nx can therefore be very large. This restric-

tion is even more serious when we also consider the CFL condition. The timestep is directly proportional to ∆x in a 1D PIC code, meaning it must decrease as ∆x decreases. So for a given grid length L, if we can justify increasing the cell size by a factor two, we may get a factor four speed up in the computation of our problem. As we need to simulate less cells, and our timestep automatically doubles (assuming the CFL timstep is the most restrictive). It is easy to see why it may be tempting to push the cell size to be as large as possible, or conversely, reduce the plasma density

as much as possible. In practice, this effect can be ameliorated by using higher order particle shape functions (at increased computational cost), and/or smoothing the current J in the simulation [Arber et al.,2015]. Another consideration is the number of particles per cell. The finite size and the number of macro particles means there is noise in the electro-magnetic fields. This noise acts to heat the plasma, and must therefore be kept to a minimum. The noise scales as N−1/2, where N is the number of macro-particles per cell. Ideally, the number of macro-particles per cell would be equal to the number of physical particles, however this is not tractable. Doubling the number of particles per cell significantly increases the computational cost, but only reduces the noise in the simulation by a factor of√2. It is possible to reduce the noise levels by using higher order particle shape-functions, and/or by using the delta-f method, in which only changes in an equilibrium particle distribution are considered, as opposed to the entire distribution function. [Sydora,1999].

There are certain practical limitations one must consider when running a PIC simulation. It is unfeasible to write all available simulation data to disk at each time-step. To this end, data is written to disk periodically in “dumps”, it is the responsibility of the user to choose this period such that the physics can be resolved. If a simulation runs for say, ten ion gyroperiods, and we want to resolve 100 ion cyclotron frequencies in a temporal Fourier transform, then, because of the Nyquist theorem, there must be at least 2000 data dumps equally spaced in time. In general, the time between output dumps ∆tout will never be an exact multiple of the

simulation timestep ∆tsim. Output dump 1 may correspond to time t = 10∆tsim in

the simulation, whereas dump 2 is at time t = 21∆tsim, not t = 20∆tsim like we had

hoped. If we want to take temporal Fourier transforms, this can be problematic, leading to spurious artefacts because not only are we approximating our signal as a periodic, but our “dt” in our Fourier transform integral is effectively changing. This problem becomes less of an issue if ∆tsim << ∆tout, which can result in an

odd situation in which the user needs to force the timestep to be artificially small, increasing their computational expense significantly, just so they can get a reliable Fourier transform. This rarely happens in practice, and if it does, it is better to take a weighted average of data from multiple simulation timesteps and output this to disk. EPOCH does not currently have the functionality to do a weighted average of outputs, but it can do regular averages, which is usually sufficient. Aliasing is another important issue that must be considered before running a simulation. It is helpful to think of the 2D discrete Fourier transform as a box of frequencies and wavenumbers with finite area. The height of the box is the maximum resolvable frequency, and the width of the box is the maximum resolvable wavenumber. If

there is a wave in the simulation propagating with a large, positive group velocity, and this wave has no cut-off frequency, it will hit the top of the box and reflect back down into a region of lower frequency and higher wavenumber. Even if this wave is of no interest to us, it may then interact with some of the higher k modes, producing non-physical spectrally dense regions modes in the dispersion relation. It is then possible for said modes to further interact with other modes in the simulation. Before we know it, there is non-physical Fourier power everywhere. Data averaging between output dumps can help with this, or we can just make our box taller, by resolving a higher frequency, in the hope that when our uninteresting wave bounces back down, it does so in a region of k space of no interest to us. Even if the data is only written periodically and not at every time-step, the amount of disk space used when outputting particle data is often too much. The usual procedure is to write out the values of the field variables every chosen user time period, and to write out the particle quantities less frequently.

With all the above in mind, it is clear that to run PIC codes requires a kind of balancing act, between being able to accurately simulate the problem of interest, and being able to do so in a feasible amount of time, such is the case with most computational physics problems. The challenges associated with these problems are discussed in chapter3.

Related documents