Files
katrin-plasma/docs/phd/jkellerer/chap/chapter5.tex
T

731 lines
123 KiB
TeX

\chapter{Particle in Cell Simulations with ACRONYM}
\label{ch:acronym}
The evolution of charged particles inside a non-collisional plasma can be described by the Vlasov equation, see equation~\ref{eq:vlasov_equation}, in conjunction with Maxwell's equations. The interplay between the equations make analytic calculations difficult. Numerical methods like \ac{pic} simulations can bridge this gap. In \acs{pic} simulations, particles are simulated in a continuous space, while their density and currents are calculated on discrete mesh points \citep{Kilian.2015}. These currents and densities are then used to solve Maxwell's equations for a given timestep. The resulting fields are extrapolated to the particle positions. The particles are then moved accordingly.
There exist multiple different \acs{pic} codes. They differ significantly in their treatment of the particle motion, the mesh generation and the approach to solve Maxwell's equations. The results presented in this thesis are obtained using the well tested \acs{acronym} code \citep{Kilian.2012}. Modifications were added to incorporate the special conditions of the \acs{katrin} source.
The first section of this chapter (section~\ref{sec:acronym:pic}) focuses on the algorithm of the \acs{acronym} code to provide the groundwork for the extensions of the code. The code specific treatment of the particle motion, the mesh generation and Maxwell solver will be presented here. In the second section (section~\ref{sec:acronym:boundaries}), simulation boundary conditions are introduced. An emphasis will be put on the treatment of perfect electrical conductors and their application on a cylindrical boundary, as they are the main boundary type of the \acs{katrin} geometry. The third section (section~\ref{sec:acronym:background}) covers backgrounds for the simulation. They include the current background generated by ions, but also the electromagnetic background of the experiment. In the fourth section (section~\ref{sec:acronym:injection}), the injection of particles is described. This reflects the continuous production of electrons and ions in the source. The fifth section (section~\ref{sec:acronym:poisson}) deals with the translation of the electromagnetic field output from \acs{acronym} towards electrostatic potentials. Lastly, the newly introduced methods of the code were tested thoroughly to ensure reliable results. The different test methods will be discussed in section~\ref{sec:acronym:validation}.
\section{The Particle in Cell Method}
\label{sec:acronym:pic}
The scheme of the particle in cell method was developed to reflect the cause and effect of the particle motion in the plasma, while retaining a good numerical evaluation method. The algorithm scheme is depicted in figure~\ref{fig:Chapter5_ACRONYM/ParticleInCellMethod/pic_scheme.pdf}. The steps of the algorithm are described shortly in this section, and each step itself more thoroughly in the following sections.
The simulation starts with the initial injection of so-called macro particles into a continuous space. The macro particles gain their initial particle properties of position, velocity, mass and charge (scaled by the macro factor). The movement of the macro particles generates an electric current. This current is evaluated on grid positions in the current deposition step. The information on the current is used to solve Maxwell's equations numerically for a predefined timestep. The fields on the grid positions are then interpolated towards the position of the macro particles. The position and velocity is updated in the movement step (Boris push) in dependence on the local electromagnetic fields. Thus, new particle properties are available and the cycle starts again.
The number of cycles $N_t$ which have to be performed depend on the timestep length $\Delta t$ and the desired time window. The timestep length is dependent on the used algorithms as well as on the fastest physics, which should be resolved, see section~\ref{ssec:pic_maxwell_solver}. The plasma frequency $\omega_\text{pe}$ (see section~\ref{ssec:plasma_frequency}) acts as a natural time scale at which most of the plasma physic has taken place. The inverse of the plasma frequency is therefore also called plasma time scale. This assumes that most of the plasma physic is moderated by the motion of electrons. The number of necessary cycles of the algorithm can be written as
\begin{equation}
N_t \approx a \cdot \Delta t \cdot \omega_\text{pe} \comma
\label{eq:acronym:number_of_timesteps}
\end{equation}
where $a$ is a small integer number. The explicit value of $a$ has to be determined through the simulation itself. It is expected that the simulated system will reach an equilibrium state, where the total energy of the electromagnetic fields and the total energy of the particles do not change significantly. At this point it is not beneficial to simulate more timesteps and the simulation can be terminated.
There exists a multitude of different methods for each of the simulation steps. The methods implemented in the \acs{acronym} code are described in the works of \citet{Kilian.2015}. Nevertheless, the specific methods used in the context of this thesis are described in the following. They need to be adapted to cope with cylindrical boundary conditions of the \acs{katrin} source.
\xfigure{tb}{1.0}{Chapter5_ACRONYM/ParticleInCellMethod/pic_scheme.pdf}{PIC algorithm.}{Particles are initiated with position $x$ and velocity $v$. These particles generate a current, which is mapped on a grid. The current is then used to update the electromagnetic fields on the grid for one timestep of length $\Delta t$. The fields are then interpolated on the particle positions. The particles are moved according to the electromagnetic field with the Boris push algorithm. Figure adapted from \citep{Kilian.2015}.}
\newpage
\subsection{Grids for Currents and Fields}
\label{ssec:pic_yee_grid}
The motion of charged particles can be described through electric currents. They induce electromagnetic fields through Ampere's circuital law. In the simulation, both current and field values are evaluated at grid positions. The grid positions are given by the Yee-grid \citep{Yee.1966}, see also figure \ref{fig:Chapter5_ACRONYM/ParticleInCellMethod/GridsForCurrent/yee_grid.pdf}. The Yee-grid consists of two grids, which are staggered by half the grid step size $\Delta x$ in each direction. The electric field and charge current density are stored at the first grid, the magnetic field on the second grid. This layout allows for a simple numerical evaluation of the curl operator in Maxwell's equations and a simple assessment of the temporal evolution of the electric field, see section~\ref{ssec:pic_maxwell_solver} for more information.
This setup can also be described through the use of equal sized cubes, which allows for a simpler enumeration of the grid positions. The electric field components $E_i$ are stored at the center of the cube edges, while the magnetic field components $B_i$ are stored at the center of the cube faces. The components of the charge current density $j_i$, in the following only named current, are located at the same position as the electric field values. Other information of the particles (particle density $\rho$ and mass current), which are not directly used in the simulation, are also stored on the grid for analysis purposes. The particle density is stored at the cube corners, while the mass current is stored at the cube edges.
\xfigure{tb}{1.0}{Chapter5_ACRONYM/ParticleInCellMethod/GridsForCurrent/yee_grid.pdf}{Yee lattice.}{Electric and magnetic field values are stored at grid positions, which are displaced for half a cell length $\Delta x$ in each direction. The staggering of the grids can also be displayed by a cubic cell, where the electric field components $E_i$ are located at the cell edges and the magnetic field components $B_i$ are located at the cell faces. The currents $j_i$ are located at the same position as the electric field values. The density $\rho$ is located at the cell corners. Figure concept from \citep{Kilian.2015}.}
\subsection{Macro Particles}
\label{ssec:pic_macro_particles}
The Vlasov equation (equation~\ref{eq:vlasov_equation}) describes the temporal evolution of the phase space density $f(\vec{x}, \vec{v},t)$. In the particle in cell algorithm, the phase space density is discretized into small phase space elements $f_\alpha(\vec{x}, \vec{v},t)$. The phase space density can therefore be written as
\begin{equation}
f(\vec{x}, \vec{v},t) = \sum_{\alpha=1}^{N_p} f_\alpha(\vec{x}, \vec{v},t) \comma
\end{equation}
where $N_p$ is the number of phase space elements. The phase space elements are considered to be localized around the position $x_\alpha$ and the velocity $v_\alpha$ with the formfactors $S_x(\vec{x} - \vec{x}_\alpha)$ and $S_v(\vec{v} - \vec{v}_\alpha)$ respectively. Thus, the phase space element can be written as
\begin{equation}
f_\alpha(\vec{x}, \vec{v},t) = w_\alpha \cdot S_x(\vec{x} - \vec{x}_\alpha) \cdot S_v(\vec{v} - \vec{v}_\alpha) \label{eq:pic_phase_space_element}\comma
\end{equation}
where $w_\alpha$ is the so-called macro factor of the phase space element. Following \citet{Kilian.2015}, it can be shown that
\begin{eqnarray}
\frac{\partial w_\alpha}{\partial t} = 0 \comma \\
w_\alpha \frac{\partial x_\alpha}{\partial t} - w_\alpha v_\alpha = 0 \comma \\
\frac{\partial v_\alpha}{\partial t} - \frac{q w_\alpha}{m w_\alpha} E(x_\alpha) = 0 \fullstop
\label{eq:macro_factor:evolution_in_field}
\end{eqnarray}
This means that the macro factor stays constant during the evolution of the phase space element. Additionally, the position $x_\alpha$ of the element changes exactly like standard particles. Furthermore, the velocity $v_\alpha$ of the phase space element changes similarly in an electric field as the velocity of a standard charged particle. Only the mass and the charge of the particle are weighted by the factor $w_\alpha$. Due to these similarities to standard particles, the phase space elements are also called macro particles. In the simulation, the macro particles are treated like particles, which makes the simulation approach very accessible.
Equation~\ref{eq:macro_factor:evolution_in_field} shows how the velocity of a macro particle changes in an external field. For simplicity, this calculation did not include, how an external field is evaluated on the position of the particle or how the macro particle interacts with its surroundings. These relations are described by the so-called form factors $S_x$ and $S_v$ from equation \ref{eq:pic_phase_space_element}. The form factor can be selected from a wide range of functions. The function must be normalized and zero in the limit of large values. The specific choice of the form factor depends on the target numerical stability of the solution and the calculation effort. In all known \acs{pic} codes, the form factor of the velocity $S_v$ is set to a Dirac-Delta function to ensure consistency in the calculation of the Lorentz force \citep{Kilian.2015}.
Generally, the spatial form factor $S_x$ can also be chosen to be a Dirac-Delta function. This would mean that each macro particle is only assigned to the next grid point of the Yee-grid. Thus, the current and particle density spikes each time a macro particle crosses from one cell to the other. This would introduce self-forces, and extremely large noise in the simulation. Additionally, the simulation would lose its isotropy because of the Euclidean geometry of the cube \citep{Kilian.2015}. Therefore, the form factor $S_x$ is chosen, throughout this thesis, to be a triangularly shaped cloud with the following structure:
\begin{align}
S_x(\vec{x}) &= S_x(x) \cdot S_x(y) \cdot S_x(z) \\
S_x(x/y/z) &=
\begin{cases}
0, & x < -\Delta x \\
1+x, & -\Delta x \leq x < 0 \\
1-x, & 0 < x \leq \Delta x \\
0 & x > \Delta x
\end{cases} \fullstop
\end{align}
This form factor ensures an easy numerical evaluation, while maintaining a good reproduction of spectra and energy conservation of the simulation \citep{Kilian.2015}.
\subsection{Particle Movement}
\label{ssec:boris_push}
In the previous section, it could be shown, that the phase space elements can be described as macro particles. These particles have to be moved according to their position and velocity, but also according to the electromagnetic fields. Therefore, the fields of the grid have to be extrapolated to the particle positions first. In a second step, the new particle position is determined for a given timestep.
The electric field at the particle position $\vec{x}$ is calculated as
\begin{equation}
E_\nu(\vec{x}) = \sum_{ijk} S_x(\vec{x} - \vec{X}_{ijk}^\nu) \cdot E_{\nu ,ijk} \comma
\label{eq:pic:field_interpolation}
\end{equation}
where $\nu$ labels the three different Cartesian axis, $\vec{X}_{ijk}^\nu$ labels the positions of the field component $E_{\nu ,ijk}$ in the cell $(i,j,k)$, and $S_x(\vec{x})$ labels the spatial form factor. In the code, the sum is not calculated for all possible cell positions, but only for the cell positions in the near vicinity of the macro particle. This is justified because the form factor of the triangular shaped cloud is only non-zero in proximity of the particle. The calculation of the magnetic field at the position of the particle is performed accordingly.
The electromagnetic field values can then be used to determine the force acting on the particle. In the simulation, only the Lorentz force is considered. The gravitational force is neglected here due to its comparably small value. The actual movement of the particle is performed in discrete timesteps. The equation of motion is solved numerically through the Leapfrog algorithm. In this algorithm, the velocity and the position are not calculated at the same time, but half timesteps apart. Thus, the equation of motion in one dimension calculates to
\begin{eqnarray}
\frac{x_{i+1} - x_i}{\Delta t} = v_{i+1/2} \comma \\
m \frac{v_{i+1/2} - v_{i-1/2}}{\Delta t} = F(v_i) \comma
\end{eqnarray}
where the index $i$ denotes the timestep at which the value is available. $F$ is the force acting on the particle, in this case the Lorentz force. The position update is straight forward and does not need any more explanation. The velocity update is more complicated, because the force on the particle is dependent on the velocity of the particle. By assuming that the velocity between two timesteps can be calculated as the mean of the values, it can be formulated that the velocity of the next timestep must read
\begin{equation}
\vec{v}_{i+1/2} = \vec{v}_{i-1/2} + \frac{q \Delta t}{m} \cdot \left(\vec{E}_i + \frac{\vec{v}_{i+1/2} + \vec{v}_{i-1/2}}{2 c} \times \vec{B}_t \right) \fullstop
\end{equation}
\xfigure{tb}{0.8}{Chapter5_ACRONYM/ParticleInCellMethod/ParticleMovement/boris_push.pdf}{Boris push algorithm.}{Grafical representation of the update of the velocity at timestep $t-\frac{1}{2}$ towards the new timestep $t+\frac{1}{2}$ (equations \ref{eq:boris_push_start} to \ref{eq:boris_push_end}). The velocity is first boosted for half a timestep by the electric field. Second the velocity vector is rotated by the magnetic field. Third the velocity is boosted again for half a timestep by the electric field. Figure taken from \citep{Kilian.2015}.}
This equation can be solved numerically for the velocity $\vec{v}_{i+1/2}$ through the use of the Boris push algorithm \citep{Penn.2003}. The algorithm is numerically stable with high precision and efficiency \citep{Kilian.2015}. The method can be used for low relativistic particles, up to a gamma factor of $\gamma \approx 1000$ \citep{Vay.2008}. At the \acs{katrin} experiment, only electrons of energies up to \SI{32}{keV} (Krypton conversion electrons) are created. This results in a gamma factor of $\gamma = 1.06$, which is well below the limit of the Boris push. Thus, the Boris push can be used without modification and will be described briefly in the following.
The change of the velocity vector is calculated in three steps, see also figure \ref{fig:Chapter5_ACRONYM/ParticleInCellMethod/ParticleMovement/boris_push.pdf}. First, the particle is accelerated by half a timestep through the electric field
\begin{equation}
\vec{v}^- = \vec{v}_{i-1/2} + \frac{q \Delta t}{2 m} \vec{E}_{i-1/2} \fullstop
\label{eq:boris_push_start}
\end{equation}
Secondly, the particle is accelerated by the magnetic field. This can be described through
\begin{eqnarray}
\vec{\Omega} = \frac{q \Delta t}{2 m c} \vec{B}_i \comma \\
\vec{t} = \frac{2 \vec{\Omega}}{1 + \vec{\Omega} \cdot \vec{\Omega}} \comma \\
\vec{v}^\prime = \vec{v}^- + \vec{v}^- \times \vec{\Omega} \\
\vec{v}^+ = \vec{v}^- + \vec{v}^\prime \times \vec{t} \fullstop
\end{eqnarray}
Thirdly, the particle is accelerated again by half a timestep through the electric field
\begin{equation}
\vec{v}_{i+1/2} = \vec{v}^+ + \frac{q \Delta t}{2 m} \vec{E}_{i-1/2} \fullstop
\label{eq:boris_push_end}
\end{equation}
In total, the new velocity was derived from the mass and charge of the particle and the extrapolated electromagnetic field values. The information on the position and velocity can now be used in the current deposition step.
\subsection{Current Deposition}
\label{ssec:pic_current_deposition}
The macro particle motion can be described by an electric current. In the simulation, this current is projected, for each time step, on the cell edges of the Yee-grid, see section \ref{ssec:pic_yee_grid}. The specific contributions of each particle are moderated by the form factor, charge, position and velocity of the particle. The naive approach, to use the mean of the contribution before and after moving the particle, fails because the charge continuity equation is not fulfilled. A charge conserving algorithm was proposed by \citet{Esirkepov.2001}. The derivation of the algorithm is extensive, so the interested reader is referred to \citet{Kilian.2015} for an accessible description. Only the corner stones will be presented here.
The algorithm hinges on the calculation of the spatial derivative of the current through eight different weights $W_i$. These weights describe the charge distribution at the corners of a paraxial cube, where two of the corners are the start and end position of the particle. The weights are used to calculate the spatial derivative of the current $\vec{C}$. For the $x$-component the derivative reads as
\begin{equation}
C_{x,ijk}^{t+1/2}(W_i) = - \frac{\Delta t}{q_\alpha \Delta x} \left(j^{t+1/2}_{x,i+1/2jk} - j^{t+1/2}_{x,i-1/2jk}\right) \fullstop
\end{equation}
Hence, the current of the particle $\alpha$ at the cell ($i+1/2,j,k$) is dependent on the current of the neighboring cell ($i-1/2,j,k$). This recursion can be resolved directly, because the form factor of the particle has a finite extension. Thus, at a certain distance from the cell the current contribution can be considered to be zero, which provides the first element of the recursion.
The current deposition step is one of the most time-consuming step of the \acs{pic} algorithm. Each of the macro particles contributes not only to the cell it is located in but also to the surrounding cells. Thus, many calls to the computer storage have to be performed, which are time-consuming. The call time can be reduced by sorting the particles before the current deposition step \citep{Kilian.2015}.
\subsection{Maxwell Solver}
\label{ssec:pic_maxwell_solver}
Maxwell's equations describe how electric and magnetic fields are generated by charges and charge currents. In vacuum, they read as
\begin{eqnarray}
\nabla \times \vec{E} =& - \frac{1}{c} \frac{\partial \vec{B}}{\partial t} \comma \label{eq:maxwell_} \label{eq:maxwell_faraday}\\
\nabla \times \vec{B} =& \frac{1}{c} \frac{\partial \vec{E}}{\partial t} + \frac{4 \pi}{c} \vec{j} \comma \label{eq:maxwell_ampere} \\
\nabla \vec{E} =& 4 \pi \rho \comma \label{eq:maxwell_gauss} \\
\nabla \vec{B} =& 0 \fullstop \label{eq:maxwell_gauss_magnetic}
\end{eqnarray}
It can be seen, that the temporal evolution of the electric and magnetic field can be described only by the current and by the respective other field. This behavior is used in the simulation to generate new field values after a given timestep $\Delta t$.
The new field values are determined by their time derivative. The derivative can be represented numerically by their finite differences. Thus, the first two Maxwell's equations (\ref{eq:maxwell_faraday}, \ref{eq:maxwell_ampere}) can be written as
\begin{eqnarray}
\frac{\partial \vec{B}}{\partial t} \approx& \frac{\vec{B}^{i+1/2} - \vec{B}^{i-1/2}}{\Delta t} &= - c \nabla \times \vec{E}^i \comma \\
\frac{\partial \vec{E}}{\partial t} \approx& \frac{\vec{E}^{i+1} - \vec{E}^{i}}{\Delta t} &= c \nabla \times \vec{B}^{i+1/2} - 4 \pi \vec{j}^{i+1/2} \comma
\end{eqnarray}
where the superscript describes the timestep, when the value is available. Thus, the magnetic and electric fields at the next timestep can be calculated directly from the field values of the previous timestep. This calculation requires the knowledge of the curl of the field values. The curl of the electric and the magnetic field can also be calculated numerically. In the simulation, the electric and magnetic field values are stored in a staggered grid, see~\ref{ssec:pic_yee_grid}. Thus, the curl operator can easily be evaluated from the neighboring field values. In the context of this thesis, the Yee-method is used for the evaluation, where the derivatives are replaced by the central differences. The $x$-component of the curl, for example, is calculated as
\begin{equation}
\begin{split}
\left(\nabla \times \vec{E}\right)_x &= \frac{\partial E_z}{\partial y} - \frac{\partial E_y}{\partial z} \\
&\approx \frac{E_z(i,j+1,k) - E_z(i,j,k)}{\Delta x} - \frac{E_y(i,j,k+1) - E_y(i,j,k)}{\Delta x} \comma
\end{split}
\end{equation}
where $\Delta x$ is the step size of the Yee-grid. In the simulation, the step size is chosen in such a way, that Debye shielding effects are resolved (see Section~\ref{ssec:debye_length}). It is calculated as
\begin{equation}
\Delta x = \sqrt{0.5} \cdot \lambda_D \comma
\label{eq:acronym:cell_size}
\end{equation}
where $\lambda_D$ is the Debye length.
The step size is linked to the timestep length $\Delta t$ through the Courant-Friedrichs-Lewy-condition (\acs{cfl}) \citep{Courant.1928}. It specifies the maximal timestep for a numerical stable solution. In easy words, it describes that the electric and magnetic field cannot move more than one cell in one timestep, which would otherwise contradict the finite speed of light. For the Yee method it reads as
\begin{equation}
\Delta t < \sqrt{\frac{1}{3}} \frac{\Delta x} c \comma
\label{eq:acronym:cfl_limit}
\end{equation}
where $c$ is the speed of light.
The timestep is also restricted by other requirements of non-numerical nature. In the context of this thesis, the most important conditions are
\begin{itemize}
\item $\Delta t < \frac{1}{2 \omega_{pe}}$: plasma oscillations have to be sufficiently resolved through the Nyquist-Shannon sampling theorem.
\item $\Delta t < \frac{1}{\Omega}$: the gyro motion of the lightest particle must be resolved.
\end{itemize}
\section{Boundary Conditions}
\label{sec:acronym:boundaries}
In the previous section, it was implicitly assumed that there are sufficient neighboring cells for each simulated cell. This assumption is valid for a central part of the simulated plasma. But, it is apparent that the simulation domain is not infinitely extended. A special treatment of the boundary regions is necessary. This treatment must include a description for the electric and magnetic field, as well for the current and the particle movement. In the context of this thesis, three different boundary conditions were applied: the perfect electrical conductor boundary (\acs{pec}), the periodic boundary condition and the perfectly matched layer boundary (\acs{pml}). These boundary conditions are described in detail in the following.
\subsection{Perfect Electrical Conductor}
\label{ssec:acronym:boundaries:pec}
The \acs{pec} boundary is used to describe the boundary between metal and the interior of the plasma. It is used both for the transition towards the beam tube walls and the rear wall. Thus, both surfaces are assumed to be perfectly conducting and to be grounded. Any deposit of non-conducting material is neglected here.
Two major cases have to be differentiated because of the Cartesian structure of the Yee-grid: a planar boundary, which is parallel to the grid, and an arbitrary shaped boundary. In the end, the arbitrary geometry will be used to simulate the cylindrical shape of the source. Nevertheless, the algorithm could also be used for more complex geometries.
\paragraph{Planar shape}
Assume, there is a planar boundary, which is aligned with the electric field from the Yee-grid, see figure~\ref{fig:Chapter5_ACRONYM/ParticleInCellMethod/Boundary/parallel_boundary.pdf}. In this case, it is easy to formulate requirements for the electromagnetic fields. The parallel electric field is always zero at the rim of a perfect conductor. Therefore, the electric field of all Yee-grid edges, which are parallel to the boundary, is set to zero. The electric field of all edges contained in the boundary is set to zero as well. The perpendicular field values of the electric field inside the simulation volume are unaltered. The magnetic field of all faces inside the \acs{pec} is set to zero. In the case of a background magnetic field, they are set to the background value. The magnetic field of the faces, which touch the boundary, is unaltered, because these fields are located $\frac{\Delta x}{2}$ away from the boundary. A graphical representation of the boundary conditions for the electric and magnetic field can be found in figure~\ref{fig:Chapter5_ACRONYM/ParticleInCellMethod/Boundary/parallel_boundary.pdf}
\xfigure{tb}{1.0}{Chapter5_ACRONYM/ParticleInCellMethod/Boundary/parallel_boundary.pdf}{Parallel PEC boundary.}{Sketch of the electric field (left, red) and magnetic field (right, blue) at a conducting surface, which is aligned parallel to the cell (light blue). Circles indicate positions, where the field value is set to zero.}
The treatment of the current at the \acs{pec} boundary is more complicated. The macro particles show a finite extension through their form factor. Therefore, there could be a current, which is deposited behind the \acs{pec} boundary. The general treatment of this case would include the usage of a current, which would stem from a theoretical image charge in the conductor. This current would cancel out the parallel current of the macro particle and increase the perpendicular current. Despite the theoretical motivation, the small mirror charge current was not implemented in the context of this thesis, to ensure consistency with the arbitrary shape \acs{pec} boundary. For the arbitrary shape, no unambiguous mirror charge method could be found. In total, the current towards the boundary in cells directly in front of the boundary is underestimated in the context of this thesis. In the future, the current deposition step at \acs{pec} boundaries can be refined by better models of mirror charges.
%The effect can be classified by the weight of the particles at the position, where the current is collected. The current is only collected at the center of the edges, see section~\ref{ssec:pic_yee_grid}. The weigth is decreasing quadratically for distances greater than $\frac{\Delta x}{2}$ from \num{0.5} to 0. Thus, the underestimation also decreases quadratically. All in all, the model of the current at \acs{pec} surfaces can be refined in the future, when a mirror charge model is available.
The \acs{pec} boundary also absorbs all incoming particles. In the simulation, they are deleted directly, when they cross the boundary. Therefore, they do not contribute to the current at their last timestep. A fast beta particle would have moved at maximum a tenth of a cell ($\Delta t \approx \SI{8E-13}{s}$). The majority of the particles are thermal electrons, which would have only moved \num{6E-5} parts of a cell. In the context of this thesis, it is therefore assumed that this contribution to the current can be neglected.
\paragraph{Arbitrary shape}
The simulation of \acs{pec} boundaries with arbitrary shape needs special treatment. In general, it is only possible to simulate shapes with features bigger than the cell step size $\Delta x$. The simplest approach to simulate the arbitrary shaped boundary is the approximation through the stair step algorithm \citep{Dey.1998}. Here, the boundary is approximated by cubes of the Yee-grid. This method allows for an easy evaluation of Maxwell's equations at the cost of accuracy and robustness towards spurious solutions \citep{Dey.1998}. \enquote{Stairstepping a boundary introduces global first-order error (e.g. the frequency of a simulated cavity would have an error scaling as the cell-length). Second-order error can be attained using the Dey-Mittra algorithm.}\citep{Nieter.2009} In order to reach a high accuracy, the Dey-Mittra will be used in the context of this thesis.
\xfigure{tb}{1.0}{Chapter5_ACRONYM/ParticleInCellMethod/Boundary/dey_mittra.pdf}{Edge length and face area for the Dey-Mittra algorithm.}{Sketch of a partial cut cell face through a conducing surface (black). The magnetic field calculation is altered by the edge length $l_i$ and the area $A$ of the face, which is inside the boundary (light blue). Representation of the electric field vectors in red and magnetic field in blue.}
In the Dey-Mittra algorithm, it is first calculated how the boundary cuts the cell. The corresponding edge length and face areas are calculated correspondingly, see figure \ref{fig:Chapter5_ACRONYM/ParticleInCellMethod/Boundary/dey_mittra.pdf}. The electric field on edges which are totally contained within the conductor is set to zero. The other electric field values are left unaltered. The magnetic field calculation is adapted to
\begin{multline}
\Delta B_z(i,j,k) = \frac{\Delta t}{A_z(i,j,k)} \cdot ( E_x(i,j,k) l_x(i,j,k) - E_x(i,j+1,k) l_x(i,j+1,k) \\ + E_y(i+1,j,k) l_y(i+1, j,k) - E_y(i,j,k) l_y(i,j,k) ) \comma
\end{multline}
where $A$ is the face area and $l_i$ are the length of the edges, which are inside the geometry. It can be seen that in the case of an unaltered cell, the calculation of the magnetic field is the same as the standard \acs{pic} algorithm.
The stability of the Dey-Mittra algorithm depends on the smallest allowed face area $A_{\text{min}}$, the smallest allowed edge length $l_\text{min}$, and the timestep length $\Delta t$. \citet{Nieter.2009} state that the algorithm is stable for a uniform grid when the following two conditions are met
\begin{eqnarray}
\Delta t <& \Delta t_{\text{CFL}} \cdot \sqrt{2 a} \comma \\
\Delta t <& \Delta t_{\text{CFL}} \cdot \sqrt{l} \comma
\end{eqnarray}
where $a = \frac{A_{\text{min}}}{\Delta x^2}$ and $l = \frac{l_{\text{min}}}{\Delta x}$.
The timestep length of the \acs{pic} algorithm for the conditions of the \acs{katrin} source has to be lower than $\Delta t \approx \SI{8E-13}{s}$, see section~\ref{ssec:pic_maxwell_solver}. Thus, many timesteps are necessary to reach reasonable results through simulation. It was therefore decided to aim for the smallest timestep reduction allowed by the stability criteria of the Dey-Mittra algorithm. This means that the area factor was chosen to be $a = 0.5$ and the edge length factor to $l = 1$. This approach is equal to the request that there are only diagonally cut and non-cut cells filled with plasma.
The physical geometry of the \acs{katrin} source has to be approximated by diagonally and non-cut cells to suit the algorithm. This procedure will be done in two steps. First, it will be determined, which edges of the grid are cut by the physical geometry. These edges are then considered outside the approximated geometry. Their edge length is set to zero. Secondly, the face areas will be determined from these new edges. This calculation is trivial, because there are only squares and triangles left. An example of the electric and magnetic field values in a cell, which is cut diagonally along one axis, is shown in figure \ref{fig:Chapter5_ACRONYM/ParticleInCellMethod/Boundary/cut_boundary.pdf}.
\xfigure{tb}{1.0}{Chapter5_ACRONYM/ParticleInCellMethod/Boundary/cut_boundary.pdf}{Diagonally cut cell at a PEC boundary.}{Sketch of a cell, which is cut diagonally by a conducting surface (ligth blue). Circles indicate positions, where the field value is set to zero. The electric field (red, left) is set to zero at edges, which are contained in the conductor. The magnetic field (blue, center) is set to zero at faces, which are contained in the conductor. Particles are deleted, when they crossed the boundary. This condition is evaluated through the use of the normal vector $\vec{n}$ and the point $\vec{P}$ of the boundary surface.}
The face areas and edge lengths are calculated prior to the simulation to reduce computing time. Additionally, in the simulation, it will be distinguished between cells, which are inside the geometry, outside the geometry and which are cut in any direction. This reduces the simulation time further, because the correct treatment of the field in each cell can be selected directly.
There was no conclusive result found in the literature, how the charged particle current shall be treated in the Dey-Mittra algorithm. A simple solution would be the usage of mirror charges. No unambiguous algorithm for the use of mirror charges was found in the context of this thesis. All approximations that were found were too computational extensive. It was therefore decided, that there is no special treatment of the current at the \acs{pec} boundary. This means, that the current towards the boundary in cells directly in front of the boundary is underestimated. In the future, the current deposition step at \acs{pec} boundaries has to be refined by better models of mirror charges.
All particles that cross the \acs{pec} boundary are absorbed. They are deleted directly in the timestep, when they cross the boundary. Numerically, this condition is verified through the use of a normal vector of the cutting plane $\vec{n}$ and a point on the plane surface $\vec{P}$. An example of this setup can be found in figure~\ref{fig:Chapter5_ACRONYM/ParticleInCellMethod/Boundary/cut_boundary.pdf}. A particle at position $\vec{x}$ is considered inside the geometry when
\begin{equation}
\vec{n} \cdot (\vec{P} - \vec{x}) > 0 \comma
\end{equation}
is fulfilled. The normal vector and the point $\vec{P}$ are calculated prior to the simulation, similar to the edges and face areas, to conserve computational effort.
\subsection{Periodic Boundary Condition}
\label{ssec:acronym:boundaries:periodic}
All experimental plasmas are naturally bound, so is the simulation domain. Nevertheless, it can be profitable to assume that the plasma of the experiment is infinite, at least in one direction. This is the case if the properties of the plasma are of such a nature, that the largest possible simulation domain is significantly smaller than the experimental geometry, or if the bulk of the plasma can be studied detached from the experimental boundaries, due to Debye shielding. Both of these cases can be applied to the \acs{katrin} source. The simulation of the whole source requires many computational resources. Thus, a subdivision of the source is beneficial. Additionally, some effects of the plasma might be observable in a section of the source.
For the periodic boundary condition, it is assumed that the simulated plasma inside the simulation domain has the same properties as the plasma outside the domain. Thus, the distribution of all particles leaving the simulation domain in one direction is the same as the distribution of all particles entering the simulation domain. Hence, in the algorithm, all particles leaving in one direction are inserted at the other side of the simulation domain. The same reasoning is applied to the electromagnetic fields. Thus, the field values are copied to the other side and used in the next field update. The use of periodic boundary condition on the electromagnetic fields limits the number of possible wave modes in the simulation to $n_x/2 - 1$, where $n_x$ is the number of cells in one direction \citep{Kilian.2015}. Thus, a sufficient simulation domain must be selected.
\subsection{Perfectly Matched Layer}
The perfectly matched layer (\acs{pml}) boundary can be used to simulate the transition of a plasma into a vacuum. This means that it absorbs all outgoing electromagnetic waves and particles. For the \acs{katrin} plasma, this condition is met in the transition region from the \acs{wgts} to the \acs{dps}.
The requirements for the particle movement are easily formulated: all particles, which leave the simulation domain through the \acs{pml} boundary, are absorbed. The formulation for the electromagnetic fields is more intricate. \citet{Berenger.2007} developed a method called complex coordinate stretching, where the space coordinates of a small region in perpendicular direction to the \acs{pml} boundary are mapped to complex numbers. Thus, the incoming wave becomes evanescent, and the wave is gradually reduced. The specific properties of the \acs{pml} boundary depend, among others, on the thickness of the layer $d$ and the position dependent absorption coefficient $\alpha$. The incorporation of the complex coordinate stretching algorithm into the field update is extensive. Therefore, it will not be discussed here. Only the key dependencies will be presented. The interested reader is referred to \citep{Berenger.2007} or to \citep{Kilian.2015}.
Assume that the \acs{pml} boundary is located in the $xy$-plane. In this case four additional fields ($\psi_{E_x}$, $\psi_{E_y}$, $\psi_{B_x}$ and $\psi_{B_y}$) are introduced, which are added later on to the field values of $E_x$, $E_y$, $B_x$ and $B_y$ respectively. The value of the fields $\psi$ at the timestep $n+1$ depend on the value of the fields of the timestep before $n$ and on the local electromagnetic field values of timestep $n$. These dependencies can be summarized as follows
\begin{eqnarray}
\psi_{E_x}^{n+1}(i,j,k) &= f(\psi_{E_x}^{n}(i,j,k), B_y^n(i,j,k), B_y^n(i,j,k-1), \alpha, d) \\
\psi_{E_y}^{n+1}(i,j,k) &= f(\psi_{E_y}^{n}(i,j,k), B_x^n(i,j,k), B_x^n(i,j,k-1), \alpha, d) \\
\psi_{B_x}^{n+1}(i,j,k) &= f(\psi_{B_x}^{n}(i,j,k), E_y^n(i,j,k+1), E_y^n(i,j,k), \alpha, d) \\
\psi_{B_y}^{n+1}(i,j,k) &= f(\psi_{B_y}^{n}(i,j,k), E_x^n(i,j,k+1), E_x^n(i,j,k), \alpha, d)
\end{eqnarray}
with the update function $f$ and the cell position $i,j,k$. Thus, the field values $\psi$ of a cell in the \acs{pml} boundary region only depend on the field values of the electric and magnetic field in $x$ and $y$-direction along the $z$-axis. This property simplifies the use of the \acs{pml} boundary in conjunction with a \acs{pec} boundary perpendicular to the \acs{pml} boundary. This configuration can be found in the transition region of the source towards the \acs{dps} at the beam tube edges. It only needs to be tested if the field values of $E_x$, $E_y$, $B_x$ and $B_y$ are set to zero by the \acs{pec} algorithm. In this case, the addition of $\psi$ to the field values is omitted. Otherwise, the update will be performed through the standard \acs{pml} update.
The \acs{pml} boundary can also be used in conjunction with the periodic boundary condition. Currently, no such combination of boundaries is needed for the simulation of the \acs{katrin} source.
\section{Background Fields and Currents}
\label{sec:acronym:background}
The application of background fields and currents plays a vital role in the simulation of the plasma in the \acs{katrin} source. They originate, for example, from the superconducting magnets, the potential differences of the beam tube surfaces, and the motion of the ions. In the context of this thesis, only static backgrounds are considered. They can easily be added to the field values of the standard \acs{pic} algorithm.
\paragraph{Electromagnetic Background}
The electromagnetic background can originate from various sources, see sections~\ref{ssec:katrin:E_bg} and \ref{ssec:katrin:B_bg}. As mentioned before, only static fields are considered here. The static fields do not contribute to the temporal evolution of the electric fields directly, see Maxwell's equation in section~\ref{ssec:pic_maxwell_solver}. Therefore, they do not have to be considered in the field update. They only need to be applied at the particle movement step, see section~\ref{ssec:boris_push}. The background fields are simply added to the evaluated field of equation~\ref{eq:pic:field_interpolation}. The background fields, which are present at the \acs{katrin} experiment, do not change significantly over small distances. It was therefore decided to forgo an interpolation to the particle position, which reduces computational effort.
The field values of the background have to be provided, prior to the simulation. This can either be done via a position dependent function or through discrete data values in a file. The corresponding values at the cell positions are then calculated in the code. The background field needs to be evaluated at the particle position at each timestep. Thus, it is imperative that the evaluation of the field takes as little computational time as possible. It was therefore decided to store the background field values in a separate array. This array is filled at the start of the simulation through the given input. The size of the array is chosen in such a way, that it coincides with the array of the dynamic field values. This way, the cell index of a particle needs to be evaluated only once for the dynamic array and can be used also in the determination of the background field.
\paragraph{Current Background}
The \acs{karl} code can provide position dependent particle currents. They can be used to determine a drift velocity for the injected particles (see section~\ref{sssec:acronym:injection:inital_loading:velocity}), or they can be directly incorporated in the current array of the simulation. The former can be used for electrons and ions. The later can only be used for ions, because the current of electrons changes significantly during the simulation. Thus, the electron current cannot be assumed to be constant. The ion movement on the other hand can be assumed to be constant during the simulation because of their large mass. Therefore, the contribution of the ions on the simulation can be represented by a static background current.
The static background current is implemented as an additive term for the current array. The current array will be calculated in each timestep from the particle movement, see section~\ref{ssec:pic_current_deposition}. Thus, the background current can be used as a starting value of the current array. In the standard \acs{pic} algorithm, this current is set to zero. The background current values have to be provided, prior to the simulation, similar to the background electromagnetic fields. Again, it was decided to store the values in a separate array, which is filled at the start of the simulation through the given input. This procedure reduces the computational overhead, in such a way that the background current have to be copied only once in each timestep.
\section{Particle Injection}
\label{sec:acronym:injection}
The injection of particles into the simulation domain can be classified into two separate steps. Particles can either be injected directly at the start of the simulation, called initial loading, or they can be injected during the simulation. In the initial loading step, the simulation domain is filled with particles from a given particle distribution. In the context of this thesis, the particle distribution is given by the results of the \acs{karl} simulation. The injection during the simulation can be used to describe the connection of an open simulation domain with the bulk of a plasma, or even the generation of particles through Tritium decay. Both injection steps have a significant influence on the simulation and are therefore discussed here in detail.
\subsection{Initial Loading}
\label{ssec:acronym:injection:inital_loading}
The initial distribution of particles is generated by the \acs{karl} code, see~chapter~\ref{ch:karl}. The distribution is classified by the spectrum of the electrons, as well as the mean current of the particles. For the \acs{acronym} simulation, this information needs to be translated into the number of particles ppc, which are inserted in each cell, the macro factor of the macro particles $w_\alpha$, the kinetic energy of these particles $E_\text{kin}$, and the direction of movement $\vec{v}$. The evaluation of each of these properties will be described in the following sections.
\subsubsection{Particles Per Cell and Macro Factor}
\label{sssec:acronym:injection:inital_loading:ppc_mf}
At the start of the simulation, each cell will be filled with a given number of macro particles. The particles will have a mass and a charge, both scaled by the macro factor. The number of particles per cell for each particle species $\alpha$, short $\text{ppc}_\alpha$, and the macro factor $w_\alpha$ are linked by the density $n_\alpha$ through
\begin{equation}
w_\alpha = \frac{n_\alpha \cdot \Delta x^3}{\text{ppc}_\alpha} \fullstop
\end{equation}
The density $n_\alpha$ is directly provided by the \acs{karl} simulation. The cell size $\Delta x$ is calculated from the maximum absolute density, see equation~\ref{eq:acronym:cell_size}.
The density of the particles is dependent on the position inside the source. Thus, two different scenarios are possible to incorporate this effect into the simulation: either the macro factor is position dependent and the number of particles per cell is fixed, or the other way around that the number of particles per cell is position dependent and the macro factor has a fixed value. The \acs{karl} simulations show, that the electron density varies by approximately two orders of magnitude, whereas the ion density varies by approximately one order of magnitude. In a plasma, quasi-neutrality can be assumed, see section~\ref{sec:introduction_to_plasmas}. Thus, the electron and ion density will equalize at some point in the simulation cycle between \acs{acronym} and \acs{karl}. Hence, it can be assumed that the density differences will be lower in the plasma at \acs{katrin} than in the first simulation of \acs{karl}. This also means, that large fluctuations of the number of particles is no longer the governing issue for the simulation. Therefore, it was decided to use a position dependent number of particles per cell. An additional benefit of this decision is the reduced effort in the analysis of the output data, because the number of particle species is kept low.
The choice of a position dependent number of particles per cell introduces a new challenge: the number of particles is an integer value, while the density has continuous values. This issue is resolved by the following consideration. The integer number of particles, which are injected in a cell $\text{ppc}(i,j,k)$ is calculated from the continuous value $\text{ppc}(\vec{x})$
\begin{equation}
\text{ppc}(i,j,k) =
\begin{cases}
\text{ppc}_f \hspace{1cm} & \text{ppc}(\vec{x}) - \text{ppc}_f < \eta \\
\text{ppc}_c \hspace{1cm} &\text{else}
\end{cases}
\end{equation}
where $\eta \in [0,1)$ is a random number, $\text{ppc}_f$ is the next lower integer value of $\text{ppc}(\vec{x})$, and $\text{ppc}_c$ is the next higher integer value of $\text{ppc}(\vec{x})$. The continuous value $\text{ppc}(\vec{x})$ is calculated from the position dependent value of the density $n(\vec{x})$ through
\begin{equation}
\text{ppc}(\vec{x}) = \frac{n(\vec{x})}{n_\text{max}} \cdot \text{ppc}_\text{max}
\label{eq:acronym:position_dependent_ppc}
\end{equation}
where $\text{ppc}_\text{max}$ is a predefined number. For a large enough number of cells, this method will reproduce the shape of the density. As described before, the accuracy of this method hinges on the expected density variation, but also on the maximal number of particles per cell $\text{ppc}_\text{max}$. The larger $\text{ppc}_\text{max}$ is, the better is the accuracy.
The procedure of a variable number of particles per cell requires a position resolved density with a position resolution of the cell size. In general, the size of density bins of the \acs{karl} simulation is larger than the cell size of the \acs{acronym} simulation. Therefore, the output of the \acs{karl} simulation needs to be interpolated to the cell positions $\vec{x}$. The density at position $\vec{x}$ is evaluated through a bilinear interpolation of the radial and longitudinal bin centers \citep{Kirkland.2010}. The azimuthal discretization is neglected because of the azimuthal symmetry of the simulation.
The maximum number of particles in each cell $\text{ppc}_\text{max}$ from equation~\ref{eq:acronym:position_dependent_ppc} needs to be specified before the simulation. In general, it is preferable to have many particles per cell to reduce the noise of the simulation. Nevertheless, the particle update is very time-consuming. Thus, the maximum number of particles in each cell is bound by the computational resources available. The necessary computational resources for a simulation can be described by the time the simulation takes and how many processors are involved in the calculation. The use of many particles per cell increases the time a simulation takes. This time can be reduced by facilitating parallel computation, by increasing the number of processors. The particle update and the field update can each be done in parallel, because the outcome is only dependent on the prior status. \acs{acronym} is designed to be used with many processors. The simulation domain is subdivided into cubes, each containing several cells of the Yee-grid. Each processor is responsible for the particle and field update in its region. Corresponding boundary conditions and communication between the processors were set up. \citet{Kilian.2015} evaluated the number of particle updates per wall-clock second in dependence on the number of processors. Thus, it can be evaluated how long a simulation will take, given the number of simulated particles and number of processors. This evaluation needs to be in line with the available computational resources.
The evaluation of the number of particles can be applied to the data of the \acs{karl} simulation to find the best values of $\text{ppc}_\text{max}$. Three distinct regions can be found in the electron spectrum: a thermal region, a beta region and the transitional region, see section \ref{sec:karl:field_free_simulation}. The densities of these regions are significantly different from each other. Most of the electrons reside in the thermal region, whereas the other two regions make up only a small fraction of the total electron density. If all electrons are represented through a single particle species with one macro factor and assuming $\text{ppc} = \num{20}$, this will result in a macro factor of $w \approx \num{5.5}$ for a total density of $n \approx \SI{5.7E5}{cm^{-3}}$. Thus, almost every real particle can be represented in the simulation as a macro particle. If the particle energy is sampled from the entire spectrum, the simulation can suffer from a large statistical uncertainty, because of the large density difference between the high-energy region and the thermal region. It was therefore decided to subdivide the spectrum into the three distinct regions in the simulation. Each region will be represented by its own particles, with their own number of particles per cell and therefore own macro factor.
This procedure introduces a new issue: the macro factor of the transitional and beta region is well below one ($w_\text{tr} \approx \num{0.08}$ and $w_\text{beta} \approx \num{6.5E-5}$ at $\text{ppc} = 1$). This way, each macro particle represents only a fraction of an electron. From a numerical standpoint, this is no problem. Nevertheless, this procedure also introduces an artificially homogeneous plasma. Dedicated simulation will have to be performed to study this behavior.
\subsubsection{Sampling of the Kinetic energy}
\label{sssec:acronym:injection:inital_loading:E_kin}
Each particle is initialized with a given kinetic energy. This energy needs to be sampled from a given distribution. This distribution can either be provided by theoretical considerations, approximated functions, or directly through data of a histogram. The sampling method depends on the type of input data. The different methods used in the context of this thesis are described in the following.
\paragraph{Theoretical Consideration}
Some parts of the source spectrum can be classified through an investigation of the origin of the features. Two major contributions can be identified directly from the spectrum of the \acs{karl} simulation, see section~\ref{sec:karl:field_free_simulation}: a thermal region and a beta region. The sampling of an energy value from each of these distributions will be described in the following.
In the source, there are many elastic collisions with the neutral gas. It can therefore be assumed that the particles adopt the energy distribution of the neutral gas. It is assumed in first order that the gas follows the Maxwell-Boltzmann distribution. Thus, the electrons follow the Maxwell-Boltzmann distribution as well. The temperature of the gas is then equal to the temperature of the particles. The energy of the injected particles is sampled in the code directly through the gamma distribution with the parameter $\alpha = \frac{3}{2}$ and $\beta = E_\text{th}$, where $E_\text{th}$ is the thermal energy of the particles. The gamma distribution is a built-in distribution function in the C\texttt{++} standard library \citep{Josuttis.2012} and can be used directly without modification.
The particles of the beta decay initially follow the Fermi distribution. It is therefore beneficial to sample the high-energy part of the spectrum through the Fermi distribution (equation \ref{eq:Neutrino-TdecayRate}). The kinetic energy is sampled in the code through the rejection method \citep{Haghighat.2014}. In the rejection method, a probability distribution function $f(x)$ is sampled through two random numbers $\eta_1 \in [f_\text{min}, f_\text{max}]$ and $\eta_2 \in [x_\text{min}, x_\text{max}]$. The sampled value $\eta_2$ is used as the result of the method if the following condition is met
\begin{equation}
\eta_1 \leq f(\eta_2) \fullstop
\end{equation}
Otherwise, the two numbers are rolled again. The rejection method models the underlying function correctly, but needs the generation of many random numbers to produce one value $x$. The efficiency of the method is given by \citep{Haghighat.2014}
\begin{equation}
\text{efficiency} = \frac{\int_{x_\text{min}}^{x_{\text{max}}} f(x)\mathrm{d}x}{f_\text{max} \cdot (x_\text{max} - x_\text{min})} \fullstop
\end{equation}
In simple terms, the efficiency is low for a function, which covers many orders of magnitude. The Fermi function is one of these functions. Nevertheless, this does not pose an issue for the \acs{acronym} simulations, because the energy only needs to be sampled once at the creation of a particle.
\paragraph{Approximate Function}
Some parts of the spectrum can be described by an arbitrary function $f(x)$. It is not necessary to know the connection of this function to the underlying physics to sample an energy from the function. This method is used in the transitional region of the \acs{karl} results, see section~\ref{sec:karl:field_free_simulation}. Here, the spectrum can be approximated by two power law functions.
In general, the sampling can be done again through the rejection method, which was presented above. If the function is reversible ($f(f^{-1}(x))$ = 1) the sampled value $x$ can then be determined directly by the random number $\eta \in [f_\text{min}, f_\text{max}]$ through
\begin{equation}
x = f^{-1}(\eta) \fullstop
\end{equation}
The inverse method has an efficiency of one. Each roll of a random number generates one random number $x$. Hence, the inverse method is preferable over the rejection method, if the inverse function is available. This is not the case for the Maxwell-Boltzmann distribution and the Fermi distribution.
\paragraph{Histogram Data}
The spectral data from the \acs{karl} simulation is available as a histogram. In this case, the random number $x$ can be sampled directly from this data $f(i)$. The bin index $i$ is found through the random number $\eta \in [0, \sum f(i)]$ for the first bin, which fulfills \citep{Haghighat.2014}
\begin{equation}
\sum_0^i f(i) > \eta \fullstop
\end{equation}
The random number $x$ must be in the interval $[x_i, x_{i+1}]$, where $x_i$ is the left bin border of the bin $i$. The exact value of $x$ is therefore not determined directly. In first order, it can be assumed that the value $x$ is given by the position of the bin center. A more precise resolution is reached through a linear interpolation towards the neighboring bins and a subsequent sampling.
The efficiency of this algorithm is dependent on the efficiency of the search algorithm. The time complexity of most search algorithms scale with $\mathcal{O}(\log N)$. Thus, the efficiency of the algorithm scales with $\frac{1}{\log N}$, where $N$ is the number of bins. The energy resolution of the \acs{karl} simulation is on the order of \num{100} bins, which is comparably low. The histogram method can therefore be used for a wide range of the spectral data.
\subsubsection{Sampling of the Velocity}
\label{sssec:acronym:injection:inital_loading:velocity}
The velocity of the new particles is initiated with entries in all three spatial directions. The norm of the velocity $v_0$ is given by the kinetic energy, which is sampled from a given spectrum, see the previous section. The distribution of the velocity to the three spatial directions is non-trivial.
In first order, it can be assumed that the velocity is distributed isotropically. Thus, the velocity vector $\vec{v}$ is sampled through two random numbers $\eta_1 \in [0, 2 \pi)$ and $\eta_2 \in [0, \pi)$ and ultimately given by
\begin{equation}
\vec{v} = v_0
\begin{pmatrix}
\cos \eta_1 \sin \eta_2 \\
\sin \eta_1 \sin \eta_2 \\
\cos \eta_2
\end{pmatrix}
\fullstop
\label{eq:acronym:isotropic_velocity}
\end{equation}
The benefit of this initiation lies in the simplicity of the algorithm.
The \acs{karl} simulations show that there is a current of the electrons. This current is not represented in the first order approximation. This shortcoming is approached by another approximation, namely that the current can be represented by an additive contribution to the first order approximation of the velocity. Thus, the total kinetic energy of the particle will be greater than the originally sampled energy. On the one hand, this procedure overestimates the kinetic energy of the particles. On the other hand, the current will be represented correctly. A more precise description of the velocity would need to resolve the three velocity directions in the \acs{karl} simulation directly and import them into the \acs{acronym} simulation.
In the second order approximation, the current is divided into a current in longitudinal direction $j_z$ and a current in radial direction $j_r$. These currents can be translated into a drift velocity through
\begin{eqnarray}
v_z(\vec{x}) &= \frac{j_z(\vec{x})}{n(\vec{x})} \comma \label{eq:acronym:drift_velocity}\\
v_r(\vec{x}) &= \frac{j_r(\vec{x})}{n(\vec{x})} \comma
\end{eqnarray}
with the density $n(\vec{x})$. The velocity gained through equation~\ref{eq:acronym:isotropic_velocity} is then boosted by these two velocity contributions. The calculated radial velocity $v_r$ is in general much smaller than the smallest thermal velocity due to the large magnetic field. Thus, it will be neglected in the following. Future extensions might include this contribution. It may also be included through a background current, see section \ref{sec:acronym:background}.
\subsection{Injection During Simulation}
\label{ssec:acronym:injection_during_simulation}
After the initial loading of particles, there can still be the need of injecting particles during the \acs{pic} cycle. This can be the case, where the simulation domain is smaller than the plasma or when there occurs particle decay in the simulated time range. The former is simulated through the use of the \acs{pml} boundary condition in conjunction with the injection of particles at that boundary. The injection can be done in two ways, through the knowledge of the incoming current, or through the assumption of a virtual plane, at which the density is kept constant. Both methods will be shown in the following, followed by the description of the injection of particles through a constant decay rate.
\subsubsection{Injection through Constant Current}
\label{sssec:acronym:injection_constant_current}
In the injection method through a constant current, it is assumed that the current $j(\vec{x})$ flowing towards the simulated plasma is given prior to the simulation, for example by the \acs{karl} simulation. This current can be translated into the number $N_j$ of physical particles, which have to be inserted into a cell per timestep
\begin{equation}
N_j(i,j,k) = j(i,j,k) \cdot \Delta t \cdot (\Delta x)^2 \comma
\end{equation}
where $i,j,k$ are cell indices. This number needs then to be scaled with the macro factor to produce the right amount of macro particles, which need to be injected.
This procedure reproduces the external current at the boundary correctly, but the injection is also independent of the local field at the injection site. The injected current produces an opposing electric field through Ampere's circuital law. In a real plasma, this field will reduce the current flowing towards the plasma and an equilibrium will be found. Contrary to the real case, the current in this method will be kept constant. Thus, the equilibrium is only found if the incoming current matches the outgoing current. In total, this method of injection overestimates the electric field in the plasma and is therefore not favored in the context of this thesis. This assessment might change if a relation between the incoming current and the electric field at the boundary can be found.
\subsubsection{Injection by retaining Constant Density}
\label{sssec:acronym:injection_constant_density}
The injection method through a constant current can show non-physical results, because the electric field at the injection site is not taken into account in the injection process. This problem can be bypassed by the use of the injection method, which retains a constant density at the boundary, also described by \citet{Kilian.2015}. Here, a virtual layer of cells is created at the injection plane. The virtual cells have to coincide with cells of the simulation domain. Therefore, they have access to the electric field at the boundary. The virtual layer will be filled each timestep with particles. The particle loading is analogous to the initial loading step, see section~\ref{ssec:acronym:injection:inital_loading}. The particles will then be moved by one timestep, corresponding to the local electric field at the virtual layer. Only those virtual particles which leave the virtual layer of cells into the simulation domain are copied to the list of macro particles. The other virtual particles will be deleted. This procedure ensures that the incoming current is closely linked to the electric field at the boundary.
Up to this point, the position of the virtual layer inside the simulation domain is not specified. An obvious choice is the last row of cells of the simulation domain. Nevertheless, in combination with the \acs{pml} boundary, two effects have to be taken into account. First, the electric field inside the \acs{pml} boundary is reduced through the \acs{pml} algorithm itself. Thus, there is a reduced dependence of the incoming current with the field of the simulation. Therefore, an injection position closer to the undisturbed simulation domain is preferable. Second, the field in front of the injection site is altered by the injection. In order to keep the size of the boundary layer to a minimum, an injection position, close to the simulation domain boundaries is preferable. In total, a tradeoff between both effects has to be found. No investigation of the injection position was found in the literature. Thus, test simulations were performed with varied injection position.
The test simulation was designed for the case of a plasma inside a conducting cylinder, which is bound at one side by a conducting plate and at the other side by the \acs{pml} boundary condition. The height of the cylinder was chosen to be much greater than the \acs{pml} layer thickness. The \acs{pml} layer was chosen to be \num{10} cells thick, which has shown good results in the past \citep{Kilian.2015}. The virtual layer of injection was set up at three different positions inside the \acs{pml} layer. The spectrum of the injected electrons was chosen to a combination of a low-energy thermal part ($T = \SI{80}{K}$) and a high-energy tritium beta decay part with densities of $n_\text{th} = \SI{1E5}{cm^{-3}}$ and $n_\beta = \SI{7.9E-1}{cm^{-3}}$, which corresponds to the conditions found at the rear wall region. The results of the simulations can be found in figure~\ref{fig:Chapter5_ACRONYM/ParticleInjection/pml_injection_comparison_SI.pdf}.
\xfigure{tb}{1.}{Chapter5_ACRONYM/ParticleInjection/pml_injection_comparison_SI.pdf}{Test of injection position at \acs{pml} boundary.}{
Electric field and charge particle density are collected in the center of the simulated tube after four plasma time scales for three different positions of the injection position. The distance $d_{inj}$ provides the number of cells towards the simulation domain boundary. The simulation was performed in a cylinder with a radius of \num{32} cells and a height of \num{1434} cells. The magnetic field $B_z = \SI{2.5}{T}$ was set in longitudinal direction. Only electrons were simulated. The electron distribution was chosen to include a thermal part ($n_\text{th} = \SI{1E5}{cm^{-3}}$ and $T = \SI{80}{K}$) and a tritium beta decay part ($n_\beta = \SI{7.9E-1}{cm^{-3}}$).}
It can be seen that there is an influence of the injection position on the electric field and density close to the \acs{pml} layer. Further away (more than 25 cells), this influence is negligible. Thus, the total boundary layer of the \acs{pml} boundary with injection of particles is only extended by approximately 25 cells in any of the tested configurations. For simplicity, it was therefore decided to use the injection position at the start of the \acs{pml} layer. More elaborate investigations of the injection position, in respect to the particle density and particle spectrum, might provide a more optimized setup.
\subsubsection{Injection through Constant Decay Rate}
\label{sssec:acronym:injection_constant_decay_rate}
In the source, electrons are created continuously through beta decay of tritium and subsequent ionization. To take this into account, a new injection method was developed, where new particles are injected in each timestep of the simulation. The injection process itself is straightforward. First, the number of injected particles is calculated. Then, this number is converted to the integer number of macro particles to be injected, similar to the initial loading step. After that, the macro particles are sampled from a predefined energy distribution and put into the corresponding cell. In total, only the number of injected particles is the relevant quantity. For this number, a distinction between the primary beta electrons and electrons created by ionization was made, due to their different creation mechanism.
The number of particles created by beta decay of tritium depends only on the density of the neutral gas $n_{T_2}$ and the decay constant $\lambda_{T_2}$. Therefore, the number of macro particles, which have to be injected in each cell per timestep, can be calculated by
\begin{equation}
N_\beta(i,j,k) = \frac{n_{T_2}(i,j,k) \cdot (\Delta x)^3 \cdot \Delta t \cdot \lambda_{T_2}}{w_{\beta}} \comma
\end{equation}
where $w_{\beta}$ is the macro factor of the beta particles. The simultaneous creation of tritium ions is neglected here, but could be implemented with the same number of injected particles.
%The plasma frequency $\omega_\text{pe}$ provides a natural time scale for the effects which are covered by the \acs{acronym} simulation. The maximal plasma frequency at the \acs{katrin} experiment is approximately \SI{5E7}{Hz}, see section~\ref{sec:frequencies}. The activity of the source can reach values up to \SI{E11}{Bq}. Thus, in one plasma time scale up to \num{2E3} beta electrons are created in the whole source through decay.
Each beta electron can create several other electrons through ionization, named here secondary electrons. The interplay between the movement of the beta particles, the ionization process and subsequent scatterings of the secondary particles is complex. Thus, it is difficult to estimate the correct position and with which energy the secondary particles have to be injected. A first order approximation can be gained through two assumptions. First, each beta electron creates a fixed number of secondary electrons $a_\text{sec}$. Second, the density of the secondary electrons scales with the initial density of the beta particles. The number of injected secondary particles $N_\text{sec}$ is then calculated as
\begin{equation}
N_\text{sec}(i,j,k) = \frac{1}{w_\text{sec}} N_\beta(i,j,k) \cdot a_\text{sec} \cdot \frac{n_\text{sec}(i,j,k)}{\max (n_\text{sec}(\vec{x}))} \comma
\end{equation}
where $n_\text{sec}(i,j,k)$ is the predefined density distribution and $w_\text{sec}$ the macro factor of the secondary electrons.
It is apparent, that the injection through a constant decay rate neglects the particle flow of secondary and primary electrons, as well as interactions with the neutral gas. Nevertheless, assuming that the collisionality between electrons and gas is low, it can act as a first approximation. Future connected atom- and plasma-physics simulations might resolve this issue.
\section{Electrostatic Potential derived by Poisson Equation}
\label{sec:acronym:poisson}
One result of the \acs{acronym} simulations is the electric field on the Yee-grid at different timesteps. A more accessible parameter can be the electrostatic potential. A method for the evaluation of the electrostatic potential from an input electric field will be presented in the following.
In general, the electric field can be represented by the superposition of a curl-free and a divergence-free field, following the Helmholtz-theorem. These fields are also called longitudinal ($\vec{E}_l$) and transversal ($\vec{E}_t$) fields. A curl-free field can be resolved to a scalar potential $\phi$, whereas a divergence-free field can be resolved to a vector potential $\vec{A}$ through
\begin{eqnarray}
\vec{E} =& \vec{E_l} + \vec{E_t} \comma \\
\vec{E_l} =& -\nabla \phi \comma \\
\vec{E_t} =& \nabla \times \vec{A} \fullstop
\end{eqnarray}
The scalar potential can be derived directly from the electric field by using $\nabla (\nabla \times \vec{A}) = 0$ through
\begin{eqnarray}
\vec{E} =& -\nabla \phi + \nabla \times \vec{A} \comma \\
\nabla \cdot \vec{E} =& -\nabla^2 \phi \fullstop \label{eq:acronym:poisson}
\end{eqnarray}
The last equation can be identified with the Poisson equation through the use of Gauss's law. So, the electrostatic potential can be derived from a generic electric field in two steps. First, the electric field is converted into a charge density through Gauss's law, see also equation~\ref{eq:maxwell_gauss}. Second, the density is then used to solve for the electrostatic potential. The solution of the Poisson equation in cylinder coordinates with an azimuthal symmetry is already shown in section~\ref{ssec:karl:poisson_solver}. Thus, only the conversion of the electric field will be discussed here.
The approach can be described in three steps. First, Gauss's law is described in cylinder coordinates. Second, the derivatives in Gauss's law are converted into finite differences. Third, boundary conditions are set up. Special treatment is needed in the case of zero radius.
Gauss's law in cylinder coordinates can be written as
\begin{equation}
\begin{split}
4 \pi \rho & = \nabla \cdot \vec{E} \\
& = \frac{\partial E_r}{\partial r} + \frac{E_r}{r} + \frac{\partial E_z}{\partial z} \comma
\end{split}
\end{equation}
assuming an azimuthal symmetry. This equation can be solved numerically through the use of finite differences. The central difference scheme is used here for the derivatives, because density and fields are given at different positions, see section~\ref{ssec:pic_yee_grid}. For the second term, it is assumed that the field at the position of the density can be calculated as the mean value of the neighboring field values. So in total, the density at the cell corners with radial and longitudinal coordinates $(i,j)$ calculates as
\begin{align}
4 \pi \rho_{i,j} = \frac{E_{r;i,j} - E_{r;i-1,j}}{\Delta r} + \frac{E_{r;i,j}+E_{r;i-1,j}}{2i \cdot \Delta r } + \frac{E_{z;i,j} - E_{z;i,j-1}}{\Delta z} \comma
\label{eq:acronym:finite_difference_gauss}
\end{align}
where $\Delta r$ and $\Delta z$ are the cell sizes in radial and longitudinal direction.
It can be seen, that equation~\ref{eq:acronym:finite_difference_gauss} diverges for zero radius ($i = 0$). L'Hôpital's rule can be used to resolve this issue, because the radial electric field vanishes in the limit of zero radius. The second term in Gauss's law can therefore be written as
\begin{equation}
\lim_{r\to 0} \frac{E_r}{r} = \frac{\partial E_r}{\partial r}\fullstop
\end{equation}
The derivative of the electric field at zero radius can be evaluated through the method of finite differences, because the electric field at position $i = -1$ is equal to the negative value at $i=0$ (radial symmetry). The density at zero radius can therefore be calculated as
\begin{equation}
4 \pi \rho_{0,j} = 4 \frac{E_{r;0,j}}{\Delta r} + \frac{E_{z;0,j} - E_{z;0,j-1}}{\Delta z} \fullstop
\end{equation}
Lastly, the calculation of the density is completed by setting up boundary conditions. Three different boundary conditions are described here: Dirichlet boundaries, Neumann boundaries and periodic boundaries. Dirichlet boundaries are used for the transition towards the beam tube walls (\acs{pec} boundary). For the \acs{acronym} simulations, it is assumed that the potential is only generated by the particles inside the cavity. Any external field, like the rear wall field, is added only in the particle movement step, see section~\ref{sec:acronym:background}. Therefore, only the dynamic field data is exported from the simulation each timestep, and the background only once. For the total electric field, both values have to be added. This also means, that in the estimation of the potential from the dynamic field values with Dirichlet boundaries, the boundary can be treated as grounded and with zero density. The background potential is then added later on. The Neumann boundary is used at the transition of the plasma towards vacuum (\acs{pml} boundary). Here, the longitudinal electric field is set to zero. Thus, the calculation of the density is carried out with $E_{z;i,J+1} = 0$, where $J$ is the maximum index of the electric field in longitudinal direction. At the periodic boundary, the density is calculated with $E_{z,i,-1} = E_{z,i,J}$.
%\xfigure{h}{1.}{Chapter5_ACRONYM/ElectrostaticPotential/finite_difference_sketch.pdf}{Sketch }{}
%\subsection{Fourier Method}
%During the PIC simulations the data from the fields is stored at the hard drive. These fields contain the eletric and magnetic fields ($\vec{E}$,$\vec{B}$) as well as the current ($\vec{j}$) and the particle density ($\vec{rho}$) on all grid positions. In a post simulation step this data has to be transformed to provide meaningfull results. Some of the procedures are shown in the following subsections.
%The write process on the hard drive is time consuming. Hence the data is not stored every timestep.
% \subsection{Cylindrical Fields}
% The field vectors in the output file are given in cartesian base ($\vec{e}_x$,$\vec{e}_y$ and $\vec{e}_z$) in the Yee-grid. In most cases the simulation is performed with cylindrical boundaries. So it can be benefitial to show the fields in a cylindrical base ($\vec{e}_r$,$\vec{e}_\theta$ and $\vec{e}_z$).
% In the following calculation it is assumed that the electric and magnetic fields are given at the cell corners, but not accordingly to their position on the Yee-grid at the edges or faces. This method provides one resulting cylindrical field vector per cell in contrast to three vectors. It introduces a small error but allows for easier grafical representation of the data.
% First the coordinates of the grid points have to be transformed to cylinder coordinates using
% \begin{align}
% r &= \sqrt{(x-x_c)^2+(y-y_c)^2} \comma \\
% \theta &= \atantwo((y-y_c),(x-x_c)) \comma \\
% z &= z-z_c \comma
% \end{align}
% where $\vec{x}_c$ is the position of the cylinder origin in cartesian coordinates. Second the base is transformed following
% \begin{align}
% E_r &= E_x \cdot \cos{\theta} + E_y \cdot \sin{\theta} \comma \\
% E_\theta &= -E_x \cdot \sin{\theta} + E_y \cdot \cos{\theta} \comma \\
% E_z &= E_z \fullstop
% \end{align}
% \subsection{Electrostatic Potential}
% An eletric field can be represented by the superposition of a curl-free and a divergence-free field following the Helmholtz-theorem \cite{}. These fields are also called longitudinal ($\vec{E}_l$) and transversal ($\vec{E}_t$) fields. A curl-free field can be resolved to a scalar potential $\phi$ whereas a divergence field can be resolved to a vector potential $\vec{A}$.
% \begin{align}
% \vec{E} &= \vec{E_l} + \vec{E_t} \\
% \vec{E_l} &= -\nabla \phi \\
% \vec{E_t} &= \nabla \times \vec{A}
% \end{align}
% The scalar potential can be derived directly from the eletric field by using $\nabla (\nabla \times \vec{A}) = 0$
% \begin{align}
% \vec{E} &= -\nabla \phi + \nabla \times \vec{A} \\
% \nabla \vec{E} &= -\nabla^2 \phi \label{eq:poisson}
% \end{align}
% Equation \ref{eq:poisson} discribes the well know poisson equation when using Gauss's law. In this case we use the fourier transformation to solve for the potential
% \begin{align}
% \mathcal{F}\left(\nabla \vec{E}(\vec{x})\right) &= \mathcal{F}\left(-\nabla^2 \phi(\vec{x})\right) \\
% \vec{k} \cdot \vec{E}(\vec{k}) &= - \left\Vert\vec{k}\right\Vert^2 \phi(\vec{k}) \\
% \rightarrow \phi(\vec{x}) &= \mathcal{F}^{-1} \left( -\frac{\vec{k} \cdot \vec{E}(\vec{k})}{\left\Vert\vec{k}\right\Vert^2} \right)
% \end{align}
% \todo{Discrete case}
% Calculation above only for continious field. Here discrete case. $\nabla \vec{E}$ is also discrete. When going to fourier space we need a filter term to reduce noise on small real scales. See Langdon etc. \\
% \todo{Field position different from potential}
% E field on edges, which is $\frac{dx}{2}$ off from corners. $F(E(x+dx/2)) = E(k) \cdot exp(-i \pi*k)$ \\
% \todo{Test case for point charge}
% Show picture of E field from point charge, than potential with filter, without filter
% \subsection{Transversal and Longitudinal Fields}
% Used to find modes. Needs time dependence. Very cpu intensive from output.
\section{Validation of ACRONYM Simulations}
\label{sec:acronym:validation}
In the context of this thesis, the generic \acs{acronym} code was extended to incorporate circular boundary conditions, background electromagnetic fields and background currents. These additions need to be tested to ensure their functionality. Each single module in the code underwent a standard unit test, in order to verify that the module produces the intended result. These tests however cannot show, if a module produces physical results. Thus, additional tests were set up. They are described in the following.
\subsection{Ion Current Approximation}
\label{ssec:acronym:validation:background_current}
In the simulation, it is assumed that the movement of the ions can be described by a constant contribution to the total current, see also section~\ref{sec:acronym:background}. Hence, no simulation of the ion movement is necessary. This hypothesis was validated through a comparison between a simulation with ion macro particles and a simulation with background current, later on called simulation with particles and simulation with background. If the hypothesis is true, then both simulations should show the same behavior in the development of the total current and of the electric field. Small variations are expected due to the statistical nature of the particle initiation.
Both simulations were carried out with an electron density of $n_\text{e} = \SI{1E5}{cm^{-3}}$ and \num{20} electrons per cell. The electrons were initiated with a thermal velocity distribution ($T_\text{e} = \SI{30}{K}$). The simulation domain was chosen to be a cube with periodic boundary conditions in all three dimensions of space. No magnetic background field was used. Both simulations were performed for two plasma time scales.
\xfigure{h!}{1.}{Chapter5_ACRONYM/Validation/IonCurrentApproximation/comparison_cube_SI.pdf}{Validation of background current.}{Comparison of two simulation with ion macro particles (particles) and with background current (background). The $z$-component of the charge current and mass current are measured along a line in $z$-direction in the center of the simulation domain.}
In the simulation with particles, the ion density and number of particles per cell were chosen equal to the settings of the electrons. The ions were initiated with a thermal velocity distribution ($T_\text{i} = \SI{30}{K}$) and with an additional drift velocity in $z$-direction $v_\text{d} = \SI{1E6}{\centi\meter\per\second}$. The value of the background current $j_\text{c}$ for the other simulation then calculates as
\begin{equation}
j_{\text{c}} = e \cdot n_\text{i} \cdot v_\text{d} \approx \SI{16}{\nano\ampere\per\centi\metre\squared}
%\SI{48}{statC \per\centi\metre\squared\per\second} \comma
\end{equation}
where $n_\text{i}$ is the ion density. The charge current, mass current and electric field of the test simulations on the central axis in $z$-direction can be found in figure~\ref{fig:Chapter5_ACRONYM/Validation/IonCurrentApproximation/comparison_cube_SI.pdf}.
At first, it was inspected, how the ions have moved during the simulation and if they retained their movement during the simulation. The behavior of the ions was investigated through the mass current. The mass current is dominated by the mass of the ions, and therefore it only shows the movement of the ions. The simulated mass current showed the expected value of
\begin{equation}
j_m = m_\text{i} \cdot n_\text{i} \cdot v_\text{d} \approx \SI{1.6E-16}{\kilo\gram\per\centi\metre\squared\per\second} \comma
\end{equation}
compare center of figure~\ref{fig:Chapter5_ACRONYM/Validation/IonCurrentApproximation/comparison_cube_SI.pdf}. Small variations in the simulated mass current were expected due to the statistical nature of the particle initiation. The mass current did not show any indication, that it has changed after initialization. It can therefore be assumed that the ion current was directed at the positive $z$-direction at all timesteps and that it had the same value during the simulation.
In a second step, it was compared if both simulations show the same result for the electric field and the electric current. It can be seen in figure~\ref{fig:Chapter5_ACRONYM/Validation/IonCurrentApproximation/comparison_cube_SI.pdf}, that both simulations produced similar values. Only slight differences are observable, which is expected. Thus, the electrons behaved similar in both simulations, even though the origin of the ion current was different.
The absolute value of the charge current and electric field is of no special interest for the validation. Nevertheless, two interesting observations can be made: the electric field $E_z$ is negative at all positions, and the charge current is negative as well. Thus, the ion movement induces an electric field, which is opposing the movement of the ions. This electric field accelerates the initial static electrons to the positive $z$-direction. Therefore, the initial positive charge current is reduced, in this case even to negative values. This simplistic explanation can only provide a rough estimation of the processes in the plasma and is no full analytic calculation. Nevertheless, the general idea, that an ion current will be opposed by the electron movement, can be grasped.
In total, it can be concluded that the background current can be used to simulate the movement of ions in the plasma. This approximation is only valid for short time scales, where the ion movement is not changed significantly by the electric field.
\subsection{Background Electric Field}
\label{ssec:acronym:validation:background_field}
Simulations with background current showed, that the background current incites an electric field. The field accelerates electrons, to match the movement of the ions. This observation is now reversed to test the use of a background electric field. In the tests, a simulation with background current was compared to a simulation with background electric field. It was expected, that the electric field with the same strength as in the background current simulation incites a similar current in the particles.
Both simulations were carried out with an electron density of $n_\text{e} = \SI{1E5}{cm^{-3}}$ and \num{20} electrons per cell. The electrons were initiated with a Maxwellian velocity ($T_\text{e} = \SI{30}{K}$). The background current was set to $j_\text{bg} \approx \SI{16}{\nano\ampere\per\centi\metre\squared}$. The background electric field was set to $E_{z,\text{bg}} = \SI{-8.7E-3}{\volt\per\centi\metre}$, which corresponds to the mean electric field of the simulation with background current. Both simulations were performed for two plasma time scales. The comparison of the resulting currents can be found in figure \ref{fig:Chapter5_ACRONYM/Validation/ElectricBackgroundField/comparison_cube_SI.pdf}.
\xfigure{tb}{1.}{Chapter5_ACRONYM/Validation/ElectricBackgroundField/comparison_cube_SI.pdf}{Validation of background electric field.}{Comparison of two simulations with background current (current) and with background electric field (field). The $z$-component of the charge current is measured in $z$-direction along a line in the center of the simulation domain.}
It was observed, that the electric background field generates a current in the simulation. This current is pointed in the same direction and has a comparable value as in the simulation with the background current only, see figure~\ref{fig:Chapter5_ACRONYM/Validation/ElectricBackgroundField/comparison_cube_SI.pdf}. This shows qualitatively that the basic expectation of the test could be confirmed: the background field incites a movement of the electrons. A quantitative analysis can be performed through a look on the mean value of the current. The mean values over the whole simulation domain calculate to
\begin{eqnarray}
j_z(j_\text{bg}) &= \SI{-8.3 +- 3.3}{\nano\ampere\per\cm\squared} \\
j_z(E_\text{bg}) &= \SI{-11.7 +- 2.7}{\nano\ampere\per\cm\squared}
\end{eqnarray}
The uncertainty of the mean value is calculated as the mean deviation. It is apparent, that the simulation with the background field shows a higher mean value. Nevertheless, both mean values show overlapping uncertainties. Therefore, both simulations could in principle show the same result, only moderated by statistical fluctuations. However, both simulations also show a basic difference. In the simulation with background current, the current excites an electric field, which in turn accelerates charges. In the simulation with background field, the field directly accelerates the charges. Thus, there is no intermediate step in the simulation with background field. It is therefore likely, that the time scales of both simulations do not match and one simulation is ahead of the other. A determination of this effect is of no further interest for the validation step, and is therefore not pursued here. Notwithstanding, it can be concluded that the background electric field works as expected, because the simulated current shows the expected behavior from the simulation with background current.
\subsection{Cavity Mode Excitation}
\label{ssec:acronym:validation:cavity_mode}
A hollow conducting cylinder can act as a waveguide for electromagnetic waves. Only waves with a specific frequency and shape are allowed by Maxwell's equations. These specific waves are called cavity modes. Cavity modes can be used to test and classify electromagnetic solvers, which also deal with conducting boundaries. The method described in this section mainly follows the approach of \citet{Nieter.2009}. First, the frequency of all possible modes will be determined analytically. Second, cavity modes in an empty cylinder will be excited in the simulation through a driving current. Third, the simulated frequency of the modes will be compared to the analytically calculated frequency, which provides an estimate on the error of the simulation.
The frequency of possible modes will be derived through the use of the wave equation in a cylindrical geometry. If the waveguide is aligned in $z$-direction, then the wave will travel in that direction as well. The electric field in this case can be written as
\begin{equation}
\vec{E}(\vec{r}, t) = \vec{E}(r,\phi) \cdot \exp (i (\omega t - k_z z) \comma
\end{equation}
where $\omega$ is the frequency of the mode, $k_z$ the wave mode number in $z$-direction, $\vec{r}$ a space vector, $r$ the radius, and $\phi$ the polar angle. The same ansatz can be pursued for the magnetic field. The full derivation of the fields can be found in \citep{Pozar.2011}. Here it will be focused on the solution only.
The solution for the electromagnetic fields is obtained by using the boundary conditions of the cavity. Two general boundary conditions have to be fulfilled for the electric and magnetic field at conducting boundaries: a vanishing tangential component of the electric field and a vanishing normal component of the magnetic field. The resulting solutions for the wave equation can be classified into two categories: the TM modes, where the magnetic field is zero in the direction of propagation, and the TE modes, where the electric field is zero in the direction of propagation. The corresponding electric fields will be presented in the following.
The spatial distribution of the electric field of a TE mode is calculated by
\begin{eqnarray}
E_r(\vec{r}) =& E_{r,0} \cdot \frac{-n \omega }{k^{\prime 2}_{n,m}}
\cdot \frac{J_n(k^\prime_{n,m} \cdot r)}{r}
\cdot \left( A \cos(n\phi) - B\sin(n\phi)\right)
\cdot \sin(k_z z)
\comma \\
E_\phi(\vec{r}) =& E_{\phi,0} \cdot \frac{\omega}{k^\prime_{n,m}}
\cdot J^\prime_n(k^\prime_{n,m} \cdot r)
\cdot \left( A \sin(n\phi) - B\cos(n\phi)\right)
\cdot \sin(k_z z)
\comma \\
E_z(\vec{r}) =& 0
\end{eqnarray}
with the Bessel function $J_n$ and its derivative $J_n^\prime$, the factors $A$ and $B$, which will be chosen to $1/\sqrt{2}$, and the so-called cutoff wavenumber $k_c^\prime := k^\prime_{n,m}$. The cutoff wavenumber must fulfill
\begin{equation}
J^\prime_n(k^\prime_{n,m} \cdot R) = 0 \comma
\end{equation}
with the radius $R$ of the cylinder and the number $m$ of the root of the derivative of the Bessel function. If the cylinder is also terminated by a conducting plate, then the wavenumber $k_z$ must fulfill
\begin{equation}
k_z = \frac{l \pi}{L} \comma
\end{equation}
where $L$ is the length of the cylinder and $l$ is an integer value. In the end, the frequency of the TE wave is calculated by
\begin{equation}
\omega^2 = \left(k_c^{\prime 2} + k_z^2 \right) c^2 \fullstop
\label{eq:acronym:validation:cavity_mode:TE_frequency}
\end{equation}
The derivation of the field for the TM mode follows analogously to the derivation for the TE mode. The spatial distribution of electric field of a TM mode is calculated by
\begin{eqnarray}
E_r(\vec{r}) =& E_{r,0} \cdot \frac{k_z}{k_{n,m}}
\cdot J_n^\prime(k_{n,m} \cdot r )
\cdot \left( A \cos(n\phi) - B\sin(n\phi)\right)
\cdot \sin(k_z z)
\comma \label{eq:acronym:validation:cavity_mode:TM:Er}\\
E_\phi(\vec{r}) =& E_{\phi,0} \cdot \frac{n k_z}{k_{n,m}^2}
\cdot \frac{J_n(k_{n,m} \cdot r)}{r}
\cdot \left( A \sin(n\phi) - B\cos(n\phi)\right)
\cdot \sin(k_z z)
\comma \label{eq:acronym:validation:cavity_mode:TM:Ephi} \\
E_z(\vec{r}) =& E_{z,0} \cdot k_{n,m}
\cdot J_n(k_{n,m} \cdot r)
\cdot \left( A \cos(n\phi) - B\sin(n\phi)\right)
\cdot \sin(k_z z)
\comma \label{eq:acronym:validation:cavity_mode:TM:Ez}
\end{eqnarray}
with the cutoff wavenumber $k_c := k_{n,m}$. The cutoff wavenumber must fulfill
\begin{equation}
J_n(k_{n,m} \cdot R) = 0 \fullstop
\end{equation}
All in all, the frequency of the TM mode is calculated by
\begin{equation}
\omega^2 = \left(k_c^{2} + k_z^2 \right) c^2 \fullstop
\label{eq:acronym:validation:cavity_mode:TM_frequency}
\end{equation}
An example of the spatial distribution of the electric field of a TM mode in $z$-direction can be found in figure~\ref{fig:Chapter5_ACRONYM/Validation/CavityMode/cavity_mode_Ez.pdf} for variable values of $n$ and $m$.
\xfigure{tb}{1.}{Chapter5_ACRONYM/Validation/CavityMode/cavity_mode_Ez.pdf}{Electric field distribution of TM modes.}{The values are generated by simulation through mode excitation with $n \in [0,1]$ and $m \in [1,2]$. The fields show structure of the Bessel function in radial direction and sine structure in azimutal direction.}
In total, the frequency of the TE and TM modes can be calculated directly from the radius and height of the cylinder and the mode numbers $n$, $m$ and $l$ through equations~\ref{eq:acronym:validation:cavity_mode:TE_frequency} and~\ref{eq:acronym:validation:cavity_mode:TM_frequency}.
In the second step, the frequency and spatial distribution of the modes can be used to excite cavity modes in a simulated cylinder geometry. The excitation is performed with a driving current, ''whose spatial profile approximates the profile of the known mode (...) The current source will have a Gaussian envelope in time and with a center frequency that matches the known mode frequency.'' \citep{Nieter.2009} An example of the driving current can be found in figure~\ref{fig:Chapter5_ACRONYM/Validation/CavityMode/cavity_mode_excitation.pdf}.
\xfigure{tb}{1.}{Chapter5_ACRONYM/Validation/CavityMode/cavity_mode_excitation.pdf}{Driving current and field response for cavity mode excitation.}{An excitation current with spatial shape of a cavity mode is applied, with the corresponding frequency of the mode and and gaussian envelope. The field in the cavity is excited and the frequency of the mode is determined after the excitation current is switched off.}
In the third step, the electric field is recorded over time after the driving current is reduced to zero, see also figure~\ref{fig:Chapter5_ACRONYM/Validation/CavityMode/cavity_mode_excitation.pdf}. The frequency of the mode is then determined from the temporal evolution of the field. \citet{Nieter.2009} use a fit with multiple sine functions to the data, and use only the frequency of the mode with the largest amplitude as a result. This procedure will not be used here, because it was found to be unstable. In the context of this thesis, the frequency was determined through the use of the fast Fourier transformation of the electric field signal and through the subsequent fit of a Lorentzian to the peak with the highest intensity, see figure~\ref{fig:Chapter5_ACRONYM/Validation/CavityMode/cavity_mode_fit.pdf}. This frequency $f_\text{sim}$ is then compared to the initial excitation frequency $f_\text{ex}$. The relative error $\epsilon$ is then calculated by
\begin{equation}
\epsilon = 1 - \frac{f_\text{sim}}{f_\text{ex}}
\end{equation}
The uncertainty on the frequency and on the relative error is calculated through the maximum between the uncertainty of the fit and the sampling rate. The sampling rate is given by the inverse of the timestep length.
\xfigure{tb}{1.}{Chapter5_ACRONYM/Validation/CavityMode/cavity_mode_fit.pdf}{Determination of the simulated cavity mode frequency.}{The field values are collected at a given position over many timesteps. The signal is then Fourier transformed and the frequency of the highest peak is determined through a fit of a Lorentzian to the data. The estimated frequency is compared to the expected theoretical frequency.}
\paragraph{Validation}
At first, it was investigated qualitatively, if cavity modes can be excited at all in the cavity. Therefore, four different simulations were performed, each with different mode numbers for $n$ and $m$. The excited electric field can be seen in figure~\ref{fig:Chapter5_ACRONYM/Validation/CavityMode/cavity_mode_Ez.pdf}. The structure of the field corresponds to the expected structure of equation~\ref{eq:acronym:validation:cavity_mode:TM:Ez}. It can be seen, that the mode number $n$ increases the azimuthal subdivision of the electric field, while the mode number $m$ increases the radial subdivision. Therefore, it can be concluded that cavity modes can be excited.
In a second step, the algorithm was used for a quantitative analysis of the excited cavity modes. This way, it allowed for a classification of the Maxwell solver of \acs{acronym} with cylindrical boundaries. For this analysis, it was decided to use the excitation of a TM mode with indices $n = 0$, $m = 1$ and $l = 2$ only. This choice of mode numbers is motivated by the simple structure of the electric field. There are no additional features in radial direction, which allows for its use in a simulation with small number of cells in radial direction. Additionally, the frequency of this mode is significantly different from other cavity modes, which reduces the possible confusion of the measured frequency with other modes.
The implemented Maxwell solver in \acs{acronym} was classified in a scenario, where the radius $R$ of the cylinder is set to a fixed value, and the number of cells in radial direction are varied. The cell length $\Delta x$ was determined from the number of cells in radial direction $N_r$ and the radius $R$ of the cylinder
\begin{equation}
\Delta x = \frac{R}{N_r} \fullstop
\end{equation}
In the \acs{acronym} code, the cell length is not chosen directly, but rather the electron density, see equation~\ref{eq:acronym:cell_size}. As a consequence also the timestep length is affected by changes of the cell length and electron density, see section~\ref{ssec:pic_maxwell_solver}. In principle, the timestep length can be adjusted through an additional predefined factor in the code. This adjustment was not done here, to provide an accuracy of the simulation under standard operation conditions. In total, \num{8} different numbers of cells in radial direction were compared, ranging from \num{30} to \num{100} cells. The specific numbers were chosen to reflect the number of cells used later on in the simulations of the \acs{katrin} source, see also chapter~\ref{ch:pic_at_katrin}.
\xfigure{tb}{1.}{Chapter5_ACRONYM/Validation/CavityMode/cavity_mode_f_vs_product.pdf}{Simulated and theoretical cavity mode frequency for various divisions of the radius.}{Theoretical cavity mode frequency and fit of the excited frequency by simulation at different segmentations of a fixed radius. The unceartainty describes the maximum between the unceartainty of the fit and the resolution of the simulation.}
The results of the different simulations can be found in figure~\ref{fig:Chapter5_ACRONYM/Validation/CavityMode/cavity_mode_f_vs_product.pdf}. In general, it can be observed that the cavity is excited by a mode, whose frequency is close to the theoretical frequency. In all cases, the simulated frequency agrees with the theoretical frequency in the limit of the uncertainty of the value. Nevertheless, three additional features are discernible. First, the uncertainty increases with the number of cells. Second, there seems to be a substructure in the simulated frequency. Third, most of the simulated frequency values lie above the theoretical value.
The first feature can be explained by a look at the evaluation of the uncertainty. It is calculated as the minimum between the fitted uncertainty and the sampling rate. The fitted uncertainty is much lower than the sampling rate. Thus, only the sampling rate determines the uncertainty. The sampling rate is dependent on the timestep length, which in turn depends on the number of cells in radial direction. Thus, the uncertainty increases with $N_r$.
The second feature, the substructure in the simulated frequency, can be explained by a combination of two effects: a reduction of the relative error through the increased number of cells, and again the sampling rate. On the one hand, it is expected that the more cells are used for the simulations, the better the geometry can be approximated by the algorithm. Thus, the frequency shows more precise values the higher the number of cells. On the other hand, the simulated frequency is bound by the sampling rate. This means, that if the true frequency is between two frequency data points, then the fit result might abruptly jump from one value to another. This explains the jump of the frequency between \num{50} and \num{60} cells. This hypothesis is supported through the fact that the theoretical frequency is always within the uncertainty bounds of the simulated frequencies, which are dominated by the sampling rate. An additional simulation was performed to test the hypothesis with a reduced timestep length by a factor of five. Here, the relative error was reduced to $\epsilon \approx \num{0.03 +- 0.06}$, not shown in the figure. This value is significantly lower than before, which is expected for a better frequency resolution.
The substructure of the simulated frequencies remembers of a sinodial wave pattern. Nevertheless, the uncertainties are too large to deny or verify this hypothesis from the presented data, and more elaborate simulations would be necessary. However, such an investigation is not gainful in respect to the validation of the implemented algorithm, but rather useful for an improvement of the algorithm itself. The explanations from above are sufficient for a validation of the implementation. It was therefore refrained from an investigation of the substructure pattern in the context of this thesis.
The third feature, the overestimation of the simulated frequency, can be explained by a look on the algorithm, which generates the simulated geometry, see section~\ref{sec:acronym:boundaries}. This algorithm determines the actual division of the simulation domain into cells and identifies, which cells are half cut, outside or inside the geometry. The algorithm is set up in such a way, that the mean radius of the simulated geometry is in almost all cases lower than the actual radius. Thus, the radius in the simulation is always underestimated, which in turn overestimates the resulting frequency.
In summary, it was found, that cavity modes can be excited in the cavity. The distribution of the field corresponds to the distribution of the excitation current. The simulated frequency corresponds to the expected theoretical frequency in the limit of the uncertainty. Deviations arise from the sampling rate and the approximation of the cylindrical shape with half cut cubes. In total, it can be concluded, that the Maxwell solver works as expected and produces reliable results of the electromagnetic fields in a cylindrical cavity.
\subsection{Boundary Layer Development}
\label{ssec:acronym:validation:boundary_layer_development}
When a plasma comes in contact with a metallic or dielectric boundary, it will interact with that boundary. This interaction will create a boundary layer, which will shield the plasma from the influence of the boundary, see section~\ref{ssec:debye_length}. A cohesive theory of all possible plasma states and boundary geometries does not exist. There exist solutions for specific sets of conditions. These solutions mostly assume that the plasma is infinitely extended in one or the other direction, that the velocity distribution of the electrons and ions follows the Maxwell distribution, and that the boundary surface is flat. In these cases, the electric potential drops towards the boundary. The potential difference between the bulk of the plasma and the boundary will adopt values of several $k_b T$. The thickness of the boundary layer will be in the order of the Debye length \citep{Morozov.1991}.
The development of a boundary layer was used to test the new \acs{pec} boundary in conjunction with the \acs{pic} algorithm. The test was subdivided into two steps. First, it was tested if a boundary layer developed towards the \acs{pec} boundary, especially in radial direction. Second, the observed boundary layer thickness and potential drop were used to investigate the behavior of the \acs{acronym} algorithm under similar plasma conditions but different simulation parameters.
The first test was performed for a plasma inside a closed cylinder with radius $R = \SI{4.5}{\centi\metre}$ and height $H = \SI{19.17}{cm}$. The radius was chosen to represent the radius of the \acs{katrin} beam tube. The height was chosen to be significantly larger than the radius, while keeping simulation effort to a minimum. Thus, the height was set to the discretionary value of approximately four times the beam tube radius. The plasma was initialized with an electron density of $n_e = \SI{1E5}{cm^{-3}}$ at $\text{ppc} = \num{20}$. The velocity of the electrons was initiated from a Maxwell Boltzmann distribution with a temperature of $T = \SI{30}{K}$, which corresponds to a thermal energy of $E_\text{th} = \SI{2.59}{meV}$. The simulation was performed for four plasma time scales. No background fields were used. The electric field was recorded at the last timestep. In a post-processing step, the field components in the Cartesian directions were transformed to the radial field $E_r$ through
\begin{equation}
E_r(i,j,k) = E_x(i,j,k)\cdot \cos \theta + E_y(i,j,k) \cdot \sin \theta \comma
\end{equation}
\begin{equation}
\theta = \arctan \left(\frac{j-j_0}{i - i_0}\right) \comma
\end{equation}
where $(i,j,k)$ are cell indices and $i_0$ and $j_0$ are the cell indices of the cylinder origin. This procedure provided simple access to the radial electric field, but is not accurate in the sense, that the field components are positioned at different locations, see section~\ref{ssec:pic_yee_grid}. Nevertheless, this inaccuracy was neglected for simplicity.
\xfigure{tb}{1.}{Chapter5_ACRONYM/Validation/DebyeSheath/E_r_thesis.pdf}{Boundary layer in radial direction.}{Simulated boundary layer in a conducting cylinder filled with a plasma with an electron density of $n_e = \SI{1E5}{cm^{-3}}$ with a thermal velocity distribution ($T = \SI{30}{K}$) after four plasma time scales. The radial electric field is generated in a post processsing step. }
The simulated radial electric field of a two-dimensional slice in the center of the cylinder is depicted in figure~\ref{fig:Chapter5_ACRONYM/Validation/DebyeSheath/E_r_thesis.pdf}. It can be seen that the radial electric field fluctuates around zero in the center of the plasma. The fluctuations are expected for a thermal plasma far away from a boundary. The behavior changes closer to the boundary. There, the field shows a predominant direction and increases towards the boundary. The boundary layer is several cells thick, which corresponds to several Debye lengths. Again, this is expected for a thermal plasma. The thickness of the boundary does not show an azimuthal behavior, which corresponds to the azimuthal symmetry of the simulation. In total, the results of the simulation indicate that the cylindrical boundaries are implemented correctly in the \acs{acronym} code. A more precise analysis was performed in the second test step.
In the second step, the cylindrical boundaries were tested under similar plasma conditions but different simulation parameters: in a simulation with half the number of cells in radial direction and in a simulation with half the cell size. In the later case, the number of particles in the cells was adapted to ensure that the electrons have the same macro factor as before. In both cases it was expected that there is also a region in the plasma, which is not influenced by the boundary and a boundary region, which shows the same potential drop as the simulation with the original radius.
The resulting radial electric field and potential can be found in figure~\ref{fig:Chapter5_ACRONYM/Validation/DebyeSheath/radial_comparison.pdf}. The radius was normalized to the cylinder radius of the simulated cavity for a better comparability. The potential was derived from a two-dimensional slice in $rz$-direction, through the use of the Poisson solver from section~\ref{sec:acronym:poisson}. The potential of the beam tube and cylinder ends was set to $U = \SI{0}{V}$. It can be seen, that all three simulations showed similar results for the electric field and the potential. The specific properties will be described in the following, and differences will be pointed out.
There is a region $(r < 0.8 R)$ in the center of the cylinder, where no influence of the boundary is discernible. Due to the random nature of the variation, it is assumed that the fluctuations of the potential arise from thermal fluctuations. There is another region $(r > 0.8 R)$ with an increased electric field and a potential drop towards the \acs{pec} boundary. The boundary layer is several cells thick, as expected for a Debye sheath. The data indicates that the boundary layer is smaller for the simulation with double the original radius. This behavior can be attributed to the normalization of the radius and has no physical foundation.
The potential drops in all three simulations towards the boundary by approximately \SI{0.8}{mV}. This value corresponds to only a third of the thermal energy, and is lower than expected for a classical Debye sheath. Two explanation attempts can be made. First, the algorithm of the \acs{pec} algorithm used in the context of this thesis, see section~\ref{sec:acronym:boundaries}, underestimates the current towards the beam tubes. Thus, the field generated by that current is lower than expected. The second explanation could be that the potential drop in a cylindrical cavity with a low electron density is lower in reality than in the case of an one-dimensional planar surface. No analytic calculation was found in the literature to prove or disprove this hypothesis. More simulations are necessary in the future to disentangle the effect of the potential at cylindrical boundaries.
\xfigure{tb}{1.}{Chapter5_ACRONYM/Validation/DebyeSheath/radial_comparison.pdf}{Radial boundary layer in a cylindrical cavity.}{The cavity was filled with an electron density of $n_e = \SI{1E5}{cm^{-3}}$ following a thermal velocity distribution ($T = \SI{30}{K}$). The simulation was performed in a cavity with a radius of 30 cells ($R = 30 \Delta x$), with double the radius ($R = 60 \Delta x$), and with the same physical radius but each cell was devided in half ($\Delta x = \frac{\Delta x_0}{2}$). The radius of the data points was normalized to the radius $R$ of the cylinder. The data was taken after four plasma time scales.}
The same three simulations can also be used to investigate the electric field and potential in longitudinal direction. The height of the cylinder of all three simulations was set to the same value. It is expected that there is a boundary layer before both end caps of the cylinder, and that there is a region, where the potential only fluctuates through thermal variation. The corresponding potential and electric field can be found in figure~\ref{fig:Chapter5_ACRONYM/Validation/DebyeSheath/longitudinal_comparison.pdf}. It can be seen that both expectations were met by the simulations. Nevertheless, additional features are discernible, which will be described in the following.
The boundary layer is thicker in longitudinal direction than in radial direction. The layer can be subdivided into two sections. In the first section, there is an initial increase of the potential over a few Debye lengths. In the second section, the potential then decreases over many Debye lengths towards a potential plateau. It seems that the bisection of the potential shape is a result of the intrinsic interaction of the longitudinal and radial boundary condition. In longitudinal direction, the potential builds up for a few Debye lengths, independent of the radial boundary. The interaction with the radial boundary flattens then the potential to lower values in the second section. This hypothesis is supported by another feature observed in the data: The potential difference in longitudinal direction is higher for the simulation with the increased physical radius than for the other two simulations. Thus, the influence of the radial boundary is less strong in the simulation with increased radius. In other words, it seems that the interaction between the tube boundary and end cap boundary impacts only a small region at the end caps. The central part is only dominated by the tube walls.
The absolute value of the potential drop at the longitudinal boundary is larger than in radial direction. It reaches values up to approximately \SI{2}{mV} (depending on the radius of the cavity). Again, this value is below the expected height of a few $k_b T$. Similar to the description of the radial potential drop, it is unclear if the difference to the expected value originates from the missing current of the mirror charges or is a physical reality. The latter hypothesis is underlined by the fact that the potential reaches higher values in the simulation with an increased radius. Thus, the radial boundary seems to have less influence on the longitudinal boundary layer. Nevertheless, more simulations are necessary for a validation of both hypothesis.
\xfigure{tb}{1.}{Chapter5_ACRONYM/Validation/DebyeSheath/longitudinal_comparison.pdf}{Longitudinal boundary layer in a cylindrical cavity.}{The cavity was filled with an electron density of $n_e = \SI{1E5}{cm^{-3}}$ following a thermal velocity distribution ($T = \SI{30}{K}$). The data was taken after four plasma time scales. The simulation was performed in a cavity with a radius of 30 cells ($R = 30 \Delta x$), with double the radius ($R = 60 \Delta x$), and with the same physical radius but each cell was devided in half ($\Delta x = \frac{\Delta x_0}{2}$). The height of the cylinder was kept the same for all three simulations. The position of the data points was normalized to the height $H$ of the cylinder.}
In total, it can be concluded that the implemented \acs{pec} boundary conditions work well with cylindrical boundaries. Simulations show, that a thermal plasma inside a cylindrical cavity produces a boundary layer towards the cavity walls. The absolute potential values were found to be lower than expected. Nevertheless, it could not be differentiated if the observed potential values are of physical nature or a relic of the used boundary conditions.
\section{Conclusion}
This chapter focused on the description of the \acs{acronym} \acs{pic} code, which will be used for the dynamic simulation of the \acs{katrin} plasma. First, the generic code was described in detail. Then the newly added features of the code were presented.
The most prominent feature is the adaptation of cylindrical \acs{pec} boundaries to the simulation. The used algorithm follows the method of Dey-Mittra \citep{Dey.1998}, where the Maxwell solver calculates the new field values corresponding to the edge length of the cells inside the geometry. A reduction of the timestep length was not necessary, because it was decided to use only half cut cells.
The \acs{acronym} code is newly equipped with a particle loading algorithm, which allows for position dependent particle densities and velocity distributions. The velocity distributions can be sampled from arbitrary functions through the rejection method, the inverse method and from histogram data. This tool will be used to insert the simulated energy distribution from the \acs{karl} simulation. A position dependent drift velocity can be added to the particles, which will be calculated from the current and density distribution of the \acs{karl} simulations. Aside from the initial loading, new particles can be added to the simulation domain during the simulation. The injection can be achieved through a virtual layer of cells, which emits particles. This injection method can also be used in conjunction with the \acs{pml} boundary condition, which allows for a simulation of the rear wall section with a connection to the bulk of the source plasma. Additionally, there is the possibility to inject beta particles in dependence on the tritium density during the simulation. This injection method can be extended with the injection of secondary particles from ionization in dependence of the mean number of particles created through a beta particle.
Another new feature of the \acs{acronym} code is the possibility to use position dependent background fields and currents. They can be used to represent the potential difference between beam tube and rear wall, the background magnetic field of the \acs{wgts} and the ion movement. The background can be modeled from data or from a given position dependent function.
The evaluation methods of the \acs{acronym} code were extended with a Poisson solver. This solver can calculate the electrostatic potential from an arbitrary electric field in a cylindrical cavity.
All additions to the code were validated through specific targeted tests. It could be shown that the addition of the background ion current is the same as simulating the ion movement directly for a small time scale. Thus, this method can conserve simulation time, while keeping the ion motion incorporated in the simulation. In a similar test, it could be shown that the background electric field can be used to simulate external electric fields, like the contact potential between rear wall and beam tube wall.
The addition of the new cylindrical \acs{pec} boundaries was tested in two steps. In a first step, the algorithm was tested in an empty cylinder. Cavity modes were excited in that cylinder, and the simulated cavity mode frequencies were compared to theoretical frequencies. A good agreement was found between simulation and theory. However, the simulated frequencies showed a large uncertainty, caused by the limited resolution of the timestep length. A reduction of the timestep length reduced the uncertainty and the relative error, enforcing the trust in the algorithm.
In the second step, the test cylinder was filled with particles. It was proven that an expected Debye boundary layer is formed between the cylinder walls and the plasma. The extent of the layer was found to be similar to the expected Debye length, both in radial and longitudinal direction of the cylinder. However, the absolute potential was lower than expected from a one dimensional Debye sheath ($\approx k_b T$). More simulations are necessary to disentangle effects from the used \acs{pec} algorithm, the inherent phase space resolution, and possible physical influences on the layer formation like the low electron density and cylindrical shape of the cavity. The latter hypothesis is supported by simulations with increased radius, which showed an increased potential.