\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 \ref{eq:vlasov_equation}, in cunjunction with the Maxwell's equations. The interplay between the equations make analytic calculations difficult. Numerical methods like \ac{pic} simulations can bridge this gap. The idea behind the simulation is that particles are simulated in a continous space, while their density and currents are calculated on discrete mesh points \todo{ref, iwie wiki}. The currents and densities can then be used to solve Maxwell's equations. The resulting fields are then extrapolated to the particle positions, which 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 \todo{citation}. Extra modifications were added to incorporate the special conditions of the \acs{katrin} source. The first section (\ref{sec:acronym:pic}) of this chapter focuses on the description of the different modules of the \acs{acronym} code. In the code the simulation domain is subdevided into cubic cells. The \acs{katrin} geometry is mainly cylindrical. Thus special treatment needs to be done for the boundary conditions of the simulation. They will be introduced in the second section (\ref{sec:acronym:boundaries}). The ion current can be considered constant during the evolution the electron movement. This background alongside the electromagnetic background of the experiment needs to be incorporated in the simulation. The procedure will be described in section \ref{sec:acronym:background}. The beta decay of Tritium in the source produces a continiously electrons and ions. This production is reflected in the simulation through special injection methods. They will be described in section \ref{sec:acronym:injection}. The \acs{acronym} code is designed to derive electromagnetic fields. These fields need to be translated into an electrostatic potential for the comparison with measuremnt data. This procedurce will be presented in section \ref{sec:acronym:poisson}. The newly introduced methods of the code need to be 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 (figure \ref{fig:Chapter5_ACRONYM/ParticleInCellMethod/pic_scheme.pdf}) was developed to reflect the cause and effect of the particle motion in the plasma. The particle motion introduces an electric current. This current introduces electromagnetic fields. These fields change the movement of the particles. Thus the current needs to be adapted and the cycle starts again. There exist a multitude of different methods for each of the simulation steps. The implemented methods in the \acs{acronym} code are described in the works of \citet{Kilian.2015}. The methods used in the context of this thesis are described in the following because each of these methods needed to be adapted to cope with cylindrical boundary conditions of the \acs{katrin} source. \todo{zeitschritte} %The temporal step size of each cycle $\Delta t$ must be smaller than the %Most of the plasma physic is moderated by the motion of electrons. The plasma frequency, see section \ref{ssec:plasma_frequency}, acts as a natural time scale at which most of the plasma physic has taken place. \xfigure{tb}{1.0}{Chapter5_ACRONYM/ParticleInCellMethod/pic_scheme.pdf}{PIC scheme}{} \subsection{Grids for Currents and Fields} \label{ssec:pic_yee_grid} The motion of charged particles induces electric currents and electromagnetic fields. The field and current values are stored on a special grid, the Yee-grid \todo{citation, Yee}, see figure \ref{fig:Chapter5_ACRONYM/ParticleInCellMethod/GridsForCurrent/grid_for_current.pdf}. The grid consists of equal sized cubes. The electric field components are stored on the cube edges, while the magnetic field components are stored at the cube faces. This layout ensures easy numerical solution of the curl operator in Maxwell's equations. The current components are considered to be on the edges as well because they induce the temporal change in the electric field. Other information (particle density and mass current), which is not directly used in the simulation is 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.}{Chapter5_ACRONYM/ParticleInCellMethod/GridsForCurrent/grid_for_current.pdf}{Yee lattice}{} \subsection{Macro Particles} \label{ssec:pic_macro_particles} The Vlasov equation (\ref{eq:vlasov_equation}) descirbes the temporal evolution of the phase space density $f(\vec{x}, \vec{v},t)$. The phase space density is discretized in the particle in cell algorithm into small phase space elements $f_\alpha(\vec{x}, \vec{v},t)$ to \begin{equation} f(\vec{x}, \vec{v},t) = \sum_{\alpha=1}^{N_p} f_\alpha(\vec{x}, \vec{v},t) \fullstop \end{equation} Each of the phase space elements has an extent spatially ($S_x(\vec{x} - \vec{x}_\alpha)$) as well in the velocity space ($S_v(\vec{v} - \vec{v}_\alpha)$). 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 macro factor of the phase space element. Following \todo{ref lapenta 2011} 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 \end{eqnarray} This means that the macro factor stays constant during the evolution of the element, that the position of the phase space element changes exactly like standart particles and that the velocity of the phase space element changes similarly in an electric field as a standart particle. Only the mass and the charge of the particle are increased by the factor $w_\alpha$. The phase space elements are also called macro particles, because of these similarities to standart particles. Thus in the simulation the phase space elements are treated like particles, which makes the simulation approach very accessible. The equation from above show how the position and velocity of a macro particle change in an external field. This calculation did not include, how this field is calculated on the particle position or how the macro particle interacts with its surrounding. This relation is described by the so called formfactors $S_x$ and $S_v$ from equation \ref{eq:pic_phase_space_element}. The choice of the formfactor is almost free, but it has to be normalized and to be zero in the limit of large values. The specific choice on the formfactor depends on the numerical stability of the solution and the calculation effort. The formfactor of the velocity ($S_v$) is chosen in all known \acs{pic} codes to a Dirac-Delta function to ensure consitency in the calculation in the Lorentz force \citep{Kilian.2015}. The spatial formfactor ($S_x$) can also be chosen to be a Diract-Delta function. But this would also 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 extremely large noise in the simulation. Additionally the simulation would loose its isotropy because of the euclidean geometry of the cube \citep{Kilian.2015}. In this thesis the formfactor is chosen to be a triangular shaped cloud with the spatial sice $\Delta x$: \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 formfactor 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} The phase space elements of the previous section can be described as macro particles. These particles have to be moved accordingly to their electric and magnetic fields. The fields of the grid have to be extrapolated first to the particle positions. This is done through the formfactor $S(\vec{x})$: \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$ are the three different cartesian axis and $\vec{X}_{ijk}^\nu$ the cell positions of the field component $E_{\nu ,ijk}$ in the cell. In the code the sum is not calculated over all possible cell positions, but only over the cell positions in the near vecinity. This is justified because the formfactor of the triangular shaped cloud is only non zero in close proximetry of the particle. The 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 done in discrete timesteps. The numerical solution of the equation of motion is done through the Leapfrog algorithm. Here the velocity and the position are not calculated at the same time but half timesteps appart. Thus the equation of motion calculate 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 time at which the value is given. The position update is straight forward and does not need any more explanation. Whereas 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 through 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} This eqaution can be solved numercially through the Boris push \todo{cite Penn et al. 2003, Kilian p84}. 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 \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} \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 again the particle is accelerated 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 \end{equation} The Boris push is numercially stable with high precision and efficiency \citep{Kilian.2015}. The method can also be used for low relativistic particles, up to a gamma factor of $\gamma \approx 1000$ \todo{cite Vay 2008, Kilian p84}. 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. \xfigure{tb}{0.8}{Chapter5_ACRONYM/ParticleInCellMethod/ParticleMovement/boris_push.pdf}{Boris push}{} \subsection{Current Deposition} \label{ssec:pic_current_deposition} The macro particle motion induces an electric current. This current is projected on the cell edges of the Yee-grid, (see section \ref{ssec:pic_yee_grid}). The specific contributions are moderated by the formfactor of the macro particles. A naiv approach would be to calculate the mean of the contribution before and after moving the particle. This method fails, because the charge continuity equation is not fullfilled. A possible solution is the algorithm of \todo{citet, Esirkepov, Kilian, p87}. The derivation of the algorithm is extensive, so the interested reader is referred to \citet{Kilian.2015} for an accessible description or \todo{Esirkepov} directly. Only the corner stones will be presented here. The derivation starts from the continuity equation, which ensures that the continuity will be conserved in the first place. The algorithm hinges on the calculation of the spatial derivative of the current through \num{8} 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 can then be 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} So the current of the particle $\alpha$ at the cell ($i+1/2jk$) is dependent on the current of the neighboring cell ($i-1/2jk$). This recursion can be resolved directly because the formfactor 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 the most time consuming step of the \acs{pic} algorithm. Each of the macro particles contributes not only to the cell it is located by also on the surrounding cells. Thus many calls to the storage have to be performed, which are time consuming. The call time can be reduced by sorting the particles before the current deposition step. %\xfigure{h}{1.}{Chapter5_ACRONYM/ParticleInCellMethod/CurrentDeposition/esirkepov.pdf}{Current deposition}{} \subsection{Maxwell Solver} \label{ssec:pic_maxwell_solver} The current at the grid positions can now be used to calculate the evolution of the electromagnetic fields through Maxwell's equations. In the simulation there are no materials present. Thus the permititvity and the permeability are set to one (cgs). Maxwell's equation in this case read as \begin{eqnarray} \nabla \times \vec{E} = - \frac{1}{c} \frac{\partial \vec{B}}{\partial t} \comma \\ \nabla \times \vec{B} = \frac{1}{c} \frac{\partial \vec{E}}{\partial t} + \frac{4 \pi}{c} \vec{j} \comma \\ \nabla \vec{E} = 4 \pi \rho \comma \\ \nabla \vec{B} = 0 \fullstop \end{eqnarray} The temporal evolution of the electric and magnetic fields are given directly by the first two equations (Faraday's law of induction and Ampere's circuital law). The time derivative is represented numerically by their finite differences \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, where the value is known. Thus the magnetic and electric fields at the next timestep can be directly calculated from the field values of the previous timestep. The curl of the electric and the magnetic field can be numerically evaluated through various methods. They differ mostly in the number and the extend of the neighboring cells, which contribute to the curl. In the context of this thesis the Yee method is used. It allows for an easy calculation of the curl, even at conducting boundaries. This method was developed alongside the Yee grid such that the field values of the magnetic and electric field are stored at different positions. Thus the curl can be directly calculated from the neighboring field entries by replacing the derivative with the central differences, see figure \ref{fig:Chapter5_ACRONYM/ParticleInCellMethod/MaxwellSolver/maxwell_solver.pdf}. The $x$ component of the curl is for example 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. For the plasma simulation It is chosen in such a way, that it reflects the Debye shielding (see Section~\ref{ssec:debye_length}) in a plasma \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} \todo{cite clf}. For the Yee method it reads as \begin{equation} \Delta t < \sqrt{\frac{1}{3}} \frac{\Delta x} c \comma \end{equation} where $c$ is the speed of light. In easy words it describes that the electric and magnetic field can not move more than one cell in one timestep, which would otherwise contradict the finite speed of light. Ultimately the timestep length has to fulfill the following conditions \begin{itemize} \item $\Delta t < \frac{1}{2 \omega_{pe}}$: plasma oszillations 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 \item $\Delta t < \sqrt{\frac{1}{3}}\frac{\Delta x}{c}$: The \acs{cfl} condition has to be met. \end{itemize} \xfigure{tb}{0.7}{Chapter5_ACRONYM/ParticleInCellMethod/MaxwellSolver/maxwell_solver.pdf}{Maxwell solver}{} \section{Boundary Conditions} \label{sec:acronym:boundaries} The particle in cell procedure presented before is used for the central part of the simulation. It was implicitly assumed that there are sufficient enough neighboring cells. It is apparent that the simulation domain is not infinitely extended. On the one hand the cartesian structure of the Yee grid suggests a cuboid simulation domain. On the other hand the geometry of the \acs{katrin} experiment is cylindrical. Thus sufficient treatment of these boundaries has to be found. In the context of this thesis the following boundary conditions were applied: the perfect electrical conductor boundary (\acs{pec}), the periodic boundary conditions and the perfectly matched layer (\acs{pml}). They differ in the treatment of the particles and of the electromagnetic fields. Because they influence the plasma in the \acs{katrin} source extensively, they are described in the following in detail. \subsection{Perfect Electrical Conductor} The \acs{pec} boundary is used to describe the boundary, where all incoming particles are absorbed and all incoming electromagnetic waves are reflected. This is the case for almost all \acs{katrin} boundaries, because most of the beamtube is made out of conducting grounded stainless steel. 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 Yee grid, see figure \todo{fig of planar boundary}. In this case it is easy to formulate conditions of the electromagnetic fields. The parallel electric field is always zero at the rim of a perfect conductor. Therefore the electric field of all edges, which are parallel to the boundary are set to zero (in the figure $E_y(i,j,k)$ and $E_z(i,j,k)$). The electric field of all edges contained in the boundary are 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} are set to zero. In the case of an background magnetic field, they are set to the background value. The magnetic field of the faces, which touch the boundary are unaltered, because these fields are located $\frac{\Delta x}{2}$ away from the boundary. The treatment of the current at the \acs{pec} boundary is more complicated. The macro particles show an finite extension through their formfactor. 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 an theoretical image charge in the conductor. This current would cancel the parallel current of the macro particle and increase the perpendicular current. Despite the theoretical motivation the mirror charge current was not implemented for the simulations shown below to ensure consistency with the arbitrary shape \acs{pec} boundary. Additionally the contribution of the mirror charge is assumed to be small. The current is only collected at the center of the edges. Thus the formfactor of the current contribution is small for a particle, which is directly positioned at the boundary. Therefore the deposited current is small as well. The \acs{pec} boundary also absorbs all incoming particles. In the simulation they are deleted directly, when they cross the boundary. In that way they do not contribute at their last timestep to the current through their movement. 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} part of a cell. Therefore this contribution to the current is neglected in the simulation shown below. \paragraph{Arbitrary shape} Assume there is a boundary, which has an arbitrary shape. Nevertheless the shape is restricted, such that the shape features are bigger than the cell step size $\Delta x$. The simplest approach to solve the electromagnetic fields is the approximation through the stairstep algorithm \todo{citation}. The boundary is approximated by cubes of the Yee grid. This method allows for an easy solution of Maxwell's equations at the cost of accuracy and robustness towards spurious solutions \todo{cite mittra 1997}. \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.}\todo{cite Nieter.2009}. In the Dey-Mittra algorithm it is calculated how the boundary cuts the cell and the corresponding edge length and face areas are calculated. The field is set to zero on edges which are totally contained within the conductor. 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$ and $l_i$ are the face area and $l_i$ length of the edges, which are inside the geometry, see figure \ref{fig:Chapter5_ACRONYM/ParticleInCellMethod/Boundary/dey_mittra.pdf}. \xfigure{tb}{1.0}{Chapter5_ACRONYM/ParticleInCellMethod/Boundary/dey_mittra.pdf}{Dey Mittra}{} The stability of the algorithm depends on the smallest allowed face area $A_{\text{min}}$, the smallest allowed edge length $l$ and the timestep length. \todo{citet Nieter 2009} states that the algorithm is stable for a uniform grid when the following two conditions are met \begin{equation} \Delta t < \Delta t_{\text{CFL}} \cdot \sqrt{2 a} \comma \end{equation} where $a = \frac{A_{\text{min}}}{\Delta x^2}$ and \begin{equation} \Delta t < \Delta t_{\text{CFL}} \cdot \sqrt{l} \comma \end{equation} where $l = \frac{l_{\text{min}}}{\Delta x}$. The simulation of the \acs{katrin} source requires a very small timestep length ($\Delta t \approx \SI{8E-13}{s}$). Thus many timesteps are necessary to reach reasonable results. It was therefore decided to reduce the timestep a little as possible. This means that the smallest area was chosen to be $a = 0.5$ and the minimal edge length to $l = 1$. This approach is the same as demanding that there are only diagonally cut and non-cut cells. Thus the given geometry is approximated to suit the algorithm. First it will be deterimend, which edges are cut by the original geometry. These edges are then considered outside of the approximated geometry and their edge length 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. The face areas and edge length are calculated prior to the siumlation, to reduce computing time. Also in the simulation it will destiquished between cells, which are inside the geometry, outside of the geometry and which are cut in any direction. Thus the correct treatment can be selected. An example of the electric and magentic field values in a cell, which is diagonally is shown in figure \ref{fig:Chapter5_ACRONYM/ParticleInCellMethod/Boundary/cut_boundary.pdf}. \xfigure{tb}{1.0}{Chapter5_ACRONYM/ParticleInCellMethod/Boundary/cut_boundary.pdf}{Electromagentic fields in a diagonally cut cell}{} There is no conclusive result in the literature, how the current shall be treated in the Dey-Mittra algorithm. A simple solution would be the usage of mirror charges. This approach would either lead to a significant increase in calculation effort or to ambiguous results. Therefore it was decided in the context of this thesis, that this specific contribution is neglected. The \acs{pec} boundary also absorbs all incoming particles. The choice of the minimal face area and edge legth also demands a special treatment. Therefore for each cell a normal vector $\vec{n}$ of the plane, which is created by the cut is calculated and a point $\vec{P}$ on the plane is selected, see figure \ref{fig:Chapter5_ACRONYM/ParticleInCellMethod/Boundary/cut_boundary.pdf}. A paritcle at position $\vec{x}$ is considered inside when \begin{equation} \vec{n} \cdot (\vec{P} - \vec{x}) > 0 \comma \end{equation} is fulfilled. \subsection{Periodic Boundary Condition} 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 so special, that the largest possible simulation domain is 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. For the periodic boundary condition it is assumed that the simulated plasma inside the simulation domain has the same properties as the plasma outside of the domain. Thus the distribution of all particles leaving the simulation domain in one direction is the same as the distribution of all paritcles 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 to $n/2 - 1$, where $n$ is the number of cells in one direction. Thus a sufficient large enough simulation domain must be selected. \subsection{Perfectly Matched Layer} Perfectly matched layer (\acs{pml}) boundary is chosen to simulate the absorption of electromagnetic waves and particles. This boundary method is used to simulate the transition of a plasma into a vacuum. This condition is met for the \acs{katrin} plasma in the transition region from the \acs{wgts} to the \acs{dps}. The requirements for the particle movement is easily formulated: all particles, which leave through the \acs{pml} are absorbed. The formulation for the electromagnetic fields is more intricate. \todo{citet berenger} developed a method (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 interessed reader is refered to \todo{cite berenger, 2007}. 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 later on added to the field values of $E_x$, $E_y$, $B_x$ and $B_y$ respectively. The value of the fields 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$. The \acs{pml} boundary condition can also be used in conjuction with the \acs{pec} boundary condition or the periodic boundary condition in the other spatial direction. In the case of the \acs{pec} boundary cnodition 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 is omitted. Otherwise the update will be performed through the standart \acs{pml} update. \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. The current version of \acs{acronym} only considers static background fields. They can easily be added to the field values of the standart \acs{pic} algorithm. Dynamic backgrounds would interact with the dynamic fiedls of the simulation and therefore change their distribution over time. \paragraph{Electromagnetic Background} The electromagnetic background can originate from various sources, see section \todo{ref ch1:ebg}. Only static fields are considered here. Thus the field update of section~\ref{ssec:pic_maxwell_solver} is not influenced by these fields. Therefore they only need to be applied at the particle movement, see section~\ref{ssec:boris_push}. The background fiedls are simply added to the evaluated field of equation~\ref{eq:pic:field_interpolation}. The background field values have to be provided, prior to the simulation. This can either be done as a function or through discrete data in a file. 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 position of a particle only needs to be evaluated once for the dynamic array and used also in the deterimantion of the background field. The background fields, which are present at the \acs{katrin} experiment do not change significantly over small distances. Thus it was decided to forgo an interpolation to the particle position. \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 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 can not be assumed to be constant. The ion movement on the other hand can be assumed to be constant during the simulation. Thus 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 calulated 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 an 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} Particles are injected in the simulation either at the start of the simulation or during the simulation. The starting conditions are given by the inital electron spectrum. The injection during the simulation is used to descirbe the connection of the open boundaries to the rest of the plasma or the Tritium decay. Both injections have a significant influence on the simulation and are therefore discussed here in detail. \subsection{Inital Loading} \label{ssec:acronym:injection:inital_loading} The inital particle spectrum $\frac{\partial n(r, z)}{\partial E}$ and the particle currents $\vec{j}(n,r)$ of the source is calculated by the \acs{karl} code. This information needs to be translated into the number of particles $ppc$, which are inserted in the cell, the macro factor of the macro paritcles $w_\alpha$, the kinetic energy of these particles $E_\text{kin}$, and the direction of movement $\vec{v}$. \subsubsection{Particles per cell and macro factor} \label{sssec:acronym:injection:inital_loading:ppc_mf} The number of particles per cell $\text{ppc}$ and the macro factor $w_\alpha$ are linked by the density inside each cell $n$ \begin{equation} w_\alpha = \frac{n \cdot \Delta x^3}{\text{ppc}} \fullstop \end{equation} The density $n$ is given by the \acs{karl} simulation. The cell size $dx$ is calculated from the maximum absolute density, see equation~\ref{eq:acronym:cell_size}. The number of particles in each cell needs to be specified before the simulation. In general it is preferable to have a large number of particles per cell, to reduce the noise of the simulation. The particle update is the most time consuming step in the simulation. Thus the maximum number of particles in each cell is bound by the computational resources available. The particle update and the field update can each be done in parallel, because the outcome is only dependent on the prior status. This property facilitates the use of parallel computation. The \acs{acronym} code is written for parallel computation. The simulation domain is subdivided into cubes and each processor is responsible for the particle and field update in its region. Corresponding boundary conditions and communication between the processors was set up. \citet{Kilian.2015} evaluated the number of particle updates per real 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. Three distinct region can be found in the electron spectrum: a thermal region, a beta region and the secondary 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 region only make up \todo{calculate density fracton} of this denisty (in the center of the source). Assuming a simulation with \num{20} particles per cell, this would result in a macro factor of \todo{mf ausrechnen}. Thus almost every real particle can be represented in the simulation as a macro particle. If the particle energy of the particles are sampled from the entire spectrum, then there will be much more electrons thermal electrons, due to the large density difference. This would also mean that there are allmost no electrons injected from the high energy region. Thus the simulation can suffer from a large statistical unceartainty. Thus it was decided to subdevide 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. One beta particle per cell will result in a macro factor of \todo{mf ausrechnen}. This macro factor is below one, which means that there are more simulated particles then real particles. This is no problem from a computational standpoint but needs to be taken into account, when looking at the data. The density of the regions is dependent on the position inside the source. Thus two different scenarios are possible to incorporate this into the simulation, either the macro factor is position dependent or the number of particle per cell is position dependent, while the other property will be kept constant. The electron denisty of the \acs{karl} simulation varies over the whole source by the factor \num{200}\todo{korrekten}, whereas the ion density varies by the factor \num{12} \todo{factor rausfinden}. In a plasma quasineutrality can be assumed. 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. For simplicity it was therefore decided to use a position dependent number of paritcles per cell. The number of particles is an integer value, while the density has continous values. The number of particles, which are injected in a cell $\text{ppc}(i,j,k)$ is calculated from the continous value $\text{ppc}_f(\vec{x})$ \begin{equation} \text{ppc}(\vec{x}) = \frac{n(\vec{x})}{n_\text{max}} \cdot \text{ppc}_\text{max} \end{equation} and from the rounded values to the next integer values \begin{eqnarray} \text{ppc}_f &= \text{floor}(\text{ppc}(\vec{x})) \\ \text{ppc}_c &= \text{ceil}(\text{ppc}(\vec{x})) \comma \end{eqnarray} through the random number $\eta \in [0,1)$ by \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} The \acs{karl} simulation evaluates the density in longitudinal, azimutal and radial bins. The azimutal discretization is neglected in most cases due to the azimutal symmetry of the simulation. This is also done in the evaluation of the density for the \acs{acronym} simulation. The cells of the \acs{acronym} simulation can be smaller than the bin size of the \acs{karl} 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 \todo{citation}. \subsubsection{Sampling of the Kinetic energy} \label{sssec:acronym:injection:inital_loading:E_kin} The kinetic energy of the particles is sampeled through different methods, depending on the underlying distribution. The underlying distribution is either given by theoretical considerations, approximated functions from the simulation data of \acs{karl} or given directly from the histogram of the spectrum from \acs{karl}. \paragraph{Theoretical consideration} Some parts of the spectrum can be identified through an investigation of the origin of the contribution to the spectrum. Two major contributions can be identified directly from the spectrum \todo{ref auf karl data}: a thermal part and a beta part. The sampling of an energy value from these distributions will be described in the following. In the source there are many elastic collisions with the neutral gas. It can be therefore be assumed that the particles adopt the energy distribution of the neutral gas. In the case of the \acs{katrin} source it is assumed 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 the temperature of the particles. The energy of the injected particles is samled in the code through the gamma distribution \todo{citation} with the parameter $\alpha = \frac{3}{2}$ and $\beta = E_\text{th}$. The gamma distribution is build in the c++ standard library \todo{citation}. The particles of the beta decay follow the Fermi distribution. Thus it is benefitial to sample the high energy part of the spectrum through the Fermi distribution (equation \ref{eq:Neutrino-TdecayRate}). The energy of the particle is sampled through the rejection method \todo{citation}. 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 $x$ is then \begin{equation} x = \eta_2 \hspace{1cm} \text{for} \, \eta_1 \leq f(\eta_2) \fullstop \end{equation} 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 \begin{equation} \text{efficiency} = \frac{\int_{x_\text{min}}^{x_{\text{max}}}}{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 intermediate region of the \acs{karl} results \todo{ref to karl data}. Here the spectrum can be approximated by two power law functions. In general the sampling can be done through the rejection method, which was presented shortly 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. \paragraph{Histogram data} If the data of the spectrum exists in histogram format the random number $x$ can be sampled directly from this data. The bin index $i$ is found through the random number $\eta \in [0, \sum f(i)]$ for the first bin, which fullfills \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 bin mid. A more precise resolution is reached through a linear interpolation towards the neigboring 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 $O(\log N)$. Thus the efficincy of the algorithm scales with $\frac{1}{\log N}$, where $N$ is the number of bins. \subsubsection{Sampling of the Velocity} \label{sssec:acronym:injection:inital_loading:velocity} The velocity 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 the spectrum $\frac{\partial n(r, z)}{\partial E}$. The distribution of the velocity to the 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 \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 first order approximation initiates the particles with no net current. The \acs{karl} simulations show that there is a current. This current can be descrbide as a current 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 \\ v_r(\vec{x}) &= \frac{j_r(\vec{x})}{n(\vec{x})} \comma \end{eqnarray} with the density $n(\vec{x})$. The \acs{karl} simulation provides the current at discrete positions. Similar to the density, the current is determined at position $\vec{x}$ through bilinear interpolation. 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}. The calculated longitudinal velocity is incorporated in the simulation as an extra contribution to the velocity. Thus the velocity is determined through the sampled kinetic energy and subsequent isotropic distribution through equation~\ref{eq:acronym:isotropic_velocity}. Then this velocity is boosted in longitudinal direction through $v_z$ at the position of the particles. Thus the total kinetic energy of the particle will be greater than sampled originally. One the one hand this procedure overestimates the kinetic energy of the particles. On the other hand the longitudinal current will be resperented correctly. This procedure can therefore be considered as the second approximation. A more precise description needs to resolve the three velocity directions in the \acs{karl} simulation directly and import them into the \acs{acronym} simulation. \subsection{Injection During Simulation} \label{ssec:acronym:injection_during_simulation} After the inital loading of particles there can still 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 through the knowlegde of the incoming current or through the assumption of a virtual plane, at which the density is kept constant. \subsubsection{Injection through Constant Current} \label{sssec:acronym:injection_constant_current} In the injection through a constant current it is assumed that the current $j(\vec{x})$ flowing towards the simulated plasma is known, for example by the \acs{karl} simulation. This current can be translated into the number $N_j$ of physical particles, which flow into a cell \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 simulated current at the boundary correctly,but the injection is also independent on the local field. 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 a equilibrium will be found. In the simulation the current will be kept constant. Thus the equilibrium is only found if the incoming current is the same as the outgoing current. Thus this methods of injection overestimates the electric field in the plasma significantly and is therefore not favored in the context of this thesis. This assesment will 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 through a constant current shows challenges because the electric field at the injection site is not taken into account. This can be bypassed by the use of the injection by retaining a constant density. Here a virtual layer of cells is created at the injection plane, which is located inside the simulation domain. This virtual layer will be filled each timestep with particles. The density and velocity distribution is given through the \acs{karl} simulations, similar to the initial loading of section~\ref{ssec:acronym:injection:inital_loading}. The particles will then be moved by one timestep corresponding to their velocity, mass, charge and the local electirc field at the virtual layer. Only those virtual particles, which leave the virtual layer cells are injected into the simulation domain. This procedure ensures that the incoming current is closely linked to the electric field at the boundary. The electric field inside the \acs{pml} boundary is reduced through the \acs{pml} algorithm. If the virtual layer is placed inside the \acs{pml} layer it will reproduce a reduced dependence of the incoming current with the local field. Nevertheless the interior of the simulation domain is further away from the injection plane, which means that less cells are effected directly by the injection. No investigation of the injection position was found in the literature. The injection was tested in a simulation, see figure~\ref{fig:Chapter5_ACRONYM/ParticleInjection/pml_injection_comparison.pdf}. The test simulation was designed for the case of 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 heigth of the cylinder was chosen to be much greater than the \acs{pml} layer thickness (1434 cells). 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. \xfigure{tb}{1.}{Chapter5_ACRONYM/ParticleInjection/pml_injection_comparison.pdf}{Test of injection at \acs{pml} 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 ($n_\text{th} = \SI{1E5}{cm^{-3}}$ and $T = \SI{80}{K}$) and a beta part ($n_\beta = \SI{7.9E-1}{cm^{-3}}$). Both parts were used in the virtual injection layer. The electric field and density were recorded in centrum of the cylinder ($r = 0$) after a time of $T = 4 \frac{1}{\omega_{\text{pe}}}$. An equilibrium in the total energy was reached.} The simulation show that there is an influence on the electric field and density close to the \acs{pml} layer for the different injection positions. Further away (more than 25 cells) this influence is negligible. It seems that the injection position has only a minor effect. Nevertheless it was decided to use an injection position of \num{5} cells into the \acs{pml} layer for the following simulations. This tradeoff seems to cover a correct modeling of the particles and fields inside the \acs{pml} layer as well as a minor influence of the injection method on the field and density. \subsubsection{Injection through Constant Decay Rate} \label{sssec:acronym:injection_constant_decay_rate} The plasma freuqency $\omega_\text{pe}$ provides a natural timescale for the effects which are covered by the \acs{acronym} simulation. The plasma frequency at the \acs{katrin} experiment is in the range of $\SIrange{E6}{E7}{Hz}$, see section~\ref{sec:frequencies}. The activity of the source can reach values up to \SI{E11}{Bq}. Thus in one plasma timescale up to \num{E5} beta electrons are created in the whole source through decay. The number of injected beta particles $N_\beta$ per timestep is calculated through \begin{equation} N_\beta(i,j,k) = n_{T_2}(i,j,k) \cdot \Delta x^3 \cdot \Delta t \cdot \lambda_{T_2} \comma \end{equation} where $n_{T_2}$ is the neutral particle density and $\lambda_{T_2}$ is the decay constant of Tritium. This number needs to be adjusted by the macro factor to get the number of macro particles, which are injected per timestep. Each beta electron can create several other electrons through ionization. Similar to the injection of beta decay particles also the secondary particles need to be taken into account. The number of secondary electrons $a_\text{sec}$, which are created by one beta particle can be evaluated with the \acs{karl} simulation. The number of injected secondary particles $N_\text{sec}$ is then calculated as \begin{equation} N_\text{sec}(i,j,k) = 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 estimated density of the secondary particle type. The number of particles needs to be adjusted by the macro factor to get the number of macro particles, which are injected per timestep. This procedure neglects the fact, that the density of the secondary electrons dose not necessarily coincide with the position, where they are created. Particle flow is neglected in this approximation. Nevertheless it provides an accessible approach for the simulation. In the future it might be possible to track the creation position of the secondary particles in \acs{karl}. This data can then be used to provide a more accurate injection in the \acs{acronym} simulation. \section{Electrostatic Potential from Poisson Equation} \label{sec:acronym:poisson} One result of the \acs{acronym} simulations in the electric field on the Yee-grid at different timesteps. This field can in reneral be represented by the superposition of a curl-free and a divergence-free field following the Helmholtz-theorem \todo{citation}. 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}$ 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 eletric field by using $\nabla (\nabla \times \vec{A}) = 0$ through \begin{eqnarray} \vec{E} &= -\nabla \phi + \nabla \times \vec{A} \comma \\ \nabla \vec{E} &= -\nabla^2 \phi \fullstop \label{eq:acronym:poisson} \end{eqnarray} This of course can be identified with the Poisson equation through the use of Gauss's law. The solution of the Poisson equation in cylinder coordinates with an azimutal symmetry is shown in section~\ref{ssec:karl:poisson_solver}. The input of this calculation is the charge density at different grid positions and the corresponding boundary condition values. Here the algorithm is extended by the calculation of the density through Gauss's law from the eletric field \begin{equation} \begin{split} 4 \pi \rho & = \nabla E \\ & = \frac{\partial E_r}{\partial r} + \frac{E_r}{r} + \frac{\partial E_z}{\partial z} \fullstop \end{split} \end{equation} So two cases have to be taken into account: the limit of zero radius and all other cases. If the radius is non zero then then density will be calculated at the discrete position $(i,j)$ \begin{align} 4 \pi \rho_{i,j} = \frac{E_{r;i,j} - E_{r;i-1,j}}{\Delta r} + \frac{E_{r;i,j}}{i \cdot \Delta r } + \frac{E_{z;i,j} - E_{z;i,j-1}}{\Delta z} \comma \end{align} where $\Delta r$ and $\Delta z$ are the cell sizes in radial and longitudinal direction. Be aware that the central difference was used here. The electric field and density are known at different positions through the Yee-grid. The electric field vanishes in the limit of zero radius. Thus L'Hôpital's rule can be used \begin{equation} \lim_{r\to 0} \frac{E_r}{r} = \frac{\partial E_r}{\partial r} \fullstop \end{equation} Additionally the electric field at position $i = -1$ is equal to the negative value at $i=0$ because of the radial symmetry. The density is then 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} The calculation of the density then only needs correct boundary conditions. For the \acs{acronym} simulations it is assumed that the potential is only generated by the particles. Any exetrnal field, like the rear wall field, is not exported in the eletric field. Thus the density at the Dirichlet boundary is set to zero. This boundary is used at the \acs{pec} boundary. At the \acs{pml} boundary the longitudinal electric field is set to zero. Thus the calculation of the density is carried out with $E_{z;i,j} = 0$, where $j$ is the index of the \acs{pml} boundary. The \acs{acronym} simulation can also be performed with the periodic boundary condition. Thus the density is calculated with $E_{z,i,-1} = E_{z,i,J}$, where $J$ is the maximum index of $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} 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 before they are used in the simulation of the \acs{katrin} plasma. \subsection{Ion Current Approximation} \label{ssec:acronym:validation:background_current} The addition of the background current is tested through a comparison between a simulation with ion macro particles and a simulation with background current. Both simulations should show the same behavior in the development of the total current and electric field. Small variations are expected due to the initation of the ions with a Maxwellian velocity distribution ($T_\text{i} = \SI{30}{K}$) with an additional drift velocity in $z$-direction. The background current is calculated from the given drift velocity $v_\text{d} = \SI{1E6}{\centi\meter\per\second}$ and ion density $n_\text{i}$ \begin{equation} j_{\text{c}} = e \cdot n_\text{i} \cdot v_\text{d} \fullstop \end{equation} 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 ion density and particle per cell were chosen to equal to the settings of the electrons. The simulation domain was chosen to be a cube with periodic boundary conditions in all three space dimensions. No magnetic background field was used. The simulation was carried out for two times the plasma timescale ($t = 2/\omega_{pe}$). The resulting charge current, mass current and electric field in $z$-direction can be found in figure~\ref{fig:Chapter5_ACRONYM/Validation/IonCurrentApproximation/comparison_cube.pdf}. \xfigure{tb}{1.}{Chapter5_ACRONYM/Validation/IonCurrentApproximation/comparison_cube.pdf}{Validation of background current}{Comparison of two simulation with ion macro particles (particles) and with background current (background). The charge current and mass current are measured in $z$-direction. Both simulations show similar values for the charge current and electric field. The mass current is expected to be different.} The mass current shows significantly different values between the two simulations, which is expected. The mass current is dominated by the mass of the ions. Thus the mass current is much larger in a simulation with ions and electrons than in a simulation with electrons only. The mass current shows the expected value \begin{equation} j_m = m_\text{i} \cdot n_\text{i} \cdot v_\text{d} \approx \SI{1.6E-13}{\gram\per\centi\metre\squared\per\second} \comma \end{equation} and the expected direction. The mass current is not expected to change significantly over time, because of the large mass of the ions. Therefore the mass current has alomst the same values as on the first timestep. It can be therefore be concluded that ion current was at all timesteps directed at the positive $z$-direction. Both charge current and electric field show similar values for both simulations. Only slight differences are observable, which is expected. Thus the electrons behave similar in both simulations, even though the origin of the ion current is different. The interplay between the current, the electric field and the magnetic field, especially in three dimension is non trivial. Nevertheless two 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 induces an electric field, which is opposing the movement of the ions. This electric field accelerates the inital static electrons to the positive $z$-direction. Thus the inital positive charge current is reduced, in this case even to negative values. This simplicic explanation can only provide a rough estimation of the processes in the plasma and is no full analyitc calculation. Nevertheless the general idea, that an ion current will be opposed by the electron movement, becomes clearer. In total it can be concluded that the use of an 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 much by the electric field. \cleardoublepage \subsection{Background Electric Field} \label{ssec:acronym:validation:background_field} \todo{Plot of current and electric field} \newpage \subsection{Cavity Mode Excitation} \label{ssec:acronym:validation:cavity_mode} \xfigure{h}{1.}{Chapter5_ACRONYM/Validation/CavityMode/cavity_mode_excitation.pdf}{Cavity mode excitation}{} \newpage \xfigure{h}{1.}{Chapter5_ACRONYM/Validation/CavityMode/cavity_mode_Ez.pdf}{TM mode pattern}{} \newpage \xfigure{h}{1.}{Chapter5_ACRONYM/Validation/CavityMode/cavity_mode_fit.pdf}{Cavity mode fit}{} \newpage \xfigure{h}{1.}{Chapter5_ACRONYM/Validation/CavityMode/cavity_mode_f_vs_product.pdf}{Cavity mode excitation}{} \newpage \subsection{Debye-Sheath Development} \xfigure{h}{1.}{Chapter5_ACRONYM/Validation/DebyeSheath/E_r_2d_(t_160000)_(z_115).pdf}{Radial debye sheath}{} \newpage \xfigure{h}{1.}{Chapter5_ACRONYM/Validation/DebyeSheath/radial_comparison.pdf}{Radial comparison}{} \newpage \xfigure{h}{1.}{Chapter5_ACRONYM/Validation/DebyeSheath/longitudinal_comparison.pdf}{Longitudinal comparison}{} \newpage \section{Conclusion}