# Chapter 10 Atomistic and Particle-in-Cell Simulation

When motivating the Boltzmann equation it was argued that there are too many particles for us to track them all, so we had to use a distribution function approach. However, for some purposes, the number of particles that need to be tracked can in fact be managable. In that case, we can adopt a computational modelling approach that is called generically Atomistic Simulation. In short, it involves time-advancing individual classical particles obeying Newton's laws of motion (or in some relativistic cases Einstein's extensions of them).
There are also situations where it is advantageous to solve Boltmann's equation by a method that uses pseudo-particles, each of them representative of a large number of individual particles. These pseudo-particles are modelled as if they were real particles. We'll come to this broader topic in a later section, for now just think of real particles.

## 10.1  Atomistic Simulation

If the particles are literally atoms or molecules, then since we will find it increasingly computationally difficult to track more than, say, a few billion of them, the volume of material that can be modelled is limited. A billion is ${10}^{9}={1000}^{3}$; so we could at most model a three-dimensional crystal lattice roughly 1000 atoms on a side. For a solid, that means the size of the region we can model is perhaps 100 nm. Nanoscale. There's no way that we are going to atomistically model a macroscopic (say 1 mm) piece of material globally with forseeable computational capacity. Still, many very interesting and important phenomena relating to solid defects, atomic displacement due to energetic particle interactions, cracking, surface behavior, and so on, occur on the 100 nm scale. Materials behavior and design is a very important area for this direct atomic or molecular simulation.
The timescale in atomic interactions ranges from, say, the time it takes a gamma ray to cross a nucleus $~{10}^{-23}$s to geological times of $~{10}^{14}$s. Modelling must choose a managable fraction of this enormous range, because the particle time-steps must be shorter than the fastest phenomenon to be modelled, and yet we can only afford to compute a moderate number of steps, maybe routinely as many as ${10}^{4}$, but not usually ${10}^{6}$, and only heroically ${10}^{8}$. Phenomena outside our time-scale of choice have to be either irrelevant or represented by simplified representations of their effects in our modelling time-scale. Fig. 10.1 illustrates the computationally feasible space and time-scale region (shaded) indicating the approximate location of a few key phenomena. Figure 10.1: Approximate space and time scales for Molecular Dynamics atomistic simulation of condensed matter. Molecular vibration must be accommodated. Then computations of heroic effort are required to explore many orders of magnitude above it.
For materials modelling where we are considering atoms whose thermal velocities are perhaps $1000$m/s, moving over lengths perhaps ${10}^{-7}$m, the required rough time duration is ${10}^{-10}$s for molecular transit. This is far longer than the characteristic time of motion of electrons within the atoms themselves, which is approximately the atomic size ${10}^{-10}$m divided by the electron velocity at say 10eV energy ${10}^{6}$m/s: a time of ${10}^{-16}$s for electronic configuration. This 1 million factor time range is too great to span routinely. So atomistic modelling usually needs to represent the atomic physics of the electron configurations in molecules in some averaged approximate way. This representation can sometimes be calculated on the basis of numerical solution of quantum mechanics, but we won't address that aspect of the problem. On the other hand, the motions of the atomic nuclei arising from molecular vibrations has typical timescale $~{10}^{-13}$s: at least 1000 times longer than electrons. This is managable, and indeed must be resolved, if the dynamics of a lattice are to be modelled. Figure 10.2: Example of a crystal lattice atomistic simulation in three dimensions. Study of a region of nanocrystaline metal with 840,000 atoms ready to be deformed. (Courtesy: Ju Li, Massachusetts Institute of Technology.)
Atomistic modelling therefore represents the interatomic forces arising from electron orbital interactions only approximately, as time averages over electronic orbits or oscillations. But it follows the atoms themselves in their motions in response to the interatomic forces. The atoms are represented as classical particles interacting via a force field. This approach is sometimes called Molecular Dynamics. It dates from as early as 1956${}^{61}$. A modern example is shown in Fig. 10.2.
The way a simulation works then is in outline
 1 Calculate the force at current position $\mathbit{x}$ on each particle due to all the others. 2 Accelerate and move particles for $\mathit{\Delta }t$, getting new velocities $\mathbit{v}$ and positions $\mathbit{x}$. 3 Repeat from 1.
Generally a fast second order accurate scheme for the acceleration and motion (stage 2) is needed. One frequently used is the leap-frog scheme. Another is called the Verlet scheme, which can be expressed as
 $\begin{array}{ccc}\multicolumn{1}{c}{{\mathbit{x}}_{n+1}}& =\hfill & {\mathbit{x}}_{n}+{\mathbit{v}}_{n}\mathit{\Delta }t+{\mathbit{a}}_{n}\mathit{\Delta }{t}^{2}/2\hfill \\ \multicolumn{1}{c}{{\mathbit{v}}_{n+1}}& =\hfill & {\mathbit{v}}_{n}+\left({\mathbit{a}}_{n}+{\mathbit{a}}_{n+1}\right)\mathit{\Delta }t/2\hfill & \hfill \left(10.1\right)\end{array}$

where ${\mathbit{a}}_{n}$ is the acceleration corresponding to position ${\mathbit{x}}_{n}$.${}^{62}$
We also usually need to store a record of where the particles go, since that is the major result of our simulation. And we need methods to analyse and visualize the large amount of data that will result: the number of steps ${N}_{t}$ times the number of particles ${N}_{p}$ times at least 6 (3 space, and 3 velocity) components.

### 10.1.1  Atomic/Molecular Forces and Potentials

The simplest type of forces, but still useful for a wide range of physical situations, are particle-pair attraction and repulsion. Such forces act along the vector $\mathbit{r}={\mathbit{x}}_{1}-{\mathbit{x}}_{2}$ between the particle positions, and have a magnitude that depends only upon the distance $r=|{\mathbit{x}}_{1}-{\mathbit{x}}_{2}|$ between them. An example might be the inverse-square electric force between two charges ${q}_{1}$ and ${q}_{2}$, $\mathbit{F}=\left({q}_{1}{q}_{2}/4\mathit{\pi }{\mathit{\epsilon }}_{0}\right)\mathbit{r}/{r}^{3}$. But for atomistic simulation more usually neutral particles are being modelled whose force changes from mutual attraction at longer distances to mutual repulsion at short distances. (a) (b)
Figure 10.3: Potential and corresponding force forms for (a) Lennard-Jones (eq. 10.2) and (b) Morse (eq.  10.3) expressions.
A very common form of interatomic potential that gives this kind of attraction and repulsion is the Lennard-Jones (12:6) potential (see Fig. 10.3(a))
 $\mathbit{F}=-\nabla U\mathrm{ }\text{with}\mathrm{ }U={E}_{0}\left[{\left(\frac{{r}_{0}}{r}\right)}^{12}-2{\left(\frac{{r}_{0}}{r}\right)}^{6}\right]$ $\left(10.2\right)$
A simplicity, but also a weakness, in the Lennard-Jones form is that it depends upon just two parameters, the typical energy ${E}_{0}$, and the typical distance ${r}_{0}$. The equilibrium distance, corresponding to where the force ($-\mathit{dU}/\mathit{dr}$) is zero is, is ${r}_{0}$. At this spacing the binding energy is ${E}_{0}$. The maximum attractive force occurs where ${d}^{2}U/{\mathit{dr}}^{2}=0$, which is $r=1.109{r}_{0}$ and it has magnitude $2.69{E}_{0}/{r}_{0}$. The weakness of having only two parameters is that the spring-constant for the force, ${d}^{2}U/{\mathit{dr}}^{2}$, near the the equilibrium position cannot be set independent of the binding energy. An alternative force expression that allows this independence, by having three parameters, is the Morse form
 $U={E}_{0}\left({e}^{-2\mathit{\alpha }\left(r-{r}_{0}\right)}-2{e}^{-\mathit{\alpha }\left(r-{r}_{0}\right)}\right).$ $\left(10.3\right)$
Its force is zero at ${r}_{0}$, where the binding energy is ${E}_{0}$; but the spring constant there can be adjusted using the parameter $\mathit{\alpha }$. See Fig. 10.3(b).
These simple two-particle, radial-force, forms omit several phenomena that are important in molecular interactions in nature. These additional phenomena include higher order potential interactions, represented by the total potential energy of the entire assembly being given as a heirarchy of sums of multiple-particle interactions
 $U=\sum _{i}{U}_{1}\left({\mathbit{x}}_{i}\right)+\sum _{\mathit{ij}}{U}_{2}\left({\mathbit{x}}_{i},{\mathbit{x}}_{j}\right)+\sum _{\mathit{ijk}}{U}_{3}\left({\mathbit{x}}_{i},{\mathbit{x}}_{j},{\mathbit{x}}_{k}\right)+\dots$ $\left(10.4\right)$
where the subscripts $i,j,\dots$ refer to different particles. The force on a particular particle $l$ is then $-\frac{\partial }{\partial {\mathbit{x}}_{l}}U$. The first term ${U}_{1}$ represents a background force field. The second represents the pairwise force that we've so far been discussing. We've been considering the particular case where ${U}_{2}$ depends only on $r=|{\mathbit{x}}_{i}-{\mathbit{x}}_{j}|$. The third (and higher) terms represent possible multi-particle correlation forces. They are often called "cluster" potential terms.
Other force laws between multi-atom molecules might include the orientation of the molecule bonds. In that case, internal orientation parameters would have to be introduced or else the molecule's individual atoms themselves represented by particles whose bonds are modelled using force laws appropriate to them. They could be represented as a third or probably at least fourth order series for the potential.

### 10.1.2  Computational requirements

If there are ${N}_{p}$ particles, then to evaluate the force on particle $i$ from all the other particles $j$, requires ${N}_{p}$ force evaluations for pair-forces (${U}_{2}$ term). It requires ${N}_{p}^{2}$ for three-particle (${U}_{3}$) terms and so on. The force calculation needs to be done for all the particles at each step, so if we include even just the pair-forces for all particles, ${N}_{p}^{2}$ force terms must be evaluated. This is too much. For example, a million particles would require ${10}^{12}$ pair force evaluations per time step. Computational resources would be overwhelmed. Therefore the most important enabling simplification of a practical atomistic simulation is to reduce the number of force evaluations till it is not much worse than linear in ${N}_{p}$. This can be done by taking advantage of the fact that the force laws between neutral atoms have a rather short range; so the forces can be ignored for particle spacings greater than some modest length. In reality we only need to calculate the force contributions from a moderately small number of nearby particles on each particle $i$. It is not sufficient to look at the position of all the other particles at each step and decide whether they are near enough to worry about. That decision is itself an order ${N}_{p}$ cost per particle (${N}_{p}^{2}$ total). Even if it's a bit cheaper than actually evaluating the force, it won't do. Instead we have to keep track, in some possibly approximate way, of which of the other particles are close enough to the particle $i$ to matter to it.
There are broadly two ways of doing this. Either we literally keep a list of near neighbors associated with each particle. Or else we divide up the volume under consideration into much smaller blocks and adopt the policy of only examining the particles in its own block and the neighboring blocks. Either of these will obviously work for a crystal lattice type problem, modelling a solid, because the atoms hardly ever change their nearest neighbors, or the members of blocks. But in liquids or gases the particles can move sufficiently that their neighbors or blocks are changing. To recalculate which particles are neighbors costs $~{N}_{p}^{2}$. However, there are ways to avoid having to do the neighbor determination every step. If we do it rarely enough, we reduce the cost scaling.
Neighbor List Algorithm   A common way to maintain an adequately accurate neighbor list is as follows. See Fig. 10.4. (a) (b)
Figure 10.4: Neighbor List (a), and Block (b), algorithms enable testing only nearby particles for force influence. The neigbors whose influence must be calculated are inside the radius ${r}_{l}$ or inside the shaded region.
Suppose ${r}_{c}$ is the cutoff radius beyond which interparticle forces are negligible. For each particle $i$, designate as neighbors particles within a larger sphere $|{\mathbit{x}}_{j}-{\mathbit{x}}_{i}|=r<{r}_{l}$. Suppose the fastest speed a particle has is ${v}_{\mathit{max}}$; then we know that no particle, starting from outside the sphere ${r}_{l}$, can reach the sphere ${r}_{c}$ in less than a time $\left({r}_{l}-{r}_{c}\right)/{v}_{\mathit{max}}$, that is, in fewer timesteps than ${N}_{l}=\left({r}_{l}-{r}_{c}\right)/{v}_{\mathit{max}}\mathit{\Delta }t$. Consequently, we need to update the neighbor lists only every ${N}_{l}$ steps. The average neighbor list cost per step is ${N}_{p}^{2}/{N}_{l}$. This is smaller than ${N}_{p}^{2}$, and if ${N}_{l}$ is large (because the maximum velocity is small), much smaller. However, it is still of order ${N}_{p}^{2}$.${}^{63}$
Block Algorithm   If the domain is divided into a large number of blocks, each of which is bigger than the cutoff radius, then we need to examine only particles that are in the same block or an adjacent block. Adjacent blocks must be examined because a particle near the boundary of a block might be influenced by particles just the other side of that boundary. Suppose there are ${N}_{b}$ blocks. They contain on average ${N}_{p}/{N}_{b}$ particles each. As the size of the computational region increases, we can keep this ratio constant. The total number of neighboring particles we need to examine for each particle $i$ is (in three dimensions) ${3}^{3}{N}_{p}/{N}_{b}\propto \mathit{const}.$ Thus, this block algorithm's step cost is $\propto {N}_{p}$, linear in the number of particles. But the constant of proportionality might be quite large. There is also an interesting question as to how the list of particles in a block is maintained. One way to do this is to use a linked list of pointers. However, such a linked list does not lend itself readily to parallel data implementations, and there are interesting forefront research questions as to the best practical way of solving this problem.

## 10.2  Particle in Cell Codes

If the interparticle force law is of infinite range, as it is, for example, with the inverse-square interactions of charged particles in a plasma, or gravitating stars, then the near-neighbor reduction of the force calculation does not work, because there is no cutoff radius beyond which the interaction is negligible. This problem is solved in a different way, by representing the long-range interactions as the potential on a mesh of cells. This approach is called "Particle in Cell" or PIC${}^{64}$.
Consider, for simplicity, a single species of charged particles (call them electrons) of charge $q$ ($=-e$ for electrons, of course), and mass $m$. Positive ions could also be modelled as particles, but for now take them to be represented by a smooth neutralizing background of positive charge density $-{n}_{i}q$. The electrons move in a region of space divided into cells labelled with index $j$ at positions ${x}_{j}$. [Most modern PIC production codes are multidimensional, but the explanations are easier in one dimension.] They give rise to an electric potential $\mathit{\phi }$. Ignoring the discreteness of the individual electrons, there is a smoothed-out total (sum of electron and ion) charge density ${\mathit{\rho }}_{q}\left(x\right)=q\left[n\left(x\right)-{n}_{i}\right]$. The potential satisfies Poisson's equation
 ${\nabla }^{2}\mathit{\phi }=\frac{{d}^{2}\mathit{\phi }}{{\mathit{dx}}^{2}}=-\frac{{\mathit{\rho }}_{q}}{{\mathit{\epsilon }}_{0}}=-\frac{q\left[n\left(x\right)-{n}_{i}\right]}{{\mathit{\epsilon }}_{0}}$ $\left(10.5\right)$
We represent this potential discretely on the mesh: ${\mathit{\phi }}_{i}$ and solve it numerically using a standard elliptic solver. The only new feature is that we need to obtain a measure of smoothed-out density on the mesh. We do this by assigning the charge density of the individual electrons to the mesh in a systematic way. The simplest way to assign it is to say that each electron's charge is assigned to the Nearest Grid Point NGP. That's equivalent to saying each electron is like a rod of length equal to the distance $\mathit{\Delta }x$ between the grid points, and it contributes charge density equal to $q/\mathit{\Delta }x$ from all positions along its length. See Fig. 10.5. The volume of the cell is $\mathit{\Delta }x$ and the electron density is equal to the number of particles whose charge is assigned to that cell divided by the cell volume. Figure 10.5: Effective shapes for the NGP and CIC charge assignments.
Usually a continuous linear interpolation is preferred, called the Cloud In Cell CIC assignment. The charge density assigned from each electron is equal to $q/\mathit{\Delta }x$ when the electron is exactly at ${x}_{j}$, and falls linearly, reaching zero when the particle is at ${x}_{j±1}$. Thus the electron is like a rod of length $2\mathit{\Delta }x$ whose charge distribution is triangular.
The way the particle in cell code runs is this.
 1 Assign the charge from all the particles onto the grid cells. 2 Solve Poisson's equation to find the potential ${\mathit{\phi }}_{j}$. 3 For each particle, find $\nabla \mathit{\phi }$ at its position, ${x}_{i}$, by interpolation from the ${x}_{j}$. 4 Accelerate, by the corresponding force, and move the particles. 5 Repeat from 1.
This process will simulate the behavior of the plasma accounting realistically for the particle motion. So it is a kind of atomistic simulation. Fig. 10.6 shows an illustration of an example in a spherical computational domain. Figure 10.6: A curved grid (relatively unusual for PIC) shaded to represent the density normalized to the distant value. A few representative particle orbits in the vicinity of a spherical object are shown, and arrows indicate the mean ion velocity.
Why introduce this cell mesh? Because this approach is computationally far more efficient than adding up the inverse square law forces between individual particles. An atomistic pair-force approach costs $~{N}_{p}^{2}$ per step. By contrast the particle moving stage, once the force is known is $~{N}_{p}$. If the potential grid has a total of ${N}_{g}$ points, then an efficient iterative Poisson solution costs $~{N}_{g}{N}_{g}^{1/{N}_{d}}$ per step, in ${N}_{d}$ dimensions${}^{65}$, or can be done by tridiagonal elimination in $~{N}_{g}$ operations in one dimension. Generally the number of particles per cell is fairly large, so ${N}_{g}$ is much smaller than ${N}_{p}$ and the Poisson cost scales linearly or nearly linearly with ${N}_{g}$. Therefore for practical purposes, the costs are dominantly those of interpolating the electric field to the particle and moving it: an order ${N}_{p}$ cost, not ${N}_{p}^{2}$ like the pair-force approach.
Sometimes the dynamics of the ions is just as important to model as the electrons. Then the ions must be treated through the PIC approach as a second species of particles obeying Newton's law. Actually it is sometimes advantageous to treat only the ions this way, and treat electrons as a continuum whose density is a known function of $\mathit{\phi }$. The latter approach is often called "Hybrid" PIC.

### 10.2.1  Boltzmann Equation Pseudoparticle Representation

In a particle in cell code, the particles move and are tracked in phase-space: $\left(\mathbit{x},\mathbit{v}\right)$ is known at each time-step. A particle's equation of motion in phase space is
 $\frac{d}{\mathit{dt}}\left(\genfrac{}{}{0}{}{\mathbit{x}}{\mathbit{v}}\right)=\left(\genfrac{}{}{0}{}{\mathbit{v}}{\mathbit{a}}\right).$ $\left(10.6\right)$
This is also the equation of motion of the characteristics of the Boltzmann equation (8.12,8.13). Thus advancing a PIC code with ${N}_{p}$ particles is equivalent to integrating along ${N}_{p}$ characteristics of the Boltzmann equation. But what about collisions?
The remarkable thing about a PIC code, in its simplest implementation, is that it has essentially removed all charged-particle collisions. The grainy discreteness of the electrons, is smoothed away by the process of assigning charge to the grid and then solving for $\mathit{\phi }$. Therefore, unless we do something to put collisions back, the PIC code actually represents integration along characteristics of the Vlasov equation, the collisionless Boltzmann equation. If we had instead used (highly inefficiently) pair-forces, then the charged particle collisions would have been retained.
Because the collisions have been removed from the problem, the actual magnitude of each particle's charge and mass no longer matters; only the ratio, $q/m$, appears in the acceleration, $\mathbit{a}$, in the Vlasov equation. That means we can represent physical situations that would in nature involve unmanagable numbers of physical electrons by regarding the electrons (or ions) of our computation as pseudo-particles. Each pseudo-particle corresponds to a very large number of actual particles, reducing the number of computation pseudo-particles to a managable total, and keeping the costs of the computation within tolerable bounds. For our computation to remain a faithful representation of the physical situation, we require only that the resolution in phase-space, which depends upon the total number of randomly distributed electrons, should be sufficient for whatever phenomenon is being studied. We also require, of course, that the potential mesh has sufficient spatial resolution. Figure 10.7: Example of phase-space locations of electrons. A one-dimensional $v$ versus $x$ calculation is illustrated, using the code XES1 (by Birdsall, Langdon, Verboncoeur and Vahedi, originally distributed with the text by Birdsall and Langdon) for two streams of particles giving rise to an instability whose wavelength is four times the domain length. Each electron position is marked as a point. Their motion can be viewed like a movie.
Particle in cell codes are a backbone of much computational plasma physics, important for modelling semiconductor processing tools, space interactions, accelerators, and fusion experiments. An example of a one-dimensional PIC calculation is shown in Fig. 10.7. They are particularly useful for collisionless or nearly collisionless problems that are widespread in the field. They can also be modified to include collisions of various different types, as the conditions require them. In plasmas, though, charged-particle collisions are often dominated by small scattering angles and are much better approximated by a Fokker-Planck diffusion in phase space than by discrete events.

### 10.2.2  Direct Simulation Monte Carlo treatment of gas

An approach that combines some of the features of PIC and atomistic simulation, is the treatment of tenuous neutral gas behavior by what have come to be called Direct Simulation Monte Carlo (DSMC) codes. These are for addressing situations where the ratio of the mean-free-path of molecules to the characteristic spatial feature size (the "Knudsen number") is of order unity (within a factor of 100 or so either way). Such situations occur in very tenuous gases (e.g. orbital re-entry in space) or when the features are microscopic. DSMC shares with PIC the features that the domain is divided into a large number of cells, that pseudo-particles are used, and that collisions are represented in simplified way that reduces computational cost and yet approximates physical behavior. DMSC is also, in effect, integrating the Boltzmann equation along characteristics, but in this case there's no acceleration term, so the characteristics are straight lines.
The pseudo-particles representing molecules are advanced in time, but at each step, chosen somewhat shorter than a typical collision time, they are examined to decide whether they have collided. In order to avoid a ${N}_{p}^{2}$ cost, collisions are considered only with the particles in the same cell of the grid. (This partitioning is all the cells are used for.) The cells are chosen to have size smaller than a mean-free-path, but not by much. They will generally have only a modest number (perhaps 20-40) of pseudo-particles in each cell. The number of individual molecules represented by each pseudo-particle is adjusted to achieve this number per cell.
Whether a collision has occurred between two particles is decided based only upon their relative velocity, not on their position within the cell. This is the big approximation. A statistical test using random numbers decides if and which collisions have happened. A collision changes the velocity of both colliding particles, in accordance with the statistics of the collision cross-section and corresponding kinematics. That way, momentum and energy are appropriately conserved within the cell as a whole. Steps are iterated, and the overall behavior of the assembly of particles is monitored and analysed to provide effective fluid parameters like density, velocity, effective viscosity, and so on. Fig. 10.8 shows an example from the code DSMC, v3.0 developed by Graeme Bird. Figure 10.8: Example of position plot in two space dimensions of tenuous gas flow past a plate. Different colors (shadings) indicate molecules that have been influenced by the plate through collisions.

### 10.2.3  Particle Boundary Conditions

Objects that are embedded in a particle computation region present physical boundaries at which appropriate approximate conditions must be applied. For example with DSMC, gas particles are usually reflected, whereas with plasmas, it is usually assumed that the electrons are removed by neutralization when they encounter a solid surface.
An important question arises in most particle simulation methods. What do we do at the outer boundary of our computational domain? If a particle leaves the domain, what happens to it? And what do we do to represent particles entering the domain?
Occasionally the boundary of our domain might be a physical boundary no different from an embedded object. But far more often the edge of the domain is simply the place where our computation stops, not where there is any specific physical change. What do we do then?
The appropriate answer depends upon the specifics of the situation, but quite often it makes sense to use periodic boundary conditions. Periodic conditions for particles are like periodic conditions for differential equations discussed in section 3.3.2. They treat the particles as if a boundary that they cross corresponds to the same position in space as the opposite boundary. A particle moving on a computational domain in $x$ that extends from $0$ to $L$, when it steps past $L$, to a new place that would have been $x=L+\mathit{\delta }$, outside the domain, is reinserted at the position $x=\mathit{\delta }$ close to the opposite boundary, but back inside the domain. Of course the particle's velocity is just what it would have been anyway. Velocity is not affected by the reinsertion process. Periodic conditions can be applied in any number of dimensions. (a) (b)
Figure 10.9: Particles that cross outer periodic boundaries (a) are relocated to the opposite side of the domain. This is equivalent (b) to modelling an (infinite) periodic array made up of repetitions of the smaller domain.
Periodic boundaries mean that the computation represents the phenomena of a periodic array of domains all connected to one another and all doing the same thing. Sometimes that is actually what one wants. But more often it is an approximation to a larger domain. If nothing of interest happens at a scale equal to or larger than the smaller computational domain, then the artifically imposed periodicity is unimportant, and the periodic conditions are a convenient way to represent the computation of a small sub-volume within a much larger, uniform, medium. Fig. 10.9 illustrates this point.
Sometimes, however, it is not appropriate to use periodic conditions. In that case a particle that leaves the domain is simply removed from the calculation. If the calculation is approximately steady, then clearly there must also be particles created within the domain or entering it from outside. A suitable method for injecting them into the calculation must be implemented. It might represent, for example, the flux of particles across the boundary from an assumed velocity distribution function.

## Worked Example: Required resolution of PIC grid

How fine must the potential mesh be in an electron Particle in Cell code?

Well, it depends on how fine-scale the potential variation might be. That depends on the parameters of the particles (electrons). Suppose they have approximately a Maxwell-Boltzmann velocity-distribution of temperature ${T}_{e}$. We can estimate the finest scale of potential variation as follows. We'll consider just a one-dimensional problem. Suppose there is at some position $x$, a perturbed potential $\mathit{\phi }\left(x\right)$ such that $|\mathit{\phi }|<<{T}_{e}/e$, measured from a chosen reference ${\mathit{\phi }}_{\mathit{\infty }}=0$ in the equilibrium background where the density is ${n}_{e}={n}_{\mathit{\infty }}={n}_{i}$. (Referring to the background as $\mathit{\infty }$ is a helpful notation that avoids implying the value at $x=0$; it means the distant value.) Then the electron density at $x$ can be deduced from the fact that $f\left(v\right)$ is constant along orbits (characteristics). In the collisionless steady-state, energy is conserved; so for any orbit $\frac{1}{2}{\mathit{mv}}^{2}-e\mathit{\phi }=\frac{1}{2}{\mathit{mv}}_{\mathit{\infty }}^{2}$, where ${v}_{\mathit{\infty }}$ is the velocity on that orbit when it is "at infinity" in the background, where $\mathit{\phi }=0$. Consequently, $f\left(v\right)={f}_{\mathit{\infty }}\left({v}_{\mathit{\infty }}\right)={n}_{\mathit{\infty }}\sqrt{\frac{m}{2\mathit{\pi }{T}_{e}}}\mathrm{exp}\left(-{\mathit{mv}}_{\mathit{\infty }}^{2}/2{T}_{e}\right)={n}_{\mathit{\infty }}\sqrt{\frac{m}{2\mathit{\pi }{T}_{e}}}\mathrm{exp}\left(-{\mathit{mv}}^{2}/2{T}_{e}+e\mathit{\phi }/{T}_{e}\right)$. Hence at $x$, $f\left(v\right)$ is Maxwellian with density $n=\int f\left(v\right)\mathit{dv}={n}_{\mathit{\infty }}\mathrm{exp}\left(e\mathit{\phi }/{T}_{e}\right)$.
Now let's find analytically the steady potential arising for $x>0$ when the potential slope at $x=0$ is $d\mathit{\phi }/\mathit{dx}=-{E}_{0}$. Poisson's equation in one-dimension is
 $\frac{{d}^{2}\mathit{\phi }}{{\mathit{dx}}^{2}}=-\frac{{\mathit{en}}_{\mathit{\infty }}}{{\mathit{\epsilon }}_{0}}\left[1-\mathrm{exp}\left(e\mathit{\phi }/{T}_{e}\right)\right]\approx \left(\frac{{e}^{2}{n}_{\mathit{\infty }}}{{\mathit{\epsilon }}_{0}{T}_{e}}\right)\mathit{\phi }.$ $\left(10.7\right)$
The final approximate form gives Helmholtz's equation. It is obtained by Taylor expansion of the exponential to first order, since its argument is small. The solution satisfying the condition at $x=0$ is then
 $\mathit{\phi }\left(x\right)={E}_{0}\mathit{\lambda }{e}^{-x/\mathit{\lambda }},\mathrm{ }\text{where}\mathrm{ }{\mathit{\lambda }}^{2}=\left(\frac{{e}^{2}{n}_{\mathit{\infty }}}{{\mathit{\epsilon }}_{0}{T}_{e}}\right).$ $\left(10.8\right)$
Based on this model calculation, the length $\mathit{\lambda }=\sqrt{{e}^{2}{n}_{\mathit{\infty }}/{\mathit{\epsilon }}_{0}{T}_{e}}$, which is called the Debye length, is the characteristic spatial scale of potential variation. A PIC calculation must have fine enough grid to resolve the smaller of $\mathit{\lambda }$ and the characteristic feature-size of any object in the problem whose influence introduces potential structure. In short, $\mathit{\Delta }x\le \mathit{\lambda }$.
If we had an operational PIC code, we could do a series of calculations with different cell size $\mathit{\Delta }x$. We would find that when $\mathit{\Delta }x$ became small enough, the solutions would give a result independent of $\mathit{\Delta }x$. That would be a good way of demonstrating adequate spatial resolution numerically. For the simple problem we've considered the requirement can be calculated analytically. Actually the criterion $\mathit{\Delta }x<~\mathit{\lambda }$ applies very widely in plasma PIC calculations.

## Exercise 10. Atomistic Simulation

1. The Verlet scheme for particle advance is
 $\begin{array}{ccc}\multicolumn{1}{c}{{\mathbit{x}}_{n+1}}& =\hfill & {\mathbit{x}}_{n}+{\mathbit{v}}_{n}\mathit{\Delta }t+{\mathbit{a}}_{n}\mathit{\Delta }{t}^{2}/2\hfill \\ \multicolumn{1}{c}{{\mathbit{v}}_{n+1}}& =\hfill & {\mathbit{v}}_{n}+\left({\mathbit{a}}_{n}+{\mathbit{a}}_{n+1}\right)\mathit{\Delta }t/2.\hfill & \hfill \left(10.9\right)\end{array}$

Suppose that the velocity at integer timesteps is related to that at half integer timesteps by ${\mathbit{v}}_{n}=\left({\mathbit{v}}_{n-1/2}+{\mathbit{v}}_{n+1/2}\right)/2$. With this identification, derive the Verlet scheme from the leap-frog scheme,
 $\begin{array}{ccc}\multicolumn{1}{c}{{\mathbit{x}}_{n+1}}& =\hfill & {\mathbit{x}}_{n}+{\mathbit{v}}_{n+1/2}\mathit{\Delta }t\hfill \\ \multicolumn{1}{c}{{\mathbit{v}}_{n+3/2}}& =\hfill & {\mathbit{v}}_{n+1/2}+{\mathbit{a}}_{n+1}\mathit{\Delta }t,\hfill & \hfill \left(10.10\right)\end{array}$

and thus show they are equivalent.

2. A block algorithm is applied to an atomistic simulation in a cubical 3 dimensional region, containing ${N}_{p}=1000000$ atoms approximately uniformly distributed. Only two-particle forces are to be considered. The cut-off range for particle-particle force is 4 times the average particle spacing. Find
(a) The optimal size of blocks into which to divide the domain for fastest execution.
(b) How many force evaluations per time-step will be required.
(c) If the force evaluations require 5 multiplications, a Verlet advance is used, and the calculation is done on a single processor which takes 1 nanosecond per multiplication on average, roughly what is the total time taken per timestep (for the full 1,000,000 particles).

3. (a) Prove from the definition of a characteristic (see section 8.3.2) that the equation of the characteristics of the collisionless Boltzmann equation is
 $\frac{d}{\mathit{dt}}\left(\genfrac{}{}{0}{}{\mathbit{x}}{\mathbit{v}}\right)=\left(\genfrac{}{}{0}{}{\mathbit{v}}{\mathbit{a}}\right).$ $\left(10.11\right)$
Show also that a particle (or pseudo-particle) trajectory in a fixed electric potential depends only on initial velocity and the ratio of its charge to mass $q/m$, and therefore that the equation of motion of a pseudo-particle must use the same $q/m$ as the actual particles, if a PIC simulation is to model correctly the force law at given speed and potential.
(b) A pseudo-particle of charge $q$ follows a characteristic, but it is supposed to be representative of many nearby particles (characteristics). If the mean density of pseudo-particles in a PIC simulation is a factor $1/g$ (where $g>>1$) smaller than the actual density of the system being modelled, how much charge must each pseudo-particle deposit on the potential grid to give the correct potential from Poisson's equation? One way to do PIC simulation is to represent all lengths, times, charges and masses in physical units, but to use this charge deposition factor, and correspondingly lower particle density.