diff --git a/docs/paper/the-karl-code/paper.bib b/docs/paper/the-karl-code/paper.bib index 120b69c..080fe3d 100755 --- a/docs/paper/the-karl-code/paper.bib +++ b/docs/paper/the-karl-code/paper.bib @@ -11,7 +11,7 @@ @article{Fermi:1934aa, author = {E. Fermi}, - title = {Versuch einer Theorie der {$\beta$-Strahlen}.}, + title = {{Versuch einer Theorie der {$\beta$-Strahlen}.}}, journal = {Zeitschrift f{\"u}r Physik}, volume = {88}, number = {3--4}, @@ -117,7 +117,7 @@ @phdthesis{Kilian.2015, author = {Kilian, Patrick}, year = {2015}, - title = {Teilchenbeschleunigung an kollisionsfreien Schockfronten}, + title = {{Teilchenbeschleunigung an kollisionsfreien Schockfronten}}, keywords = {Computersimulation;kinetische Plasmaphysik;Schockfront;Sonnenwind;Sto{\ss}freies Plasma;Sto{\ss}welle;Teilchenbeschleunigung}, address = {W{\"u}rzburg}, school = {{Universit{\"a}t W{\"u}rzburg}} @@ -147,7 +147,7 @@ } @article{peckham.1992, - title={Applications of Maxwell-Boltzmann distribution diagrams}, + title={{Applications of Maxwell-Boltzmann distribution diagrams}}, author={Peckham, Gavin D and McNaught, Ian J}, journal={Journal of chemical education}, volume={69}, @@ -162,14 +162,13 @@ author = {B. Grosswendt and E. Waibel}, Date-Added = {2019-02-11 15:07:06 +0100}, Date-Modified = {2019-11-25 13:57:09 +0100}, - Doi = {https://doi.org/10.1016/0029-554X(78)90198-2}, + Doi = {10.1016/0029-554X(78)90198-2}, Issn = {0029-554X}, Journal = {Nuclear Instruments and Methods}, Keywords = {model}, Number = {1}, Pages = {145 - 156}, Title = {Transport of low energy electrons in nitrogen and air}, - Url = {http://www.sciencedirect.com/science/article/pii/0029554X78901982}, Volume = {155}, Year = {1978}, Bdsk-File-1 = {YnBsaXN0MDDSAQIDBFxyZWxhdGl2ZVBhdGhZYWxpYXNEYXRhXxBdLi4vLi4vLi4vLi4vLi4vLi4vUGFwZXJzL0dyb3Nzd2VuZHQvVHJhbnNwb3J0IG9mIGxvdyBlbmVyZ3kgZWxlY3Ryb25zIGluIG5pdHJvZ2VuIGFuZCBhaXIucGRmTxECLAAAAAACLAACAAAMTWFjaW50b3NoIEhEAAAAAAAAAAAAAAAAAAAAAAAAAEJEAAH/////H1RyYW5zcG9ydCBvZiBsb3cgZSNGRkZGRkZGRi5wZGYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP////8AAAAAAAAAAAAAAAAABgADAAAKIGN1AAAAAAAAAAAAAAAAAApHcm9zc3dlbmR0AAIAbi86VXNlcnM6Q2hyaXN0aWFuUmVpbGluZzpEb2N1bWVudHM6UGFwZXJzOkdyb3Nzd2VuZHQ6VHJhbnNwb3J0IG9mIGxvdyBlbmVyZ3kgZWxlY3Ryb25zIGluIG5pdHJvZ2VuIGFuZCBhaXIucGRmAA4AdAA5AFQAcgBhAG4AcwBwAG8AcgB0ACAAbwBmACAAbABvAHcAIABlAG4AZQByAGcAeQAgAGUAbABlAGMAdAByAG8AbgBzACAAaQBuACAAbgBpAHQAcgBvAGcAZQBuACAAYQBuAGQAIABhAGkAcgAuAHAAZABmAA8AGgAMAE0AYQBjAGkAbgB0AG8AcwBoACAASABEABIAbFVzZXJzL0NocmlzdGlhblJlaWxpbmcvRG9jdW1lbnRzL1BhcGVycy9Hcm9zc3dlbmR0L1RyYW5zcG9ydCBvZiBsb3cgZW5lcmd5IGVsZWN0cm9ucyBpbiBuaXRyb2dlbiBhbmQgYWlyLnBkZgATAAEvAAAVAAIAF///AAAACAANABoAJACEAAAAAAAAAgEAAAAAAAAABQAAAAAAAAAAAAAAAAAAArQ=}, @@ -196,7 +195,7 @@ } @software{jansson, - author = {Petri Lehtinen, et. al}, + author = {{Petri Lehtinen, et. al}}, title = {{Jansson}}, url = {https://github.com/akheron/jansson.git}, version = {2.13}, @@ -210,4 +209,11 @@ address = {Ann Arbor}, publisher = {{Addison-Wesley Professional}}, isbn = {978-0321623218} +} + +@book{hussein2010radiation, + title={Radiation mechanics: Principles and practice}, + author={Hussein, Esam MA}, + year={2010}, + publisher={Elsevier} } \ No newline at end of file diff --git a/docs/paper/the-karl-code/paper.tex b/docs/paper/the-karl-code/paper.tex index f667ce9..8734cd0 100755 --- a/docs/paper/the-karl-code/paper.tex +++ b/docs/paper/the-karl-code/paper.tex @@ -97,14 +97,12 @@ \cortext[author] {Corresponding author.\\\textit{E-mail address:} felix@fspanier.de} \address[a]{Institut f\"ur Astroteilchenphysik, KIT, Hermann-von-Helmholtz-Platz 1, 76344 Eggenstein-Leopoldshafen, Germany} - \address[b]{Institut f\"ur Theoretische Astrophysik, Universit\"at Heidelberg, Albert-Ueberle-Str. 2 und Philosophenweg 12, + \address[b]{Institut f\"ur Theoretische Astrophysik, Universit\"at Heidelberg, Albert-Ueberle-Str. 2, 69120 Heidelberg, Germany} \begin{abstract} - %At the KATRIN experiment, the electron antineutrino mass is inferred from the shape of the $\upbeta$-decay spectrum of tritium. Important systematic effects in the Windowless Gaseous Tritium Source (WGTS) of the experiment include the energy loss by electron scattering, and the extended starting potential. In the WGTS, primary high-energy electrons from $\upbeta$-decay produce an extended secondary spectrum of electrons through various atomic and molecular processes including ionization, recombination, cluster formation and scattering. In addition to providing data essential to the simulation of energy loss processes, the electron spectrum also provides information important in the simulation of plasma processes. These simulations will then provide an insight on the starting potential.\\ - - A new parallelized simulation code is presented, which uses a semi classical Monte Carlo method to determine particle spectra in the KATRIN source by tracking single particles from interaction to interaction. The moved distance is determined from the mean free path and subsequently from cross sections and particle densities. Particle densities can be provided by the user, or are calculated during simulation from the movement of the simulated particles. This enables also the inclusion of recombination effects in the calculation. The implemented interaction types include elastic scattering, ionization, clustering and excitation (electric, vibrational, rotational) and recombination. Initial particles are created using the neutral gas density and known $\upbeta$-decay spectrum. The code is optimized for the conditions in the KATRIN source, being able to cope with a large density gradient, neutral gas flow and many different particle species in a Tritium environment. + A new parallelized simulation code is presented, which uses a semi-classical Monte Carlo method to determine particle distribution in the KATRIN source by tracking single particles from interaction to interaction. The moved distance is determined through usage of the mean free path and subsequently from cross sections and particle densities. Particle densities can be provided by the user, or are calculated during simulation from the movement of the simulated particles. This enables also the inclusion of recombination effects in the calculation. The implemented interaction types include elastic scattering, ionization, clustering and excitation (electric, vibrational, rotational) and recombination. Initial particles are created using the neutral gas density and known $\upbeta$-decay spectrum. The code is optimized for the conditions in the KATRIN source, being able to cope with a large density gradient, neutral gas flow and many different particle species in a tritium environment. The code is parallelized using MPI and writes output using HDF5. Input to the simulation is read from a JSON description that provides general information on the simulation (resolution of the simulation domain) and the various optional features of the code, namely user defined species with their own terminator, interaction types, movers and initialization. \end{abstract} @@ -116,7 +114,7 @@ \begin{keyword} %% keywords here, in the form: keyword \sep keyword - Monte Carlo \sep Tritium decay \sep Ionization \sep Scattering + Monte Carlo \sep tritium decay \sep Ionization \sep Scattering \end{keyword} \end{frontmatter} @@ -143,7 +141,7 @@ {\em Solution method:} Semi-classical Monte Carlo \\ {\em Restrictions:} The geometry of the experiment is currently limited to the KATRIN experiment, but this may easily be changed.\\ {\em Unusual features:} The configuration is stored in JSON files. \\ - {\em Running time:} minutes to hours; Depending on number of simulated decays \\ + {\em Running time:} minutes to hours; depending on number of simulated decays \\ \end{small} @@ -161,19 +159,19 @@ Two different methods of descriptions seem obvious: a description through the te In the KARL code, single particles are tracked through the source from one interaction to another. The moved distance between interactions is determined from the mean free path. The performed interactions is rolled from a list of available interactions. During movement it is recorded how long a particle stays within a predefined segment of the source. The density of the particle specie in this segment is then proportional to the cumulated time in that segment. Thus, the density can be determined during simulation. It can therefore also be used to evaluated the likeliness of recombination. -The KARL code is customized to the special conditions in the KATRIN source. Hence, special care is taken to ensure correct movement of particles through the large density gradient. Additionally, all relevant interactions in a tritium gas atmosphere are included for both electrons and ions. +The KARL code is customized to the special conditions in the KATRIN source. Hence, special care is taken to ensure correct movement of particles through the large density gradient. Additionally, all relevant interactions in a tritium gas atmosphere are included for both electrons and ions. However, the KARL code can also be easily adapted to other environments, given the background particle density and particle interactions. \section{Description of the method} \label{sec:method} -In the simulation, decays are successively processed. Meaning that each decay particle is followed until its destruction, with an optional creation of new secondary particles. All primary and secondary particles are processed first, before new decay particles are added. The particle tracking is divided into two alternating steps. First, the particle is moved according to the electromagnetic fields in the source and the mean free path of the particle. Secondly, an interaction is performed. A detailed description of the simulation flow can be found in section~\ref{ssec:general_diagram}. The simulation ends until a predefined number of decays has been processed. During the simulation it is recorded how long a specific particle resides in predefined sections of the source and how often a particle crosses from one section to another. Both quantities can be used to calculate the particle density and particle currents in the source, see section~\ref{ssec:denstiy_fields} and \ref{ssec:current_collection}, which make up the result of the simulation. +In the simulation decays are successively processed. Meaning that each decay particle is followed until its destruction, with an optional creation of new secondary particles. All primary and secondary particles are processed first, before new decay particles are added. The particle tracking is divided into two alternating steps. First, the particle is moved according to the electromagnetic fields in the source and the mean free path of the particle. Secondly, an interaction is performed. A detailed description of the simulation flow can be found in section~\ref{ssec:general_diagram}. The simulation ends until a predefined number of decays has been processed. During the simulation it is recorded how long a specific particle resides in predefined sections of the source and how often a particle crosses from one section to another. Both quantities can be used to calculate the particle density and particle currents in the source, see section~\ref{ssec:denstiy_fields} and \ref{ssec:current_collection}, which make up the result of the simulation. \subsection{General diagram} \label{ssec:general_diagram} After initialization (see section~\ref{ssec:initialization}), the simulation starts its iterative cycle, which contains three subcycles, see figure~\ref{fig:simulation_flow}. The first addresses how many primary particles/events are processed, which is predefined by the user. It adds primary particles to the particle queue, if it is empty. In the second subcycle a particle is selected at random from the particle queue. This particle is processed until its termination and a new particle is selected from the queue. Within the third subcycle, the actual particle treatment is performed, which includes alternating between the movement step and interaction step. -For each movement step, the mean free path (MFP) $\lambda_\text{mfp}$ of the corresponding particle is calculated through +For each movement step, the mean free path (MFP) $\lambda_\text{mfp}$ of the corresponding particle is calculated through \citep{hussein2010radiation} \begin{equation} \lambda_\text{mfp} = \frac{1}{\sum_i \sigma_i(E) n_i} \commaeq \end{equation} @@ -183,7 +181,7 @@ where $E$ is the kinetic energy of the particle in the lab frame, $\sigma_i$ is d = \lambda_\text{mfp} \cdot \log \frac{1}{\eta} \commaeq \label{eq:distance_from_mfp} \end{equation} -where $\eta \in (0, 1]$ is a random number. The particle is then moved by this distance $d$ in dependence on the electromagnetic fields inside the source, see section~\ref{ssec:movement}. During this step the density fields of the corresponding specie are updated. +where $\eta \in (0, 1]$ is an uniform random number. The particle is then moved by this distance $d$ in dependence on the electromagnetic fields inside the source, see section~\ref{ssec:movement}. During this step the density fields of the corresponding specie are updated. After the movement step it is evaluated if the particle needs to be terminated, which is mainly a check if the particle has left the simulation domain, or has hit a wall, see~\ref{ssec:termination}. If the particle is still alive, a random interaction is selected from the list of available interactions, weighted by its probability to occur. The probability scales with the cross section of that interaction and the interaction partner particle density. The corresponding interaction is performed and the interaction products, which are not the current particle are added to the particle queue. If the particle does no longer exist after the interaction (through recombination or clustering) it is terminated, otherwise the next movement step is performed. @@ -205,7 +203,7 @@ In the simulation, the source is segmented into evenly spaced segments in longit n_\alpha = \frac{\sum_i t_i}{t_\text{sim} V} - \frac{N_\gamma}{V} \commaeq \label{eq:target_field_density} \end{equation} -where $t_\text{sim}$ is called the simulated time \citep{Kellerer_2022}. It describes the simulated physical time that is past after simulating a fixed number of primary events $N_\text{prim.}$. In the case of radioactive beta decay at KATRIN, it can be directly determined by the activity $a$ through +where $t_\text{sim}$ is called the simulated time \citep{Kellerer_2022}. It describes the simulated physical time that has past after simulating a fixed number of primary events $N_\text{prim.}$. In the case of radioactive beta decay at KATRIN, it can be directly determined by the activity $a$ through \begin{equation} t_\text{sim} = \frac{N_\text{prim.}}{a}\, . \label{eq:simulated_time} \end{equation} @@ -221,31 +219,31 @@ The activity of the source is not dependent on the interaction of the charged pa \subsection{Current collection} \label{ssec:current_collection} -The second main objective of the code is to determine the particle currents in the source. This task is performed through so-called virtual barriers: predefined planes within the source, where each particle is registered, when it crosses from one side to another. The total current through the segment faces is then given by +The second main objective of the code is to determine the particle currents in the source. This task is performed through so-called virtual barriers: predefined planes within the source, where each particle is registered, when it crosses from one side to another. The total current through the segment faces is then given by \citep{Kellerer_2022} \begin{equation} j = \frac{N^+ - N^-}{A \, t_\text{sim}} \commaeq \end{equation} -(\citep{Kellerer_2022}) where $N^+$ and $N^-$ is the number of particles crossing the faces in positive and negative direction, $A$ is the area of the face and $t_\text{sim}$ the simulated time, see~Eq.~\ref{eq:simulated_time}. For convenience, the location of the virtual barriers are chosen to coincide with the segment boundaries, see figure~\ref{fig:segmentation}, of the density field calculation, see section~\ref{ssec:denstiy_fields}. +where $N^+$ and $N^-$ is the number of particles crossing the faces in positive and negative direction, $A$ is the area of the face and $t_\text{sim}$ the simulated time, see~Eq.~\ref{eq:simulated_time}. For convenience, the location of the virtual barriers are chosen to coincide with the segment boundaries, see figure~\ref{fig:segmentation}, of the density field calculation, see section~\ref{ssec:denstiy_fields}. \section{Description of the implementation} \label{sec:implementation} -For the simulation, we decided to use c++ as a programming language for several reasons. First, it can be used for object oriented programming. This makes the code easier to read, because the classes were closely modelled after their physical representation. Secondly, the accuracy of the simulation relies on high statistics. Thus, many particle decays need to be simulated, which requires a fast calculation. For the same reason, we decided to employ parallel calculation, see section~\ref{ssec:parallelization}. +For the simulation, we decided to use C++ as a programming language for several reasons. First, it can be used for object oriented programming. This makes the code easier to read, because the classes were closely modelled after their physical representation. Secondly, the accuracy of the simulation relies on high statistics. Thus, many particle decays need to be simulated, which requires a fast calculation. For the same reason, we decided to employ parallel calculation, see section~\ref{ssec:parallelization}. There are three basic building blocks of the simulation. First, the simulation itself is treated as a class, which is responsible for initialization of the simulation environment, see section~\ref{ssec:initialization} and guiding through the flow of the simulation, see figure~\ref{fig:simulation_flow}. Second, the particle class, which represents the simulated physical particles through their physical position, velocity and type of specie. Third, the specie class, which encapsulates the general behaviour of each particle type (like electrons) in the simulation. -The main feature of the specie class is to provide access to the density, velocity distribution and drift velocity of a specific type of particle. All three quantities are used for the calculation of the MFP and the choice of the interaction partner. However, we decided to distinguish between two types of species, those particles who are tracked throughout the simulation (electrons and ions) and those who act as background (tritium gas). This way, it is more clear which specie fulfils which function, especially in the initialization process. Additionally, the particle class only accepts the tracked specie class as input, reducing programming errors in the development of new injectors or interactions. +The main feature of the species class is to provide access to the density, velocity distribution and drift velocity of a specific type of particle. All three quantities are used for the calculation of the MFP and the choice of the interaction partner. However, we decided to distinguish between two types of species, those particles who are tracked throughout the simulation (electrons and ions) and those who act as background (tritium gas). This way, it is more clear which specie fulfils which function, especially in the initialization process. Additionally, the particle class only accepts the tracked specie class as input, reducing programming errors in the development of new injectors or interactions. The tracked specie class is composed of different classes, providing access to the behaviour of each particle type. Hence, each tracked specie can be tailored to the requirements of the user, either for testing, but also for the inclusion of further particles types. Along these lines, the code can be adapted to other experimental environments, provided the knowledge of the interactions and their cross sections. Each of the class members fulfils a special task, which will be described in detail in the following sections. \subsection{Movement} \label{ssec:movement} -The movement of particles is outsourced to the mover class. It moves the particle dependent on the E/B fields at the position of the particle, given the integrated distance a particle will move, see section~\ref{ssec:general_diagram}. The movement itself is subdivided into in smaller steps. This way, it can be evaluated if the particle has left the simulation domain between the steps, which stops the movement. Apart from the simulation boundary, the movement is stopped if the particle leaves a segment or energy bin of the density fields, see section~\ref{ssec:denstiy_fields}. No interaction will be performed afterwards, but a new distance will be rolled from the MFP at the new position of the particle, see equation~\ref{eq:distance_from_mfp}. This procedure does not increase the mean distance a particle travels, if the traversed density stays the same. However, large gradients will be taken into account in the calculation. Hence, the distance a particle moves is not over- or underrated when moving into higher or lower density regions respectively. However, the density fields need a higher resolution than the density difference, which increases the simulation time. Thus, the user needs to evaluate the trade off between simulation time and accuracy. +The movement of particles is outsourced to the mover class. It moves the particle dependent on the E/B fields at the position of the particle, given the integrated distance a particle will move, see section~\ref{ssec:general_diagram}. The movement itself is subdivided into in smaller steps. This way, it can be evaluated if the particle has left the simulation domain between the steps, which stops the movement. Apart from the simulation boundary, the movement is stopped if the particle leaves a segment or energy bin of the density fields, see section~\ref{ssec:denstiy_fields}. No interaction will be performed afterwards, but a new distance will be rolled from the MFP at the new position of the particle, see equation~\ref{eq:distance_from_mfp}. This procedure does not increase the mean distance a particle travels, if the traversed density stays the same. However, large gradients will be taken into account in the calculation. Hence, the distance a particle moves is not over- or underestimated when moving into higher or lower density regions respectively. However, the density fields need a higher resolution than the density difference, which increases the simulation time. Thus, the user needs to evaluate the trade off between simulation time and accuracy. Stopping the movement if a particle has left a density field segment has an additional benefit: it can be easily evaluated how long a particle has stayed in the segment. Each movement step the particle is alive, a counter variable is increased by the time the movement step took. If the movement is stopped this counter variable can be added to the corresponding density field segment. -Two different kinds of movers are implemented (Boris, Drift), which differ in their calculation of the new position and velocity. In general, the Boris mover provides a high accuracy, because it resolves the gyro motion of the particles, but it therefore needs more calculation time. Vice versa, the drift mover provides a fast calculation time, because it does not resolve the gyro motion, but it therefore less accurate. Both movers will be presented shortly in the following. +Two different kinds of movers are implemented (Boris, drift), which differ in their calculation of the new position and velocity. In general, the Boris mover provides a high accuracy, because it resolves the gyro motion of the particles, but it therefore needs more calculation time. Vice versa, the drift mover provides a fast calculation time, because it does not resolve the gyro motion, but it therefore less accurate. Both movers will be presented shortly in the following. \paragraph{Boris mover} @@ -261,13 +259,13 @@ The Boris push algorithm was chosen, because it is numerically stable with high \paragraph{Drift mover} -The drift mover is based on the description of the movement of the particle through its movement around its gyro centrum and the drift movement of the gyro centrum, see \citep{Chen.1984}. In the current version of the code, the drift mover should only be used for a constant magnetic field. No magnetic field gradients are considered, because the magnetic field at KATRIN is constant over most parts of the source \citep{Kellerer2022_1000143868}. +The drift mover is based on the description of the movement of the particle through its movement around its gyrocenter and the drift movement of the gyrocenter, see \citep{Chen.1984}. In the current version of the code, the drift mover should only be used for a constant magnetic field. No magnetic field gradients are considered, because the magnetic field at KATRIN is constant over most parts of the source \citep{Kellerer2022_1000143868}. In the drift mover, the movement is subdivided into smaller steps, given by the smaller value of the maximal step length $d_\text{max}$ (provided by the user) and the leftover distance the particle has still to move. The movement is ended, when the leftover distance is zero. Each movement step follows the same procedure. It can be subdivided into the change of the particle position and the change of the velocity, both described in the following. -The position change is described by the movement around the gyro centrum $\Delta \vec{x}_\text{c}$, the movement of the gyro centrum parallel to the magnetic field $\Delta \vec{x}_\parallel$ and the drift movement of the gyro centrum $\Delta \vec{x}_\text{D}$. +The position change is described by the movement around the gyrocenter $\Delta \vec{x}_\text{c}$, the movement of the gyrocenter parallel to the magnetic field $\Delta \vec{x}_\parallel$ and the drift movement of the gyrocenter $\Delta \vec{x}_\text{D}$. -The drift movement of the gyro centrum is calculated from the $E \times B$ drift velocity +The drift movement of the gyrocenter is calculated from the $E \times B$ drift velocity \begin{equation} \vec{v}_\text{D} = \frac{\vec{E}\times \vec{B}}{\abs{\vec{B}}} \end{equation} @@ -280,16 +278,16 @@ where $\Delta x$ is the step length of the movement step and $\vec{v}_\parallel$ \Delta \vec{x}_\text{D} = \Delta t \cdot \vec{v}_\text{D} \fullstop \end{equation} -The movement of the gyro centrum parallel to the magnetic field is calculated from +The movement of the gyrocenter parallel to the magnetic field is calculated from \begin{equation} \Delta \vec{x}_\parallel = \Delta t \cdot \vec{v}_\parallel \fullstop \end{equation} -The position change around the gyro centrum is calculated in three steps. First, the gyro radius is determined +The position change around the gyrocenter is calculated in three steps. First, the gyro radius is determined \begin{equation} r_\text{g} = \frac{m \abs{\vec{v}_\perp}}{q \abs{\vec{B}}} \commaeq \end{equation} -from the perpendicular velocity, the particle mass $m$ and charge $q$, which in turn is then used to determine the vector from the particle to the gyro centrum $\vec{x}_\text{pc}$ +from the perpendicular velocity, the particle mass $m$ and charge $q$, which in turn is then used to determine the vector from the particle to the gyrocenter $\vec{x}_\text{pc}$ \begin{equation} \vec{x}_\text{pc} = - r_\text{g} \frac{\vec{v}_\parallel \times \vec{v}_\perp}{\abs{\vec{v}_\parallel \times \vec{v}_\perp}} \fullstop \end{equation} @@ -297,18 +295,18 @@ Second, the gyro frequency is calculated through \begin{equation} \omega_\text{g} = \frac{q \cdot \abs{\vec{B}}}{m} \fullstop \end{equation} -The gyro frequency is then used to calculate the relative angle change towards the gyro centrum +The gyro frequency is then used to calculate the relative pitch angle change towards the gyrocenter \begin{equation} \Delta \theta = \Delta t \cdot \omega_\text{g} \fullstop \end{equation} -Third, the movement of the gyro centrum is calculated by the rotation of $\vec{x}_\text{pc}$ around $\vec{v}_\parallel$ with the angle of rotation $\Delta \theta$ through Rodriges' rotation formula. In total, the position changes calculates to +Third, the movement of the gyrocenter is calculated by the rotation of $\vec{x}_\text{pc}$ around $\vec{v}_\parallel$ with the angle of rotation $\Delta \theta$ through Rodriges' rotation formula. In total, the position changes calculates to \begin{equation} \Delta \vec{x} = \Delta \vec{x}_\text{c} + \Delta \vec{x}_\parallel + \Delta \vec{x}_\text{D} \fullstop \end{equation} -The velocity after movement is determined by the acceleration of the particle through the electric field $\Delta \vec{v}_\text{E}$, through the rotation of the perpendicular velocity around the gyro centre $\vec{v}_\perp^\text{rot}$ and the initial parallel velocity +The velocity after movement is determined by the acceleration of the particle through the electric field $\Delta \vec{v}_\text{E}$, through the rotation of the perpendicular velocity around the gyro centre $\vec{v}_{\perp,\text{rot}}$ and the initial parallel velocity \begin{equation} - \Delta \vec{v} = \vec{v}_\parallel + \Delta \vec{v}_\text{E} + \vec{v}_\perp^\text{rot} \fullstop + \Delta \vec{v} = \vec{v}_\parallel + \Delta \vec{v}_\text{E} + \vec{v}_{\perp,\text{rot}} \fullstop \end{equation} The acceleration through the electric fields calculates to @@ -329,33 +327,37 @@ In addition to the terminator class, the user can choose to add a deletion logge \subsection{Interactions} \label{ssec:interactions} -Interactions of particles are processed in the interaction class. Additionally, it is used to provide access to the cross section of the interaction and the macroscopic cross section, which can be used in the calculation of the MFP and in the selection of the interaction, see section~\ref{ssec:general_diagram}. The interaction class itself is an interface class. The details of the interaction are implemented in the derived classes. This way it is easy to add more types of interactions in the future. All interactions are initiated using a given cross section and target specie. For the cross section, we decided to use a one dimensional functional. This way the user can either specify an implemented cross section to be used, or can also provide an own function in the configuration file, see section~\ref{ssec:initialization}. The target specie can either be a tracked or background specie. This allows for a high flexibility of the interaction class. +Interactions of particles are processed in the interaction class. Additionally, it is used to provide access to the cross section of the interaction and the macroscopic cross section, which can be used in the calculation of the MFP and in the selection of the interaction, see section~\ref{ssec:general_diagram}. The interaction class itself is an interface class. The details of the interaction are implemented in the derived classes. This way it is easy to add more types of interactions in the future. All interactions are initiated using a given cross section and target species. For the cross section, we decided to use a one dimensional functional. This way the user can either specify an implemented cross section to be used, or can also provide an own function in the configuration file, see section~\ref{ssec:initialization}. The target species can either be a tracked or background specie. This allows for a high flexibility of the interaction class. Currently there are seven types of interactions implemented: elastic scattering, clustering, recombination, free movement, charge exchange, excitation, ionization. In general, all types can the added to all species. However, the user has to decide if the specific use is sensible. In the following, the implementation of each interaction will be described. For the physical explanation, please refer to \citep{Kellerer_2022}. \paragraph{Elastic scattering} -The elastic scattering class is initiated using the cross section, the target specie and a scattering angle distribution. This distribution can be used to roll a scattering angle, given the energy of the incoming particle. It can be set to an isotropic distribution, to a distribution provided by a file and a composite of distributions. For the distribution from a file, the angle distribution has to be provided given an energy binning. During evaluation of the scattering angle, the corresponding energy bin is determined and the corresponding angle distribution selected. The composite of distributions is used in cases, where there is data for a certain energy range, but not in the other. This is the case for the scattering of electrons of tritium molecules. At high energies, the scattering angle distribution is determined from external simulation \citep{Kellerer_2022}, at lower energies isotropic scattering is assumed. +The elastic scattering class is initiated using the cross section, the target species and a scattering angle distribution. This distribution can be used to roll a scattering angle, given the energy of the incoming particle. It can be set to an isotropic distribution, to a distribution provided by a file and a composite of distributions. + +If the distribution is provided by a file, the angle distribution inside the file has to be provided given an energy binning. During evaluation of the scattering angle, the corresponding energy bin is determined and the corresponding angle distribution selected. The scattering angle is then determined from the selected angle distribution. + +In some cases, there is not enough data from one source alone, to cover the whole impact energy range, but maybe from different sources. This is the case for the scattering of electrons of tritium molecules. At high energies, the scattering angle distribution is determined from external simulation \citep{Kellerer_2022}, at lower energies isotropic scattering can be assumed. For these cases, the angle can be determined through the composite of two distributions. The interaction itself is performed in multiple steps. First, the velocity of a target particle is determined. It is compound of the drift velocity of the species and a velocity, which is rolled from the underlying velocity distribution. For the tritium gas, the drift velocity is determined in external simulation and the velocity distribution is given by a Maxwell-Boltzmann distribution \citep{Kellerer_2022}. For tracked particles the drift velocity is assumed to be zero and the velocity distribution is given by the density field. The velocity of the target particle is used to determine the impact energy in the laboratory frame. This energy is then used for the evaluation of the azimuthal scattering angle $\theta$. A second scattering angle is rolled in the interval $[0, 2\pi)$, responsible for the change of momentum in polar direction. Both angles and the target velocity are then used to rotate the velocity vector of the impact particle in the centre of mass frame, see \citep{Kellerer_2022} for the full calculation. This rotated velocity is then used as the new velocity of the impact particle. \paragraph{Clustering} -The clustering class is initiated using the cross section, the target specie and the specie, which is the result of the clustering process. In the interaction itself it is assumed that the new particle follows the direction of movement of the target particle, but with different absolute velocity. The new absolute velocity is calculated from the velocity of a target particle and the new particles mass. The velocity of a target particle is determined analogue to its calculation in elastic scattering. +The clustering class is initiated using the cross section, the target species and the specie, which is the result of the clustering process. In the interaction itself it is assumed that the new particle follows the direction of movement of the target particle, but with different absolute velocity. The new absolute velocity is calculated from the velocity of a target particle and the new particles mass. The velocity of a target particle is determined analogue to its calculation in elastic scattering. \paragraph{Recombination} -The recombination class is initiated using the cross section and the target specie. The interaction itself has only two steps. First, the target density field logs one deletion at the corresponding position, see section~\ref{ssec:denstiy_fields}. Second, the impact particle is marked for deletion. +The recombination class is initiated using the cross section and the target species. The interaction itself has only two steps. First, the target density field logs one deletion at the corresponding position, see section~\ref{ssec:denstiy_fields}. Second, the impact particle is marked for deletion. \paragraph{Free movement} The free movement interaction is only a helper class, which is necessary to be used if no other interaction should be used. It provides the simulation with a very small cross section, which results in a very large mean free path. This large mean free path guarantees a free movement through the simulation domain. If the interaction step is evoked for a particle nothing is done. \paragraph{Charge exchange} -The charge exchange class is initiated using the cross section and the target specie. No product specie is necessary, because product and impact specie are the same. In the interaction, only the velocity of a target particle is determined, analogue its calculation in elastic scattering. This velocity is then used as the new velocity of the impact particle. +The charge exchange class is initiated using the cross section and the target species. No product specie is necessary, because product and impact specie are the same. In the interaction, only the velocity of a target particle is determined, analogue its calculation in elastic scattering. This velocity is then used as the new velocity of the impact particle. \paragraph{Excitation} -The excitation class is initiated using the cross section, the target specie and the excitation energy. In the interaction itself, first the velocity and direction of movement of the impact particle is determined. Second the kinetic energy of the particle calculated and reduced by the excitation energy. Lastly, the new velocity is determined from the reduced energy and direction of movement. This is a simple but effective method for excitation processes. However, no scattering is considered here. This is justifiable, because excitation processes are often much more unlikely than elastic scattering processes und therefore scattering angle effects do not play a significant role. +The excitation class is initiated using the cross section, the target species and the excitation energy. In the interaction itself, first the velocity and direction of movement of the impact particle is determined. Second the kinetic energy of the particle calculated and reduced by the excitation energy. Lastly, the new velocity is determined from the reduced energy and direction of movement. This is a simple but effective method for excitation processes. However, no scattering is considered here. This is justifiable, because excitation processes are often much more unlikely than elastic scattering processes und therefore scattering angle effects do not play a significant role. \paragraph{Ionization} -The ionization class is initiated using the cross section, the target specie, the new electron specie, the new ion specie, the ionization energy and distribution and the scattering angle distribution. It is developed for ionization of the target specie by impact of a particle, which is much lighter than the target. However, the code does not check for this condition. +The ionization class is initiated using the cross section, the target species, the new electron specie, the new ion specie, the ionization energy and distribution and the scattering angle distribution. It is developed for ionization of the target species by impact of a particle, which is much lighter than the target. However, the code does not check for this condition. In the interaction, first the velocity of a target particle is determined analogue to its calculation in elastic scattering. Then, the impact energy in the laboratory frame $E_\text{i}$ is calculated. If the impact energy is below the ionization energy $E_\text{ion}$, no ionization could occur and a new target particle velocity is rolled. This procedure can take a long time. However, the cross section of ionization decreases significantly before the ionization energy. Thus, very few particles with energies close to the ionization energy will undergo ionization, which will therefore not increase the simulation time significantly. When a suitable target particle velocity is determined, the impact energy is used in the ionization energy distribution to roll the impact energy after collision $E_\text{i}^\text{new}$. The energy of the new electron $E_\text{e}$, also called ejected electron in the following, then follows through \begin{equation} @@ -373,17 +375,17 @@ The azimuth angle of both particles is calculated, using the derivation of Gross The density fields are implemented as a class. Each specie holds its own member of this class, which simplifies the evaluation of the fields during the simulation, for example for the calculation of the MFP. The class holds its information in member variables, which are the time particles of the species have spend in a segment of the source, the number of recombination in this segment and the derived density itself. They are represented as four dimensional arrays. The fastest axis (third axis) is used for the different energy bins. This reduces the calculation time of the determination of the density in a segment, which is mainly a sum over all energy bins. It is evoked multiple times during the particle update, which requires a fast calculation. The use of the other axis follows the consideration of how often the bin changes in longitudinal, azimuthal and radial direction. The magnetic field is most commonly aligned in longitudinal direction. Thus, the particles mostly travel in longitudinal direction. Therefore, the second fastest axis is used for the longitudinal direction. The other two directions are similar in their usage. Because of the magnetron drift in radial inhomogeneous magnetic fields, it was decided to use the azimuthal direction next, followed by the radial direction. -The size of the arrays is derived from the user input. It is calculated from the desired number of segments and a build in under- and overflow. This way, if a particle can not be classified into one of the segments, the information is still recorded in the simulation. The energy bins are created in logarithmic scale with one bin each for under- and overflow. It can be set differently for each specie. Thus, important effects for each specie can be resolved more easily. In longitudinal direction, the bins are divided evenly with one bin each for under- and overflow. In general, these under- and overflow bins should not be filled during the simulation, because this would mean that a particle has left the simulation domain and is still alive. Hence, they can be used for debugging purposes. In radial direction, there is only an overflow bin, because the radius is lower bound to zero. In azimuthal direction no over- and underflow bins are used, due to the circular nature of the problem. +The size of the arrays is derived from the user input. It is calculated from the desired number of segments and a built in under- and overflow. This way, if a particle can not be classified into one of the segments, the information is still recorded in the simulation. The energy bins are created in logarithmic scale with one bin each for under- and overflow. It can be set differently for each specie. Thus, important effects for each specie can be resolved more easily. In longitudinal direction, the bins are divided evenly with one bin each for under- and overflow. In general, these under- and overflow bins should not be filled during the simulation, because this would mean that a particle has left the simulation domain and is still alive. Hence, they can be used for debugging purposes. In radial direction, there is only an overflow bin, because the radius is lower bound to zero. In azimuthal direction no over- and underflow bins are used, due to the circular nature of the problem. The calculation of the density needs also the physical time, see equation~\ref{eq:target_field_density}. This time is provided by a pointer to a timer class. This class is called, when new particles are injected in the simulation domain, see section~\ref{ssec:injection}, and thus the physical time increases. -The current collector is structured similar to the density field class. The difference being, that it holds instead the crossings in positive and negative direction through the predefined faces in three dimensional arrays for crossings in longitudinal, azimuthal and radial direction. The faces can be aligned to the segmentation of the density fields, but can in general be set to its own segmentation. However, the mover uses both the density fields and current collectors to evaluate possible endpoints of movement, see section~\ref{ssec:movement}. Thus, a different segmentation will lead to a longer simulation time. +The current collector is structured similar to the density field class. The difference being, that it holds the crossings in positive and negative direction through the predefined faces in three dimensional arrays for crossings in longitudinal, azimuthal and radial direction instead. The faces can be aligned to the segmentation of the density fields, but can in general be set to its own segmentation. However, the mover uses both the density fields and current collectors to evaluate possible endpoints of movement, see section~\ref{ssec:movement}. Thus, a different segmentation will lead to a longer simulation time. \subsection{Injection} \label{ssec:injection} -The injection of new particles to the particle queue is managed by the injector class. It is initiated by providing the event position distribution, the mother drift velocity and a list of species, with their energy and injection angle distribution. The event position distribution is used to determine the position, at which the new particles are to be injected. For each injected specie, the kinetic energy is rolled through the energy distribution. The corresponding velocity vector is rolled from the injection angle distribution and scaled by the kinetic energy. This velocity is then boosted by the mother drift velocity, which represents the movement of the decaying gas. +The injection of new particles to the particle queue is managed by the injector class. It is initiated by providing the event position distribution, a list of created species, with their energy and injection angle distribution, and the drift velocity of the mother species. In this context, the mother species means, the species from which the new particles are created from, eg. through decay. The event position distribution is used to determine the position, at which the new particles are to be injected. For each injected specie, the kinetic energy is rolled through the energy distribution. The corresponding velocity vector is rolled from the injection angle distribution and scaled by the kinetic energy. This velocity is then boosted by the mother drift velocity. In the case of the KATRIN source, the injected species are electrons, with an isotropic injection angle distribution and a Fermi energy distribution \citep{Fermi:1934aa} and T$_2^+$ ions, also with an isotropic injection angle distribution, but with a Maxwell-Boltzmann energy distribution. The mother drift velocity is provided by the drift velocity of the neutral tritium gas. @@ -395,7 +397,7 @@ After the injection of particles, the timer class is provided with a time, which \subsection{Parallelization} \label{ssec:parallelization} -In order to obtain reasonable and robust results of the simulation, high statistics is necessary. This is especially the case, if also improbable effects like the excitation by rotation, should be visible in the results. The goal of high statistics can be reached by parallel computation. For the code, a simple parallelization strategy was used. The desired number of decays are distributed evenly on the cores, and each CPU core follows the simulation loop (see section~\ref{ssec:general_diagram}) independent from the others. The general setup of the simulation stays the same between CPU cores. However, a asset of the code is, that the Monte Carlo events of each particle track can be dependent on the other, for example in the case of recombination. In order to obtain this strong point, the number of desired events per CPU core are further subdivided into cycles with a fixed length. After each cycle, a synchronization step between the CPU cores is initiated. During the synchronization step, the data on the density fields is shared among all CPU cores. Since the simulation is set up the same for all CPU cores, this step only needs an additive operation on the array of cumulated times, see section~\ref{ssec:denstiy_fields}, and an additive step, to share the passed time. Additionally to the density field synchronization, also the data of the current borders and deletion loggers are synchronized, which is not strictly necessary, but keeps the data congruent on all CPU cores and makes the output step easier, see section~\ref{ssec:output}. +In order to obtain reasonable and robust results of the simulation, high statistics is necessary. This is especially the case, if also improbable effects like the excitation by rotation, should be visible in the results. The goal of high statistics can be reached by parallel computation. For the code, a simple parallelization strategy was used. The desired number of decays are distributed evenly on the cores, and each CPU core follows the simulation loop (see section~\ref{ssec:general_diagram}) independent from the others. The general setup of the simulation stays the same between CPU cores. However, an asset of the code is, that the Monte Carlo events of each particle track can be dependent on the other, for example in the case of recombination. In order to obtain this strong point, the number of desired events per CPU core are further subdivided into cycles with a fixed length. After each cycle, a synchronization step between the CPU cores is initiated. During the synchronization step, the data on the density fields is shared among all CPU cores. Since the simulation is set up the same for all CPU cores, this step only needs an additive operation on the array of cumulated times, see section~\ref{ssec:denstiy_fields}, and an additive step, to share the passed time. Additionally to the density field synchronization, also the data of the current borders and deletion loggers are synchronized, which is not strictly necessary, but keeps the data congruent on all CPU cores and makes the output step easier, see section~\ref{ssec:output}. The benefit of this parallelization scheme lies in its simplicity. It is easy to include more CPU cores for the calculation. Only the synchronization step takes slightly longer. However, the main simulation effort lies in the movement and interaction step. Thus, the synchronization does not play a significant role. Further more, there is no need of a CPU core, which directs tasks to the other CPU cores. Hence, little communication and data exchange is necessary between CPU cores, which saves calculation time. @@ -411,12 +413,12 @@ The simplicity of the method also produces some drawbacks. First, the load on th \subsection{Output} \label{ssec:output} -The output of the simulation is written to a single HDF5 file \citep{hdf5}, which allows for extendable, structured data storage. Output is performed in two different modes. First, it is enacted after the initialization phase of the simulation to write non-changing data to file for each of the tracked specie. This includes for example, the mass and charge of the species, the volumes and surface areas of the segmentation and the number of bins. Second, the output is performed to write the simulated data (from density fields, current collector, deletion logger) to file. This step is performed after each CPU synchronization, see section~\ref{ssec:parallelization}. In general, only the last output is of interest for the user. However, the steps in between can be used for debugging. Additionally, if the user has not set the correct wall time at the programming cluster an intermediate result is available. Thus, the user can decide for each specie and output type (density field, current collector, deletion logger) the output interval and if the new data of the step should be saved separately or if the data of the old step should be overwritten. The latter saves disk space. Nevertheless, the size of the output file is comparably small, since it holds only derived properties; Depending of course on the number of segments chosen by the user. +The output of the simulation is written to a single HDF5 file \citep{hdf5}, which allows for extendable, structured data storage. Output is performed in two different modes. First, it is enacted after the initialization phase of the simulation to write non-changing data to file for each of the tracked specie. This includes for example, the mass and charge of the species, the volumes and surface areas of the segmentation and the number of bins. Second, the output is performed to write the simulated data (from density fields, current collector, deletion logger) to file. This step is performed after each CPU synchronization, see section~\ref{ssec:parallelization}. In general, only the last output is of interest for the user. However, the steps in between can be used for debugging. Additionally, if the user has not set the correct wall time at the computing cluster an intermediate result is available. Thus, the user can decide for each specie and output type (density field, current collector, deletion logger) the output interval and if the new data of the step should be saved separately or if the data of the old step should be overwritten. The latter saves disk space. Nevertheless, the size of the output file is comparably small, since it holds only derived properties; Depending of course on the number of segments chosen by the user. \subsection{Initialization} \label{ssec:initialization} -The initialization of the simulation it administered by the simulation class using generators which are available for classes, which need special user input. The specific build instructions have to be provided in a JavaScript Object Notation (JSON) file. Due to its hierarchical structure, it is easy to read, test and extend by the user, even with little programming experience. We use the Jansson library \citep{jansson} to read in the file. +The initialization of the simulation it administered by the simulation class using generators which are available for classes, which need special user input. The specific run instructions have to be provided in a JavaScript Object Notation (JSON) file. Due to its hierarchical structure, it is easy to read, test and extend by the user, even with little programming experience. We use the Jansson library \citep{jansson} to read in the file. The JSON file is structured, such that each of the sections corresponds to one main idea of the code or class. Subsections are used, when the class is a composite of other classes. This way the parameter file stays extensible in the face of new methods and classes, which will be added in the future. A collection of JSON files for each generator is provided together with the code for easy usage. A selections of generators will be discussed in the following. @@ -426,7 +428,7 @@ If energy or length values are to be input by the user, the corresponding value Functions are an integral part of the code, used for example to express cross sections. There are two types of functions implemented: a mapping of $\mathbb{R} \to \mathbb{R}$, called later on 1D-function or a mapping of $\mathbb{R}^3 \to \mathbb{R}$, called later on 3D-function. \paragraph{Scalar field} -Scalar fields represent the idea, that for every point in space a certain value can be assigned. The scalar field can currently only be initiated through one option, namely the \textit{ScalarFieldFunctionInZ}. As the name suggests, it returns values, which are provided through a 3D-function. The general input of coordinates are transformed to cylinder coordinates $(r, \phi, z)$ and the corresponding function value is returned. +Scalar fields represent the idea, that for every point in space a certain value can be assigned. The scalar field can currently only be initiated through one option, namely the \textit{ScalarFieldFunctionInZ}. As the name suggests, it returns values, which are provided through a 3D-function. The general input of coordinates are transformed to cylinder coordinates $(r, \phi, z)$ and the corresponding function value is returned. In the case of the \textit{ScalarFieldFunctionInZ} only the $z$ coordinate is taken into account. \paragraph{Vector field} Vector fields represent the idea, that for every point in space a certain three dimensional vector can be assigned. The vector field can be initiated through three different options: \textit{VectorFieldConstant}, \textit{VectorFieldFunctionInZ} and \textit{VectorFieldFromArray}. For all three types, the general input of coordinates are transformed in the class to cylinder coordinates $(r, \phi, z)$ and the corresponding vector is calculated and returned. @@ -518,7 +520,7 @@ Electrons are created with energies drawn from the Fermi distribution of $\upbet Ions on the other hand are created with thermal energies of the neutral gas and then perform mostly elastic scatterings, which preserves the Maxwell Boltzmann distribution. The thermal distributions of ions and electrons differ due to different cross sections at lower energies \citep{Kellerer2022_1000143868}. The relative height of the differential density for the different ion species is a result of clustering processes, which will result in the end in T$_3^+$ ions. Clustering is more efficient for T$_2^+$ ions than for T$^+$ ions, which results in a higher density for T$^+$ ions than for T$_2^+$ ions. -The spectrum shows very clearly that all processes for the particles interact in a non-trivial manor. It is therefore necessary to use a sophisticated tool like KARL to simulate their behaviour inside the KATRIN source. +The spectrum shows very clearly that all processes for the particles interact in a non-trivial manner. It is therefore necessary to use a sophisticated tool like KARL to simulate their behaviour inside the KATRIN source. %\appendix