diff --git a/docs/paper/the-karl-code/figures/density_doubly_double_scattering.pdf b/docs/paper/the-karl-code/figures/density_doubly_double_scattering.pdf index a786d00..7e8fbb8 100644 Binary files a/docs/paper/the-karl-code/figures/density_doubly_double_scattering.pdf and b/docs/paper/the-karl-code/figures/density_doubly_double_scattering.pdf differ diff --git a/docs/paper/the-karl-code/figures/density_singly_scattered_double_scattering.pdf b/docs/paper/the-karl-code/figures/density_singly_scattered_double_scattering.pdf index e04df1b..70182eb 100644 Binary files a/docs/paper/the-karl-code/figures/density_singly_scattered_double_scattering.pdf and b/docs/paper/the-karl-code/figures/density_singly_scattered_double_scattering.pdf differ diff --git a/docs/paper/the-karl-code/figures/density_unscattered_double_scattering.pdf b/docs/paper/the-karl-code/figures/density_unscattered_double_scattering.pdf index 29f70e0..8eea5af 100644 Binary files a/docs/paper/the-karl-code/figures/density_unscattered_double_scattering.pdf and b/docs/paper/the-karl-code/figures/density_unscattered_double_scattering.pdf differ diff --git a/docs/paper/the-karl-code/paper.tex b/docs/paper/the-karl-code/paper.tex index c1d6d58..e6aeb55 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 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.\\ +\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. } @@ -171,13 +171,13 @@ Two different methods of descriptions seem obvious: a description through the te \section{Description of the method} \label{sec:method} - -\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 decay events are successively processed. Meaning that each decay particle is followed until its destruction, during which it might produce new, secondary particles. All primary and secondary particles are processed until termination before new decay particles are added. -The initial energy spectrum for electrons created by the 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, user-specified interactions. +\changed{In the KARL code, particles are tracked from interaction to interaction. The distance between the interactions is determined from the mean free path. The performed interaction is then drawn from a user-specified list of possible interactions. During the simulation new particles are created either through beta decay or through interaction between particles. All particles are put into a list, from where they are processed until they terminate. In case the list is empty new decay particles are created and inserted. The energy distribution of electrons created by the decay process is relatively simple to describe, since 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 decay events are successively processed. Meaning that each decay particle is followed until its destruction, during which it might produce new, secondary particles. All primary and secondary particles are processed until termination before new decay particles are added. +%The initial energy spectrum for electrons created by the 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, user-specified interactions. %Through these interactions decay particles 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''. -Newly generated particles are put into a list that is processed after the incident particle reaches the end of its lifetime.} +%Newly generated particles are put into a list that is processed after the incident particle reaches the end of its lifetime.} \changed{Apart from the decay process new particles are created mainly through electron impact ionization.} \changed{Ionization produces two indistinguishable electrons with energies between \SI{0}{eV} and the impact energy subtracted by the ionization energy.} @@ -205,7 +205,7 @@ For each movement step, the mean free path $\lambda_\text{mfp}$ of the correspon \label{eq:mean_free_path} \lambda_\text{mfp} = \frac{1}{\sum_i \sigma_i(E) n_i} \commaeq \end{equation} -where $E$ is the kinetic energy of the particle in the \changed{center of mass} frame, $\sigma_i$ is the cross section of a specific interaction, and $n_i$ the particle number density of the target. \changed{All three of these quantities are with respect to the interaction partner of the i-th interaction.} In the lab frame, the neutral gas has a non-zero drift velocity. The cross sections are evaluated from predefined functions. \changed{The particle number density is either calculated during the simulation for particle species that are simulated or through user input at the beginning of the simulation for particle species that act as a constant background population}. +where $E$ is the kinetic energy of the particle in the \changed{center of mass} frame, $\sigma_i$ is the cross section of a specific interaction, and $n_i$ the particle number density of the target. \changed{All three of these quantities are with respect to the interaction partner of the i-th interaction.} In the lab frame, the neutral gas has a non-zero drift velocity. The cross sections are evaluated from predefined functions. \changed{The particle number density is either calculated during the simulation for particle species that are tracked or through user input at the beginning of the simulation for particle species that act as a background population}. %The particle number density of the interaction partner is calculated either from a predefined function for background species, or from the density field for tracked species, see section~\ref{ssec:denstiy_fields} and \ref{sec:implementation} for more information. The actual moved distance $d$ is a statistical quantity, which \changed{is} derived from the MFP through \changed{ @@ -222,8 +222,8 @@ where $\eta \in (0, 1]$ is an uniform random number. The particle is then moved by this distance $d$ \changed{taking} the electromagnetic fields inside the source \changed{into consideration}. %, 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 \changed{then} 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. +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 \changed{then} performed and the interaction products, \changed{not including the incident 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. \changed{The details of the implementation of the described components are described later in section~\ref{sec:implementation}.} @@ -238,14 +238,14 @@ If the particle is still alive, a random interaction is selected from the list o \subsection{Density fields} \label{ssec:denstiy_fields} -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 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 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 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 in the selection of the interaction type. 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 segments, labeled 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} \end{equation} -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 +where $t_\text{sim}$ is called the simulated time \citep{Kellerer_2022}. It describes the simulated physical time that has passed 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} @@ -377,10 +377,10 @@ Using the requirement $d_\text{Drift} < d_\text{Boris}$ and the formula for the \label{eq:magneticField_req_boris} B_\text{max} < \frac{v_{typ} m}{q d_\text{Drift}} \commaeq \end{equation} -as a threshold for the magnetic field for which the Boris mover outperforms the Drift mover. For electrons originating from a beta decay (approximately \SI{20}{\kilo eV}) and $d_\text{Drift} = \SI{1}{\mm}$ this leads to a value of $B_\text{max} \approx \SI{470}{\milli\tesla}$. For a thermal population of T$_2^+$ at \SI{80}{\kelvin} with the same value for $d_\text{Drift}$ the value is $B_\text{max} \approx \SI{21}{\milli\tesla}$, and for thermal electrons the value is even lower. However, the timestep also needs to consider the same restrictions as the choice of $d_\text{Drift}$, meaning that the timestep also has to be chosen such that no segments are skipped during one movement step. This in turn means that the Drift and Boris mover have at best the same computational effort, even at low magnetic fields.\\ +as a threshold for the magnetic field for which the Boris mover outperforms the Drift mover. For electrons originating from a beta decay (approximately \SI{20}{\kilo eV}) and $d_\text{Drift} = \SI{1}{\mm}$ this leads to a value of $B_\text{max} \approx \SI{470}{\milli\tesla}$. For a thermal population of T$_2^+$ at \SI{80}{\kelvin} with the same value for $d_\text{Drift}$ the value is $B_\text{max} \approx \SI{21}{\milli\tesla}$, and for thermal electrons the value is even lower. However, the timestep also needs to consider the same restrictions as the choice of $d_\text{Drift}$, meaning that the timestep also has to be chosen such that no segments might be skipped during one movement step. This in turn means that the Drift and Boris mover have at best the same computational effort, even at low magnetic fields.\\ If no electric fields are present and the magnetic field is uniform everywhere the above discussion is the only criterion for the choice of the mover. Therefore in this case only the Drift mover should be chosen since it is always at least as performant as the Boris one and more importantly the drift approximation becomes exact.\\ However if the magnetic field is not uniform or zero the Boris mover has to be used since the Drift mover has no support for gradients in the magnitude of the magnetic field.\\ -If the magnetic field is uniform and electric fields are present, the choice becomes more complex. For very strong magnetic fields, i.e. a slow Drift motion and a tight gyro-orbit the Drift mover is still a good approximation and also outperforms the Boris mover. In the opposite case of very weak magnetic fields, the approximation becomes bad and the Boris mover should be used instead. +If the magnetic field is uniform and electric fields are present, the choice becomes more complex. For very strong magnetic fields, i.e. a slow Drift motion and a tight gyro-orbit the Drift mover is still a good approximation and also outperforms the Boris mover. The opposite is the case for very weak magnetic fields, the approximation becomes bad and the Boris mover should be used instead. % probably write down the actual requirements for the drift approximation and maybe even cut the first discussion completely } @@ -416,7 +416,8 @@ 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 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}. @@ -441,7 +442,7 @@ During evaluation of the scattering angle, the energy bin is determined and the %Note: Somewhere the structure for input files has to be explained! -> explain in README, short desc. in text here -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.} +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, \changed{where data for the cross section was only available for low impact energies}. 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}. @@ -499,7 +500,7 @@ The charge exchange class is initiated using the cross section and the target sp \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 +The target particle can be excited if the collision energy is above the corresponding excitation 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 @@ -543,11 +544,11 @@ The cross sections and more importantly the distribution of secondary particles \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 \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 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 axes 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 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 calculation of the density also needs the physical time, see equation~\eqref{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 \changed{with} the segmentation of the density fields, but can in general be set \changed{arbitrarily}. @@ -581,7 +582,7 @@ The simplicity of the method also produces some drawbacks. First, the load on th %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.} +\changed{The graph shows the weak scaling behavior of the code, i.e. the number of events per 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 behavior 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 behavior is expected and is a common characteristic of parallelized simulations. @@ -598,7 +599,7 @@ Once the simulation is properly initialized, the linear scaling is observed for 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 the 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 \changed{an user-specified number of} CPU synchronization \changed{steps}, 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. \changed{Furthermore, the output of the different diagnostics (density field, current collector, deletion logger) can be modified to the specific use case. For each of the three fields the output interval can be set independently. The species for which the specific output should be performed and whether the latest output should be overwritten can be set individually as well.} %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. For most use cases the size of the output file is well below 1 gigabyte. +Overwriting 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. For most use cases the size of the output file is well below 1 gigabyte. \subsection{Initialization} \label{ssec:initialization} @@ -617,7 +618,9 @@ For input quantities that have a physical unit attached to them, e.g. the height 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 currently can 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 currently can only be initiated through one option, namely the \textit{ScalarFieldFunctionInZ}. As the name suggests, the return values only depend on the $z$-coordinate. +%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. \paragraph{Vector field} % Vector fields represent the idea, that for every point in space a certain three dimensional vector can be assigned. @@ -647,7 +650,9 @@ There are three different energy distributions available in the code, the electr In the simulation section, one can set the number of simulated events over all CPU cores (\textit{SimulatedEvents}). For KATRIN these events symbolize tritium decays. The events are distributed evenly on all CPUs. The parameter \textit{EventStride} is used to define the number of events per CPU after which the density field data is synchronized between the CPUs. %Also, output could be performed here. \paragraph{Output} -In the output section, it is defined, where the output file is stored and with which filename. The folder is given relative to the home folder of the user or can be given as an absolute path. Additionally, the output specifics are defined in this section for each of the simulation data, density fields, current borders and deletion logger. +In the output section, it is defined, where the output file is stored and with which filename. +\changed{The folder is interpreted relative to the directory the code has been called from.} %The folder is given relative to the home folder of the user or can be given as an absolute path. +Additionally, the output specifics are defined in this section for each of the simulation data: density fields, current borders and deletion logger. \begin{itemize} \item \textit{Interval}: Defines how often an output should occur \changed{relative to the CPU synchronization step. The value can either be set to \textit{EachSync} or a positive integer value}. %This can either be set to \textit{EachSync}, so each time the CPUs are synced the output is performed, or to a positive integer value. %This value specifies the rate of output. @@ -666,7 +671,7 @@ In the species section, all relevant information on the species used in the simu \subsection{Particle queue} \label{ssec:particle_queue} -The queue used in the simulation to keep track of the simulated particles is no queue in the classical sense. Similar to a classical queue, particles are added to the end of the queue, when they are created through injection or by interactions like ionization. However, the next particle to simulate after the old one was deleted is not drawn from the bottom of the queue but at random from all particles in the queue. This decision was made, because the single events can be dependent on each other through the density fields and a bias towards injected particles should be avoided, especially because the injected particles have mostly higher energies than the others. Hence, it was decided to store the particles in a standard library vector \citep{Josuttis.2012}. To save computation time, the vector is initialized with a size of 100 elements, which marks a rough estimate of an upper limit on new particle per particle loop at standard KATRIN conditions. +The queue used in the simulation to keep track of the simulated particles is no queue in the classical sense. Similar to a classical queue, particles are added to the end of the queue, when they are created through injection or by interactions like ionization. However, the next particle to simulate after the old one was deleted is not drawn from the front of the queue but at random from all particles in the queue. This decision was made, because the single events can be dependent on each other through the density fields and a bias towards injected particles should be avoided, especially because the injected particles have mostly higher energies than the others. Hence, it was decided to store the particles in a standard library vector \citep{Josuttis.2012}. To save computation time, the vector is initialized with a size of 100 elements, which marks a rough estimate of an upper limit on new particle per particle loop at standard KATRIN conditions. @@ -703,9 +708,9 @@ Figure~\ref{fig:ionization_test} shows the electron spectrum at two different $z \end{figure} \paragraph{Excitation} -\changed{The excitation process is quite similar to the ionization process, in that it requires a threshold energy of the impact particle. The main difference is that no new particles are created. Due to the assumption made on the scattering angle distribution in the excitation process (see section~\ref{ssec:interactions}), it is quite simple to formulate an analytic example if only a single interaction is possible during propagation.\\ -There is a high amount of potential excitation interactions that electrons can have with molecular tritium. However, the only major difference between these different interactions are the energy threshold $E_\text{th}$ and the cross section of the interaction. Therefore it is sufficient to only consider a single implemented excitation process in order to test the validity of the approach.\\ -In the setup of the simulations, the electrons were injected at the left side of the simulation domain with a specific energy and their velocity directed with the $z$-axis. The neutral density $n_\text{b}$ is chosen to be uniformly distributed within the source starting from a position $z_\text{neutral} > 0$ in order to allow for a distance of free propagation. The value of $n_\text{b}$ is chosen to be \SI{3.21e21}{\per\cubic\m} in order to allow for an appropriate MFP. The used interaction (or rather the specific cross section) has a threshold energy $E_\text{th} = \SI{12.754}{eV}$. The injection energies considered were \SI{12}{eV}, \SI{20}{eV}, \SI{33}{eV} and \SI{500}{eV}. The first energy was chosen such as to test for the threshold energy, the second one allows for a singular interaction, the third for at most two interactions and the fourth one allows for many interactions. For each case a number of \num{8e5} particles are simulated.\\ +\changed{The excitation process is somewhat similar to the ionization process, in that it requires a threshold energy of the impact particle. The main difference is that no new particles are created. Due to the assumption made on the scattering angle distribution in the excitation process (see section~\ref{ssec:interactions}), it is quite simple to formulate an analytic example if only a single interaction is possible during propagation.\\ +There is a high amount of potential excitation interactions that electrons can have with molecular tritium. However, the only difference between these interactions are the energy threshold $E_\text{th}$ and the cross section of the interaction. Therefore it is sufficient to only consider a single implemented excitation process in order to test the validity of the approach.\\ +In the setup of the simulations, the electrons were injected at the left side of the simulation domain with a specific energy and their velocity aligned with the $z$-axis. The neutral density $n_\text{n}$ is chosen to be uniformly distributed within the source starting from a position $z_\text{neutral} > 0$ in order to allow for a distance of free propagation. The value of $n_\text{n}$ is chosen to be \SI{3.21e21}{\per\cubic\m} in order to allow for an appropriate MFP. The used interaction (or rather the specific cross section) has a threshold energy $E_\text{th} = \SI{12.754}{eV}$. The injection energies considered were \SI{12}{eV}, \SI{20}{eV}, \SI{33}{eV} and \SI{500}{eV}. The first energy was chosen such as to test for the threshold energy, the second one allows for a singular interaction, the third for at most two interactions and the fourth one allows for many interactions. For each case a number of \num{8e5} particles are simulated.\\ The density of the injected particles $n_u$ is expected to follow an exponential distribution, depending on the mean free path of the interaction \begin{equation} \label{eq:density_injected} @@ -725,7 +730,7 @@ n_s = \left(1-\exp\left(-\frac{z - z_\text{neutral}}{\lambda_\text{mfp}(E_\text{ Adding $n_u$ and $n_s$ yields the expected density profile.\\ In case the impact energy allows for at most two excitation events to be performed, the density for the twice scattered electrons $n_{s,2}$ can be calculated as well. In order to do so, one just has to calculate the probability $p(z)$ for a single particle to scatter twice within the length $z$: \begin{equation} -p(z) = \int_0^z d\,x \int_0^{z-x} d\,y p_1(x) p_2(y) \commaeq +p(z) = \int_0^z dx \int_0^{z-x} dy p_1(x) p_2(y) \commaeq \end{equation} where $p_1(x)$ is the probability for a particle to scatter after a distance $x$ and $p_2(y)$ is the same at the new energy after the first scattering. Since the distribution of distances follows an exponential distribution, this leads to \begin{equation} @@ -740,8 +745,8 @@ n_{s,2} &= n_0 \sqrt{\frac{E}{E - 2E_{th}}} \left[1-\left(1 - \frac{\lambda_2}{\ \end{equation} For the case that both $\lambda_1$ and $\lambda_2$ have the same value the expressions change but can be derived the same way. \\ -Similar calculations can be done for the case of a maximum of two interactions, but for higher interaction counts this becomes increasingly more difficult. Therefore only the case for a single scattering are shown in Figure~\ref{fig:excitation_test_densities}. In this plot the \SI{12}{eV} is also shown to indicate the value of $n_0$. Furthermore, the density for the \SI{20}{eV} case has been scaled such that it fits to $n_0$ in the non-interaction region. It can be seen that the data fits the expectation very well, with the relative error being below 0.5\% everywhere. In Figures~\ref{fig:excitation_double_scattering_unscattered}, -\ref{fig:excitation_double_scattering_singly} and \ref{fig:excitation_doubly_scattering_doubly} the densities for the electrons that have scattered a different amount of time is shown. While the unscattered electrons follow the expectation quite well, the singly and doubly scattered electrons deviate somewhat from the expectation. This might be due to differences in the calculated cross section with the one calculated in the code. In Figure~\ref{fig:excitation_spectrum_500eV} the energy spectrum for an injection energy of $E_\text{inj} = \SI{500}{eV}$ is shown. Overall, it can be seen that the length of the simulation domain is not large enough for any electron to scatter down to below the threshold energy. However a shift in the energy with the maximal density can be seen, as would be expected. +For higher interaction counts this becomes increasingly more difficult to formulate an expectation. Therefore only the case for a single scattering are shown in Figure~\ref{fig:excitation_test_densities}. In this plot the \SI{12}{eV} is also shown to indicate the value of $n_0$. Furthermore, the density for the \SI{20}{eV} case has been scaled such that it fits to $n_0$ in the non-interaction region. It can be seen that the data fits the expectation very well, with the relative error being below 0.5\% everywhere. In Figures~\ref{fig:excitation_double_scattering_unscattered}, +\ref{fig:excitation_double_scattering_singly} and \ref{fig:excitation_doubly_scattering_doubly} the densities for the electrons that have scattered a zero, once and twice are shown respectively for the case of a maximum of two interactions. While the unscattered electrons follow the expectation quite well, the singly and doubly scattered electrons deviate somewhat from the expectation. This might be due to differences in the calculated cross section with the one calculated in the code. In Figure~\ref{fig:excitation_spectrum_500eV} the energy spectrum for an injection energy of $E_\text{inj} = \SI{500}{eV}$ is shown. Overall, it can be seen that the length of the simulation domain is not large enough for any electron to scatter down to below the threshold energy. However a shift in the energy with the maximal density can be seen, as would be expected. } \begin{figure} @@ -802,7 +807,7 @@ and \label{eq:clustering_test_radiative_cross} \lambda_{\text{mfp,rad}} = \frac{1}{\sigma n_{\text{T}^2}} \fullstop \end{equation} -All three cases were simulated using the same setup. The ions were injected on the left side of the simulation domain with an energy of \SI{6.8}{\milli eV} and a direction in positive $z$-direction. The neutral gas was chosen to be uniformly distributed in the simulation domain. A number of 80000 events were chosen to be simulated. Furthermore a strong magnetic field of \SI{2.5}{\tesla} was applied. The difference between the simulations is solely the density of the neutral gas due to the different magnitudes of the MFP. Therefore a density of \SI{1e18}{\per\cubic\m} has been chosen for the reaction T$_2^+$ + T$_2$. The cross section for this reaction has a value of $\sigma = \SI{1.91e-18}{\square\m}$. For the tertiary process a density of \SI{1e22}{\per\cubic\m} was chosen. The value of the rate coefficient at \SI{80}{\kelvin} is $ k_\text{ter} = \SI{2.6e-41}{\m\tothe{6}\per\second}$. And lastly for the radiative process of T$^+$ a density of \SI{2e25}{\per\cubic\m} has been chosen with a radiative association rate coefficient of $k_\text{rad} = \SI{5e-23}{\cubic\m\per\s}$ at \SI{80}{\kelvin}.\\ +All three cases were tested using the same setup. The ions were injected on the left side of the simulation domain with an energy of \SI{6.8}{\milli eV} and a direction in positive $z$-direction. The neutral gas was chosen to be uniformly distributed in the simulation domain. A number of \num{8e4} events were chosen to be simulated. Furthermore a strong magnetic field of \SI{2.5}{\tesla} was applied. The difference between the simulations is solely the density of the neutral gas due to the different magnitudes of the MFP. Therefore a density of \SI{1e18}{\per\cubic\m} has been chosen for the reaction T$_2^+$ + T$_2$. The cross section for this reaction has a value of $\sigma = \SI{1.91e-18}{\square\m}$. For the tertiary process a density of \SI{1e22}{\per\cubic\m} was chosen. The value of the rate coefficient at \SI{80}{\kelvin} is $ k_\text{ter} = \SI{2.6e-41}{\m\tothe{6}\per\second}$. And lastly for the radiative process of T$^+$ a density of \SI{2e25}{\per\cubic\m} has been chosen with a radiative association rate coefficient of $k_\text{rad} = \SI{5e-23}{\cubic\m\per\s}$ at \SI{80}{\kelvin}.\\ The results of the tree simulations together with the expected result are shown in Figures~\ref{fig:clustering_tp_ter}, \ref{fig:clustering_tp_rad} and \ref{fig:clustering_t2p}.\\ As can be seen the expectation and the results fit quite well, only showing some deviation in the low density region due to statistical noise. The values for the rate coefficients and cross section were also inferred and have shown a deviation below 1\% for all three cases.} @@ -830,7 +835,7 @@ As can be seen the expectation and the results fit quite well, only showing some \paragraph{Charge Exchange} \changed{The expectation for charge exchange is quite similar as for the case of elastic scattering, namely that the initial population adopts the energy distribution of the background population. The difference being that only one scattering event per particle is needed to thermalize.\\ For the simulation monoenergetic T$_2^+$ ions are injected from the left side of the simulation domain with an energy of \SI{10}{eV} and a velocity direction pointing in positive $z$-direction. The neutral density has been set to \SI{1.224e19}{\per\cubic\m} to allow for a short MFP with a temperature of \SI{80}{\kelvin}.\\ -The energy spectrum for the ions is shown in Figure~\ref{fig:charge_exchange} close to the right side of the simulation domain at $z = \SI{1.44}{\m}$. A peak at \SI{10}{eV} can also be seen, due to unscattered particles. Furthermore, the Maxwell Boltzmann distribution is not well met. This is however an effect of a non-constant cross section. From the cross section shown in Figure~\ref{fig:t2p_interactions} it becomes apparent that lower energetic ions have a higher likelihood to interact and therefore spending a lower amount of time with their current energy than a particle with a higher energy. Assuming the time to scale inversely with the probability of performing an interaction leads to an additional factor in the Maxwell Boltzmann distribution of $1/\sigma(E)$. This scaled version is also shown in the plot of the results and it is evident that this expectation is met quite well confirming the above discussion. +The energy spectrum for the ions is shown in Figure~\ref{fig:charge_exchange} close to the right side of the simulation domain at $z = \SI{1.44}{\m}$. A peak at \SI{10}{eV} can also be seen, due to unscattered particles. Furthermore, the Maxwell Boltzmann distribution is not well met. This is however an effect of a non-constant cross section. From the cross section shown in Figure~\ref{fig:t2p_interactions} it becomes apparent that lower energetic ions have a higher likelihood to interact and therefore spending a lower amount of time at their current energy than a particle with a higher energy before scattering. Assuming the time to scale inversely with the probability of performing an interaction leads to an additional factor in the Maxwell Boltzmann distribution of $1/\sigma(E)$. This scaled version is also shown in the plot of the results and it is evident that this expectation is met quite well confirming the above discussion. } \begin{figure} \centering @@ -840,21 +845,21 @@ The energy spectrum for the ions is shown in Figure~\ref{fig:charge_exchange} cl \end{figure} \paragraph{Recombination} -\changed{In order to test recombination there are two parts that were tested separately. First recombination was tested for both interaction partners against a fixed background density to retrieve the cross section and check if the simple expected exponential profile are retrieved correctly. Second, recombination with both interaction partners being fully variable was simulated. For this case it is not as simple to formulate an expectation for the density profiles in relation to the spatial coordinates. However, it is possible to set the densities of both interaction partners into relation. Therefore one starts with a simple advection equation with a sink term that couples the two interaction partners +\changed{In order to test recombination there are two parts that were tested separately. First recombination was tested for both interaction partners against a fixed background density to retrieve the cross section and check if the simple expected exponential profile is retrieved correctly. Second, recombination with both interaction partners being fully variable was simulated. For this case it is not as simple to formulate an expectation for the density profiles in relation to the spatial coordinates. However, it is possible to set the densities of both interaction partners into relation. Therefore one starts with a simple advection equation with a sink term that couples the two interaction partners \begin{equation} \begin{split} -\partial_t n_e &= v_e\partial_z n_e + \sigma(E_e)n_en_iv_e\\ -\partial_t n_i &=v_i\partial_z n_i + \sigma(E_i)n_en_iv_e \fullstop \end{split} \end{equation} -Since only the equilibrium is of interest, the time derivative will vanish. This lead to +Since only the equilibrium is of interest, the time derivative will vanish. This leads to \begin{equation} \label{eq:ne_nt2p} n_e = \frac{\sigma(E_e)}{\sigma(E_i)}n_i + c \commaeq \end{equation} where $c$ is an integration constant. Ideally the fraction of the cross sections is one. However due to different simplifications taken in the code to speed up calculation of the cross section for both the electron and ion species this is not the case, but it is nonetheless close to one.\\ -The three test case simulations all share the same setup. The electrons and ions are both injected from the left side of the simulation domain and propagate to the right. The ion energy was set to \SI{0.1}{eV} and the electron energy to \SI{9.1e-6}{eV} in order to achieve a similar density in the absence of any interaction. In total a number of 80000 events were simulated.\\ -The densities and their corresponding expectations are shown in Figures~\ref{fig:recombination_e_only} and \ref{fig:recombination_t2p_only}. It can be seen that fit quite well and only small statistical uncertainty. From the simulation results the cross sections can be inferred as well. These deviate less than 2\% for both cases from the expected values.\\ +The three test case simulations all share the same setup. The electrons and ions are both injected from the left side of the simulation domain and propagate to the right. The ion energy was set to \SI{0.1}{eV} and the electron energy to \SI{9.1e-6}{eV} in order to achieve a similar density in the absence of any interaction. In total a number of \num{8e4} events were simulated.\\ +The densities and their corresponding expectations are shown in Figures~\ref{fig:recombination_e_only} and \ref{fig:recombination_t2p_only}. It can be seen that fit quite well with only small statistical uncertainty. From the simulation results the cross sections can be inferred as well. These deviate less than 2\% for both cases from the expected values.\\ The dependence of the electron density on the ion density are shown in Figure~\ref{fig:recombination_ne_nt2p}. Both the ideal slope and the expected slope as defined in equation~\ref{eq:ne_nt2p} can be seen and it is apparent that the data points follow this relation quite well. The expected value of the slope is $\sigma_e/\sigma_{\text{T}_2^+} = 0.973$. } \begin{figure} @@ -879,11 +884,11 @@ The dependence of the electron density on the ion density are shown in Figure~\r \end{figure} \paragraph{Maximum Interaction Count} -\changed{Removing particles form the simulation before they physically leave the domain or are lost due to an interaction introduces an error in the simulation. However, it can be a necessary process in order to make the simulation time be sensible. It is nonetheless necessary to to investigate the influence of the maximum number of interactions on the density of the simulated particles.\\ +\changed{Removing particles form the simulation before they physically leave the domain or are lost due to an interaction introduces an error in the simulation. However, it can be a necessary process in order to make the simulation time be sensible. It is nonetheless necessary to investigate the influence of the maximum number of interactions on the density of the simulated particles.\\ It is obvious that the optimal number of maximum interactions depends on multiple factors, i.e. the electric and magnetic background fields as well as the mean free path of the particle. Since the presence of electromagnetic fields that cause the trapping of a particle is relatively unlikely to occur on their own, the neutral density will have the major impact on the time a particle spends in the simulation. \\ -Therefore two sets of simulations with a different neutral density $n_n$ were performed. Apart from the number of maximum interactions and the neutral density, the remaining parameters were not changed. The simulation domain was chosen to have a radius $R = \SI{0.4}{cm}$ and a length of $L = \SI{3}{cm}$. The temperature for the background gas was chosen to be at \SI{300}{\K}. The reason being that in a small simulation domain particles terminate quicker at one of the boundary walls and thus speed up computation time a bit. For the same reason it was chosen to not use a magnetic field. All implementations interactions were enabled during the simulation. The two chosen neutral density values are \SI{2.41e24}{\per\cubic\m} and \SI{2.41e22}{\per\cubic\m}.\\ %mention total simulated particles for each value and how the points are calculated and the density distribution of the neutral gas -Figure~\ref{fig:maxInteractions_vs_density_2e24} shows the density and the fraction of particles that are deleted due to reaching their maximum number of interactions for the \SI{2.41e24}{\per\cubic\m} case. It can be seen that for the T$_2^+$ population a maximum interaction count of about 10 would suffice for all particles to terminate before reaching that limit. This is due to the high clustering cross section with the background gas. Both for T$^+$ and T$_2^+$ the densities converge relatively quickly, i.e. within a limit of \num{1e3} interactions. Some fluctuation is still visible afterwards but that is likely due to more electrons being able to ionize and thus creating more of these species. For both T$_3^+$ and e$^-$ the simulated limit of \num{1e5} maximum interactions is to low for the density to have converged or the fraction of particles that are deleted due to the interaction restriction to have reached zero. This effect is especially pronounced for the T$_3^+$ population due to the high interaction probability at thermal energies. \\ -Figure~\ref{fig:maxInteractions_vs_density_2e22} shows the same plot as before but now with the second, lower density. The main difference are that this time all densities converge and that it takes longer for T$^+$ to reach convergence. This is due to the reduced cross section for clustering, which increases the effect of interactions in which the ion is not destroyed. For this case a maximum interaction count of \num{1e5} would be sufficient to capture the correct densities.} +Therefore two sets of simulations with a different neutral density $n_n$ were performed. Apart from the number of maximum interactions and the neutral density, the remaining parameters were not changed. The simulation domain was chosen to have a radius $R = \SI{0.4}{cm}$ and a length of $L = \SI{3}{cm}$. The temperature for the background gas was chosen to be at \SI{300}{\K}. The reason being that in a small simulation domain particles terminate quicker at one of the boundary walls and thus speed up computation time a bit. For the same reason it was chosen to not use a magnetic field. All implemented interactions were enabled during the simulation. The two chosen neutral density values are \SI{2.41e24}{\per\cubic\m} and \SI{2.41e22}{\per\cubic\m}.\\ %mention total simulated particles for each value and how the points are calculated and the density distribution of the neutral gas +Figure~\ref{fig:maxInteractions_vs_density_2e24} shows the density and the fraction of particles that are deleted due to reaching their maximum number of interactions for the \SI{2.41e24}{\per\cubic\m} case. It can be seen that for the T$_2^+$ population a maximum interaction count of about 10 would suffice for all particles to terminate before reaching that limit. This is due to the high clustering cross section with the background gas. Both for T$^+$ and T$_2^+$ the densities converge relatively quickly, i.e. within a limit of \num{1e3} interactions. Some fluctuation is still visible afterwards but that is likely due to more electrons being able to ionize and thus creating more of these species. For both T$_3^+$ and e$^-$ the simulated limit of \num{1e5} maximum interactions is too low for the density to have converged or the fraction of particles that are deleted due to the interaction restriction to have reached zero. This effect is especially pronounced for the T$_3^+$ population due to the high elastic scattering probability at thermal energies. \\ +Figure~\ref{fig:maxInteractions_vs_density_2e22} shows the same plot as before but now with the second, lower density. The main differences are that this time all densities converge and that it takes longer for T$^+$ to reach convergence. This is due to the reduced cross section for clustering, which increases the effect of interactions in which the ion is not destroyed. For this case a maximum interaction count of \num{1e5} would be sufficient to capture the correct densities.} \begin{figure}