diff --git a/numerics.tex b/numerics.tex index fd31f7c..77f96df 100644 --- a/numerics.tex +++ b/numerics.tex @@ -1,5 +1,5 @@ -\section*{Numerical Implementation} - +\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 @@ -7,39 +7,48 @@ 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. -\subsection*{Field Solvers} - -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 +\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 electromagentic fields (as opposed to scalar electrostatic potential and +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$. 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}. +$x_i$. +%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. 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 the make the magnitude of electric and magnetic +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}$, -there can use them interchangeably with the respective flux densities $\vec{D}$ +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}\\ @@ -109,7 +118,7 @@ the magnetic field and use \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 given current. Since small numbers of macroparticles leads to an increased noise, solvers that 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 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. @@ -156,21 +165,25 @@ comparable to the length of the cell edges. 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 +extension to $4^{th}$ order in space would look like. The discrete form of the curl then 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. 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. +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 @@ -178,12 +191,28 @@ non-standard finite-difference (NSFD) schemes have been investigated over the years. \begin{figure}[h!] +\begin{minipage}[t]{0.48\textwidth} \centering - \includegraphics[width=0.25\hsize]{figure/numerics/rotation_m24.png} + \includegraphics[width=0.35\hsize]{figure/numerics/rotation_m24.png} \caption{Finite difference approximation in M24 scheme} \label{fig:num:rot_m24} +\end{minipage} +\begin{minipage}[t]{0.48\textwidth} + \centering + \includegraphics[width=0.35\hsize]{figure/numerics/rotation_nsfd.png} + \caption{Finite difference approximation in Cole-Karkkainen schemes} + \label{fig:num:rot_ck} +\end{minipage} \end{figure} + +%\begin{figure}[h!] + %\centering + %\includegraphics[width=0.25\hsize]{figure/numerics/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 @@ -194,13 +223,7 @@ 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]{figure/numerics/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 @@ -208,7 +231,10 @@ for a narrow range of frequencies propagating on the grid. Subsequently 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. +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 @@ -221,21 +247,31 @@ given in \cite{Vay_2011}. Of course the development did not stop at this point, % Lehe_2013.pdf NCI suppression with tuned FDTD % Blinne_2018.pdf optimized FTDT stencils -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}). +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 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 @@ -343,7 +379,7 @@ Eq.~\eqref{eq:num:Bzinterpol}, the shape function should have compact support, i.e. be non-zero only up to some small $x_{max}$. In principle all these properties are satiesfied by a $\delta$-function. This -use of $S9x) = \delta(x)$ is also refered to as \textit{Nearest Grip Point} or +use of $S(x) = \delta(x)$ is also refered 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 locaton. The downside however is @@ -579,7 +615,9 @@ can be found in \cite{Ripperda_2018} or \cite{Zenitani_2018}. % \cite{Hyman_1997}), but no particle pusher based on this analytic solution is % in widespread use. -\subsection*{Deposition and Filtering} +\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 @@ -604,7 +642,7 @@ 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 approximiation to calculate the electric field at the midpoint of +difference approximation to calculate the electric field at the midpoint of the edges. Calculating the current $\vec{\jmath}(t+\Delta{t}/2)$ based on the old location @@ -614,7 +652,7 @@ $\vec{v}(t+\Delta{t}/2)$ is slightly more complicated. \begin{figure}[htbp] \begin{center} \includegraphics[width=0.5\textwidth]{currentassignment_naive.pdf} - \caption{Naive current deposition for a charged particle moving as indecated 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.} + \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} @@ -627,10 +665,10 @@ $\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 -floowing through the associated cell face over the course of a time step. +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 satiesfies the discrete continuity equation given by +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 \\ @@ -642,15 +680,15 @@ 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 -desireable and different methods have been used to correct the problem. One is -deposit the charge density deparately and to solve a Poisson equation to get +desirable and different methods have been used to correct the problem. One is +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 -depositing a current that satiesfies the discrete continuity equation directly. +depositing 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