\documentclass[twoside,onecolumn,10pt]{waflarticle}
% can use option mtpro

\usepackage{graphicx}
\usepackage{rotating}
\usepackage{scalefnt}
\usepackage{bm}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\usepackage{amsmath}

%\AtBeginEnvironment{eqnarray}{\setlength{\arraycolsep}{2pt}}
%\usepackage[hidelinks]{hyperref}

\newlength\lengthfigure                  % declare a figure width unit
\setlength\lengthfigure{0.16\textwidth} % make the figure width unit scale with the textwidth
\renewcommand{\fontsizetable}{\footnotesize\scalefont{1.0}}
\renewcommand{\fontsizefigure}{\footnotesize\scalefont{1.1}}
\renewcommand{\vec}[1]{\bm{#1}}
\let\citen\cite
\setcounter{tocdepth}{3}

\newcommand{\alb}{\vspace{0.1cm}\\} % array line break
\newcommand{\mfd}{\displaystyle}
\newcommand{\ns}{{n_{\rm s}}}
\newcommand{\nd}{3}
\renewcommand{\vec}[1]{\bm{ #1 }}

\journalvolume{Journal of Computational Physics, Vol.\ 300, Pages 779--799, 2015.}

\title{Modeling Weakly-Ionized Plasmas in Magnetic Field:\\ a New Computationally-Efficient Approach}

\author{  Bernard Parent\thanks{Associate Professor, Dept.\ of Aerospace Engineering, Pusan National University, Busan 609-735, Korea, http://bernardparent.ca.},
          ~~Sergey O.\ Macheret\thanks{Professor, School of Aeronautics and Astronautics, Purdue University, West Lafayette, IN 47907-2045, USA.},
          ~~and Mikhail N.\ Shneider\thanks{Senior Research Scientist, Dept.\ of Mechanical and Aerospace Engineering, Princeton University, Princeton, NJ 08544-5263, USA.}\\
}

%\setlength\nomenclaturelabelwidth{0.13\hsize}  % optional, default is 0.03\hsize
%\setlength\nomenclaturecolumnsep{0.09\hsize}  % optional, default is 0.06\hsize

\nomenclature{
  \begin{nomenclaturelist}{Roman symbols}
   \item[$\vec{A}$] origin of the magnet dipole moment
   \item[$A$]         cross-sectional area, $\rm m^2$
  \end{nomenclaturelist}

  \begin{nomenclaturelist}{Greek symbols}
   \item[$\alpha_{ij}$]  commonly used term in the diffusion matrix $K$
  \end{nomenclaturelist}

  \begin{nomenclaturelist}{Superscripts}
   \item[$\star$]    sum of turbulent and molecular diffusion
  \end{nomenclaturelist}

  \begin{nomenclaturelist}{Subscripts}
   \item[$t$]      turbulent
  \end{nomenclaturelist}
}

\abstract{
Despite its success at simulating accurately both non-neutral and quasi-neutral weakly-ionized plasmas, the drift-diffusion model has been observed to be a particularly stiff set of equations. Recently, it was demonstrated that the stiffness of the system could be relieved by rewriting the equations such that the potential is obtained from Ohm's law rather than Gauss's law while adding some source terms to the ion transport equation to ensure that Gauss's law is satisfied in non-neutral regions. Although the latter was applicable to multicomponent and multidimensional plasmas, it could not be used for plasmas in which the magnetic field was significant. This paper hence proposes a new computationally-efficient set of electron and ion transport equations that can be used not only for a plasma with multiple types of positive and negative ions, but also for a plasma in magnetic field. Because the proposed set of equations is obtained from the same physical model as the conventional drift-diffusion equations without introducing new assumptions or simplifications, it results in the same exact solution when the grid is refined sufficiently while being more computationally efficient: not only is the proposed approach considerably less stiff and hence requires fewer iterations to reach convergence but it yields a converged solution that exhibits a significantly higher resolution. The combined faster convergence and higher resolution is shown to result in a hundredfold increase in computational efficiency for some typical steady and unsteady plasma problems including non-neutral cathode and anode sheaths as well as quasi-neutral regions.

}

\begin{document}

\pagestyle{fancy}
\fancyhead{}
\fancyhead[CO,CE]{\begin{minipage}{\textwidth}\footnotesize\center
      \it  {B.\ Parent, S.\ O.\ Macheret, M.\ N.\ Shneider, ``Modeling Weakly-Ionized Plasmas in Magnetic Field: a New Computationally-Efficient Approach'',\\  {Journal of Computational Physics}, Vol.\ 300, Pages 779--799, 2015.}~\\ \end{minipage}}
\renewcommand{\headrulewidth}{0.0pt}

  \pagenumbering{arabic}
  \setcounter{page}{1}
  \maketitle
%  \tableofcontents
%  \makenomenclature
%%  \listoftables
%%  \listoffigures

\linespread{1.05}

\section{Introduction}

\dropword Generally referred to as magneto-plasmadynamics or magnetohydrodynamics (MHD), the process of applying a force on a fluid in motion using a magnetic field is the main mechanism behind several new aerospace technologies such as shockwave control in supersonic flows   \cite{pof:2002:poggie,aiaa:2004:shneider}, power generation during re-entry using a MHD generator  \cite{jpp:2009:fujino,aiaa:2009:wan,jsr:2012:kim}, heat shield in hypersonic flows \cite{jsr:2013:bizek,jsr:2012:kawamura},  thrust generation using a Faraday accelerator \cite{jpp:2005:parent,jpp:2007:parent}, or efficiency improvement of pulse detonation engines through MHD energy bypass \cite{jpp:2012:zeineh}. In such devices, the working fluid on which the magnetic field acts is air ionized either through high electric fields, through electron or microwave beams, or through potassium or cesium seeding. Independently of the ionization process, the  ionization fraction of the air remains low (typically less than 0.1\% or so) due to the energy needed to ionize the air being high relative to the flow enthalpy. For this reason, air plasmas in aerospace applications can be considered  \emph{weakly-ionized}.  % weakly-ionized plasmas  are such that the electrons collide mostly with non-ionized atoms or molecules, and the momentum and energy of the flow is mostly due to the bulk non-ionized atomic/molecular species

When assuming quasi-neutrality throughout, the numerical simulation of weakly-ionized plasmas in magnetic field can be accomplished efficiently by obtaining the potential from the generalized Ohm's law (see Refs.\ \cite{aiaa:2009:wan, jpp:2007:parent} for instance). However, because the quasi-neutral assumption limits its use to plasmas in which the positive and negative charges closely approach each other, such a strategy can not be applied in the vicinity of dielectric surfaces or within the cathode and anode sheaths where the positive charge density differs substantially from the negative charge density. Because the accurate modelling of the non-neutral regions near the surfaces is often critical due to the large voltage (and hence power) drop within cathode sheaths, the numerical simulation of many weakly-ionized plasmas can not be accomplished through the generalized Ohm's law  without inducing excessive error in the solution. Rather, it is deemed necessary for many problems to obtain the potential from Gauss's law and to solve additional transport equations to account for the motion of the ions and the electrons with respect to the neutrals. Commonly referred to as the  ``drift-diffusion model'', such a strategy was first demonstrated viable in solving weakly-ionized gases under the influence of an externally-applied magnetic field in Ref.\ \cite{jcp:2004:surzhikov}, and was used subsequently to obtain multiple solutions of gas discharges in which the electrons were magnetized (see for instance Refs.\ \cite{jpp:2008:poggie,jap:2009:shang,bookchapter:2009:shang}).

Despite its success at predicting accurately both non-neutral and quasi-neutral plasmas in the presence of magnetic field, the drift-diffusion model has been observed to be an exceptionally stiff set of equations. That is, the system of equations is such that it forces a numerical method to use an integration steplength which is excessively small in relation to the smoothness of the exact solution, hence resulting in a disproportionate number of iterations to reach convergence. The stiffness is further exacerbated should the plasma contain quasi-neutral regions of substantial size, in which case the number of iterations needed to obtain a solution is in the order of millions. In Ref.\ \cite{jcp:2013:parent}, it was argued that the stiffness of the drift-diffusion model originates from the potential equation based on Gauss's law being particularly sensitive to small errors in the charged species densities when the plasma becomes quasi-neutral. It was then demonstrated that the stiffness of the system could be relieved by rewriting the equations such that the potential is obtained from Ohm's law rather than Gauss's law while adding some source terms to the ion transport equation to ensure that Gauss's law is satisfied in non-neutral regions (see Ref.\ \cite{jcp:2013:parent} and also Ref.\ \cite{jcp:2007:crispel}).

The recast of the drift-diffusion set of equations first proposed in Ref.\ \cite{jcp:2013:parent} was extended to multicomponent and multidimensional plasmas in Ref.\ \cite{jcp:2014:parent}, where several test cases involving quasi-neutral plasmas between dielectrics  and non-neutral discharges between electrodes showed a remarkable improvement in computational efficiency compared to the conventional approach: Not only did the recast set of equations permit the use of considerably higher integration steplengths  resulting in a thirtyfold or more reduction in the number of iterations to reach convergence, but it also resulted in a higher resolution of the converged solution whenever the plasma included quasi-neutral regions of substantial size. The combined gains in resolution and convergence rates resulted in the recast system of equations being typically 100 times more computationally efficient than the conventional drift-diffusion equations  while not sacrificing on the generality of the physical model.

Despite being generally applicable to weakly-ionized plasmas in multiple dimensions including plasmas with various types of ions (including negative ions), the recast set of transport equations presented in Ref.\ \cite{jcp:2014:parent} is not applicable to a plasma in which either the ions or the electrons are magnetized and can hence not be used to solve problems in which the external magnetic field is significant. The goal of this paper is hence to craft a new computationally-efficient set of electron and ion transport equations that can be used not only for a multicomponent and multidimensional plasma, but also for a plasma in magnetic field. As will be shown subsequently, this will require the potential equation to be based on the \emph{generalized} Ohm's law rather than the standard form of Ohm's law and to require a change in the definition of the ambipolar electric field when recasting the transport equations for the negatively-charged species. As in prior work, it is ensured that the recast set of equations is obtained from the same physical model as the conventional drift-diffusion equations and, as such, yields the same exact solution either within quasi-neutral regions or within non-neutral regions including cathode, anode, and dielectric sheaths.

\section{Physical Model}

Let us now outline the physical model from which the recast computationally-efficient set of transport equations will be subsequently derived. Commonly referred to as the ``fluid model'' or ``drift-diffusion model'', the physical model under consideration treats the neutrals and each charged species as independent fluids with their own velocities interacting with the other fluids through collision forces. In the presence of a magnetic field, the drift-diffusion model yields the following mass conservation equation for each charged species (either electrons, positive ions, or negative ions):
%
\begin{equation}
  \frac{\partial N_k}{\partial t} + \sum_{i=1}^3 \frac{\partial}{\partial x_i} N_k \vec{V}_i^k = W_k
  \label{eqn:massconservation}
\end{equation}
%
where $k$ is an index associated with the species to be solved and where the species velocity $\vec{V}^k$ is obtained from:
%
\begin{equation}
  \vec{V}^k=\vec{V}^{\rm n} + s_k \mu_k \left(\vec{E}+\vec{V}^k \times \vec{B}\right)-\frac{\mu_k}{|C_k| N_k}\nabla P_k
 \label{eqn:Vvector}
\end{equation}
%
The latter expression for the species velocity can be obtained from the momentum equation by assuming that the terms related to inertia change and to collision forces between charged species are negligible compared to the terms related to the collision forces between the charged species and the neutrals.

In the mass and momentum equations above, $N_k$ is the number density of species $k$, $\vec{V}_i^k$ is the $i$th component of the $k$th species velocity including drift and diffusion, $\vec{V}^{\rm n}$ is the neutrals velocity vector including drift and diffusion, $W_k$ is the source term containing all chemical reactions, and $P_k$ is the partial pressure. As well, $s_k$ is the species sign  (equal to $+1$ for the positive ions and to $-1$ for the electrons and the negative ions), $C_k$ is the species charge  (equal to $-e$ for the electrons, to $+e$ for the singly-charged positive ions, to $-2e$ for the doubly-charged negative ions, etc, with $e$ the elementary charge), $\vec{E}$ is the electric field vector, $\vec{B}$ the magnetic field vector, and $\mu_k$ the species mobility.

It can be convenient to rewrite the  charged species velocity vector in tensor form as follows:
%
\begin{equation}
  \vec{V}^{k}_i = \vec{V}^{\rm n}_i+\sum_{j=1}^\nd s_k \wtilde{\mu}^k_{ij}  \vec{E}_j^{\rm n}
             - \sum_{j=1}^\nd  \frac{\wtilde{\mu}^{k}_{ij}}{|C_k| N_k} \frac{\partial P_k}{\partial x_j}
  \label{eqn:V}
\end{equation}
%
with $\vec{E}^{\rm n}$ being the effective electric field in the neutrals reference frame:
%
\begin{equation}
\vec{E}^{\rm n} \equiv \vec{E}+\vec{V}^{\rm n} \times \vec{B}
\label{eqn:En}
\end{equation}
%
and with the mobility tensor equal to:
%
\begin{equation}
\!\!\!
\begin{array}{l}\mfd
\wtilde{\mu}^k  =\frac{\mu_k}{1+\mu_k^2|\vec{B}|^2}\left[\!\!\begin{array}{ccc}
      1+\mu_k^2 \vec{B}_1^2
     & \mu_k^2\vec{B}_1\vec{B}_2+s_k \mu_k \vec{B}_3
     & \mu_k^2\vec{B}_1\vec{B}_3-s_k \mu_k \vec{B}_2 \alb
      \mu_k^2\vec{B}_1\vec{B}_2-s_k\mu_k\vec{B}_3 & 1+\mu_k^2\vec{B}_2^2 &  \mu_k^2\vec{B}_2\vec{B}_3+s_k\mu_k\vec{B}_1  \alb
      \mu_k^2\vec{B}_1\vec{B}_3 +s_k\mu_k\vec{B}_2 & \mu_k^2 \vec{B}_2\vec{B}_3-s_k\mu_k\vec{B}_1  & 1+\mu_k^2\vec{B}_3^2
    \end{array} \!\!\!\!\right]
\end{array}
\label{eqn:mutilde}
\end{equation}
%
In the latter, the magnetic field $\vec{B}$ corresponds to the externally applied magnetic field, as the induced magnetic field can be shown to have negligible impact on many weakly-ionized plasmas (the so-called low magnetic Reynolds number approximation). When the induced magnetic field plays a negligible role, and when the applied (external) magnetic field does not vary in time, it can be demonstrated that the Maxwell equations reduce to the solution of Gauss's law:
%
\begin{equation}
\sum_{j=1}^3 \frac{\partial \vec{E}_j}{\partial x_j}=\frac{1}{\epsilon_0} \sum_{k=1}^\ns C_k N_k
\label{eqn:gauss}
\end{equation}
%
in which the electric field vector can be expressed in terms of a potential function as follows:
%
\begin{equation}
  \vec{E}_j=-\frac{\partial \phi}{\partial x_j}
  \label{eqn:potential}
\end{equation}
%
The electric field potential $\phi$ exists as long as the curl of the electric field is zero, which is the case when the magnetic field does not vary in time.
Although not required to solve the system of equations outlined above, one physical parameter that is often used when analyzing plasma flowfields is the current density $\vec{J}$, which is defined as:
%
\begin{equation}
  \vec{J}_i \equiv \sum_{k=1}^\ns C_k N_k  \vec{V}^k_i
 \label{eqn:Jdefinition}
\end{equation}
%
After substituting in the latter the velocity tensor from Eq.\ (\ref{eqn:V}), the following expression for the current can be obtained:
%
\begin{equation}
\begin{array}{l}
\mfd  \vec{J}_i = \sum_{j=1}^3  \wtilde{\sigma}_{ij} \vec{E}_j^{\rm n}
             - \sum_{j=1}^3 \sum_{k=1}^\ns s_k \wtilde{\mu}^k_{ij}  \frac{\partial P_k}{\partial x_j}
+ \rho_{\rm e} \vec{V}_i^{\rm n}
\end{array}
\label{eqn:J}
\end{equation}
%
in which the tensor conductivity and the net charge density are defined as:
%
\begin{equation}
\begin{array}{l}
\mfd
\wtilde{\sigma}\equiv\sum_{k=1}^\ns |C_k| N_k \wtilde{\mu}^k
\end{array}
\label{eqn:sigmatilde}
\end{equation}
%
%
\begin{equation}
\rho_{\rm e}\equiv\sum_{k=1}^\ns C_k N_k
\label{eqn:rhoe}
\end{equation}
%
Finally, a constitutive relation that is needed to close the system of equations is the ideal gas law which yields the partial pressure given the number density and the temperature:
%
\begin{equation}
P_k = N_k k_{\rm B} T_k
\label{eqn:Pk}
\end{equation}
%
where $T_k$ is the species temperature.

Commonly used to simulate weakly-ionized plasmas in the presence of magnetic field, the physical model outlined above can predict accurately not only quasi-neutral phenomena such as ambipolar diffusion and ambipolar drift but also non-neutral phenomena within cathode and anode sheaths. It can also be used to simulate multicomponent plasmas in which there are several types of ions (either negative or positive) as well as unsteady plasmas in which the displacement current is significant. Nonetheless, it is pointed out that the physical model used herein is subject to several assumptions, with the most critical being the following: (i) the forces due to collisions between charged species are small compared to forces due to collisions  between the charged species and the neutrals; (ii) the induced magnetic field is negligible; (iii) within the momentum equation, the terms related to the inertia change are negligible compared to the terms related to collision forces. As was demonstrated in Ref.\ \cite{jcp:2011:parent}, such assumptions are well justified as long as the plasma remains weakly-ionized (i.e. the ionization fraction should remain lower than $10^{-3}$ or so), which is the case for a wide variety of plasmas used in industrial applications.

\section{Conventional Governing Equations}

When using digital computers, the conventional approach to simulate the drift-diffusion physical model outlined in the previous section  consists of solving a transport equation for each charged species along with the potential equation obtained from Gauss's law (see for instance Refs.\ \cite{jcp:2004:surzhikov,jpp:2008:poggie,jap:2009:shang,book:2012:surzhikov,aiaaconf:2014:surzhikov}). The charged species transport equation can be derived from the mass conservation equations as outlined in Eq.\ (\ref{eqn:massconservation}) with the species velocity from the momentum equation applicable to a weakly-ionized plasma as shown in Eq.\ (\ref{eqn:V}). This  yields the following:
%
\begin{equation}
  \frac{\partial N_k}{\partial t} + \sum_{i=1}^3 \frac{\partial}{\partial x_i} N_k\left(\vec{V}^{\rm n}_i+\sum_{j=1}^\nd s_k \wtilde{\mu}^k_{ij}  \vec{E}_j^{\rm n}
             - \sum_{j=1}^\nd  \frac{\wtilde{\mu}^{k}_{ij}}{|C_k| N_k} \frac{\partial P_k}{\partial x_j}\right) = W_k
\end{equation}
%
When the magnetic field is strong (resulting in an electron Hall parameter $\mu_{\rm e}|\vec{B}|$ approaching or exceeding 1), and when the transport equations are solved through an implicit integration strategy, it is beneficial to the stability of the method to extract from the pressure gradient terms the diffusion terms that are diagonally dominant. This can be achieved by first subtracting and adding a pressure gradient term on the LHS as follows:
%
\begin{equation}
  \frac{\partial N_k}{\partial t} + \sum_{i=1}^3 \frac{\partial}{\partial x_i} N_k\left(\vec{V}^{\rm n}_i+\sum_{j=1}^\nd s_k \wtilde{\mu}^k_{ij}  \vec{E}_j^{\rm n}
             - \sum_{j=1}^\nd  \frac{\wtilde{\mu}^{k}_{ij}}{|C_k| N_k} \frac{\partial P_k}{\partial x_j}
-\frac{\mu_k}{|C_k| N_k} \frac{\partial P_k}{\partial x_i} +\frac{\mu_k}{|C_k| N_k} \frac{\partial P_k}{\partial x_i}
\right) = W_k
\end{equation}
%
Then, expand the partial pressure using the ideal gas law $P_k=N_k k_{\rm B} T_k$ and reformat:
%
\begin{equation}
\begin{array}{l}\mfd
  \frac{\partial N_k}{\partial t} + \sum_{i=1}^3 \frac{\partial}{\partial x_i} N_k\left(\vec{V}^{\rm n}_i+\sum_{j=1}^\nd s_k \wtilde{\mu}^k_{ij}  \vec{E}_j^{\rm n}
             - \sum_{j=1}^\nd  \frac{\wtilde{\mu}^{k}_{ij}-\delta_{ij} \mu_k}{|C_k| N_k} \frac{\partial P_k}{\partial x_j}\right)
-\sum_{i=1}^3 \frac{\partial}{\partial x_i} \left(\frac{T_k k_{\rm B} \mu_k}{|C_k| } \frac{\partial N_k}{\partial x_i} \right)\alb\mfd
=W_k+
\sum_{i=1}^3 \frac{\partial}{\partial x_i} \left(\frac{N_k k_{\rm B} \mu_k}{|C_k| } \frac{\partial T_k}{\partial x_i}
\right)
\end{array}
\end{equation}
%
with $\delta_{ij}$ the Kronecker delta which is equal to 1 should $i=j$ and to 0 otherwise. We can write the latter in matrix form as follows:
%
\begin{equation}
 R = Z \frac{\partial U}{\partial t} + \sum_{i=1}^3 \frac{\partial}{\partial x_i} A_i U  - \sum_{i=1}^3  \frac{\partial}{\partial x_i}  \left( K \frac{\partial U}{\partial x_i}\right)  -S
\end{equation}
%
where $R$ is the residual vector and the other matrices correspond to:
%
\begin{eqnarray}
 \left[U\right]_k&=&N_k \alb
 \left[A_i\right]_{k,k} &=& \vec{V}^{\rm n}_i+\sum_{j=1}^\nd s_k \wtilde{\mu}^k_{ij}  \vec{E}_j^{\rm n}
             - \sum_{j=1}^\nd  \frac{\wtilde{\mu}^{k}_{ij}-\delta_{ij} \mu_k}{|C_k| N_k} \frac{\partial P_k}{\partial x_j}  \alb
 \left[K\right]_{k,k} &=& \frac{T_k k_{\rm B} \mu_k}{|C_k|} \alb
 \left[Z\right]_{k,k} &=& 1 \alb
 \left[S\right]_k &=&W_k+
\sum_{i=1}^3 \frac{\partial}{\partial x_i} \left(\frac{N_k k_{\rm B} \mu_k}{|C_k| } \frac{\partial T_k}{\partial x_i}
\right)
\end{eqnarray}
%
where the notation $[M]_{k,k}$ denotes the diagonal element on the $k$th row of the matrix $M$ while the notation $[F]_k$ refers to the element on the $k$th row of the vector $F$. The latter yields a diagonally-dominant diffusion matrix $K$ even at high electron Hall parameter, which is a necessary condition for stable integration using an implicit method. As well, extracting the non-diagonal diffusion terms from matrix $K$ and inserting them in the convection matrix $A$ permits standard central stencils to be used when discretizing the diffusion terms. However, should they include cross-derivatives, the diffusion terms would require non-standard upwinded stencils or they would lead to spurious oscillations at a high Hall parameter (see Ref.\ \cite{jcp:2011:parent} for more details on this point).

The electric field is obtained from the potential as in Eq.\ (\ref{eqn:potential}) which itself is found by integrating the potential equation concurrently to the mass conservation equations. To ensure that Gauss's law is satisfied within the non-neutral regions, it is necessary to obtain the potential equation from Gauss's law by substituting Eq.\ (\ref{eqn:potential}) into Eq.\ (\ref{eqn:gauss}):
%
\begin{equation}
\sum_{j=1}^3 \frac{\partial^2 \phi}{\partial x_j^2}=-\frac{\rho_{\rm e}}{\epsilon_0}
\label{eqn:potentialgauss}
\end{equation}
%
The latter constitute what is here denoted as the ``conventional governing equations'', which are commonly used to solve weakly-ionized plasmas (either quasi-neutral or non-neutral) in the presence of a magnetic field using discrete methods.

\section{Recast of the Positively-Charged Species Transport Equations}

The ``conventional governing equations'' outlined in the previous section are well known to be exceptionally stiff. Such stiffness has been observed to be independent of the type of integration strategy used, either explicit or fully-implicit. As first outlined in Ref.\ \cite{jcp:2013:parent}, the stiffness originates from the potential equation based on Gauss's law being particularly sensitive to small errors in the electron or ion densities whenever the plasma becomes quasi-neutral. One approach that has been shown successful in relieving the stiffness is by rewriting the governing equations such that the electric field is obtained from a potential based on Ohm's law rather than Gauss's law (see Refs.\ \cite{jcp:2013:parent} and \cite{jcp:2014:parent}). As well, to ensure that Gauss's law is satisfied some source terms need to be added to the positive ion transport equations.

We here generalize the approach proposed in Ref.\ \cite{jcp:2014:parent} to a plasma in magnetic field. To do so, it is convenient to first define $\Delta \vec{V}^k$ as the difference between the velocity of species $k$ and the velocity of species $k$ should the magnetic field be zero:
%
\begin{equation}
\Delta \vec{V}^k_i \equiv \vec{V}^k_i - \left(\vec{V}^{\rm n}_i+ s_k \mu_k  \vec{E}_i
             -   \frac{\mu_k}{|C_k| N_k} \frac{\partial P_k}{\partial x_i}\right)
\label{eqn:deltaV}
\end{equation}
%
Isolate $\vec{V}^k$ in the latter and substitute in Eq.\ (\ref{eqn:massconservation}), and simplify noting that $s_k=1$ and $C_k$ is positive for the positive ions:
%
\begin{equation}
  \frac{\partial N_{k}}{\partial t} + \sum_{i=1}^3 \frac{\partial}{\partial x_i} \left(N_k \Delta \vec{V}_i^k +N_{k} \vec{V}^{\rm n}_i+N_{k}  \mu_k   \vec{E}_i
             -    \frac{\mu_k }{|C_{k}| } \frac{\partial P_{k}}{\partial x_i}\right) = W_{k}
\end{equation}
%
The source terms that must be added to ensure that Gauss's law is satisfied can be obtained by multiplying Gauss's law Eq.\ (\ref{eqn:gauss}) by $\mu_{k} N_{k}$ and rearranging:
%
\begin{equation}
0=\mu_{k} N_{k} \sum_{i=1}^3 \frac{\partial \vec{E}_i}{\partial x_i}-\mu_{k} N_{k}\frac{1}{\epsilon_0} \sum_{r=1}^\ns C_r N_r
\end{equation}
%
Then, we add the latter to the former to obtain:
%
\begin{equation}
  \frac{\partial N_{k}}{\partial t} + \sum_{i=1}^3 \frac{\partial}{\partial x_i} \left(N_k \Delta \vec{V}_i^k +N_{k} \vec{V}^{\rm n}_i+N_{k}  \mu_k  \vec{E}_i
             -    \frac{\mu_k }{|C_{k}| } \frac{\partial P_{k}}{\partial x_i}\right) = W_{k}+\mu_{k} N_{k} \sum_{i=1}^3 \frac{\partial \vec{E}_i}{\partial x_i}-\mu_{k} N_{k}\frac{1}{\epsilon_0} \sum_{r=1}^\ns C_r N_r
\end{equation}
%
And we note that the following statement holds:
%
\begin{equation}
\mu_{k} N_{k} \sum_{i=1}^3 \frac{\partial \vec{E}_i}{\partial x_i}
= \sum_{i=1}^3 \frac{\partial }{\partial x_i} \mu_{k} N_{k} \vec{E}_i
 - \sum_{i=1}^3 \vec{E}_i \frac{\partial }{\partial x_i} \mu_{k} N_{k}
\end{equation}
%
Substitute the latter in the former, rewrite the partial pressure term using the ideal gas law outlined in Eq.\ (\ref{eqn:Pk}), expand the pressure derivatives, and rearrange:
%
\begin{equation}
\begin{array}{l}\mfd
  \frac{\partial N_{k}}{\partial t}
+ \sum_{i=1}^3 \frac{\partial}{\partial x_i} N_k \left(\Delta \vec{V}_i^k + \vec{V}^{\rm n}_i\right)
- \sum_{i=1}^3  \frac{\partial}{\partial x_i} \left(
                 \frac{\mu_k k_{\rm B} T_{k}}{|C_{k}| } \frac{\partial N_{k}}{\partial x_i}
\right)
+ \sum_{i=1}^3 \vec{E}_i \frac{\partial }{\partial x_i} \mu_{k} N_{k}
 \alb\mfd~~~~~
=
 W_{k}
-\mu_{k} N_{k}\frac{1}{\epsilon_0} \sum_{r=1}^\ns C_r N_r
+ \sum_{i=1}^3  \frac{\partial}{\partial x_i} \left(
                 \frac{\mu_k k_{\rm B} N_{k}}{|C_{k}| } \frac{\partial T_{k}}{\partial x_i}
\right)
\end{array}
\label{eqn:positivespecies}
\end{equation}
%
The latter is the modified transport equation for the positively-charged species, and must be used for all positive ions. It is obtained without introducing assumptions or simplifications from the physical model outlined in Section 2.

\section{Recast of the Negatively-Charged Species Transport Equations}

It can be shown that a system of equations composed of the recast transport equation outlined in Eq.\ (\ref{eqn:positivespecies}) for the positive ions, combined with the standard transport equation for the negative species (Eq.\ (\ref{eqn:massconservation})), and combined with a potential equation based on the generalized Ohm's law \cite{jcp:2011:parent} has the same exact solution as the conventional governing equations outlined in Section 3 while not exhibiting high stiffness. However, such a set of equations would yield a rather low resolution and require significantly more nodes to reach the same accuracy within quasi-neutral regions of the plasma. As was  demonstrated in Ref.\ \cite{jcp:2013:parent}, such can be overcome by rewriting the transport equation for the negative species in \emph{ambipolar form} following the approach outlined in Ref.\ \cite{jcp:2011:parent:2}. Rewriting the transport equations in ambipolar form increases the resolution because it reduces the dependence of the potential equation on the charged species transport equations in quasi-neutral regions.

The ambipolar form of the negatively-charged species transport equations can be obtained by first isolating $\vec{V}_i^k$ in  Eq.\ (\ref{eqn:deltaV}) and substituting in Eq.\ (\ref{eqn:massconservation}) noting that $s_k=-1$ when the species is negatively-charged:
%
\begin{equation}
\begin{array}{l}\mfd
  \frac{\partial N_k}{\partial t}
+ \sum_{i=1}^3 \frac{\partial}{\partial x_i}  N_k \left(  \Delta \vec{V}_i^k +\vec{V}^{\rm n}_i - \mu_k  \vec{E}_i
\right)
- \sum_{i=1}^3  \frac{\partial}{\partial x_i}  \left(
   \frac{\mu_k }{|C_k|} \frac{\partial P_k}{\partial x_i}
\right)
= W_k
\end{array}
\end{equation}
%
Then, without loss of generality, we can add and subtract the ambipolar electric field $\vec{E}^\prime$ to the electric field:
%
\begin{equation}
\begin{array}{l}\mfd
  \frac{\partial N_k}{\partial t}
+ \sum_{i=1}^3 \frac{\partial}{\partial x_i}  N_k \left(  \Delta \vec{V}_i^k +\vec{V}^{\rm n}_i - \mu_k  \left(\vec{E} -\vec{E}^\prime  \right)_i
\right)
- \sum_{i=1}^3  \frac{\partial}{\partial x_i}  \mu_k N_k \vec{E}^\prime_i
- \sum_{i=1}^3  \frac{\partial}{\partial x_i}  \left(
   \frac{\mu_k }{|C_k|} \frac{\partial P_k}{\partial x_i}
\right)
= W_k
\end{array}
\label{eqn:negspecies1}
\end{equation}
%
As outlined in Ref.\ \cite{jcp:2014:parent}, significant gains in resolution can be reached when $\vec{E}^\prime$ is defined as the component of the electric field that cancels out all components of the current except due to drift. However, defining the ambipolar electric field  in this manner leads to some difficulties when the plasma is in the presence of a magnetic field. Not only does this result in a particularly complicated transport equation in which several terms are expensive to compute, but this  also entails convergence hangs when the magnetic field reaches high values. We here find it necessary to define the ambipolar electric field in a slightly different manner as the component of the electric field that cancels out all components of the \emph{unmagnetized} current except due to drift and due to the motion of the neutrals, with the unmagnetized current being the current that would be obtained locally should the magnetic field be zero. The ambipolar electric field thus takes on the form:
%
\begin{equation}
 \vec{E}_i^\prime \equiv \vec{E}_i - \frac{1}{\sigma} \left(\vec{J}_i-\sum_{r=1}^\ns C_r N_r \Delta \vec{V}_i^r -\rho_{\rm e} \vec{V}_i^{\rm n} \right)
 \label{eqn:Eprimedefinition}
\end{equation}
%
where the term within the bracket on the RHS can be easily shown to be the unmagnetized current density (the current density in the absence of a magnetic field):
%
\begin{equation}
\mfd  \vec{J}_i-\sum_{r=1}^\ns C_r N_r \Delta \vec{V}_i^r  - \rho_{\rm e} \vec{V}_i^{\rm n} =   \sigma \vec{E}_i
             -  \sum_{r=1}^\ns s_r \mu_r  \frac{\partial P_r}{\partial x_i}
\label{eqn:Jzero}
\end{equation}
%
and where the conductivity $\sigma$ is defined as:
%
\begin{equation}
  \sigma \equiv \sum_{k=1}^\ns \mu_k |C_k| N_k
\end{equation}
%
After substituting Eq.\ (\ref{eqn:Jzero}) in Eq.\ (\ref{eqn:Eprimedefinition}) it can be shown that:
%
\begin{equation}
   \vec{E}_i^\prime =
   \sum_{r=1}^\ns \frac{s_r \mu_r }{\sigma}  \frac{\partial P_r}{\partial x_i}
\label{eqn:Eprime}
\end{equation}
%
Then, after substituting $\vec{E}-\vec{E}^\prime$ from Eq.\ (\ref{eqn:Eprimedefinition}) and $\vec{E}^\prime$ from Eq.\ (\ref{eqn:Eprime}) into Eq.\ (\ref{eqn:negspecies1}) and rearranging, we obtain:
%
\begin{equation}
\begin{array}{l}\mfd
  \frac{\partial N_k}{\partial t}
+ \sum_{i=1}^3 \frac{\partial}{\partial x_i}   N_k \left(      \sum_{r=1}^\ns \frac{\delta_{rk}\sigma+ C_r N_r \mu_k}{\sigma}   \Delta \vec{V}_i^r +\left(1+\frac{\mu_k \rho_{\rm e}}{\sigma}\right)\vec{V}^{\rm n}_i - \frac{\mu_k}{\sigma}  \vec{J}_i \right)
\alb\mfd~~~~
- \sum_{i=1}^3 \sum_{r=1}^{\ns} \frac{\partial}{\partial x_i} \left( \mu_r \left( \frac{\delta_{rk}}{|C_k|}+ \frac{ \mu_k N_k s_r }{\sigma} \right) \frac{\partial P_r}{\partial x_i}\right)
=
W_k
\end{array}
\end{equation}
%
where $\delta_{rk}$ is the Kronecker delta.
After splitting the derivative involving the current $\vec{J}$ into two terms and noting that the divergence of the current can be written as:
%
\begin{equation}
\sum_{i=1}^3 \frac{\partial \vec{J}_i}{\partial x_i}=-\sum_{r=1}^\ns C_r \frac{\partial N_r}{\partial t}
\end{equation}
%
the following is obtained:
%
\begin{equation}
\begin{array}{l}\mfd
  \sum_{r=1}^{\ns} \frac{\delta_{rk}\sigma+C_r  \mu_k N_k}{\sigma} \frac{\partial N_r}{\partial t}
+ \sum_{i=1}^3 \frac{\partial}{\partial x_i}   N_k \left(\sum_{r=1}^\ns \frac{\delta_{rk}\sigma+C_r  \mu_k N_r}{\sigma} \Delta \vec{V}_i^r +\left(1+\frac{\mu_k\rho_{\rm e}}{\sigma}\right)\vec{V}^{\rm n}_i\right)
\alb\mfd~~~~
- \sum_{i=1}^3 \vec{J}_i \frac{\partial}{\partial x_i}  \left( \frac{\mu_k N_k}{\sigma}
\right)
- \sum_{i=1}^3 \sum_{r=1}^{\ns} \frac{\partial}{\partial x_i} \left(\mu_r \left(\frac{ \delta_{rk} }{ |C_k|}+   \frac{ \mu_k N_k s_r}{\sigma}\right)  \frac{\partial P_r}{\partial x_i}\right)
= W_k
\end{array}
\end{equation}
%
We then use the ideal gas relationship in Eq.\ (\ref{eqn:Pk}), expand the partial derivatives, and rewrite:
%
\begin{equation}
\begin{array}{l}\mfd
  \sum_{r=1}^{\ns} \frac{\delta_{rk}\sigma+C_r  \mu_k N_k}{\sigma} \frac{\partial N_r}{\partial t}
+ \sum_{i=1}^3 \frac{\partial}{\partial x_i}   N_k \left(\sum_{r=1}^\ns \frac{\delta_{rk}\sigma+C_r  \mu_k N_r}{\sigma} \Delta \vec{V}_i^r +\left(1+\frac{\mu_k\rho_{\rm e}}{\sigma}\right)\vec{V}^{\rm n}_i\right)
- \sum_{i=1}^3 \vec{J}_i \frac{\partial}{\partial x_i}  \left( \frac{\mu_k N_k}{\sigma}
\right)
\alb\mfd~~~~
- \sum_{i=1}^3 \sum_{r=1}^{\ns} \frac{\partial}{\partial x_i} \left(\mu_r k_{\rm B} T_r\left(\frac{ \delta_{rk} }{ |C_k|}+   \frac{ \mu_k N_k s_r}{\sigma}\right)  \frac{\partial N_r}{\partial x_i}\right)
= W_k
+ \sum_{r=1}^\ns \sum_{i=1}^3  \frac{\partial}{\partial x_i} \left( \mu_r k_{\rm B} N_r   \left(\frac{\delta_{rk}}{|C_k|}+\frac{s_r \mu_k N_k}{\sigma}\right)  \frac{\partial T_r}{\partial x_i} \right)
\end{array}
\label{eqn:negativespecies}
\end{equation}
%
The latter is the proposed ``ambipolar form'' of the transport equation for the negatively-charged species. It must be used not only for the electrons but for all negative ions. It is emphasized that the recast Eq.\ (\ref{eqn:negativespecies}) is obtained from the physical model outlined in Section 2 without making any assumption or simplification. As such, it can be used not only in quasi-neutral regions but also in non-neutral regions including cathode and anode sheaths.

\section{Proposed Governing Equations}

We can combine the transport equation for the positively-charged species, Eq.\ (\ref{eqn:positivespecies}) and the transport equation for the negatively-charged species, Eq.\ (\ref{eqn:negativespecies}) into a single equation:
%
\begin{equation}
\begin{array}{l}\mfd
  \sum_{r=1}^{\ns} \frac{\delta_{rk}\sigma + \beta^-_k C_r  \mu_k N_k}{\sigma} \frac{\partial N_r}{\partial t}
+ \sum_{i=1}^3 \frac{\partial}{\partial x_i}   N_k \left(\sum_{r=1}^\ns \frac{\delta_{rk}\sigma+\beta_k^- C_r  \mu_k N_r}{\sigma} \Delta \vec{V}_i^r + \left(1+\beta_k^- \frac{\mu_k\rho_{\rm e}}{\sigma}\right)\vec{V}^{\rm n}_i\right)
\alb\mfd~~~~
-  \sum_{i=1}^3 \beta_k^- \vec{J}_i \frac{\partial}{\partial x_i}  \left( \frac{\mu_k N_k}{\sigma}
\right)
+ \sum_{i=1}^3 \beta_k^+ \vec{E}_i \frac{\partial }{\partial x_i} \mu_{k} N_{k}
- \sum_{i=1}^3 \sum_{r=1}^{\ns} \frac{\partial}{\partial x_i} \left(\mu_r k_{\rm B} T_r\left(\frac{ \delta_{rk} }{ |C_k|}+   \frac{\beta_k^- s_r \mu_k N_k }{\sigma}\right)  \frac{\partial N_r}{\partial x_i}\right)
\alb\mfd~~~~
= W_k
+ \sum_{r=1}^\ns \sum_{i=1}^3  \frac{\partial}{\partial x_i} \left( \mu_r k_{\rm B} N_r   \left(\frac{\delta_{rk}}{|C_k|}+\frac{\beta_k^- s_r \mu_k N_k}{\sigma}\right)  \frac{\partial T_r}{\partial x_i} \right)
-\beta_k^+ \mu_{k} N_{k}\frac{\rho_{\rm e}}{\epsilon_0}
\end{array}
\end{equation}
%
with
%
\begin{equation}
\beta_k^\pm = \max(0,~\pm s_k)
\end{equation}
%
We can simplify further the latter by defining the ambipolar tensor $\alpha$ as:
%
\begin{equation}
\alpha_{kr} \equiv
  \frac{\delta_{rk}\sigma+ \beta_k^- C_r  \mu_k N_k}{\sigma}
=  |C_r| \left( \frac{\delta_{rk}}{|C_k|}+  \frac{ \beta_k^- s_r \mu_k N_k}{\sigma}\right)
=  \frac{N_k}{N_r}\frac{\delta_{rk}\sigma+ \beta_k^- C_r  \mu_k N_r}{\sigma}
\end{equation}
%
and by noting that the following equality holds:
%
\begin{equation}
1+\beta_k^- \frac{\mu_k\rho_{\rm e}}{\sigma}
= \sum_{r=1}^\ns \frac{\delta_{rk}\sigma+ \beta_k^- C_r  \mu_k N_r}{\sigma}
 \end{equation}
%
We thus obtain:
%
\begin{equation}
\begin{array}{l}\mfd
  \sum_{r=1}^{\ns} \alpha_{kr} \frac{\partial N_r}{\partial t}
+ \sum_{i=1}^3 \sum_{r=1}^\ns  \frac{\partial}{\partial x_i}      \alpha_{kr} \left( \Delta \vec{V}_i^r + \vec{V}^{\rm n}_i \right)N_r
+  \sum_{i=1}^3 \left( \beta_k^+ \vec{E}_i- \beta_k^- \vec{J}_i   \right) \frac{\partial}{\partial x_i}  \mu_{k} N_{k} \left( \beta_k^+ + {\textstyle \frac{1}{\sigma}} \beta_k^-
\right)
\alb\mfd~~~~
- \sum_{i=1}^3 \sum_{r=1}^{\ns} \frac{\partial}{\partial x_i} \left(\frac{\mu_r k_{\rm B} T_r \alpha_{kr}}{|C_r|}  \frac{\partial N_r}{\partial x_i}\right)
= W_k
-\beta_k^+ \mu_{k} N_{k}\frac{\rho_{\rm e}}{\epsilon_0}
+ \sum_{r=1}^\ns \sum_{i=1}^3  \frac{\partial}{\partial x_i} \left( \frac{\mu_r k_{\rm B} N_r  \alpha_{kr}}{|C_r|}   \frac{\partial T_r}{\partial x_i} \right)
\end{array}
\label{eqn:positivenegativespecies}
\end{equation}
%
The proposed charged species transport equations can also be written in general matrix form as follows:
%
\begin{equation}
  R=Z\frac{\partial U}{\partial t} + \sum_{i=1}^3\frac{\partial}{\partial x_i} A_i U
    + \sum_{i=1}^3 G_i \frac{\partial}{\partial x_i} B U - \sum_{i=1}^3  \frac{\partial}{\partial x_i} \left( K \frac{\partial U}{\partial x_i} \right)-S
\label{eqn:Rproposed}
\end{equation}
%
where $R$ is the residual which is driven to zero through the iterative process, and where the other matrices can be shown to correspond to:
%
\begin{eqnarray}
 \left[U\right]_k&=&N_k \alb
 \left[A_i\right]_{k,k}&=&\sum_{r=1}^\ns \frac{\delta_{rk}\sigma+\beta_k^- C_r  \mu_k N_r}{\sigma} \Delta \vec{V}_i^r + \left(1+\beta_k^- \frac{\mu_k\rho_{\rm e}}{\sigma}\right)\vec{V}^{\rm n}_i \alb
% \left[A_i\right]_{k,k}&=&\sum_{r=1}^\ns \alpha_{kr}\frac{N_r}{N_k} \left(\Delta \vec{V}_i^r +\vec{V}^{\rm n}_i\right) \alb
 \left[B\right]_{k,k}&=&\beta_k^+ \mu_k + \frac{1}{\sigma}\beta_k^- \mu_k \alb
 \left[G_i\right]_{k,k}&=&\beta_k^+ \vec{E}_i - \beta_k^- \vec{J}_i \alb
 \left[K\right]_{k,r} &=& \frac{\mu_r k_{\rm B} T_r \alpha_{kr}}{|C_r|} \alb
 \left[Z\right]_{k,r} &=& \alpha_{kr} \alb
 \left[S\right]_k &=& W_k -\beta_k^+ \mu_{k} N_{k}\frac{\rho_{\rm e}}{\epsilon_0}
+ \sum_{r=1}^\ns \sum_{i=1}^3  \frac{\partial}{\partial x_i} \left( \frac{\mu_r k_{\rm B} N_r \alpha_{kr}}{|C_r|}  \frac{\partial T_r}{\partial x_i} \right)
\end{eqnarray}
%
In the latter, the velocity difference $\Delta \vec{V}$ can be obtained by substituting Eq.\ (\ref{eqn:V}) into Eq.\ (\ref{eqn:deltaV}):
%
\begin{equation}
 \Delta \vec{V}_i^k =
   \sum_{j=1}^\nd s_k \wtilde{\mu}^k_{ij}  \vec{E}_j^{\rm n}
      + \sum_{j=1}^\nd  \left(\frac{\delta_{ij} \mu_k-\wtilde{\mu}^{k}_{ij}}{|C_k| N_k}\right) \frac{\partial P_k}{\partial x_j}
-  s_k \mu_k  \vec{E}_i
\end{equation}
%
while the current density is obtained from Eq.\ (\ref{eqn:J}) and the electric field is obtained from the potential equation based on Ohm's law which can be derived from the physical model outlined in Section 2 following the approach shown in Ref.\ \cite{jcp:2011:parent}:
%
\begin{equation}
\!\begin{array}{l}
  \mfd\sum_{i=1}^3 \frac{\partial}{\partial x_i}\left(\sum_{j=1}^3 \wtilde{\sigma}_{ij} \left(-\frac{\partial \phi}{\partial x_j}  + \left(\vec{V}^{\rm n} \times \vec{B}\right)_j\right)
             - \sum_{j=1}^3 \sum_{k=1}^\ns s_k   \wtilde{\mu}^{k}_{ij}  \frac{\partial P_k}{\partial x_j}
              + \rho_{\rm e} \vec{V}_i^{\rm n}  \right)=-  \frac{\partial \rho_{\rm e}}{\partial t}
\end{array}
\end{equation}
%
from which the electric field can be found using Eq.\ (\ref{eqn:potential}).

It is noted that the set of equations proposed herein is obtained from the same physical model as the conventional set of equations without introducing any additional assumption or simplification. As such, the exact solution obtained from the proposed set of equations is identical to the one obtained from the conventional set not only for quasi-neutral plasmas with significant ambipolar diffusion and drift phenomena but also for non-neutral sheaths, for unsteady plasmas, as well as for plasmas where the displacement current is non-negligible.

Despite yielding the same exact solution as the conventional equations, the set of equations proposed herein is advantaged  by being considerably less stiff and hence requiring significantly less computing effort to reach convergence. Further, as will be shown below in the Test Cases section, the proposed equations yield a considerably higher resolution within plasma regions that are quasi-neutral.

\section{Boundary Conditions}

When the electron Hall parameter (i.e.\ the product between the electron mobility and the magnitude of the magnetic field) becomes significant due to a strong applied magnetic field, the enforcement of boundary conditions can become problematic. The difficulties arise when imposing a zero current condition perpendicular to dielectric surfaces by setting to zero the component of $\vec{J}$ perpendicular to the surface in Eq.\ (\ref{eqn:J}). When the magnetic field is non-zero, such leads to the potential $\phi$ at the boundary node depending not only on the properties of the nearest inner node but also on the properties of the adjacent boundary nodes. Numerical experiments show that such direct dependence between boundary nodes entails major convergence problems for many plasma flowfields either when using the conventional or the proposed set of governing equations. The convergence difficulties become more severe when the electron Hall parameter approaches or exceeds 0.1 often leading to the solution diverging towards aphysical states or continuously oscillating without reaching a root.

One way that this problem can be overcome is by setting the magnetic field to zero on all boundary nodes and on all inner nodes adjacent to boundary nodes. In doing so, the plasma is not subject to a magnetic field near the surfaces and the same boundary conditions as used for a plasma in the absence of magnetic field can be specified:
%
\begin{equation}
\frac{\partial }{\partial \eta} N_+ \vec{V}^{+}_\eta = 0
{~~~~~\rm and~~~~~}
N_{-}=0
{~~~~~\rm and~~~~~}
N_{\rm e}=\frac{\gamma}{\mu_{\rm e}} \sum_{k=1}^\ns N_k \mu_k \beta_k^+
{~~~~~\rm for~dielectrics~or~for~}
\vec{E}_\eta<0
\end{equation}
%
%
\begin{equation}
N_{+}=0
{~~~~~\rm and~~~~~}
\frac{\partial }{\partial \eta} N_- \vec{V}^{-}_\eta = 0
{~~~~~\rm and~~~~~}
\frac{\partial }{\partial \eta} N_{\rm e} \vec{V}^{\rm e}_\eta= 0
{~~~~~\rm otherwise}
\end{equation}
%
with $\gamma$ being the secondary emission coefficient and the subscripts/superscripts ``e'', ``$-$'', and ``$+$'' denoting the electron species, the negative ion species, and the positive ion species respectively. In the latter $\eta$ refers to the coordinate perpendicular to the boundary and pointing away from the surface towards the nearest inner node, while  $\vec{E}_\eta$ and $\vec{V}^k_\eta$ refer to the electric field component and $k$th species velocity component in the direction of $\eta$.

As well, the potential on the dielectrics is specified such that the current perpendicular to dielectric surfaces is zero. Because the magnetic field is zero at the boundary nodes and the near-boundary nodes, this yields the following expression for the dielectrics potential:
%
\begin{equation}
\mfd  \frac{\partial \phi}{\partial \eta} =
             - \frac{1}{\sigma}\sum_{k=1}^\ns s_k \mu_k  \frac{\partial P_k}{\partial \eta}{~~~~~\rm for~dielectrics~only}
\end{equation}
%

It may be argued that setting the magnetic field to zero on the boundary and near-boundary nodes may entail some errors in the converged solution. However, such errors disappear as the grid is refined because the volume of the unmagnetized regions near the surfaces becomes insignificant compared to the total volume of the plasma.

When applying the boundary conditions, it is found necessary to under-relax the update of the number densities and of the potential on the boundary nodes in order to prevent convergence hangs. For all cases here considered, either when using the conventional or the proposed equations, the relaxation factor is set to 0, 0.8, and 0.5 for the ion, electron, and potential equations respectively. The relaxation factor is such that, when set to 0, the boundary node property does not depend on its previous value when being updated and, when set to 1, the boundary node property remains unaltered.

\section{Discretization and Integration}

To enable a fair comparison, both the conventional and the proposed sets of equations are discretized using the same stencils and solved using the same iterative procedure.

The convection terms are discretized with the Steger-Warming scheme turned second-order accurate through the Van Leer TVD limiter, while the diffusion terms are discretized with centered stencils, and the term $G \delta_x BU$ is discretized as specified in Ref.\ \cite{jcp:2013:parent}. When extending the Steger-Warming scheme or the centered diffusion stencils to multiple dimensions, a dimensional-splitting strategy is employed in which the derivatives are split amongst the several dimensions and then discretized using one-dimensional operators. Because the problems tackled herein are such that the molecular and ambipolar diffusion effects are sufficiently strong to prevent discontinuities in the charged species densities, it is found unnecessary to use the upwinded discretization stencils for the potential equation proposed in Ref.\ \cite{jcp:2011:parent} (which are needed to prevent even-odd node discoupling of the potential to occur in the vicinity of discontinuities). Rather, all terms within the potential equation are discretized with centered stencils whether the potential equation is based on Gauss's law or the generalized Ohm's law.

The discretized set of transport equations is converged by minimizing the residual vector through a block-implicit ADI algorithm \cite{jcp:1980:briley}. To improve the convergence rates, it is found beneficial to linearize the Townsend ionization chemical source terms under the condition of constant current and to partially linearize the source terms added to enforce Gauss's law within the proposed equations   (see Ref.\ \cite{jcp:2014:parent} for details).  The potential equation either based on Ohm's law or Gauss's law is not solved in coupled form with the species transport equations. Rather, as in other plasma solvers, a more robust integration strategy is to solve the potential equation independently through a scalar approximate factorization algorithm (see Ref.\ \cite{jcp:2011:parent}). Thus, the convergence procedure consists of performing one iteration in pseudotime of the charged species transport equations keeping the potential constant, followed by one or more iterations  in pseudotime of the potential keeping the charged species densities constant. Such a procedure is repeated until the residual of the potential and of all species transport equations is reduced sufficiently. Through trial and error, it is found that specifying the pseudotime step as follows for the potential equation yields optimal convergence rates:
%
\begin{equation}
\Delta \tau_\phi = \left\{
\begin{array}{ll}
\mfd L_{\rm c}\cdot \raisebox{-1.5ex}{$\stackrel{\stackrel{\scriptstyle 3}{\textstyle \rm min}}{\scriptstyle i=1}$} \left(\frac{\Delta x_i}{\sigma_{\rm ref}+\sigma}\right) & \textrm{for the potential equation based on Ohm's law} \alb
\mfd L_{\rm c}\cdot \raisebox{-1.5ex}{$\stackrel{\stackrel{\scriptstyle 3}{\textstyle \rm min}}{\scriptstyle i=1}$} \left({\Delta x_i}\right) & \textrm{for the potential equation  based on Gauss's law} \alb
\end{array}
\right.
\end{equation}
%
As well, either for the proposed or conventional charged species transport equations, the pseudotime step is set to the same value for all nodes and equal to the highest value that satisfies the following condition on all inner nodes:
%
\begin{equation}
\Delta \tau_N \le {\rm CFL}\cdot \raisebox{-1.5ex}{$\stackrel{\stackrel{\scriptstyle 3}{\textstyle \rm min}}{\scriptstyle i=1}$} \left(\mfd\frac{\Delta x_i}{a_{\rm ref}+\mu_{\rm e} \left|\vec{E}_i-\vec{E}^\prime_i\right|}\right)~~~~\textrm{for all inner nodes}
\end{equation}
%
where $\Delta x_i$ is the grid spacing in the $i$th dimension, $L_{\rm c}$ is a characteristic length that varies depending on the problem solved, $a_{\rm ref}$ and $\sigma_{\rm ref}$ are some reference sound speed and conductivity typically set to 300~m/s and 0.003~S/m, and CFL is a user-defined parameter that is set to some low value (close to 1) in the initial stages of convergence and then progressively increased. How the parameters affecting the local pseudotime step are varied will be outlined in more detail for each test case.

\section{Test Cases}

The test cases considered herein consist of simulating electron-beamed ionized air plasmas enclosed by dielectrics and electrodes. Unless otherwise stated, the air plasma includes 6 components ($\rm N_2$, $\rm O_2$, $\rm e^-$, $\rm N_2^+$, $\rm O_2^+$, and $\rm O_2^-$) with the reaction rates  as well as the mobilities for each charged species being taken from Ref.\ \cite{jcp:2014:parent}. The plasma chemical reactions include Townsend ionization, electron-beam ionization, ion-ion recombination, electron attachment as well as dissociative recombination. For simplicity and to avoid the handling of the O and N species, we rewrite the dissociative recombination reaction for oxygen $\rm e^- + O_2^+ \rightarrow O+O$ to $\rm e^- + O_2^+ \rightarrow O_2$ and similarly for nitrogen. As can be demonstrated starting from the energy transport equation for each charged species, the electric field appearing within the expressions for the mobilities and within the Townsend ionization rates must be substituted by the \emph{effective electric field} in the respective species reference frame, i.e.\ $|\vec{E}+\vec{V}^k \times \vec{B}|$. A justification for doing so as well as details on how to obtain the effective electric field through an iterative process are given in Appendix A. The characteristic length scale needed to converge the potential equation is varied cyclically for all cases as  $L_{\rm c}=0.0003,~0.003,~0.03,~0.0003~{\rm m},...$, while the CFL number and the number of potential subiterations  are outlined below on a case by case basis.

%
\begin{table*}
  \center
  \begin{threeparttable}
    \tablecaption{Relative error assessment in solving the multicomponent plasma test case (with quasi-neutral region).\tnote{a,b}}
    \label{tab:case6-error}
    \fontsizetable
    \begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}}llllcllll}
    \toprule
     ~       & \multicolumn{9}{c}{Average relative error }\\
\cmidrule{2-10}
     ~                         & \multicolumn{4}{c}{$\mfd\frac{1}{S N_{\rm ref}}\int_{0}^{S}{\left|N_{\rm e}-\left(N_{\rm e}\right)_{\rm exact}\right|}~{\rm d}S$}  &~& \multicolumn{4}{c}{$\mfd\frac{1}{S \phi_{\rm ref}}\int_{0}^{S}{\left|\phi-\phi_{\rm exact}\right|}~{\rm d}S$} \\
\cmidrule{2-5}\cmidrule{7-10}
     Governing equations                         & $44^2$\,nodes   &  $87^2$\,nodes  & $173^2$\,nodes & $345^2$\,nodes &~& $44^2$\,nodes & $87^2$\,nodes & $173^2$\,nodes & $345^2$\,nodes \\
    \midrule
     Proposed                  & 0.180    &  0.0730     & 0.0250   & 0.0071 &~&  0.205  & 0.0785    & 0.0148  & 0.0047\\
     Conventional              & 0.201    &  0.0811     & 0.0287   & 0.0081 &~&  0.830   & 0.326    & 0.120  & 0.041 \\
    \bottomrule
    \end{tabular*}
 \begin{tablenotes}
   \item[a] The ``exact solution'' is computed with the proposed governing equations and a mesh of $689^2$ nodes
   \item[b] The domain surface area $S$ is set to 9~mm$^2$ while the reference density $N_{\rm ref}$ and reference potential $\phi_{\rm ref}$ are given values of $10^{17}$/m$^3$ and 10~V respectively.
 \end{tablenotes}
   \end{threeparttable}
\end{table*}
%

Being less stiff and offering significantly faster convergence are not the only advantages that the proposed equations offer. The present approach is further  advantaged by offering a higher resolution of the converged solution within quasi-neutral regions. This becomes apparent when evaluating the relative error on the potential on several meshes, as is done in Table \ref{tab:case6-error}: for a given mesh size, the error on the potential is typically reduced fourfold when using the proposed equations. Differently put, the present approach can achieve the same accuracy on the potential with a mesh size being 4 times smaller, which would result approximately in a eightfold decrease in computational effort  (the computing time is proportional to the mesh size times the number of iterations, with the number of iterations typically increasing with the square root of the mesh size in 2D). The relatively low resolution of the solution when using the conventional equations is attributed to the potential equation based on Gauss's law being strongly function of the net charge density, which is itself highly sensitive to small errors of the electron and ion densities in regions of quasi-neutrality. This leads to an amplification of the numerical error when computing the potential and a somewhat low resolution of the converged solution. Because the potential equation based on the generalized Ohm's law is not strongly dependent on the net charge density, the proposed equations are not subject to such an error amplification and lead to a solution that is more accurate for a given mesh size.

When simulating a non-neutral plasma in which the electrons are magnetized and in which there is a quasi-neutral region of significant size, it is here seen that the proposed equation set is not only considerably less stiff than the conventional set but also exhibits a higher resolution of the converged solution. Combined together, these lead to a considerable two-hundredfold decrease in computing effort for a desired level of accuracy.

\subsection{Gas Discharge}

%
\begin{figure}[!b]
   \fontsizefigure
   \center
   \includegraphics[width=3.5\lengthfigure]{setup_discharge.pdf}
   \caption{Gas discharge test case; all dimensions in millimeters.}
\label{fig:setup_discharge}
\end{figure}
%

The third test case here investigated consists of a gas discharge between two electrodes with a voltage difference of 800 Volts and with the boundary conditions and problem setup schematized in Fig.\ \ref{fig:setup_discharge}. The magnetic field is fixed to 0.8~Tesla and is perpendicular to the computational plane. This results in a significant magnetic field effect on the flow properties due to the electron Hall parameter being of $0.5$. Because such a test case requires a very high number of iterations to converge when using the conventional equations, and because solving a 6-component plasma chemical model requires significantly more computing effort than a 3-component model, it is here decided to reduce the complexity of the chemical model by solving a reduced set of reactions involving only 3 species. The air plasma here considered is thus composed of one type of positive air ions, one type of air neutral molecules, and electrons, with the chemical reactions and mobilities taken from Ref.\ \cite{jcp:2014:parent}. The voltage difference is sufficient for Townsend ionization to occur near the cathode, and the electron-beam power deposited is sufficiently high for a quasi-neutral region to form near the anode. Such a test case is hence well suited to test the performance of the proposed equations in simulating non-neutral cathode sheaths in the presence of a magnetic field typical of plasma magneto-aerodynamics.

\section{Conclusions}

A new set of equations is here presented to simulate weakly-ionized plasmas in magnetic field using the drift-diffusion fluid model. The proposed set of equations consists of obtaining the potential from the generalized Ohm's law rather than from Gauss's law as is the case in the conventional set of equations. To ensure that Gauss's law is satisfied in non-neutral regions some source terms are added to the ion transport equations. Because the proposed equations are obtained from the same physical model as the conventional equations without introducing new simplifications, they yield the same exact solution either in non-neutral or in quasi-neutral plasma regions (including sheaths near the surfaces as well as regions with significant ambipolar diffusion and drift).

The present equation set is nonetheless advantaged over the conventional set by not being subject to high stiffness when the plasma includes one or more zones of quasi-neutrality. Reducing the stiffness of the system permits larger integration steplengths to be used which leads to a significant decrease in the number of iterations to reach convergence. Several test cases reveal that the integration steplength can be increased by 20 times or more leading typically to a thirtyfold decrease in  the iteration count whenever a quasi-neutral region of substantial size forms within the plasma. Such gains in convergence acceleration are observed to be independent of the size of the mesh, of the current magnitude, or of the strength of the magnetic and  electric fields.

Another advantage of the proposed equations is in yielding a higher resolution of the converged solution within (or in the vicinity of) quasi-neutral regions when the externally-applied magnetic field is significant. Indeed, several grid convergence studies of plasmas  with large quasi-neutral regions show that the electric field potential is subject to excessive error when obtained from a potential equation based on Gauss's law. This is attributed to the latter amplifying the error associated with the charged species densities when the net charge tends towards zero. Such an error amplification is avoided when obtaining the potential from the generalized Ohm's law because the latter is not strongly dependent on the net charge density, which leads to the conventional set of equations typically requiring 5 times more nodes to yield the same accuracy as the proposed set within or nearby quasi-neutral regions.

Not only is the present set of equations advantaged by being less stiff and hence exhibiting faster convergence, but it also results in a more accurate solution on a given mesh. When combined together, these gains in resolution and convergence acceleration result in a one-hundredfold or more increase in computational efficiency for typical steady and unsteady problems involving a quasi-neutral region of substantial size. On the other hand, should the plasma be entirely non-neutral and not include zones  of quasi-neutrality, the proposed equations are observed to converge as rapidly and to exhibit as high a resolution as the conventional set. Because the proposed governing equations yield significant computational advantages with no associated drawback, they are  unconditionally recommended to simulate numerically through the drift-diffusion model weakly-ionized plasmas in the presence of magnetic field.

\section*{Acknowledgment}

This research was supported by a 2-year Pusan National University Research Grant.

%% The Appendices part is started with the command \appendix;
%% appendix sections are then done as normal sections
% \appendix

\appendix

\section{Effective Electric Field in Species Reference Frame}
\label{AppendixA}

A justification is here given to why the effective electric field must be determined in the electron reference frame rather than in the neutrals reference frame when computing the electron mobility and the Townsend ionization rates.

Let us start from the electron energy transport equation as taken from Ref.\ \cite[page 34]{book:1991:raizer}:
%
\begin{equation}
  \frac{\partial }{\partial t} \left( \frac{3}{2} N_{\rm e} k_{\rm B} T_{\rm e} \right)
  + \sum_{i=1}^\nd \frac{\partial }{\partial x_i} \left(\frac{5}{2}  N_{\rm e} k_{\rm B} T_{\rm e} \vec{V}_i^{\rm e} \right)
  - \sum_{i=1}^\nd \frac{\partial }{\partial x_i} \kappa_{\rm e} \frac{\partial T_{\rm e}}{\partial x_i}
  =
   \vec{F}^{\rm e}\cdot \vec{V}^{\rm e}
 - \frac{3}{2} N_{\rm e} k_{\rm B} T_{\rm e} \zeta_{\rm e} \nu_{\rm m} - Q_{\rm ei}
 \end{equation}
%
where $Q_{\rm ei}$ represents the amount of energy the electrons lose in creating new electrons through Townsend
ionization (that is, the product between the ionization potential and the number of electrons per unit volume per unit time created by electron-impact processes), $\kappa_{\rm e}$ is the thermal diffusivity, $\nu_{\rm m}$ the collision frequency, $\vec{F}^{\rm e}$ is the force per unit volume acting on the electrons due to electromagnetic fields in the electron reference frame, and $\zeta_{\rm e}$ is a term function of the effective electric field which can be determined similarly as in Ref.\ \cite{misc:1995:boeuf}.

Consider the energy transport equation in the ``local approximation'' and neglect the unsteady, convective, and diffusive terms. Then, noting that the collision frequency can be written as follows:
%
\begin{equation}
\nu_{\rm m}=\frac{e}{m_{\rm e}\mu_{\rm e}}
\end{equation}
%
we obtain the following expression for the electron temperature:
%
\begin{equation}
  T_{\rm e}
=
 \frac{2 m_{\rm e} \mu_{\rm e}}{3 e N_{\rm e} k_{\rm B} \zeta_{\rm e} }
\left(  \vec{F}^{\rm e}\cdot \vec{V}^{\rm e}
 - Q_{\rm ei}\right)
\label{eqn:appendix:Te}
 \end{equation}
%
where the force per unit volume acting on the electrons in the electron reference frame due to electromagnetic fields  corresponds to:
%
\begin{equation}
\vec{F}^{\rm e} = -eN_{\rm e}\left(\vec{E} + \vec{V}^{\rm e} \times \vec{B}\right)
\label{eqn:appendix:Fe}
\end{equation}
%
and where, in the ``local approximation'',  the electron velocity can be taken from Eq.\ (\ref{eqn:Vvector}) neglecting the pressure gradients:
%
\begin{equation}
  \vec{V}^{\rm e}=\vec{V}^{\rm n} - \mu_{\rm e} \left(\vec{E}+\vec{V}^{\rm e} \times \vec{B}\right)
\label{eqn:appendix:Ve}
\end{equation}
%
Substitute Eq.\ (\ref{eqn:appendix:Ve}) and Eq.\ (\ref{eqn:appendix:Fe}) in Eq.\ (\ref{eqn:appendix:Te}):
%
\begin{equation}
  T_{\rm e}
=
 \frac{2 m_{\rm e} \mu_{\rm e}}{3 e N_{\rm e} k_{\rm B} \zeta_{\rm e} }
\left( -e N_{\rm e} \left(\vec{E} + \vec{V}^{\rm e} \times \vec{B}\right)\cdot \left(\vec{V}^{\rm n} - \mu_{\rm e} \left(\vec{E}+\vec{V}^{\rm e} \times \vec{B}\right)\right)
 - Q_{\rm ei}\right)
 \end{equation}
%
Because the magnitude of the neutrals velocity can be assumed small compared to the magnitude of the electron velocity, the electron temperature becomes:
%
\begin{equation}
  T_{\rm e}
=
 \frac{2 m_{\rm e} \mu_{\rm e}}{3 e N_{\rm e} k_{\rm B} \zeta_{\rm e} }
\left(  N_{\rm e} \mu_{\rm e} e |\vec{E}+\vec{V}^{\rm e}\times \vec{B}|^2
 - Q_{\rm ei}\right)
 \end{equation}
%
From the latter, it is clear that in the local approximation the electron temperature is a function of the electric field in the electron reference frame $|\vec{E}+\vec{V}^{\rm e}\times \vec{B}|$, not of the electric field in the laboratory frame $|\vec{E}|$. Because the electron mobility and the Townsend ionization rates depend on the electron temperature, and because the electron temperature is a function of the electric field in the electron reference frame, it follows that the electron mobility and Townsend ionization rates should be determined from an effective electron electric field as follows:
%
\begin{equation}
 E_{\rm eff}^{\rm e}=|\vec{E}^{\rm e}|=|\vec{E}+\vec{V}^{\rm e}\times\vec{B}|
\label{eqn:Ee_refframe}
\end{equation}
%
where the electron velocity $\vec{V}^{\rm e}$ can be obtained from Eq.\ (\ref{eqn:V}):
%
\begin{equation}
  \vec{V}^{\rm e}_i = \vec{V}^{\rm n}_i+\sum_{j=1}^\nd s_{\rm e} \wtilde{\mu}^{\rm e}_{ij}  \vec{E}_j^{\rm n}
             - \sum_{j=1}^\nd  \frac{\wtilde{\mu}^{\rm e}_{ij}}{|C_{\rm e}| N_{\rm e}} \frac{\partial P_{\rm e}}{\partial x_j}
\label{eqn:Ve_refframe}
\end{equation}
%
Thus, to find $E_{\rm eff}^{\rm e}$, proceed iteratively: (i) Find $\vec{V}^{\rm e}$ from Eq.\ (\ref{eqn:Ve_refframe}), (ii) Find $E_{\rm eff}^{\rm e}=|\vec{E}^{\rm e}|$ from Eq.\ (\ref{eqn:Ee_refframe}), and (iii) update $\wtilde{\mu}^{\rm e}$ using the latest value of $E_{\rm eff}^{\rm e}$ found in step (ii). Repeat steps (i)-(iii) until $E_{\rm eff}^{\rm e}$ is converged. It is sometimes necessary to under-relax the update of the effective electric field $E_{\rm eff}^{\rm e}$ in the above iterative process in order to prevent some convergence hang, with the relaxation factor typically given a value of 0.9.

Similarly, it can be demonstrated that the effective electric field  $E_{\rm eff}^k$ needed for the ion mobilities  must also be determined in the reference frame of the charged species under consideration (i.e. $E_{\rm eff}^k=|\vec{E}^k|=|\vec{E}+\vec{V}^k\times \vec{B}|$). The electric field in the ion frame of reference can be obtained for each ion species through the use of Eq.\ (\ref{eqn:V}) by following a similar iterative process as  outlined above.

\bibliographystyle{waflarticle}
\bibliography{all}

\end{document}


% This LaTeX was auto-generated from an M-file by MATLAB.
% To make changes, update the M-file and republish this document.

      \subsection{solve\_chol.m}

\begin{par}
solve\_chol - solve linear equations from the Cholesky factorization. Solve A*X = B for X, where A is square, symmetric, positive definite. The input to the function is R the Cholesky decomposition of A and the matrix B. Example: X = solve\_chol(chol(A),B);
\end{par} \vspace{1em}
\begin{par}
NOTE: The program code is written in the C language for efficiency and is contained in the file solve\_chol.c, and should be compiled using matlabs mex facility. However, this file also contains a (less efficient) matlab implementation, supplied only as a help to people unfamiliar with mex. If the C code has been properly compiled and is avaiable, it automatically takes precendence over the matlab code in this file.
\end{par} \vspace{1em}
\begin{par}
Copyright (c) 2004, 2005, 2006 by Carl Edward Rasmussen. 2006-02-08.
\end{par} \vspace{1em}

\subsection*{Code}

\begin{lstlisting}
function x = solve_chol(A, B)

if nargin ~= 2 | nargout > 1
  error('Wrong number of arguments.');
end

if size(A,1) ~= size(A,2) | size(A,1) ~= size(B,1)
  error('Wrong sizes of matrix arguments.');
end

x = A\(A'\B);
\end{lstlisting}


%
% %CopyrightBegin%
%
% Copyright Ericsson AB 2017. All Rights Reserved.
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
%     http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%
% %CopyrightEnd%
%

\chapter{Portable hashing}

\label{chapter:hashing}
\index{term!hashing|(}
\index{erlang:hash/2 BIF@\T{erlang:hash/2} BIF|(}
\index{hash/2 BIF@\T{hash/2} BIF|(}

The function \I{Hash} defined in this appendix is used as part of the
definition of the BIF \T{erlang:hash/2} (\S\ref{section:hash2}).
Given an arbitrary \Erlang\ term and a positive integer $r$, it returns
an integer in the range $[0,r-1]$.  The function has been designed with
the aim to make it a good hash function, i.e., that it spreads function
values evenly across the range.
\index{erlang:hash/2 BIF@\T{erlang:hash/2} BIF|)}
\index{hash/2 BIF@\T{hash/2} BIF|)}

\section{Definitions}

%\index{C1, ..., C9@$C_1$, \ldots, $C_9$|(}
We make use of nine constants $C_1$, \ldots, $C_9$:
\begin{align*}
C_1 &= 268440163 \\
C_2 &= 268439161 \\
C_3 &= 268435459 \\
C_4 &= 268436141 \\
C_5 &= 268438633 \\
C_6 &= 268437017 \\
C_7 &= 268438039 \\
C_8 &= 268437511 \\
C_9 &= 268439627
\end{align*}
%\index{C1, ..., C9@$C_1$, \ldots, $C_9$|)}
%\index{Foldl@\I{Foldl}|(}
We will use a helper function \I{Foldl}, such that
\[\I{Foldl}(F,E,\langle v_1,\ldots,v_k\rangle) =
F(v_k,F(v_{k-1},\ldots F(v_2,F(v_1,E)) \ldots))\]
(Note that $\I{Foldl}(F,E,\langle\rangle) = E$, regardless of $F$.)
%\index{Foldl@\I{Foldl}|)}

\noindent\index{  bitwise exclusive OR@$\otimes$}
$w_1 \otimes w_2$ denotes the bitwise exclusive OR of $w_1$ and $w_2$.

\noindent All arithmetic operations in this appendix are modulo $2^{32}$.

\section{The hash function}

%\index{Hash@\I{Hash}|(}
The main function \I{Hash} is defined as follows:
\[\I{Hash}(\TZ{t},r) = H(\TZ{t},0) \bmod r\]
%\index{Hash@\I{Hash}|)}
The auxiliary function $H$ is defined by cases.
\begin{itemize}
\item If \TZ{t} is an atom having a printname with character codes $i_1$, ..., $i_k$,
where for all $j$, $1\leq j\leq k$, $i_j\in[0,255]$, then
\[H(\TZ{t},h) = C_1*h+\I{Foldl}(F,0,\langle i_1,\ldots,i_k\rangle),\]
where
\begin{align*}
F(i,h) &= G(16h + i) \\
G(j) &= (j \bmod 2^{28}) \otimes 16(\lfloor j / 2^{28}\rfloor).
\end{align*}
(Note that for any application of $F$, $i\in[0,255]$ and $h\in[0,2^{28}-1]$,
and for any application of $G$, $j\in[0,2^{28}-1]$.)
\item If \TZ{t} is a fixnum, then
\[H(\TZ{t},h) = C_2*h+(\Er[t] \bmod 2^{32}).\]
I'M NOT SURE I GOT THIS RIGHT AND I'D RATHER NOT MENTION FIXNUMS AND BIGNUMS!!!
\item If \TZ{t} is a bignum where the 32-bit words of its absolute value
in little-endian order is $w_1$, ..., $w_k$, then
\[H(\TZ{t},h) = C*\I{Foldl}(F,h,\langle w_1,\ldots,w_k\rangle)+k,\]
where
\begin{alignat*}{2}
     C &= C_2 && \qquad\text{if $\Er[t]\geq0$;} \\
       &= C_3 && \qquad\text{if $\Er[t]<0$.} \displaybreak[0]\\[\smallskipamount]
F(w,h) &= C_2*h+w
\end{alignat*}
\item If \TZ{t} is \T{[]}, then
\[H(\TZ{t},h) = C_3*h+1.\]
\item If \TZ{t} is a binary consisting of the bytes $i_1$, \ldots, $i_k$, then
\[H(\TZ{t},h) = C_4*\I{Foldl}(F,h,\langle i_1,\ldots,i_l\rangle)+k,\]
where
\begin{align*}
l &= \min(k,15) \\
F(i,h) = C_1*h+i.
\end{align*}
\item If \TZ{t} is a PID, then
\[H(\TZ{t},h) = C_5*h+\I{MagicPid}(\TZ{t}).\]
\item If \TZ{t} is a port or a ref, then
\[H(\TZ{t},h) = C_9*h+\I{MagicPortRef}(\TZ{t}).\]
\item If \TZ{t} is a float represented by the two unsigned 32-bit quantities
$w_1$ and $w_2$, then (THIS IS NOT VERY PORTABLE!!!)
\[H(\TZ{t},h) = C_6*h+(w_1 \otimes w_2).\]
\item If \TZ{t} is a term \T{[$\Z{t}_1$,\tdots,$\Z{t}_k$|$\Z{t}_{k+1}$]}, then
\[H(\TZ{t},h) = C_8*H(\TZ{t}_{k+1},\I{Foldl}(H,h,\langle t_1,\ldots,t_k\rangle)).\]
\item If \TZ{t} is a tuple \T{\{$\Z{t}_1$,\tdots,$\Z{t}_k$\}}, then
\[H(\TZ{t},h) = C_9*\I{Foldl}(H,h,\langle t_1,\ldots,t_k\rangle)+k.\]
\end{itemize}
\index{term!hashing|)}


\documentclass[main.tex]{subfiles}

\begin{document}
	\section{Discussion}
	In this thesis we set out to create a suite of programs to visualise key concept in the field of condensed matter physics. These concepts included crystal structures, families of lattice planes, a simulation of neutron scattering, along with band structures of two dimensional materials.

	The end result is a code package written in Python which accomplishes just that. It includes 4 main functions: \texttt{Lattice}, \texttt{Reciprocal}, \texttt{Scattering} and \texttt{Band\_structure}. These 4 functions take in a wealth of arguments, supplied by the user, and produce some sort of figure. Examples of these being the crystal structure of hexagonal lattice with a one atom basis (figure \ref{fig:lattice_demo_2}), the (001) family of lattice planes for a bcc lattice (figure \ref{fig:lattice_planes}), neutron scattering on an fcc lattice (figures \ref{fig:scattering_no_systemic} and \ref{fig:scattering_systemic}) or the band structure of a monovalent two dimensional material with a high strength potential (figure \ref{fig:band_structure_strong}).

	More can be done with these programs though, and they are by no means a comprehensive resource. For the lattice plotting program, there is currently no perfect algorithm to detect type of lattice that the user has input.

	The algorithm employed to detect lattices relies on the user inputting primitive lattice vectors with the specifications from appendix \ref{app:lattice}. These lattices can be rotated and scaled to the heart's desires, and the program will still detect them. But the algorithm does not take into account the non-uniqueness of primitive lattice vectors.

	The "easy" way to take this into account would be to use the method specified in section \ref{sec:lattice_theory}, calculating the matrix $ M $ for the different lattices and checking whether or not it meets the necessary criteria. However, this method cannot work if the user also rotates the lattice. Different magnitudes of input primitive lattice vectors will also complicate things, as the program would have to check a range of different sets of primitive lattice vectors for each lattice. For example, say the user inputs an fcc lattice with $ a_1 = a \D(1,0,0) $, $ a_2 = a\D(0, 1/2, 1/2) $ and $ a_3 = a\D(1/2, 0, 1/2) $. There is currently no way for the program to "know" which magnitude to use for the primitive lattice vectors used for comparison, and the only recourse is to brute-force check all combinations.

	So currently no catch-all solution of classification is implemented. A thing to note is that the current algorithms only depend on the primitive lattice vectors. A different approach may be to construct the full crystal and look for a specific "type" of unit cell, corresponding to one of the Bravais lattices. However, this will necessarily involve a more complicated algorithm, which unfortunately there was not time for.

	Furthermore, the program only calculates the relevant quantities for one specific set of values per function call. As such, if the user wants to see how systemic absences appear in scattering experiments, or how the Fermi surface distorts for stronger potentials, they will need to manually call the relevant function multiple times with different form factors or potential strength. This gets tedious after a while.

	A solution to this is to create some sort of GUI which will display input boxes or sliders for the relevant quantities, automatically call the functions and display the results. This can be done, for example with the python package \href{http://flask.pocoo.org/}{Flask}, which allows the creation of web-applications. These can be run locally on the users machine and allows for javascript integration. This is especially useful (necessary, even!) for accomplishing the goal of added interactivity, as Matplotlib figures can be rendered as javascript objects.

	With regards to distortion of the Fermi surface: The next (small) step would be to maybe include different two dimensional lattices. A rectangular lattice would be as simple as altering a value or two in the code, for example. But perhaps a better change would be to bump up the dimensions of the lattices to three. Doing this, however, means we run into problems with the number of available dimensions. It seems we live in a universe with only three spatial dimensions, which means we will use up all of those just specifying the geometry of the lattice, leaving no dimension for any other quantities of interest - like the dispersion relation of the particles in the crystal.

	This limits us to only looking at isosurfaces of energy - like the Fermi surface, where we in two dimensions could view the entire Fermi sea (and the rest of the dispersion relation). While this would be  enough to view the distortion of the Fermi surface (especially if combined with a web-app as specified above), there is the added issue of the computational time required. Currently, for a two dimensional lattice, with $ n_k $ values of $ \V{k} $ in each direction, and $ n_G $ allowed values of $ \V{G} $ (again in each direction), necessitates finding the eigenvalues of $ n_k^2 $ matrices of size $ n_G^2 \times n_G^2 $. By default these values og $ n_k $ and $ n_G $ are around 100 and 7 respectively, meaning the program diagonalises $ 10^4 $ $ 49\times 49 $ matrices. Increasing the dimensionality would increase both the number of matrices to be diagonalised, and the size of these. We would increase the amount of matrices by a factor of $ n_k $, and the size of each of these would go from $ n_G^2 \times n_G^2$ to $ n_G^3 \times n_G^3 $. With the standard arguments this would necessitate the diagonalisation of $ 10^6 $ matrices of size $ 343 \times 343 $. A very considerable increase.

	As it currently stands the program does take a while to compute the band structure (around a second or so, for a decent resolution), and to get the same resolution in three dimensions would take at least a factor $ n_k \approx 100 $ longer (assuming it takes the same amount of time to diagonalise a $ 49 \times 49 $ matrix as it does a $ 343 \times 343 $ matrix, which it most certainly does not). So if three dimensions are to be considered, the program would need to be thoroughly optimised. One way to do this would be to employ an algorithm to find just the lowest eigenvalue of these matrices, as we are only concerned with the lowest band - i.e. the Fermi surface.

	A line had to be drawn somewhere though, and a two dimensional lattice seemed like a reasonable compromise between added dimensionality and computational complexity.

	One last issue is in regards to the programming language and packages chosen. Python is an interpreted language, which means that it necessarily trades computational speed for added ease of development. There are alternatives to this, like \href{https://nim-lang.org/}{Nim} or \href{https://julialang.org/}{Julia}, which are properly compiled or just-in-time compiled respectively. They do not, however, have as large a community as Python does, and therefore not as big a support for third-party packages like Matplotlib.

	Further, Matplotlib has one glaring issue in that it does not support a fully fledged 3D graphics engine. This means that all the three dimensional figures in this thesis and the programs are actually just 2D projections of underlying 3D data (of course, computer screens are 2D, so the projection has to happen at some point, but the way Matplotlib does it has significant drawbacks). This creates artefacts like how there is no proper support for the intersection of surface plots. This can be seen in the band structure program, where the orange horizontal plane, indicating the Fermi energy, does not properly intersect the dispersion relation, seen in blue.

	There are other packages, like \href{https://docs.enthought.com/mayavi/mayavi/}{Mayavi} which do support proper 3D plotting. However, these problems (and their potential solution in this package) were discovered too late in the process of writing, so could not be solved in time.

	In conclusion: 4 programs have been created which illustrate concepts in the field of condensed matter physics. While they are not without their flaws or potential for improvement, they do still hold merit, and could be a valuable tool if used in combination with traditional book-based learning.

\end{document}


    \filetitle{irisuserconfig}{User configuration file called at the IRIS start-up}{config/irisuserconfighelp}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
function c = irisuserconfig(c)
    c.option = value;
    c.option = value;
    ...
 end
\end{verbatim}

\paragraph{Description}\label{description}

You can create your own configuration file to modify the general IRIS
options of your choosing at each IRIS start-up. The file must be saved
as \texttt{irisuserconfig.m} on the Matlab search path.

The \texttt{irisuserconfig.m} file must be an m-file function taking one
input argument (a struct with the factory settings), and returning one
output argument (a struct with the user-modified settings); see
\href{config/irisset}{\texttt{irisset}} for the list of options you can
change. In addition, you can also add your own new options, which will
be then also accessible through \href{config/irisset}{\texttt{irisset}}
and \href{config/irisget}{\texttt{irisget}}.

\paragraph{Example}\label{example}

If you want the names of months to be displayed in Finnish, create the
following m-file and save it in a folder which is on the Matlab search
path:

\begin{verbatim}
function c = irisuserconfig(c)
    c.months = { ...
        'Tammikuu','Helmikuu','Maaliskuu', ...
        'Huhtikuu','Toukokuu','Kesakuu', ...
        'Heinakuu','Elokuu','Syyskuu', ...
        'Lokakuu','Marraskuu','Joulukuu'};
end
\end{verbatim}

This modification will take effect after you next run
\href{config/irisstartup}{\texttt{irisstartup}}. Your graphs will be
then fluent in Finnish:

\begin{verbatim}
x = tseries(mm(2009,1):mm(2009,6),@rand);
plot(x,'dateformat','MmmmYY');
\end{verbatim}


% !TEX TS-program = pdflatex
% The line above tells TeXShop to use the latex -> dvi -> distiller
% path to produce the pdf.

\documentclass[12pt]{article}

\usepackage{amsmath,amssymb,amsfonts}
\usepackage{courier,type1cm,array}
\usepackage{makeidx,graphicx,multicol}
\usepackage[bottom]{footmisc} % places footnotes at page bottom
\usepackage{natbib,float}
\usepackage[vmargin=1in,hmargin=1in]{geometry}

% allows compilation with pdflatex, under Windows
\usepackage{epstopdf}

% Coloring of R code listings
\usepackage[formats]{listings}
\usepackage{color}
\definecolor{mygreen}{rgb}{0.1,0.5,0.1}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
\definecolor{mygrey}{rgb}{0.3,0.3,0.1}
\lstset{
language=R,
otherkeywords={data.frame},
basicstyle=\normalsize\ttfamily,
commentstyle=\normalsize\ttfamily,
keywordstyle=\normalsize\ttfamily,
stringstyle=\color{mymauve},
commentstyle=\color{mygreen},
keywordstyle=\color{blue},
showstringspaces=false, xleftmargin=2.5ex,
columns=flexible,
literate={~}{{$\sim \; \; $}}1,
alsodigit={\.,\_},
deletekeywords={on,by,data,R,Q,mean,var,sd,log,family,na,options,q,weights,effects,matrix,nrow,ncol,wt,fix,distance},
}
\lstset{escapeinside={(*}{*)}}

\lstdefineformat{Rpretty}{
	; = \space,
	\, = [\ \,\]]\string\space,
	<- = [\ ]\space\string\space,
	\= = [\ ]\space\string\space}

\usepackage[compact]{titlesec}
\usepackage{enumitem}
\setlist{leftmargin=0.75cm}

\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

% reduce white space above and below verbatim text blocks
\usepackage{etoolbox}
\makeatletter
\preto{\@verbatim}{\topsep=0.5pt \partopsep=0.5pt }
\makeatother

% let figs,boxes etc. occupy most of a page near where they
% appear in the source file, instead of getting pushed to
% the chapter's end.
\renewcommand{\topfraction}{0.9}
\renewcommand{\bottomfraction}{0.9}
\renewcommand{\textfraction}{0.07}
\renewcommand{\floatpagefraction}{0.85}
% floatpagefraction MUST be less than topfraction
\setcounter{topnumber}{2}
\setcounter{bottomnumber}{2}
\setcounter{totalnumber}{4}

% Define Box environment for numbered boxes.
\newcounter{box}
\newcommand{\boxnumber}{\addtocounter{box}{1} \thebox \thinspace}

\floatstyle{boxed}
\newfloat{Box}{tcph}{box}[section]
\numberwithin{Box}{section}

% A few shortcuts
% Define \z so that \z_0 and z'_0 have the same kerning for _0.
\def\z{z^{}}
\def\Z{\mathbf{Z}}
\def\N{\mathbf{N}}

\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\ba}{\begin{equation} \begin{aligned}}
\newcommand{\ea}{\end{aligned} \end{equation}}

\makeindex

\usepackage[scaled=0.9]{zi4}
\usepackage{textcomp}

\linespread{1.2}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% End of the preamble

\begin{document}

\author{Stephen P. Ellner, Dylan Z. Childs and Mark Rees}
\title{Errata for \\ \emph{Data-driven Modeling of Structured Populations:
A Practical Guide to the Integral Projection Model}}

\date{Last update: \today}

\maketitle

\paragraph{Page 12:} We think that the statement about ``piecewise continuous'' in the footnote is true,
but at least one proof in the book isn't valid regardless of what the curves are that divide $\Z^2$ into
subregions. A slightly less general definition, which should be sufficient for any applications, is as follows.
For the basic model where the individual-level state space $\Z$ is a
bounded interval $[L,U]$, a partition of $\Z$ is a set of
intervals
\begin{equation}
\Z_1 = (z_0,z_1), \Z_2 = (z_1,z_2), \cdots, \Z_m = (z_{m-1},z_m)
\end{equation}
where
\be
L=z_0 < z_1 < z_2 < \cdots < z_M=U.
\ee
A partition breaks $\Z^2$ into a set of open rectangles
$$\Z_{ij} = \Z_i \times \Z_j = \{(z',z): z' \in \Z_i, z \in \Z_j\}.$$
Define the kernels $K_{ij}$ to be $K$ restricted to $\Z_{ij}$.

We say that $K$ is \emph{piecewise continuous} if there exists a
partition such that each of the kernels $K_{ij}$ is continuous on $\Z_{ij}$,
and can be defined on the boundary of $\Z_{ij}$ so that it is continuous
on the closed rectangle $\bar{\Z}_{ij}$ consisting of $\Z_{ij}$ and its boundary.

The reason this definition works is the general theory in section 6.9
(originally in the Appendices to Ellner \& Rees 2006), applied to the
closed intervals $\bar{\Z}_{i} =  [z_0,z_1]$ as a set of continuous components,
with continuous component-to-component kernels $K_{ij}$. In terms of the general
theory, this is an IPM with continuous kernels. Formally, there is a separate state distribution
function $n_i(z,t)$ defined on each $\bar{\Z}_i$. But we can also think of there being a
single distribution function $n(z,t)$ on all of $[L,U]$, consisting of $n_1,n_2, \cdots n_M$
side-by-side.

Each of the boundary points $z_i$ is in two adjacent components, but this doesn't matter because
single points contribute nothing to the subsequent population.
As an example consider  $\Z = [0,2]$ and the (contrived) kernel $K(z',z) = 1$
if $z'>1$, and 0 otherwise. The partition is $\Z_1 = (0,1), \Z_2 = (1,2)$ and the kernels are
\be
K_{11}=K_{12}\equiv 0, K_{21}=K_{22}\equiv 1.
\ee
The population dynamics are
\ba
n_1(z',t+1) & = \int_0^1 K_{11}(z',z) n_1(z,t) dz + \int_1^2 K_{12}(z',z) n_2(z,t) dz  = 0 \\
n_2(z',t+1) & = \int_0^1 K_{21}(z',z) n_1(z,t) dz + \int_1^2 K_{22}(z',z) n_2(z,t) dz  \\
& =  \int_0^1 n_1(z,t) dz + \int_1^2 n_2(z,t) dz.
\label{eqn:badK1}
\ea
So $n_1(1,t+1)=0$, while $n_2(1,t+1)>0$ unless there were no individuals at time $t$.
However, the values of $n_1$ and $n_2$ at the one point $z=1$ have no effect on the
integrals in the population dynamics, so we can regard $n(1,t+1)$ as being undefined,
or give it an arbitrary value such the average $n_1(1,t+1)$ and $n_2(1,t+1)$.

The contrived kernel \eqref{eqn:badK1} is a counter-example to the claim in section 6.9 of the book
that a piecewise continuous kernel, as defined in that section, maps $L_1(\Z)$ into $C(\Z)$.
The gap in the proof is the assertion that the functions $f_n$ converge almost everywhere,
which is not necessarily true regardless of how the partitioning into sets $\mathcal{U}_k$ is done. But on the
set of domains $\bar{\Z}_{i}$ the component kernels are all continuous and the $f_n$ converge
pointwise, which is sufficient for the rest of the proof.
In example \eqref{eqn:badK1}, $n_1$ is continuous on $\bar{\Z}_1$ and
$n_2$ is continuous on $\bar{\Z}_2$, and that is exactly what it means to be continuous
on the state space with domains $\bar{\Z}_1$ and $\bar{\Z}_2$.

Please see the related correction below about \textbf{Page 181}.

\paragraph{Page 15:} Equation (2.3.6), $C_1$ should be $C_0$ as it is in the life-cycle diagram, Figure 2.2.

\paragraph{Page 29:} 9 lines from the bottom, ``the the'' $\to$ ``the''

\paragraph{Page 119:} \emph{Artemisia} is the correct spelling of the genus.

\paragraph{Page 181:} As we wrote regarding \textbf{Page 12}, ``piecewise continuous'' needs
to be defined more narrowly, so that all the claims in this section are valid.
Even if we ignore the fact that ``continuous curve'' was conveniently undefined,
eqn. \eqref{eqn:badK1} remains a counterexample to the claim that $K$ maps $L_1(\Z)$ into $C(\Z)$.

Fortunately, the same approach works in the general setting. A definition of ``piecewise continuous''
that actually works is (informally): we can break up $\Z$ into pieces $\Z_j$, and thereby break up the kernel into
pieces $K_{ij}$ for transitions from $\Z_j$ to $\Z_i$, in such a way that each $K_{ij}$ is continuous.

Reading the rest of this item requires some familiarity with the basics of measure theory
and functional analysis. Sorry, there's no way around this.

We are considering an IPM where the individual state-space $\Z$ is a compact metric space with metric $d$,
and the kernels are defined relative to a finite Borel measure $\mu$ on $\Z$.
The population dynamics are
\be
n(z',t+1) = \int_{\Z} K(z',z)n(z,t) d\mu(z);
\ee
in the book this is eqn. (6.9.1). The kernel is a function on $\Z^2 = \Z times \Z$, which we give the
$L_2$ product metric and resulting product topology. Subsets of $\Z$ and $\Z^2$ are given the relative
metric and measure.

Following the definition for the basic model, a partition of $\Z$ is defined to be a collection of disjoint
open (and therefore measurable) sets $\Z_1, \Z_2, \cdots, \Z_m $ whose boundaries all have $\mu$-measure 0,
such that the union of their closures $\bar{\Z}_j$ is $\Z$. Again, define the kernels $K_{ij}$ to be $K$
restricted to $\Z_{ij} = \Z_i \times \Z_j$.

We say that a kernel $K$ is piecewise continuous if there is a partition such that each $K_{ij}$ is
continuous on each $\Z_{ij} = \Z_i \times \Z_j$ and can be defined on the boundary
of $\Z_{ij}$ so as to be continuous on its closure $\bar{\Z}_{ij}$. At a point $(z',z)$ that is on the boundary
of $\Z_{ij}$ and of $\Z_{kl}$, the values chosen for $K_{ij}(z',z)$ and for $K_{kl}(z',z)$ to ensure continuity
of $K_{ij}$ and $K_{kl}$ do not need to be the same.

The reason this works is (again) that the set of kernels $K_{ij}$ (extended to be continuous on their
domain $\bar{\Z}_{ij}$) defines a general IPM in the sense of section 6.9 in which the overall
kernel is continuous. The individual-level state space for the general IPM is the collection of
sets $\bar{\Z}_j, j=1,2,\cdots m$ considered as distinct sets. Formally, define $\bar{\Z}^*_j$ to be
the set of ordered pairs $(z,j)$ where $z \in \bar{\Z}_j$, and let $\Z^*$ be the collection
of all $\bar{\Z}^*_j$ with the metric
\be
d^*((z_1,i),(z_2,j)) = \sqrt{d(z_1,z_2)^2 + (i-j)^2}.
\ee
The overall kernel is
\be
K^*((z',i),(z,j)) = K_{ij}(z',z).
\ee
A convergent sequence $x^*_n \to x^*_0$ in $\Z^* \times \Z^*$ must eventually consist of points whose $z$ coordinates
all lie in the same $\bar{\Z}_{ij}$, so the sequence is convergent in $\bar{\Z}_{ij}$. So for sufficiently large $n$,
$K^*(x^*_n) = K_{ij}(x^*_n)$ which converges to $K_{ij}(x^*_0)=K^*(x^*_0)$ because $K_{ij}$ is continuous. The overall
kernel is therefore continuous. All results in section 6.9 for continuous kernels therefore also hold for
piecewise continuous kernels under the definition of piecewise continuity given here.

\paragraph{Page 313:} 2nd line after eqn. (10.7.2), $Cov(Y_1,Y_2)$ $\to$ $Cov[X_2,Y_2]$

\paragraph{Page 313:} line before eqn. (10.7.5) should refer to eqn. (10.7.4)

\paragraph{Page 314:} penultimate line, al\'{a} $\to$ \`{a}  la

\end{document}


\documentclass[a4paper,12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{a4}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{float}
\usepackage{listings}
\usepackage{color}
\usepackage{hyperref}
\usepackage{cite}
\usepackage{textgreek}
\usepackage{amsfonts}
\usepackage{amsmath}

\usepackage[margin=1in]{geometry}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\lstset{frame=tb,
  language=matlab,
  aboveskip=5mm,
  belowskip=5mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\small\ttfamily},
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  breaklines=true,
  breakatwhitespace=true,
  tabsize=2
}

\title{
  {\Huge \bf Power Systems Lab}\\
  \vspace{0.25in}

  {\bf Experiment 4}\\
  Laboratory Report
  \vspace{1in}
}
\author{
  \bf Syed Alisamar Husain, 17BEE012\\
  B.Tech Electrical Engg, 8th Semester
}

\begin{document}
  \begin{titlepage}
    \maketitle
    \vspace*{\fill}
    \begin{center}
      {\bfseries Department of Electrical Engineering} \\
      Jamia Millia Islamia, New Delhi
    \end{center}
    \thispagestyle{empty}
  \end{titlepage}

  \newpage
  \begin{center}
    \huge Experiment 4
    \vspace{0.5in}
  \end{center}

  \section{Objective}
  To write a MATLAB program to determine line currents to a Y-connected load
  by mesh analysis and by using symmetrical components.

  {\bf Let the given problem be as follows:}
  \begin{center}
    \itshape
    A balanced three phase voltage of 120 V line to neutral is applied to a
    Y-connected load with ungrounded neutral. The three phase load consists
    of three mutually-coupled reactances. Each phase has a series reactance of
    $Z_s = j12 \Omega$, and the mutual coupling between phases is $Z_m = j4 \Omega$.
  \end{center}
  \begin{enumerate}
    \itshape
    \item Determine the line currents by mesh analysis.
    \item Determine the line currents by using symmetrical components.
  \end{enumerate}

  \section{Theoretical Background}
  Shown below is a 3-phase supply connected to a Y-connected load.
  Each of the voltages $V_1$, $V_2$ and $V_3$ represents the phase voltage
  which are 120 degrees out of phase with each other.
  The impedances are represented by $Z_1$, $Z_2$ and $Z_3$.

  \begin{figure}[H]
    \centering
    \includegraphics[width=5in]{img/y-load.png}
    \caption{Y-connected load with ungrounded neutral.}
    \label{yload}
  \end{figure}

    \subsection{Mesh Analysis}
    The Mesh-Current Method, also known as the Loop Current Method,
    is quite similar to the Branch Current method in that it uses simultaneous
    equations, Kirchhoff’s Voltage Law, and Ohm’s Law to determine unknown
    currents in a network. It differs from the Branch Current method in that
    it does not use Kirchhoff’s Current Law, and it is usually able to solve
    a circuit with less unknown variables and less simultaneous equations.

    \pagebreak
    \subsection{Sequence Components}
    A set of three balanced voltages (phasors) $V_a, V_b, V_c$ is charactertzed by equal
    magnitudes and interphase differences of $120\deg$. The set is said to have a phase
    sequence $abc$ (positive sequence) if $V_b$ lags $V_a$ by $120\deg$ and $V_c$ lags
    $V_b$ by $120\deg$.

    The three phasors can then be expressed in terms of the reference phasor $V_a$ as
    \begin{center}
      $V_a$ = $V_a$\\
      $V_b$ = $\alpha^2 V_a$\\
      $V_c$ = $\alpha V_a$\\
    \end{center}
    where the complex number operator $\alpha$ is defined as $\alpha = e^{j 120\deg}$.
    The same applies to voltages or currents.

    If the phase sequence is $acb$ (negative sequence), then
    \begin{center}
      $V_a$ = $V_a$\\
      $V_b$ = $\alpha V_a$\\
      $V_c$ = $\alpha^2 V_a$\\
    \end{center}

    Thus a set of balanced phasors is fully characterized by its reference phasor
    (say $V_a$) and its phase sequence (positive or negative).

    Consider now a set of three voltages (phasors) $V_a, V_b, V_c$ which in general may
    be unbalanced. According to {\bf Fortesque's theorem} the {\it three phasors can be
    described as the sum of positive, negative and zero sequence phasors}.

    \begin{center}
      $V_a = V_a^1 + V_a^2 + V_a^0$\\
      $V_b = V_b^1 + V_b^2 + V_b^0$\\
      $V_c = V_c^1 + V_c^2 + V_c^0$
    \end{center}

    The three phasor sequences (positive, negative and zero) are called the
    {\bf symmetrical components} of the original phasors. These equations
    can be expressed in the matrix form

    \begin{center}
      \begin{math}
        \begin{bmatrix}
          V_a \\ V_b \\ V_c
        \end{bmatrix}
        =
        \begin{bmatrix}
          1 & 1        & 1 \\
          1 & \alpha^2 & \alpha \\
          1 & \alpha   & \alpha^2
        \end{bmatrix}
        \begin{bmatrix}
          V^0_a \\ V^1_b \\ V^2_c
        \end{bmatrix}
      \end{math}
    \end{center}

    \begin{center}
      $ \bf V_p = A V_s $\\
    \end{center}

    To find the sequence components, we can invert the equation
    \begin{center}
      $ \bf V_s = A^{-1} V_p $
    \end{center}

    \begin{center}
      where
      \begin{math}
        {\bf A^{-1}} =
        \dfrac{1}{3}
        \begin{bmatrix}
          1 & \alpha   & \alpha^2 \\
          1 & \alpha^2 & \alpha \\
          1 & 1        & 1
        \end{bmatrix}
      \end{math}
    \end{center}

  \pagebreak
  \section{Implementation}
  \begin{lstlisting}
    % To write a MATLAB program to determine line currents to a Y-connected
    % load by mesh analysis and by using symmetrical components.

    % 17BEE012 - Alisamar Husain

    Vp = 120;       % 3-phase Supply Voltage

    Zs = 1j*12;     % Branch series reactance
    Zm = 1j*4;      % Branch mutual reactance

    % 1. Line currents by mesh analysis
    disp('1. Line currents by mesh analysis')
    Vl=sqrt(3)*Vp;

    Z = [ (Zs-Zm) -(Zs-Zm) 0
          0 (Zs-Zm) -(Zs-Zm)
          1 1 1];

    V = [ Vl*(cos(pi/6) + 1j*sin(pi/6))
          Vl*(cos(-pi/2) + 1j*sin(-pi/2))
          0];

    Iabc = Z \ V;
    disp(Iabc)

    % 2. Line currents by symmetric components
    disp('2. Line currents by symmetric components')
    a = cos(2*pi/3)+ 1j*sin(2*pi/3);

    A = [ 1 1 1;
          1 a^2 a;
          1 a a^2];

    Z012 = [  Zs+2*Zm 0 0
              0 Zs-Zm 0
              0 0 Zs-Zm];

    V012 = [0; Vp; 0];
    I012 = Z012 \ V012;

    Iabc = A * I012;
    disp(Iabc)
  \end{lstlisting}

  \section{Observations}
  \begin{figure}[H]
    \centering
    \includegraphics{img/run.png}
    \caption{Result in MATLAB}
    \label{result}
  \end{figure}
  The result of the above program with the given parameters
  is shown in figure \ref{result}.

  \section{Result}
  The line currents for the given problem {\bf by mesh analysis} are found to be
  \begin{center}
    0.0000 -15.0000i A\\
    -12.9904 + 7.5000i A\\
    12.9904 + 7.5000i A
  \end{center}
  and line currents for {\bf by symmetric components} are found to be
  \begin{center}
    0.0000 -15.0000i A\\
    -12.9904 + 7.5000i A\\
    12.9904 + 7.5000i A
  \end{center}
  It is observed that identical values are obtained by both methods.

\end{document}