Fix some small things

This commit is contained in:
Cory Balaton 2023-10-16 20:58:50 +02:00
parent 03344c3298
commit f29424f96e
No known key found for this signature in database
GPG Key ID: 3E5FCEBFD80F432B
2 changed files with 92 additions and 42 deletions

Binary file not shown.

View File

@ -6,6 +6,41 @@
\section{Methods} \section{Methods}
\subsection{Units and constants}
Before continuing, we need to define the units we'll be working with.
Since we are working with particles, we need small units to work with so the
numbers we are working with aren't so small that they could potentially lead
to large round-off errors in our simulation. The units that we will use are listed in Table~\ref{tab:units}.
\begin{table}[H]
\begin{center}
\begin{tabular}[c]{lll}
Dimension & Unit & Symbol \\
\hline
Length & micrometer & $\mu m$ \\
Time & microseconds & $\mu s$ \\
Mass & atomic mass unit & $u$ \\
Charge & the elementary charge & $e$ \\
\hline
\end{tabular}
\end{center}
\caption{The set of units we'll be working with.}\label{tab:units}
\end{table}
With these base units, we get
\begin{equation}
k_e = 1.3893533 \cdot 10^5 \frac{u(\mu m)^3}{(\mu s)^2 e},
\end{equation}
and we get that the unit for magnetic field strength (Tesla, $T$) and electric potential (Volt, $V$) are
\begin{equation}
\begin{split}
T &= 9.64852558 \cdot 10^1 \frac{u}{(\mu s) e} \\
V &= 9.64852558 \cdot 10^7 \frac{u (\mu m)^2}{(\mu s)^2 e}. \\
\end{split}
\label{eq:}
\end{equation}
\subsection{Dealing with a multi--particle system}
For a multi-particles system, we need to modify $\vb{F}$ to account for the For a multi-particles system, we need to modify $\vb{F}$ to account for the
force of other particles in the system acting upon each other. To do that, we force of other particles in the system acting upon each other. To do that, we
add another term to $\vb{F}$ add another term to $\vb{F}$
@ -21,7 +56,7 @@ where $i$ and $j$ are particle indices and
Newton's second law for a particle $i$ is then Newton's second law for a particle $i$ is then
\begin{equation} \begin{equation}
\frac{d^2\vb{r}_i}{dt^2} = \frac{\vb{F}\left(t, \frac{d\vb{r}_i}{dt}, \vb{r_i}\right)}{m_i}, \frac{d^2\vb{r}_i}{dt^2} = \frac{\vb{F}_i\left(t, \frac{d\vb{r}_i}{dt}, \vb{r_i}\right)}{m_i},
\label{eq:newtonlaw2} \label{eq:newtonlaw2}
\end{equation} \end{equation}
We can then rewrite the second order ODE from equation~\ref{eq:newtonlaw2} We can then rewrite the second order ODE from equation~\ref{eq:newtonlaw2}
@ -30,24 +65,23 @@ We now rewrite Newton's second law of motion as
\begin{equation} \begin{equation}
\begin{split} \begin{split}
\frac{d\vb{r}_i}{dt} &= \vb{v}_i \\ \frac{d\vb{r}_i}{dt} &= \vb{v}_i \\
\frac{d\vb{v}_i}{dt} &= \frac{\vb{F}(t, \vb{v}_i, \vb{r}_i)}{m_i}. \frac{d\vb{v}_i}{dt} &= \frac{\vb{F}_i(t, \vb{v}_i, \vb{r}_i)}{m_i}.
\end{split} \end{split}
\label{eq:coupled} \label{eq:coupled}
\end{equation} \end{equation}
\subsection{Forward Euler} \subsection{Forward Euler}
For a single particle, the forward Euler method for a coupled system is For a particle $i$, the forward Euler method for a coupled system is
expressed as expressed as
\begin{equation} \begin{equation}
\begin{split} \begin{split}
\vb{r}_{i+1} &= \vb{r}_i + h \cdot \frac{d\vb{r}_i}{dt} = \vb{r}_i + h \cdot \vb{v}_i \\ \vb{r}_{i,j+1} &= \vb{r}_{i,j} + h \cdot \frac{d\vb{r}_{i,j}}{dt} = \vb{r}_{i,j} + h \cdot \vb{v}_{i,j} \\
\vb{v}_{i+1} &= \vb{v}_i + h \cdot \frac{\vb{v}_i}{dt} = \vb{v}_i + h \cdot \frac{\vb{F}\left( t_i, \vb{v}_i, \vb{r}_i \right)}{m}, \vb{v}_{i,j+1} &= \vb{v}_{i,j} + h \cdot \frac{\vb{v}_{i,j}}{dt} = \vb{v}_{i,j} + h \cdot \frac{\vb{F}\left( t_{j}, \vb{v}_{i,j}, \vb{r}_{i,j} \right)}{m},
\end{split} \end{split}
\end{equation} \end{equation}
where $i$ is the current time step of the particle $m$ is the mass of the particle, and $h$ for particle $i$ where $j$ is the current time step of the particle,
is the time step length. $m$ is the mass of the particle, and $h$ is the step length.
When dealing with a multi-particle system, we need to ensure that we do not When dealing with a multi-particle system, we need to ensure that we do not
update the position of any particles until every particle has calculated their update the position of any particles until every particle has calculated their
@ -75,28 +109,38 @@ Algorithm~\ref{algo:forwardeuler} provides an overview on how that can be achiev
\subsection{4th order Runge-Kutta} \subsection{4th order Runge-Kutta}
For a single particle, we can express the 4th order Runge-Kutta (RK4) method as For a particle $i$, we can express the 4th order Runge-Kutta (RK4) method as
\begin{equation} \begin{equation}
\begin{split} \begin{split}
\vb{v}_{i+1} &= \vb{v}_i + \frac{h}{6} \left( \vb{k}_{\vb{v},1} \vb{v}_{i,j+1} &= \vb{v}_{i,j} + \frac{h}{6} \left( \vb{k}_{\vb{v},1,i}
+ 2\vb{k}_{\vb{v},2} + 2\vb{k}_{\vb{v},3} + \vb{k}_{\vb{v},4} + 2\vb{k}_{\vb{v},2,i} + 2\vb{k}_{\vb{v},3,i} + \vb{k}_{\vb{v},4,i}
\right) \\ \right) \\
\vb{r}_{i+1} &= \vb{r}_i + \frac{h}{6} \left( \vb{k}_{\vb{r},1} \vb{r}_{i,j+1} &= \vb{r}_{i,j} + \frac{h}{6} \left( \vb{k}_{\vb{r},1,i}
+ 2\vb{k}_{\vb{r},2} + 2\vb{k}_{\vb{r},3} + \vb{k}_{\vb{r},4} + 2\vb{k}_{\vb{r},2,i} + 2\vb{k}_{\vb{r},3,i} + \vb{k}_{\vb{r},4,i}
\right), \right),
\end{split} \end{split}
\end{equation} \end{equation}
where where
\begin{equation} \begin{equation}
\begin{split} \begin{split}
\vb{k}_{\vb{v},1} &= \frac{\vb{F}(t_i, \vb{v}_i, \vb{r}_i)}{m} \\ \vb{k}_{\vb{v},1,i} &= \frac{\vb{F}_i(t_j, \vb{v}_{i,j},
\vb{k}_{\vb{r},1} &= \vb{v}_i \\ \vb{r}_{i,j})}{m} \\
\vb{k}_{\vb{v},2} &= \frac{\vb{F}(t_i+\frac{h}{2}, \vb{v}_i + h \cdot \frac{\vb{k}_{\vb{v},1}}{2}, \vb{r}_i + h \cdot \frac{\vb{k}_{\vb{r},1}}{2})}{m} \\ \vb{k}_{\vb{r},1,i} &= \vb{v}_{i,j} \\
\vb{k}_{\vb{r},2} &= \vb{v}_i + h \cdot \frac{\vb{k}_{\vb{v},1}}{2} \\ \vb{k}_{\vb{v},2,i} &= \frac{\vb{F}_i(t_j+\frac{h}{2}, \vb{v}_{i,j}
\vb{k}_{\vb{v},3} &= \frac{\vb{F}(t_i+\frac{h}{2}, \vb{v}_i + h \cdot \frac{\vb{k}_{\vb{v},2}}{2}, \vb{r}_i + h \frac{\cdot \vb{k}_{\vb{r},2}}{2})}{m} \\ + h \cdot \frac{\vb{k}_{\vb{v},1,i}}{2}, \vb{r}_{i,j}
\vb{k}_{\vb{r},3} &= \vb{v}_i + h \cdot \frac{\vb{k}_{\vb{v},2}}{2} \\ + h \cdot \frac{\vb{k}_{\vb{r},1,i}}{2})}{m} \\
\vb{k}_{\vb{v},4} &= \frac{\vb{F}(t_i+h, \vb{v}_i + h \cdot \vb{k}_{\vb{v},3}, \vb{r}_i + h \cdot \vb{k}_{\vb{r},3})}{m} \\ \vb{k}_{\vb{r},2,i} &= \vb{v}_{i,j}
\vb{k}_{\vb{r},4} &= \vb{v}_i + h \cdot \frac{\vb{k}_{\vb{v},1}}{2}. + h \cdot \frac{\vb{k}_{\vb{v},1,i}}{2} \\
\vb{k}_{\vb{v},3,i} &= \frac{\vb{F}_i(t_j+\frac{h}{2}, \vb{v}_{i,j}
+ h \cdot \frac{\vb{k}_{\vb{v},2,i}}{2}, \vb{r}_{i,j}
+ h \frac{\cdot \vb{k}_{\vb{r},2,i}}{2})}{m} \\
\vb{k}_{\vb{r},3,i} &= \vb{v}_{i,j}
+ h \cdot \frac{\vb{k}_{\vb{v},2,i}}{2} \\
\vb{k}_{\vb{v},4,i} &= \frac{\vb{F}_i(t_j+h, \vb{v}_{i,j}
+ h \cdot \vb{k}_{\vb{v},3,i}, \vb{r}_{i,j}
+ h \cdot \vb{k}_{\vb{r},3,i})}{m} \\
\vb{k}_{\vb{r},4,i} &= \vb{v}_{i,j}
+ h \cdot \frac{\vb{k}_{\vb{v},1,i}}{2}.
\end{split} \end{split}
\end{equation} \end{equation}
@ -110,46 +154,48 @@ can update the particles correctly for each step.
This approach would require 8 loops to be able to complete the calculation since This approach would require 8 loops to be able to complete the calculation since
we cannot update the particles until after all $\vb{k}$ values have been we cannot update the particles until after all $\vb{k}$ values have been
computed, however if we create a temporary array that holds particles, we can computed, however if we create a temporary array that holds particles, we can
put the updated particles in there, and then use that array in the next loop. put the updated particles in there, and then use that array in the next loop,
around 8 separate loops to calculate all $\vb{k}$ values and would reduce the required amount of loops down to 4.
\newpage
\begin{figure} \begin{figure}
\begin{algorithm}[H] \begin{algorithm}[H]
\caption{RK4 method} \caption{RK4 method}
\label{algo:rk4} \label{algo:rk4}
\begin{algorithmic} \begin{algorithmic}
\Procedure{Evolve RK4}{$dt$} \Procedure{Evolve RK4}{$particles, dt$}
\State $N \leftarrow \text{Number of particles inside the Penning trap}$ \State $N \leftarrow \text{Number of particles inside the Penning trap}$
\State $orig\_p \leftarrow \text{Copy of particles}$ \Comment{Keep the original particles} \State $orig\_p \leftarrow \text{Copy of particles}$
\State $tmp\_p \leftarrow \text{Array of particles of size }N$ \State $tmp\_p \leftarrow \text{Array of particles of size }N$
\State $\vb{k}_{\vb{r}} \leftarrow \text{2D array of vectors of size } 4 \cross N$ \State $\vb{k}_{\vb{r}} \leftarrow \text{2D array of vectors of size } 4 \cross N$
\State $\vb{k}_{\vb{v}} \leftarrow \text{2D array of vectors of size } 4 \cross N$ \State $\vb{k}_{\vb{v}} \leftarrow \text{2D array of vectors of size } 4 \cross N$
\For{ $i = 1, 2, \ldots, N$ } \For{ $i = 1, 2, \ldots, N$ }
\State $\vb{k}_{\vb{r},1,i} \leftarrow \vb{v}$ \State $\vb{k}_{\vb{r},1,i} \leftarrow particles_i.\vb{v}$
\State $\vb{k}_{\vb{v},1,i} \leftarrow \frac{\vb{F}}{m}$ \State $\vb{k}_{\vb{v},1,i} \leftarrow \frac{\vb{F}_i}{m_i}$
\State $tmp\_p_i.\vb{r} \leftarrow orig\_p_i.\vb{r} + \frac{dt}{2} \cdot \vb{k}_{\vb{r},1,i}$ \State $tmp\_p_i.\vb{r} \leftarrow orig\_p_i.\vb{r}
\State $tmp\_p_i.\vb{v} \leftarrow orig\_p_i.\vb{v} + \frac{dt}{2} \cdot \vb{k}_{\vb{v},1,i}$ + \frac{dt}{2} \cdot \vb{k}_{\vb{r},1,i}$
\State $tmp\_p_i.\vb{v} \leftarrow orig\_p_i.\vb{v}
+ \frac{dt}{2} \cdot \vb{k}_{\vb{v},1,i}$
\EndFor \EndFor
\State $particles \leftarrow tmp\_p$ \Comment{Update particles} \State $particles \leftarrow tmp\_p$ \Comment{Update particles}
\For{ $i = 1, 2, \ldots, N$ } \For{ $i = 1, 2, \ldots, N$ }
\State $\vb{k}_{\vb{r},2,i} \leftarrow \vb{v}$ \State $\vb{k}_{\vb{r},2,i} \leftarrow particles_i.\vb{v}$
\State $\vb{k}_{\vb{v},2,i} \leftarrow \frac{\vb{F}}{m}$ \State $\vb{k}_{\vb{v},2,i} \leftarrow \frac{\vb{F}_i}{m_i}$
\State $tmp\_p_i.\vb{r} \leftarrow orig\_p_i.\vb{r} + \frac{dt}{2} \cdot \vb{k}_{\vb{r},2,i}$ \State $tmp\_p_i.\vb{r} \leftarrow orig\_p_i.\vb{r}
\State $tmp\_p_i.\vb{v} \leftarrow orig\_p_i.\vb{v} + \frac{dt}{2} \cdot \vb{k}_{\vb{v},2,i}$ + \frac{dt}{2} \cdot \vb{k}_{\vb{r},2,i}$
\State $tmp\_p_i.\vb{v} \leftarrow orig\_p_i.\vb{v}
+ \frac{dt}{2} \cdot \vb{k}_{\vb{v},2,i}$
\EndFor \EndFor
\State $particles \leftarrow tmp\_p$ \Comment{Update particles} \State $particles \leftarrow tmp\_p$ \Comment{Update particles}
\For{ $i = 1, 2, \ldots, N$ } \For{ $i = 1, 2, \ldots, N$ }
\State $\vb{k}_{\vb{r},3,i} \leftarrow \vb{v}$ \State $\vb{k}_{\vb{r},3,i} \leftarrow particles_i.\vb{v}$
\State $\vb{k}_{\vb{v},3,i} \leftarrow \frac{\vb{F}}{m}$ \State $\vb{k}_{\vb{v},3,i} \leftarrow \frac{\vb{F}_i}{m}$
\State $tmp\_p_i.\vb{r} \leftarrow orig\_p_i.\vb{r} + dt \cdot \vb{k}_{\vb{r},3,i}$ \State $tmp\_p_i.\vb{r} \leftarrow orig\_p_i.\vb{r} + dt \cdot \vb{k}_{\vb{r},3,i}$
\State $tmp\_p_i.\vb{v} \leftarrow orig\_p_i.\vb{v} + dt \cdot \vb{k}_{\vb{v},3,i}$ \State $tmp\_p_i.\vb{v} \leftarrow orig\_p_i.\vb{v} + dt \cdot \vb{k}_{\vb{v},3,i}$
@ -158,16 +204,16 @@ around 8 separate loops to calculate all $\vb{k}$ values
\State $particles \leftarrow tmp\_p$ \Comment{Update particles} \State $particles \leftarrow tmp\_p$ \Comment{Update particles}
\For{ $i = 1, 2, \ldots, N$ } \For{ $i = 1, 2, \ldots, N$ }
\State $\vb{k}_{\vb{r},4,i} \leftarrow \vb{v}$ \State $\vb{k}_{\vb{r},4,i} \leftarrow particles_i.\vb{v}$
\State $\vb{k}_{\vb{v},4,i} \leftarrow \frac{\vb{F}}{m}$ \State $\vb{k}_{\vb{v},4,i} \leftarrow \frac{\vb{F}}{m}$
\State $tmp\_p_i.\vb{r} \leftarrow orig\_p_i.\vb{r} + \frac{dt}{6} \State $tmp\_p_i.\vb{r} \leftarrow orig\_p_i.\vb{r} + \frac{dt}{6}
\cdot \left( \vb{k}_{\vb{r},1,i} + \vb{k}_{\vb{r},2,i} \cdot \left( \vb{k}_{\vb{r},1,i} + \vb{k}_{\vb{r},2,i}
+ \vb{k}_{\vb{r},3,i} + \vb{k}_{\vb{r},4,i} \right)$ + \vb{k}_{\vb{r},3,i} + \vb{k}_{\vb{r},4,i} \right)$
\State $tmp\_p_i.\vb{v} \leftarrow orig\_p_i.\vb{v} + \frac{dt}{6} \State $tmp\_p_i.\vb{v} \leftarrow orig\_p_i.\vb{v} + \frac{dt}{6}
\cdot \left( \vb{k}_{\vb{v},1,i} + \vb{k}_{\vb{v},2,i} \cdot \left( \vb{k}_{\vb{v},1,i} + \vb{k}_{\vb{v},2,i}
+ \vb{k}_{\vb{v},3,i} + \vb{k}_{\vb{v},4,i} \right)$ + \vb{k}_{\vb{v},3,i} + \vb{k}_{\vb{v},4,i} \right)$
\EndFor \EndFor
@ -181,5 +227,9 @@ around 8 separate loops to calculate all $\vb{k}$ values
\end{figure} \end{figure}
\subsection{Testing the simulation}
\subsection{Relative error and error convergance rate}
\biblio \biblio
\end{document} \end{document}