\documentclass[12pt,a4paper,twoside]{scrbook} %Individuelle Kopf- und Fußzeilen \usepackage[headsepline]{scrlayer-scrpage} \pagestyle{scrheadings} %Tabellen \usepackage{booktabs}%für horizontale Linien \usepackage{multirow} \usepackage{bigdelim} %Figures \usepackage{graphicx} \usepackage{adjustbox} \usepackage{caption} \usepackage{subcaption}%subfigures \usepackage{sidecap}%caption an der seite %Mathe/Physik \usepackage{amsmath} \usepackage{amssymb} \usepackage{mathtools} \usepackage{bigints}%rescale integrals %\usepackage{bbold} % einheitsmatrix-doppeleins \usepackage{esint}%volumen und oberflächenintegrale \usepackage[thinc]{esdiff}%derivative-macros \usepackage{physics} \usepackage{siunitx} \DeclareSIUnit\gauss{G} \DeclareSIUnit \clight {\text{\ensuremath {c}}} \sisetup{range-phrase=-} \sisetup{range-units=single} %Literatur \usepackage{natbib} \usepackage{csquotes}%recommended to ensure that quoted texts are typeset according to the rules of the main language %Sonstiges %\usepackage{microtype}%bessere abstände zur vermeidung von underfull boxes etc. \usepackage[framemethod=tikz]{mdframed}%merkboxen \mdfdefinestyle{theoremstyle}{ linecolor=gray,linewidth=2pt, frametitlerule=true, frametitlebackgroundcolor=gray, } \mdtheorem[style=theoremstyle]{nutshell}{"In a Nutshell"} \usepackage{framed}%kleine merkboxen \usepackage[english]{babel} \usepackage{blindtext} \usepackage{color}%farbiger text \usepackage{hyperref} \usepackage{cleveref} \newcommand{\pd}[2]{\frac{\partial #1}{\partial #2}} \begin{document} %Titelseite(n) \KOMAoptions{twoside=false} %Preface and Contents \clearpage \begingroup \pagestyle{empty} \renewcommand*\chapterpagestyle{empty} \begin{titlepage} \centering \includegraphics[width=0.5\textwidth]{./unihdlogo.pdf}\par\vspace{3cm} {\scshape\LARGE Lecture Notes \par} \vspace{1cm} {\scshape\Large Winter 2022/2023 \par} \vspace{2.5cm} {\huge\bfseries Numerical Methods in Plasma-Astrophysics \par} \vspace{3cm} {\Large\itshape Priv.-Doz. Dr. F. Spanier \par} \vfill \end{titlepage} \chapter*{Preface} Plasma is sometimes called "the $4^{th}$ state of matter" or it is claimed that "99\% of the universe is made up of plasma". While there is some truth behind these claims, the reality is far more complex. It is an undisputed fact that most astrophysical objects are primarily containing plasma. Unfortunately trying to understand astrophysical plasmas is not really simple and only very few cases allow for a simple pen-and-paper calculation. This inevitably leads to computer simulations. Within this lecture some simulation techniques shall be discussed. This list neither conclusive nor is everything discussed in depth. This script is still deep in writing process. If you have suggestion or if you find errors, typos etc. please email \href{mailto:felix.spanier@uni-heidelberg.de}{felix.spanier@uni-heidelberg.de}\\ \tableofcontents \clearpage \endgroup %Pagestyle, Kopf und Fußzeilen für den Rest des Dokuments \newpage \KOMAoptions{twoside=true} \setcounter{page}{1} \ohead{\headmark} \automark[section]{chapter} \setlength{\parindent}{0em}%keine Einrückung bei neuem Absatz \chapter{Short introduction to plasma physics} \label{chap:1-short-intro} Many people - mostly people doing plasma research - claim that the universe is "99\% plasma". Others not so involved in the topic say that plasma is "the $4^{th}$ state of matter" and the common belief is that a plasma is simply an ionized gas.\\ None of the above is really wrong, but most of it is at some point incorrect. I would like to refer the reader to my lecture ``Introduction to astro-plasmaphysics'' or the vast literature to read about the details of how plasmas work. In order to understand the physical background of the numerical techniques in this lecture we will go through the main definitions and parameters of plasmas. \section{Collective behavior} \label{sec:1-1-coll-behavior} The difference between a gas and a plasma is the interaction of single particles. In a gas interaction only takes place during collisions (particles "feel" the short range $r^{-6}$ field). In a plasma particles are subject to the long range $r^{-2}$ electrostatic forces. This leads to a simultaneous response of the plasma to an external stimulus. \subsection{Debye Shielding} \label{sec:1-1-1-debye-shielding} The most important factor of a plasma is its ability to reduce electric fields effectively. The effect of shielding can be discussed by introducing an additional point-like charge $+Q$ into an infinite homogeneous plasma which has equal densities of ions and electrons $n_{e0}=n_{i0}$. $+Q$ shall be located at the origin of the coordinate system. Electrons will be attracted while ions will be repelled. This effect is sketched in \cref{fig:1-2-shielding}. \begin{figure}[bh] \centering \begin{subfigure}[t]{.49\textwidth} \centering \includegraphics[width=.4\linewidth, height=3.5cm]{./fig_chapter1/2a_shielding.png} \caption{Shielding arises from a net attraction of electrons and repulsion of ions, leading to trajectory bending.} \label{fig:1-2-shielding-a} \end{subfigure} \begin{subfigure}[t]{.49\textwidth} \centering \includegraphics[width=.4\linewidth, height=3.5cm]{./fig_chapter1/2b_shielding.png} \caption{For higher energies the trajectories become stiffer and the shielding less efficient} \label{fig:1-2-shielding-b} \end{subfigure} \caption{The effect of shielding} \label{fig:1-2-shielding} \end{figure} This gives rise to a net space charge in the vicinity of $+Q$, which tends to weaken the electric field generated by $+Q$.\par\medskip The bending depends on the particle energy. The higher the energy of the electrons (ions), i.e. the higher the temperature of the electron(ion)gas is, the stiffer the trajectory becomes (\cref{fig:1-2-shielding-b}). Therefore a cold species of particles will be very effective in shielding the extra charge and we can conjecture that the size of the perturbed region is small, whereas the perturbation has a greater range for hotter electrons (ions).\par\medskip Obviously, this shielding process is not static, but is governed by the thermal motion of the plasma electrons and ions. Therefore we need a simple statistical description, for which we use the Boltzmann factor. For a quantitative description we calculate the number of electrons and ions that are found at an enhanced electric potential in the vicinity of $+Q$. For a repulsive potential the Boltzmann factor \eqref{eq:1-1-boltz-distr} gives the number of particles in a thermal distribution that have overcome a potential barrier $\Phi$. For an attractive potential, the density can even become higher than the equilibrium value: \begin{align} \label{eq:1-8-shielding-densities} n_{\mathrm{e}}(\mathbf{r})=n_{e 0} \exp \left(+\frac{e \Phi(\mathbf{r})}{k_{\mathrm{B}} T_{\mathrm{e}}}\right) \nonumber\\ \\ n_{\mathrm{i}}(\mathbf{r})=n_{i 0} \exp \left(-\frac{e \Phi(\mathbf{r})}{k_{\mathrm{B}} T_{\mathrm{i}}}\right). \nonumber \end{align} For simplicity, we assume that the perturbed potential $\Phi$ is small compared to the thermal energy, which allows us to expand the exponential and use only the first term in the Taylor-expansion \begin{align} \label{eq:1-9-shielding-densities-approx} n_{\mathrm{e}}(\mathbf{r}) \approx n_{\mathrm{e} 0}\left(1+\frac{e \Phi(\mathbf{r})}{k_{\mathrm{B}} T_{\mathrm{e}}}\right)\nonumber\\ \\ n_{\mathrm{i}}(\mathbf{r}) \approx n_{\mathrm{i} 0}\left(1-\frac{e \Phi(\mathbf{r})}{k_{\mathrm{B}} T_{\mathrm{i}}}\right). \nonumber \end{align} A self-consistent solution for the electric potential can then be obtained by using Poisson’s equation \begin{equation} \label{eq:1-10-shielding-poisson} \Delta \Phi = -4 \pi \rho = -4 \pi \left[Q \delta (\vec{r}) - e n_{\mathrm{e}}(\mathbf{r})+e n_{\mathrm{i}}(\mathbf{r}) \right]. \end{equation} Inserting the linearized densities from \eqref{eq:1-9-shielding-densities-approx} we get \begin{equation} \label{eq:1-11-insert-linearization} \frac{\partial^{2} \Phi}{\partial r^{2}}+\frac{2}{r} \frac{\partial \Phi}{\partial r}=-4 \pi\left[4\pi Q \delta(r)-e n_{\mathrm{e} 0} \frac{e \Phi}{k_{\mathrm{B}} T_{\mathrm{e}}}-e n_{\mathrm{i} 0} \frac{e \Phi}{k_{\mathrm{B}} T_{\mathrm{i}}}\right] \end{equation} We are only considering the $r$-dependency, i.e. we assume spherical symmetry. This can be brought into the Helmholtz-type equation \begin{equation} \label{eq:1-12-shielding-helmholtz} \frac{\partial^{2} \Phi}{\partial r^{2}}+\frac{2}{r} \frac{\partial \Phi}{\partial r}-\frac{1}{\lambda_{\mathrm{D}}^{2}} \Phi=-16 \pi^2 Q \delta(r). \end{equation} The parameter $\lambda_D$ has the dimension of a length and is defined by \begin{equation} \label{eq:1-13-debye-length} \frac{1}{\lambda_{\mathrm{D}}^{2}}=\frac{4 \pi e^{2} n_{\mathrm{e} 0}}{ k_{\mathrm{B}} T_{\mathrm{e}}}+\frac{4 \pi e^{2} n_{\mathrm{i} 0}}{ k_{\mathrm{B}} T_{\mathrm{i}}} \end{equation} The differential equation \eqref{eq:1-12-shielding-helmholtz} can be solved by assuming that the potential distribution is given by a modified Coulomb potential \begin{equation} \label{eq:1-14-mod-coulomb} \Phi(r)=\frac{a}{r} f(r). \end{equation} Then for all $r>0$ the function $f(r)$ is a solution of the differential equation \begin{equation} \label{eq:1-15-shielding-dgl-allg} f^{\prime \prime}-\lambda_{\mathrm{D}}^{-2} f=0, \end{equation} which gives $f_1(r) = \exp(-r/\lambda_D)$. The second solution $f_2(r) = \exp(+r/\lambda_D)$ is unphysical due to the exponential growth.\\ The solution to the original problem is then \begin{equation} \label{eq:1-16-shielding-solution} \Phi(r)=\frac{Q}{r} \mathrm{e}^{-r / \lambda_{\mathrm{D}}}. \end{equation} This is called Debye-Hückel-potential. Typically this is also called "Debye-shielding". The parameter $\lambda_D$ is the Debye shielding length. For the identification of specific contributions the electron Debye length $\lambda_{De}$ and ion Debye length $\lambda_{Di}$ are defined: \begin{equation} \label{eq:1-17-individual-debye-length} \lambda_{\mathrm{De}}=\left(\frac{k_{\mathrm{B}} T_{\mathrm{e}}}{4 \pi n_{\mathrm{e} 0} e^{2}}\right)^{1 / 2} \lambda_{\mathrm{Di}}=\left(\frac{k_{\mathrm{B}} T_{\mathrm{i}}}{4 \pi n_{\mathrm{i} 0} e^{2}}\right)^{1 / 2}. \end{equation} \subsection{Quasineutrality} \label{sec:1-1-2-quasineutrality} As we have learned in the preceding paragraph, a plasma is not a strictly neutral mixture of electrons and positive ions but deviations from neutrality can develop on short scales, the Debye length. Therefore, we define that on length scales larger than the Debye length the plasma must be quasineutral \begin{equation} \label{eq:1-18-quasineutral} \left|\sum_{j} Z_{j} e n_{\mathrm{i} 0, j}-n_{\mathrm{e} 0} e\right| \ll n_{\mathrm{e} 0} e. \end{equation} Here, the sum is extended over all (positive) ion species $j$ of charge number $Z_{j}$. The charge number is a positive quantity, hence negative ions will have a minus sign before the charge number. For a single ion species of charge $q=+e$ the short-hand notation of the quasineutrality condition is $n_{\mathrm{i} 0}=n_{\mathrm{e} 0} .$ In this way, quasineutrality can be used as a defining quality of a classical plasma.The plasma region can be distinguished from space-charge regions. \subsection{Response Time and Plasma Frequency} \label{sec:1-2-3-plasma-freq} The response to an external electric perturbation was established by the combined action of many particles. Therefore, Debye shielding is one example for collective behavior of a plasma. The second aspect of collective behavior is the time scale, after which the electrons establish a shielded equilibrium.The heavier ions will take a much longer time to reach their equilibrium positions.\\ When the potential perturbation is small, $|e \Phi| \ll k_{\mathrm{B}} T,$ the electron energy is not much changed from its thermal value. Hence, the typical electron velocity remains close to a thermal velocity $v_{\mathrm{e}} \approx\left(k_{\mathrm{B}} T_{\mathrm{e}} / m_{\mathrm{e}}\right)^{1 / 2}$. For the establishment of the new equilibrium, the electron must be able to reach its new position at a typical distance $\lambda_{\mathrm{De}} .$ This time can be estimated as $\tau \approx \lambda_{\mathrm{De}} / v_{\mathrm{e}} .$ The reciprocal of this response time is called the electron plasma frequency \begin{equation} \label{eq:1-19-plasma-freq} \omega_{\mathrm{pe}}=\frac{v_{\mathrm{e}}}{\lambda_{\mathrm{De}}}=\left(\frac{4 \pi n_{\mathrm{e} 0} e^{2}}{m_{\mathrm{e}}}\right)^{1 / 2}. \end{equation} \section{Existence regimes} \label{sec:1-2-exis-regimes} A plasma of size $L$ must be sufficiently large, i.e. $L>>\lambda$ to behave in a collective manner (candle flames are not a plasma...). A plasma must also exist longer than the response $t>>\omega_{pe}^{-1}$.\\ Plasmas are found in a huge parameter space, which covers seven orders of magnitude in temperature and twenty-five orders of magnitude in electron density (see \cref{fig:1-3-existence-diagramm} ). \begin{figure}[ht] \centering \includegraphics[width=\textwidth, height=0.45\paperheight]{./fig_chapter1/3_existence-diagramm.png} \caption{Existence diagram of various plasmas. The dotted line marks the border for strong coupling, the dashed line the onset of quantum effects. Relativistic effects play a role for $T > 10^9 \si{\kelvin}$} \label{fig:1-3-existence-diagramm} \end{figure} \subsection{Strong-Coupling Limit} \label{sec:1-2-1-strong-coupling} The usual definition of a weakly coupled or ideal plasma is the requirement that there are many electrons inside the electron Debye sphere. This ensures that Debye shielding is a collective process and that the statistical derivation of a Debye length was correct. For this purpose we define the number of electrons inside the electron Debye sphere as the plasma parameter $N_{\text {De }}$ \begin{equation} \label{eq:1-20-plasma-parameter} N_{\mathrm{De}}=\frac{4 \pi}{3} \lambda_{\mathrm{De}}^{3} n_{\mathrm{e}} \end{equation} Because of the different temperatures, we can have different coupling states of electrons and ions $N_{\mathrm{De}} \neq N_{\mathrm{Di}} .$\\ The border line between weakly and strongly coupled plasmas is defined by $N_{\mathrm{De}}=1$ (see dotted line in \cref{fig:1-3-existence-diagramm} ), which gives the equation of the border line \begin{equation} \label{eq:1-21-border-line} n_e = \frac{k_B^3}{36 \pi e^6} T_e^3 \end{equation} This line has the slope 3 in the $\log n-\log T$ representation of \cref{fig:1-3-existence-diagramm} and we obtain a relation between the plasma parameter $N_{\mathrm{Di}}$ and the coupling parameter $\Gamma_{\mathrm{i}}$ \begin{equation} \label{eq:1-22-coupling-parameter2} \Gamma_{\mathrm{i}}=\frac{1}{3} N_{\mathrm{Di}}^{-2 / 3}. \end{equation} Hence, a larger number of particles in the Debye sphere ensures that the coupling strength is small. In other words, the electric field is the average field of many particles, whereas in a strongly coupled system the field of the nearest neighbor dominates. Weakly coupled plasmas are found at high temperature and low electron density. \subsection{Quantum effect} \label{sec:1-2-2-quantum-effects} Quantum effects come into play when the interparticle distance of the electrons becomes comparable with their thermal de Broglie wavelength \begin{equation} \label{eq:1-23-de-broglie} \lambda_{\mathrm{B}}=\frac{h}{m_{\mathrm{e}} v_{\mathrm{Te}}}. \end{equation} Here, $v_{\mathrm{Te}}=\left(2 k_{\mathrm{B}} T_{\mathrm{e}} / m_{\mathrm{e}}\right)^{1 / 2}$ is the most probable speed of a Maxwell distribution (see Sect. 4.1). In this limiting case, the Pauli exclusion principle becomes important and we must use Fermi-Dirac statistics. Such a plasma is called degenerate and the conditions of a cold dense plasma are typically found in dead stars, like White Dwarfs. It is worth mentioning that the exclusion principle prevents the final collapse of such a burnt-out star.\par\medskip The second border line for degeneracy of the electron gas, $\lambda_{\mathrm{B}}=n_{\mathrm{e}}^{-1 / 3}$ is also shown as dashed line in Fig. $2.5 .$ Here, the slope is $3 / 2$ in the $\log n-\log T$ diagram. Note that the electrons in a metal form a strongly coupled degenerate system. Relativistic effects for the electrons become important for $T>10^{9} \mathrm{~K}$ as marked by the dot-dashed line in Fig. $2.5 .$ The marked regions of typical plasmas can all be treated by non-relativistic models. \begin{nutshell}[Basics] \begin{itemize} \item Plasmas are quasineutral: $n_{\mathrm{e}}=\sum_{k} Z_{k} n_{k}$. \item Quasineutrality can be violated within a Debye length $\lambda_{D}$ $$ \lambda_{\mathrm{D}}=\frac{\lambda_{\mathrm{De}} \lambda_{\mathrm{Di}}}{\left(\lambda_{\mathrm{De}}^{2}+\lambda_{\mathrm{Di}}^{2}\right)^{1 / 2}} \quad, \quad \lambda_{\mathrm{De}, \mathrm{Di}}=\left(\frac{ k_{\mathrm{B}} T_{\mathrm{e}, \mathrm{i}}}{4 \pi n_{\mathrm{e}, \mathrm{i}} e^{2}}\right)^{1 / 2} $$ \item Quasineutrality can be established by the electrons within $\tau=\omega_{\mathrm{pe}}^{-1},$ with the plasma frequency $$ \omega_{\mathrm{pe}}=\left(\frac{4 \pi n_{\mathrm{e}} e^{2}}{ m_{\mathrm{e}}}\right)^{1 / 2} $$ \item The coupling parameter $\Gamma$ determines the state of each plasma component (electrons, ions, dust) $$ \Gamma=\frac{q^{2}}{a_{\mathrm{WS}} k_{\mathrm{B}} T} $$ $\Gamma$ may be different for the components, depending on the individual temperatures and densities. A gaseous phase is found for $\Gamma \ll 1$, the liquid state for $1<\Gamma<180$ and the solid phase for $\Gamma>180$. \end{itemize} \end{nutshell} \section{Single particle description} \label{sec:1-3-single-particle} \subsection{Basic Equations} \label{sec:1-3-1-motion-basics} We will start with Newton's equation of motion together with the Lorentz force for a particle of mass $m$, charge $q$ in a given electric field $\vec{E}$ and magnetic field $\vec{B}$: \begin{equation} \label{eq:2-1-newton-lorentz} \diff{\vec{p}}{t} = m \dot{\vec{v}} = q \left(\vec{E} + \frac{\vec{v}}{c} \times \vec{B} \right) \end{equation} \subsection{Cyclotron Frequencies} \label{sec:2-1-2-cyclotron} Let us first consider the case of a homogeneous and stationary magnetic field $\vec{B} = B_z \vec{e}_z$ and a vanishing electric field $\vec{E}=0$. This yields the equations: \begin{align} \label{eq:2-2-cartesian-eom} \nonumber \dot{v}_x &= + v_y \frac{q}{m c} B_z \\ \dot{v}_y &= - v_x \frac{q}{m c} B_z \\ \nonumber\dot{v}_z &= 0. \end{align} Combining the equations for $v_x$ and $v_y$ yields the differential equation for a harmonic oscillator \begin{equation} \label{eq:2-3-harmonic-osci} \ddot{v}_{x,y} = - \left(\frac{q B_z}{m c}\right)^2 v_{x,y} \, . \end{equation} The frequency for this oscillator is \begin{equation} \label{eq:2-4-cyclotron-frequency} \Omega = \frac{\lvert q \rvert}{m c} B_z \, , \end{equation} This frequency is called cyclotron frequency (sometimes designated $\omega_c$). \\ For protons and electrons we find \begin{align*} \Omega_p &= 9,58 \times 10^3 \, \si{\per\second} \cdot B \,[\text{Gauss}] \, , \\ \Omega_e &= 1,76 \times 10^7 \, \si{\per\second} \cdot B \, [\text{Gauss}] \, . \\ \end{align*} In the x–y plane, a particle with perpendicular velocity $v_{\perp}$ performs a circular orbit with the gyroradius or Larmor radius \begin{equation} \label{eq:2-5-lamor-radius} r_L = \frac{v_{\perp}}{\Omega} \end{equation} When the initial velocity $v_z$ along the magnetic field is nonzero, the orbit becomes a helix of constant pitch about the magnetic field direction. The motion about a magnetic field line is referred to as gyromotion or gyroorbit.\\ The sense of rotation about the magnetic field depends on the sign of the particle’s charge. Electrons move in a right-handed, positive ions in a left-handed orbit (see \cref{fig:2-1-gyromotion}). \begin{SCfigure} \centering \caption{A schematic overview of the gyromotion for charged particles. Note the different direction for $e^-$ and $\text{Ion}^+$ !} \includegraphics[width=0.49\textwidth]{./fig_chapter1/1_gyromotion.png} \label{fig:2-1-gyromotion} \end{SCfigure} When the ions (electrons) can perform complete gyroorbits, the ions (electrons) are called magnetized. This is the case, when the gyroorbits are not interrupted by collisions. A condition for this to happen is that the ion (electron) collision frequency (\color{red} hier Referenz auf entsprechendes kapitel einsetzen\color{black}) is smaller than the ion (electron) cyclotron frequency. Usually, this condition can be better fulfilled by electrons than by ions. \subsection{E x B Drift} \label{sec:1-3-3-exb-drift} When we allow for a stationary and homogeneous electric field, we can choose the orientation of our coordinate system to have electric and magnetic field in the $x-z$ plane, $\vec{E}=\left(E_{x}, 0, E_{z}\right)$ and $\vec{B}=\left(0,0, B_{z}\right) .$ In this case, Newton's equation of motion reads \begin{equation} \label{eq:2-6-drift-eom} \begin{aligned} \dot{v}_{x} &=\frac{q}{m}\left(E_{x}+\frac{v_{y}}{c} B_{z}\right) \\ \dot{v}_{y} &=\frac{q}{m}\left(-\frac{v_{x}}{c} B_{z}\right) \\ \dot{v}_{z} &=\frac{q}{m} E_{z} \, . \end{aligned} \end{equation} The motion along the magnetic field is now accelerated but independent of the motion in the $x-y$ plane. According to the principle of superposition of motions, we can consider both effects separately. For the $x-y$ plane, the motion can again be decomposed \begin{equation} \label{eq:2-7-eom-decomposed} \begin{array}{l} \ddot{v}_{x}=-\Omega^{2} v_{x} \\ \ddot{v}_{y}=-\Omega^{2}\left(v_{y}+c \frac{E_{x}}{B_{z}}\right) \, . \end{array} \end{equation} Again, we find a harmonic oscillation in $x$ -direction, but the motion in $y$ -direction is more complex. In a moving frame of reference, $\tilde{v}_{y}=v_{y}+c \cdot E_{x}/B_{z},$ which moves at a constant velocity $-c \cdot E_{x} / B_{z}$ in negative $y$ -direction, we obtain a simple harmonic motion \begin{equation} \label{eq:2-8-eom-y-direction} \ddot{\tilde{v}}_{y}=-\Omega^{2} \tilde{v}_{y} \, . \end{equation} Thus the solution for the velocities is the superposition of a circular orbit and a constant motion in the same plane. This constant motion is called the $\mathrm{E} \times \mathrm{B}$ -drift. For a particle that is initially at rest, the solution reads \begin{equation} \label{eq:2-9-solution-drift} \begin{aligned} v_{x} &= c \frac{E_{x}}{B_{z}} \sin \Omega t \\ v_{y} &= c \frac{E_{x}}{B_{z}}\left[\cos \Omega t-1\right] \end{aligned} \end{equation} A typical trajectory is shown in \cref{fig:2-2-drift}. Mathematically, the trajectory is a cycloid. For a positive particle starting at $t=0$ from the origin, the trajectory is described by \begin{equation} \label{eq:2-10-trajectory-drift} x=\frac{c E_{x}}{B_{z} \Omega}\left[1-\cos \left(\Omega t\right)\right], \quad y=\frac{c E_{x}}{B_{z} \Omega}\left[\sin \left(\Omega t\right)-\Omega t\right] \end{equation} The $\vec{E} \times \vec{B}$ -drift can also be understood from energy considerations. On the high potential side, the kinetic energy is small, which makes the instantaneous gyroradius small. On the low-potential side, the ion has gained kinetic energy from the electric field, which makes the gyro-radius larger. The combination of these two effects results in a cycloidal motion. It is a peculiarity of the $\vec{E} \times \vec{B}$ -drift that negative electrons and positive ions experience the same sign of the drift velocity. This is a consequence of the fact that the applied electric field force $q \vec{E}$ and the resulting Lorentz force $q \vec{v} \times \vec{B}$ both depend on the sign of $q,$ which cancels in the result. This effect can also be seen in \cref{fig:2-2-drift}. In vector notation, the $\vec{E} \times \vec{B}$ drift velocity is given by \begin{equation} \label{eq:2-11-drift-velocity} \vec{v}_{E}=c \frac{\vec{E} \times \vec{B}}{B^{2}} \, . \end{equation} \begin{SCfigure}[1][th] \centering \caption{Cycloidal trajectory resulting from the superposition of gyro-motion and E × B-drift. The electric field is oriented along the x-axis, the magnetic field is perpendicular to the x–y plane. Note that ions (full line) and electrons (dashed line) have the same drift direction. An artificial electron mass, $m_e=0.3 m_{ion}$, was assumed here for clarity!} \includegraphics[width=0.49\textwidth, height=0.4\paperheight]{./fig_chapter1/2_drift.png} \label{fig:2-2-drift} \end{SCfigure} \section{Kinetic description} In the classical description of plasmas the first step is to define a cold plasma (thermal velocity of all particles is zero). In this limit simple plasma descriptions are possible and the calculation of Eigenmodes is rather straightforward. For plasmas with a thermal distribution (mostly \emph{hot} plasmas) a different description is chosen: From Liouville's theorem over some dirty tricks the Vlasov equation can be derived: \begin{equation} \label{eq:vlasov-equation} \frac{\partial f_{\alpha}}{\partial t}+\vec{v} \cdot \frac{\partial f_{\alpha}}{\partial \vec{r}}+\frac{q_{\alpha}}{m_{\alpha}}(\vec{E}+\frac{\vec{v}}{c} \times \vec{B}) \cdot \frac{\partial f_{\alpha}}{\partial \vec{v}}=0 \end{equation} The \emph{Vlasov theory} is a quite complete description of fully ionized plasmas and it provides a solid foundation for wave-particle interactions. At the same time it often is much too detailed for practical purposes. The theory has its own limitations, in particular in weakly ionized plasmas (e.g., ionosphere, solar photosphere), where plasma-neutral collisions cannot be neglected. The effects arising from the collision term of the Boltzmann equation can be added to the Vlasov treatment, but that reduces the generality of the approach. \subsection{Properties of the Vlasov equation} \label{sec:1-4-1-properties-of-vlasov-eq} The Vlasov equation is sometimes regarded as the most important equation of plasma physics. It has several useful properties: \begin{itemize} \item The Vlasov equation conserves particles. It is straightforward to show that \begin{equation} \label{eq:particle-conservation} \frac{\partial}{\partial t} \int n_{\alpha} f_{\alpha} d^{3} r d^{3} v=0 \, , \end{equation} by integrating $(5.1)$ over the entire $(\vec{r}, \vec{v})$ -space. Here $n_{\alpha}$ denotes the average density of species $\alpha$ in the volume under consideration. \item Positive probabilities remain positive in the Vlasov description. If $f_{\alpha}(\vec{r}, \vec{v}, t=0)>0$ for all $(\vec{r}, \vec{v})$, then $f_{\alpha}(\vec{r}, \vec{v}, t)>0$ for all $t>0$. This is an important property to be ensured in numerical Vlasov simulations. \item The Vlasov equation conserves entropy. Entropy is defined by \begin{align} \label{eq:entropy-conservation} S &= -\sum_{\alpha} \int f_{\alpha} \ln f_{\alpha} d^{3} r d^{3} v \\ \Rightarrow \qquad \frac{d S}{d t} &=-\sum_{\alpha} \int\left(\frac{d f_{\alpha}}{d t} \ln f_{\alpha}+\frac{d f_{\alpha}}{d t}\right) d^{3} r d^{3} v=0 \, . \end{align} This is an important issue in the interpretation of Landau's solution of the Vlasov equation to which we turn in the next section. \item The Vlasov equation has many equilibrium solutions. In statistical physics Boltzmann's \emph{H-theorem} states that there is a unique equilibrium in the collisional time scale, the Maxwell distribution. The relevant time scales of the Vlasov theory are much shorter than the collision periods due to the assumption $\partial f /\left.\partial t\right|_{c} \rightarrow 0 .$ Let $f_{\alpha 0}$ be any Vlasov equilibrium, then $\partial f_{\alpha 0} / \partial t=0$ and thus \begin{equation} \label{eq:equilibrium} \left[\vec{v} \cdot \frac{\partial}{\partial \vec{r}}+\frac{q_{\alpha}}{m_{\alpha}}(\vec{E}+\vec{v} \times \vec{B}) \cdot \frac{\partial}{\partial \vec{v}}\right] f_{\alpha 0}=0 \, . \end{equation} In order to generate a general solution to this equation let $\left(\vec{r}^{\, \prime}\left(t^{\, \prime}\right), \vec{v}^{\, \prime}\left(t^{\, \prime}\right)\right)$ be the orbit of a particle that intersects the point $(\vec{r}, \vec{v})$ at the time $t^{\, \prime}=t$. If functions $a\left(\vec{r}^{\, \prime}, \vec{v}^{\, \prime}\right), b\left(\vec{r}^{\, \prime}, \vec{v}^{\, \prime}\right), \ldots$ are constants of motion for particles of species $\alpha$, then any function $f_{\alpha 0}\left[a\left(\vec{r}^{\, \prime}, \vec{v}^{\, \prime}\right),\right.$, $\left.b\left(\vec{r}^{\, \prime}, \vec{v}^{\, \prime}\right), \ldots\right]$ satisfies $(5.5)$ at the time $t^{\, \prime}=t$, and thus any function $f_{\alpha 0}[a(\vec{r}, \vec{v}), b(\vec{r}, \vec{v}), \ldots]$ of the constants of motion is a stationary-state solution of the Vlasov equation. \end{itemize} \paragraph{Examples of Vlasov Equilibria.} \begin{enumerate} \item $\vec{E}_{0}=\vec{B}_{0}=0 .$ In this case the constants of motion are \begin{align*} W &=\frac{m_{\alpha}}{2}\left(v_{x}^{2}+v_{y}^{2}+v_{z}^{2}\right) \\ \vec{p} &=m_{\alpha} \vec{v} \, . \end{align*} Examples of equilibrium solutions are now \begin{align} \label{eq:e-and-b-zero} f_{\alpha 0} &= \left(\frac{m_{\alpha}}{2 \pi k_{B} T_{\alpha}}\right)^{3 / 2} \exp \left(-\frac{m_{\alpha}}{2 k_{B} T_{\alpha}} v^{2}\right) \\ f_{\alpha 0} &= C_{1} \frac{v_{0}}{2} \frac{1}{v^{4}+v_{0}^{4}} \\ f_{\alpha 0} &= C_{2} \, v_{0} \, \delta\left(v_{x}\right) \delta\left(v_{y}\right) \delta\left(v_{z}^{2}-v_{0}^{2}\right) \\ f_{\alpha 0} &= \sqrt{\frac{m_{\alpha}}{2 \pi k_{B} T_{\alpha}}} \delta\left(v_{x}\right) \delta\left(v_{y}\right) \exp \left(-\frac{m_{\alpha}\left(v_{z}^{2}-v_{\alpha 0}^{2}\right)}{2 k_{B} T_{\alpha}}\right) \, . \end{align} \item $\vec{E}_{0}=0, \vec{B}_{0}=B_{0}(\vec{r}) \vec{e}_{z} .$ A possible selection of constants of motion is $$ \begin{array}{l} W=\frac{m_{\alpha}}{2}\left(v_{x}^{2}+v_{y}^{2}+v_{z}^{2}\right) \\ p_{\|}=m_{\alpha} v_{z} \\ \vec{L}=m_{\alpha}\left(x v_{y}-y v_{x}\right) \vec{e}_{z}-q_{\alpha} r A_{\phi}(r) \vec{e}_{\phi} \end{array} $$ where $A_{\phi}$ is the azimuthal component of the vector potential, which is the only non-zero component in this configuration. \\ One of several possible equilibria for a constant $B_{0}$ is \begin{equation} \label{eq:constant-B0} f_{\alpha 0}=F\left(v^{2}, v_{y}+\frac{q_{\alpha} B_{0}}{m_{\alpha} c} x, v_{x}-\frac{q_{\alpha} B_{0}}{m_{\alpha} c} y\right) \, . \end{equation} \end{enumerate} \subsection{Vlasov-Maxwell-system} \label{sec:1-4-2-landau-solution} The Vlasov equation is not easy to solve. It must, of course, be done under the constraint to fulfill Maxwell's equations because the source terms of Maxwell's equations $(\rho, \vec{J})$ are determined by the distribution function, which, in turn, evolves according to the Vlasov equation. Furthermore, the force term in the Vlasov equation is nonlinear. Thus the Vlasov equation can be solved analytically only for small perturbations when linearization is possible. We start by writing functions to be solved as sums of equilibirum solutions and small perturbations \begin{align*} f_{\alpha} &=f_{\alpha 0}+f_{\alpha 1} \\ \vec{E} &=\vec{E}_{0}+\vec{E}_{1} \\ \vec{B} &=\vec{B}_{0}+\vec{B}_{1} \end{align*} and consider the equations of the first-order terms. However, the problem remains difficult. The general solution for homogeneous plasma in a homogeneous background magnetic field was presented for the first time by Bernstein [1958] and inclusion of inhomogeneities rapidly leads to problems that can be handled by numerical methods only. Landau [1946] solved the field-free case in the following way. Consider homogeneous plasma free of ambient electromagnetic fields $\left(\vec{E}_{0}=\vec{B}_{0}=0\right)$ in \emph{electrostatic approximation}: $\vec{E}_{1}=-\nabla \varphi_{1} ; \vec{B}_{1}=0 .$ The linearized Vlasov equation is now \begin{equation} \label{eq:vlasov-linearized-1} \frac{\partial f_{\alpha 1}}{\partial t}+\vec{v} \cdot \frac{\partial f_{\alpha 1}}{\partial \vec{r}}-\frac{q_{\alpha}}{m_{\alpha}} \frac{\partial \varphi_{1}}{\partial \vec{r}} \cdot \frac{\partial f_{\alpha 0}}{\partial \vec{v}}=0 \, , \end{equation} where \begin{equation} \label{eq:vlasov-linearized-2} \nabla^{2} \varphi_{1}=-4 \pi \sum_{\alpha} n_{\alpha} q_{\alpha} \int f_{\alpha 1} d^{3} v \, . \end{equation} \section{Fluid description} \label{sec:1_5_derivation_of_macroscopic_equations} \subsection{Derivation of macroscopic quantities} \label{sec:1_5_1_derivation_of_macroscopic_quantities} The Vlasov equation \ref{eq:vlasov-equation} as reproduced here \begin{equation} \frac{\partial f_{\alpha}}{\partial t}+\vec{v} \cdot \frac{\partial f_{\alpha}}{\partial \vec{r}}+\frac{q_{\alpha}}{m_{\alpha}}(\vec{E}+\frac{\vec{v}}{c} \times \vec{B}) \cdot \frac{\partial f_{\alpha}}{\partial \vec{v}}=0 \end{equation} describes the temporal evolution of the distribution function in a collision free plasma. The inclusion of collision leads to the Boltzmann equation \begin{equation} \frac{\partial f_{\alpha}}{\partial t}+\vec{v} \cdot \frac{\partial f_{\alpha}}{\partial \vec{r}}+\frac{q_{\alpha}}{m_{\alpha}}(\vec{E}+\frac{\vec{v}}{c} \times \vec{B}) \cdot \frac{\partial f_{\alpha}}{\partial \vec{v}}=\left( \frac{\partial f_\alpha}{\partial t}\right)_\text{c} \label{eq:boltzmann} \end{equation} The term on the RHS describes collisions through a collision operator in an arbitrary way. Depending on the specific problem this term may be complicated. This is typically a problem, when a numeric solution is needed for the Boltzmann equation. For most derivations used here we will just need some algebraic properties of the collision operator, but not the specific form. A very simple form of a collision operator is the Krook model or relaxation time approximation: It is assumed that any distribution function will relax to an equilibrium after a certain time (typically this would be the Maxwell-Boltzmann distribution and the Krook model comes down to the H-theorem). The Krook model has the form \begin{align} \left( \frac{\partial f_\alpha}{\partial t}\right)_\text{c} = -\nu_c(f-f_0) \label{eq:krook} \end{align} Here $f_0$ is the equilibrium distribution and $\nu_c$ the collision frequency. This model is often used in Lattice Boltzmann Simulations. From thermodynamics and statistics we know that a distribution function can be characterized by an infinite series of moments of the distribution function. The same is true for the distribution function used in the Boltzmann or Vlasov equation. The first step now is to identify the moments of the distribution function with macroscopic quantities. Before doing so we have to define a suitable normalization. In this case we choose \begin{align} \int_\mathfrak{V} \int_{\vec{v}} f(\vec r, \vec v, t) \dd^3 r \dd^3 v = N \end{align} So $f$ describes the \emph{number density} in the volume element $\dd x \dd y \dd z \dd v_x \dd v_y \dd v_z$ and has the unit \unit{cm^{-6} s^3}. The average density in the volume $\mathfrak{V}$ is $\langle n\rangle =N/\mathfrak{V}$. However the particle density is usually a function of space and time. It is defined as the zero order velocity moment of the distribution function \begin{align} n(\vec r, t) = \int f(\vec r, \vec v, t) \dd^3 v \end{align} We will define the macroscopic quuantities as velocity moments of the distribution function \begin{align*} \int f(\vec r, \vec v, t) \dd^3 v; \quad \int \vec v f(\vec r, \vec v, t) \dd^3 v; \quad \int \vec v \vec v f(\vec r, \vec v, t) \dd^3 v \end{align*} In a plasma different species (labeled by $\alpha$) may have different distribution functions and therefore different velocity moments. If the particles of species $\alpha$ are charged with charge $q_\alpha$, the charge density\footnote{Please note that the use of $\rho$ as charge density is common, but not a unique choice. $\rho$ could very well be the mass density\dots} of the species is \begin{align} \rho_\alpha = q_\alpha n_\alpha \end{align} The first order moment yields the \emph{particle flux} \begin{align} \vec{\Gamma}_\alpha (\vec r, t) = \int \vec v f_\alpha(\vec r, t) \dd^3 v \end{align} Dividing this by the particle density we get the \emph{average velocity} \begin{align} \vec{V}_\alpha (\vec r, t) = \frac{\int \vec v f_\alpha(\vec r, t) \dd^3 v}{\int f_\alpha(\vec r, t) \dd^3 v} \end{align} from which we can further determine the \emph{current density} \begin{align} \vec j_\alpha(\vec r, t) = q_\alpha \vec{\Gamma}_\alpha = q_\alpha n_\alpha \vec{V}_\alpha \end{align} In second order we find the \emph{pressure tensor} \begin{align} \mathbb{P}_\alpha (\vec r, t) = m_\alpha \int (\vec v - \vec{V}_\alpha)(\vec v - \vec{V}_\alpha) f_\alpha(\vec r,\vec v,t)\dd^3 v \end{align} where the product in the integral is \textbf{not} a scalar product, but a vector product of the type $A_{ij} = b_i c_j$. In the spherically symmetric case the pressure tensor reduces to the \emph{scalar pressure} \begin{align} P_\alpha = \frac{m_\alpha}{3} \int (\vec v - \vec{V}_\alpha)^2 f_\alpha(\vec r,\vec v,t)\dd^3 v = n_\alpha k_B T_\alpha \end{align} (the square now is actually a scalar product). Here we introduce the concept of \emph{temperature} $T_\alpha$. In the frame moving with the velocity $\vec V$ the temperature is given by \begin{align} \frac{3}{2} k_B T_\alpha (\vec r, t) = \frac{m_\alpha}{2} \frac{\int \vec v^2 f_\alpha(\vec r, t) \dd^3 v}{\int f_\alpha(\vec r, t) \dd^3 v} \end{align} which for a \emph{Maxwellian distribution} is the temperature of classical thermodynamics. In collisionless plasmas equilibrium distributions my be far from Maxwellian. Thus temperature is a non-trivial concept in plasma physics. The relationship between the particle pressure and \emph{magnetic pressure} is the \emph{plasma beta} \begin{align} \beta = \frac{8\pi\sum_\alpha n_\alpha k_B T_\alpha}{B^2} \end{align} If $\beta>1$ the plasma governs the evolution of the magnetic field, if $\beta \ll 1$, the magnetic field determines the plasma dynamics. \subsection{Derivation of differential equations} \label{sec:1_5_2_derivation_of_evolution} Now that we have defined the macroscopic quantities we can come back to Eq. \eqref{eq:boltzmann} to derive differential equations for these quantities. Starting with the zeroth moment of the Boltzmann equation itself we see that $f_\alpha \to 0$ for $v\to\infty$. Also the force term vanishes since \begin{align} \int \vec E \cdot \frac{\partial f}{\partial \vec v}\dd^3 v = \int \frac{\partial }{\partial \vec v}(f \vec E) \dd^3v =\int f\vec{E}\cdot \dd \vec S = 0 \end{align} as $f$ goes more quickly to 0 than $S$ and \begin{align} \int (\vec v \times\vec B) \cdot \frac{\partial f}{\partial \vec v}\dd^3 v = \int f(\vec v\times\vec B)\cdot\dd\vec S-\int f\frac{\partial}{\partial\vec v}\cdot(\vec v\times\ vec B)\dd \vec v = 0 \end{align} The first vanisches with the same argument, the second vanishes since $\vec v\times\vec B$ is perpendicular to $\partial/\partial \vec v$. The first term in the Boltzmann equation simply yields the time derivative of density. The collision term can be neglected as long as there are no ionizing or recombining collisions (as they would change the particle numbers in one species). We are left with the spatial derivative. Here velocity integration and spatial derivative can be interchanged \begin{align} \int \vec v\cdot \frac{f_\alpha}{\vec r} \dd^3 v = \nabla \cdot \int \vec v f_\alpha\dd^3 v = \nabla \cdot(n_\alpha \vec{V}_\alpha) \end{align} This leads to the\emph{continuity equation} \begin{align} \frac{\partial n_\alpha}{\partial t}+ \nabla (n_\alpha \vec{V}_\alpha) = 0 \label{eq:zeromomentcont} \end{align} Continuity equations for charge and mass are obtained by multiplying Eq. \eqref{eq:zeromomentcont} by $q_\alpha$ and $m_\alpha$ respectively. The continuity equation is a special case of a \emph{hyperbolic conservation law} \begin{align} \frac{\partial F}{\partial t} +\nabla\cdot\vec G = 0 \end{align} for a density $F$ and a flux $\vec G$ Multiplying Eq. \eqref{eq:boltzmann} with $m_\alpha\vec v$ and integrating over $\vec v$ we find the first moment equation. This yields the \emph{momentum transport equation} which is the macroscopic \emph{equation of motion} \begin{align} n_\alpha m_\alpha \frac{\partial \vec{V}_\alpha}{\partial t} + n_\alpha m_\alpha \vec{V}_\alpha \cdot \nabla\vec{V}_\alpha - n_\alpha q_\alpha (\vec E + \frac{1}{c}\vec V_\alpha\times\vec B)+\nabla\cdot\mathbb{P}_\alpha = m_\alpha\int \vec v \left( \frac{\partial f_\alpha}{\partial t}\right)_\text{c}\dd^3 v \label{eq:firstmomentmotion} \end{align} The average electric and magnetic field in Eq. \eqref{eq:firstmomentmotion} are determined by both internal and external sources and fulfill the average Maxwell equations \begin{align} \nabla\cdot \langle \vec E \rangle &= 4\pi(\sum_\alpha n_\alpha q_\alpha + \rho_\text{ext})\\ \nabla\times \langle \vec E \rangle &= \frac{1}{c}\frac{\partial\langle \vec E \rangle }{\partial t} +\frac{4\pi}{c}\left(\sum_\alpha n_\alpha q_\alpha\vec{V}_\alpha + \vec{j}_\text{ext}\right)\\ \end{align} Because collisions transport momentum between different plasma species, the collision integral does not vanish, except for collisions between particles of the same species. The collision term is a complicated function of velocity. A useful approximation related to the Krook model is \begin{align} m_\alpha \int \vec v \left( \frac{\partial f_\alpha}{\partial t}\right)_\text{c}\dd^3 v = -\sum_\beta m_\alpha n_\alpha (\vec{V}_\alpha - \vec{V}_\beta)\langle v_{\alpha \beta}\rangle \end{align} where $\langle v_{\alpha \beta}\rangle$ is the average collision betewenn particles of type $\alpha$ and $\beta$. The second-order contributions $\vec{V}_\alpha \cdot \nabla\vec{V}_\alpha$ and $\mathbb{P}_\alpha$ arise from terms containing products $\vec v \vec v$ or $\vec v\cdot \vec v$. The divergence of $\mathbb{P}_\alpha$ contains information of imhomogeneity and viscosity of the plasma. Note that $\mathbb{P}_\alpha$ is not independent of the collisions. For example if the collisions are frequent enough, the pressure tensor becomes diagonal or even isotropic. Unfortunately the first moment equation contains the second moment of the distribution function (and this will go on forever\dots). The second moment of the Boltzmann equation can be calculated and the result will be presented here. But in most applications only the first two moments of the Boltzmann equation are used and the pressure tensor is replaced with a simple closure. Typically the pressure is assumed to be a scalar following an equation of state (isothermal, adiabatic, etc.). The second moment equation is called \emph{energy} or \emph{heat transport equation}. We can write the equation in the form \begin{align} \frac{3}{2}n_\alpha k_B \left( \frac{\partial T_\alpha}{\partial t}+\vec V_\alpha\cdot\nabla T_\alpha\right) +P_\alpha \nabla\cdot \vec V_\alpha =\\\nonumber -\nabla \cdot \vec H_\alpha-(\mathbb{P}_\alpha^\prime\cdot\nabla)\cdot\vec V-\frac{\partial}{\partial t}\left(\frac{n_\alpha m_\alpha V_\alpha^2}{2}\right) \end{align} where the isotropic part of the pressure $P_\alpha$ is written on the LHS and the non-isotropic part $\mathbb{P}_\alpha^\prime$. The third order term $\vec H_\alpha$ describes the \emph{heat flux}. An equation for this quantity is found by taking the third order moment of the Boltzmann equation. \subsection{Deriving MHD equations from the Boltzmann equation} \label{sec:1_5_3_mhd_from_boltzmann} So far we have derived macroscopic quantities and equations for each plasma species separately. The truncated series of equations can be used to set up a multi-fluid theory. Even in the presence of only one ion species and electrons it may be necessary to have more than two species, e.g., when different electron species with different temperature profiles exist. Our goal is now to find a simplified single-fluid theory. As a first step we will reduce the problem to a two-fluid theory: All electrons are one fluid, all ions together another fluid. These two fluids interact through electromagnetic interaction and collisions. \emph{Magnetohydrodynamics} (MHD) is probably the most widely known plasma theory. In MHD the plasma is considered as a single fluid in the center-of-mass (CM) frame. This a well-motivated approach in collision dominated plasmas, where the collisions constrain the plasma particles to follow each other closely and thermalize the distribution towards a Maxwellian, which makes the interpretation of velocity moments straightforward. MHD works also remarkably well in collisionless tenuous plasmas. However, great care should be exercised both with interpretation and approximations. The single fluid variables are defined as:\\ mass density \begin{align} \rho_\text{m}(\vec{r}, t) = \sum_\alpha n_\alpha m_\alpha \end{align} charge density \begin{align} \rho_\text{q}(\vec{r}, t) = \sum_\alpha n_\alpha q_\alpha \end{align} macroscopic velocity \begin{align} \vec V(\vec{r}, t) = \frac{ \sum_\alpha n_\alpha m_\alpha \vec V_\alpha}{ \sum_\alpha n_\alpha m_\alpha} \end{align} current density \begin{align} \vec J(\vec{r}, t) = \sum_\alpha n_\alpha q_\alpha \vec V_\alpha \end{align} and pressure tensor in the CM frame \begin{align} \mathbb{P}_alpha^\text{CM}(\vec{r}, t) = m_\alpha\int (\vec v- \vec V)(\vec v - \vec V) f_\alpha\dd^3 v \end{align} from which we get the total pressure \begin{align} \mathbb{P}^\text{CM}(\vec{r}, t) = \sum_\alpha \mathbb{P}_\alpha^\text{CM}(\vec{r}, t) \end{align} Summing the individual continuity and momentum transport equation over particle species yields the continuity equation equations \begin{align} \frac{\partial \rho_\text{m}}{\partial t}+ \nabla \cdot(\rho_\text{m} \vec V) &= 0\\ \frac{\partial \rho_\text{q}}{\partial t}+ \nabla \cdot\vec J &= 0 \end{align} and momentum transport equation \begin{align} \rho_\text{m}\left(\frac{\partial \vec V}{\partial t} +\vec V \cdot \nabla\vec V\right) = \rho_\text{q} \vec E +\vec J \times \vec B -\nabla\cdot\mathbb{P} \end{align} The momentum transport equation corresponds to the Navier-Stokes equation of hydrodynamics where the viscosity terms are written explicitly (here they are hidden in $\nabla\cdot\mathbb{P}$). At macroscopic level the deviations from charge neutrality are small and $\rho_\text{q} \vec E$ is usually negligible. The magnetic part of the Lorentz force $\vec J\times\vec B$ (sometimes called Amper\'e's force) is, however, essential in the theory of magnetic fluids. Ohm's law in fluid description is a more complicated issue. In the particle picture the plasma current is the sum of all charged particle motions. In a single-fluid theory the current transport equation is derived by multiplying the momentum transport equations of each particle population by $q_\alpha/m_\alpha$ and summing over all populations. In the two-fluid case (e, i) we get \begin{align} \pd{\vec J}{t} + \nabla \cdot (\vec V \vec J + \vec J \vec V - \vec V\vec V \rho_\text{q}) = \sum_\alpha\frac{n_\alpha q_\alpha^2}{m_\alpha} \vec E +\left(\frac{e^2}{m_e} + \frac{e^2}{m_i} \right)\frac{\rho_\text{m} \vec V \times\vec B}{m_e+m_i}\\\nonumber - \left( \frac{e m_i}{m_e} -\frac{e m_e}{m_i} \right)\frac{\vec J \times \vec B}{m_e+m_i} -\frac{e}{m_e}\nabla\cdot\left( \mathbb{P}_i^\text{CM}\frac{m_e}{m_i}-\mathbb{P}_i^\text{CM}\right) +\sum_\alpha\int q_\alpha \vec v \left( \frac{\partial f_\alpha}{\partial t}\right)_\text{c}\dd^3 v \label{eq:hannu_2_133} \end{align} where the products $\vec V \vec J$ etc., are cartesian tensors (dyads) with elements $V_i J_k$, and the divergence of a dyad is a vector, e.g. with components $\sum_i \partial_i V_i J_k$. This equation expresses the relationship between the electric current and the electric field. Thus it can be called \emph{generalized Ohm's law}. The first step to simplify Eq. \eqref{eq:hannu_2_133} is to approximate the collision integral introducing a constant collision frequency $\nu$ \begin{align} \sum_\alpha \int q_\alpha \vec v \left( \pd{f_\alpha}{t} \right)_\text{c}\dd^3 v = -\nu \vec J \end{align} Defining the \emph{conductivity } by $\sigma = n e^2/\nu m_e$ and neglecting all derivatives and the magnetic field in Eq. \eqref{eq:hannu_2_133} we get the familiar form of Ohm's law $\vec J = \sigma \vec E$. Not all terms in the generalized Ohm's law are equally important. There are some that clearly are small than others (e.g. $\propto m_e/m_i$). Furthermore, the derivatives of the second-order terms $\vec V \vec J$, $\vec J \vec V$ and $\vec V \vec V$ can usually be neglected. At this level we have the generalized Ohm's law in the form that contains the most important terms for space plasmas \begin{align} \vec E + \frac{1}{c}\vec{v}\times\vec{B} = \frac{\vec J}{\sigma}\times\vec B-\frac{1}{n e}\nabla\cdot\mathbb{P}_e+\frac{m_e}{n e^2}\pd{\vec J}{t} \label{eq:hannu_2_135} \end{align} Assume further so slow temporal change and large spatial gradient scales that $|\vec J\times\vec B|,\ |\partial \vec J/\partial t|$ and $|\nabla\cdot\mathbb{P}|$ are all smaller than $|\vec V\times\vec B|$. This leaves us with the standard form of Ohm's law in MHD \begin{align} \vec J = \sigma (\vec E +\frac{1}{c}\vec V \times \vec B) \end{align} which already familiar from elementary electrodynamics in cases, when moving frame are taken into account. Here the moving frame is attached to the fluid flow with the velocity $\vec V$. If the conductivity is very large, we find Ohm's law of the \emph{ideal MHD} \begin{align} \vec E +\frac{1}{c}\vec V \times \vec B=0 \end{align} The road from the Liouville or Klimontovich equations to this simple equation is long and there are several potholes on the road. For example, while the ideal MHD is a reasonable starting point, it is not all clear that the next term to take into account should be $\vec J/\sigma$. In many space applications the \emph{Hall term} $\vec J\times\vec B/n e c$ and the pressure term $\nabla\cdot\mathbb{P}/ n e$ are more important. \subsection{Simple approach: Adding terms to the equations of hydrodynamics} \label{sec:1_5_4_from_hydrodynamics} The approach using moments of the Boltzmann equation is instructive and allows for a microscopic derivation of Ohm's law, but is also very tedious. The different direction is to start with gas dynamics and add current and magnetic field. The equation of ordinary gas dynamics can be written as \begin{align} \pd{\rho}{t} &= - \nabla \cdot(\rho\vec V)\label{eq:fluidcont}\\ \rho\frac{\dd \vec V}{\dd t} &= -\nabla P +\nu \rho\nabla^2\vec V \label{eq:navierstokes}\\ \frac{\dd}{\dd t}(P\rho^{-\gamma}) &= 0 \end{align} where $\dd /\dd t = \partial/\partial t+ \vec V \cdot \nabla$ and $\gamma$ is the polytropic index. This set of five equations has five unknowns: density $\rho$, pressure $P$, and three velocity components. Equations \eqref{eq:navierstokes} are known as Navier-Stokes-equations, where $\nu$ is the viscosity. If viscosity can be neglected, as we often do in MHD, the equations are called Euler equations. Of these equations Eq. \eqref{eq:fluidcont} is given in \emph{conservative form} $\partial F/\partial t +\nabla\cdot \vec G = 0$, where $F$ is the conserved quantity and $\vec G$ is the corresponding flux quantity. Often, particularly when doing numerical fluid simulations in conservative systems, it is convenient to write the whole theory in terms of conserved quantities. In hydrodynamics this requires that Euler equations can be used instead of Navier-Stokes-equations (i.e., $\nu=0$) because viscosity causes dissipation, making the system non-conservative. The whole set of equations of conservative hydrodynamics can be formulated as \begin{align} \pd{\rho}{t} &= -\nabla\cdot \vec p\\ \pd{\vec p}{t} &= -\nabla\cdot\left( \frac{\vec p \vec p}{\rho} + P\mathbb{1} \right)\\ \pd{u}{t} &= -\nabla\cdot\left( (u+P)\frac{p}{\rho} \right) \end{align} where $\vec p = \rho \vec V$ is the momentum density (mass density flux), $\vec p \vec p$ denotes the direct product (dyad) with the components $p_i p_j$, $\mathbb{1}$ is the unit dyad, and $u$ the total energy density related to the pressure as \begin{align} u = \frac{p}{\gamma - 1} + \frac{\vec{p}^2}{2\rho} \end{align} $P/(\gamma-1)$ is the thermal energy density and $\vec{p}^2/2\rho$ is the kinetic energy density. Variables $(\rho, \vec V, P)$ are called \emph{primitive variables}, whereas $(\rho, \vec p, u)$ are \emph{conserved variables}. In MHD we must add Amper\'e's force $\vec J \times \vec B$ to the momentum equation \begin{align} \pd{\vec p}{t}= -\nabla\cdot\left( \frac{\vec p \vec p}{\rho} + P\mathbb{1} \right) + \frac{1}{c} \vec J\times\vec B \end{align} This is not yet the conservative form, but neglecting the displacement current as we normally do in MHD we can express Amp\'ere's force as \begin{align} \vec{J} \times \vec B = -\frac{c}{4\pi}\vec B\times (\nabla \times \vec B)=\frac{c}{4\pi}\left( -\nabla \left(\frac{B^2}{2} \right) +\nabla\cdot(\vec B \vec B)\right) \label{eq:koskinen69} \end{align} With this the momentum equation can be written in the conservative form \begin{align} \pd{\vec p}{t}= -\nabla\cdot\left( \frac{\vec p \vec p}{\rho} + \left(P\mathbb{1} + \frac{\vec{B}^2}{8\pi} \right) - \frac{1}{4\pi}\vec B \vec B\right) \end{align} Thus the momentum of the magnetic field is taken care of in a natural way. The magnetic field is now split into a magnetic tension ($\vec B \vec B$) and a magnetic pressure ($B^2$). The energy equation is automatically conservative. However, it is instructive to write it in the form that explicitly illustrates the conservation of total energy density $u$ in the same way as in gas dynamics. This is straightforward to do because the magnetic energy density is $B^2/8\pi$. Thus \begin{align} u = \frac{P}{\gamma - 1}+\frac{\vec{p}^2}{2\rho} + \frac{B^2}{8\pi} \end{align} and the energy equation can be written as \begin{align} \pd{u}{t} = -\nabla\cdot\left( \left( u + P - \frac{\vec{B}^2}{8\pi} \right) \frac{\vec p}{\rho} + \frac{1}{4\pi \rho} \vec B\times(\vec p \times \vec B) \right) \end{align} We need one more equation to describe the time evolution of the magnetic field. Because we are now interested in conservative MHD, we must limit the discussion to the ideal MHD case, where $\vec E = -\vec V \times \vec B$. Inserting this into Faraday's law we get \begin{align} \pd{\vec B}{t}=\nabla\times(\vec V \times \vec B) \end{align} which after replacing $\vec V$ by the conserved quantity $\vec p$ reads \begin{align} \pd{\vec B}{t} = \nabla \times \left(\frac{\vec p}{\rho}\times\vec{B}\right) \end{align} Now we have the complete set of 8 equations for 8 conservative variables $(\rho, \vec p, u, \vec B)$ of the ideal MHD. \chapter{Plasma-Astrophysics and where to find it} \section{The Sun and other stars} \begin{figure} \begin{center} \pgfimage[width=0.7\textwidth]{fig_chapter2/solar_plasmas} \end{center} \caption{ALMA image of the ISM \url{https://www.plasmacoalition.org/plasma_writeups/solar_plasmas.pdf} } \label{fig:solar_plasmas} \end{figure} The Sun is in first place a fully ionized ball of gas. This could lead to the conclusion that the Sun is a pure plasma phenomenon. This is not completely true: In the core collisions are so frequent that the collective behaviour \begin{figure} \begin{center} \pgfimage[width=0.7\textwidth]{fig_chapter2/plasma-parameters-sun} \end{center} \caption{Plasma parameters of the Sun \url{https://www.researchgate.net/figure/Plasma-parameters-and-magnetic-field-in-Sun-4_tbl1_312016940/download} } \label{fig:plasma-sun} \end{figure} In the convection zone we find plasmas that can be well described by MHD theory, this holds to some degree also in the corona. In the corona we find also a larger number of nonthermal particles accelerated in solar energetic particle events or coronal mass ejections. Coronal mass ejections (CME) will most likely not encounter collisions (mean free path of a proton is about 1 AU!) and therefore they are typically described as kinetic plasma. \section{Interplanetary medium} The Sun has an open atmosphere, i.e., particles are constantly streaming out. This particle stream is called the solar wind and consists mainly of protons and electrons. The wind is more or less collisionless and its density is decreasing outwards. \begin{figure} \begin{center} \pgfimage[width=.7\textwidth]{fig_chapter2/ramigramm} \end{center} \caption{Profiles of solar wind speed (dash-dotted curves), Alfv´en speed (dashed curves), and number density (solid curves). The thick [thin] curves result from our slow [fast] solar wind model. A fit to the observational equatorial electron densities is denoted by crosses (Vainio et al., 2003).} \end{figure} One of the most interesting features of the solar wind is the termination shock, the interface between the interstellar and interplanetary medium. Here shocks can be found, where cosmic are rays are accelerated or reflected. \begin{figure} \begin{center} \pgfimage[width=.7\textwidth]{fig_chapter2/heliosphere} \end{center} \caption{Artist's impression of the heliosphere} \end{figure} \section{Earth's magnetosphere} Earth's magnetosphere is the special case of the solar wind hitting a planetary body that has a magnetic field. The shape of the Earth's magnetosphere is the direct result of being blasted by solar wind. The solar wind compresses its sunward side to a distance of only 6 to 10 times the radius of the Earth. A supersonic shock wave is created sun-ward of Earth called the Bow Shock. Most of the solar wind particles are heated and slowed at the bow shock and detour around the Earth in the Magnetosheath. The solar wind drags out the night-side magnetosphere to possibly 1000 times Earth's radius; its exact length is not known. This extension of the magnetosphere is known as the Magnetotail. The outer boundary of Earth's confined geomagnetic field is called the Magnetopause. The Earth's magnetosphere is a highly dynamic structure that responds dramatically to solar variations. Also residing within the magnetosphere are areas of trapped charged particles; the inner and outer Van Allen Radiation Belts, the Plasmasphere and the Plasmasheet. \begin{figure} \begin{center} \pgfimage[width=.7\textwidth]{fig_chapter2/magnetosphere} \end{center} \caption{Artist's impression of the magnetosphere (NASA)} \end{figure} Of special interest is the interaction of the solar wind with the magnetosphere when violent events take place on the Sun. The following storm may lead to strong effects even on Earth's surface (the aurora borealis being one of mildest phenomena). The so-called space weather is one of the fields in space research that has a direct economic influence. Current simulations of plasmas in this area are performed using hybrid simulations (electrons are a fluid, ions are particles). \section{The interstellar medium} \begin{figure} \begin{center} \pgfimage[width=0.7\textwidth]{fig_chapter2/alma} \end{center} \caption{ALMA image of the ISM \url{https://astrochem.iff.csic.es/interstellar-medium/} } \label{fig:alma_ism} \end{figure} The interstellar medium takes up the largest part of the volume of our galaxy. It is basically everywhere a plasma with a significant background field. Cosmic rays can be found anywhere in the ISM as nonthermal component. A very rough estimate shows that in kinetic energy, magnetic field and cosmic rays the energy density is on the order of 1 erg/cm$^{-3}$. Depending on the scientific question hydrodynamic (structure formation), magnetohydrodynamic (particle transport and shocks) or kinetic (particle acceleration and shocks) simulation techniques are used. Properties of the interstellar medium \begin{itemize} \item densities: $n \approx 10^{-3} - 10^5$ cm$^{-3}$ \item temperatures: $T \approx 10 - 10^6$ K \item composition: \item ca. 10\% of the visible matter in the Galaxy \item mass: $\approx$ 70\% hydrogen (HI, HII, H 2) + 28\% He + ``metals'' (C, N, O, Ne, Na, Mg, S, Si, \dots) + dust (ca. 1\% of the ISM mass) \item number of atoms: $\approx$ 90\% hydrogen + 10\% He + ``metals'' \item ionised and neutral atomic gas, ionization rate 1 - 100 \% \end{itemize} \begin{figure} \begin{center} \pgfimage[width=0.7\textwidth]{fig_chapter2/mckee_and_ostriker} \end{center} \caption{Phases of the ISM according to McKee and Ostriker} \label{fig:mckee_ostriker} \end{figure} \section{The intergalactic medium} The intergalactic medium resembles to some extent the hot-interstellar medium, only thinner and hotter ($n\approx 10^{-9}$ cm$^{-3}$, $T \approx 10^5 - 10^7$ K). One important difference is the absence of a strong background magnetic field. Measurements of the magnetic field strength are complicated, but recently (Neronov\& Vovk) a combination of plasma simulations and gamma-ray observations has been used to calculate an estimate for the magnetic field strength. \section{Supernovae} Supernovae are a prime example of expanding hot plasma into a cold and dense medium. Typically the temperature of the plasma is well above $10^6$ K and expansion speeds are clearly supersonic. \begin{figure} \begin{center} \pgfimage[width=0.7\textwidth]{fig_chapter2/crab} \end{center} \caption{The crab nebula} \label{fig:crab} \end{figure} As supernova explosions have different stages different plasma descriptions and simulation techniques are relevant. Especially the very early stages where nuclear processes will still take place a simple ansatz is not possible. For later stages either kinetic simulations (allowing for particle acceleration) or fluid approaches (modeling shock fronts at very late stages) are used. \section{Accretion discs and jets} Accretion discs can form around black holes. These accretion discs are typically very hot plasmas, which are governed in the inner part not only by plasma physics but also by general relativity. Frame dragging and other effects play a major role. \begin{figure} \begin{center} \pgfimage[width=0.7\textwidth]{fig_chapter2/m87} \end{center} \caption{The Active Galactic Nucleus M87 with its jet extending to 10 kpc} \label{fig:m87} \end{figure} In, e.g., Active Galactic Nuclei (AGN) jets are launched from black holes. These jets can reach several parsec in length. The process of jet launching is not fully understood, but the models involved are typically a combination of general relativity, plasma physics and particle physics (here: electron-positron pair creation from high luminosities). Most jet plasma simulations are based purely on MHD (for the sake of simplicity). Since AGN jets are a prime source of (ultra-high energy) cosmic rays kinetic models of shock waves in jets are also of utmost importance. \chapter{N-body codes and general ideas of numerical methods} In the previous chapter we have introduced a number of different concepts for the description of plasmas. From a physics viewpoint the main distinction here is between kinetic and fluid descriptions. Both descriptions can be cast into a hyperbolic conservation law (the prime example for this is the Navier-Stokes equation - a fluid description). In terms of fluid dynamics two different viewpoints for the equations have been established: \begin{itemize} \item Lagrange picture: We follow a fluid element and changes are given by the material derivative \item Euler picture: We look at a fixed point in space and a fluid flows through the volume. \end{itemize} \begin{figure} \begin{center} \pgfimage[width=.9\textwidth]{fig_chapter3/euler-lagrange} \end{center} \end{figure} The derivatives are linked to each other like this \begin{align} \diffp{}{t} + \vec v \cdot \nabla = \frac{D}{D t} \end{align} For essentially any numerical scheme describing actual fluids the Euler picture is used. If we go back to our different descriptions of plasmas we see that kinetic descriptions of a plasma can be given as single particles. This would be the Lagrangian viewpoint! The distinction in plasma physical simulations is more on the line of particle- and mesh-methods. The main branches are pure mesh methods (e.g., MHD simulations) and particle-mesh methods (e.g., particle-in-cell). In first place we will now focus on pure particle methods. This is typically not used for plasma simulations. The reason behind this is simple: In pure particle methods the interaction is calculated between each particle with every other, but plasmas actually shield long range interactions. A typical application are \emph{N-body codes} used for gravitational simulations. In order to discuss some general ideas and concepts, we will look into these N-body codes anyway! \section{Simple approach to N-body} We want to calculate the evolution of a system of particles that interact with each other through gravity. A very naive interpretation of an N-body code looks like this \begin{itemize} \item Build a list of particles with mass, position and velocity \item Iterate through the particle list \item Calculate the distance to each other particle and the associated force \item Update the velocity from the force \item Update the position from the velocity \end{itemize} This looks nice since it's a very simple approach, but actually everything's bad. The algorithm is $\mathcal{O}(N^2)$ with respect to the particle number and it is numerically unstable. We are actually using a ``forward Euler'' scheme here \begin{align} \vec{r}_i^{n+1} &= \vec{r}_i^n+\Delta t\cdot \vec{v}_i^{n}\\ \vec{v}_i^{n+1} &= \vec{v}_i^n+\Delta t\cdot \vec{a}_i^{n}\\ \vec{a}_i^n &= \sum_{j\neq i}G \frac{m_i m_j}{m_i} \frac{\vec{r}_i^n - \vec{r}_j^n}{|\vec{r}_i^n - \vec{r}_j^n|^3} \end{align} The Euler scheme requires very small time steps (this is bad\dots) A first improvement to such a scheme is the so called \emph{Leapfrog}: We define positions at time $t^n, t^{n+1}, t^{n+2},\dots$ and velocities at $t^{n-1/2}, t^{n+1/2}, t^{n+3/2},\dots$ \begin{align} \vec{r}^n &= \vec{r}^{n-1}+\Delta t \cdot \vec{v}^{n-1/2} \\ \vec{v}^{n+1/2} &= \vec{v}^{n-1/2} + \Delta t \cdot \vec{a}^n \end{align} The initial condition is $\vec{v}^{1/2} = \vec{v}^{0} + 1/2 \Delta t \cdot \vec{a}^0$. The shift between position and velocity by a half timestep changes the stability drastically and makes the whole scheme 2nd order. But what does that mean? \section{Numerics - the general idea} Let us assume the following \begin{itemize} \item $u^n$ is the numerical solution of a given problem at time $t^n$ \item $u_e^n$ is the exact solution of a given problem at time $t^n$ (which is unknown for any interesting problem) \item $L$ is the operator of a numerical scheme (this is typically a linear operator that yiels $u^{n+1} = L u^n$ \end{itemize} From these definitions we may now derive the following terms (the norm $||\dots||$ is typically the $L_2$ norm, but that does not matter too much) \subsection{Consistency and order} For a numerical solution we may define \begin{align} || u^n - u^n_e|| = \epsilon(\Delta x, \Delta t) = \mathcal{O}((\Delta x)^p, (\Delta t)^q) \end{align} In order for a numerical scheme to be \emph{consistent} the numerical solution must converge to the exact solution, when $\Delta x$ and $\Delta t$ go to 0. The constants $p$ and $q$ are called the order of the scheme. The \emph{local truncation error} \begin{align} LTE = u_e^{n+1} - L u_e^n \end{align} is also defined. It is a measure on the amount of deviation one step produces. \subsection{Stability} If we look at \begin{align} || L u_e^n - L u^n|| \leq k ||u_e^n -u^n|| \end{align} we see that there should be a bound on growth of the error of a numerical scheme. Using harmonic analysis (which we will do later), one can determine this growth factor. In real life it means that the ``energy'' of the numerical solution should not grow without physical cause. In fact the $L_2$ norm is related to the energy. \subsection{Convergence} A numerical scheme that has consistency and stability is called \emph{convergent}. \section{Return to N-body} We have discussed the Leapfrog scheme as a solution for the N-body problem. Can we do better than the 2nd order there? Easily: We can use the Hermite scheme \begin{align} \vec{r}^{n+1} &= \vec{r}^n +\frac{1}{2}(\vec{v}^n + \vec{v}^{n+1}) \Delta t + \frac{1}{12}(\vec{a}^n - \vec{a}^{n+1})(\Delta t)^2\\ \vec{v}^{n+1} &= \vec{v}^n +\frac{1}{2}(\vec{a}^n + \vec{a}^{n+1}) \Delta t + \frac{1}{12}(\vec{j}^n - \vec{j}^{n+1})(\Delta t)^2 \end{align} where $j$ is the so called jerk \begin{align} \vec{j} = \diff{^3}{t^3} \vec r \end{align} which can be calculated as \begin{align} \vec{j}^n = \sum_{i\neq j} \left( \frac{\vec{v}_j^n-\vec{v}_i^n}{\vec{r}_{ij}^3} - 3 \frac{(\vec{r}_j^n \cdot \vec{v}_j^n)\vec{r}_j^n}{\vec{r}_{ij}^5} \right) \end{align} This scheme is of higher order than the Leapfrog. That itself is not too interesting. It is much more interesting to figure out, how this scheme is derived and how it works. Before we go into the derivation, here are some definitions \begin{align} \vec s = \diff{^4}{t^4} \vec r, \quad \vec c = \diff{^4}{t^4} \vec c, \quad \vec p = \diff{^6}{t^6} \vec r \end{align} Now we can go into the Taylor expansion of the position \begin{align} \vec{r}^{n+1} &= \vec{r}^n + \vec{v}^n \Delta t + \frac{1}{2} \vec{a}(\Delta t)^2 + \frac{1}{6}\vec{j}^n(\Delta t)^3 + \frac{1}{24} \vec{s}^n (\Delta t)^4 + \frac{1}{120} \vec{c}^n (\Delta t)^5\\ \vec{v}^{n+1} &= \vec{v}^n + \vec{a}^n \Delta t + \frac{1}{2} \vec{j}(\Delta t)^2 + \frac{1}{6}\vec{s}^n(\Delta t)^3 + \frac{1}{24} \vec{c}^n (\Delta t)^4 \\ \vec{a}^{n+1} &= \vec{a}^n + \vec{j}^n \Delta t + \frac{1}{2} \vec{s}(\Delta t)^2 + \frac{1}{6}\vec{c}^n(\Delta t)^3\\ \vec{j}^{n+1} &= \vec{j}^n + \vec{s}^n \Delta t + \frac{1}{2} \vec{c}(\Delta t)^2 \end{align} Now one can eliminate $\vec{c}^n$ and $\vec{s}^n$ \begin{align} \vec{s}^n &= 6 (\vec{a}^{n+1}-\vec{a}^n)(\Delta t)^{-2} - 2(\vec{j}^{n+1}+2\vec{j}^n)(\Delta t)^{-1}\\ \vec{c}^n &= -12(\vec{a}^{n+1}-\vec{a}^n)(\Delta t)^{-3} +6(\vec{j}^{n+1}+\vec{j}^n)(\Delta t)^{-2}\\ \Rightarrow \vec{v}^{n+1} &= \vec{v}^n +\frac{1}{2}(\vec{a}^n + \vec{a}^{n+1}) \Delta t + \frac{1}{12}(\vec{j}^n - \vec{j}^{n+1})(\Delta t)^2 \end{align} So what do we learn from this? One can perform a Taylor expansion to higher order (every good physicist should do that!) and solve for the updated values at $t^{n+1}$. On the one hands a looks a bit lengthy, but solvable. That first impression is so wrong! In order to solve the equations for the next time step we need knowledge about quantities from that future time. This is not too uncommon, there are actually many applications for such \emph{implicit} schemes and as a rule of thumb implicit schemes are far more stable. How do we solve these implicit equations then? There are basically two approaches: \begin{itemize} \item We can treat the equation as a matrix equation (the numerical scheme in discretized quantities can be viewed as a linear operator), which can inverted. There are exact and approximate inversion techniques, the latter being the faster. \item We can use predictor/corrector schemes, where we take a guess for the next time step and then correct this approximation. \end{itemize} We will discuss matrix methods later (especially in the context of the Poisson equation). Let's shortly discuss how such a predictor-corrector scheme looks like (there are several different types on the market with slightly different properties). Predictor \begin{align} \vec{v}_p^{n+1} &= \vec{v}^n + \vec{a}^n \Delta t + \frac{1}{2} \vec{j}^n (\Delta t)^2\\ \vec{r}_p^{n+1} &= \vec{r}^n + \vec{v}^n \Delta t + \frac{1}{2} \vec{a}^n (\Delta t)^2 +\frac{1}{6}\vec{j}^n(\Delta t)^3 \end{align} where we can now calculate the acceleration and jerk using these predicted values \begin{align} \vec{a}_p^{n+1} = \vec{a}(t^{n+1},\vec{r}_p^{n+1}),\quad \vec{a}_p^{n+1} = \vec{j}(t^{n+1},\vec{r}_p^{n+1},\vec{v}_p^{n+1}) \end{align} Now we can apply the corrector \begin{align} \vec{v}_c^{n+1} &= \vec{v}_p^{n+1} + \frac{1}{6} \ddot\vec{a}^n(\Delta t)^3 + \frac{1}{24}\dddot{\vec{a}}(\Delta t)^4\\ \vec{r}_c^{n+1} &= \vec{r}_p^{n+1} + \frac{1}{24} \ddot\vec{a}^n (\Delta t)^4 + \frac{1}{120}\dddot{\vec{a}}(\Delta t)^5 \end{align} with \begin{align} \frac{1}{2} \ddot\vec{a}^n &= -3 \frac{\vec{a}^n-\vec{a}^{n+1}_p}{(\Delta t)^2}-\frac{\dot\vec{a}^n+\dot\vec{a}_p^{n+1}}{\Delta t}\\ \frac{1}{6} \dddot{\vec{a}}^n &= 2 \frac{\vec{a}^n-\vec{a}^{n+1}_p}{(\Delta t)^3}-\frac{\dot\vec{a}^n+\dot\vec{a}_p^{n+1}}{(\Delta t)^2} \end{align} \section{The Barnes-Hut algorithm} We have started solving the N-body problem in probably the most naive way: Using a forward-Euler step with direct forces between each particle pair. This is unstable - which has been resolved using Leapfrog or higher-order schemes - but we are still left with a $\mathcal{O}(N^2)$ algorithm. One idea to resolve this problem is to simplify the interactions: Far away clusters of masses cannot be distinguished from a single mass point. So why not use the center of mass?\footnote{Some of the following text is stolen from Wikipedia. As we are not diving too deep into the matter the description there is sufficient.} The ``Barnes–Hut simulation'' (named after Josh Barnes and Piet Hut) is an approximation algorithm for performing an N-body simulation. It is notable for having $\mathcal{O}(n \log n)$ compared to a direct-sum algorithm which would be $\mathcal{O}(N^2)$. The simulation volume is usually divided up into cubic cells via an octree (in a three-dimensional space), so that only particles from nearby cells need to be treated individually, and particles in distant cells can be treated as a single large particle centered at the cell's center of mass. This can dramatically reduce the number of particle pair interactions that must be computed. \subsection{The Barnes–Hut tree} In a three-dimensional N-body simulation, the Barnes–Hut algorithm recursively divides the $N$ bodies into groups by storing them in an octree (or a quadtree in a 2D simulation). Each node in this tree represents a region of the three-dimensional space. \begin{figure} \begin{center} \pgfimage[width=.8\textwidth]{fig_chapter3/quadtree} \end{center} \caption{A quadtree representation of 100 particles using the Barnes-Hut algorithm} \end{figure} The topmost node represents the whole space, and its eight children represent the eight octants of the space. The space is recursively subdivided into octants until each subdivision contains 0 or 1 bodies (some regions do not have bodies in all of their octants). There are two types of nodes in the octree: internal and external nodes. An external node has no children and is either empty or represents a single body. Each internal node represents the group of bodies beneath it, and stores the center of mass and the total mass of all its children bodies. \begin{figure} \begin{center} \pgfimage[width=.45\textwidth]{fig_chapter3/2galaxies}\hspace{5mm} \pgfimage[width=.45\textwidth]{fig_chapter3/2galaxies_tree} \end{center} \caption{Mass distribution of two neighbouring galaxies and the representation using the Barnes-Hut tree} \end{figure} \subsection{Calculating the force acting on a body} To calculate the net force on a particular body, the nodes of the tree are traversed, starting from the root. If the center of mass of an internal node is sufficiently far from the body, the bodies contained in that part of the tree are treated as a single particle whose position and mass is respectively the center of mass and total mass of the internal node. If the internal node is sufficiently close to the body, the process is repeated for each of its children. Whether a node is or isn't sufficiently far away from a body, depends on the quotient $s/d$, where $s$ is the width of the region represented by the internal node, and $d$ is the distance between the body and the node's center of mass. The node is sufficiently far away when this ratio is smaller than a threshold value $\Theta$. The parameter $\Theta$ determines the accuracy of the simulation; larger values of $\Theta$ increase the speed of the simulation but decreases its accuracy. If $\Theta = 0$, no internal node is treated as a single body and the algorithm degenerates to a direct-sum algorithm. \section{Fast Multipole Method} Another approach at getting around the pairwise evaluation of interactions is the Fast Multipole Method. Multipole expansions are already known from electrodynamics lectures: Instead of calculating the interaction of a single charge with a complex charge distribution spherical harmonics are calculated for that charge distribution and the interaction with the leading terms can be calculated. The potential of a cell with masses can be written as \begin{align} \Phi(\vec r) &= \sum_{l=0}^\infty \sum_{m=-l}^l \frac{M_l^m}{} Y_{lm}(\Theta,\varphi)\\ M_l^m &= \sum_{i=1}^k m_i \rho_i^l Y_{lm}^* (\alpha_i,\beta_i) \end{align} where $\rho, \alpha, \beta$ are the positions within the cell. Now one starts with an idea similar to Barnes-Hut: The mass distribution is split into a tree. Depending on the distance we have either multipole-multipole or local interaction. With intelligent tree splitting and cluster finding this method can drive the complexity of the problem down to $\mathcal{O}(N)$. The Fast Multipole Method is considered one of the top 10 algorithms. For plasma simulations, however, its use is extremely limited as charge shielding is dominating. \section{Poisson equation} The next chapter will focus on the Particle-in-Cell method, which is a \emph{Particle-Mesh-Method}. It should be pointed out that the gravitational problem can also be solved using a PM-approach: Instead of calculating the force between particle pairs we can work out the gravitational potential of masses \begin{align} \nabla \vec g &=-\nabla \cdot (\nabla \Phi_\mathrm m(\vec r)) = -4 \pi \cdot G \cdot \rho_\mathrm m(\vec r)\\ \Leftrightarrow \Delta \Phi_\mathrm m(\vec r)& = 4 \pi \cdot G \cdot \rho_\mathrm m(\vec r) \end{align} This opens up two questions: \begin{itemize} \item How do we figure out $\rho_\mathrm{m}$? \item How do we solve the Poisson equation? \end{itemize} The first question will be addressed in great depth in the next chapter - for now we will just assume the so-called \emph{Nearest Grid Point} method: On a grid the mass of particle will be deposited at the nearest point of the mesh. The second question is far more complicated. It all starts with a discretization of the Poisson equation. Using the finite difference numerical method to discretize the 2-dimensional Poisson equation (assuming a uniform spatial discretization, $\Delta x=\Delta y$) on a $m\times n$ grid gives the following formula: \begin{align} {\nabla}^2 u )_{ij} &= \frac{1}{\Delta x^2} (u_{i+1,j} + u_{i-1,j} + u_{i,j+1} + u_{i,j-1} - 4 u_{ij}) = g_{ij} \end{align} This will result in an $mn \times mn$ linear system: \begin{align} A\mathbf{u} = \mathbf{b} \end{align} where \begin{align} A = \begin{bmatrix} ~D & -I & ~0 & ~0 & ~0 & \cdots & ~0 \\ -I & ~D & -I & ~0 & ~0 & \cdots & ~0 \\ ~0 & -I & ~D & -I & ~0 & \cdots & ~0 \\ \vdots & \ddots & \ddots & \ddots & \ddots & \ddots & \vdots \\ ~0 & \cdots & ~0 & -I & ~D & -I & ~0 \\ ~0 & \cdots & \cdots & ~0 & -I & ~D & -I \\ ~0 & \cdots & \cdots & \cdots & ~0 & -I & ~D \end{bmatrix}, \end{align} $ I $ is the $m \times m$ identity matrix, and $D$, also $m \times m$, is given by: \begin{align} D = \begin{bmatrix} ~4 & -1 & ~0 & ~0 & ~0 & \cdots & ~0 \\ -1 & ~4 & -1 & ~0 & ~0 & \cdots & ~0 \\ ~0 & -1 & ~4 & -1 & ~0 & \cdots & ~0 \\ \vdots & \ddots & \ddots & \ddots & \ddots & \ddots & \vdots \\ ~0 & \cdots & ~0 & -1 & ~4 & -1 & ~0 \\ ~0 & \cdots & \cdots & ~0 & -1 & ~4 & -1 \\ ~0 & \cdots & \cdots & \cdots & ~0 & -1 & ~4 \end{bmatrix}, \end{align} and $\mathbf{b}$ is defined by \begin{align} \mathbf{b} = -\Delta x^2 \begin{bmatrix} g_{11} , g_{21} , \ldots , g_{m1} , g_{12} , g_{22} , \ldots , g_{m2} , \ldots , g_{mn} \end{bmatrix}^\mathsf{T} \end{align} For further discussions it is helpful to break this down to the 1D Poisson equation \begin{align} \frac{1}{(\Delta x)^2} \begin{pmatrix} -2 & 1 & & & \\ 1 & -2 & 1& & \\ & & \ddots & &\\ & & & 1 & -2 \end{pmatrix} \begin{pmatrix} u_1 \\ u_2 \\ \vdots \\ u_N \end{pmatrix} \begin{pmatrix} f_0 \\ f_1 \\ \vdots \\ f_{N-1} \end{pmatrix} \end{align} One can of course try to solve for the inverse of the matrix, but that is insane in terms of computation time. Instead one wants to go for an iterative solver to yield an approximate solution. The Gauss-Seidel algorithm is such a technique for solving a square system of $n$ linear equations with unknown $x$: \begin{align}A\mathbf x = \mathbf b .\end{align} It is defined by the iteration \begin{align} L_* \mathbf{x}^{(k+1)} = \mathbf{b} - U \mathbf{x}^{(k)}, \end{align} where $\mathbf{x}^{(k)}$ is the $k$th approximation or iteration of $\mathbf{x}$, $\mathbf{x}^{(k+1)}$> is the next or $k + 1$ iteration of $\mathbf{x}$, and the matrix $A$ is decomposed into a lower triangular component $L_*$, and a strictly upper triangular component $U$ i.e., $A = L_* + U$ In more detail, write out $A$, $x$ and $b$ in their components: \begin{align} A=\begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\a_{n1} & a_{n2} & \cdots & a_{nn} \end{bmatrix}, \qquad \mathbf{x} = \begin{bmatrix} x_{1} \\ x_2 \\ \vdots \\ x_n \end{bmatrix} , \qquad \mathbf{b} = \begin{bmatrix} b_{1} \\ b_2 \\ \vdots \\ b_n \end{bmatrix}. \end{align} Then the decomposition of $A$ into its lower triangular component and its strictly upper triangular component is given by: \begin{align} A& =L_*+U \qquad \text{where} \qquad \\ L_* &= \begin{bmatrix} a_{11} & 0 & \cdots & 0 \\ a_{21} & a_{22} & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\a_{n1} & a_{n2} & \cdots & a_{nn} \end{bmatrix},\\ U &= \begin{bmatrix} 0 & a_{12} & \cdots & a_{1n} \\ 0 & 0 & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\0 & 0 & \cdots & 0 \end{bmatrix}. \end{align} The system of linear equations may be rewritten as: \begin{align} L_* \mathbf{x} = \mathbf{b} - U \mathbf{x} \end{align} The Gauss–Seidel method now solves the left hand side of this expression for $x$, using previous value for $x$ on the right hand side. Analytically, this may be written as: \begin{align} \mathbf{x}^{(k+1)} = L_*^{-1} \left(\mathbf{b} - U \mathbf{x}^{(k)}\right). \end{align} However, by taking advantage of the triangular form of $L_*$, the elements of $x^{k+1}$ can be computed sequentially using forward substitution: \begin{align} x^{(k+1)}_i = \frac{1}{a_{ii}} \left(b_i - \sum_{j=1}^{i-1}a_{ij}x^{(k+1)}_j - \sum_{j=i+1}^{n}a_{ij}x^{(k)}_j \right),\quad i=1,2,\dots,n. \end{align} How does this very theoretical approach now look like when applied to the Poisson equation? In 2D we can formulate the finite-difference equation as \begin{align} \frac{u_{ij+1}-2u_{ij}+u_{ij-1}}{(\Delta x)^2} + \frac{u_{i+1j}-2u_{ij}+u_{i-1j}}{(\Delta x)^2} = f_{ij} \end{align} An iterative solution looks now like \begin{align} u_{ij}^{n+1} = \frac{1}{4}(u_{ij+1}^n + u_{i+1j}^n + u_{ij-1}^{n+1} + u_{i-1j}^{n+1} + (\Delta x)^2 f_{ij}) \end{align} This Gauss-Seidel algorithm uses updated values of the solution $u$. This is somewhat advantageous in terms of memory usage, but otherwise pretty slow. A slighlty updated version of the Gauss-Seidel scheme is the \emph{Red-Black} scheme: Points are alternating red or black. The update runs over red points first, after all red points are updated, the black points will be updated. The main advantage is that the update only relies on old points (which allows for parallelization). While the scheme is extremely simple, it is also horribly slow. One way to speed up things is the \emph{successive over-relaxation}. For \begin{align} A x = f \Rightarrow A = D + L + U \end{align} Where $D$ is the diagonal matrix and $L$ and $U$ are the strictly lower and upper matrix respectively. The relaxation now looks like \begin{align} (D+\omega L) x = \omega f -(\omega U+(\omega-1)D) x \end{align} Where $\omega > 0$ with $\omega=1$ being the Gauss-Seidel case \begin{align} x^{k+1} = (D+\omega L)^{-1}(\omega f - (\omega U + (\omega -1) D)x^k) \end{align} Making use of matrix structure then yields \begin{align} x_i^{k+1} = (1-\omega) x_i^k + \frac{\omega}{a_{ii}}(f_i - \sum{j>i} a_{ij}x_j^k-\sum_{j1$ yields faster convergence and $\omega<1$ yields convergence safely. Another scheme used typically is the Jacobi scheme \begin{align} A x =f \Rightarrow A = D + R\\ x^{k+1} = D^{-1} (f-R x^k) \end{align} \subsection{Multigrid} If one looks at previous methods one will notice that methods like Gauss-Seidel are correct on smallest scale, but tend to deviate from the correct solution when larger scales are involved. This is due to the fact that the update only relies on the neighbouring points. Before we discuss a strategy to circumvent this problem we need to discuss some terms. We are looking for the correct solution $u$ (which we may or maybe not reach) and approximate this by the iteration $u^n$. The difference these two is the error \begin{align} e = u^n - u \end{align} Again: If we knew the error we would also know the real solution. We will never know the real solution\dots What we know is the residual \begin{align} r = f - A u^n \end{align} But since for the exact solution we know \begin{align} A u = f \end{align} we have \begin{align} f - A u^n = A (u-u^n ) = r \end{align} Coming back to the original problem: How can we improve our solution on larger levels? One is the so-called Multigrid scheme: Instead of using one fixed grid the data is sampled grids with different resolutions. The ``original'' grid is the finest grid and data is coarsened from there on. Using the notation ``superscript describes the coarseness of the grid'' (i.e., $u^n$ is an approximate solution on the finest grid, while $u^{2n}$ is the approximate solution on a grid with double spacing) we need the following ingredients \begin{itemize} \item A restriction matrix $R^h_{2h}$ transfers vectors from the fine grid to the coarse grid. \item The return step to the fine grid is by an interpolation matrix $I = I^h_{2h}$. \end{itemize} Possible interpolation: \begin{align} u_{2i,2j} = v_{i,j},\quad u_{2i,2j+1} = \frac{1}{2}(v_{i,j}+v_{i,j+1} \end{align} The restriction is essentially the inversion of this. A simple two grid v-cycle looks like this \begin{enumerate} \item Iterate on $A^h u = b^h$ to reach $u^h$ (say 3 Jacobi or Gauss-Seidel steps). \item Restrict the residual $r^h = b^h -A^h u^h$ to the coarse grid by $r^{2h} = R^{2h}_h r^h$. \item Solve $A^{2h} e^{2h} = r^{2h}$ (or come close to $e^{2h}$ by 3 iterations from $e = 0$). \item Interpolate $e^{2h}$ back to $e^h = I^h_{2h} e_{2h}$. Add $e^h$ to $u^h$. \item Iterate 3 more times on $A^h u = b^h$ starting from the improved $u^h + e^h$ \end{enumerate} Here we solve the Poisson equation on a fine grid and one coarser grid. This scheme can be extended to ever finer grids. \begin{figure} \begin{center} \pgfimage[width=.7\textwidth]{fig_chapter3/multigrid} \end{center} Grapical representation of the multigrid cycle \end{figure} \chapter{Particle-in-Cell} While plasmas with a nonthermal component could be described using numerical standard techniques for hyperbolic conservation laws, the so-called Particle-in-Cell (PiC) technique has become the standard technique for many plasma simulations. PiC is a versatile and extremely easy to implement method, which is the main factor behind its popularity. The relatively low computational cost is the next point making PiC such a common choice. Unfortunately this simplicity leads often to carelessness in implementation and simulation design. This chapter shall give a brief introduction to the physics of kinetic plasmas, the setup of PiC codes, implementation details and the design of simulations of various physical effects. \section{Numerical Implementation} \label{sec:num} Particle-in-Cell codes are semi-Lagrangian in that they follow a Lagrangian description of phase space samples represented as macro particles coupled to electromagnetic fields described in an Eulerian way on a grid. Connecting the two parts correctly is crucial in the numerical implementation, but let us start with the relatively simple step of evolving the electric and magnetic fields on the grid for one time step. The simulation grid can resolve one, two or three dimensions, but typically vector quantities such as fields vectors or particle velocities retain all three components. \subsection{Field Solvers} \label{sec:num:field} This subsection discusses how electromagnetic fields are calculated from source terms (moments of the distribution function of all charged particle species). The source are assumed to be known on a uniform grid of rectangular cells. How the source terms are calculated is discussed in section \ref{subsec:num:depostion}. Non-rectangular grids are discussed in the review \cite{Meierbachtol_2015}. %In this subsection we will assume that the source terms that are based on %moments of the distribution function of all charged species are known on the %grid. How this is actually accomplished will be discussed in the next %subsection. We will further more assume that we have a uniform grid of %rectangular or cubic cells. Triangular or tetrahedral cells are much more %complicated to deal with and are typically only used when a body-fitted mesh %around or inside a metal body is needed. More details can be found in the %review \cite{Meierbachtol_2015}. Particle-in-Cell codes commonly use a finite difference formulation based on the electromagnetic fields (as opposed to scalar electrostatic potential and magnetic vector potential). The typical arrangement of field samples is then given by the Yee lattice described in \cite{Yee_1966}. Component of the electric field $E_i$ are located at the mid points of edges pointing in coordinate direction $x_i$ whereas magnetic flux components $B_i$ are located at the center of cell phases with have normal vectors pointing in direction $x_i$, as shown in Figure~\ref{fig:num:rot_yee}. %In principle the two dual subgrids could be interchanged, but this %arrangement neatly follows the view of electromagnetism as a discrete exterior %calculus, where the electric field is a one-form that naturally lives on cell %edges. The magnetic flux is represented by two-forms assigned to cell phases. %This view of computational electrodynamics is rather recent but has proven %useful when designing field solvers on unstructured grids \cite{Rabina_2014, Na_2018}. The staggered arrangement of components %looks complicated as first and the reader might fear that it will require a lot of re-interpolation. is non-trivial and it looks as if interpolation is needed to calculate derivatives at the correct positions. But the contrary is true as we will see in a moment. We start our consideration from Maxwell's equation in CGS units. These are still customarily used in Particle-in-Cell codes as they make the magnitude of electric and magnetic components similar. Since we treat all material effects due to the plasma explicitly by having particles react to the fields $\vec{E}$ and $\vec{H}$, we can use them interchangeably with the respective flux densities $\vec{D}$ and $\vec{B}$. \begin{align} \nabla \times \vec{E} &= - \frac{1}{c} \frac{\partial \vec{B}}{\partial t} \label{eq:num:faraday}\\ \nabla \times \vec{B} &= \phantom{-} \frac{1}{c} \frac{\partial \vec{E}}{\partial t} + \frac{4 \pi}{c} \vec{\jmath} \label{eq:num:ampere} \\ \nabla \cdot \vec{E} &= 4 \pi\,\rho \label{eq:num:gauss}\\ \nabla \cdot \vec{B} &= 0 \label{eq:num:monopol} \end{align} Gauss's Law in Eq.~\eqref{eq:num:gauss} is the corner stone for electrostatic Particle-in-cell codes, but we will ignore it for now. Its equivalent for the magnetic field, Eq.~\eqref{eq:num:monopol}, that describes the absence of monopoles is mostly relevant as an initial condition. Faraday's Law and Ampere's law can be rewritten as evolution equations: \begin{align} \frac{\partial \vec{B}}{\partial t} &= -c \, \nabla \times \vec{E} \label{eq:num:Bevolution} \\ \frac{\partial \vec{E}}{\partial t} &= \phantom{-} c \nabla \times \vec{B} - \frac{4 \pi}{c} \vec{\jmath} \label{eq:num:Eevolution} \end{align} The time evolution given by these equations will not violate Eqs.~\eqref{eq:num:gauss} and \eqref{eq:num:monopol} if they were satisfied initially. Eqs.~\eqref{eq:num:Bevolution} and \eqref{eq:num:Eevolution} imply that the curl of the electric field does not have to be known at the location of the electric field, but rather at the location of the dual, magnetic field. \begin{figure}[h!] \centering \begin{subfigure}{0.4\hsize} \centering \includegraphics[width=3cm]{fig_chapter4/rotation_yee.png} \caption{Finite difference approximation in Yee scheme} \label{fig:num:rot_yee} \end{subfigure} \begin{subfigure}{0.4\hsize} \centering \includegraphics[width=3.5cm]{fig_chapter4/rotation_o4.png} \caption{Finite difference approximation in simplest $4^{th}$ order scheme} \label{fig:num:rot_o4} \end{subfigure} \caption{$2^{nd}$ and $4^{th}$ order Finite-Difference Time-Domain schemes} \end{figure} %%\begin{figure}[h!] %%\centering %%\includegraphics[width=0.5\hsize]{fig_chapter4/rotation_yee.png} %%\caption{Finite difference approximation in Yee scheme} %%\label{fig:num:rot_yee} %%\end{figure} %% %%As figure \ref{fig:num:rot_yee} illustrates, there is an elegant finite %%difference approximation for the curl of the electric field at the location of %%the magnetic flux, based on the four edges that surround the magnetic flux at %%the center of the face. If we write this approximation carefully it reads %%\begin{align} %%\left(\nabla \times \vec{E}\right)_x&(i\Delta{x},(j+1/2)\Delta{y},(k+1/2)\Delta{z}) \approx \nonumber \\ %%&\frac{E_y(i\Delta{x},(j+1/2)\Delta{y},k\Delta{z}) - E_y(i\Delta{x},(j+1/2)\Delta{y},(k+1)\Delta{z})}{\Delta{z}} + \nonumber \\ %%&\frac{E_z(i\Delta{x},(j+1)\Delta{y},(k+1/2)\Delta{z}) - E_z(i\Delta{x},j\Delta{y},(k+1/2)\Delta{z})}{\Delta{y}} \quad . \label{eq:num:rot_yee_long} %%\end{align} %%This expression is of course rather unwieldy, so customarily the edge length as %%well as the offsets required to center components along edges and on faces are %%suppressed and Eq.~\eqref{eq:num:rot_yee_long} is simply written as %%\begin{equation} %%\left(\nabla \times \vec{E}\right)_x(i,j,k) \approx %%\frac{E_y(i,j,k) - E_y(i,j,k+1)}{\Delta{z}} + %%\frac{E_z(i,j+1,k) - E_z(i,j,k)}{\Delta{y}} \quad . \label{eq:num:rot_yee} %%\end{equation} %%When presented with such an expression the reader needs to know that the use of %%the electric field at locations $k\Delta{z}$ and $(k+1)\Delta{z}$ implies that %%the magnetic flux (where the curl is used) is located at $(k+1/2)\Delta{z}$. %%This can make reading papers tedious, but is much more compact and closer to %%the actual implementation where the array indices into the arrays holding the %%values of the field components are naturally integers. %% The classical solution to store electric and magnetic fields on the grids that yields the curl of the fields at the required position is the Yee grid. Here e.g. $B_y$ is stored at cell face $(i+1/2,j,k+1/2)$, while $E_y$ is stored at $(i,j+1/2,k)$\footnote{The grid cells have edge length $\Delta{x}$, $\Delta{y}, \Delta{z}$ and any position can be given as $\vec{x} = \left(i\cdot\Delta{x}, j\cdot\Delta{y}, k\cdot\Delta{z}\right)$.}. Not only does this process result in curls calculated at the correct position without interpolation, but the curl is calculated in second order immediately. The temporal derivative in Eqs.~\eqref{eq:num:Bevolution} and \eqref{eq:num:Eevolution} can be solved using the second-order spatial derivatives. The customary solution is to leap-frog the fields, i.e. use the curl of the electric field at time $t\Delta{t}$ to update the magnetic field from time $(t-1/2)\Delta{t}$ to $(t+1/2)\Delta{t}$ and then use the curl of the magnetic field at that time to update the electric field to $(t+1)\Delta{t}$. This leads to a scheme that is also second order accurate in time. The timestep $\Delta{t}$ can not be larger than the CFL limit $\Delta{t} < \sqrt{\Delta{x}^2 + \Delta{y}^2 + \Delta{z}^2} / c$ to avoid instability. To update the particle position and location it is useful to have electric and magnetic fields at the position of the particle at the same time. The solution to this is to split the update of the magnetic field and use \begin{align} \vec{B}^{t\phantom{+1/2}} &= \vec{B}^{t-1/2} - \frac{1}{2} c \cdot \Delta t \cdot \nabla \times \vec{E}^{t} \label{eq:num:B1update} \quad ,\\ \vec{B}^{t+1/2} &= \vec{B}^{t\phantom{-1/2}} - \frac{1}{2} c \cdot \Delta t \cdot \nabla \times \vec{E}^{t} \label{eq:num:B2update} \quad ,\\ \vec{E}^{t+1\phantom{/2}} &= \vec{E}^{t\phantom{-1/2}} + c \cdot \Delta t \cdot \nabla \times \vec{B}^{t+1/2} - 4 \pi \Delta t \cdot \vec{\jmath}^{t+1/2} \label{eq:num:Eupdate} \quad . \end{align} This solver is the most common method and is accurate to second order with respect to a given current. Since small numbers of macroparticles lead to an increased noise, solvers are sought after to remove the noise. Increasing particles numbers is typically not an option as the noise level decreases as $1/\sqrt{N}$. Either the source term $\vec{\jmath}^{t+1/2}$ can be filtered or the noise can be damped. The latter is possible since noise is concentrated at high $k$ values. This low-pass filtering is described in \cite{Friedman_1990} and changes Eqs.~\eqref{eq:num:B1update} and \eqref{eq:num:B2update}. %%This solver works well and is implemented in many codes. However the %%electromagnetic fields can be rather noisy in Particle-in-cell simulations. %%There is a limited number of options to combat this. Increasing the number of %%macro particles to bring it close to the number of physical particles works, %%but is rather expensive as the noise level only goes down as $1/\sqrt{N}$. %%Another commonly used method is to filter the the source term %%$\vec{\jmath}^{t+1/2}$. %%%FIXME do that below and reference here %%The third option is to make use of the fact that most of that noise is %%concentrated at high $k$ and modify the field solver to damp those modes. This %%is exactly what the method described in \cite{Friedman_1990} does. It replaces %%Eqs.~\eqref{eq:num:B1update} and \eqref{eq:num:B2update} by %%\begin{align} %%\vec{B}^{t+1/2} &= \vec{B}^{t-1/2} - c \cdot \Delta t \cdot \nabla \times \left[\left(1+\frac{\theta}{4}\right)\vec{E}^t-\frac{1}{2}\vec{E}^{t-1}+\left(\frac{1}{2}-\frac{\theta}{4}\right)\vec{\bar{E}}^{t-2}\right]\quad , \label{eq:num:Bupfriedman}\\ %%\vec{\bar{E}}^{t-2} &= \left(1-\frac{\theta}{2}\right)\vec{E}^{t-1} + \frac{\theta}{2}\vec{\bar{E}}^{t-3} \quad . %%\end{align} %%If desired Eq.~\eqref{eq:num:Bupfriedman} can be split into two steps to get %%access to $\vec{B}^t$. The method allows tuneable damping by selecting $\theta$ %%between 0 and 1 at the extra expense of storing and updating $\vec{\bar{E}}$. %%The damping rate $\gamma$ is given by %%\begin{equation} %%\gamma\Delta{t} = - \frac{8\,\theta}{(2-\theta)^2} \left(\frac{c\,\Delta{t}}{\Delta{x}}\right)^4\sin^4\left(\frac{k\,\Delta{x}}{2}\right) \quad . %%\end{equation} The one instability that plagues electromagnetic Particle-in-Cell codes and is the main driver to go beyond the simple and robust field solver described above is the Numerical Cherenkov Instability (NCI). This long known instability (see \cite{Godfrey_1974}) occurs when particles move close to the speed of light and couple to light waves. In reality this only happens when the influence of a medium reduces the speed of light below the vacuum value and particle can reach the local phase velocity. Numerically this can happen when the numerical scheme introduces a dispersion error which reduces the speed of light. The Maxwell solver presented above does that, especially for short wavelength comparable to the length of the cell edges. %\begin{figure}[h!] % \centering % \includegraphics[width=0.25\hsize]{fig_chapter4/rotation_o4.png} % \caption{Finite difference approximation in simplest $4^{th}$ order scheme} % \label{fig:num:rot_o4} %\end{figure} In other applications of finite-difference time-domain (FDTD) schemes the solution would typically be to use a higher order approximation of the discrete curl operator. Fig.~\ref{fig:num:rot_o4} shows how the straight forward extension to $4^{th}$ order in space would look like. % The equivalent to Eq.~\eqref{eq:num:rot_yee} reads The right hand side of Eq.~\eqref{eq:num:Bevolution} now reads \begin{align} \left(\nabla \times \vec{E}\right)_x(i,j,k) \approx & \frac{27}{24}\frac{E_y(i,j,k) - E_y(i,j,k+1)}{\Delta{z}} \nonumber \\ & - \frac{E_y(i,j,k-1) - E_y(i,j,k+2)}{\Delta{z}} \nonumber \\ & + \frac{27}{24}\frac{E_z(i,j+1,k) - E_z(i,j,k)}{\Delta{y}} \nonumber \\ & - \frac{E_z(i,j+2,k) - E_z(i,j-1,k)}{\Delta{y}} \label{eq:num:rot_o4} \end{align} in this case. Also the temporal derivatives can be approximated in fourth order \cite{Fang_1989}. For typical PiC simulations with marginal stable time steps the gain in accuracy is negligible compared to the computational cost. %It is also possible to make the approximation of the temporal %derivative accurate to $4{th}$ order in the timestep $\Delta{t}$ as shown in %\cite{Fang_1989}. The problem is that Particle-in-Cell simulation tend to use %space and time steps that are just sufficient to get stable results. Using %substantially smaller steps is usually prohibitively expensive. This means that %$\lambda/\Delta{x}$ or $\omega \Delta{t}$ tend to be close to unity and the %difference between second and fourth order is small. The way forward has therefore been to use schemes that are still ``only'' second order, but with a small constant in front of the error term. Many such non-standard finite-difference (NSFD) schemes have been investigated over the years. %\begin{figure}[h!] % \centering % \includegraphics[width=0.25\hsize]{fig_chapter4/rotation_m24.png} % \caption{Finite difference approximation in M24 scheme} % \label{fig:num:rot_m24} %\end{figure} \begin{figure}[h!] \centering \begin{subfigure}{0.4\hsize} \centering \includegraphics[width=2.84cm]{fig_chapter4/rotation_m24.png} \caption{Finite difference approximation in M24 scheme} \label{fig:num:rot_m24} \end{subfigure} \begin{subfigure}{0.4\hsize} \centering \includegraphics[width=6cm]{fig_chapter4/rotation_nsfd.png} \caption{Finite difference approximation in Cole-Karkkainen schemes} \label{fig:num:rot_ck} \end{subfigure} \caption{Non-standard Finite-Difference Time-Domain schemes} \end{figure} %\begin{figure}[h!] %\centering %\includegraphics[width=0.25\hsize]{fig_chapter4/rotation_m24.png} %\caption{Finite difference approximation in M24 scheme} %\label{fig:num:rot_m24} %\end{figure} One such scheme, proposed by \cite{Hadi_1997} under the name ``M24'' makes use of the grid locations used by the standard Yee scheme, the locations used by the fourth order scheme and additional locations that close a larger loop around the mid point. The relative weights of the three loops are in principle arbitrary, subject to the constraint that they have to sum to one. The remaining two free parameters can be tuned to optimize the dispersion properties of the scheme. The original paper suggests some values, but more interesting is \cite{Greenwood_2004} that shows how these parameters can be chosen to reduce NCI. %\begin{figure}[h!] % \centering % \includegraphics[width=0.5\hsize]{fig_chapter4/rotation_nsfd.png} % \caption{Finite difference approximation in Cole-Karkkainen schemes} % \label{fig:num:rot_ck} %\end{figure} So far all schemes only used grid locations at $i\Delta{x}$, but \cite{Cole_2002} shows that using $(i\pm1)\Delta{x}$ can be useful, at least for a narrow range of frequencies propagating on the grid. Subsequently \cite{Karkkainen_2006} extended that to broad bandwidth. Fig.\ref{fig:num:rot_ck} illustrates all the grid locations that are used in this family of schemes. Choosing different relative weights between the different grid locations allows to tune for different optimization goals. An overview is given in \cite{Vay_2011}. %Of course the development did not stop at this point, but to keep the page number limited, the interested reader is referred to \cite{Shlager_1993, Garcia_1996, Pukhov_1999, Finkelstein_2006, Yang_2006, Hadi_2007, Smith_2012, Lehe_2013, Blinne_2018} as entry points to further reading on this fascinating topic. %%Das ist fast eine halbe Seite an Referenzen, die sich daraus ergeben... % Shlager_1993.pdf Dispersion error of FDTD schemes % Garcia_1996.pdf construction of high order FDTD in anisotropic dielectrica % Pukhov_1999.pdf Laser-Plasma simulation with tuned Maxwell solver, open boundaries % Finkelstein_2006.pdf M24 scheme for low dispersion FDTD % Yang_2006.pdf nummerically tuned FDTD solvers % Hadi_2007.pdf finite volume based low dispersion FDTD % Smith_2012.pdf low-dispersion and low-anisotropy FDTD % Jung_2013.pdf optimized 2,4 FDTD scheme % Lehe_2013.pdf NCI suppression with tuned FDTD % Blinne_2018.pdf optimized FTDT stencils A different approach is the pseudo-spectral solution of the field equations. As known from e.g. hydrodynamics the partial differential equations in real space are converted to ordinary equations in Fourier space. This eliminates finite stencils, but requires a global FFT \cite{Haber_1973, Jalas_2017}. For constant current density Maxwell's equations can be integrated analytically in time leading to pseudo-spectral analytic time domain (PDATD) schemes that are completely free of numerical dispersion. Since global parallel FFTs require a lot of communication and can limited scalability, there have been some attempts to avoid them and instead use local FFTs to build field solvers (\cite{Vay_2013}). %An old idea that has recently gained traction again is to try field solvers %that are not based on FDTD schemes, but based on solving Maxwell's equations in %the spectral domain (\cite{Haber_1973, Jalas_2017}). This requires global FFTs %to convert the fields between real space and the spectral domain. The upside %is that there is no need to use a finite stencil that approximates the curl to %some low order. Instead the differential operator can be expressed as a %multiplication by $\imath k$ which gives rise to the class of pseudo-spectral %time domain solvers which have basically infinite stencil order. Under the %assumption of fixed source terms, i.e. constant current density, is is %additionally possible to integrate Maxwell's equation analytically in time and %derive pseudo-spectral analytic time domain (PDATD) schemes that are completely %free of numerical dispersion. Since global FFTs require a lot of communication %and can limited scalability, there have been some attempts to avoid them and %instead use local FFTs to build field solvers (\cite{Vay_2013}) or correction %methods for more conservative FDTD schemes (\cite{Yu_2016, Li_2017}). % Jalas_2017.pdf pseudo spectral analytic time domain % Li_2017.pdf local FFT correction to FTDT to remove NCI % Yu_2017.pdf yee-fft % Na_2018b.pdf diagnosing NCI on general meshes % electrostatic %%If all particle motion is slow compared to the speed of light life is much %%easier. Not only do all NCI related problems go away, but it might be possible %%to remove light waves completely from the plasma model and to reduce %%computational expense. The straight forward way to do this is the electrostatic %%plasma model, where the electric field is not updated using an evolution %%equation based on Amperes Law (Eq.~\eqref{eq:num:Eevolution}), but is directly %%calculated from Gauss Law (Eq.~\eqref{eq:num:gauss}). This of course limits the %%electric field to is longitudinal, curl-free component. Bases on %%Eq.~\eqref{eq:num:Bevolution} this tell us that the magnetic field will not %%evoluve in time, but is restricted to an initial magnetic field that stays %%constant in time. Intuitively that makes sense as very slow (comparted to the %%speed of light) particle motion implies very small currents. Historically some %%of the first Particle-in-Cell codes were electrostatic (see e.g. %%\cite{Hockney_1966, Gitomer_1972}) and very also the first to be expressed in %%implicit form (\cite{Cohen_1989}). Numerically there is several options to %%solve Eq.~\eqref{eq:num:gauss}. In one spatial dimension direct integration is %%possible, in higher dimension two methods are worth considering. A basic %%spectral solver is simple to implementr and the book \cite{Birdsall_2005} has a %%good overview of the more subtil design trade-off one can make. The other %%option is a multigrid solver. This is somewhat harder to implement but has the %%possibility for better parallelisation for large systems, when the FFTs are %%communication limited. For the limit of very small particle velocities (as compared to the speed of light) the situation becomes much simpler. This is the electrostatic limit, where electric fields are calculated using Gauss Law (Eq.~\eqref{eq:num:gauss}) and magnetic fields are no longer time dependent. This of course limits the electric field to its longitudinal, curl-free component. Historically some of the first Particle-in-Cell codes were electrostatic (see e.g. \cite{Hockney_1966, Gitomer_1972}). Gauss Law can be solved in higher dimensions using either spectral solvers \cite{Birdsall_2005} or multigrid solvers. % darwin %%Between the electrostatic and electromagnetic plasma model that is rarely %%considered, but can be very effective and successfull in its domain of %%application. In the Darwin approximation \cite{Darwin_1920}, effects up to %%order $\mathcal{O}((v/c)^2)$ are retained, which allows for magnetic field %%fluctuations but removes light waves. Alternatively it can be though of the %%approximation where the time retardation due to the finite speed of light is %%removed. Aquivalently the divergence-free part of the displacement current is %%removed, which explicitly removes lightwaves from the problem. Interestingly %%all these approximation turn out to be identically as demonstrated by %%\cite{Krause_2007}. Some codes have been implemented in this approximation (see %%e.g. \cite{Eremin_2013}). The approximation does however change the natural of %%the system of differential equations to elliptic, requiring a global field %%solve in every time step. This makes the timestep more expensive and can limit %%scalability. Thus the Darwin approximation only results in a net speed up if %%the time step covers a much longer duration then the CFL limit for an %%electromagnetic code. Another limitation to keep in mind is that some low %%frequency modes that are not ordered out are still modified as demonstrated by %%\cite{Xie_2014}. %% %%The Vlasov-Poiswell model that only retains effects up to $\mathcal{O}(v/c)$ %%can be formulated in a consistent manner (see \cite{Besse_2007}), but is rarely %%used in practice. Besides the domain of electrostatic and electromagnetic models there is another intermediate regime called Darwin approximation \cite{Darwin_1920} which includes magnetodynamic effects up to order $\mathcal{O}((v/c)^2)$, but which does not consider light waves. This equivalent to removing the divergence-free part of the displacement current. While time resolution constraints are relaxed since the speed of light is no longer present, the differential equations representing the electromagnetic field are now elliptic requiring a global field solver. \subsection{Interpolation} \label{sec:num:interpol} The previous section only discussed Eulerian quantities on the regular grid. But the electromagnetic fields act on the Lagrangian particles, which requires knowledge of the field strength at the location of the particle, not just at the regular grid locations. This crucial switch in view point is done by means of an interpolation that we will discuss next. \begin{figure}[h!] \centering \includegraphics[width=0.25\hsize]{fig_chapter4/interpolation.png} \caption{Interpolation using the overlap between the cell and the particle, weighted by the shape function} \label{fig:num:interpolation} \end{figure} Fig.~\ref{fig:num:interpolation} illustrates how the interpolation from grid quantities (magnetic field $B_z$ in this case) to the particle location is done. As discussed in the last scetion the numerical macroparticle represents a sample of the phase space with finite extent and a macro factor, or (statistical) weight given by the number of physical particles it represents. %The computational macro-particle represents a large number of physical %particles and is thus seen as a chunk of phase space with a density %distribution over a finite extend. The fraction of the phase space volume that is located in the cell is used as a interpolation weight for the field strength contribution from that cell. %The fraction of particle that fall in the cell are used as a weight to multiply %the field strength at the center of that cell. Contributions from different cells are then added up to compute the mean magnetic field strength at the particle location. In a single dimension, this calculation can be expressed by \begin{equation} \bar{B}_z(x_p) = \sum_{i} B_z((i+1/2)\Delta{x}) \cdot \int_{i\Delta{x}}^{(i+1)\Delta{x}} S(x - x_p)\, \mathrm{d}x \quad . \end{equation} Since this calculation is required for all particles and all field components in each timestep, the integral over the shape function $S$ is not performed numerically, but rather done analytically ahead of time to obtain the weight function $W$: \begin{equation} W(x) = \int_{-\Delta{x}/2}^{\Delta{x}/2} S(x - x'), \mathrm{d}x' \quad . \end{equation} Using this and suppressing the explicit location of the gridded quantity in the cell we can write the two-dimensional interpolation as \begin{equation} \bar{B}_z(\vec{x}_p) = \sum_{i,j} B_z(i,j) \cdot W\left(x_p-(i+1/2)\Delta{x}\right) \cdot W\left(y_p - (j+1/2)\Delta{y}\right) \label{eq:num:Bzinterpol}\quad . \end{equation} Many different choices for the shape function $S$ are possible and different codes make different design choices here. Some properties are however required. The shape function does not include the statistical weight of the macro particle, but rather has to be normalized, i.e. $\int_{-\infty}^{\infty}S(x)\,\mathrm{d}x = 1$ and should be symmetric, i.e. $S(-x) = S(x)$. To allow efficient evaluation of Eq.~\eqref{eq:num:Bzinterpol}, the shape function should have compact support, i.e. be non-zero only up to some small $x_{max}$. The \textit{Nearest Grip Point} or NGP scheme is the minimal example satisfying all requirements: The shape function is the $\delta$-function $S(x) = \delta(x)$. This choice is simple to implement and computationally cheap, but the field that particles see is non-contiguous and the current induced by particles using this shape function switches from one cell to another when an interface is crossed. %In principle all these properties are satisfied by a $\delta$-function. This %use of $S(x) = \delta(x)$ is also referred to as \textit{Nearest Grip Point} or %NGP scheme. Computationally it is very cheap, as no interpolation or summation %has to be done, we just assume that the field at the particle location is %identical to nearest available field on a grid location. The downside however is %that the field that particles see is non-contiguous and the current induced by %particles using this shape function switches from one cell to another when an %interface is crossed. This leads to a high level of numerically induced %fluctuations in the source terms and consequently the fields. The Cloud-in-Cell %efficiently the algorithm by \cite{Birdsall_1968} was a major step forward in the performance and usefulness of Particle-in-Cell codes. Here each particle is viewed as a cloud of constant density and with the same size as a grid cell (but freely movable relative to the grid). The shape and weight function that generate that view are given by \begin{equation} S_{CIC}(x) = \begin{cases} 1 & |x|\leq 1/2 \\ 0 & \text{else} \end{cases},\quad W_{CIC}(x) = \begin{cases} 1-|x| & |x|\leq 1 \\ 0 & \text{else} \end{cases} \end{equation} and illustrated in Fig.~\ref{fig:num:S_CIC}. %The associated weight function $W_{CIC}$ is %straight forward to calculate and given by %\begin{equation} %W_{CIC}(x) = \left\{ %\begin{array}{ll} %1-|x| & |x|\leq 1 \\ %0 & \mathrm{else} %\end{array} %\right. %\end{equation} \begin{figure}[h!] \centering \begin{subfigure}{0.25\hsize} \centering \includegraphics[width=\hsize]{fig_chapter4/formfaktor_CIC_S.png} \caption{Cloud-in-Cell \phantom{andere zeile}} \label{fig:num:S_CIC} \end{subfigure} \begin{subfigure}{0.25\hsize} \centering \includegraphics[width=\hsize]{fig_chapter4/formfaktor_TSC_S.png} \caption{Triangular Shaped Cloud} \label{fig:num:S_TSC} \end{subfigure} \begin{subfigure}{0.25\hsize} \centering \includegraphics[width=\hsize]{fig_chapter4/formfaktor_PQS_S.png} \caption{Piecewise Quadratic Shape} \label{fig:num:S_PQS} \end{subfigure} \\ \begin{subfigure}{0.25\hsize} \centering \includegraphics[width=\hsize]{fig_chapter4/formfaktor_CIC_density.png} \caption{Cloud-in-Cell \phantom{andere zeile}} \label{fig:num:density_CIC} \end{subfigure} \begin{subfigure}{0.25\hsize} \centering \includegraphics[width=\hsize]{fig_chapter4/formfaktor_TSC_density.png} \caption{Triangular Shaped Cloud} \label{fig:num:density_TSC} \end{subfigure} \begin{subfigure}{0.25\hsize} \centering \includegraphics[width=\hsize]{fig_chapter4/formfaktor_PQS_density.png} \caption{Piecewise Quadratic Shape} \label{fig:num:density_PQdensity} \end{subfigure} \caption{Different shape functions in 1d and 2d} \label{fig:num:shape_function} \end{figure} This simple shape function is not only a major step forward, but has the added benefit of generating an entire family of shape function of increasing order, by using the weight function $W$ for the previous order as the shape function $S$ of the new, higher order. The next step after CIC in this chain is called \textit{triangular shaped cloud} or TSC. This shape function has the advantage of being continuous. This implies that the Fourier transform of it falls faster towards higher $k$. %As \cite{Langdon_1970} showed this corresponded to reduced %aliasing of higher $k$ to low $k$ that can be represented by the Eulerian grid %and consequently a reduction of the finite grid instability. This numerical %instability heats the plasma when the numerical grid does not resolve the Debye %length and can outgrow the physical processes the simulation is supposed to %study. Using higher order shape function suppress the instability and allows %the use of (slightly) larger grid cells or alternatively a better conservation %of the plasma thermal energy at identical resolution \cite{Shadwick_2009}. A %similar problem exists when the cell size does not resolve the gyro radius of %electrons, as shown by \cite{Horky_2017}, and again higher order shape function %can help. The downside is that the finite support of the shape function is %larger and more grid cells are involved in both the interpolation of the fields %to the particle location as well as the deposition. In \cite{Langdon_1970} it has been shown that this decreases aliasing of high $k$. This in turn decreases the finite grid instability - a numerical artifact that occurs, when the numerical grid does not resolve the Debye length and that artificially heats the plasma. The use of higher order shape functions improves the conservation of thermal energy\cite{Shadwick_2009}. Higher order shape function from the same family such as \textit{Piecewise Quadratic Shape} PQS illustrated in Fig.~\ref{fig:num:S_PQS} have been used. Higher order have an increasing number of continuous derivatives and therefore quicker drop off in Fourier space, but at the cost of each particle interacting with an increasing number of cells. The smoother fields generated by higher order shape functions reduce unphysical binary forces between nearby particles and therefore numerical collisionality \cite{Eastwood_1974,Matsuda_1975}. %The EPOCH code \cite{} might be the most widely used code to %use high order shape function. Otherwise order beyond TSC are not used widely enough that a consensus as to their names has emerged. %Historically another family of shape function was used, the so-called %subtracted dipole shapes, see \cite{Kruer_1973} for more detail. If the code %uses cylindrical or spherical coordinates one can either use unmodified shape %function in ``index space'' that look cartician, just like the grids we discuss %here. Or one can take into account that grid cells become smaller and %eventually have a singularity as they approach $r=0$ and follow the approach by %\cite{Ruyten_1993} to obtain a correct density representation, even at the %symmetry axis. %So far only interpolation in one dimension has been discussed or interpolation %that treats all dimensions the same. So far only dimension-by-dimension interpolation has been discussed. This construction leads to codes that conserve total momentum. Alternatively it is possible to combine shape function of different orders to obtain a code that conserves total energy \cite{Sokolov_2013}. A good example of this is the VPIC code (description in \cite{Bowers_2008}) that mixed NGP and CIC shape functions. Magnetic field components $B_i$ are interpolated using linear interpolation in the $x_i$ coordinate and NGP in the other two coordinates. Electric field components $E_i$ use NGP in the $x_i$ coordinate and CIC for the other two directions. %The use of only six locations to obtain the local magnetic field and twelve for %the electric field allows to handle larger numbers of particles efficiently. %The downside is of course that hundreds or thousands of particles per species %are required to bring down the noise level. The low-level interpolation unfortunately requires very high particle numbers to reach acceptable noise levels. Since many different choices for shape functions are possible, many comparisons have been made \cite{Abe_1986,Kilian_2013,Munoz_2014}. No universal winner has emerged and it is advisable to test different shape function to make sure that physical results are insensitive to the choices made. A recent idea by \cite{Wu_2018} is to use adaptive width per particle and update them during the course of the simulation to reduce overall noise. %Other schemes that pick or modify the width of the shape function to %reduce known numerical problems might follow. \subsection{Particle Motion} \label{sec:num:particle} Once the electromagnetic fields have been interpolated to the location of the particle, it is necessary to update the position and velocity of the particle accordingly. Since the first publication of the particle push by \cite{Boris_1970} basically all codes use this method, possibly with minor adjustments. Similar to the leap-frog procedure for the electromagnetic fields the particle's position and velocity are updated according to \begin{align} \vec{v}(t+\Delta{t}/2) &= \vec{v}(t-\Delta{t}/2) + \vec{F}(x(t),v(t))\cdot\Delta{t}/m \quad , \label{eq:num:velupdate}\\ \vec{x}(t+\Delta{t})\phantom{/2} &= \vec{x}(t)\phantom{-\Delta{t}/2}\,\,\, + \vec{v}(t+\Delta{t}/2)\cdot\Delta{t} \quad . \label{eq:num:posupdate} \end{align} When the force depends only on position, this can be solved straightforwardly. For velocity dependent forces - magnetic fields are the most important case - there is dependence on $\vec{x}(t)$, which is not known. The interpolation $\vec{v}(t) \approx 1/2\left(\vec{v}(t-\Delta{t}/2)+\vec{v}(t+\Delta{t}/2)\right)$, but this leads to an implicit dependence of Eq.~\eqref{eq:num:velupdate} on $\vec{v}(t+\Delta{t}/2)$ on both sides. % %Without magnetic field, when the force $\vec{F}$ only depends on the particle %position $x(t)$, this is straight forward to solve. If there is however a %magnetic field, the Lorentz force introduces a dependence on the velocity %$\vec{v}(t)$ that we do not know. The straight forward next step is to approximate %the velocity at this point in time by $\vec{v}(t) \approx %1/2\left(\vec{v}(t-\Delta{t}/2)+\vec{v}(t+\Delta{t}/2)\right)$, but now %Eq.~\eqref{eq:num:velupdate} has new new velocity $\vec{v}(t+\Delta{t}/2)$ on %both sides. The Boris push allows us to solve this implicit equation without %matrix inversion or iteration. %The Boris push allows us to solve this implicit equation without matrix inversion or iteration. Since different modifications of the Boris push differ in how they handle the %relativistic case it is worthwhile to switch from velocities $\vec{v}$ to the %relativistic momentum per rest mass $\vec{u} = \vec{p}/m = \gamma\vec{v}$. %This quantity does not suffer from the problem that it has a fixed upper value %and thus we avoid the loss of precision due to the finite resolution of %floating point numbers close to the speed of light. %Eqs.~\eqref{eq:num:velupdate} and \eqref{eq:num:posupdate} then read The Boris push allows us to solve this directly and efficiently. The computation efficiency is important since typical simulations contain many more particles than grid cells. In order to account for relativistic versions, the formulation shall be done using relativistic momentum per rest mass $\vec{u} = \vec{p}/m = \gamma\vec{v}$. Here $\gamma$ is the Lorentz factor of the macro particle. This quantity does not suffer from the problem that it has a fixed upper value and thus we avoid the loss of precision due to the finite resolution of floating point numbers close to the speed of light. Eqs.~\eqref{eq:num:velupdate} and \eqref{eq:num:posupdate} then read \begin{align} \vec{u}(t+\Delta{t}/2) &= \vec{u}(t-\Delta{t}/2) + \vec{F}(x(t),v(t))\cdot\Delta{t}/m \quad , \\ \gamma(t+\Delta{t}/2) &= \sqrt{1 + \frac{\vec{u}(t+\Delta{t}/2) \cdot \vec{u}(t+\Delta{t}/2)}{c^2}} \\ \vec{x}(t+\Delta{t})\phantom{/2} &= \vec{x}(t)\phantom{-\Delta{t}/2}\,\,\, + \vec{u}(t+\Delta{t}/2)\cdot\Delta{t}/\gamma(t+\Delta{t}/2) \quad , \\ \vec{F}(x(t),v(t)) &= \frac{q}{m} \left(\vec{E}(x(t)) + \vec{v}(t) \times \vec{B}(x(t))\right) \quad . \end{align} \begin{figure}[h!] \centering \includegraphics[width=0.4\hsize]{fig_chapter4/boris_push.pdf} \caption{Velocity diagram of the Boris push: The red arrows indicate the change in velocity $q/m \vec{E}(t) \Delta{t}/2$ from the acceleration by the electric field $E(t)$ at the beginning and end of the Boris push. The vector $\vec{\Omega}$ is a normalized magnetic field $\vec{B}$ such that a cross product with it produces half the final rotation. This allows the construction of $\vec{v}_2$ and the final accurate solution.} \label{fig:num:boris_push} \end{figure} The major insight that allows to solve the problem is that the magnetic field can only change the direction of the velocity vector. It is therefore possible to construct a suitable rotation using geometric considerations. The effect of the electric field is purely an acceleration in the direction of the electric field. To maintain reversibility in time and second order accuracy it is split into two equal parts performed before and after handling the magnetic field. Using this insight we can perform the following steps: \begin{align} \vec{u}_1 &= \vec{u}(t-\Delta{t}/2) + \frac{q}{m}\vec{E}(t)\frac{\Delta{t}}{2} \\ \vec{\Omega} &= \tan{\left(\frac{q}{\gamma\,m}|B(t)|\frac{\Delta{t}}{2}\right)}\frac{\vec{B}}{|\vec{B}|} \label{eq:num:tanrotation} \\ \vec{t} &= \frac{2}{1 + \vec{\Omega}\cdot\vec{\Omega}} \vec{\Omega}\\ \vec{u}_2 &= \vec{u}_1 + \vec{u}_1 \times \vec{\Omega} \\ \vec{u}_3 &= \vec{u}_1 + \vec{u}_2 \times \vec{t} \\ \vec{u}(t+\Delta{t}/2) &= \vec{u}_3 + \frac{q}{m}\vec{E}(t)\frac{\Delta{t}}{2} \end{align} It is worth noting that the original algorithm by Boris contains the $\tan$ in Eq.~\eqref{eq:num:tanrotation} and the suggestion to expand it at least up to fourth order if it is too expensive to compute $\tan$ to machine precision. However many codes since then have made the approximation $\vec{\Omega} \approx q/(\gamma\,m)\,\vec{B}(t)\,\Delta{t}/2$, This produces only the correct gyro radius, not the correct gyro angle. The Lorentz factor $\gamma$ in Eq.~\eqref{eq:num:tanrotation} is approximated by $\gamma = \sqrt{1 + \vec{u}_1\cdot\vec{u}_1 / c^2}$, which according to \cite{Vay_2008} can lead to spurious forces. %and he suggests a more complicated expression. % % He therefor suggests to use % \begin{align} % \vec{u}_1 &= \vec{u}(t-\Delta{t}/2) + \frac{q}{m}\vec{E}(t)\frac{\Delta{t}}{2} \\ % \vec{\tau} &= \frac{q}{m}\vec{B}(t)\frac{\Delta{t}}{2} \\ % \vec{u}' &= \vec{u}_2 + \frac{q}{m}\vec{E}(t)\frac{\Delta{t}}{2} \\ % u^{*} &= \left(\vec{u}' \cdot \vec{\tau}\right) / c \\ % \gamma' &= \sqrt{1 + \frac{\vec{u}' \cdot \vec{u}'}{c^2}} \\ % \sigma &= \gamma'^2 - \vec{\tau} \cdot \vec{\tau} \\ % \gamma &= \sqrt{\frac{\sigma+\sqrt{\sigma^2 + 4(\vec{\tau}\cdot\vec{\tau} + u^{*2})}}2{}}\\ % s &= \frac{1}{1 + \vec{\tau}\cdot\vec{\tau}}\\ % \vec{u}(t+\Delta{t}/2) &= s\left( \vec{u}' + (\vec{u}' \cdot \vec{\tau})\vec{\tau} + \vec{u}' \times \vec{\tau}\right) % \end{align} % Other modifications of the Boris push, such as \cite{Higuera_2017} and \cite{Umeda_2018} exist as well. Some comparison between different variants can be found in \cite{Ripperda_2018} or \cite{Zenitani_2018}. % All of these algorithm assume that the electric and magnetic fields do not % change during the time step $\Delta{t}$, nor is the field reinterpolated to the % changing position of the particle. The particle therefore effectively % experiences a constant and homogeneous field. The solution to the (relativistic) % equation of motion is in principle known analytically (see e.g. % \cite{Hyman_1997}), but no particle pusher based on this analytic solution is % in widespread use. \subsection{Deposition and Filtering} \label{subsec:num:depostion} Now that the electromagnetic field has acted on the particle we need to calculate -- in the case of an electrostatic code -- the charge density distribution resulting from the new locations of the particles, or -- in the case of an electromagnetic code -- the current density distribution. This requires interpolation from the particle locations back to the grid and is typically the most expensive operation in the simulation code. As \cite{Birdsall_2005} shows it is desirable to use the same interpolation method for both the interpolation from the grid to the particle location as well as the deposition of the particle quantities $\rho$ and $\vec{\jmath}$ onto the grid to avoid spurious self-forces. The deposition of $\rho(t+\Delta{t})$ based on the newly calculated $\vec{x}(t+\Delta{t})$ is straight forward and simply given by \begin{equation} \rho(i\Delta{x},j\Delta{y}) = \sum_{p} q_p W(x_p - i\Delta{x}) \cdot W(y_p - j\Delta{y}) \quad . \end{equation} The sum is taken over all particles, multiplying their charge with the weight function based on the distance between the particle position $\vec{x}_p(t+\Delta{t})$ and the origin of the grid cell, where the charge density is located. %One might be tempted to locate the charge density at the %center of the cell, to allow for the nice interpretation as the charge %contained in the cell, but typically the field solver calculates the %electrostatic potential at the location where the charge density is located. %Picking the corners of the cell allows to use a straight forward finite %difference approximation to calculate the electric field at the midpoint of %the edges. It is advisable to store the charge density at the cell corners. Calculating the current $\vec{\jmath}(t+\Delta{t}/2)$ based on the old location $\vec{x}(t)$, the new location $\vec{x}(t+\Delta{t})$ and the velocity $\vec{v}(t+\Delta{t}/2)$ is slightly more complicated. \begin{figure}[htbp] \begin{center} \includegraphics[width=0.5\textwidth]{fig_chapter4/currentassignment_naive.pdf} \caption{Naive current deposition for a charged particle moving as indicated by the black arrow and deposition current density onto the grid as shown in green. Solid black lines indicate grid cells, dashed line illustrate midplanes of cell faces.} \label{fig:num:currentassignment_naive} \end{center} \end{figure} The current carried by a particle with charge $q_p$ moving at velocity $\vec{v}(t+\Delta{t}/2)$ is given by $\vec{\jmath} = q_p \vec{v}(t+\Delta{t}/2)$ and it is located around the position at this time, $\vec{x}(t+\Delta{t}/2)$ that can be approximated by $\left(\vec{x}(t)+\vec{x}(t+\Delta{t})\right)/2$. Fig.~\ref{fig:num:currentassignment_naive} illustrates that this current can simply be interpolated onto the grid using the weight functions, just as for the charge density. The current on a cell edge is then simply the charge flowing through the associated cell face over the course of a time step. The problem with this straightforward procedure is that the current deposited in this way does not satisfies the discrete continuity equation given by \begin{align} &\frac{\rho(i\Delta{x},j\Delta{y},t+\Delta{t})-\rho(i\Delta{x},j\Delta{y},t)}{\Delta{t}} \nonumber \\ &\quad + \frac{j_x((i+1/2)\Delta{x},j\Delta{y},t+\Delta{t}/2) - j_x((i-1/2)\Delta{x},j\Delta{y},t+\Delta{t}/2)}{\Delta{x}} \nonumber \\ &\quad + \frac{j_y(i\Delta{x},(j+1/2)\Delta{y},t+\Delta{t}/2) - j_y(i\Delta{x},(j-1/2)\Delta{y},t+\Delta{t}/2)}{\Delta{y}} = 0 \quad . \end{align} Since this current enters Maxwell's equations as a source term it will lead to an electric field that does not actually satisfy Gauss' Law. In other words the curl-free component of the electric field in an electromagnetic code using this current deposition scheme will differ from the electric field in an electrostatic code with the same particle distribution. This is clearly not desirable and different methods have been used to correct the problem. One is to deposit the charge density separately and to solve a Poisson equation to get the longitudinal part of the electric field correct. Computationally cheaper and very effective is to make use of the fact that the electric field is nearly correct and to clean up the remaining error using a correction scheme, such as the one by \cite{Marder_1987}. This problem is solved all-together by current deposition schemes that deposit a current that satisfies the discrete continuity equation directly. The first of these so called \textit{charge conserving} schemes is by \cite{Eastwood_1991}, %\footnote{this paper is probably better known for the novel %Maxwell solver described therein, not the current deposition algorithm.} but several others have been developed since. The deposition in these schemes is slightly more expensive than in the naive algorithm, but the need to remove violations of Gauss' Law is completely eliminated. Somewhat more widely implemented in the scheme by \cite{Villasenor_1992}. The downside of this scheme is the need to treat the particle motion differently depending how many cell interfaces the particle interacts with. Since this scheme needs to branch to different algorithms its use especially on GPU is disadvantageous as branching computationally more expensive there.Additionally this scheme is tedious to extend to shape functions beyond CIC. % \begin{figure}[htbp] % \begin{center} % \includegraphics[width=0.5\textwidth]{currentassignment_esirkepov.pdf} % \caption{Current deposition using the algorithm by \cite{Esirkepov_2001}. The particle motion is decomposed into axis-parallel segments that are individually weighted.} % \label{fig:num:currentassignment_esirkepov} % \end{center} % \end{figure} \begin{figure}[h!] \centering \begin{subfigure}{0.4\hsize} \centering \includegraphics[width=\textwidth]{fig_chapter4/currentassignment_esirkepov.pdf} \caption{Current deposition using the algorithm by \cite{Esirkepov_2001}. The particle motion is decomposed into axis-parallel segments that are individually weighted.} \label{fig:num:currentassignment_esirkepov} \end{subfigure} \begin{subfigure}{0.4\hsize} \centering \includegraphics[width=\textwidth]{fig_chapter4/currentassignment_umeda.pdf} \caption{Current deposition using the Zig-Zag algorithm by \cite{Umeda_2003}. As the particle closes from one cell to another %(across the solid black line indicating the cell interface) , its trajectory is modified to go via the midpoint.} \label{fig:num:currentassignment_umeda} \end{subfigure} \caption{Charge conserving current deposition} \end{figure} A scheme that works with arbitrary shape functions (as long as they are products of separate one-dimensional shape functions) and without the need for different treatment of special cases is the current deposition by \cite{Esirkepov_2001}. Fig.~\ref{fig:num:currentassignment_esirkepov} illustrates the current density that is deposited using this algorithm for the same particle move as used in Fig.~\ref{fig:num:currentassignment_naive}. The reader can verify that the total current is identical, but the distribution onto the different grid points is different. In this algorithm the motion of the particle is decomposed into separate displacements parallel to the grid axis that are weighted individually. Readers that are interested in implementing this algorithm are referred back to the excellent original paper. The other widely used scheme %in modern codes is the Zig-Zag scheme described in \cite{Umeda_2003}. In this scheme particles can only cross between cells at the midpoint of the interface. A particle that does not naturally go through that point has its motion split into a motion from the starting position to the mid point, followed by a separate motion from the midpoint to the final location, resulting in a Zig-Zag trajectory %that gave the scheme it's name. as illustrated in Fig.~\ref{fig:num:currentassignment_umeda}% illustrates this motion and the ~resulting current for the same particle trajectory as used before. %Finding the midpoints for the fraction of particles that does not stay in the same cell %requires some conditional code, but the upside is that the current deposition %inside each cell is slightly simpler. Overall the computational cost and %noise-properties between the two deposition schemes is similar. Although the method requires some code depending on conditional branching the computational cost and noise-properties between the two later deposition schemes is similar. % \begin{figure}[htbp] % \begin{center} % \includegraphics[width=0.5\textwidth]{currentassignment_umeda.pdf} % \caption{Current deposition using the Zig-Zag algorithm by \cite{Umeda_2003}. As the particle closes from one cell to another (across the solid black line indicating the cell interface), it's trajectory is modified to go via the midpoint.} % \label{fig:num:currentassignment_umeda} % \end{center} % \end{figure} % %Even in the case of unstructured grids, a charge-conserving current deposition %method has been developed by \cite{Moon_2015}, that makes use of the %discrete exterior algebra in its derivation. Once the current is deposited on the grid it can be filtered to remove unwanted noise. The noise level in PiC simulations is exacerbated by the artificially lowered number of macro particles. The paper by \cite{Vay_2011} has an introduction to some digital filters and the associated terminology. Many codes simply use one or more passes of a simple binomial filter to reduce high frequency fluctuations, but it is possible to tune filters specifically to the problem at hand and get much better performance. \subsection{Initialization and Particle Handling} \label{subsec:num:init} %We can now covered how the particle based source terms are incorporated in the %evolution of the gridded electromagnetic quantities, how those act on the %particles and how new source terms are deposited onto the grid based on the %updated particle properties. An important part that is still undescribed is the %setup of the initial conditions. For the field quantities on the grid these are %usually simply set base on analytic expression for known equilibria. Most of %them only require an initial magnetic field and have vanishing electric field. %Creating the initial particle population is a little bit more complicated and %can have an important influence on the noise level in the simulation. %The difficulty is to create a number of particles that represent the desired %distribution function $f(\vec{x},\vec{v},t_0)$. We will approach this problem %step by step. So far we have described how the temporal evolution of particles and fields and their interaction are done in PiC codes. Yet the initial conditions have to be prescribed. For field quantities this is a straight forward procedure: Analytic expressions for equilibria are used (typically the magnetic field is given and the electric is assumed to be zero). Reproducing the desired distribution function $f(\vec{x},\vec{v},t_0)$ is more complicated and the method used may have a measurable impact on the noise level. The easiest and not uncommon case is a constant spatial density and a non-relativistic Maxwellian velocity distribution. In this case we can pick the initial position of the particle at random using \begin{equation} \vec{x} = \left(L_x\cdot \mathcal{U}(0,1), L_y \cdot \mathcal{U}(0,1), L_z \cdot \mathcal{U}(0,1)\right) \quad, \end{equation} where the random generator function $\mathcal{U}$ produces three independent (pseudo-)random numbers, uniformly distributed between zero and one. The expected number of \textit{particles per cell} (\textit{ppc}) is Poisson distributed as we have a discrete probability distribution with independent probability. Since the number of macroparticles is significantly smaller than the number of real particles, the statistical density fluctuations are higher in the simulation than in the reality. One easy step to remedy this to some extent is to create exactly the expected number of macro particles per cell and only choose the position inside the cell at random. This also makes it easy to represent spatially changing densities, by computing the number of particles in each cell from a known analytic function $n(\vec{x})$. This works well as long as the scale length $l_n = n / \frac{\partial\, n}{\partial{x}}$ is large compared to the cell size $\Delta{x}$. For uniform densities there is also the possibility to use \textit{low discrepancy series} such as the Halton sequence \cite{Halton_1964}. This sequence distributes particles more uniformly in the simulation domain. This reduces the noise level as $\mathcal{O}(1/N)$ with the particle number. Adding more particles would reduce the noise level only like $\mathcal{O}(1/\sqrt{N})$ . This \textit{quiet start} has been successfully used e.g. in the study of instabilities. %(see \cite{Byers_1970} for an example). The non-relativistic Maxwellian distribution is simply the composition of three velocity components that individually follow a normal distribution: \begin{equation} \vec{v} = \left(\mathcal{N}(u_x, v_{th}), \mathcal{N}(u_y, v_{th}), \mathcal{N}(u_z,v_{th})\right) \quad. \end{equation} $\mathcal{N}(\mu,\sigma)$ produces a random number from a normal distribution with mean $\mu$ and standard deviation $\sigma$. The mean can be the average drift velocity of that species (and can depend on position and particle species, e.g. in the setup of a current sheet) and the standard deviation is set by the thermal speed \begin{equation} v_{th} = \sqrt{\frac{k_B T}{m}} \quad . \end{equation} Note that there is a second popular definition of the thermal speed that includes a factor of square root two. When comparing with other codes and results this is a point worth double-checking. Different species of different masses will have different thermal speeds at the same temperature. %The extension of this method %to include species of different temperatures for different species or spatial %directions is straight forward. %Some early simulations used other methods to approximate a Maxwellian %distribution, but on modern machines the generation of $\mathcal{N}$ using the %Box-Muller method or the ziggurat algorithm is sufficiently fast that a %straight-forward approach performs well. This is both thanks to the fast %evaluation of $\log$ and trigonometric functions and to the increased %performance of the underlying generators producing pseudo-random integers. If the drift speed $\vec{u}$ approaches relativistic speeds, but the thermal speeds are still sufficiently low, some accuracy can be gained by generating a non-drifting distribution and boosting it with a Lorentz boost. If the thermal speed is large as well, it is necessary to generate a proper Maxwell-J\"uttner distribution. This used to be problematic and many older codes neglect this, however this leads to problematic deviations from the correct distribution as demonstrated in \cite{Melzani_2013}. Fortunately an efficient algorithm is described in \cite{Zenitani_2015}. Sometimes it is desired to generate new particles from a given distribution during initialization, but also later in the simulation, e.g. to fill a portion of newly expanded simulation space or to inject plasma through an inflow boundary. This is possible, but some subtleties need to be considered due to the interaction with existing fields in the domain \cite{Cartwright_2000}. % particle splitting and merging In many simulations particles are created once and afterwards their number never changes. It can however be useful to split particles into particles with smaller macrofactor. in regions of (phase-)space, where there is a low number of particles, to get better statistics and reduce noise. Many of those particles however leave the interesting region again and need to be merged together again to avoid a ballooning of the computational cost. Splitting particles in a way that conserves mass, momentum and energy is straight forward, as we can simply pick a source particle, split it into two equal parts of half the statistical weight and displace them slightly from the center mass to ensure that the following plasma dynamics will transport them separately. Some care can be taken that the displacement does not change the energy in the electromagnetic fields. %, but even without that the naive algorithm works well. The main problem is particle merging, as we will never find two particles of exactly equal velocities close to each other. Combining two particles of unequal speeds however can not conserve both momentum and energy at the same time. %A first solution was offered by \cite{Shon_2001}, combining several particles %into several new particles to conserve charge density, momentum and energy. In simulations where many new particles are created the algorithm by \cite{Welch_2007} that estimates the distribution function from $N \gg 2$ particles and replaces them with $M$ ($2 \ll M < N$) new particles can be useful. The method of \cite{Faghihi_2017} extends this to include also the stress tensor. If we do not want to redraw the complete particle population, e.g. because we want to preserve features in phase space that are not well described by the first few fluid moments, it is necessary to find particles of similar speeds. The method by \cite{Martin_2012} to find such particle pairs or groups can be useful for this task. The method by \cite{Vranic_2015} aims to merge $N$ existing particles into two new particles while conserving charge, momentum and energy. %If the reason for splitting particles is mesh-refinement %in one of the rare AMR codes, the method by \cite{Drouin_2018} can help with %splitting, but merging remains a problem. %Handling of dynamic particle numbers in a way that covers phase space well, is %numerically efficient and conserves all global quantities remains a problem, %despite all the described attempts and many others in recent year. \subsection{Boundary Conditions} \label{subsec:num:boundary} As mentioned before it might be desirable to create new particles at the boundary and proper care has to be taken for to match the existing fields there. This is a general problem with boundary conditions in Particle-in-cell codes. One has to handle both the fields and the particles there and should do so in a consistent way to avoid problems. Numerically easiest are periodic boundary conditions where the cell at the upper end of a coordinate is logically wrapped around (for $N$ cells cell number 0 is right of cell $N-1$) to be just below the lower end of the coordinate. Particles that leave through one side are reinjected unmodified at the other end. Periodic boundary conditions mimic infinite space reasonably well, as there are no fixed walls or ends to the simulations. The periodic nature of the simulation does however select a finite number of modes %-- out of the infinite possibilities that exist in free space -- that have an integer number of wavelengths in the simulation box. The number of grid limits the mode number and the spectrum. %If the number of grid cells is small, so is the number of allowed wave modes and the %quantization of the spectrum can have visible, undesirable effects. %Another set of boundary conditions that are reasonably popular is a version of %Dirichlet boundary conditions for some field components. More specifically the %normal component of the magnetic field is held fixed in time and the two %tangential components of the electric field are set to zero. Geometrically this %affects the three field components that are located at that face of the unit %cell. The two magnetic field components on the perpendicular faces and the %electric field on the edge normal to the boundary are not needed at the %boundary and are not modified by evolved freely, same as in the interior of the %domain. Vanishing electric field, even in the presence of an electric current %is typical for a \textit{perfect electric conductor} (PEC). This boundary %therefore mimics a metal wall with vanishing resistivity. If a realistic metal %boundary is required, much more effort is needed. This boundary condition does %reflect impinging electromagnetic waves. Also popular are Dirichlet boundary conditions for some field components: The normal component of the magnetic field is held fixed in time and the two tangential components of the electric field are set to zero. Geometrically this affects the three field components that are located at that face of the unit cell. The two magnetic field components on the perpendicular faces and the electric field on the edge normal to the boundary are not needed at the boundary and are evolved freely, same as in the interior of the domain. Vanishing electric field, even in the presence of an electric current is typical for a \textit{perfect electric conductor} (PEC). This boundary therefore mimics a metal wall with vanishing resistivity. If a realistic metal boundary is required, much more effort is needed. This boundary condition does reflect impinging electromagnetic waves. The PEC boundary is therefore often coupled with a reflecting boundary condition for particles. When a particle ends outside the boundary at the end of the timestep, both the component of the position normal to the wall, as well as the normal component of the velocity are flipped. This process is identical to specular reflection when reaching the boundary. More complicated boundary conditions for particles might absorb the particle or emit one or more new particles drawn from some distribution function, possibly depending on the energy of the incoming particle. This can simulate more or less realistic metal wall including effects such as wall charging or secondary electron emission. While physically not a boundary condition, moving simulation domains are often implemented in terms of boundary conditions. One example is the moving window in the XOOPIC code \cite{Bruhwiler_2001}. Here the Eulerian mesh is not moving, but instead new grid cells are created on one side and populated with background magnetic field and fresh thermal particles. On the other side the grid is truncated and particles are removed. If the window happens to move at the speed of light -- common in simulation that follow the path of a laser pulse through a plasma (see e.g. \cite{Yu_2016}) -- no perturbation caused by the downstream boundary can reach the interior of the simulation domain, greatly simplifying the implementation. If the window is moving slower, a boundary that absorbs waves and does not reflect them back into the interior is needed at the lower end of the moving window. This brings us to the topic of absorbing boundary conditions. These have been a problem for a long time. Initially Liao boundary conditions \cite{Liao_1984} and Mur \cite{Mur_1981} have been used. These boundary condition are described in detail in the great book on FDTD methods by \cite{Taflove_2000}. The problem with these boundary conditions is that they rely on fixed waves speeds. The presence of the plasma changes the wave speed. %from the speed of light to a lower speed that might depend on wavelength, %incident angle and plasma parameters such as the magnetizations This makes it very hard to absorb all wave modes that reach the boundary sufficiently well. A great step forward was the development of the \textit{Perfectly Matched Layer} (PML) by \cite{Berenger_1994}. This layer is technically not a boundary condition, but rather a region of space with modified permeability and permittivity. These material properties are chosen such that the impedance of the material is identical to the adjacent free space. Therefore the refractive index does not change from free space to the material layer and no waves are reflected. Inside the material the wave is however damped, attenuating before it reaches the actual boundary. There a simple boundary condition such as PEC can be chosen. Any wave that does reach the boundary and gets reflected is attenuated a second time on the way out, greatly improving performance of this scheme. %Several different formulations of PML have been developed such as %split-PML (where each electric and magnetic field component inside the boundary %is split into two independent, unphysical fields that are damped separately), %uniaxial PML (UPML) and more general stretched-coordinate PML wave been %developed. One implementation known as convolutional PML (CPML) has been used successfully in multiple cases. The book \cite{Berenger_2007} explains the different methods and their connections. %Even before the development of these methods was completed, PML conditions were %used in Particle-in-Cell simulations, see e.g. \cite{Pasik_1999, Pukhov_1999}. PML boundary conditions are often combined with boundaries that absorb outgoing particles and replace them in some scheme to simulate the presence of a thermal plasma bath outside the simulation domain that can act as the source of unperturbed upstream. This has been used in the simulation of magnetic reconnection, where the removal of plasma in the outflow regions and the injection of fresh upstream with not-yet-reconnected magnetic flux allows for the study of larger systems (see \cite{Daughton_2006, Klimas_2008, Ohtani_2009}). %Besides the injection of thermal plasma on the boundary It is also possible to inject electromagnetic waves to study their propagation. This can either be achieved by the means of an artificial current, acting as an antenna or by manipulating the electromagnetic field directly. More complicated injection schemes that allow for the injection of realistic laser pulses (\cite{Thiele_2016}), of oblique waves with arbitrary envelops (\cite{Perez_2018}) or of magnetized plasma without unwanted numerical noise (\cite{Kilian_2018}) are possible as well.%, but require a bit of care. % Eliasson_2002.pdf outflow condition for Fourier transformed Vlasov-poison system \subsection{Diagnostics} \label{subsec:num:diag} Designing and using a Particle-in-Cell code is interesting by itself, the ultimate goal is to produce output that can be used to gain understanding of the physical system. This requires the calculation of diagnostic quantities and storing them in a way that persists beyond the duration of the simulation. %As tempting as it might be to simply save the complete state of the simulation and %use later post-processing to produce higher-level diagnostics and plots, it is %usually a bad idea from a performance standpoint. Simply storing the full state of the simulation is typically impossible for performance reasons. Whenever possible the simulation code should calculate diagnostics as close to the final plots and output only them. After all, a simple histogram for a velocity distribution might only be a few kilobytes, where the dump of all particles is several terabytes. Saving the simulation state for later analysis or restart might still be necessary but should be performed as rarely as possible. There are of course many high-level diagnostics and it is impossible to cover all of them. This section will therefore mostly cover general-purpose output that can be postprocessed further. To gain high-level insight into the simulation at low I/O cost it is often useful to calculate a breakdown of the energy content in the simulation in several rough categories, such as the energy in the electric field, the energy in the magnetic field and in the particles. The diagnostic is also very valuable to check conservation of total energy in a PiC code that conserves momentum by construction. Another obvious candidate for output are gridded quantities, such as electric and magnetic field as well as current density. These quantities do not require any extra calculation. The two most widely used choices are dumping the memory of every MPI domain to a separate binary file or writing a global view to a structured format such as HDF5\footnote{other formats are available, but HDF5 is widely supported by many post-processing tools}. The first choice has the advantage of low overhead as nearly no metadata is saved. The downside is that the separate views of the different domains need to be combined for further analysis. The overhead of creating many files at once and the tedious file handling make this alternative a poor choice for more than a few hundred cores. Parallel I/O to HDF5 requires slightly more complicated I/O code and introduces some overhead, but allows for the inclusion of meta-data and easy loading into analysis tool, independent of programming language and CPU architecture. Other field data that need to be computed just for diagnostic purposes such as the mass density, charge density, average bulk velocities, or components of the pressure tensor can also be good choices for grid based output. Even if many of these quantities are required it is typically cheaper to compute the diagnostics during the parallel simulation instead of dumping the full particle information and doing post-processing. In many cases not all of the three-dimensional field data is required. Averaging over one or two dimensions to obtain line profiles or two-dimensional selections is an option. Alternatively line-outs or two-dimensional cuts can be useful. If points of interest are known beforehand or can easily be computed on the fly it is interesting to output time histories of those points at high cadence. If a global overview is needed, but not the full resolutions, it is possible to output a downsampled grid. Care should be taken to apply a digital low-pass filter -- such as a Kaiser window \cite{Kaiser_1980} -- before the decimation to avoid aliasing. In some cases it is necessary to restart the simulation, either due to reaching a wallclock limit, or due to a compute node crashing. Also some analysis can only be performed as post-processing, either due to poor scalability or because it is actively being developed based on the simulation results. In this case, the full particle information needs to be stored. Again direct binary dumps or higher-level self-describing formats are the two main possibilities. %Some codes %even implement both, the high-level format for scientific analysis and binary %dumps that are overwritten periodically as faster checkpoints that are only %used for restarts. Many other diagnostics have been developed and the following list of examples is certainly incomplete: one-dimensional histograms of particle quantities (speed, energy), two-dimensional cuts in phase space showing e.g. $x-v_x$-densities, Fourier transforms of other quantities such as $\tilde{B}(|k|)$, time averages of other quantities to remove high-frequency noise, trajectories of specially selected particles of interest, often together with local field quantities at the position of the tracer particles, reconstruction of the particle phase space density on a six-dimensional grid, discrete estimates of the entropy based on a binned phase space. The possibilities are endless here and a large fraction of the development time of a mature code will be invested in providing user friendly, scalable, efficient diagnostics. One special diagnostic that is of interest in astrophysical applications is the calculation of radiation spectra. This is different from the spectrum of the field inside the simulation domain that is limited to frequencies that are explicitly resolved. Often there is synchrotron or inverse-Compton radiation at much higher frequencies that can be calculated separately. See \cite{Pausch_2018} on how to implement and properly test such radiation diagnostics. Some recent codes include the production of gamma rays and electron-positron pairs \cite{Nerush_2017}. This is especially relevant for the nascent field of pulsar magnetosphere simulations, where the back reaction of the radiation processes on the energetic particles in the simulation needs to be included \cite{Kalapotharakos_2018}. \subsection{Test Cases} \label{subsec:num:test} Compared to fluid codes that easily develop instabilities e.g. through negative densities or numerical instabilities, PiC codes are rather robust. This numerical stability is sometimes mistaken as physical plausibility. It is therefore important that the researcher employs a healthy skepticism towards the code and that the code is tested. Other communities like the fluid simulation community. have a large number of test cases for which analytic solutions are known, or at least results from other codes are available. In the Particle-in-Cell community validation efforts (making sure that the employed plasma model is adequate and that the underlying assumptions are met), benchmarking (comparison with other codes) and validation (testing proper implementation) are relatively new and rare. One of the reasons is that the number of test problems with known, analytic solutions is rather small. %Unlike hydro codes that tend to develop negative densities or pressures when %numerical problems occur Particle-in-Cell codes are relatively robust. This %can be a good, but brings the risk of obtaining a plausible but wrong result. %It is therefore important that the researcher employs a healthy skepticism %towards the code and that the code is tested. Other communities have a large %number of test cases for which analytic solutions are known, or at least %results from other codes are available. In the Particle-in-Cell community %effort into validation (making sure that the employed plasma model is adequate %and that the underlying assumptions are met), benchmarking (comparison with %other codes) and validation (testing proper implementation) are relatively new %and rare. One of the reasons is that the number of test problems with known, %analytic solutions is rather low. %But there some test cases that can be recommended. The paper by %\cite{Jacobs_2006} introduced a discontinuous Galerkin code on unstructured %mesh, but also includes several useful test cases. The study of %Kelvin-Helmholtz instability in Saturn's magnetopause in \cite{Delamere_2011} %has been used by several hybrid codes. Code description paper such as the one %for the Apart-T code \cite{Melzani_2013} or the SHARP code \cite{Shalaby_2017} %lists several test problems that are solvable with that code and offers %opportunity for benchmarking. Papers that investigate new hybrid codes such as %\cite{Amano_2014,Munoz_2018} contain testproblems to demonstrate the new %method, but many of them are also accessible to PiC codes. The paper by %\cite{Kilian_2017} contains a list of wave modes and suggested parameters that %are accessible to different plasma models that can be implemented by PiC codes. But there are some test cases that can be recommended. The paper by \cite{Jacobs_2006} introduced a discontinuous Galerkin code on unstructured mesh, but also includes several useful test cases. The study of Kelvin-Helmholtz instability in Saturn's magnetopause \cite{Delamere_2011} has been used by several hybrid codes. Code description paper such as the one for the Apart-T code \cite{Melzani_2013} or the SHARP code \cite{Shalaby_2017} lists several test problems that are solvable with that code and offers opportunity for benchmarking. Papers that investigate new hybrid codes such as \cite{Amano_2014,Munoz_2018} contain test problems to demonstrate the new method, but many of them are also accessible to PiC codes. The paper by \cite{Kilian_2017} contains a list of wave modes and suggested parameters that are accessible to different plasma models that can be implemented by PiC codes. Physical setups for which analytic solutions exist include the study of plasma waves \citep{Aastroem_1950, Bernstein_1958, Andre_1985, Swanson_2003} and the thermal excitation of fluctuations in density \citep{Dougherty_1960} or electromagnetic fields \cite{Akhiezer_1975, Yoon_2017}. For complicated distribution function that do not admit analytic solutions for the dispersion relation of plasma waves comparison with numeric dispersion solver \cite{Roennmark_1982, Xie_2016} is useful. The study of Landau damping has a long tradition \cite{Dawson_1961} and can be useful to test the long term stability of the code \cite{Manfredi_1997}. The comparison between different code types such as in \cite{Dimits_2000, Munoz_2015} can be useful to find the limits of applicability. This kind of comparison is especially popular in the Fusion power community \cite{Falchetto_2008}. The expected scaling behavior when improving numerical resolution can also be used to test the code, even without outside reference simulations, as shown in \cite{Riva_2017}. \chapter{Hyperbolic conservation laws} A large number of physics problems can be cast into a hyperbolic conservation law of the type \begin{align} \diffp{u(x,t)}{t} + \diffp{f(u(x,t))}{x} = 0 \end{align} or in more than one dimension \begin{align} \diffp{u(x,t)}{t} + \nabla f(u(x,t)) = 0 \end{align} As the name promises, something is conserved. Here $u$ is conserved and $f$ is the flux of this quantity. Whenever something behaves vaguely like a fluid this type of equation comes into play. The most simple form of this conservation law is the advection equation. As we will discuss later, the advection equation has - in its simple form - an analytic solution. If this was the case for all hyperbolic conservation laws there would be no need for numerical simulations. Unfortunately most hyperbolic conservation laws are similar to the Burgers equation, which includes a nonlinearity on the RHS (Navier-Stokes, MHD, etc.). And then there is no analytic solution. We still need to understand how solutions look like for hyperbolic conservation laws to develop numerical schemes and decide, which solution is correct. One point we have to discuss is the fact that we deal with PDEs now rather than ODEs before. We may solve a conservation law using, e.g., a Runge-Kutta 3rd order scheme \begin{align} u^\prime &= u^n +\Delta t \diffp{u^n}{x}\\ u^{\prime\prime} &= \frac{3}{4} u^n + \frac{1}{4}u^\prime +\frac{1}{4}\diffp{u^\prime}{x}\\ u^{n+1} &= \frac{1}{3} u + \frac{2}{3} u^{\prime\prime} - \frac{2}{3}\diffp{u^{\prime\prime}}{x} \end{align} Looks simple? It isn't. As we will figure out, the derivatives with respect to $x$ cannot just be cast into a finite difference. \section{Advection equation} The advection equation \begin{align} \partial_t u + a \partial_x u &= 0\\ u_0(x,t=0) &= u_0(x) \end{align} describes how the quantity $u$ is advected with a constant velocity $a$. When everything moves at constant speed, we can easily find the analytic solution \begin{align} u(x,t) = u_0(x- a t) \end{align} The solution is constant along the line $x_0 = x-at$. These lines are called characteristics. \begin{figure} \begin{center} \pgfimage[width=.8\textwidth]{fig_chapter5/linear-advection} \end{center} \end{figure} Characteristics are a fundamental concept for first order differential equations and we will make use of this concept for the more complicated conservation schemes. The characteristic fulfills $x^\prime(t)=a$ and $x(0)=x_0$. When differentiating $u$ along the characteristic we find \begin{align} \diff{}{t} u(x(t),t) &= \diffp{}{t} u(x(t),t) + \diffp{}{x} u(x(t),t) x^\prime(t)\\ &= u_t + a u_x = 0 \end{align} As pointed out before: $u$ is a constant along the characteristic. Now we may take a more general approach: let the advection speed be a function of $x$ \begin{align} \partial_t u + \partial_x (a(x) u) = 0 \end{align} where $a(x)$ is a smooth function. \begin{align} \partial_t u + a(x)\partial_x u = -a^\prime(x) \Leftrightarrow\left(\diffp{}{t}+a(x)\diffp{}{x} \right) u(x,t) = -a^\prime(x) u(x,t) \end{align} The evolution of $u$ along \begin{align} x^\prime(t) = a(x(t)),\quad x(0) = x_0 \end{align} is given by the ODE \begin{align} \diff{}{t} u(x(t),t) = -a^\prime(x(t)) u(x(t),t) \end{align} We have found a characteristic again, but this is no longer a constant. On which points does the solution depend? For the linear advection equation the answer is simple: It is the point $x_0$ through which the characteristic goes. The concept is called \emph{Domain of Dependence} $\mathcal{D}(x,t) = \{x_0\}$. It is not completely unexpected that $\mathcal{D}$ is not necessarily a single point. For hyperbolic systems we can at least conclude that $\mathcal{D}$ is a bounded interval. The length of the interval will increase with time \begin{align} \mathcal{D} \subset \{x:|x-\bar x| \leq a_\text{max} \bar t\} \end{align} Vice versa this means that starting from a single given point only a given area $ \{x:|x- x_0| \leq a_\text{max} t\}$ will be influenced (\emph{Range of Influence}). Hyperbolic systems have a limited velocity of propagation. \subsection{Non-smooth data} We have implictly assumed that $u_0$ is differentiable. For the characteristic differentiable functions are not essential. Even for $u_0$ with singularities we may define a solution. The singularity will move along the characteristic. For non-differentiable $u_0$ the solution $u$ is no longer a classic solution (since the differential equation requires\dots differentiation\dots). The solution fulfills, however, the integral conservation law (i.e., the fundamental physics behind this). A different approach to this would be: Let $u_0^\epsilon$ be a series of differentiable functions with $\lim_{\epsilon\to 0} = u_0$ \begin{align} \| u_0 - u_0^\epsilon \|_1 < \epsilon, \quad \| \cdot \|_1 \Rightarrow \| v\|_1= \int_{-\infty}^{+\infty} |v(x)| \dd x \end{align} The $u_0^\epsilon$ lead to differentiable, classic solutions $u^\epsilon(x,t)$ \begin{align} u^\epsilon(x,t) = u_0^\epsilon(x - at) \Rightarrow u(x,t) = \lim_{\epsilon\to 0} u_0^\epsilon(x-at) = u_0(x- at) \end{align} This works totally fine when talking about the linear case. When we move on to a non-constant advection speed we change from the advection equation to the diffusion advection equation \begin{align} \partial_t u + a \partial_x u = \epsilon \partial_x^2 u \end{align} in the limit of vanishing viscosity $\epsilon$. Let $u^\epsilon(x,t)$ be a solution to this equation. This solution is always differentiable since we have moved from a hyperbolic to a parabolic equation. From that point we can move to $\lim_{\epsilon\to 0}$ - the so-called vanishing viscosity solution. We will discuss this for non-linear equations in the next section. \section{Burgers equation} Let's move on to real nonlinear equations. We will consider equations of the type \begin{align} \partial_t u + \partial_x f(u) = 0 \end{align} where $f(u)$ is a convex function with $\partial_x^2 f(u) > 0$. The simplest case is the Burgers equation with $f(u) = 1/2 u^2$ \begin{align} \partial_t u + u\partial_x u = 0 \end{align} It should be pointed out that the original Burgers equation in fact includes a dissipation term $\epsilon \partial_x^2 u$ on the RHS. One may find the exact solution to this equation using the Cole-Hopf transformation that transforms the Burgers equation to heat transfer equation. But this is too theoretical. We are interested in the characteristics \begin{align} x^\prime (t) &= u(x(t),t)\\ \diff{}{t} u(x(t),t) &= \diffp{}{t} u(x(t),t) + \diffp{}{x} u(x(t),t) x^\prime(t)\\ &= u_t + u u_x \end{align} Since $u$ is constant along the characteristic the gradient of the characteristic does not change, i.e. the gradients are straight lines (cf. Fig. \ref{fig:burgers1}). \begin{figure} \begin{center} \pgfimage[width=.8\textwidth]{fig_chapter5/burgers1} \end{center} \caption{Solution to the Burgers equation with characteristics. Due to the nonlinearity the peak moves faster and becomes steeper.} \label{fig:burgers1} \end{figure} For small times $t$ the characteristics do not cross each other, one may calculate \begin{align} x &= \zeta + u(\zeta,0) t\\ u(x,t) &= u(\zeta,0) \end{align} For increasing times $t$ the characteristic come close to each other (cf. \ref{fig:burgers2}) until at some time $T_b$ two characteristic cross each other. This leads to a non-unique solution. \begin{figure} \begin{center} \pgfimage[width=.8\textwidth]{fig_chapter5/burgers2} \end{center} \caption{Solution to the Burgers equation for non-smooth data. As in Fig. \ref{fig:burgers1} the peak becomes faster.} \label{fig:burgers2} \end{figure} This process is somewhat like wave-breaking. As seen in Fig. \ref{fig:burgers3} we would have a three valued function for $t>T_b$ (don't be fooled by the breaking wave analogy: the process is similar, but $u$ is not a wave shape). \begin{figure} \begin{center} \pgfimage[width=.8\textwidth]{fig_chapter5/burgers3} \end{center} \caption{Following the evolution of \ref{fig:burgers1} would result in a non-well defined solution. For some points three solutions exist. This is clearly unphysical} \label{fig:burgers3} \end{figure} As pointed out before we may make use of viscosity to find the correct solution (the vanishing viscosity solution). \subsection{Weak solutions} So how do we find the solution for the inviscid equation without demanding differentiability? We will take a step back and consider the integral formulation (the integral includes the fundamental physical background of conservation). Let's consider a test function $\varphi \in C_0^1 (\mathbb{R}\times \mathbb{R})$ which is continuously differentiable with compact support (i.e., 0 outside the interval). We will now multiply the equation $u_t + f_x = 0$ with $\varphi(x,t)$ \begin{align} \int_0^\infty \dd t \int_{-\infty}^{+\infty} \dd x (\varphi \partial_t u + \varphi \partial_x f(u)) &= 0 \end{align} Using integration by parts we can show that this is \begin{align} \left(\int_{-\infty}^{+\infty}\dd x \varphi u \right)|_0^\infty - \int_0^\infty \dd t\int_{-\infty}^{+\infty} \dd x \varphi_t u + \varphi_x f(u) \end{align} The function $u(x,t)$ is called weak solution when for all functions $\varphi \in C_0^1 (\mathbb{R}\times \mathbb{R})$ the following equation holds \begin{align} \int_0^\infty \dd t\int_{-\infty}^{+\infty} \dd x \varphi_t u + \varphi_x f(u) = -\int_{-\infty}^{+\infty} \dd x \varphi(x,0) u(x,0) \end{align} The concept of weak solutions is not something that is used in real life, it is a theoretical concept to prove the correctness of solutions. The following solutions all fulfil the weak solution concept. \section{The Riemann problem} The connection of a conservation problem and a piecewise constant initial value yields a so called Riemann problem. The Riemann problem is essentially a template for the general solution. We will again consider the Burgers equation as conservation law and \begin{align} u(x,0) = \begin{cases} u_l & x<0 \\ u_r & x>0 \end{cases} \end{align} We will assume $u>0$ for the sake of simplicity. \subsection{Case 1} For $u_l> u_r$ we will find the following solution \begin{align} u(x,t) = \begin{cases} u_l & x < s t\\ u_r & x > s t\end{cases} \end{align} with the shock speed $s=1/2(u_l+u_r)$. When viscosity is included, this will result in the traveling wave solution. \begin{figure} \begin{center} \pgfimage[width=.8\textwidth]{fig_chapter5/riemann1} \end{center} \caption{The case $u_l>u_r$} \label{fig:riemann1} \end{figure} Fig. \ref{fig:riemann1} shows the solution of a moving shock where the characteristic converge \emph{into} the shock. \subsection{Case 2} For $u_l < u_r$ there are infinitely many weak solutions. The upper solution in Fig. \ref{fig:riemann2} includes again a shock with speed $s$. The difference to the previous case is that the characteristics come out of the shock. This is an entropy violating solution, which is unstable against perturbations. The correct solution is a rarefaction wave (shown in the lower part of Fig. \ref{fig:riemann2}) \begin{align} u(x,t) = \begin{cases} u_l & x < u_l t\\ x/t & u_l t \leq x \leq u_r t \\ u_r & x> u_r t \end{cases} \end{align} \begin{figure} \begin{center} \pgfimage[width=.8\textwidth]{fig_chapter5/riemann2} \end{center} \caption{The case $u_l s t$ \begin{align} \diff{}{t} \int_{-M}^{+M}\dd x u(x,t) &= f(u_l) - f(u_r) \\ &= \frac{1}{2} (u_l+u_r)(u_l-u_r)\\ \int_{-M}^{+M}\dd x u(x,t) &= (M+st) u_l + (M-st) u_r\\ \Rightarrow \diff{}{t}\int_{-M}^{+M}\dd x u(x,t) &= s(u_l-u_r) \end{align} In the general case the $f(u)$ can be derived from the Rankine-Hugoniot jump conditions \begin{align} f(u_l) - f(u_r) = s(u_l-u_r) \end{align} In the scalar case \begin{align} s = \frac{f(u_l) - f(u_r)}{u_l-u_r} = \frac{[f]}{[u]} \end{align} where $[\cdot]$ is the difference over the shock. When $f$ and $u$ are vectors, $s$ is still a scalar. Jumps are, therefore, only allowed for when $f(u_l) - f(u_r)$ and $u_l-u_r$ are linear dependent. In the real world (more than dimension, more than one quantity) the flux $f(u)$ is a linear system $A u$ where $u$ is $N$-dimensional and $A$ is a $N\times N$ matrix. The characteristics of this system are then the Eigenvalues of the system. Discontinuities are following these characteristics. \subsection{Manipulation of conservation laws} When considering the Burgers equation \begin{align} \partial_t u + \partial_x(1/2 u^2) = 0 \end{align} we can perform the following manipulations \begin{align} 2 u \partial_t u + 2 u^2 \partial_x u & 0\\ \Rightarrow \partial_t (u^2) + \partial_x (2/3 u^3) = 0 \end{align} This is seemingly a conservation law (for $u^2$) and we have made no grave mathematical mistake. The smooth solutions are even identical. The weak solutions, however, are behaving differently \begin{align} s_1 &= \frac{[1/2 u^2]}{[u]} = 1/2 (u_l + u_r)\\ s_2 &= \frac{[2/3 u^3]}{[u^2]} = 2/3 \frac{(u_r^3 - u_l^3)}{u_r^2-u_l^2} \end{align} Why is this different (and wrong\dots)? The manipulation is only valid for smooth solutions, where taking the derivative is a safe and well-defined operation. \subsection{Entropy condition} Obviously there is some ambiguity in solving the correct equations correctly. How do I figure out which solution is correct? The theoretical considerations from the last sections show that we may use the \emph{vanishing viscosity} ansatz. While this is technically correct, it is completely impractical and complicated. We may use our knowledge about what happens at the shock: Characteristics shall run \textbf{into} the shock rather than \textbf{out of} the shock. In the latter case the solution is unstable. From this we can conclude an \emph{entropy condition} Version 1 \begin{align} f^\prime(u_l) > s > f^\prime(u_r) \end{align} Version 2 \begin{align} \frac{f(u) - f(u_l)}{u - u_l} \geq s \geq \frac{f(u) - f(u_r)}{u - u_r} \end{align} Version 3 \begin{align} \exists E \forall a > 0, t> 0 \quad \frac{u(x+a,t)-u(x,t)}{a} < \frac{E}{t} \end{align} % \subsection{Scalar examples} \subsubsection{Traffic flow} Traffic fulfills a continuity equation \begin{align} \partial_t \rho + \partial_x(\rho u) = 0 \end{align} where one can derive the velocity $u$ from the traffic density $\rho$ \begin{align} u = u(\rho) = u_\text{max}(1-\frac{\rho}{\rho_\text{max}}) \end{align} This is actually a closure for a complicated system - only one equation earlier than in typical fluid equations \begin{align} \partial_t \rho + \partial_x(f(\rho)) = 0,\quad f(\rho) =\rho u_\text{max}(1-\frac{\rho}{\rho_\text{max}}) \end{align} For some system (here: Lincoln tunnel) other fluxes have been measured $f(\rho) = a \rho \log \rho_\text{max}/\rho$. The characteristics can be derived for the standard case \begin{align} f^\prime(\rho) = u_\text{max}\left( 1 - \frac{2\rho}{\rho_\text{max}} \right) \end{align} Bildchen mit Stau/Fahrzeug-Charakteristik \subsection{Nonlinear systems} \subsubsection{Euler equation} The Euler equations describe gas flows \begin{align} \partial_t \rho +\partial_x (\rho v ) &= 0\\ \partial_t (\rho v) + \partial_x(\rho v^2 + p) &= 0\\ 1/2 \rho v^2 + \rho e &= E \quad \text{(specific inner energy)}\\ \partial_t E +\partial_x(v(E+p)) &= 0 \end{align} This can be written in vector form \begin{align} \partial_t \begin{pmatrix} \rho \\\rho v\\E\end{pmatrix} +\partial_x \begin{pmatrix} \rho v\\ \rho v^2 +p\\ v(E+p) \end{pmatrix} \end{align} For the ideal gas we have the following relations \begin{align} p &= \rho k_B T/m\\ e &= c_V T \\ \gamma = c_p/c_V \end{align} The entropy is known to be \begin{align} S &= c_V \log(p/\rho^\gamma)\\ \Rightarrow p &= \kappa \exp(S/c_V)\rho^\gamma\\ \Rightarrow \partial_t S + v\partial_x S &= 0 \end{align} which leads to the Euler equation for the ideal gas \begin{align} \partial_t \rho + \partial_x (\rho v) &= 0\\ \partial_t (\rho v) + \partial_x ) &= 0\\ \partial_t S + v\partial_x S &= 0 \end{align} \section{Numerical methods} Let us linear equations of the type \begin{align} \partial_t u + A \partial_x u &= 0 \label{eq:leveque10.1}\\ u(x,0) &= u_0 (x)\\ x_j &= j h \\ t^n &= n k \\ x_{j+1/2} &= x_j + h/2 \end{align} where $A$ is a linear operator. The finite solution will produce approximations $U_j^n \in \mathbb{R}^m$ to the true solution $u(x_j,t^n)$ which will be denoted $u_j^n = u(x_j, t^n)$. A better approximation is the cell average \begin{align} \bar{u}_j^n = \frac{1}{h}\int_{x_{j-1/2}}^{x_{j+1/2}} \dd x\ u(x,t^n) \end{align} since $u$ is a conserved quantity and the conservation is given as exactly this integral. There are a wide variety of finite difference methods that can be used. Many of these are derived simply by replacing the derivatives occurring in Eq. \eqref{eq:leveque10.1} by appropriate finite differenc eapproximations. For example, replacing $u_t$, by a forward-in-time approximation and $u_x$, by a spatially centered approximation, we obtain the following difference equations for $U^{n+1}$: \begin{align} \frac{U_j^{n+1} - U_j^n}{k}+A\left( \frac{U_{j+1}^n-U_{j-1}^n}{2h}\right) = 0 \end{align} This can be solved to obtain \begin{align} U_j^{n+1} = U_j^n-\frac{k}{2h}A(U_{j+1}^n - U_{j-1}^n)\label{eq:leveque10.7} \end{align} Unfortunately, despite the quite natural derivation of this method, it suffers from severe stability problems and is useless in practice. A far more stable method is obtained by evaluating the centered difference approximations to $u_x$ at time $t_{n+1}$ rather than at time $t_n$, giving \begin{align} \frac{U_j^{n+1} - U_j^n}{k}+A\left( \frac{U_{j+1}^{n+1}-U_{j-1}^{n+1}}{2h}\right) = 0 \end{align} or \begin{align} U_j^{n+1} = U_j^n-\frac{k}{2h}A(U_{j+1}^{n+1} - U_{j-1}^{n+1})\label{eq:leveque10.9} \end{align} Note, however, that in order to determine $U^{n+1}$ from the data $U^n$ in each timestep, we must view equation \eqref{eq:leveque10.9} as a coupled system of equations over all values of $j$. This would be an infinite system for the Cauchy problem, but in any practical calculation we would use a bounded interval with $N$ gridpoints and this would be a finite system. In the scalar case this is an $N\times N$ linear system with a tridiagonal coefficient matrix.When $ u\in \mathbb{R}^m$, the discrete system is $mN\times mN$. The method \eqref{eq:leveque10.7} allows us to determine $U^{n+1}$ explicitly, and is called an explicit method, whereas \eqref{eq:leveque10.9} is an implicit method. Implicit methods are rarely used for time-dependent hyperbolic problems, although they are very important for other classes of equations. Although the method \eqref{eq:leveque10.7} is useless due to stability problems, there are other explicit methods which work very satisfactorily with reasonable size timesteps and these are typically more efficient than implicit methods. If we look at which gridpoints are involved in the computation of $U^{n+1}$ with a given method, we can obtain a diagram that is known as the stencil of the method. The stencils for the methods \eqref{eq:leveque10.7} and \eqref{eq:leveque10.9} are given below. A wide variety of methods can be devised for the linear system \eqref{eq:leveque10.1} by using different finite difference approximations. A few possibilities are listed in the table below along with their stencils. Most of these are based directly on finite difference approximations to the PDE. An exception is the Lax-Wendroff method, which is based on theTaylor series expansion \begin{align} u(x,t+k) = u(x,t) + k \partial_t u(x,t) + \frac{1}{2} k^2 \partial_t^2 u(x,t) + \dots \label{eq:leveque10.10} \end{align} and the observation that from $\partial_t u = - A\partial_x u$, we can compute \begin{align} \partial_t^2 = - A \partial_x\partial_t u = - A\partial_t\partial_x u = A^2 \partial_x^2 u \end{align} so that Eq. \eqref{eq:leveque10.10} becomes \begin{align} u(x,t+k) = u(x,t) -k A \partial_x u(x,t) + \frac{1}{2}k^2 A^2 \partial_x^2 u(x,t)\label{eq:leveque10.12} \end{align} The Lax-Wendroff method then results from retaining only the first three terms of \eqref{eq:leveque10.12} and using centered difference approximations for the derivatives appearing there. With the exception of the Leapfrog method, all of themethods below are 2-level methods. For time-dependent conservation laws, 2-level methods are almost exclusively used. Methods involving more than 2 levels have additional difficulties. They require more storage (a disadvantage primarily in two or three dimensional calculations) and they require special start up procedures, since initially only one level of data is known. We will study explicit 2-level methods almost exclusively, and introduce some special notation for such methods, writing \begin{align} U^{n+1} = \mathcal{H}_k(U^n) \end{align} Here $U^{n+1}$ represents the vector of approximations $U_j^{n+1}$ at time $t^{n+1}$. The value $U_j^{n+1}$ at a particular point $j$ typically depends on several values from the vector $U^n$ (depending on how large the stencil is), and so we write \begin{align} U_j^{n+1} =\mathcal{H}_k(U^n; j) \end{align} to signify that $U^{n+1}_j$ depends on the full vector $U^n$. For example, the $\mathcal{H}_k$ operator for method \eqref{eq:leveqie10.7} takes the form \begin{align} \mathcal{H}_k(U^n;k) = U_j^n - \frac{k}{2 h}(U_{j+1}^n - U_{j-1}^n) \end{align} A list of often used discretizations is given here. This list is not exhaustive, but gives a rough idea of what is used in the wild. The graphics provide an idea of the stencil in space and time. \begin{description} \item[Backward Euler] $$U_j^{n+1} = U_j^n-\frac{k}{2h} A(U_{j+1}^{n+1} - U_{j-1}^{n+1}) $$ \begin{figure}[h!] \begin{center} \begin{tikzpicture} \fill[black] (0,1) circle (0.1); \draw (0.2,1) -- (0.8,1); \fill[black] (1,1) circle (0.1); \draw (1.2,1) -- (1.8,1); \fill[black] (2,1) circle (0.1); \draw(1,0.8) -- (1,0.2); \fill[black] (1,0) circle (0.1); \end{tikzpicture} \end{center} \end{figure} \vspace{1cm} \item[One-sided] $$U_j^{n+1} = U_j^n-\frac{k}{h} A(U_{j}^n - U_{j-1}^n) $$ \begin{figure}[h!] \begin{center} \begin{tikzpicture} \fill[black] (1,0) circle (0.1); \draw (0.2,0) -- (0.8,0); \fill[black] (1,1) circle (0.1); \draw (1,0.2) -- (1,0.8); \fill[black] (0,0) circle (0.1); \end{tikzpicture} \end{center} \end{figure} \vspace{1cm} \item[One-sided] $$U_j^{n+1} = U_j^n-\frac{k}{h} A(U_{j+1}^n - U_{j}^n) $$ \begin{figure}[h!] \begin{center} \begin{tikzpicture} \fill[black] (1,0) circle (0.1); \draw (1.2,0) -- (1.8,0); \fill[black] (1,1) circle (0.1); \draw (1,0.2) -- (1,0.8); \fill[black] (2,0) circle (0.1); \end{tikzpicture} \end{center} \end{figure} \vspace{1cm} \item[Lax-Friedrichs] $$U_j^{n+1} = \frac{1}{2}(U_{j-1}^n + U_{j+1}^n)-\frac{k}{2h} A(U_{j+1}^n - U_{j-1}^n) $$ \begin{figure}[h!] \begin{center} \begin{tikzpicture} \fill[black] (0,0) circle (0.1); \draw (0.2,0.2) -- (0.8,0.8); \fill[black] (1,1) circle (0.1); \draw (1.8,0.2) -- (1.2,0.8); \fill[black] (2,0) circle (0.1); \end{tikzpicture} \end{center} \end{figure} \vspace{1cm} \item[Lax-Wendroff] $$U_j^{n+1} = U_j^n-\frac{k}{2h} A(U_{j+1}^n - U_{j-1}^n) + \frac{k^2}{2h^2}A^2(U_{j+1}^n - 2U_j^n + U_{j-1}^n) $$ \begin{figure}[h!] \begin{center} \begin{tikzpicture} \fill[black] (0,0) circle (0.1); \draw (0.2,0) -- (0.8,0); \fill[black] (1,1) circle (0.1); \draw (1.2,0) -- (1.8,0); \fill[black] (2,0) circle (0.1); \draw(1,0.8) -- (1,0.2); \fill[black] (1,0) circle (0.1); \end{tikzpicture} \end{center} \end{figure} \vspace{1cm} \item[Leapfrog] $$U_j^{n+1} = U_j^{n-1}-\frac{k}{2h} A(U_{j+1}^n - U_{j-1}^n) $$ \begin{figure}[h!] \begin{center} \begin{tikzpicture} \fill[black] (0,1) circle (0.1); \draw (0.2,1.2) -- (0.8,1.8); \fill[black] (1,2) circle (0.1); \draw (1.2,1.8) -- (1.8,1.2); \fill[black] (2,1) circle (0.1); \draw(1.8,0.8) -- (1.2,0.2); \fill[black] (1,0) circle (0.1); \draw(0.8,0.2) -- (0.2,0.8); \end{tikzpicture} \end{center} \end{figure} \vspace{1cm} \end{description} \subsection{Local truncation error} The local truncation error $L_k(x,t)$ is a measure of how well the difference equation models the differential equation locally. It is defined by replacing the approximate solution $U_j^n$ in the difference equations by the true solution $u(x_j,t^n)$. Of course this true solution of the PDE is only an approximate solution of the difference equations, and how well it satisfies the difference equations gives an indication of how well the exact solution of the difference equations satisfies the differential equation. As an example, consider the Lax-Priedrichs method. This method is similar to the unstable method \eqref{eq:leveque10.7} but replaces $U_j^n$ by $1/2(U_{j-1}^n+U_{j+1}^n)$ and is stable provided $k/h$ is sufficiently small, as we will see later. We first write this method in the form \begin{align} \frac{1}{k}\left( U_j^{n+1} - \frac{1}{2}(U_{j-1}^n + U_{j+1}^n\right) +\frac{1}{2h} A (U_{j+1}^n - U_{j-1}^n) = 0 \end{align} so that it appears to be a direct discretization of the PDE. If we now replace each $U_j^n$ by the exact solution at the corresponding point, we will notget zero exactly. What we get instead is defined to be thelocal truncation error \begin{align} L_k(x,t) = \frac{1}{k}\left( u(x,t+k) - \frac{1}{2}(u(x-h,t)+u(x+h,t)\right) +\frac{1}{2h} A (u(x+h,t) - u(x-h,t)) \end{align} In computing the local truncation error we always assume smooth solutions, and so we can expand each term on the right hand side in a Taylor series about $u(x,t)$. Doing this and collecting terms gives (with $u=u(x,t)$): \begin{align} L_k(x,t) &= \frac{1}{k}\left( (u+k\partial_t u +\frac{1}{2} k^2 \partial_t^2 u+\dots) - (u +\frac{1}{2}h^2 \partial_x^2 u+\dots)\right) +\frac{1}{2h} A (2 h \partial_x u +\frac{1}{3}\partial_x^3 u+\dots)\\ &= \partial_t u + A\partial_x u +\frac{1}{2}\left(k\partial_t^2 u -\frac{h^2}{k} \partial_x^2 u \right) + \mathcal{O}(h^2) \end{align} Since we assume that $u(x,t)$ is the exact solution $\partial_t u +A\partial_x u =0i$ we find that \begin{align} L_k(x,t) &= \frac{1}{2} k \left( A^2 - \frac{h^2}{k^2}I\right) \partial_x^2 u(x,t) + \mathcal{O}(k^2)\\ &= \mathcal{O}(k) \ \text{as} \ k\to 0 \end{align} \subsection{Stability} %- Finite Differenzen %- Finite Volumina %- Flux-Limiter %- Positivity %- Fluiddynamik %- MHD \chapter{Hybridcodes} \chapter{Spektrale Methoden} \chapter{Lattice-Boltzmann} \bibliographystyle{natdin} \bibliography{./literatur.bib} \end{document}