\chapter{Spectral analysis}

Chapter \ref{chap:precond} introduce possible preconditioning techniques for the MHD system \eqref{eq:mhd_saddle}. In this chapter we will go thought an eigenvalue analysis for the preconditioner $\mathcal{M}_{\rm MH}$ \eqref{eq:mhd_pc_ls}.


\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{\textsc{URIsolve App}}
\rhead{\textsc{Node Voltage Method (Supernode approach)}}
\cfoot{www.isep.ipp.pt}
\lfoot{DEE - ISEP}
\rfoot {\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

\title{
\raisebox{-.2\height}{\includegraphics[height=1cm, keepaspectratio]{logo}} URIsolve APP \\
\newline
\textsc{Node Voltage Method} \\
\textsc{(Supernode approach)} \\
Step by Step Solution \\
\vspace*{1\baselineskip}
}

\author{
\begin{tabular}[t]{c@{\extracolsep{8em}}c}
Lino Sousa           & Mário Alves          \\
1140355@isep.ipp.pt  & mjf@isep.ipp.pt      \\
					 &                      \\
André Rocha          & Francisco Pereira    \\
anr@isep.ipp.pt      & fdp@isep.ipp.pt      \\
\end{tabular}
}

\date{}

\begin{document}

\maketitle
\thispagestyle{empty}

\vspace{\fill}
\begin{abstract}
\centering
This document provides a step by step solution for the submitted circuit, using the Node Voltage Method (NVM). If possible, it's implemented the Supernode approach to simplify the circuit analysis.
\end{abstract}
\vspace{\fill}

\begin{center}
\today
\end{center}

\clearpage
\pagenumbering{arabic}

\newpage

\section{Circuit Image}

\begin{figure}[hbt]
\centering{\includegraphics[height=12cm, keepaspectratio]{circuit}}
\caption{Circuit image}
\label{circuitimage}
\end{figure}

\section{Circuit Information}

\begin{table}[h!]
\centering
\begin{tabular}{clclclc}
\textbf{Frequency {[}F{]}} &  & \textbf{Current Sources {[}I{]}} &  & \textbf{Ammeters {[}A{]}} &  & \textbf{Simulation {[}AC/DC{]}} \\
F=1GHz                     &  & I=1                              &  & 15/15                     &  & AC
\end{tabular}
\end{table}

\section{Fundamental Variables}

\begin{table}[hbt!]
\centering
\begin{tabular}{clclclc}
\textbf{Branches {[}R{]}} &  & \textbf{Nodes {[}N{]}} &  & \textbf{Isolated Voltage Sources {[}T{]}} &  & \textbf{Equations {[}E{]}} \\
R=15                      &  & N=9                    &  & T=6                                       &  & E=N-T-1=2
\end{tabular}
\end{table}

\section{Supernodes}

\subsection{Floating}

\subsubsection{SNf1}

\paragraph{} Formed by Nodes: {A, B, E, J, H, D}
\par

\paragraph{} Equations:

\begin{gather*}
\begin{cases}
V_{B} = \mathrm{V_{A}}-5\\V_{E} = \mathrm{V_{A}}-4\\V_{J} = \mathrm{V_{A}}-13\\V_{H} = \mathrm{V_{A}}-13\cdot\left( i+1\right)\\V_{D} = \mathrm{V_{A}}-4\\
\end{cases}
\end{gather*}
\par

\paragraph{} Steps:

\begin{gather*}
\begin{cases}V_{B} = \mathrm{V_{A}}- V2\\[0.7em] V_{D} = \mathrm{V_{A}}- V3\\[0.7em] V_{E} = \mathrm{V_{A}}- V2+ V12\\[0.7em] V_{J} = \mathrm{V_{A}}- V6- V2+ V12\\[0.7em] V_{H} = - V2- V10- V6+\mathrm{V_{A}}+ V12\end{cases}
\end{gather*}

\subsubsection{SNf2}

\paragraph{} Formed by Nodes: {T, M}
\par

\paragraph{} Equations:

\begin{gather*}
\begin{cases}
V_{M} = \mathrm{V_{T}}-1
\end{cases}
\end{gather*}
\par

\paragraph{} Steps:

\begin{gather*}
\begin{cases}V_{M} = \mathrm{V_{T}}- V11\end{cases}
\end{gather*}
\par

\subsection{Grounded}
Not found in this circuit.

\newpage
\section{Circuit Currents}

\subsection{General information}

\begin{table}[ht]
\caption{List of the circuit currents and its properties/components}
\centering
\begin{tabular}{cccc}
\textbf{Reference} & \textbf{Start Node} & \textbf{End Node} & \textbf{Components} \\ \hline
I01                & A                   & GND               & V1, L1, V7          \\
I02                & GND                 & B                 & R6                  \\
I03                & GND                 & H                 & C1, I3, R7          \\
I04                & A                   & B                 & V2                  \\
I05                & B                   & H                 & R4                  \\
I06                & H                   & J                 & V10                 \\
I07                & B                   & E                 & V12                 \\
I08                & A                   & D                 & V3                  \\
I09                & D                   & T                 & R1                  \\
I10                & E                   & T                 & R10, C2             \\
I11                & T                   & M                 & R2                  \\
I12                & J                   & M                 & R3                  \\
I13                & D                   & E                 & R9                  \\
I14                & E                   & J                 & V6                  \\
I15                & T                   & M                 & V11
\end{tabular}
\end{table}

\subsection{Equivalent Impedances and Voltages}
\paragraph{} Branch from A to gnd
\begin{gather*}
\begin{cases}
VeqAgnd =  - V1 - V7 = -11\;V
\end{cases}
\end{gather*}
\par

\paragraph{} Branch from D to T
\begin{gather*}
\begin{cases}
VeqDT =  - V4 - V5 = -8\;V
\end{cases}
\end{gather*}
\par

\paragraph{} Branch from E to T
\begin{gather*}
\begin{cases}
ZeqgndH = R10 + C2  = 50 - 159.155i\;\Omega
\end{cases}
\end{gather*}
\par

\paragraph{} Branch from gnd to H
\begin{gather*}
\begin{cases}
ZeqgndH = C1 + R7  = 5 - 159.155i\;\Omega
\end{cases}
\end{gather*}
\par
newpage
\subsection{Equations}
Equations using the Kirchhoff Nodes Law (KNL)

\subsubsection{Node SNf1}
\begin{figure}[hbt]
\centering{\includegraphics[height=4cm, keepaspectratio]{snf1}}
\caption{Node SNf1 currents}
\label{snf1currents}
\end{figure}
\begin{equation}
  I01+I09+I10+I12=I02+I03
\end{equation}

\subsubsection{Node SNf2}
\begin{figure}[hbt]
\centering{\includegraphics[height=4cm, keepaspectratio]{snf2}}
\caption{Node SNf2 currents}

\label{snf2currents}
\end{figure}
\begin{equation}
  I09+I10+I12=0
\end{equation}

\newpage
\section{Equation System}

\paragraph{} Equations:
\begin{gather*}
\begin{cases}\frac{\left(\mathrm{V_{A}}- V1- V7\right)}{ XL1}+\left(\frac{\mathrm{V_{B}}}{ R6}\right)+\frac{\left( V_{D}- V4- V5-\mathrm{V_{T}}\right)}{ R1}+\frac{\left( V_{E}-\mathrm{V_{T}}\right)}{ XC2}+\frac{\left(\mathrm{V_{J}}- V_{M}\right)}{ R3}-0.001 = 0 \\[0.7em] \frac{\left( V_{D}- V4- V5-\mathrm{V_{T}}\right)}{ R1}+\frac{\left( V_{E}-\mathrm{V_{T}}\right)}{ XC2}+\frac{\left(\mathrm{V_{J}}- V_{M}\right)}{ R3} = 0\end{cases}
\end{gather*}
\par

\paragraph{} Steps:

%\hfill\begin{minipage}{\dimexpr\textwidth-1cm}
\begin{small}\textbf{\textit{Step 1:}}\end{small}  Reorder current equations
\begin{gather*}
\begin{cases}I01 - I02 + I09 + I10 + I12 - I03 = 0 \\[0.7em] I09 + I10 + I12 = 0\end{cases}
\end{gather*}

\begin{small}\textbf{\textit{Step 2:}}\end{small}  Substitute the known currents
\begin{gather*}
\begin{cases}I01 - I02 + I09 + I10 + I12 - 0.001 = 0 \\[0.7em] I09 + I10 + I12 = 0\end{cases}
\end{gather*}

\begin{small}\textbf{\textit{Step 3:}}\end{small}  Compute the remaining currents using Ohm's Law
\begin{gather*}
\begin{cases}I01 = \frac{\left(\mathrm{V_{A}}- V1 -  V7\right)}{ XL1} \\[0.7em] I02 = -\left(\frac{\mathrm{V_{B}}}{ R6}\right) \\[0.7em] I09 = \frac{\left( V_{D}- V4 -  V5 - \mathrm{V_{T}}\right)}{ R1} \\[0.7em] I10 = \frac{\left( V_{E}-\mathrm{V_{T}}\right)}{ XC2} \\[0.7em] I12 = \frac{\left(\mathrm{V_{J}}- V_{M}\right)}{ R3}\end{cases}
\end{gather*}

\begin{small}\textbf{\textit{Step 4:}}\end{small}  Substitute each current by its equation
\begin{gather*}
\begin{cases}\frac{\left(\mathrm{V_{A}}- V1- V7\right)}{ XL1}+\left(\frac{\mathrm{V_{B}}}{ R6}\right)+\frac{\left( V_{D}- V4- V5-\mathrm{V_{T}}\right)}{ R1}+\frac{\left( V_{E}-\mathrm{V_{T}}\right)}{ XC2}+\frac{\left(\mathrm{V_{J}}- V_{M}\right)}{ R3}-0.001 = 0 \\[0.7em] \frac{\left( V_{D}- V4- V5-\mathrm{V_{T}}\right)}{ R1}+\frac{\left( V_{E}-\mathrm{V_{T}}\right)}{ XC2}+\frac{\left(\mathrm{V_{J}}- V_{M}\right)}{ R3} = 0\end{cases}
\end{gather*}

\begin{small}\textbf{\textit{Step 5:}}\end{small}  Replace the constants with their value
\begin{gather*}
\begin{cases}\frac{\mathrm{V_{A}}-11}{\frac{ i\cdot62830}{10000}}+\frac{\mathrm{V_{B}}}{12}+\frac{-8-\mathrm{V_{T}}+ V_{D}}{20}+\frac{ V_{E}-\mathrm{V_{T}}}{\frac{ i\cdot-7.9577\cdot10^{+7}}{5\cdot10^{+5}}}+\frac{\mathrm{V_{J}}- V_{M}}{30}+\frac{-1}{1000} = 0 \\[0.7em] \frac{-8-\mathrm{V_{T}}+ V_{D}}{20}+\frac{ V_{E}-\mathrm{V_{T}}}{\frac{ i\cdot-7.9577\cdot10^{+7}}{5\cdot10^{+5}}}+\frac{\mathrm{V_{J}}- V_{M}}{30} = 0\end{cases}
\end{gather*}

\begin{small}\textbf{\textit{Step 6:}}\end{small} Set a reference for each floating supernode
\newline
In supernode SNf1 the node A was chosen as a reference. \\
In supernode SNf2 the node T was chosen as a reference.

\newline
\begin{footnotesize}
\textbf{\textit{Notes:}} \\
The voltage of each node from a floating supernode must be expressed as a function of the reference node. \\
In the Supernodes section, you can confirm that node equations are already referenced to the chosen node. \\
Use these expressions to perform the substitution in the equation system.
\end{footnotesize}

%\end{minipage}
\par

\newpage

\section{Results}

\subsection{Node Voltages}
\begin{gather*}
\begin{cases}V_{A} = 9.712-2.461i\;V \\[0.7em] V_{T} = -2.243-1.861i\;V \\[0.7em] V_{B} = 4.712-2.461i\;V \\[0.7em] V_{D} = 5.712-2.461i\;V \\[0.7em] V_{M} = -3.243-1.861i\;V \\[0.7em] V_{E} = 5.712-2.461i\;V \\[0.7em] V_{J} = -3.288-2.461i\;V \\[0.7em] V_{H} = -3.288-15.461i\;V\end{cases}
\end{gather*}

\subsection{Circuit Currents}
\begin{gather*}
\begin{cases}I03 = 0.001\;A\end{cases}
\end{gather*}
\begin{footnotesize}
\textbf{\textit{Note:}} \\
Currents were obtained by an existing current source in their branch.
\end{footnotesize}

\begin{gather*}
\begin{cases}I01 = \frac{\mathrm{V_{A}}-11}{\frac{ i\cdot1.256\cdot10^{+7}}{2\cdot10^{+6}}} \\[0.7em] I05 = \frac{\mathrm{V_{B}}-\mathrm{V_{H}}}{10} \\[0.7em] I02 = \frac{\mathrm{V_{B}}\cdot-1}{12} \\[0.7em] I13 = \frac{ V_{D}- V_{E}}{25} \\[0.7em] I09 = \frac{-8-\mathrm{V_{T}}+ V_{D}}{20} \\[0.7em] I10 = \frac{ V_{E}-\mathrm{V_{T}}}{-\left(159.154\cdot i\right)} \\[0.7em] I12 = \frac{\mathrm{V_{J}}- V_{M}}{30} \\[0.7em] I11 = \frac{\mathrm{V_{T}}- V_{M}}{20}\end{cases} \Leftrightarrow\large \begin{cases}I01 = -0.392\;A \\[0.7em] I05 = 0.8\;A \\[0.7em] I02 = -0.393\;A \\[0.7em] I13 = 0\;A \\[0.7em] I09 = -0.002\;A \\[0.7em] I10 = 0.004\;A \\[0.7em] I12 = -0.002\;A \\[0.7em] I11 = 0.05\;A\end{cases}
\end{gather*}
\begin{footnotesize}
\textbf{\textit{Note:}} \\
Currents were obtained by their Ohm's Law equation.
\end{footnotesize}

\begin{gather*}
\begin{cases}I08 = I13 + I09 \\[0.7em] I06 = I05 + I03 \\[0.7em] I15 = -I12 - I11 \\[0.7em] I04 = -I01 - I08 \\[0.7em] I07 = -I05 + I04 + I02 \\[0.7em] I14 = -I10 + I07 + I13\end{cases} \Leftrightarrow\large \begin{cases}I08 = -0.002\;A \\[0.7em] I06 = 0.801\;A \\[0.7em] I15 = -0.048\;A \\[0.7em] I04 = 0.394\;A \\[0.7em] I07 = -0.799\;A \\[0.7em] I14 = -0.803\;A\end{cases}
\end{gather*}
\begin{footnotesize}
\textbf{\textit{Note:}} \\
Currents were obtained by their KNL equation, since they belong to branches with isolated voltage sources.
\end{footnotesize}

\end{document}


\section{Dynamical Core for Cartesian C-grid} \label{sec:atmos_dyn_cartesC}
%------------------------------------------------------
In this section, the dynamical core for the Cartesian C-grid is described.
The Cartesian C-grid is employed in \scalerm.
In the Cartesian C-grid, scalar quantities, such as density, thermodynamics variable and vapor, is defined at the cell center, while components of vector quantities, such as the momentums and fluxes, are defined at staggered point.
See the description document of \scalerm for more details.

\subsection{Setting Integration Numerical Method}  %\label{subsec:atmos_dyn_sover}
%------------------------------------------------------
The numerical method for time integration in the dynamical process is specified in \nmitem{ATMOS_DYN_TYPE} in \namelist{PARAM_ATMOS} in the configuration file.
\editboxtwo{
\verb|&PARAM_ATMOS  | & \\
\verb| ATMOS_DYN_TYPE    = "HEVE", | & ; Choose from Table \ref{tab:nml_dyn}.\\
\verb|/             | & \\
}

Time step depends on the sound speed in the case of using the explicit method, while it does not in the case of using the implicit method.
In most real atmospheric simulations, vertical grid spacing is much smaller than the horizontal ones.
Thus, fully explicit scheme, that is ``HEVE'', requires a quite small time step, which depends on vertical grid spacing and sound speed.
Therefore, ``HEVI'' is often used for the real atmospheric simulations.

\begin{table}[bth]
\begin{center}
  \caption{Options of methods for time integration in dynamical process}
  \label{tab:nml_dyn}
  \begin{tabularx}{150mm}{llX} \hline
    \rowcolor[gray]{0.9}  Scheme name & Description of scheme & Note\\ \hline
      \verb|HEVE|  & Fully explicit method & \\
      \verb|HEVI|  & Horizontally explicit and vertically implicit methods & Recommended for real experiment\\
    \hline
  \end{tabularx}
\end{center}
\end{table}

\subsection{Setting Temporal and Spatial Schemes} \label{subsec:atmos_dyn_scheme}
%------------------------------------------------------

The temporal and spatial schemes are configured in \namelist{PARAM_ATMOS_DYN}.
An example of setting, which is recommended for real atmospheric simulations,
is shown below.
\editboxtwo{
 \verb|&PARAM_ATMOS_DYN  | & \\
 \verb|ATMOS_DYN_TINTEG_SHORT_TYPE          = RK4,|          & ; Choose from temporal schemes in Table \ref{tab:nml_atm_dyn}\\
 \verb|ATMOS_DYN_TINTEG_TRACER_TYPE         = RK3WS2002,|    & ; Choose from temporal schemes\\
 \verb|ATMOS_DYN_FVM_FLUX_TYPE              = UD3,|          & ; Choose from temporal spatial schemes in Table \ref{tab:nml_atm_dyn}\\
 \verb|ATMOS_DYN_FVM_FLUX_TRACER_TYPE       = UD3KOREN1993,| & ; Choose from spatial schemes\\
 \verb|ATMOS_DYN_FLAG_FCT_TRACER            = .false.,|      & ; Use FCT scheme (.true.) or not (.false.)\\
 \verb|ATMOS_DYN_NUMERICAL_DIFF_COEF        = 0.D0, |        & \\
 \verb|ATMOS_DYN_NUMERICAL_DIFF_COEF_TRACER = 0.D0, |        & \\
 \verb|ATMOS_DYN_wdamp_height               = 15.D3,|        & ; height [m] of the bottom of sponge layer (for Rayleigh damping)\\
\verb|/             | & \\
}

The other options for temporal and spatial schemes are shown in Table \ref{tab:nml_atm_dyn}.
Note that the time step should be set according to the used schemes in order to ensure numerical stability.
An criteria to determine the time step is described in Section \ref{sec:timeintiv}.

\begin{table}[bth]
\begin{center}
  \caption{Setting temporal and spatial schemes}
  \label{tab:nml_atm_dyn}
  \begin{tabularx}{150mm}{lllX} \hline
    \rowcolor[gray]{0.9} & \multicolumn{1}{l}{Scheme name} & \multicolumn{1}{l}{Description of scheme} & \\ \hline
    \multicolumn{3}{l}{Temporal scheme} &  \\ \hline
    & \multicolumn{1}{l}{\verb|RK3|} & \multicolumn{2}{l}{Heun-type 3 stage and 3rd-order Runge--Kutta scheme} \\
    & \multicolumn{1}{l}{\verb|RK3WS2002|} & \multicolumn{2}{l}{3 stage and generraly 2nd-order Runge--Kutta scheme in \citet{Wicker_2002}} \\
    & \multicolumn{1}{l}{\verb|RK4|} & \multicolumn{2}{l}{4 stage and 4th-order Runge--Kutta scheme} \\
    & \multicolumn{1}{l}{\verb|RK7s6o|} & \multicolumn{2}{l}{7 stage and 6th-order Runge--Kutta scheme in Lawson (1967) (supported only for HEVE)} \\
    & \multicolumn{1}{l}{\verb|RK11s8o|} & \multicolumn{2}{l}{11 stage and 8th-order Runge--Kutta scheme in Cooper and Verner (1972) (supported only for HEVE)} \\
    \hline
    \multicolumn{3}{l}{Spatial scheme} & Minimum number of halos\\ \hline
    & \multicolumn{1}{l}{\verb|CD2|} & \multicolumn{1}{l}{2nd-order central flux} & \multicolumn{1}{l}{1}\\
    & \multicolumn{1}{l}{\verb|CD4|} & \multicolumn{1}{l}{4th-order central flux} & \multicolumn{1}{l}{2}\\
    & \multicolumn{1}{l}{\verb|CD6|} & \multicolumn{1}{l}{6th-order central flux} & \multicolumn{1}{l}{3}\\
    & \multicolumn{1}{l}{\verb|CD8|} & \multicolumn{1}{l}{8th-order central flux} & \multicolumn{1}{l}{3}\\
    & \multicolumn{1}{l}{\verb|UD3|} & \multicolumn{1}{l}{3rd-order upwind flux} & \multicolumn{1}{l}{2}\\
    & \multicolumn{1}{l}{\verb|UD5|} & \multicolumn{1}{l}{5th-order upwind flux} & \multicolumn{1}{l}{3}\\
    & \multicolumn{1}{l}{\verb|UD7|} & \multicolumn{1}{l}{7th-order upwind flux} & \multicolumn{1}{l}{3}\\
    & \multicolumn{1}{l}{\verb|UD3KOREN1993|} & \multicolumn{1}{l}{3rd-order upwind flux + \citet{Koren_1993}'s filter} & \multicolumn{1}{l}{2}\\
\hline
  \end{tabularx}
\end{center}
\end{table}

The default setting for advection scheme used for the prognostic variables in dynamics, spcified by \nmitem{ATMOS_DYN_FVM_FLUX_TYPE}),
is the 4th-order central flux (\verb|CD4|) in the \scalerm.
When using \verb|CD4| in a simulation with a steep terrain,
an artificial grid-scale vertical flow is often seen at the peak of mountains.
This grid-scale flow may be reduced by using \verb|UD3|.
So, the use of \verb|UD3| is recommended for experiments with steep terrains.

\subsection{Numerical Diffusions}

The numerical stability depends on schemes used in simulations.
Numerical diffusion may improve the stability.
\scalerm has the hyper-diffusion and divergence dumping as the numerical diffusion.
The setting for them is the following:
\editboxtwo{
 \verb|&PARAM_ATMOS_DYN  | & \\
 \verb|ATMOS_DYN_NUMERICAL_DIFF_LAPLACIAN_NUM = 2,    |        & \\
 \verb|ATMOS_DYN_NUMERICAL_DIFF_COEF          = 1.D-4,|        & \\
 \verb|ATMOS_DYN_NUMERICAL_DIFF_COEF_TRACER   = 0.D0, |        & \\
 \verb|ATMOS_DYN_DIVDMP_COEF                  = 0.D0, |        & \\
\verb|/                  | & \\
}

The number of laplacian operator associated with hyper-diffusion is specified by \\
\nmitem{ATMOS_DYN_NUMERICAL_DIFF_LAPLACIAN_NUM}.
\nmitem{ATMOS_DYN_NUMERICAL_DIFF_COEF} and \\
\nmitem{ATMOS_DYN_NUMERICAL_DIFF_COEF_TRACER} is a non-dimensional coefficient of the hyper-diffusion.
The two-grid scale noise is dumped to $1/e$ in one time step if the coefficient is unity.
The dumping is stronger for larger coefficient.
The hyper-diffusion itself would be numerically unstable if the coefficient is larger than 1.
\nmitem{ATMOS_DYN_NUMERICAL_DIFF_COEF} is for the dynamical prognostic variables, such as density, momentum and potential temperature, and \nmitem{ATMOS_DYN_NUMERICAL_DIFF_COEF_TRACER} is for the tracer variables, such as specific humidity, hydrometeors, and turbulent kinetic energy.
\nmitem{ATMOS_DYN_NUMERICAL_DIFF_COEF} can be set to zero when using the upwind schemes, such as \verb|UD3, UD5|, which has implicit numerical diffusion.

The divergence dumping can also be available to improve numerical stability.
Its coefficient can be set with \nmitem{ATMOS_DYN_DIVDMP_COEF}.

\subsection{Positive Definite}

For tracer advection, guaranteeing a non-negative value is required in most cases.\\
The \verb|UD3KOREN1993| scheme guarantees a non-negative value, whereas other schemes do not.
When schemes other than \verb|UD3KOREN1993| are used the FCT filter can be used to guarantee the non-negative value.
The advection scheme is specified by \nmitem{ATMOS_DYN_FVM_FLUX_TRACER_TYPE}, and switch for the FCT filter is \nmitem{ATMOS_DYN_FLAG_FCT_TRACER}$=$\verb|.true.|.

\subsection{Halos}

The necessary number of halos grid depends on the spatial difference scheme as shown in Table \ref{tab:nml_atm_dyn}.
Set \nmitem{IHALO} and \nmitem{JHALO} in \namelist{PARAM_ATMOS_GRID_CARTESC_INDEX} for the number of halos grid for the x- and y-directions, respectively.
By default, the number of the grid is 2, which is suitable for ``UD3'', ``UD3KOREN1993'', and ``CD4''.
For example, the configuration of the halo for the fifth-order upwind difference scheme is as follows:

\editboxtwo{
 \verb|&PARAM_ATMOS_GRID_CARTESC_INDEX | &  \\
 \verb| IHALO = 3,|   &\\
 \verb| JHALO = 3,|   &\\
 \verb|/ | & \\
}

\subsection{Setting for Coriolis Force} \label{subsec:coriolis}
%----------------------------------------------------------

In this subsection, treatments of the Coriolis force in \scalerm is explained.
The Coriolis parameter is zero as the default, so that you have to set (some) parameter(s) to introduce the Coriolis force in the simulation.
There are two types of setting for the Coriolis parameter: $f$-/$\beta$-plane and sphere.
The type can be specified by \nmitem{CORIOLIS_type} in \namelist{PARAM_CORIOLIS}.

\subsubsection{$f$-/$\beta$-plane}
If \nmitem{CORIOLIS_type} is set to ``PLANE'', the Coriolis parameter $f$ is $f=f_0 + \beta (y-y_0)$.
When $f_0=0$ and $\beta=0$, which is default, no Coriolis force is taken into account.

The plane for $\beta=0$ is called $f$-plane, otherwise it is called $\beta$-plane.
The parameters of $f_0, \beta$ and $y_0$ is set with the parameters of \namelist{PARAM_CORIOLIS} as follows:
\editbox{
  \verb|&PARAM_CORIOLIS| \\
  \verb| CORIOLIS_type = 'PLANE',| ! PLANE or SPHERE \\
  \verb| CORIOLIS_f0   = 1.0D-5, | ! $f_0$ \\
  \verb| CORIOLIS_beta = 0.0D0,  | ! $\beta$ \\
  \verb| CORIOLIS_y0   = 0.0D0,  | ! $y_0$ \\
  \verb|/| \\
}

The default values of the \nmitem{CORIOLIS_f0}, \nmitem{CORIOLIS_beta},
and \nmitem{CORIOLIS_y0} are 0.0, 0.0, and $y$ at the domain center, respectively.

If you want to add the geostrophic pressure gradient force that is in balance with the Coriolis force accompanied by the geostrophic wind, you need to modify the user specific file \verb|mod_user.f90| (see Section \ref{sec:mod_user}).
The test case of \verb|scale-rm/test/case/inertial_oscillation/20km| is an example of a simulation on the $f$-plane with the geostrophic pressure gradient force.

\subsubsection{Sphere}
On the sphere, the Coriolis parameter depends on the latitude as $f = 2\Omega \sin(\phi)$, where $\Omega$ and $\phi$ are angular velocity of the sphere and latitude, respectively.
In this case, you have to set \nmitem{CORIOLIS_type} = ``SPHERE''.
The angular velocity of the sphere is set by \nmitem{CONST_OHM} parameter of \namelist{PARAM_CONST} (see Section \ref{subsec:const}).
The latitude of the individual grids is determined depending on the map projection, which is explained in Section \ref{subsec:adv_mapproj}.

\subsubsection{Lateral Boundary Condition for Coriolis Force}

If there exists geostrophic wind, the periodic boundary conditions cannot be applied in its perpendicular direction, since the wind is not periodic.
For the $f$-plane, the double periodic boundary conditions can be applied with no geostrophic wind.
For the $\beta$-plane or sphere, the periodic boundary condition cannot be used in the y-direction, since the Coriolis parameter differs at the southern and northern boundaries.
In the absent of meridional geostrophic wind, the periodic boundary in the x-direction is allowed for the all the settings (i.e., the $f$-plane, $\beta$-plane, and sphere).

The nudge lateral boundary conditions at the south and north boundaries might be used for $f$- and $\beta$-plane experiment.
For the details of the nudging boundary, see Sections \ref{subsec:buffer}.
The test case of \verb|scale-rm/test/case/rossby_wave/beta-plane| is an example of a simulation on the $\beta$-plane with the south and north nudging boundaries.


\chapter{KG-RNN: Our Architecture}
\label{chap:KG-RNN}
In this chapter we introduce our own architecture, based on the previous chapter where we present our \textbf{Evolving Entity Encoder}. This novel architecture leverage different graph theory techniques and machine learning to encompass information from other entities and thus further boost the predictive power of the model. \\

The first section will highlight the different steps of the pipeline, then the following section describes the process of constructing the weighted knowledge graph from internal (MIMIC-III) as well as external information. Right after, we develop the idea of ``extracting`` other entities of interest from the knowledge graph that will improve the prediction for a given input entity. Finally, we expose our \emph{KG-RNN} deep learning architecture to leverage the input entity as well as the ones we extracted in the previous stage.

\section{Overview}
Our ``KG-RNN`` architecture extends on the previous baseline described in chapter~\ref{chap:Baseline}. The novelty and improvement rely on neighboring entities of interest (i.e. admissions in our use-case) to encompass more information than solely the input entity. \\

To do so, the first phase consists in creating an appropriate knowledge graph from our dataset but also external information to enrich the linkage structure between entities. This can be done in many different ways, in a weighted or unweighted fashion ($w=1$), and we will describe here how we proceeded in the healthcare use-case. \\

Right after, from this enhanced knowledge graph, weighted or not, we have to extract neighboring entities of interest. For this purpose, we can employ any graph sampling technique (leveraging edge weight or not) and we will go through the one we chose. Finally, from the extracted neighbors and the input entity, we build a machine learning model extending from the baseline one to convey information from these neighbors.

\section{Weighted Knowledge Graph Construction}
As a first step and to the end of building our weighted knowledge graph, the main field of interest is~\emph{DIAGNOSIS} (that we will call ``prediagnosis`` hereafter to avoid confusion with ICD9 diagnoses) in the admission table. Firstly, we clean the prediagnosis: \begin{enumerate*}\item Converting to lower-case. \item Remove non-alphabetic characters. \item Remove multi-spaced as well as leading and trailing ones.\end{enumerate*} \\

On top of this \textit{prediagnosis}, we leverage external information from a recent paper that creates a mapping between diseases and symptoms~\cite{Rotmensch2017}. This external knowledge graph is built from Electronic Health Records (EHR) and links diseases with their respective symptoms, while providing a symptom relevance weight (between 0 and 1). An example of entry from this external source is: \emph{Migraine: Headache ($w=0.384$), nausea ($w=0.316$), sensitivity to light ($w=0.223$), ...} These diseases and symptoms are cleaned in the exact same way as the prediagnosis and assembled to create our \textbf{dictionary}. \\

Our goal now is to link the external information with our internal information to create an enriched knowledge graph. We want to link prediagnosis with symptoms and diseases, while these latter two are intrinsically linked directly by the external information (cf. \textit{Migrain} example above). \\

To this end we have to cope with the problem of spelling mistakes as well as quasi-similar prediagnosis and diseases/symptoms (e.g. ``Coronary heart disease`` vs. ``Arteries heart disease``), we create a character N-grams~\footnote{\url{https://en.wikipedia.org/wiki/N-gram}} (where the size of the n-gram has to be tuned) list from the cleaned entries of the dictionary (prediagnosis, disease and symptoms). From this n-grams list, we create a TF-IDF~\footnote{\href{https://en.wikipedia.org/wiki/Tf\%E2\%80\%93idf}{https://en.wikipedia.org/wiki/Tf\_idf}} vector with a minimum document frequency of 1. \\

Finally, we match prediagnosis with diseases and symptoms based on the cosine similarity between their n-grams + TF-IDF vectors. Namely, we link a prediagnosis with a disease and a symptom if their cosine similarity score is above a given threshold (to manually filter out noise), and we link diseases and symptoms based on the external information while also applying a threshold on the symptoms relevance weight provided out-of-the-box by the external source. The final knowledge graph is represented in the figure~\ref{fig:kg-healthcare}, including both internal and external information. \\

\begin{figure}[H]
 \centering
 \includegraphics[width=0.9\textwidth]{figures/kg-healthcare.pdf}
 \caption{Final knowledge graph made of external and internal information that will be used in the experiments and discussions.}
 \label{fig:kg-healthcare}
\end{figure}

On a practical note, for the rest of the discussions and experiments, we set n-grams to \textbf{3 characters}, the minimum cosine similarity score of \textbf{0.6} and a relevance weight between diseases and symptoms of \textbf{0.2}.

\newpage
\section{Weighted Knowledge Graph Extraction}
Secondly, from this weighted knowledge graph, we want to extract relevant neighboring entities to enrich our input entity with additional information. For this purpose, one can use any graph sampling technique~\cite{DBLP:journals/corr/HuL13, Leskovec:2006:SLG:1150402.1150479}, making use of the weights defined during \textit{Graph Construction} or not. \\

This graph sampling will be very important for the downstream model and also the number of neighbors is a critical hyper-parameter that has to be tuned. In that regard, relevant experiments can be found in the appropriate chapter. Some common sampling techniques could be \begin{enumerate*}\item Random sampling on 1-hop neighbors. \item Snow-Ball sampling. \item Forest Fire sampling.\end{enumerate*}. \\

For our use-case at hand, we decided to employ some \textit{importance sampling} based algorithm. This technique is inspired from a paper~\cite{DBLP:journals/corr/abs-1806-01973} by Pinterest and Stanford, it relies on random walks to create an importance score for each entity and take the top scoring entities as neighbors of interest. \\

Concretely, the process is to simulate many random walks \emph{starting from input entity} and compute the $L_1$-normalized visit count as the importance score. Now, instead of simulating thousands of random walks it can be proven that in the limit of an infinity of simulations, the normalized $L_1$ visit count is equivalent to a Personalized PageRank score. Henceforth, we decided to compute the Weighted Personalized PageRank score (personalized on the input entity) using \textit{Oracle PGX} for each input entity. \\

Finally, and as stated previously, the top-$M$ scoring entities are extracted for each input admission and we define a minimum score of \textbf{0.0001} as an arbitrary threshold. Otherwise, there would always have exactly M neighbors sampled even if some are isolated and thus have a score of 0. This threshold allows for more flexibility and to have $0 \leq \mbox{neighbors} \leq M$ for a given input admission. A made-up example resulting from this whole process is available in figure~\ref{fig:kg-healthcare-extraction}.\\

From a practical standpoint, we also make sure not to sample neighbors from the testing or validation set when we are training, or respectively sampling entities from the training or testing set during validation. Equivalently, we make sure not to sample entities from training and validation when we do the final evaluation on the test set.

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{figures/kg-healthcare-extraction.pdf}
	\caption{Example of potential \textit{WPPR} scoring for the knowledge graph in figure~\ref{fig:kg-healthcare}. If we set $M=1$, only ``Admission 2`` would be extracted, whereas if we set $M=2$ both admissions 1 and 2 would be extracted as neighbors of ``Admission 1``.}
	\label{fig:kg-healthcare-extraction}
\end{figure}

\newpage
\section{Graph Machine Learning}
The machine learning model encapsulating information from neighboring entities as well as the input entity relies on the building block described in the chapter~\ref{chap:Baseline}. Indeed, the input admission is first encoded using the \textbf{Evolving Entity Encoder} from which the final embedding vector $\bm{\tilde{h}} \in \mathbb{R}^{b}$ is fed to the main module. The main module job lies in blending information from extracted neighbors with the input admission vector $\bm{\tilde{h}}_i^m$. \\

To better understand the mechanics, the extracted neighbors can be seen as made of static information throughout admission (e.g. patient age) and dynamic information (e.g. their respective events). The main module can either process dynamic information and static information, or just one or the other. Explicitly, the extracted neighbors entities can also go through the Evolving Entity Encoder to embed their dynamic behavior in a vector $\bm{\tilde{h}} \in \mathbb{R}^{b}$ that will be then concatenated with static information vectors. \\

Eventually, the embedded vector is concatenated with static information vectors, and fed through a fully-connected layer (\textit{encoder}) to obtain the final neighbor encoding vector. These vectors are then fed through an aggregator of the same kind as the one described in chapter~\ref{chap:Baseline}, that is \textit{sum}, \textit{mean} or \textit{max}. hHe purpose of this aggregator is to squash the data along the $M$ dimension to squeeze out information from neighbors. The final prediction diagnoses are made from the concatenation of the aggregated neighbors and input entity encoding, that is finally fed into a fully-connected layer mapping to our \emph{50} classes. \\

On our use-case at hand, we decided to discard dynamic behavior of neighbors and solely take into account the final diagnoses of those as our static information. Additionally, for a one-hot encoded vector of a neighbor final diagnoses $\bm{y}=[0, 0, 1, 0, 1, 0, \dots, 1]\mbox{, where }|\bm{y}|=50$ we decided to make use of the \textbf{SEQ\_NUM} field by transforming this one-hot vector using the function $1/x$. That is, our new static information vector becomes $\bm{\tilde{y}}=[0, 0, 1/1, 0, 1/3, 0, \dots, 1/2]\mbox{, where }|\bm{\tilde{y}}|=50$ if we respectively have a \textbf{SEQ\_NUM} of 1, 3 and then 2. \\

A schematic visualization of the general machine learning model is available on the figure~\ref{fig:kg-rnn-general}, while the applied model can be found on the figure~\ref{fig:kg-rnn-healthcare}.

\newpage
\subsection{Schematic Visualizations}
In order to provide the reader an overview of the mechanics behind KG-RNN, the following visualization summarizes the textual description of the previous section.

\begin{figure}[H]
 \centering
 \includegraphics[width=0.7\textwidth]{figures/kg-rnn-general.pdf}
 \caption{The general module of our architecture, where \textbf{Evolving Entity Encoder} relies on work from previous chapter. The static properties and information from neighbors are concatenated and fed through an \emph{Encoder}, consisting of a simple fully-connected layers to blend the concatenated information. All encoding vectors from neighbors are aggregated along the $M$ dimension and concatenated with the input entity. This vector is then further fed into a fully-connected layer, here hidden in the \emph{Concatenate} block, to output the predictions.}
 \label{fig:kg-rnn-general}
\end{figure}

The following figure is a special case of the general approach available in the previous figure. Indeed, in our practical application we decided to get rid of the dynamic information from neighbors, leading to the following adapted schema:

\begin{figure}[H]
 \centering
 \includegraphics[width=0.6\textwidth]{figures/kg-rnn-healthcare.pdf}
 \caption{Similar to the previous schema, except that only static information from neighbors is encoded and squashed. Here the static information consist of only the diagnoses of these neighboring admissions.}
 \label{fig:kg-rnn-healthcare}
\end{figure}

As mentioned previously, in our case we decided to discard dynamic information from neighbors but we argue that this is heavily application-dependent, thus validating on different tasks and knowledge graphs would be insightful.


%
% This is Chapter 1 file (chap1.tex)
%
\chapter{Introduction}\label{chap:chap1}

    \section{Prologue to Plasma}\label{sec:plas0}

        Our daily life is dominated by our interactions with the three classical states of matter:
        solid, liquid and gas. Plasma is the fourth state of matter and by far the most abundant
        one. In fact the observable universe is almost entirely made up of plasma (99.9\% of the
        universe) \citep{Boulos1994}. From the HII region around a huge star to the surface of a
        star, from the super hot Inter Galactic Medium to the inside of a plasma TV, plasma is
        everywhere. Given its abundance and ubiquitous nature, it becomes vitally important to study
        and understand plasma. In the rest of this chapter we define what constitutes a plasma
        (\Cref{sec:plas1}) and  discuss some of its salient properties and the laws of physics that
        govern it. We also shed some light on the local regions around Earth that are made up of
        plasma (\Cref{sec:plas2}) and discuss studying them (\Cref{sec:plas3}). We conclude the
        chapter with with a brief discussion of topics covered in this thesis. (\Cref{sec:plas4}).

    \section{Introduction To Plasma} \label{sec:plas1}

        The term ``plasma" comes from the ancient Greek word ``$\pi \lambda \acute{\alpha} \sigma
        \mu \alpha$" that means something that is moldable. It was first used in the modern context
        by \citet{Langmuir1928} to describe the ``region (around electrodes) containing balanced
        charges of ion and electrons".

        A plasma is a sub-type of ionized gas; a gas where significant fraction of the atoms have
        been ionized. There are specific criteria that distinguishes plasmas from other ionized
        gases (discussed later in this section), but first we consider the equations that govern the
        dynamics of charged particles (electrons and ions).

        As is with everything that has mass in the universe, a plasma's dynamics is governed by
        Newton's equation of motion:
        \begin{align}
            %\begin{split}
            \mathbf{F}_{\rm net} = \frac{d \mathbf{P}}{d t} & = m \frac{d^2 \mathbf{x}}{d t^2} \protect\footnotemark \label{eq:nwtn1}
        \end{align}
        \footnotetext{$\mathbf{F}_{\rm net} = m \frac{d^2 \mathbf{x}}{d t^2}$ is only valid when the
        particle is moving at speed much smaller than the speed of light.} where $\mathbf{F}_{\rm
        net}$ is the net external force acting on the system and \textbf{P} is its momentum. t is
        time, \textbf{x} is the position vector and $\frac{d}{dt}$ is the derivative with respect to
        time.

        For a charged particle with charge \textit{q}, moving with velocity \textbf{v} in an
        electromagnetic field with electric and magnetic field as \textbf{E} and \textbf{B}
        respectively, the electromagnetic force or Lorentz force is given as:
        \begin{align}
            \mathbf{F}_{\rm EM} = q \left( \mathbf{E} + \mathbf{v} \times \mathbf{B} \right)
            \label{eq:lorentz}
        \end{align}
        These equations (\Crefrange{eq:nwtn1}{eq:lorentz}) coupled with the four Maxwell's equations
        (\Crefrange{eq:maxwell1}{eq:maxwell4}) define the complete dynamics of a plasma.
        \begin{align}
            \nabla \cdot \mathbf{E} & = \frac{\rho}{\epsilon_\circ} \label{eq:maxwell1}\\
            \nabla \cdot \mathbf{B} & = 0 \label{eq:maxwell2}\\
            \nabla \times \mathbf{E} & = -\frac{\partial \mathbf{B}}{\partial t} \label{eq:maxwell3}\\
            \nabla \times \mathbf{B} & = \mu_\circ \mathbf{J} + \frac{1}{c^2} \frac{\partial \mathbf{E}}{\partial t} \label{eq:maxwell4}
            %\end{split}
        \end{align}
        where, $\rho$ is the charge density, $\epsilon_\circ$ is the permittivity of free space,
        $\frac{\partial}{\partial t}$ is the partial derivative with respect to time, $\mathbf{J}$
        is the current density, and c is the speed of light in vacuum.

        The most accurate way to study the behaviour of plasma is to track each particle
        individually using \Crefrange{eq:nwtn1}{eq:maxwell4}, all while accounting for all the
        fields, external as well as those arising because of the charge and motion of particles
        themselves. However, that method is almost impossible to implement not only because of
        difficulty in computing the field arising because of mutual interactions but also because of
        the huge number of particles involved. Consequently, scientists often fall back to
        statistical methods in their studies, such as applying kinetic equations that use physics
        based on ensemble averages (see \Cref{chap:chap2}) or by approximating the plasma as a fluid
        as is done in Magneto-hydrodynamics (MHD).

        Since even the lightest ion, a proton, is nearly 2000 times more massive than an electron
        and the dynamics of particles are often governed by their masses, both the time and length
        scales at which dynamics occur in plasmas are extremely diverse, even when one is studying
        the same phenomena for ions and electrons. Values of some of the parameters associated with
        plasma (generally referred to as \textit{plasma parameters}) can help in understanding the
        scales one is dealing with. Also, as will become apparent in \Cref{chap:chap2,chap:chap3},
        one may choose to focus on a specific scale depending on the interest or scope of the study.
        Here, we list some of the most relevant plasma parameters, what each one of them mean, and
        their mathematical expressions.\\
        \\
        \textbf{Debye Length} ($\lambda_{\rm D}$): The Debye length \index{Debye length} is the scale above which a
        plasma (with no net charge) maintains near charge neutrality --- $\rho \approx 0$ when
        $\rho$ is smoothed over a scale $\gtrsim \lambda_{\rm D}$. On scales smaller than
        $\lambda_{\rm D}$, particles behave as if it were interacting with other moving charges
        individually instead of a smooth macroscopic electromagnetic field. If we have sufficiently
        large number of particles inside a spherical volume with $\lambda_{\rm D}$ as the radius
        ($n_{\rm p} \lambda_{\rm D}^3 > 1$), then particles are shielded by its neighbours from the
        surrounding plasma (called \textit{Debye shielding}). On scales $\lesssim \lambda_{\rm D}$,
        random thermal motions of the particles give rise to isolated regions of non-zero charge
        density.  We would then expect $\lambda_{\rm D}$ to increase with plasma temperature.
        Indeed, for a plasma consisting of ionized hydrogen for which the protons and electrons have
        comparable temperatures, we define Debye length as:
        \begin{align}
            \lambda_{\rm D} & = \frac{\epsilon_\circ k_{\rm B} T_{\rm p}}{n_{\rm e} e^2}^{1/2} \label{eq:debye}
        \end{align}
        where $k_{\rm B}$ is the Boltzmann constant, $n_{\rm e}$ is the electron number density and
        $T_{\rm p}$ is the proton temperature. In order for a system to be classified as plasma, we
        must have the physical length scale (L) of the system much larger than its Debye length.
        \begin{align}
            \lambda_{\rm D} \ll L \label{eq:lambda}
        \end{align}
        \\
        \textbf{Ion-inertial Length \index{Ion-inertial Length}($d_{\rm j}$):} This is the length scale in plasma at which the
        electrons are decoupled from ions and the magnetic field is frozen in with the electrons.
        For species `$j$' of plasma (where $j = p^{+}$ for protons and $j = i^{n+}$ for any other
        ion with n positive charge)\footnote{In this thesis unless otherwise specified ion will
        refer to protons and two terms will be used interchangeably}, it can be written in terms of
        ion plasma frequency ($\omega_{\rm pj}$) as:
        \begin{align}
            d_{\rm j} = \frac{c}{\omega_{\rm pj}} \label{eq:ionint}
        \end{align}
        \\
        \textbf{Plasma Frequency \index{Frequency!plasma} ($\omega_{\rm pj}$)}\footnote{Note that `p' in $\omega_{\rm pj}$
        refers to plasma and not proton.}: It is the frequency at which any given species in plasma
        oscillates and is given by:
        \begin{align}
            \omega_{\rm pj} & = \left(\frac{n_{\rm j} q_{\rm j}^2}{\epsilon_\circ m_{\rm j}}\right)^{\frac{1}{2}} \label{eq:plasf}
        \end{align}
        \\
        \textbf{Cyclotron Frequency \index{Frequency!cyclotron} ($\Omega_{\rm cj}$):} In a magnetized plasma (a plasma which has
        a background magnetic field), due to the perpendicular direction of the magnetic force with
        respect to the particle's velocity, any non-stationary charged particle in a magnetic field
        gyrates around a point called the center of gyration. The frequency of gyration or cyclotron
        frequency is given by:
        \begin{align}
            \Omega_{\rm cj} & = \frac{q_{\rm j} B}{m_{\rm j}} \label{eq:cyclf}
        \end{align}
        where \textbf{B} is the background magnetic field. \\
        \\
        \textbf{Gyroradius \index{Gyroradius}}\textbf{($\rho_{\rm j}$)}: This is the radius of the circular path that a particle takes in
        the presence of a magnetic field, and is dependent on the ratio of thermal speed to that of
        cyclotron frequency.
        \begin{align}
            \rho_{\rm j} = \frac{w_{\rm j}}{\Omega_{\rm cj}} \label{eq:rho}
        \end{align}
        where $w_{\rm j}$ is the thermal speed of the particle. \\
        \\
        \textbf{Alfv\'en Speed \index{Alfv\'en Speed} ($V_{\rm Aj}$)}: It is the speed at which magnetic signals, like a
        fluctuation in the field, travel in a plasma. It depends on the strength of the magnetic
        field in the plasma as well the density and mass of the species and has the following
        expression:
        \begin{align}
            v_{\rm Aj} = \frac{B}{\sqrt{\mu_\circ \sum_{\rm j} n_{\rm j} m_{\rm j}}} \label{eq:alfv}
        \end{align}

    \section{Plasma in Near-Earth Environment} \label{sec:plas2}

        The Sun is the largest source of plasma in our solar system. Huge amounts of charged
        particles emanate from the Sun originating in its outermost atmospheric layer, called the
        Corona \citep{Parker1958,Parker1960,Parker1963,Gringauz1960,Neugebauer1962}. This constant
        outflow of particles is commonly called solar wind. The solar wind is often highly
        magnetized, is weakly collisional, travels at supersonic speed and is primarily composed of
        ionized hydrogen (i.e., protons) \citep{Marsch1982}. \Cref{tab:plaspar1} lists out some of
        the plasma parameters and their typical values for the solar wind at 1\,au.
        \Cref{fig:plas_para_wnd} shows the distribution of some of the parameters listed in
        \Cref{tab:plaspar1}.
        \begin{figure}
            \begin{center}
                \includegraphics[width=1\textwidth]{figures/chap1/plasma_parameters_wnd.pdf}
                \caption[Plasma parameter distributions at 1\,au ]{Distribution of various plasma
                parameters near Earth, based on data from Wind spacecraft. Top row shows
                distribution for (from left to right) proton-inertial length ($d_{\rm i}$), Debye
                length ($\lambda_{\rm D}$), proton-gyrofrequency ($\Omega_{\rm cp}$) and the lower
                row shows (from left to right) proton-gyroradius ($\rho_{\rm i}$), proton-plasma
                frequency ($\omega_{\rm pp}$) and alfv\'en speed ($v_{\rm A}$). Red line shows the
                median value of each parameter, whereas the shaded region shows $10^{\rm th}$ to
                $90^{\rm th}$ (cyan) and $25^{\rm th}$ to $75^{\rm th}$ percentile (magenta) of each
                parameter.\protect\footnotemark}
                \label{fig:plas_para_wnd}
            \end{center}
        \end{figure}
        \footnotetext{\Cref{fig:plas_para_wnd} is based on data from Wind Spacecraft. See
        \Cref{sec:wind} for more details on data and spacecraft.}

        The Earth's local magnetic field, which arises as a result of dynamo action of its molten
        core \citep{Elsasser1956}, extends far into space (roughly 10 earth radii in the direction
        of the sun and $\sim$ 300 earth radii in the anti-sunward direction) and interacts with the
        incoming solar wind. This interaction gives rise to a plethora of structures.
        \Cref{fig:ms_earth} shows an artistic rendition of Earth's magnetosphere. The layer along
        which solar wind transitions from supersonic to subsonic speed is called the bow shock
        (region 1). The region immediately after the bow shock is called the magnetosheath (region
        2) and is comprised mostly of shock treated solar wind. This region is of special importance
        to the present work (see \Cref{chap:chap5,chap:chap7}). The region beyond the magnetosheath,
        towards Earth, where the pressure exerted by the solar wind and Earth's magnetic field are
        in equilibrium is called the magnetopause (region 3) and forms the boundary between Earth's
        magnetosphere (volume  around  Earth  where the influence  of  its magnetic field is felt
        (region 4)) and the solar wind. There is also a long magnetotail further away from the Sun,
        which extends far beyond the surface of the Earth (regions 5 and 6). The region closest to
        the surface (region 7) is called the plasmasphere, which is made up of relatively cooler
        plasma and is located above the ionosphere. The shape and size of all these structures vary
        greatly depending on the velocity and density of the incoming plasma, the strength of
        magnetic field, and solar activity.

        %Another distinct region of plasma close to the Earth is the ionosphere. It is part of the
        %upper region of Earth's atmosphere and forms because of photoionization of atoms by
        %ultraviolet radiation from Sun \cite[\S 4.4.3]{Wallace2006}. These radiation get absorbed
        %by around 90\,km above the surface and have enough energy and intensity to ``give rise to
        %sufficient number of free electrons" which helps in propagation of radio waves \cite[\S
        %4.4.3]{Wallace2006}. The structure of ionosphere is quite complicated and has a lot of
        %variability, both diurnal and seasonal. Owing to its complicated structure and dynamics it
        %is its own huge field of research and holds considerable interest for both geophysicists
        %and climatologists.\\

        \begin{table}[ht]
            \centering
            \caption[Plasma Parameters - Median values]{Plasma parameters and their typical values for different space plasmas.\protect\footnotemark}
            \begin{tabular}{ p{0.15\linewidth}  p{0.25\linewidth}  p{0.25\linewidth}
            p{0.25\linewidth}  }
                \hline
                \\
                Parameter & Solar Wind (0.15\,au ) & Solar Wind (1\,au ) & Magnetosheath \\ \\
                \hline
                \\
                $d_{\rm i}$ & 15,510 $\pm$ 6,200 m & 91,920 $\pm$ 42,000 m & 45,600 $\pm$ 9,900 m\\
                \\
                %\hline
                \\
                $\lambda_{\rm D}$ & 2.87 $\pm$ 1.98 m & 6.41 $\pm$ 6.20 m & 23.18 $\pm$ 8.00 m\\ \\
                %\hline
                \\
                $\Omega_{\rm cp}$ & 6.47 $\pm$ 2.70 1/s & 0.45 $\pm$ 0.26 1/s & 2.16 $\pm$ 1.00
                1/s\\ \\
                %\hline
                \\
                $\omega_{\rm pp}$ & 19,328 $\pm$ 7,300 1/s & 3,261 $\pm$ 1,500 1/s & 6,574 $\pm$
                1,500 1/s\\ \\
                %\hline
                \\
                $\rho_{\rm p}$ & 12,793 $\pm$ 8,500 m & 68,615 $\pm$ 48,000 m & 97,795 $\pm$ 69,000
                m\\ \\
                %\hline
                \\
                $V_{\rm A}$ & 102,503 $\pm$ 39,000 m/s & 43,390 $\pm$ 26,000 m/s & 94,256 $\pm$
                50,000 m/s\\ \\
                \hline
            \end{tabular}
            \label{tab:plaspar1}
        \end{table}
        \footnotetext{These values are based on datasets as described in \Cref{chap:chap4}.}

        \begin{figure}
            \begin{center}
                \includegraphics[width=1\textwidth]{figures/chap1/Magnetosphere_Levels.pdf}
                \caption[Earth's Magnetosphere's structure]{Artistic rendition of Earth's magnetosphere, its structure and different layers. The name of each numbered layer is 1.bow shock, 2. magnetosheath, 3. magnetopause, 4. magnetosphere, 5 and 6. tail lobes, 7. plasmasphere.\protect\footnotemark}
                \label{fig:ms_earth}
            \end{center}
        \end{figure}
        \footnotetext{Picture credit: https://commons.wikimedia.org/wiki/File:Magnetosphere\_Levels.svg}

    \section{Studying Space Plasmas} \label{sec:plas3}

        In the previous section (\Cref{sec:plas2}) we discussed two different kinds of naturally
        occurring plasma regions close to Earth. A complete theory of plasma would require us to
        understand the commonality as well as the uniqueness of each of these regions. Consequently,
        over the last century or so the scientific community has devised several methods to study
        them. From Guglielmo Marconi using an antenna on a kite to receive radio signals in 1901 to
        NASA launching a spacecraft costing more than a billion dollars (Parker Solar Probe (PSP))
        in 2018 to study the Sun from a closer distance than ever before, the community has been in
        a constant pursuit to understand them.
        %\Cref{tab:spcmsn} lists out some of the major programs and missions along with mission
        %objectives, dedicated to such studies.\\
        %\begin{table}[ht] \centering \caption[Major space missions to study space plasmas]{Some of
        %    the major space missions to study space %plasmas \todo{update the table with full
        %    list}} \begin{tabular}{ | p{0.15\linewidth} | p{0.15\linewidth} | p{0.45\linewidth}|}
        %    \hline Spacecraft & Years Active & Major Objective \\
        %        \hline Voyager 1 \newline Voyager 2 & 1977 - \newline 1977 - & Study outer planets
        %         and interplanetary %medium \\
        %        \hline Wind & 1994 - & Study plasma processes in the solar wind near earth and in
        %        magnetosphere and %ionosphere\\
        %        \hline Helios A \newline Helios B & 1974 - 1982 \newline 1976 - 1985 & Observation
        %        of solar wind, electromagnetic fields, cosmic rays\\
        %        \hline MMS & 2016 - & Understanding magnetic reconnection and turbulence\\
        %        \hline Parker Solar Probe & 2018 - & Understanding Coronal heating\\
        %        \hline SoHo & 2018 - & Understanding Coronal heating\\
        %        \hline Ace & 2018 - & Understanding Coronal heating\\
        %        \hline STEREO & 2018 - & Understanding Coronal heating\\
        %        \hline \end{tabular} \label{tab:spcmsn} \end{table}

    \section{In This Thesis} \label{sec:plas4}

        Work done towards this thesis presents an incremental contribution towards understanding the
        nature and behaviour of space plasmas. \Cref{chap:chap2,chap:chap3} provide a theoretical
        background on plasma microkinetics and turbulence, respectively. \Cref{chap:chap4} gives a
        brief overview of all the datasets used in the present document and explains some of the
        data analysis techniques employed in \Crefrange{chap:chap5}{chap:chap7}.

        \Crefrange{chap:chap5}{chap:chap8} report the author's original work. \Cref{chap:chap5}
        discusses the intermittency in space plasmas and simulations as well as its co-development
        with linear instabilities. \Cref{chap:chap6} explores the heating of ions close to the Sun
        as a consequence of intermittent structures. \Cref{chap:chap7} discusses the competition
        between linear and non-linear processes using a statistical approach on six different
        datasets. \Cref{chap:chap8} presents an exploratory study of magnetic field reconstruction
        using machine learning (ML) techniques. \Cref{chap:chap9} provides a summary of the entire
        thesis and a guide for future work.


\chapter{Assignment: Model Explanation}
\label{hw:model-explanation}

\newthought{Understanding the model is essential for decision-making.}\marginnote{For this assignment, we will be using Explain add-on, which you can install in Options -- Add-ons.} We will be using \textit{Attrition - Train} data from the \widget{Datasets} widget. We already know the data and its properties. But for reaching any kind of decisions regarding employee attrition, it is important not only to evaluate the models, but to understand them - what they do, which features are important, and in what way.

\begin{figure*}[h]
  \centering
  \includegraphics[width=\linewidth]{workflow.png}%
  \caption{$\;$}
\end{figure*}

Use \widget{Random Forest} to train a model, then answer the following questions:
\begin{enumerate}
    \item Looking at \widget{Explain Model}, which are the top three features for the random forest model?
    \item Change the target class to \textit{Yes}. What happens?
    \item Two of the top three features are the same. Why?
    \item In \widget{Data Table}, select the employee for whom you wish to explain the prediction. Say, we go with John. Will John likely stay with the company or resign? Look at \widget{Predictions} for an answer.
    \item In \widget{Explain Predictions}, explain \emph{why} John is leaving or staying.
\end{enumerate}


\documentclass[main.tex]{subfiles}
\begin{document}

\subsection{Statistical descriptions of plasmas}

\marginpar{Thursday\\ 2021-11-18}

If the length scales we consider are larger than the Debye length, we can safely neglect the effect of the Coulomb potential of each individual particle.
This does not mean that there are no electric fields, but the electric fields are mesoscopic or larger.

This is ``desirable'', in that we'd like to use statistical descriptions of the plasma.
Such a statistical description will necessarily work in phase space.

Let us start out in the nonrelativistic approximation: if we only have one particle, we can write its phase space distribution function as
%
\begin{align}
N(\vec{x}, \vec{v}, t) = \delta (\vec{x} - \vec{X}(t)) \delta (\vec{v} - \vec{\dot{X}}(t))
\,.
\end{align}

If we have several particles, this can be readily generalized:
%
\begin{align}
N(\vec{x}, \vec{v}, t) =
\sum _{i} \delta (\vec{x} - \vec{X}_i(t)) \delta (\vec{v} - \vec{\dot{X}}_i(t))
\,,
\end{align}
%
but this only describes a single particle species: we know that at the very least we will have electrons and protons, in order to preserve charge neutrality.
So, let us call the quantity defined above \(N_s\), where \(s\) is an index spanning \(\qty{e, i}\) for electrons and ions respectively.

We want to describe the evolution of this quantity: its \textbf{total} time derivative can be computed through the chain rule, and if we set it to zero we find that \(\dv*{N_s}{t} = 0\) is equivalent to:
%
\begin{align}
\pdv{N_s}{t} (\vec{x}, \vec{v}, t) =
- \sum _{i}
\vec{\dot{X}} \cdot
\nabla_x \delta (\vec{x} - \vec{X}_i(t))
\delta (\vec{v} - \vec{V}_i (t) )
- \sum _{i}
\delta (\vec{x} - \vec{X}_i(t))
\vec{\dot{V}}_i(t) \cdot
\nabla_v \delta (\vec{v} - \vec{V}_i(t))
\,.
\end{align}

Now, these charges will evolve under the actions of the electric and magnetic fields: but we also need to describe what is the source of these fields.

The action of these fields on a particle with velocity \(\vec{V}_i\) will be described by the Lorentz force,
%
\begin{align}
m_s \vec{\dot{V}}_i (t) = q_s \vec{E}^{\text{microscopic}} (\vec{x}) + \frac{q_s}{c} \vec{V}_i \times \vec{B}^{\text{microscopic}} (\vec{x}, t)
\,.
\end{align}

This acceleration term will then be put into the aforementioned evolution equation.
We can already understand why this problem will be hard: the fields acting on a particle will be sourced by all the others.

The microscopic EM fields will satisfy Maxwell's equations:
%
\begin{align}
\vec{\nabla} \cdot \vec{E}^{\text{micro}} (\vec{x}, t)
&= 4 \pi \zeta^{\text{micro}}  \\
\vec{\nabla} \cdot \vec{B}^{\text{micro}} &= 0  \\
\vec{\nabla} \times E^{\text{micro}} &= - \frac{1}{c} \pdv{\vec{B}^{\text{micro}}}{t}  \\
\vec{\nabla} \times \vec{B}^{\text{micro}} &= \frac{4 \pi }{c} \vec{J}^{\text{micro}} + \frac{1}{c} \pdv{\vec{E}^{\text{micro}}}{t}
\,,
\end{align}
%
where the density and current density read
%
\begin{align}
\zeta^{\text{micro}} (\vec{x}, t) &= \sum _{s=i, e} q_s
\int \dd[3]{\vec{v}} N_s (\vec{x}, \vec{v}, t)  \\
\vec{J}^{\text{micro}} &= \sum _{s=i, e} q_s
\int \dd[3]{\vec{v}} \vec{v} N_s (\vec{x}, \vec{v}, t)
\,.
\end{align}

The Boltzmann equation plus the Lorentz one can be more compactly written as
%
\begin{align}
\pdv{N_s}{t}
= - \vec{v} \cdot \vec{\nabla}_x N_s
- \sum _{i=1}^{N} \frac{q_s}{m_s}
\qty[ \vec{E}^{\text{micro}} + \frac{1}{c} \vec{v} \times \vec{B}^{\text{micro}}] \cdot \vec{\nabla}_v \qty[
    \delta (\vec{v} - \vec{\dot{X}}_i(t))
    ]
\delta (\vec{x} - \vec{X}_i(t))
\,.
\end{align}

The EM fields are \emph{a priori} computed at the position and velocity of the \(i\)-th particle, \((\vec{X}_i, \vec{V}_i)\), but because of the \(\delta \)-functions at each point we can substitute this position for the generic one \((\vec{x}, \vec{v})\).

% where we have done a nontrivial step: the gradient \dots

% \todo[inline]{That's wrong! Or maybe not? it's because the velocity dependence is mediated through the delta-function\dots }

The equation then becomes
%
\begin{align}
\pdv{N_s}{t} + \vec{v} \cdot \vec{\nabla}_x N_s
&= - \frac{q_s}{m_s} \qty[\vec{E}^{\text{micro}} + \frac{\vec{v} \times \vec{B}^{\text{micro}}}{c}] \cdot \nabla_v N_s
\,.
\end{align}

This equation is called the Klimontovich-Dupree equation.\footnote{As many things done during the Cold War, it was developed by military personnel independently in the two blocks. }

This equation, however, is basically useless, unless we do a mean-field approximation.

Let us introduce the quantity \(f_s (\vec{x}, \vec{v}, t)\), which we want to compute through average on mesoscopic scales:
%
\begin{align}
f_s (\vec{x}, \vec{v}, t) = \expval{N_s (\vec{x}, \vec{v}, t)}_{\Delta V}
\,.
\end{align}

The true phase space density will then be
%
\begin{align}
N_s (\vec{x}, \vec{v}, t) = f_s (\vec{x}, \vec{v}, t) + \delta f_s
\,,
\end{align}
%
where the fluctuations are assumed to average to zero.
We can write a similar expression for the electric and magnetic fields:
%
\begin{align}
\vec{E}^{\text{micro}} &= \vec{E} + \delta \vec{E} \\
\vec{B}^{\text{micro}} &= \vec{B} + \delta \vec{B}
\,.
\end{align}

The averaged KD equation then becomes:
%
\begin{align}
\dv{f_s}{t} + \vec{v} \cdot \nabla_x f_s + \frac{q_s}{m_s}
\qty[\vec{E} + \frac{1}{c} \vec{v} \times \vec{B}] \vec{\nabla}_v f_s = - \frac{q_s}{m_s} \expval{
    \qty( \delta \vec{E} + \frac{1}{c} \vec{v} \times \delta \vec{B} ) \cdot \vec{\nabla}_v \delta f_s
}
\,.
\end{align}

The interaction and collision terms are \emph{quadratic} in the fluctuations.
If we neglect this term (which is typically called a ``correlation'' term), we get the \textbf{Vlasov} equation:
%
\begin{align}
\pdv{f_s}{t} + \vec{v} \cdot \vec{\nabla}_x f_s + \frac{q_s}{m_s} \cdot \qty[ \vec{E} + \frac{\vec{v} \times \vec{B}}{c}] \vec{\nabla}_v f_s = 0
\,.
\end{align}

We can do the same thing to the Maxwell equations, using an averaged version of the charge and current densities.

We will need to generalize to the relativistic case: we move to \((\vec{x}, \vec{p})\) phase space.
For relativistic particles, the Lorentz force reads
%
\begin{align}
\vec{\dot{p}} = q_s \qty[\vec{E} + \frac{\vec{v} \times \vec{B}}{c}]
\,.
\end{align}

The source terms in the Maxwell equations will be integrated in \(\dd[3]{p}\), but for the charge current we will have an integral \(\int \dd[3]{p} \vec{v} f_s\).

The relativistic Vlasov equation is then readily derived with minor modifications, and reads
%
\begin{align}
\pdv{f_s}{t} + \vec{v} \cdot \vec{\nabla}_x f_s + q_s \qty[ \vec{E} + \frac{\vec{v} \times \vec{B}}{c}] \vec{\nabla}_p f_s = 0
\,.
\end{align}

Let us now move to the nonrelativistic plasma again, and assume we are at zero temperature.
We will then make a small perturbation: the ions will be stationary in first approximation.
Will the Vlasov equation contain the plasma waves we derived earlier?

We only write it for electrons, so
%
\begin{align}
\pdv{f}{t} + \vec{v} \cdot \vec{\nabla}_x f_s
- \frac{e}{m_e} \qty[\vec{E} + \frac{\vec{v} \times \vec{B}}{c}]_\alpha \pdv{f}{v_\alpha } = 0
\,,
\end{align}
%
where in the second term we are adopting the Einstein convention, summing over \(\alpha \).

We will assume that there is no magnetic field perturbation: this is the same thing we did in the plasma waves, specifically in assuming that \(\mathbb{K}\) is diagonal.

\todo[inline]{is this correct?}

In the stationary configuration there is \(\vec{E} = 0\).
To linear order, the perturbed equation will read
%
\begin{align}
\pdv{ \delta f}{t} + \vec{v} \cdot \nabla \delta f + \frac{e}{m_e} \nabla \varphi _\alpha \pdv{f}{v_\alpha } = 0
\,.
\end{align}

\todo[inline]{But isn't \(f = \text{const}\) at zeroth order?}
We want to assume that the plasma is cold!

The electric potential \(\varphi \) will satisfy
%
\begin{align}
- \nabla^2 \varphi = - 4 \pi e \int \dd[3]{v} \delta f
\,.
\end{align}

We then move to Fourier space:
%
\begin{align}
- i \omega \widetilde{\delta f} +
i \vec{k} \cdot \vec{v} \widetilde{\delta f}
+ \frac{e}{m_e} i k_\alpha  \widetilde{\varphi} \pdv{f}{v_\alpha } = 0
\,,
\end{align}
%
but the electric potential will satisfy
%
\begin{align}
k^2 \widetilde{\varphi} = - 4 \pi e \int \dd[3]{v} \widetilde{\delta f}
\,,
\end{align}
%
so we get
%
\begin{align}
\widetilde{\delta f} \qty[ i \vec{k} \cdot \vec{v} - i \omega ] &=
- \frac{e}{m_e} \widetilde{\varphi} k_\alpha \pdv{f}{v_\alpha }  \\
\widetilde{\delta f} &= - \frac{e}{m_e} \widetilde{\varphi} \frac{k_\alpha \pdv*{f}{v_\alpha }}{\vec{k} \cdot \vec{v} - \omega }
\,,
\end{align}
%
which we substitute into the integral for \(\widetilde{\varphi}\):
%
\begin{align}
\widetilde{\varphi} = \frac{4 \pi e^2}{k^2m_e} \widetilde{\varphi} k_\alpha \int \dd[3]{v}  \pdv{f}{v_\alpha } \frac{1}{\vec{k} \cdot \vec{v} - \omega }
\,,
\end{align}
%
so the allowed perturbations are those which make this equation true (for arbitrary \(\varphi \)).
For now we have not assumed that the electrons are cold: this will enter in how we write the unperturbed \(f\).

The assumptions of the electrons being cold can be modelled as \(f = n_0 \delta (\vec{v})\): therefore, we need to integrate by parts.

Suppose that the \(z\) axis is along \(k\): then, the integrand reads
%
\begin{align}
\int \dd{v_x} \dd{v_y} \dd{v_z} \pdv{f}{v_\alpha } \frac{1}{k v_z - \omega } &=
\int \dd{v_x} \dd{v_y} \dd{v_z} f \frac{1}{(k v_z - \omega)^2 }  \\
&= \int \dd{v_x} \dd{v_y} \delta (v_x) \delta (v_y) n_0 \frac{k}{\omega^2} = \frac{n_0 k }{ \omega^2}
\,,
\end{align}
%
so the equation just reads
%
\begin{align}
1 - \frac{4 \pi e^2 n_0 }{k^2 m_e} \frac{k^2}{\omega^2} \implies \omega^2 = \frac{4 \pi e^2 n_0 }{m_e} = \omega_p^2
\,.
\end{align}

At the very least, this more complicated approach allows us to recover the results we expected.

% \subsection{}
\section{Alfvén waves}

Next time, we will add one complication: a global, ordered magnetic field.

We know that this happens, for example, in spiral galaxies like our own: we observe large-scale magnetic fields.

Much of the physics of the transport of non-thermal particles will be affected by these magnetic fields.

The perturbation of the two coupled Vlasov equations under the effect of this external \(\vec{B}\) field will yield what are called \textbf{Alfvén waves}.

% We will also find a simplification of the

\end{document}


\subsubsection{\stid{3.03} LLNL ATDM Math Libraries}

\paragraph{Overview}

The LLNL ATDM Mathematical Libraries project performs work in the MFEM library
\cite{MFEM} that is focused on providing high-performance mathematical algorithms
and finite element discretizations to next-gen high-order ECP/ATDM
applications. A main component of these efforts is the development of
ATDM-specific physics enhancements in the finite element algorithms in MFEM and
the MFEM-based BLAST Arbitrary Lagrangian-Eulerian (ALE) code \cite{BLAST}, in
order to provide efficient discretization components for LLNL's ATDM efforts,
including the MARBL application (ECP's LLNLApp).

A second main task in the project is the development of unique unstructured
adaptive mesh refinement (AMR) algorithms in MFEM, that focus on generality,
parallel scalability, and ease of integration in unstructured mesh
applications. The new AMR capabilities can benefit a variety of ECP apps that
use unstructured meshes, as well as many other applications in industry and the
SciDAC program.

Another aspect of the work is the preparation of the MFEM finite element library
and related codes for exascale platforms by using mathematical algorithms and
software implementations that exploit increasing on-node concurrency targeting
multiple complex architectures (e.g. GPUs). This part of the project is
synergistic with and leverages efforts from the ECP CEED co-design center.

MFEM is an open-source finite element library with ~3000 downloads/year from 70+
countries. It is freely available at \url{mfem.org}, on GitHub
at \url{github.com/mfem}, where the MFEM community includes more than 165
members), as well as via Spack and OpenHPC. The application outreach and the
integration in the ECP ecosystem is further facilitated by MFEM's participation
in ECP's xSDK project.

\paragraph{Key Challenges}

The key challenges addressed by the LLNL ATDM Mathematical Libraries project are:

\noindent
{\bf \em Robust high-order finite element methods for ALE compressible flow.}
While high-order methods offer significant advantages in terms of HPC performance,
their application to complicated ALE problems requires careful considerations to
control oscillations and ensure accuracy.

\begin{figure}[htb]
\centering
\includegraphics[width=\textwidth]{projects/2.3.3-MathLibs/2.3.3.03-LLNL-ATDM-MathLibs/mfem-amr}
\caption{\label{fig:mfem-amr}AMR implementation in MFEM allows many applications to benefit from non-conforming adaptivity, without significant changes in their codes.}
\end{figure}

\noindent
{\bf \em Scalable algorithms for unstructured adaptive mesh refinement.}
Adaptive mesh refinement is a common way to increasing application efficiency
in problems with localized features. While block-structured AMR has been
well-studied, applying AMR in unstructured settings is challenging, especially
in terms of derefinement, anisotropic refinement, parallel rebalance and
scalability.

\noindent
{\bf \em GPU porting of finite element codes.}
Due to the relatively high complexity of the finite element machinery, MFEM,
BLAST and related codes use object-oriented C++ design that allows generality
and flexibility, but poses challenges in terms of porting to GPU architectures.
Finding the right balance between generality and performance in the GPU context
is an important challenge for many finite element-based codes that remains
outstanding in the current software and programming model environment.

\paragraph{Solution Strategy}

The MFEM team has performed and documented a lot of research in
high-performance mathematical algorithms and finite element discretizations
of interest to ATDM applications
\cite{BLAST18,BLASTFCT18,BLASTFCT17,BLAST16,BLAST14,BLAST13,BLAST12,BLAST11}.
Our work has demonstrated that the high-order finite element approach can
successfully handle coupled multi-material ALE, radiation-diffusion and MHD.
We have also shown how high-order methods can be adapted for monotonicity
(positivity preservation), handling of artificial viscosity (shock capturing),
sub-zonal physics via closure models, etc.

To enable many applications to take advantage of unstructured mesh adaptivity,
the MFEM team is developing AMR algorithms at library level, targeting both
{\em conforming} local refinement on simplex meshes and {\em non-conforming}
refinement for quad/hex meshes. Our approach is fairly general, allowing for
any high-order finite element space, H1, H(curl), H(div), on any high-order
curved mesh in 2D and 3D, arbitrary order hanging nodes, anisotropic refinement,
derifenement and parallel load balancing.
An important feature of our library approach is that it is independent of
the physics, and thus easy to incorporate in apps, see Figure \ref{fig:mfem-amr}.

As part of the efforts in the ECP co-design Center for Efficient Exascale
Discretizations (CEED), the MFEM team is also developing mathematical algorithms
and software implementations for finite element methods that exploit increasingq
on-node concurrency targeting multiple complex architectures (e.g. GPUs). This
work includes the libCEED low-level API library, the Laghos miniapp, and several
other efforts available through CEED.

To reach its many customers and partners in NNSA, DOE Office of Science, academia
and industry, the MFEM team delivers regular releases on GitHub (e.g. mfem-3.3 and
mfem-3.3.2 in 2017) that include detailed documentation and many example codes.
Code quality is ensured by smoke tests with Travis CI on Linux, Mac, Windows and
nightly regression testing at LLNL.

\paragraph{Recent Progress}

Selected recent highlights:
\begin{itemize}
\item
New optimized version of parallel AMR in MFEM, including construction of parallel interpolation, parallel refinement and rebalancing, demonstrated excellent weak and strong scalability during runs on the full Vulcan BG/Q machine at LLNL (400K MPI tasks).
\item
An interface for the new TMOP mesh optimization capabilities from mfem-3.3.2 was completed in the BLAST code, so that its remesh phase can use the TMOP functionality.
\item
Completed initial version of multi-group radiation-diffusion in BLAST.
\item
Participated in the ATDM L2 milestone for MARBL, ``Demonstration of Modular Transport Capability in a Multi-Physics Code'', which included MFEM support for high-order (HO) to low-order-refined (LOR) field transfer.
\item
BLAST's closure model was improved by separating the material energies into finite element and point-based parts, avoiding L2 projections of highly oscillatory modes.
\item MFEM v3.3.2 was released with many new features including: support for high-order mesh optimization, xSDK support, integration with STRUMPACK, 5 new examples and miniapps, physical-to-reference space mapping, continuous integration testing on Linux, Mac and Windows, and more.
\item MFEM v3.3 was released with many new features including: support for PETSc, SUNDIALS, CMake, matrix-free preconditioning, parallel mesh format, 36 new integrators, 16 new examples, and more.
\item Moved main MFEM development to GitHub, including many internal branches and pull requests.
\end{itemize}

\paragraph{Next Steps}

Our next steps include:
prepare and release mfem-3.4; continue to attend and contribute to the weekly MARBL and BLAST meetings;
complete an initial draft of MFEM's unified interface extensions to support GPUs and other accelerators;
and provide support for the upcoming MARBL L2 milestones.


\section{Relational Data Model Analysis}

The current data model is the one described in the Figure~\ref{fig:er}.

\subsection{Volume Table}

The first step towards a fair analysis is dimensioning the problem. To do so we
have to create a volume table.

\vspace{0.3cm}
\resizebox{\textwidth}{!}{%
	\begin{tabular}{|l|l|l|l|}
		\hline
		\thead{Name} & \thead{E/R} & \thead{Instances} & \thead{Justification} \\
		\hline
		User & E & \(50\,000\) & Initial Assumption \\
		\hline
		Owning & R & \(200\) & We suppose that 2\% of users is a restaurant owner \\
		\hline
		Restaurant & E & \(200\) & \makecell{Every restaurant owner has only 1
			restaurant\\ (Cardinality (1,1))} \\
		\hline
		Reservation & R & \(1\,500\,000\) & \makecell{On average a user has 30 reservations per year,\\ and that an owner in his restaurants has on average\\ 20 reservation per day (7300 per year).}\\
		\hline
	\end{tabular}
}

\subsection{Possible Operations}

After dimensioning the problem we provide a set of CRUD operations that can be
performed on the database. Each operations has a frequency defined as the number
of times the operation is performed per day.

\subsubsection{Login}

\begin{itemize}
	\item Description: Find a user in the system.
	\item Frequency: \(35\,000\) per week.
\end{itemize}

\subsubsection{Register}

\begin{itemize}
	\item Description: Insert a new user.
	\item Frequency: \(100\) per week.
\end{itemize}

\subsubsection{List of Restaurants}

\begin{itemize}
	\item Description: A customer request the list of all the available
		restaurants.
	\item Frequency: \(175\,000\) per week (5 times per login session on
		average).
\end{itemize}

\subsubsection{List of Reservations per User}

\begin{itemize}
	\item Description: Find all the reservation of a given user.
	\item Frequency: \(175\,000\) per week (Considering after a login and after each booking we ask for a new list of reservation this operation is performed 5 times per week for each user).
\end{itemize}

\subsubsection{List of Reservations per Restaurant}

\begin{itemize}
	\item Description: Find all the reservations for a given restaurant.
	\item Frequency: \(140\,000\) per week (every owner will check multiple times the list of reservation (10 times per day) at his restaurant we assume on average 70 per week for each user).
\end{itemize}

\subsubsection{Modify a Restaurant}

\begin{itemize}
	\item Description: Update the informations of a given restaurant.
	\item Frequency: \(25\) per week (we assume that these informations are
		not so likely to change frequently).
\end{itemize}

\subsubsection{Book a table in a Restaurant}

\begin{itemize}
	\item Description: Insert a reservation.
	\item Frequency: \(105\,000\) per week.
\end{itemize}

\subsubsection{Check available seats in a Restaurant}

\begin{itemize}
	\item Description: Find the number of seats available in a restaurant.
	\item Frequency: \(210\,000\) per week (considering that a customer will perform on average 3 reservation per week, may happen that some restaurant are full or a customer just want to know if there are seats available, so there will be slightly more check then reservations).
\end{itemize}

\subsubsection{Delete a Reservation}

\begin{itemize}
	\item Description: Remove a reservation from the database.
	\item Frequency: \(525\) per week (0,5\% of weekly reservations).
\end{itemize}

\subsubsection{Add a Restaurant}

\begin{itemize}
	\item Description: Add a restaurant in the system.
	\item Frequency: \(3\) per week.
\end{itemize}

\subsection{Analysis Results}

The most important thing that we can see from these analysis is that the
database is used mostly for read operations. The prominent operations are:

\begin{itemize}
	\item List of Restaurant (175\,000 access/week)
	\item List of Reservation per User (175\,000 access/week)
	\item List of Reservation per Restaurant (140\,000 access/week)
	\item Check available seats in a Restaurant (210\,000 access/week)
\end{itemize}

Starting from this situation we must consider the complexity in terms of join
operations that must be performed for each operation.

\subsubsection{List of Restaurants}

Read all the instances in restaurants. It is not necessary any join operation.

\subsubsection{List of Reservation per User}

In this operation we need a join between Restaurant and Reservation tables.  We
need the name of each Restaurant where the User with given userID have a
Reservation.

\subsubsection{List of Reservation per Restaurant}

In this operation we need a join between User and Reservation tables.  We need
the name of each user that have a Reservation in the Restaurant with given
restaurantID.

\subsubsection{Check available seats in a Restaurant}

In this operation we need a join between Restaurant and Reservation table. We
need the number of remaining seats in a given restaurant for the given date and
hour.
\vspace{0.75cm}
The first operation, even if it's a frequently used read operation, it doesn't
require any join.  Instead, the last three operations are frequently
used read operations that need a join. They are the ones that most will achieve
advantages in terms of performances using a Key-Value Database among the above
listed ones. In particular, the key-value database will be used as a cache of
the relational database for the aforementioned read operations.

\subsection{Data Model Translation}

In this step we have to create a key value data model that fits our needs.  In
other words we need a key-value data model that can be derived from the join of
three tables involved in the previously mentioned operations.

Starting from the ER model in Figure~\ref{fig:er} we can translate our join
table as follow:

\vspace{0.75cm}

\centerline{\textbf{reservations:<userId>:<restaurantId>:<date>:<time>:<attribute name>=value}}

\vspace{0.75cm}

Attribute name can be:
\begin{itemize}
	\item id
	\item seats
	\item user\_username
	\item restaurant\_name
\end{itemize}

\vspace{0.75cm}
The introduction of the fields <date> and <time> in the key give us an advantage
when we need to check for available seats. In fact when we need this operation
we just have to iterate on the reservations with given date and time without the
need to check for that.

\vfill