diff --git a/docs/paper/the-karl-code/paper.tex b/docs/paper/the-karl-code/paper.tex
index e7a4ed0..31447ad 100755
--- a/docs/paper/the-karl-code/paper.tex
+++ b/docs/paper/the-karl-code/paper.tex
@@ -104,7 +104,7 @@
\begin{abstract}
-\changed{A new parallelized simulation code is presented, which uses a semi classical Monte Carlo method to determine particle spectra in the KATRIN source. Reaction chains are generated from the decay of tritium within the source. The code includes all relevant processes: elastic scattering, ionization, excitation (electric, vibrational, rotational), recombination and various clustering processes. The main emphasis of the code is the calculation of particle spectra and particl densities and currents at specific points within the source. It features a new technique to determine these quantities. It also calculates target fields for the interaction of particles with each other as it is needed for recombination processes.\\
+\changed{A new parallelized simulation code is presented, which uses a semi classical Monte Carlo method to determine particle spectra in the KATRIN source. Reaction chains are generated from the decay of tritium within the source. The code includes all relevant processes: elastic scattering, ionization, excitation (electric, vibrational, rotational), recombination and various clustering processes. The main emphasis of the code is the calculation of particle spectra and particle densities and currents at specific points within the source. It features a new technique to determine these quantities. It also calculates target fields for the interaction of particles with each other as it is needed for recombination processes.\\
The code has been designed for the KATRIN experiment but is easily adaptable for other tritium based experiments like Project 8. Geometry and background tritium gas flow can be given as user input.\\
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.
}
@@ -162,35 +162,25 @@ The experiment can be divided into two parts: the source section and the detecto
The atomic and molecular processes produce secondary particles which may subsequently yield even more particles, which are either eliminated through recombination or similar processes or absorbed by the walls of the experiment. The charged particle density is high enough, that a plasma forms in the source \citep{Kuckert.2016}. \changed{This plasma influences the high energy spectrum through its self generated inhomogeneous electric potential.} A precise knowledge of the electron and ion energy spectrum and density is necessary for any plasma analysis.
-Two different methods of descriptions seem obvious: a description through the temporal evolution of phasespace elements and a description through the Monte Carlo method by tracking of single particles \citep{MOBUS2001519}. \changed{The first method impresses with a high resolution in space and velocity but is very computational intensive, especially with many different interaction types and species. A comparison with Monte Carlo type simulations is complicated: Since this would not be a statistical method the noise is negligble, but the requirements to save the phase-space distribution (specifically for high velocities) are extremely high. Thus, it was rejected for the simulation of the problem at hand.} The Monte Carlo method seems preferable, but in a classical Monte Carlo scheme each of the simulated events is independent on the others. This is not the case for events for electron and ions tracks because of recombination. This problem is addressed in the KARL code, which is presented in the this paper.
-
-\changed{The simulation approach presented in this paper and realized through the KARL code works under the assumption that all atomic and molecular processes are fast compared to the plasma processes. Using a Monte Carlo like approach the effects of different processes are taken into account and produce spectra of different species. These spectra will be utilized to calculate plasma potentials elsewhere. Resulting plasma potentials can then be fed back into the KARL code.}
-
-The experimental setup of the KATRIN experiment is used as the default setup in the code. Other experiments using tritium decay may be easily implemented as the geometry and injection characteristics can be modified. This applies particularly to the Project 8 experiment \citep{2022arXiv220307349P}. Within the KARL framework the majority of all tritium reactions are implemented, but some reactions that occur in vastly different parameter regimes may not be implemented yet.
-
-
-
-
-
-
+Two different methods of descriptions seem obvious: a description through the temporal evolution of phasespace elements and a description through the Monte Carlo method by tracking of single particles \citep{MOBUS2001519}. \changed{The first method impresses with a high resolution in space and velocity but is very computational intensive, especially with many different interaction types and species. A comparison with Monte Carlo type simulations is complicated: Since this would not be a statistical method the noise is negligble, but the requirements to save the phase-space distribution (specifically for high velocities) are extremely high. Thus, it was rejected for the simulation of the problem at hand. However, in a classical Monte Carlo scheme each of the simulated events is independent of the others. This is not possible if direct interactions (e.g. recombination) between electrons and ions are of interest.} This problem is addressed in the KARL code, which is presented in the this paper.
+\changed{The simulation approach presented in this paper and realized through the KARL code works under the assumption that all atomic and molecular processes are fast compared to the plasma processes. Using a Monte Carlo like approach the effects of different processes are taken into account and produce energy spectra of different species. These spectra will be utilized to calculate plasma potentials elsewhere. Resulting plasma potentials can then be fed back into the KARL code.}
+\changed{The experimental setup of the KATRIN experiment is used as the default setup in the code. Other experiments using tritium decay may be easily implemented as the geometry and injection characteristics can be modified. This applies particularly to the Project 8 experiment \citep{2022arXiv220307349P}. Within the KARL framework the majority of all tritium reactions are implemented, but some reactions that occur in vastly different parameter regimes may not be implemented yet.}
\section{Description of the method}
\label{sec:method}
-\changed{The general setup of the code is such that in first place incident particles from tritium beta decay are tracked. 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 incident electron spectrum originating from tritium beta decay before any scattering for high energy electrons is comparably simple to describe, as it follows the Fermi statistics of beta decay \citep{Fermi:1934aa}.
-
+\changed{The general setup of the code is such that in the first place incident particles from tritium beta decay are tracked. 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 before new decay particles are added.
+The initial electron energy spectrum for electrons created by tritium beta decay is comparably simple to describe, as it follows the Fermi statistics of beta decay \citep{Fermi:1934aa}.
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 are drawn from a list of available interactions.
+Through their interactions they form a reaction tree with subsequently generated secondary particles (or with pre-existing particles that change properties via the interaction). In order to follow all interactions of this tree each secondary particle forms a new ``branch''. Within the code newly generated particles are put into a list that is processed after the incident particle reaches the end of its lifetime.}
-Through their interactions they form a reaction tree with subsequently generated secondary particles (or with pre-existing particles that change properties via the interaction). In order to follow all interactions of this tree each secondary particles forms a new ``branch''. Within the code newly generated particles are put into a list that is processed after the incident particles reaches the end of its lifetime.}
+\changed{Apart from the decay process new particles are created mainly by ionization.}
+\changed{Ionization produces two indistinguishable electrons with energies between \SI{0}{eV} and the impact energy subtracted by the ionization energy.}
-New particles are created through ionization first. \changed{Ionization produces two indistinguishable electrons with energies between \SI{0}{eV} and the impact energy.}
-
-\changed{For electrons below \SI{100}{eV} elastic scattering is the dominant process, while for electrons above that energy ionization becomes dominant. This can lead to a large amount of electrons being created if the neutral gas density is high enough.}
+\changed{For electrons below \SI{100}{eV} elastic scattering is the dominant process, while for electrons above that energy ionization becomes dominant, see Figure~\ref{fig:et2_interactions}. Depending on the neutral gas density this can lead to a large amount of secondary electrons being created.}
%For high energy electrons these interactions include mostly elastic scattering, but also ionization. Hence, many more electrons, and therefore also ions, are created in the source than from beta decay alone.
@@ -201,7 +191,9 @@ The KARL code is customized to the special conditions in the KATRIN source. Henc
\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.
+\changed{The main simulation cycle of the code consists of three subcycles, see Figure~\ref{fig:simulation_flow}.}
+%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.
%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.
@@ -225,7 +217,7 @@ 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.
+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 \changed{do} not \changed{include} 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.
\begin{figure}[tbp]
\centering
@@ -240,7 +232,7 @@ After the movement step it is evaluated if the particle needs to be terminated,
In a general Monte Carlo simulation, each event is assumed to be independent of the other. However, different particles types can in general interact with each other, for example electrons and ions through recombination. Therefore, each Monte Carlo event in our simulation must be dependent on the other events. This dependence is mimicked in the simulation by so-called density fields. These density fields determine the number density of each particle specie during the simulation. These fields are then used to determine the MFP and are used in the selection of the interaction type.
-In the simulation, the source is segmented into evenly spaced intervals in longitudinal, radial and azimuthal direction, predefined by the user, see Figure~\ref{fig:segmentation} for a schematic representation. In each iteration step of the particle queue, it is recorded how long a particle with index $i$ stays in one of the predefined segments, labelled by the time $t_i$. The number density $n_\alpha$ of a species $\alpha$ is then proportional to the total time of all particles of the corresponding species spent in the segment $\sum_i t_i$ and the volume $V$ of the segment. In case of recombination, an additional term has to be added corresponding to the number of recombination $N_\gamma$ of the recombination partner $\gamma$ in the segment, resulting in
+In the simulation, the source is \changed{split} into evenly spaced intervals in longitudinal, radial and azimuthal direction, predefined by the user, see Figure~\ref{fig:segmentation} for a schematic representation \changed{of the segmentation}. In each iteration step of the particle queue, it is recorded how long a particle with index $i$ stays in one of the predefined segments, labelled by the time $t_i$. The number density $n_\alpha$ of a species $\alpha$ is then proportional to the total time of all particles of the corresponding species spent in the segment $\sum_i t_i$ and the volume $V$ of the segment. In case of recombination, an additional term has to be added corresponding to the number of recombination $N_\gamma$ of the recombination partner $\gamma$ in the segment, resulting in
\begin{equation}
n_\alpha = \frac{\sum_i t_i}{t_\text{sim} V} - \frac{N_\gamma}{V} \commaeq
\label{eq:target_field_density}
@@ -261,20 +253,20 @@ 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 \citep{Kellerer_2022}
+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, \changed{which register particle crossings.} 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}
-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 respectively, $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}.
-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.
+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 (\changed{e.g.} electrons) in the simulation.
-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.
+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 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.
@@ -282,11 +274,11 @@ The tracked specie class is composed of different classes, providing access to t
\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 drawn 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.
+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 divided into 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 drawn 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 is therefore less accurate. Both movers will be presented shortly in the following.
\paragraph{Boris mover}
@@ -302,9 +294,9 @@ 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 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}.
+The drift mover is based on the description of the movement of the particle 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.
+In the drift mover, the movement is divided 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 \changed{is} 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 gyrocenter $\Delta \mathbf{x}_\text{c}$, the movement of the gyrocenter parallel to the magnetic field $\Delta \mathbf{x}_\parallel$ and the drift movement of the gyrocenter $\Delta \mathbf{x}_\text{D}$.
@@ -316,7 +308,7 @@ and the timestep length $\Delta t$
\begin{equation}
\Delta t = \frac{\Delta x}{\abs{\mathbf{v}_\parallel} + \abs{\mathbf{v}_\perp} + \abs{\mathbf{v}_\text{D}}} \commaeq
\end{equation}
-where $\Delta x$ is the step length of the movement step and $\mathbf{v}_\parallel$ and $\mathbf{v}_\perp$ the velocity parallel and perpendicular to the magnetic field. The moved distance through the drift motion evaluates the to
+where $\Delta x$ is the step length of the movement step and $\mathbf{v}_\parallel$ and $\mathbf{v}_\perp$ the velocity parallel and perpendicular to the magnetic field. The moved distance through the drift motion evaluates to
\begin{equation}
\Delta \mathbf{x}_\text{D} = \Delta t \cdot \mathbf{v}_\text{D} \fullstop
\end{equation}
@@ -364,12 +356,12 @@ The rotation of the perpendicular velocity is again calculated using Rodriges' r
\label{ssec:termination}
The termination of particles is addressed by the terminator class. It checks for three different conditions. First it checks, if the particle has left the simulation geometry. For the KATRIN experiment the geometry can be approximated by a cylinder. However, the radius and height have be provided by the user for special analysis. Second, the terminator class checks if the particle has exceeded the user defined number of maximal interactions. This counter was added, to ensure that no trapped particles are tracked by the simulation. Otherwise the simulation would not end. \changed{To assure that the simulation continues to be physically accurate, it is important to choose an appropriate value for the number of maximal interactions. In Figure~\ref{fig:maxInteractions_vs_density} some small test setup has been used %Note: has to be described, probably has to be moved into the Test cases subsection
-to show the dependence of the density w.r.t. the number of maximal interactions.} This trap can occur for example through opposite neutral gas flow and reflection by electric fields. Third, the terminator class checks if the particle has exceeded the user defined lifetime. This counter ensures, that particles are not stored indefinitely. This could occur through special configuration of magnetic and electric fields.
+to show the dependence of the density w.r.t. the number of maximal interactions.} This trapping can occur for example through opposite neutral gas flow and reflection by electric fields. Third, the terminator class checks if the particle has exceeded the user defined lifetime. This counter ensures, that particles are not stored indefinitely. This could occur through special configuration of magnetic and electric fields.
\begin{figure}
\centering
\includegraphics[width=1\textwidth]{figures/maxInteractions_vs_density.pdf}
-\caption{TBD}
+\caption{Dependence of the densities of different tracked species on the number of maximal interactions. Simulation has been performed using a neutral background specie density of \SI{2.41e24}{\per\cubic\metre}. The densities of the shown species have been averaged over the whole simulation domain.}
\label{fig:maxInteractions_vs_density}
\end{figure}
@@ -399,7 +391,7 @@ In addition to the terminator class, the user can choose to add a deletion logge
\label{fig:t3p_interactions}
\end{figure}
-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 \changed{target-density scaled} cross section, which \changed{is} used in the calculation of the MFP, \changed{see equation \eqref{eq:mean_free_path}}, 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, or provide an own function in the configuration file, see section~\ref{ssec:initialization}. The target specie can either be a tracked or background specie, \changed{with some restrictions dependent on the specific interaction}.
+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 \changed{target-density scaled} cross section, which \changed{is} used in the calculation of the MFP, \changed{see equation \eqref{eq:mean_free_path}}, 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 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, or provide an own function in the configuration file, see section~\ref{ssec:initialization}. The target specie can either be a tracked or background specie, \changed{with some restrictions dependent on the specific interaction}.
%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 and ionization. In general, all types can be 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}.
@@ -407,23 +399,27 @@ Currently there are seven types of interactions implemented: elastic scattering,
\paragraph{Elastic scattering}
\changed{
-The type of elastic scattering interactions considered are of the form:
+The most prominent interaction between low energy particles is elastic scattering, in which the total kinetic energy is conserved. For electrons colliding with molecular tritium this interaction can be written as
\begin{align}
\label{eq:elastic_scattering}
\begin{split}
-e^- + H_2 &\rightarrow e^- + H_2 \quad \text{and} \\
-H_2^+ + H_2 &\rightarrow H_2^+ + H_2 \, .
+e^- + H_2 &\rightarrow e^- + H_2 \fullstop
\end{split}
\end{align}
-This can be used for any tracked specie with a background species as the target.
+This interaction can be used for any tracked specie colliding with a background species as the target.
% Note: a tracked species can also be used as the target but in that case both a drift velocity and a velocity distribution have to be specified.
The values of the cross sections for electrons can be seen in Figure~\ref{fig:et2_interactions} and for H$_2^+$ in Figure~\ref{fig:t2p_interactions}.}
The elastic scattering class is initiated using the cross section, the target species and a scattering angle distribution. This distribution \changed{is} used to draw a scattering angle, given the energy of the incoming particle. \changed{The available options are} an isotropic distribution, a distribution provided by a file and a \changed{composition} 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 energy bin is determined and the corresponding angle distribution selected. The scattering angle is then determined from \changed{this} angle distribution. %Note: is not helpful, need to mention somewhere how the file has to be structured
+During evaluation of the scattering angle, the energy bin is determined and the corresponding angle distribution selected. The scattering angle is then drawn from \changed{this} angle distribution \changed{using a piecewise linear 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 with 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 composition of two distributions. The cross section of elastic scattering was measured at different experiments in the energy range of \changed{\SI{2e-2}{eV} to \SI{1e2}{eV}}. The results of these experiments were combined by \citep{Tawara.1990} and parameterized by \citep{Yoon.2008}.
+%Note: Somewhere the struture for input files has to be explained!
+
+In some cases, there is not enough data from one source alone, to cover the whole impact energy range. This is the case for the scattering of electrons with 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. \changed{For these cases, the scattering angle distribution can be composed using the known distributions and a threshold energy defining point of transition between the distributions.}
+%For these cases, the angle can be determined through the composition of two distributions.
+
+The cross section of elastic scattering was measured at different experiments in the energy range of \changed{\SI{2e-2}{eV} to \SI{1e2}{eV}}. The results of these experiments were combined by \citep{Tawara.1990} and parameterized by \citep{Yoon.2008}.
The interaction itself is performed in multiple steps. First, the velocity of a target particle is determined. It is \changed{a} compound of the drift velocity of the species and a velocity, which is drawn 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}.
%Note: the following sentence should be a lie. A tracked species should throw an error if any of the two components is initialized with "null"...
@@ -457,7 +453,7 @@ The clustering class is initiated using these \changed{approximated} cross secti
Recombination is the interaction in which an ion species and an electron species form a neutral particle:
\begin{equation}
\label{eq:recombination}
-H^+ + e^- \rightarrow H \, .
+H^+ + e^- \rightarrow H + h\nu \fullstop
\end{equation}
}
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 different recombination cross sections are given by \citep{Janev.2003,Kotelnikov.2019,Pettersson.2015} \changed{and are plotted in Figures~\ref{fig:t2p_interactions} and \ref{fig:t3p_interactions}.}
@@ -472,12 +468,13 @@ Only the following type of charge exchange interactions is considered
\label{eq:charge_exchange}
H_2^+ + H_2 \rightarrow H_2 + H_2^+ \, .
\end{equation}
-I.e. charge exchange processes are only possible between a background species and its singly charged ion.
+I.e. charge exchange processes are only possible between a background species and the corresponding singly charged ion.
}
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. Cross sections for this process class can be found in \citep{Janev.2003} \changed{ and are plotted in Figure~\ref{fig:t2p_interactions}}.
\paragraph{Excitation}
\changed{
+The target particle can be excited if the collision energy is above the corresponding threshold energy. This is mainly the case in electron collisions with the background gas
\begin{equation}
\label{eq:excitation}
e^- + H_2 \rightarrow e^- + H_2^* \commaeq
@@ -488,27 +485,28 @@ The excitation class is initiated using the cross section, the target specie and
\paragraph{Ionization}
\changed{
-In a molecular background gas there are principally two types of electron ionization processes. In the first one, the target only loses an electron
+In a molecular background gas there are two types of electron ionization processes. In the first one, the target only loses an electron
\begin{equation}
\label{eq:ionization_non_diss}
e^- + H_2 \rightarrow e^- + e^- + H_2^+ \, .
\end{equation}
-In the second one the target itself is also destroyed:
+In the second one the target itself also dissociates:
\begin{equation}
\label{eq:ionization_diss}
e^- + H_2 \rightarrow e^- + e^- + H^+ + H \commaeq
\end{equation}
-where the $H$ might also be in an excited state.
+where the $H$ might also be left in an excited state.
}
-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 specie, the new electron specie, the new ion specie, the ionization energy, \changed{the ionization energy 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.
In the interaction, first the velocity of a target particle is determined \changed{analogous} to its calculation in elastic scattering. Then, the impact energy in the \changed{center of mass} 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 drawn. This procedure can take a long time. However, the cross section of ionization decreases significantly \changed{close to} 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. \changed{Once} a suitable target particle velocity is determined, the impact energy is used in the ionization energy distribution
% Note: should probably be cited and plotted...
+% Note: mention how the particles are actually differentiated? (fast->impact, slow->ejected)
to draw 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 \changed{from}
\begin{equation}
E_\text{e} = E_\text{i} - E_\text{ion} - E_\text{i}^\text{new} \fullstop
\end{equation}
-Next, the direction of movement has to be determined. For both the impact particle and the ejected electron, the direction of movement is calculated as a rotation of the impact velocity direction in the \changed{center of mass} frame by the polar and azimuthal angle. The azimuthal angle of the impact particle $\phi_\text{i}$ is drawn from the interval $[0,2\pi)$. The direction of the \changed{ejected} electron is set to the opposite direction. Thus, the azimuthal angle of the ejected electron $\phi_\text{e}$ is calculated from
+Next, the direction of movement has to be determined. For both the impact particle and the ejected electron, the direction of movement is calculated as a rotation of the impact velocity direction in the \changed{center of mass} frame by the polar and azimuthal angle. The azimuthal angle of the impact particle $\phi_\text{i}$ is drawn \changed{uniformly} from the interval $[0,2\pi)$. The direction of the \changed{ejected} electron is set to the opposite direction. Thus, the azimuthal angle of the ejected electron $\phi_\text{e}$ is calculated from
\begin{equation}
\phi_\text{e} = \phi_\text{i} - \pi \fullstop
\end{equation}
@@ -519,25 +517,29 @@ The cross sections and more importantly the distribution of secondary particles
\subsection{Calculation of fields}
\label{ssec:field_calculation}
-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 spent 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. The fastest axis refers to the axis for which the entry can be accessed the quickest. 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 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 \changed{stores} the time particles of the species have spent 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. The fastest axis refers to the axis for which the entry can be accessed the quickest. \changed{This is an effect created by caching. Since data blocks located closely in the memory are pre-loaded into the cache, which reduces the access time.} 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 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 calculation of the density also needs 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}, \changed{to increase the physical 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.
+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 \changed{with} the segmentation of the density fields, but can in general be set \changed{arbitrarily}.
+
+% Next sentence is a lie, only the binning of the density field is used, the current collector does not even have the funcitons to perform the corresponding checks
+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 drawn from the energy distribution. The corresponding velocity vector is drawn 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 \changed{decay} 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 drawn from the energy distribution. The corresponding velocity vector is drawn 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.
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. T$_2^+$ is used instead of HeT$^+$ due to the fact that both molecules have almost the same mass and no cross section data could be found in the literature for the latter. Nuclear recoil from the $\upbeta$-decay is not considered. This is again due to the higher interaction probability of the ions with the neutral gas, which thermalizes them more quickly. The mother drift velocity is provided by the drift velocity of the neutral tritium gas.
The injector class can also be used for the injection of a stream of directed particles. This is necessary, either for the evaluation of the influence of an electron gun in the experiment, or for test purposes.
-After the injection of particles, the timer class is provided with a time, which has passed between injections. This time is based on the user defined activity.
+After the injection of particles, the timer class is provided with the time, that has passed between injections. This time is based on the user defined activity.
%% Might imply that the code can do that, which it can't
%It can be calculated from the integrated density in the source and the decay constant.
@@ -552,12 +554,16 @@ The benefit of this parallelization scheme lies in its simplicity. It is easy to
The simplicity of the method also produces some drawbacks. First, the load on the CPU cores can be different even though the number of events was set to the same value because of the creation of new particles through ionization. However, if the cycle length is chosen large enough, the load can balance out. The specific choice of cycle length depends on the simulated problem and has to be chosen by the user.
-The simulation code used for this study was parallelized to improve the efficiency of the computation, as described in the previous paragraph. The effectiveness of this parallelization strategy can be seen in the scaling graph shown in Figure~\ref{fig:scaling_graph}. The graph illustrates the time it took for the simulation to complete for different numbers of events and CPU cores. As can be seen, the scaling is linear except for the first data point, which is slightly slower. This is due to the initialization of the simulation and the distribution of events to the different CPU cores. Once the simulation is properly initialized, the linear scaling is observed for all subsequent data points. This behaviour is expected and is a common characteristic of parallelized simulations.
+%The simulation code used for this study was parallelized to improve the efficiency of the computation, as described in the previous paragraph.
+The effectiveness of this parallelization strategy can be seen in the scaling graph shown in Figure~\ref{fig:scaling_graph}.
+\changed{The graph show the weak scaling behaviour of the code, i.e. the number of events per CPU core is kept constant and the number of cores is varied. In an ideal scenario the wallclock time needed until completion depends only on the number of events per CPU core, meaning that the number of events processed per second should increase linearly with the number of tasks. It can be seen that the graph follows this behaviour quite well, except for the first data point, which is slower due to the initialization step that cannot be parallelized.}
+%The graph illustrates the time it took for the simulation to complete for different numbers of events and CPU cores. As can be seen, the scaling is linear except for the first data point, which is slightly slower. This is due to the initialization of the simulation and the distribution of events to the different CPU cores.
+Once the simulation is properly initialized, the linear scaling is observed for all subsequent data points. This behaviour is expected and is a common characteristic of parallelized simulations.
\begin{figure}[tbp]
\centering
\includegraphics[width=1.0\textwidth]{figures/parallelization.pdf}
- \caption{Scaling graph. Simulated using standard KATRIN parameters with increasing number of events. The load was divided evenly between the CPU cores. It was recorded how long the simulation took from start to finish, including output. The result of a single CPU core is used for prognosis of the ideal scaling. The simulations were performed on the bwForCluster NEMO\citep{nemo_cluster}.}
+ \caption{Weak scaling graph. Simulated using standard KATRIN parameters with increasing number of events. The load was \changed{kept constant on the} CPU cores. It was recorded how long the simulation took from start to finish, including output. The result of a single CPU core is used for prognosis of the ideal scaling. The simulations were performed on the bwForCluster NEMO\citep{nemo_cluster}.}
\label{fig:scaling_graph}
\end{figure}
@@ -586,7 +592,7 @@ Scalar fields represent the idea, that for every point in space a certain value
\paragraph{Vector field}
% Vector fields represent the idea, that for every point in space a certain three dimensional vector can be assigned.
-A vector field can be initiated through three different options: \textit{VectorFieldConstant}, \textit{VectorFieldFunctionInZ} and \textit{VectorFieldFromArray}. \changed{Any vector field object takes either a position as either a Cartesian or cylinder vector and returns the value at that position as a cylinder vector.}
+A vector field can be initiated through three different options: \textit{VectorFieldConstant}, \textit{VectorFieldFunctionInZ} and \textit{VectorFieldFromArray}. \changed{Any vector field object takes either a position as a Cartesian or cylinder vector and returns the value at that position as a cylinder vector.}
%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.
\begin{itemize}
@@ -596,7 +602,7 @@ A vector field can be initiated through three different options: \textit{VectorF
\end{itemize}
\paragraph{Velocity distribution}
-The velocity distribution represents the idea, that a velocity vector can be sampled for each point in space. Currently there is only one type of distribution implemented, the \textit{VelocityDistributionFromFunction}. However, in cases, where a velocity distribution is needed for a constructor but never will be used a 'null' option is also available. For the \textit{VelocityDistributionFromFunction}, the velocity is sampled from a predefined function, the \textit{VelocityDistributionFunction}. Here, two options are available, the \textit{IsotropicDistribution} and the \textit{DirectedDistribution}. Both have in common, that first an energy is sampled from an given energy distribution. However, for the \textit{DirectedDistribution} this energy is used to scale a predefined direction vector using a predefined mass. For the \textit{IsotropicDistribution} the direction of movement is sampled from an isotropic distribution and then scaled to represent the correct energy. The mass can either be derived from a given particle type, or directly given as a value.
+The velocity distribution represents the idea, that a velocity vector can be sampled for each point in space. Currently there is only one type of distribution implemented, the \textit{VelocityDistributionFromFunction}. However, in cases, where a velocity distribution is needed for a constructor but never will be used a `null' option is also available. For the \textit{VelocityDistributionFromFunction}, the velocity is sampled from a predefined function, the \textit{VelocityDistributionFunction}. Here, two options are available, the \textit{IsotropicDistribution} and the \textit{DirectedDistribution}. Both have in common, that first an energy is sampled from an given energy distribution. However, for the \textit{DirectedDistribution} this energy is used to scale a predefined direction vector using a predefined mass. For the \textit{IsotropicDistribution} the direction of movement is sampled from an isotropic distribution and then scaled to represent the correct energy. The mass can either be derived from a given particle type, or directly given as a \changed{numerical} value.
There are three different energy distributions available in the code, the electron energy distribution of tritium decay (\textit{TritiumBetaDecay}), the Maxwell Boltzmann distribution (\textit{MaxwellBoltzmann}) and a constant distribution (\textit{Constant}).
\begin{itemize}
diff --git a/docs/paper/the-karl-code/referee_report_2.md b/docs/paper/the-karl-code/referee_report_2.md
index 9024b1b..e763fdb 100644
--- a/docs/paper/the-karl-code/referee_report_2.md
+++ b/docs/paper/the-karl-code/referee_report_2.md
@@ -104,7 +104,7 @@ Excitation: C, F: same comment as above.
Page 16: C, F:
Line 15: Shouldn't the ionization energy threshold be applied in the center of mass frame? Text suggests it is in the lab frame. Please also give plots of cross sections etc.
-Page 17: C, F: "the fastest axis refers to the axis for which the entry can be accessed the quickest". This note doesn't make sense to me; my understanding is that to access a 4D array you give 4 coordinates A[j,k,l,m]. Please clarify in what sense any axis is quicker than any other.
+Page 17: C, F: "the fastest axis refers to the axis for which the entry can be accessed the quickest". This note doesn't make sense to me; my understanding is that to access a 4D array you give 4 coordinates A[j,k,l,m]. Please clarify in what sense any axis is quicker than any other. Added sentence about it being an effect of caching.
On this page the text is quite verbose with some things being repeated in multiple sentences. I recommend to edit and condense this section.
Page 18: F, C: