From 11523e625b26386c0d4e366197b864d81e827069 Mon Sep 17 00:00:00 2001 From: Felix Spanier Date: Thu, 23 Jan 2025 18:26:52 +0100 Subject: [PATCH] KARL code: Added Boris push description --- docs/paper/the-karl-code/paper.tex | 36 ++++++++++++++++++-- docs/paper/the-karl-code/referee_report_2.md | 18 +++++----- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/docs/paper/the-karl-code/paper.tex b/docs/paper/the-karl-code/paper.tex index e751bb4..b35ea1b 100755 --- a/docs/paper/the-karl-code/paper.tex +++ b/docs/paper/the-karl-code/paper.tex @@ -283,7 +283,7 @@ The tracked specie class is composed of different classes, providing access to t \label{ssec:movement} The movement of particles is outsourced to the mover class. It moves the particle dependent on the E/B fields at \changed{its} position, 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}. -\changed{In this case} no interaction will be performed , but a new distance will be drawn from the MFP at the new position of the particle, \changed{according to} 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. +\changed{In this case} no interaction will be performed , but a new distance will be drawn from the MFP at the new position of the particle, \changed{according to} 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 \changed{a higher resolution than the scale length of 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. @@ -291,7 +291,39 @@ Two different kinds of movers are implemented (Boris, drift), which differ in th \paragraph{Boris mover} -The Boris mover uses the Boris push algorithm \citep{Penn.2003} for the movement step described in the previous paragraph (see \citep{Kellerer2022_1000143868} for a in depth description of the Boris push algorithm). However, the steps are not chosen by a given length but a given timestep $\Delta t$, which is needed as an input for the Boris push algorithm. The moved distance is calculated after the movement \changed{step}. This distance is then subtracted from the total distance the particle has still to move. When this distance is smaller than zero the movement will be ended. +The Boris mover uses the Boris push algorithm \citep{Penn.2003}. It solves the coupled differential equations +\begin{align} + \frac{x_{i+1} - x_i}{\Delta t} &= v_{i+1/2} \comma \\ + m \frac{v_{i+1/2} - v_{i-1/2}}{\Delta t} &= F(v_i) \comma +\end{align} +where the index $i$ denotes the timestep at which the value is available. $F$ is the force acting on the particle, in this case the Lorentz force. The position update is straight forward and does not need any more explanation. The velocity update is more complicated, because the force on the particle is dependent on the velocity of the particle. By assuming that the velocity between two timesteps can be calculated as the mean of the values, it can be formulated that the velocity of the next timestep must read +\begin{align} + \vec{v}_{i+1/2} &= \vec{v}_{i-1/2} + \frac{q \Delta t}{m} \cdot \left(\vec{E}_i + \frac{\vec{v}_{i+1/2} + \vec{v}_{i-1/2}}{2 c} \times \vec{B}_t \right) \fullstop +\end{align} + + +The change of the velocity vector is calculated in three steps. First, the particle is accelerated by half a timestep through the electric field + \begin{equation} + \vec{v}^- = \vec{v}_{i-1/2} + \frac{q \Delta t}{2 m} \vec{E}_{i-1/2} \fullstop + \label{eq:boris_push_start} + \end{equation} + Secondly, the particle is accelerated by the magnetic field. This can be described through + \begin{eqnarray} + \vec{\Omega} = \frac{q \Delta t}{2 m c} \vec{B}_i \comma \\ + \vec{t} = \frac{2 \vec{\Omega}}{1 + \vec{\Omega} \cdot \vec{\Omega}} \comma \\ + \vec{v}^\prime = \vec{v}^- + \vec{v}^- \times \vec{\Omega} \\ + \vec{v}^+ = \vec{v}^- + \vec{v}^\prime \times \vec{t} \fullstop + \end{eqnarray} + Thirdly, the particle is accelerated again by half a timestep through the electric field + \begin{equation} + \vec{v}_{i+1/2} = \vec{v}^+ + \frac{q \Delta t}{2 m} \vec{E}_{i-1/2} \fullstop + \label{eq:boris_push_end} + \end{equation} +In total, the new velocity was derived from the mass and charge of the particle and the extrapolated electromagnetic field values. + +%for the movement step described in the previous paragraph (see \citep{Kellerer2022_1000143868} for a in depth description of the Boris push algorithm). + +However, the steps are not chosen by a given length but a given timestep $\Delta t$, which is needed as an input for the Boris push algorithm. The moved distance is calculated after the movement \changed{step}. This distance is then subtracted from the total distance the particle has still to move. When this distance is smaller than zero the movement will be ended. The timestep has to be provided by the user. \changed{In order to resolve the gyro-motion of all particles of a species, the timestep should be chosen depending on the highest possible gyro frequency $\Omega_{g,\text{max}}$ of that specie. Thus } %It should be based on the highest gyro frequency possible in the simulation domain $\Omega_{g,\text{max}}$ and fulfil diff --git a/docs/paper/the-karl-code/referee_report_2.md b/docs/paper/the-karl-code/referee_report_2.md index 9b6d31c..4016e90 100644 --- a/docs/paper/the-karl-code/referee_report_2.md +++ b/docs/paper/the-karl-code/referee_report_2.md @@ -25,16 +25,16 @@ The paper omits much of the information that is the most interesting about this
Following the two referee reports we have made a large number of changes. While doing so we have tried to clarify the logic, avoided repetitions and focussed on the new developments. As far as we know the KARL code is the only freely available code for the simulation of tritium experiments - this is the point that makes it most interesting.
We have reduced the explaination of basic concepts to a minimum, but we believe that a minimal explaination is required for context.
-2. C, F: Almost all the "results" are referred out to Ref [7], which makes the reader wonder why it is necessary to have two papers rather than one. I would like to encourage the authors to bring the results forward into this text. I also encourage them to include the scripts that generate these as documented examples in the code repository, since these are the actual code use cases that an external user may want to recreate. - +1. Almost all the "results" are referred out to Ref [7], which makes the reader wonder why it is necessary to have two papers rather than one. I would like to encourage the authors to bring the results forward into this text. I also encourage them to include the scripts that generate these as documented examples in the code repository, since these are the actual code use cases that an external user may want to recreate. +
We have extended the "results" section and included the necessary scripts to re-run those and possibly extend them. The intention of this paper has been primarily to make the code publicly available along with documentation. We understand that the documentation effort has not been sufficient in first place, but we hope that this problem has now been remedied. -3. C, F: Barely any performance estimates are given. For the two stepper algorithms, for example, how different are the simulation results, and at what relative CPU cost? What degree of uncertainty is associated with granularity of the geometry? How many events need be simulated for a typical application in KATRIN and how long does this take? Which of the processes carry the most time cost, and can any of them be neglected for faster simulations without losing too much accuracy? +1. C, F: Barely any performance estimates are given. For the two stepper algorithms, for example, how different are the simulation results, and at what relative CPU cost? What degree of uncertainty is associated with granularity of the geometry? How many events need be simulated for a typical application in KATRIN and how long does this take? Which of the processes carry the most time cost, and can any of them be neglected for faster simulations without losing too much accuracy? -4. I took a look at the source code. There are almost no comments anywhere, in either the headers or source, and this is especially problematic when many of the functions accept an argument that is simply named "object". It seems to me it would be good practice to add comments to at least add comments to explain what each function does, what it accepts as input and gives as output. +1. I took a look at the source code. There are almost no comments anywhere, in either the headers or source, and this is especially problematic when many of the functions accept an argument that is simply named "object". It seems to me it would be good practice to add comments to at least add comments to explain what each function does, what it accepts as input and gives as output.
We have written extensive comments for the source code. Our main objective was to make the functions readable, some of the inner workings are not that well documented. -5. C, F: There are some example scripts given in the codebase, but they are not referenced in the paper, do not come with documentation, and it is not clear what they do in terms of expected input, processing and output. Somewhere it should be made clear how one should run these examples, what they do, and what the expected output is. Furthermore, the examples should contain at least some semi-realistic use cases of the code for addressing relevant physics questions for tritium experiments. +1. C, F: There are some example scripts given in the codebase, but they are not referenced in the paper, do not come with documentation, and it is not clear what they do in terms of expected input, processing and output. Somewhere it should be made clear how one should run these examples, what they do, and what the expected output is. Furthermore, the examples should contain at least some semi-realistic use cases of the code for addressing relevant physics questions for tritium experiments.
We have added a section to the README in karl that explains a bit what the different given json files are. A semi-realistic use case is always included with katrin_parameter_example.json. I now proceed to give some line-by-line comments - @@ -63,7 +63,7 @@ Line 13: "High resolution" -> resolution in what quantity? What does high Line 24: mention the mean free path used to sample a poisson process (as written it suggests a fixed distance step)
The equation for the mean free path is given right after this text. -Line 28: C: "density is proportional to cumulated time" - presumably it depends not only on the time but also on the flux into the segment and also the volume of the segment? How large are the segments? Is there variability of density across those segments? text changes necessary? Stuff is explaned in the non-introduction part Sag was dazu! +Line 28: > "density is proportional to cumulated time" - presumably it depends not only on the time but also on the flux into the segment and also the volume of the segment? How large are the segments? Is there variability of density across those segments?
It is of course completely valid to calculate the time integral of the in- and outflux at the boundaries which would give the density inside the boundaries via the continuity equation. We use an equivalent formulation: With the known number of total particles one can calculate the fraction of time spent within one specific part of the simulation volume. The time fraction is then translated into a density fraction. This is explained later in the paper in more detail. The formulation of course only yields an average density. Line 31: "likeliness of recombination" → "rate of recombination"? Reworded the sentence to make the original intent clearer @@ -72,11 +72,11 @@ Page 5: Line 21: mean free path has been used earlier, introduce the acronym then.
Done Page 9: -C: "Additionally, the particle class only accepts…" → the relevance of this comment is not clear to me. What would be the alternative?
removed that sentence +C: "Additionally, the particle class only accepts…" → the relevance of this comment is not clear to me. What would be the alternative?
The sentence has been removed. -Page 10: F: "The density fields need a higher resolution than the density difference". Why? Can you be quantitative about the scale of error introduced with some different resolutions? Perhaps a plot showing the accuracy for a few choices? +Page 10: F: "The density fields need a higher resolution than the density difference". Why? Can you be quantitative about the scale of error introduced with some different resolutions? Perhaps a plot showing the accuracy for a few choices?
The mean free path can only be calculated on the base of local quantities. When particles move through large density differences this may cause a problem. Our solution to the problem is to stop motion at boundaries and rolling the mfp again. The practical effect on the other hand is minimal: For all simulations the maximum distance is significantly smaller anyway. -Page 11-12: F: It reads oddly that the drift mover is treated in so much more analytical detail than the Boris one. I suggest to balance these better, ideally increasing the level of description of the Boris approach to match the drift one. I would also like to see some performance comparisons of these two options, in terms of simulation time and performance. Some general discussion is given as to why the user may choose one or other, but an evaluation of how well they work in some realistic test cases seems relevant here. +Page 11-12: F: It reads oddly that the drift mover is treated in so much more analytical detail than the Boris one. I suggest to balance these better, ideally increasing the level of description of the Boris approach to match the drift one. I would also like to see some performance comparisons of these two options, in terms of simulation time and performance. Some general discussion is given as to why the user may choose one or other, but an evaluation of how well they work in some realistic test cases seems relevant here.
Being very familiar with the Boris push we felt that the drift mover needed more attention. This decision was obviously too biased. It has been corrected now. Page 13: I see that trapped particles are killed by the simulation. But doesnt this invalidate the density field calculation, since trapped particles should have a very long retention time and hence contribute a lot to the density? Do trapped particles also
You are essentially correct: Dumping particles could invalidate the density fields. This is a somewhat delicate choice of the max interaction counter. We have added some plots showing which max interaction numbers yield correct density fields.