\section{Introduction}
\label{sec:background}

%In this chapter we provide background for the 802.11 wireless communications standard, including its 802.11af \ac{TVWS} extensions, with a focus on \ac{MU-MIMO} transmission techniques in 802.11ac/ax and key performance factors for general \ac{MU-MIMO}.
In this chapter we provide background for wireless communications systems with a focus on \ac{MU-MIMO} transmission techniques such as those used in \ac{IEEE} 802.11ac/ax and key performance factors for \ac{MU-MIMO}.

We will also review software-defined radios and their implementation in order to provide context for the innovative \ac{SDR} system design in this thesis.

	%#######################################################
	%\section{Wi-Fi: the IEEE 802.11 Standard}
	%\label{sec:back_80211}
%
%\iftoggle{isready} {
%
	%As the second widespread use of spectrum sharing,\footnote{The IEEE 802.11a standard includes \ac{DFS} sensing and protection of radar signals between [5.260, 5.700]~GHz.}
%
	%\rgnote{Basic background about 802.11, random access, frame structure, terminology. 802.11ac extension for MU-MIMO. This is where \ac{STA} and \ac{AP} get defined}
%
	%%#######################################################
	%\subsection{IEEE 802.11af Standard Extension for TVWS}
	%\label{sec:back_80211af}
%
	%\rgnote{Motivation and constraints of 802.11af, pulling from my IEEE article content. Database vs. sensing approaches--we focus on database-driven approaches.}
%
	%Wifi over TVWS: \cite{bahl2009white}
%
%}{ \rgnote{The WiFi background section is pending.}}

%#######################################################
\section{Multi-user Beamforming}
\label{sec_mubf_back}
	Multi-user beamforming is a multi-antenna transmission technique that allows a transmitter to spatially reuse a wireless channel by transmitting multiple concurrent data streams on the same radio frequency using linear pre-coding.
	This is achieved in two steps: first, the wireless channel is estimated and represented as a complex matrix $\mathbf{H}_c\in \mathbb{C}^{M\times K}$ representing the narrowband scalar channel weights for each path between $M$ transmit antennas and $K$ receive antennas for each of $C$ narrowband subcarriers within the wideband.
	Shown in Figure~\ref{fig_h_matrix}, this wireless channel representation is called the \ac{OFDM} wideband channel representation since it treats each subcarrier independently and is used for \ac{OFDM} transmission techniques \cite{perahia2008}.
	An underlying assumption for this channel model is that the bandwidth of the subcarriers is chosen such that a complex scalar coefficient, $h_{mkc}$, is sufficient to accurately represent the magnitude and phase of the channel state of subcarrier $c$.
	For the remainder of this thesis, we will forgo the subscript $c$ when discussing the wireless $\mathbf{H}$ matrix channel representation.

	\begin{figure}[h]
\centering
  \includegraphics[width=4.5in]{figs/general/beamforming_h_matrix}
    \caption{H-matrix representation of the physical wireless channel.}
\label{fig_h_matrix}
\end{figure}

	The second step for multi-user beamforming is the application of downlink beam-steering weights.
	Each data stream for each of $K$ receive antennas, $\mathbf{S}\in \mathbb{C}^{K\times 1}$, is left-multiplied by a matrix of complex steering weights $\mathbf{W}\in \mathbb{C}^{M\times K}$  resulting in $\mathbf{X} = \mathbf{W}\cdot \mathbf{S} \in\mathbb{C}^{1\times M}$ pre-coded signals containing a linear combination of each data stream to transmit from each of the \ac{AP}'s $M$ antennas.

	The $K$ antennas may each be on a single separate \ac{STA} or may be in any combination where a subset of $K$ is on a single receiver \ac{STA}.
	When all $K$ are on a single \ac{STA} this reduces to a simple single-user \ac{MIMO} transmission.
	The key distinction is that \acp{STA} are independent receivers in \ac{MU-MIMO} transmissions and do not share receive information between each other.

%#######################################################
\subsection{Pre-coding Weight Selection}
	The linear pre-coding weights $\textbf{W}$, also called ``beam-steering weights,'' are chosen such that the interference between the parallel streams is minimal.
	To compute these weights, the transmitter must first measure the channel state matrix $\textbf{H}$.
	The optimal method of constructing the steering matrix is \acf{DPC} \cite{costa1983dpc}; however, its computational complexity makes it impractical to implement in full.

	Instead, a practical method for calculating $\mathbf{W}$ from $\mathbf{H}$ that approaches optimal performance is \ac{ZFBF}\cite{goldsmith2006zf}.
 Zero-forcing drives interference between spatial streams to zero, and can be inefficient when users' \ac{CSI} is not sufficiently orthogonal \cite{aryafar2010design} or in low \ac{SNR} environments.
 \ac{ZFBF} requires calculation of the $\mathbf{H}$ matrix's Moore-Penrose pseudo-inverse:
\begin{equation}
\mathbf{W} = \mathbf{H}^\dagger =  (\mathbf{H}^\textsc{H} \mathbf{H})^{-1} \mathbf{H}^\textsc{H}, \label{eq:zf}
\end{equation}
where $(\cdot)^\textsc{H}$ represents the matrix conjugate transpose and $(\cdot)^\dagger$ is the Moore-Penrose pseudo-inverse.
%When the transmitter precodes with perfect \ac{ZFBF} weights, $\mathbf{W}$, signals ideally cancel the effects of the wireless channel at the receiver, allowing each user to receive their own, independent streams.

	A key element of \ac{ZFBF} is the zero-interference condition which is a direct result of the pseudo-inverse.
	Because $\textbf{W}=\textbf{H}^\dagger$, then $\textbf{H}\cdot\textbf{W}$ is the identity matrix, meaning that the interference from the data stream from user $k=i$ on the data stream for user $k=j$ is nulled and vice versa.
	\ac{ZFBF} pre-codes the transmitted data streams such that the combined wireless channel between the transmitter and the receivers is separated.
	If \ac{ZFBF} works perfectly, we can express the pre-coded transmission $\mathbf{X}$ as:
\begin{align}
\mathbf{X} = \mathbf{W} \cdot \mathbf{S} \xrightarrow[\mathbf{H}]{\text{Transmit}} & \mathbf{H}\cdot (\mathbf{W} \cdot \mathbf{S}) \notag \\
 = & \cancel{\mathbf{H}} \cdot (\cancel{\mathbf{W}} \cdot \mathbf{S}) = \mathbf{S}
\end{align}

	There are additional ways to calculate the pre-coding weights for digital beamforming systems; two of the most notable alternatives are conjugate beamforming \cite{yang2013performance} and \ac{MMSE} beamforming \cite{joham2005linear}, both of which are optimal under certain conditions.
	In our work, due to the computational complexity of \ac{MMSE} beamforming implementation, we focus on the zero-forcing beamforming technique for \ac{MU-MIMO}, though most of the insights and systems could be easily applied to alternative types of beamforming.

%#######################################################
\subsection{MIMO Channel Correlation and Temporal Correlation Function}
%\rgnote{Beamforming Performance Limits Clean this notation and discusion up}
	The key to the success of the precoding operation is that $\textbf{H}\cdot \textbf{W}$ is designed to reduce to the identity matrix so the transmitted streams are received separately at each receiver.
	We are generally interested in two characteristics of $\textbf{H}$ that can degrade the performance of this precoding operation: an ill-conditioned $\textbf{H}$ \cite{zhong2011distribution} or an out-dated $\textbf{H}$ \cite{kaltenberger2008correlation}, each related to different statistical correlation concepts.

\textbf{MIMO Channel Correlation.}
	An ill-conditioned $\textbf{H}$ matrix renders matrix inversion inaccurate \cite{greenbaum2012numerical, peel2005vector} which is required to calculate the pseudo-inverse in Equation~\ref{eq:zf}.
	This results in $\textbf{H}\cdot \textbf{W}$ becoming far less likely to equal $\textbf{I}$ and causes ``inter-stream interference'' as a result of beamformed data streams interfering and degrading the received signal strength of a data stream to its intended receiver \cite{kaltenberger2008correlation}.
	Ill-conditioned $\textbf{H}$ matrices can be a result of \ac{MIMO} channel correlation, a characteristic of the physical arrangement of the \ac{MIMO} antenna array or the wireless environment that measures how similar the independent paths between \ac{MIMO} antennas are to each other by relating their individual path random processes \cite{loyka2001channel}.
	With sufficiently high \ac{MIMO} channel correlation, any particular realization of the matrix channel random process is likely to not be full-rank, which makes it non-invertible or singular \cite{peel2005vector}.
	Increasing channel correlation in general results in a decrease in \ac{SNR} for a \ac{MIMO} system \cite{loyka2001channel}, and can be interpreted as a lack of physically independent information channels in the environment or radio array available to convey information.

\textbf{Channel Correlation Function.}
	Channel correlation is a property of the wireless \ac{MIMO} channel matrix $\textbf{H}$ and is not to be confused with the channel \emph{temporal correlation} function, which is a property of the individual channel random process $h_{mk}$ and indicates how correlated the channel condition is as a function of time.
	Temporal correlation is the expected autocorrelation between channel snapshots at varying intervals of time calculated as described in \cite{wallace2003experimental}.
	An intrinsic property of the channel random process, an empirical temporal correlation function can be estimated from time series of channel state observations.
	The empirical correlation coefficient for a single channel $\rho$ at time interval $\ell$ is defined as:
\begin{align}
\rho_\ell = \frac{\mathbb{E}\big[h_{m}[k]h^{*}_{mn}[k+\ell]\big]}{\mathbb{E}\big[h_{mn}[k]h^{*}_{mn}[k]\big]}
\label{eq_corr_coeff}
\end{align}
where the expectation is calculated for all combinations of transmit antenna $m$, receive antenna $n$ and starting time sample $k$.
 %Assuming each channel path is generated by the same random process, the resulting empirical correlation functions for each \ac{MIMO} channel path can be averaged together for an overall estimate of channel temporal performance.

	Out-dated $\textbf{H}$ matrices are a direct result of the latency between the measurement of the $\textbf{H}$ matrix and the transmission of the $\textbf{W}$ precoded data streams.
	Increased time between the measurement of $\textbf{H}$ and the transmission of $\textbf{W}\cdot \textbf{S}$, results in a higher probability of incorrect transmit precoding.
	Essentially, the transmitter measures $\textbf{H}_{t}$ and then calculates $\textbf{W}_t = \textbf{H}_t^\dagger$.
However, the subsequent precoded transmission is $\textbf{H}_{t+\Delta}\cdot \textbf{W}_{t}$, which may not equal $\textbf{I}$ since the channel has changed since estimation at time $t$.
	The temporal correlation function is a way of estimating how much the channel will change over time.
	Whether or not $\textbf{H}_{t}=\textbf{H}_{t+\Delta}$ is based on environmental variability and user mobility; and, like channel conditioning, is also an environment and frequency dependent characteristic.

	While a large number of studies have characterized the indoor and outdoor propagation environment for the purpose of network planning and algorithm design, few are applicable to evaluating \ac{MU-MIMO} performance and most have focused on a single frequency band \cite{boyer2007mimo, hammons2008cooperative, jung2011multipath}.
	This makes measurement studies of different frequencies and radio technologies difficult to compare.

At the same time, the implementation complexity and computation required for real-time implementation of multi-carrier \ac{MU-MIMO} has traditionally been prohibitive for software-defined radio platforms \cite{aryafar2010design}, thus providing a challenge to empirical measurement of \ac{MU-MIMO} performance.

%\subsection{Systemic CSI Estimation Error}
%\label{sec_systemic_csi_error}
%
%\rgnote{review this section--I wanted to include it because I constantly have to explain this and it's not immediately clear until you actually prove it with math. This might get cut.}
%
%Recall that given a channel estimate, $\Hb$, the precoding weights for the zero-forcing transmitter are $\mathbf{W} = \mathbf{H}^\dagger =  (\mathbf{H}^\textsc{H} \mathbf{H})^{-1} \mathbf{H}^\textsc{H}$.
	%Arbitrary magnitude and phase offsets may be present in any one estimate of the \ac{CSI} due to receive gain control or timing estimation jitter, respectively.
	%These are normal effects in \ac{OFDM} transceivers that are compensated by the receive \ac{OFDM} channel equalization, yet become part of the channel estimation at the receiver \cite{park2003timing, breit2009coherencetime}.
	%While not a new finding, it is useful to discuss the effect that these types of systemic \ac{CSI} estimation error components and how they differ from estimation error due to stale \ac{CSI}.
	%
	%We define a systemic \ac{CSI} estimation error as any error matrix $\Phi \in \mathbb{C}^{M\times K}$ that can be represented as a diagonal matrix: $\Phi = diag(\alpha_1,\ldots,\alpha_M)$.
%
	%It is a well-known property of beamforming that the input \ac{CSI}, $\Hb$, can be perturbed by an arbitrary diagonal matrix $\Phi = diag(\alpha_1,\ldots,\alpha_M)$ such that the \ac{CSI} used for precoding is $\hat{\Hb} = \Hb\Phi$.
	%The resulting original beamformed streams, $\mathbf{Y} = \mathbf{W}\Hb$, and the received perturbed beamformed streams, $\mathbf{Y'} = \hat{\Hb}^\dagger\Hb$, still preserve the orthogonal separation of the user streams owing to the diagonality of $\Phi$.
	%In other words, $\mathbf{Y'} = (\Phi)^{-1}\mathbf{Y}$, and beamforming performance is not significantly impacted by such measurement artifacts.
%
	%This is a powerful result \rgnote{finish this section when I'm less tired}

%#######################################################
%\section{Many-Antenna and Massive MIMO}
%\label{sec_mami_back}
%
%\iftoggle{isready} {
%
%
%}{ \rgnote{The Massive MIMO background section is pending.}}

%#######################################################
\section{Software Defined Radio Architecture}
\label{sec_sdr_back}

A \acf{SDR} is a radio that replaces analog signal processing components with programmable digital logic.
This radio architecture increases flexibility by replacing analog signal processing components with digital logic, enabling the use of more flexible and complex waveforms such as \ac{OFDM} and simplifying cross-layer system design.

\begin{figure}[ht] % Idealized AGC block diagram
\centering
\includegraphics[width=1\linewidth]{./figs/agc/generic_sdr}
\caption{Block diagram of a generalized Software-Defined Radio system.}
\label{fig_sdr_ideal}
\end{figure}

We present a generalized block diagram model of a single-radio \ac{SDR} in Figure~\ref{fig_sdr_ideal}.
While implementations of \acp{SDR} vary, our model captures key components (from left to right) considered in this work and generalizes well to most commercial \ac{SDR} architectures:
\begin{itemize}
	\item \textbf{Network stack} - signal processing components with non time-critical functions; for example: user scheduling, priority queuing, or layer-2 routing.
	\item \textbf{Programmable logic} - signal processing components with time-critical or hardware-accelerated functions, specifically for networks layers 1 and 2; for example: gain control, digital pre-distortion, forward error correction.
	\item \textbf{Analog/Digital interface} - \acp{ADC} and \acp{DAC} provide the interface between digital and analog domains by converting digital samples to analog voltages and vice-versa.
	\item \textbf{Analog Gain Block (1)} - controls the amplitude of the signal entering or leaving the ADC/DAC.
	\item \textbf{Anti-aliasing filter (2)} - provides a low-pass filtering function on the analog signal to limit its information bandwidth to below the Nyquist sampling rate of the digital conversion step in order to avoid aliasing.
	\item \textbf{Analog Gain Block (3)} - controls the amplitude of the signal entering or leaving the analog mixer.
	\item \textbf{Frequency Up/Downconversion Mixing (4)} - a local center frequency, or \textit{carrier}, is multiplied by the analog signal to either up-convert or down-convert the signal to/from the RF frequency.
	\item \textbf{RF Gain Block (5)} - the input and output RF signal is amplified in order to meet the linearity or power budget requirements of the system's components.
	\item \textbf{Receive Band-Pass Filter (6)} - a band-pass filter limits the frequency content of the signal input to the receive radio chain in order to limit noise ingress and harmonic interference from strong out-of-band signals.
	\item \textbf{Transmit/Receive Switch (7)} - shares a signal antenna with the transmit and receive circuits; while this work generally considers \ac{TDD} protocols, this system component can be replaced with a frequency duplexer to support \ac{FDD} protocols, as well.
\end{itemize}

	This is by no means an exhaustive enumeration of the signal conditioning components present in all \ac{SDR} systems, but captures the important features needed for the techniques and systems in this work while being generic enough to apply across a wide range of commercial \ac{SDR} platforms.

	In addition, the division of functions between ``programmable logic'' and ``network stack'' blocks is a soft delineation made for ease of discussion.
	For the purpose of this work, we consider programmable logic to be an \ac{FPGA} or similar digital logic, whereas the network stack is implemented in embedded C or higher layer computer languages on a general-purpose processor.
	This division matches well-known experimental \ac{SDR} platforms like those mentioned in Section~\ref{sec_related_sdr}.

\subsection{Direct Sampling RF}
	As digital circuit integration and speed increases, a new \ac{SDR} paradigm is emerging in recent years that further reduces the amount of analog components necessary, shifting the dividing line between digital and analog domains in Figure~\ref{fig_sdr_ideal} nearly all the way to the antenna.
	``Direct sampling RF'' systems first used a combination of filtering and aliased sampling to directly sample RF signals without a down-conversion mixing step \cite{psiaki2005design}.
	More recently, increases in the integration and speed of digital circuits now permit direct sampling \acp{ADC} at RF frequencies without the drawback of aliased sampling \cite{xilinx2017rfsoc}.
	Although widespread use of direct sampling architectures will obviate the need for some of the analog components discussed in this thesis, key contributions of \ac{AGC}, environmental \ac{MU-MIMO} studies, and our protocol design remain unchanged.

%#######################################################
\section{Two Port Scattering Parameters}
\label{sec_scattering}

	In order to present some of our circuit design techniques, it will be necessary to be familiar with the definition and notation of normalized scattering, or S-parameters.
	The following discussion is a summary of the discussion and derivation by Yarman \cite{yarman2010design} and Orfanidis \cite{orfanidis2002electromagnetic} to describe a lossless two-port device.

\begin{figure}[h]
\centering
  \includegraphics[width=0.4\linewidth]{figs/matching/general_2_port}
    \caption{General diagram of a lossless linear 2-port device with scattering parameters.}
\label{fig_general_2_port}
\end{figure}

	Consider Figure~\ref{fig_general_2_port}, a linear two-port microwave device that is excited by a complex source or ``generator'' impedance $Z_G$ and terminated in a complex load impedance $Z_L$.
	Assuming it it lossless, it is possible to describe the two-port system by describing the relationship of any incident and reflected voltage wave characterized by the wave variables $a_i, b_i$, where the current is defined in the direction of the corresponding $a_i$ vector and the characteristic reference impedance of the system is $Z_0$.
\begin{align}
a_1 &= \frac{V_1+Z_0 I_1}{2\sqrt{Z_0}}  &a_2 = \frac{V_2+Z_0 I_2}{2\sqrt{Z_0}} \\
b_1 &= \frac{V_1-Z_0 I_1}{2\sqrt{Z_0}}  &b_2 = \frac{V_2-Z_0 I_2}{2\sqrt{Z_0}}
\end{align}
This results in a relationship between incident and reflected traveling waves:
\begin{align}
	b_1 &= S_{11}a_1 + S_{12}a_2 \\
	b_2 &= S_{21}a_1 + S_{22}a_2.
\end{align}
	The system of traveling wave equations forms a scattering matrix, $\mathbf{S}\in\mathbb{C}^{2\times2}$ for a two-port device, $\mathbf{S}\in\mathbb{C}^{4\times4}$ for a four-port device, etc, that completely characterizes the device's linear, lossless behavior.

	There are two important assumptions related to the use of S-parameters; the first is that each set of empirical S-parameter is measured within a system with arbitrary characteristic impedance $Z_0$.
	As a matter of convention, nearly all S-parameters are measured in reference to 50~$\Omega$ and we will assume that in the rest of this thesis.

	Second, S-parameters only capture \emph{linear} steady-state device behavior, and for this reason they are generally described as ``small-signal'' parameters. For example, as the input signal power to a two-port amplifier is increased close to the IP1dB point, or the point where the amplifier becomes saturated and the output power decreases by 1~dB from ideal, non-linear behavior will be observed, requiring ``large-signal'' design techniques like load-pull analysis.
	Quaglia and Cripps present an excellent discussion of recent developments and models for power amplifiers operating in the saturated regime \cite{quaglia2017reappraisal}.
	We instead focus on linear operating conditions and small-signal designs for our system in order to preserve the simplicity of each radio chain within a complex many-antenna system, leaving energy efficiency optimization to future work.

For the system in Figure~\ref{fig_general_2_port}, it is also useful to define generator and load \emph{reflection coefficients} that describe the portion of a reflected incident wave with characteristic reference impedance $Z_0$ into a load.
\begin{equation}
\Gamma_G = \frac{Z_G - Z_0}{Z_G + Z_0},~~~ \Gamma_L = \frac{Z_L - Z_0}{Z_L + Z_0}
\end{equation}

	In this work, we will use the $\hat{(\cdot)}$ notation to indicate a reflection coefficient that is cascaded into a non-reference impedance.
	For example, $\hat{S}_{11}$ in Figure~\ref{fig_general_2_port} is the reflection coefficient of the active two-port terminated in an arbitrary load impedance $Z_L$ and can be written:
\begin{equation} \label{eq_}
\hat{S}_{11}=S_{11}+\frac{S_{12}S_{21}\Gamma_L}{1-S_{22}\Gamma_L},
\end{equation}
where in the case of $Z_L = Z_0 = 50~\Omega$, we see that this reduces to $\hat{S}_{11} = S_{11}$.
	Similarly, we can see that:
\begin{equation}
\hat{S}_{22}=S_{22}+\frac{S_{21}S_{12}\Gamma_G}{1-S_{11}\Gamma_G}.
\end{equation}

	We now have the tools needed to address the broadband power transfer network design problems presented in Section~\ref{sec_wurc_pa_design}.


\section{Methodology} \label{method}
% what is TIMES
\subsection{TIMES Model Description}
\gls{TIMES} models dynamic energy systems and simulates transition scenarios as a mixed-integer linear optimisation problem that is subject to a primary objective function and additional constraints \cite{loulou_etsap-tiam_2008}. The generation, refinement, supply, storage, and trade of energy commodities are modelled across multiple sectors and multiple regions using a wide variety of in-built commodity and process types. Emissions can be associated with energy commodities or processes as an emission coefficient per unit commodity produced or consumed.

%basic features of model
We outline salient features of our model in this section, while the data used for our simulations are in \ref{Appendix}. The relevant input files can be accessed online \cite{chaube_arfci2cner_2021}. The objective function in our single-region model is the overall cost of the transition. The major constraints in our simulations are the demand for electricity (Table \ref{demand}), emission constraints on the electricity-generation sector based on Japan's \gls{INDC} (Table \ref{co2-limits}), and feasible nameplate capacity deployment limits (Table \ref{caplim}). Miscellaneous assumptions are summarised in Table \ref{misc-assump}. In summary, our model minimises the transition cost while meeting the increasing electricity demand and achieving the required emission cuts using a combination of generation and storage technologies.

\begin{table}[H]
\centering
	\caption{Electricity demand increase over the simulation time frame.}
	\vspace{0.1in}
	\begin{tabularx}{0.4\textwidth}{p{0.15\textwidth} p{0.25\textwidth}}
		\hline
\textbf{Year} & \textbf{Annual demand} \\
 & \textbf{increase} \\
\hline
2017-2030 & 1.7 \% \cite{noauthor_electricity_2019} \\
2031-2050 & 1.0 \% \\
2051-2070 & 0.5 \% \\
2070-2100 & 0.0 \% \\
\hline
	\end{tabularx}
\label{demand}
\end{table}

\begin{table}[H]
\centering
	\caption{Emission constraints.}
	\vspace{0.1in}
	\begin{tabularx}{0.6\textwidth}{p{0.05\textwidth} p{0.2\textwidth}p{0.05\textwidth} p{0.3\textwidth}}
		\hline
\textbf{Year} & \textbf{Emission limit} & \textbf{Base} & \textbf{Reduction} \\
 & & \textbf{year} & \textbf{from base year} \\
\hline
2030 & 438 Mt CO$_2$-eq. & 2013 & 26 \% \\
2050 & 75 Mt CO$_2$-eq. & 1990 & 80 \% \\
2100 & 75 Mt CO$_2$-eq. & 2050 & 0 \% \\
\hline
	\end{tabularx}
\label{co2-limits}
\end{table}

While Japanese electricity demand is expected to grow in the near future  \cite{noauthor_electricity_2019}, long-term electricity demand in Japan is expected to plateau, or even decrease, due to Japan's ageing population. However, precisely quantifying this rate of decrease is challenging, as this reduction in population will likely be accompanied by increased electrification of transportation and industrial sectors. Hence, post-2030, we have assumed a demand curve based on increased electrification driving increasing demand, which eventually plateaus due to the aforementioned expected demographic changes. The model captures the initial condition of the post-Fukushima Japanese electricity supply system using The Energy Data and Modelling Centre's data from 2013-2016 \cite{the_institute_of_energy_economics_japan_energy_2018}. Long term impacts of factors such as the retirement of the existing nuclear reactor fleet and the deployment of emerging technology is assessed by simulating the system until 2100. We account for the carbon cost of each technology using an emission coefficient that incorporates both direct emissions and life cycle emissions averaged over the entire operating lifetime for each technology. Using \gls{TIMES} day-night and seasonal time periods \cite{loulou_etsap-tiam_2008}, the daily and seasonal variability of renewables is incorporated. The availability of renewables varies during these time periods based on the annually averaged capacity factors of renewables in Japan \cite{the_institute_of_energy_economics_japan_energy_2018, irena_renewable_2020}.

%scenario description
To explore possible pathways to curbing \gls{GHG} emissions, we simulated five transition scenarios of varying likelihoods, with different sets of technologies enabled for deployment, as described in Table \ref{scen-table}. The first set includes conventional technologies such as  \gls{USC}, \gls{lng}, solar photovoltaic, wind energy (with onshore, offshore-fixed, and offshore-floating considered separately), and utility-scale lithium-ion battery storage. New deployments of oil-fuelled power plants are disabled due to the declining use of oil for electricity generation in accordance with Japan's goal of energy security and independence, as per the Basic Energy Plan. The second set of technologies considered includes emerging carbon-neutral technologies that are already commercialised or close to commercialisation, namely emerging solar photovoltaic (modelled as a composite of perovskites and CdTe solar cells), \gls{CCS}, and utility-scale hydrogen power. For hydrogen power, steam reforming, steam reforming with \gls{CCS}, \glspl{AEC}, \glspl{PEMEC}, \glspl{PEMFC}, and \glspl{SOFC} were incoporated based on their technological potential. Along with these two technology groups, we also explore the potential impact of nuclear energy. Nuclear power has significant advantages over renewables including long operational lifetimes, extremely low life-cycle emissions, and high capacity factors. However, nuclear power faces extremely low public acceptance in Japan after the Fukushima-Daiichi accident, therefore its future in Japan is highly uncertain. Hence, transition scenarios with and without new nuclear reactor deployment must be juxtaposed to assess the importance of the role of nuclear in emission reduction. Finally, the long-term impact of nascent hydrogen technologies on the hydrogen economy is assessed in an additional scenario. In this scenario, the potential commercialisation of \gls{SOEC} and \gls{PWS} post-2050 is explored in the absence of new nuclear power.

\begin{table}[H]
\centering
	\caption{Electricity supply transition scenario definition based on enabled technologies.}
	\vspace{0.1in}
	\begin{tabularx}{0.65\textwidth}{p{0.1\textwidth} p{0.18\textwidth} p{0.15\textwidth} p{0.18\textwidth}}
\hline
\textbf{Scenario}& \textbf{Emerging} & \textbf{New} & \textbf{Nascent}\\
 & \textbf{tech.} & \textbf{nuclear} & \textbf{tech.}\\

%                 & \textbf{enabled} & \textbf{enabled} & \textbf{enabled}\\
                  \hline
%1               &   \xmark       &      \xmark     &   \xmark     \\
%2               &   \xmark       &      \greencheck     &   \xmark     \\
%3               &   \greencheck       &      \xmark     &   \xmark     \\
%4               &   \greencheck       &      \greencheck     &   \xmark     \\
%5               &   \greencheck       &      \xmark     &   \greencheck     \\
1               &  No       &         No     &     No  \\
2               &   No       &      Yes     &     No  \\
3               &   Yes     &         No      &     No   \\
4               &   Yes     &      Yes     &     No  \\
5               &   Yes     &      No     &     Yes  \\
\hline
	\end{tabularx}
\label{scen-table}
\end{table}

%misc assumptions
Exogenous variables such as economic data, emission coefficients, nameplate capacity limits, and growth rates are detailed in Tables \ref{eco}, \ref{caplim}, and \ref{growrate} respectively. Prices and projections for fossil fuels and nuclear fuel are incorporated \cite{wittenstein_projected_2015, world_bank_commodity_2016, international_energy_agency_world_2019}. Learning curves for costs and life-cycle emissions are compiled from existing data (Table \ref{eco}) based on expected scaling of manufacturing, availability of manufacturing materials, and the use of clean energy for manufacturing energy system components. These learning curves are modelled as piecewise linear functions interpolated between the available data points, with the curve plateauing at the latest value for a given parameter, as detailed in Table \ref{eco}. Capacity limits of renewables and \gls{PWS} are based on their land-use requirements. The maximum annual capacity growth rates for existing technologies are held constant. The growth rate of nuclear power is based on historic trends and current pressure vessel manufacturing limitations \cite{iaea_pris_nodate}. The reactor size assumed in this study is 1165 MWe, based on Watts-Bar Unit 2 \cite{iaea_pris_nodate-1}. Due to a projected increase in the share of renewables, nuclear power plants must be able to load-follow to a certain extent, which is approximated in our model based on French reactors' range of capacity factors. The growth rates of all emerging technologies are modelled on the rates observed for solar photovoltaic technology, with rapid initial growth followed by gradual reduction, eventually reaching a moderate maximum attainable growth rate. One notable exception is the maximum growth rate of emerging solar technologies, which we have assumed to be the same as that of existing solar photovoltaic technologies. We assume that these technologies, some of which are already commercialised or close to commercialisation, will benefit immensely from the already streamlined solar photovoltaic manufacturing and supply chain. Therefore, they could be deployed as rapidly as conventional solar photovoltaic cells.

All hydrogen storage devices are operated with a maximum availability factor of 90\%, making them extremely flexible for load-following. Long-term storage of hydrogen is also available using hydrogen tanks with appropriate loss factors \cite{iea_technology_2015}. For hydrogen electrolysers and fuel cells, life-cycle emissions from just the stack are considered, as balance-of-plant emissions from utility scale hydrogen depend strongly on the type of plant and the source of energy used for electrolysis. Our assumptions about the reduction in the investment costs and life-cycle emissions of batteries are conservative due to the rising cost of cobalt and nickel, and lithium-ion battery manufacturing being concentrated in high \gls{GHG}-emitting nations, respectively \cite{oliveira_environmental_2015,emilsson_lithium-ion_2019,turcheniuk_ten_2018,simon_potential_2015}.

\subsection{Sensitivity analysis}
%approach, goal, what are we hoping to learn
%variables, sampling approach, median, range, which variables, which base case scenario, why
While the aforementioned scenarios identify potential pathways that are likely to result in deep emission cuts, many parameters, such as the investment cost, life cycle emissions, and lifetimes, are highly uncertain for novel technologies like \gls{CCS} and hydrogen generation and conversion technologies. Therefore, our sensitivity analysis is focused on investigating the impact of such parameters (Table \ref{sa-vars}). We analyse the sensitivity of the share of each of these technologies in the electricity-generation mix and of the system transition cost with respect to these variables.

\begin{table}[H]
\centering
	\caption{Candidate parameters and their variation in our sensitivity analysis.}
	\vspace{0.1in}
	\begin{tabularx}{0.9\textwidth}{p{0.3\textwidth} p{0.15\textwidth} p{0.15\textwidth}p{0.3\textwidth}}
\hline
\textbf{Technology}  & \textbf{Sampled} & \textbf{Distribution}& \textbf{Distribution}\\
\textbf{Parameter} & \textbf{Distribution} & \textbf{Mean}& \textbf{Range}\\
\hline
\gls{PWS} Investment Cost       & Gaussian    & 3088 \$/kW & $\pm$20\%. \\
\gls{SOEC} Investment Cost      & Gaussian    & 1388 \$/kW & $\pm$20\%.\\
\gls{PEMEC} Investment Cost     & Gaussian    & 3800 \$/kW & $\pm$20\%.\\
\gls{SOFC} Investment Cost      & Gaussian    & 7399 \$/kW & $\pm$20\%.\\
\gls{PEMFC} Investment Cost     & Gaussian    & 7399 \$/kW & $\pm$20\%.\\
\gls{CCS} Gas Investment Cost   & Gaussian    & 2626 \$/kW & $\pm$20\%.\\
\gls{CCS} Coal Investment Cost  & Gaussian    & 5252 \$/kW & $\pm$20\%.\\
\gls{PWS} Emission Coefficient  & Triangular  & 1.08 g/kWh & 0.2-5.405 g/kWh. \\
\gls{SOEC} Emission Coefficient & Triangular  & 1.08 g/kWh & 0.2-5.405 g/kWh. \\
\gls{PWS} Efficiency            & Triangular  & 0.525 & 0.5-0.58. \\
\hline
	\end{tabularx}
\label{sa-vars}
\end{table}

While there is significant uncertainty in the investment cost of nuclear power plants \cite{lovering_historical_2016}, it varies for individual plants and not for the technology as a whole. Preliminary simulations also demonstrated that nuclear power dominates the energy mix, and its share is fairly insensitive to perturbations over known ranges of investment costs \cite{lovering_historical_2016} due to its low life cycle emissions. Consequently, we eliminated nuclear power's investment cost as a candidate for sensitivity analysis. Furthermore, Japan has been exploring low-emission alternatives to nuclear since the Fukushima Daiichi disaster. In order to assess these potential alternatives which would otherwise be eliminated from the energy mix if new nuclear reactors were deployed, we chose Scenario 5 (Table \ref{scen-table}) as our base scenario for sensitivity analysis. Ten model parameters were sampled 30 times from appropriate distributions (Table \ref{sa-vars}). The parameter value at the first year of deployment (Table \ref{eco}) was varied, but the parameter's learning curve was held constant throughout all scenarios. For example, a 20\% change in the deployment year (2030) investment cost of \gls{SOFC}s with respect to the base case scenario reduces their investment cost in 2050 by 20\% as well. This makes learning-based cost-reductions proportionate across all sensitivity analysis runs. These parameters were randomly co-varied in 30 simulations. The share of each electricity generation technology (as the ratio of cumulative technology output to the cumulative electricity demand) and output of hydrogen technologies was plotted versus each varying parameter to correlate the effect of these parameters with the penetration of these technologies into the mix. A similar approach was also used to correlate these parameters with the system's transition cost.


\documentclass[11pt]{article}
% \textwidth=6in
% \textheight=9in
% \oddsidemargin=0.25in
% \evensidemargin=0.25in
% \marginparwidth=0in
% \marginparsep=0in
% \topmargin=0in
% \headheight=0in
% \headsep=0in
% \topskip=0in
\usepackage{amssymb}
\usepackage{hyperref}
\usepackage{lscape}
\usepackage{longtable}
\usepackage{graphics}
\usepackage[pdftex]{graphicx}
\usepackage{color}
\usepackage{rotating}
\newcommand{\hilight}[1]{\colorbox{yellow}{#1}}

\newenvironment{packed_itemize}{
\begin{itemize}
  \setlength{\itemsep}{1pt}
  \setlength{\parskip}{0pt}
  \setlength{\parsep}{0pt}
}{\end{itemize}}

\title{Options for a consistent GraphBLAS notation}
\author{Tim Davis, Gabor Szarnyas}
\date{\today}
\begin{document}

\maketitle

\section{Creating matrices}

\begin{itemize}
\item[] in the C API: \verb'GrB_Matrix_new (&A, m, n, GrB_INT64)'
\item[] in ASCII: \verb'A = int16(m,n)' (I'm open to suggestions for this)
\item[] in LaTeX: $\mbox{let: } {\bf A} \in \mathbb{Z}^{m \times n}_{16}$
\end{itemize}

\section{Mask computation}

In the following table the ``mask'' column is the value of the
mask after applying the value/structural option and optionally
complementing the mask.  If no mask is present (and not complemented)
then mask is 1.  If no mask is present (yet complemented) then the mask is
always 0; this has no effect unless the Replace option is also used.

The repl column in the table is ``yes'' if Replace is enabled, ``no'' otherwise.
The accum column in the table is ``yes'' if the accum is
present, ``no'' otherwise.
The ${\bf C}$ column is listed as $c_{ij}$ if that entry is present,
and a dash otherwise, likewise for the ${\bf A}$ column.

\begin{table}
{\small
\begin{tabular}{lllll|l}
\hline
repl & accum & ${\bf C}$ & ${\bf A}$ & mask & action taken by ${\bf C \langle M \rangle = C \odot A}$ \\
\hline
\hline
       &    &          &           &      & \verb'C<M>=A' and \verb'C<!M>=A' \\
\hline
    -  &-   & $c_{ij}$ & $a_{ij}$  & 1    &  $c_{ij} = a_{ij}$, update \\
    -  &-   &  -       & $a_{ij}$  & 1    &  $c_{ij} = a_{ij}$, insert \\
    -  &-   & $c_{ij}$ &  -        & 1    &  delete $c_{ij}$ because $a_{ij}$ not present \\
    -  &-   &  -       &  -        & 1    &   \\
\hline
    -  &-   & $c_{ij}$ & $a_{ij}$  & 0    &   \\
    -  &-   &  -       & $a_{ij}$  & 0    &   \\
    -  &-   & $c_{ij}$ &  -        & 0    &   \\
    -  &-   &  -       &  -        & 0    &   \\
\hline
\hline
       &    &          &           &      & \verb'C<M,repl>=A' and \verb'C<!M,repl>=A' \\
\hline
    yes&-   & $c_{ij}$ & $a_{ij}$  & 1    &  $c_{ij} = a_{ij}$, update \\
    yes&-   &  -       & $a_{ij}$  & 1    &  $c_{ij} = a_{ij}$, insert \\
    yes&-   & $c_{ij}$ &  -        & 1    &  delete $c_{ij}$ because $a_{ij}$ not present \\
    yes&-   &  -       &  -        & 1    &   \\
\hline
    yes&-   & $c_{ij}$ & $a_{ij}$  & 0    &  delete $c_{ij}$  (because of \verb'GrB_REPLACE') \\
    yes&-   &  -       & $a_{ij}$  & 0    &   \\
    yes&-   & $c_{ij}$ &  -        & 0    &  delete $c_{ij}$  (because of \verb'GrB_REPLACE') \\
    yes&-   &  -       &  -        & 0    &   \\
\hline
\hline
       &    &          &           &      & \verb'C<M>+=A' and \verb'C<!M>+=A' \\
\hline
    -  &yes & $c_{ij}$ & $a_{ij}$  & 1    &  $c_{ij} = c_{ij} \odot a_{ij}$, apply accumulator \\
    -  &yes &  -       & $a_{ij}$  & 1    &  $c_{ij} = a_{ij}$, insert \\
    -  &yes & $c_{ij}$ &  -        & 1    &   \\
    -  &yes &  -       &  -        & 1    &   \\
\hline
    -  &yes & $c_{ij}$ & $a_{ij}$  & 0    &   \\
    -  &yes &  -       & $a_{ij}$  & 0    &   \\
    -  &yes & $c_{ij}$ &  -        & 0    &   \\
    -  &yes &  -       &  -        & 0    &   \\
\hline
\hline
       &    &          &           &      & \verb'C<M,repl>+=A' and \verb'C<!M,repl>+=A' \\
\hline
    yes&yes & $c_{ij}$ & $a_{ij}$  & 1    &  $c_{ij} = c_{ij} \odot a_{ij}$, apply accumulator \\
    yes&yes &  -       & $a_{ij}$  & 1    &  $c_{ij} = a_{ij}$, insert \\
    yes&yes & $c_{ij}$ &  -        & 1    &   \\
    yes&yes &  -       &  -        & 1    &   \\
\hline

\hline
    yes&yes & $c_{ij}$ & $a_{ij}$  & 0    &  delete $c_{ij}$  (because of \verb'GrB_REPLACE') \\
    yes&yes &  -       & $a_{ij}$  & 0    &   \\
    yes&yes & $c_{ij}$ &  -        & 0    &  delete $c_{ij}$  (because of \verb'GrB_REPLACE') \\
    yes&yes &  -       &  -        & 0    &   \\
\hline
\end{tabular}
}
\caption{Results of the mask/accumulator phase \label{tab:maskaccum}}
\end{table}

\newpage
\section{For Mask/Accum/Replace: there are 32 variants}

All these options can affect each other so there are 32 variants total,
except that when no mask is present, the value/structural option makes
no difference.

\begin{itemize}
\item the mask ${\bf M}$ can be present, or not present.
\item the mask can be complemented, or not (even when no mask is present)
\item the mask can be valued or structural
\item the replace option can be enabled, or not.
\item the accumulator can be present, or not.
\end{itemize}

Here are some options:

\begin{itemize}
\item plain mask, with accum:

    \begin{itemize}
    \item[] in ASCII: \verb'C<M>+=A'
    \item[] in LaTex: $\bf C \langle M \rangle \odot\!\!= A $
    \end{itemize}

\item negated mask, with accum.  Several options for LaTeX.
I like the $\overline{\bf M}$ since it is more compact, but it
has problems when $\bf M$ is also structural (see below).

    \begin{itemize}
    \item[] in ASCII: \verb'C<!M>+=A'
    \item[] in LaTex: $\bf C \langle \neg M \rangle \odot\!\!= A$
    \item[] in LaTex:  $\bf C \langle \overline{M} \rangle \odot\!\!= A$
    \end{itemize}

\item structural mask, not complemented:
using $s({\bf M})$ where $s$ stands for structural.
This feels wordy to me.  Not elegant.
The letter $s$ could be confused for a vector or scalar.

    \begin{itemize}
    \item[] in ASCII: \verb'C<s(M)>+=A'
    \item[] in LaTex:  ${\bf C} \langle s({\bf M}) \rangle \odot\!\!= {\bf A}$
    \end{itemize}

\item structural mask alternatives.  The letter $s$ could be confused
for a scalar or vector, so a Greek letter could be used instead,
such as sigma ($\sigma$).  But this is also wordy.

    \begin{itemize}
    \item[] in ASCII: \verb'C<s(M)>+=A'
    \item[] in LaTex:  ${\bf C} \langle \sigma({\bf M}) \rangle \odot\!\!= {\bf A}$
    \end{itemize}

\item structural mask alternative.  The notation
$s({\bf M})$ is a little wordy.  The Mask cannot be transposed in a
single call to \verb'GrB_anything' so a superscript would work.  But a
subscript might be better, because someone might want to indicate a
transposed mask (which would have to be done as a separate call to
\verb'GrB_transpose').  This doesn't look good in ASCII however:

    \begin{itemize}
    \item[] in ASCII: \verb'C<M_s>+=A'
    \item[] in LaTex:  ${\bf C} \langle {\bf M}_s \rangle \odot\!\!= {\bf A}$
    \end{itemize}

\item structural mask: why not use set notation?  The structure of ${\bf M}$
is a set of the entries of ${\bf M}$.  In a sense, selecting the
structural option in the descriptor converts ${\bf M}$
into a set.  So how about set notation, with curly brackets?
We don't use curly brackets anywhere else in GraphBLAS, so this is unambigous.
I like this the best.

    \begin{itemize}
    \item[] in ASCII: \verb'C<{M}>+=A'
    \item[] in LaTex:  ${\bf C} \langle \{{\bf M}\} \rangle \odot\!\!= {\bf A}$
    \end{itemize}

\item complemented structural mask, for $s({\bf M})$:

    \begin{itemize}
    \item[] in ASCII: \verb'C<!s(M)>+=A'
    \item[] in LaTex:  ${\bf C} \langle \neg s({\bf M}) \rangle \odot\!\!= {\bf A}$
    \end{itemize}

\item  complemented structural mask, for the curly bracket option:
It is important to note that the structure of ${\bf M}$ is taken
first, and then complemented.  Not the other way around.
I like this option the best (with $\neg$).

    \begin{itemize}
    \item[] ASCII: \verb'C<!{M}>+=A'
    \item[] LaTeX: ${\bf C} \langle \neg \{{\bf M}\} \rangle \odot\!\!= {\bf A}$
    \item[] LaTeX:
    ${\bf C} \langle \overline{ \{{\bf M}\}} \rangle \odot\!\!= {\bf A}$
    ouch.  That is a long overline, and could be confused with
    ${\bf C} \langle  \{\overline{\bf M}\} \rangle \odot\!\!= {\bf A}$
    \end{itemize}

\end{itemize}

(Gabor) I like the set notation for the ``structure'' option and the $\neg$
symbol for negation.  (Tim): I think this is the best option I've seen so far,
too.

\newpage

\section{Replace option}

The examples consider all options except for Replace.
Here are some ideas; I am not really happy with any of them.

\begin{itemize}

\item simple case: a mask with replace

    \begin{itemize}
    \item[] in ASCII: \verb'C<M,replace>+=A'
    \item[] in LaTex: $\bf C \langle M, \mbox{replace} \rangle \odot\!\!= A $
    \end{itemize}

\item complemented structural mask with replace

    \begin{itemize}
    \item[] ASCII: \verb'C<!{M},replace>+=A'
    \item[] LaTeX: ${\bf C} \langle \neg \{{\bf M}\}, \mbox{replace}
    \rangle \odot\!\!= {\bf A}$
    \end{itemize}

\item no mask, yet complemented, with replace.  This does actual work that
does not depend on the input matrix $\bf A$ or input scalar.

    \begin{itemize}
    \item[] ASCII: \verb'C<!,replace>=A'
    \item[] LaTeX: ${\bf C} \langle \neg, \mbox{replace}
    \rangle \odot\!\!= {\bf A}$
    \end{itemize}

\end{itemize}

\subsection{(Gabor) Alternative. (Tim): I like this}

How about double angle brackets for ``replace''? This could symbolize that the computation only keeps that part by the mask and discards the rest.

(Tim):  I like this idea.  It indicates to me that the Mask is ``strong,''
in the sense that stuff outside the mask (where the final mask value is
false after possibly taking the structure and/or complementing)
gets obliterated.

\begin{itemize}

    \item simple case: a mask with replace

        \begin{itemize}
        \item[] in ASCII: \verb'C<<M>>+=A'
        \item[] in LaTex: $\bf C \langle\!\langle M \rangle\!\rangle \odot\!\!= A $
        \end{itemize}

    \item complemented structural mask with replace

        \begin{itemize}
        \item[] ASCII: \verb'C<<!{M}>>+=A'
        \item[] LaTeX: ${\bf C} \langle\!\langle \neg \{{\bf M}\}
        \rangle\!\rangle \odot\!\!= {\bf A}$
        \end{itemize}

    \item no mask, yet complemented, with replace

        \begin{itemize}
        \item[] ASCII: \verb'C<<!>>=A'
        \item[] LaTeX: ${\bf C} \langle\!\langle \neg \rangle\!\rangle \odot\!\!= {\bf A}$
        \end{itemize}

\end{itemize}

\section{Different accum operators}

The accum operator can be any function, such as PLUS, TIMES, FIRST, MIN, MAX,
ANY, logical OR, logical AND etc.  I propose using using symbols from C/C++ if
available, or spelling out the function otherwise.
Assuming no mask/replace/complement, in ASCII:

    \begin{itemize}
    \item[] \verb'C +=A ' plus
    \item[] \verb'C *= A ' times
    \item[] \verb'C &&= A ' logical AND
    \item[] \verb'C &= A ' bitwise AND
    \item[] \verb'C ||= A ' logical OR
    \item[] \verb'C |= A ' bitwise OR
    \item[] \verb'C ^= A ' logical XOR, but see the XOR in LaTeX below
    \item[] \verb'C /= A ' divide
    \item[] \verb'C max= A ' maximum
    \item[] \verb'C any= A ', this is Tim's \verb'GxB_ANY_*' operator.
    \item[] \verb'C first= A '
    \item[] and so on
    \end{itemize}

In LaTeX, it is very similar.  Note the spacing:

    \begin{itemize}
    \item[] $\bf C \,+\!\!= A $, plus
    \item[] Latex source of the above: \verb'$\bf C \,+\!\!= A$'
    \item[] $\bf C \,*\!\!= A $, times
    \item[] $\bf C \,\wedge\!\!= A $, logical AND
    \item[] $\bf C \,\&\!\!= A $, bitwise AND
    \item[] $\bf C \,\vee\!\!= A $, logical OR
    \item[] $\bf C \,|\!\!= A $, bitwise OR
    \item[] $\bf C \,\oplus\!\!= A $, logical XOR?  but this conflicts with
        the use of $\oplus$ to denote a generic additive operator.
        So perhaps logical XOR should be written
        $\bf C \,\mbox{xor}\!\!= A $.
    \item[] $\bf C \,/\!\!= A $, divide, or perhaps
        $\bf C \,\div\!\!= A $
    \item[] $\bf C \,\mbox{max}\!\!= A $, maximum
    \item[] $\bf C \,\mbox{any}\!\!= A $, ANY
    \item[] $\bf C \,\mbox{first}\!\!= A $, FIRST
    \item[] and so on
    \end{itemize}

(Gabor) I propose to use \verb+\mathbin{}+ for spacing around the operator,
e.g., $\bf C \mathbin{+\!\!=} A $.
(Tim) I like that suggestion, which looks like this in the LaTeX:
\verb'$\bf C \mathbin{+\!\!=} A$'.

\end{document}


%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex
%-------------------------------------------CLUSTERING OVERTURNER-----------------------------------------------%
\newpage
\section{Clustering of the overturner problem}
% 1. Expliquer ce qu'on va faire
% 2. Décomposition du domaine en boxes, on cherche ce que donne le clustering sur ces boxes.
% 3. Résultats pour nboxy = 15, nboxz = 10 (et expliquer que ces choix permettent que y0 et z0 correspondent à des frontières de box)

This section presents the results of applying a stability-based community detection algorithm on the overturner problem. First, we explain how the method is applied and then we present the results for a given set of data's.

% %-----------------------DESCRIPTION OF THE METHOD---------------------------------%
% \subsection{Description of the method}
% In order to apply a clustering algorithm on the overturner problem, we have to define how the model can be considered as a graph. To this end, the domain is decomposed into $\nby \times \nbz$ boxes. We note $N_{box} = \nby\nbz$ the total number of boxes. Figure~\ref{fig:box_scheme} represents an example of such a domain decomposition with $\nby = 15$ and $\nbz = 10$. For any time $T$, the corresponding directed graph is build as follows : each node represents a box, and the weight of the edge between nodes $i$ and $j$ is the probability $m_{ij}(T)$ that a particle ends up in box $j$ after a time $T$ if it was initially in box $i$. If $m_{ij}(T) = 0$, one can equivalently consider that there is no edge between nodes $i$ and $j$. Since the problem is stationary, $m_{ij}(T)$ depends only on the elapsed time $T$, not on the initial time. Hence, the initial time can indifferently be considered as being zero. The adjacency matrix $\b M(T)$ of the graph is build from the weights $m_{ij}(T)$: $[\b M(T)]_{ij} = m_{ij}(T)$. For any time $T$, $\b M(T)$ is row-stochastic, i.e. $\b M(T)\b 1 = \b 1$, where $\b 1$ is the $N_{box}$-dimensional unit column vector. The latter has a straightforward physical interpretation: every particle remains in the domain.
% \begin{figure}[h!]
% 	\centering
% 	\input{fig/clusters/box_scheme}
% 	\caption{Illustration of the decomposition of the domain into boxes with $\nby = 15$ and $\nbz = 10$.}
% 	\label{fig:box_scheme}
% \end{figure}

% To estimate the probabilities $m_{ij}(T)$, the program is run for a time $T$ with each box containing initially $J$ uniformly distributed particles. $m_{ij}(T)$ is then numerically estimated as the number of particles having started in box $i$ and ending up in box $j$, divided by $J$. This \textit{box counting} method has been extensively used to estimate the concentration in studies using random walk modeling, see e.g. \cite{riddle1998specification}. Nevertheless, this method suffers some drawbacks; the most important of them are pointed in \cite{spivakovskaya2007lagrangian}, but we recall them here for the sake of completeness. The estimated transition probability depends on the choice of the boxes, in particular of their size and their center. Moreover, the number of boxes cannot be chosen to be too large; otherwise the estimated concentration tends to become very irregular or noisy. Finally, the resolution of the estimated concentration is limited to the size of the boxes, as it cannot be described in a box more precisely than a constant. But it is the perfect method for our problem since the volume average over such boxes (the nodes) is precisely what we want. Note however that other methods exist for estimating the concentration, that might be better suited for other studies. For example, the \textit{kernel estimation} method allows to reduce drastically the number of particles, and does not suffer from the resolution limit inherent to the box counting method. This method is briefly presented in \cite{spivakovskaya2007lagrangian}. Classical references are \cite{silverman1986density} and \cite{wand1995kernel}.

% %-------------------------USE OF THE TOOLBOX----------------------------%
% \subsection{Use of the stability software}
% % \newcommand\localFontSize@mlpr{10}
% We present here briefly how the \textit{PartitionStability} software is used to compute the partitions. Every concept appearing here has been presented in chapter~\ref{chap:clustering}. The \mtlb{stability} function is simply called as follows : \vspace{-.2cm}
% \begin{center}
% 	\mtlb{[S,N,VI,C] = stability(M,Markov_T,'directed','plot','teleport',0.01);}
% \end{center} %style = Matlab-bw for black and white
% Here, \mtlb{M} is the matrix $\b M(T)$ at the desired time $T$; \mtlb{Markov_T} is the vector containing every Markov times at which the optimal stability partition has to be computed (ideally, the sampling should be exponential); the \mtlb{'directed'} option specifies that we consider a directed graph; \mtlb{'plot'} asks the program to plot the stability, number of communities and variation of information as a function of the Markov time; and \mtlb{'teleport',0.01} allows to specify the value of the teleportation probability $\tau$ to $0.01$, the default value being $0.15$. The choice of $0.01$ is motivated by the fact that we believe the graph to be ergodic, even if we cannot prove it. Note that the program allows to choose which type of laplacian should be used to calculate the stability. However, the question does not arise here since both laplacians are equivalent in our case. Indeed, the total outgoing weight is the same at every node and is precisely equal to the number of particles $J$ released in each box. Hence, $k_i = J$ for every node $i$ and $\langle \b k \rangle = J$, so that $\bs \lambda_{combi}(\b k) = \b k/ \langle \b k \rangle = \b 1 = \bs \lambda_{norm}(\b k)$. We let thus the program run with the default normalized Laplacian, since it does not make any difference in our case. The output arguments \mtlb{S}, \mtlb{N}, \mtlb{VI} and \mtlb{C} contain respectively the stability, the number of communities, the variation of information, and the optimal partition for each Markov time contained in \mtlb{Markov_T}. If the latter is of size $n$, then \mtlb{S}, \mtlb{N} and \mtlb{VI} are $n$-dimensional vectors and \mtlb{C} is a $N_{box} \times n$ matrix. At the $j$th Markov time, communities are labeled by consecutive integers between $0$ and \mtlb{N(j)}$-1$ such that \mtlb{C(i,j)} $= k$ means that node $i$ belongs to community $k$ at Markov time \mtlb{Markov_T(j)}.

%--------------------------RESULTS--------------------------------------%
\subsection{Results}
Now we present some results on a particular discretization of the overturner problem. The box decomposition of the domain is the one shown in figure~\ref{fig:box_scheme}, and $J = 10\,000$ particles are released in each box. More precisely, a box is decomposed into a $100 \times 100$ sub-grid, and one particle is initially located at every point of the sub-grid, so that the particles are initially uniformly distributed within the box. The transition probability matrices $\b M(T)$ are generated for different values of $T$. We show here the results for $T = 1$, $10$, $50$ and $100$ years. The vector of the Markov times \mtlb{Markov_T} is sampled exponentially from $0.1$ to $100$ : $\log_{10}($\mtlb{Markov_T}$) = [-1,\, -0.98, \dots ,\, 1.98,\, 2]$. Notice that the physical meaning of the Markov time changes with $T$ : a Markov time step of $1$ is equal to a physical time step of $T$. Hence, for $a >0$, if for $\b M(T)$ we find some communities in the range of Markov times $[t_{M_1},\, t_{M_2}]$, then for $\b M(aT)$ we expect to find similar communities in the range of Markov times $\frac{1}{a}[t_{M_1},\, t_{M_2}]$.

% \begin{figure}[!htp]
% 	\centering
% 	\input{fig/clusters/box_scheme}
% 	\caption{Illustration of the decomposition of the domain into boxes with $\nby = 15$ and $\nbz = 10$.}
% 	\label{fig:box_scheme}
% \end{figure}

Figures~\ref{fig:stab0}, \ref{fig:stab1}, \ref{fig:stab5} and~\ref{fig:stab10} show the stability curves, the number of communities and the variation of information as functions of the Markov time for $T = 1$, $10$, $50$ and $100$ years respectively. As discussed in section~\ref{subsec:robustness}, robust partitions correspond to plateaux in the community curve of the graphs. By using this criterion, partitions of 6, 5, 4, 3 and 2 communities are found at different time scales. Those partitions are summarized in table~\ref{tab:partitions_summary} along with the physical time range at which they reveal themselves. Figure~\ref{fig:cluster0}, \ref{fig:cluster1}, \ref{fig:cluster5} and~\ref{fig:cluster10} shows the most robust clusterings for $T=1$, $10$, $50$ and $100$ respectively. From table~\ref{tab:partitions_summary}, we observe that some similar partitions happen to be the most relevant at different time scales when we modify $T$. For example, for $T=1$, 6 communities are found in the time range 9 - 12 years (figure~\ref{fig:cluster0_6_}). A similar clustering is found for $T = 10$ and $T = 50$ but in the time ranges 24 - 48 years and 36-48 years respectively (figures~\ref{fig:cluster1_6_} and~\ref{fig:cluster5_6_}).

It is important to notice that the community detection algorithm may fail to detect the right number of communities. Take figure~\ref{fig:cluster1_2_} for example : the stability software detects 2 communities. However, the white community consists of two noncontiguous blocks. Intuitively, particles leaving the lower white block should enter the khaki block first before entering the upper white block. Hence, there should be 3 communities rather than 2 for this partitioning. A way to quantify this intuition is by looking at
\begin{equation}
	\b M_{\P}(T) = \diag^{-1}(\b n)\b H^{\t}_{\P} \b M(T) \b H_{\P},
\end{equation}
where $\b n$ is the $c$-dimensional vector containing the number of blocks in each community. $[\b M_{\P}]_{kl}$ is the transition probability from community $k$ to community $l$. By considering the clustering where the lower and the upper white blocks are separated communities, we get
\begin{equation}
	\b M_{\P}(10) =
	\begin{pmatrix}
		0.886 & 0.114 & 0.000\\
	    0.052 & 0.895 & 0.053\\
	    0.017 & 0.256 & 0.727\\
    \end{pmatrix}.
\end{equation}
Here, community 1 is the lower white block, community 2 is the khaki block and community 3 is the upper white block. We observe that $[\b M_{\P}]_{13} = 0$ and $[\b M_{\P}]_{31} = 0.017$, indicating very weak links between the lower and the upper white blocks. Hence, they should indeed be considered as separated communities. However, this does not mean that~\ref{fig:cluster1_2_} provides then the optimal clustering with 3 communities ! Such a clustering is rather given by figure~\ref{fig:cluster1_3_}, and the clustering proposed in figure~\ref{fig:cluster1_2_} should simply be disregarded as being non-relevant.

Now, let us analyze a seemingly relevant community structure. By looking at table~\ref{tab:partitions_summary} together with figures~\ref{fig:cluster1_5_} and~\ref{fig:cluster5_5_}, we observe that two similar 5-communities clusterings arise in the time range 50 - 63 years when $T = 10$ and $T = 50$. This indicates that those community structures might be more resilient than others. There is only a 2 boxes difference between the two clusterings; we will therefore focus on the clustering found for $T = 10$, namely the one from figure~\ref{fig:cluster1_5_}. The communities are numbered from 1 to 5 on the figure. The matrix $\b M_{\P}$ for this community structure is
\begin{equation}
	\b M_{\P}(10) =
	\begin{pmatrix}
	0.907 & 0.024 &     0 & 0.024 & 0.045\\
    0.073 & 0.827 & 0.043 & 0.057 & 0\\
        0 & 0.029 & 0.925 & 0.036 & 0.010\\
    0.039 & 0.041 & 0.089 & 0.776 & 0.055\\
    0.020 &     0 & 0.048 & 0.022 & 0.910\\
	\end{pmatrix}.
\end{equation}
Obviously, particles in a community tends to stay in that community. But what are the main interconnections between communities ? By looking at matrix $\b M_{\P}$, we observe that particles leaving community 1 goes preferentially to community 5; from community 2, the main tendency is to go to community 1; from 3 to 4 and 2; from 4 to 3 (mainly because of the size of 3) and from 5 to 3. Hence, the dominant tendency is that the particles tend to describes a clockwise cycle in the domain, which is exactly the expected behavior.

\textcolor{blue}{J'aimerais aller un peu plus loin dans mes commentaires mais les idées ne se bousculent pas... Et les commentaires que je fais ci-dessus ne nous apprennent rien. Cela fait sans doute beaucoup d'images d'images pour au final pas grand chose.}

\begin{table}[H]
\centering
\caption{Summary of the dominant clusterings found by inspection of the transition probability matrix $\b M(T)$ for $T = 1$, $10$, $50$ and $100$ years.}
\label{tab:partitions_summary}
\begin{tabular}{l|ccccc}
\hline
\multirow{2}{*}{$T$} & \multicolumn{5}{c}{Time range [year]} \\ \cline{2-6}
                  &  6 communities &  5 communities  &  4 communities  &  3 communities &  2 communities \\ \hline
              1   & \phantom{0}9 - 12  & 15 - 26 & 28 - 36 & \phantom{0}38 - $\dots$  &   \\
              10  & 24 - 48 &  50 - 63 & & \phantom{0}91 - 316 & 331 - $\dots$ \\
              50  & 36 - 48 & 50 - 66 & & \phantom{0}69 - 138 & 144 - 190 \\
              100 & 58 - 76 & 79 - 105 & &120 - 229 & 240 - 316 \\ \hline
\end{tabular}
\end{table}

%------------------ T = 1 ------------------------------%
\begin{figure}[H]
	\centering
	\includegraphics[width = .7\textwidth]{clusters/stab0.eps}
	\caption{Stability, number of communities and variation of information as a function of the Markov time for $T=1$ year.}
	\label{fig:stab0}
\end{figure}

\begin{figure}[H]
	\centering
	\begin{subfigure}[t]{0.49\textwidth}
		\includegraphics[width=\textwidth]{clusters/cluster0_6_.eps}
		\caption{6 communities.}
		\label{fig:cluster0_6_}
	\end{subfigure}
	\begin{subfigure}[t]{0.49\textwidth}
		\includegraphics[width=\textwidth]{clusters/cluster0_5_.eps}
		\caption{5 communities.}
		\label{fig:cluster0_5_}
	\end{subfigure}
	\begin{subfigure}[t]{0.49\textwidth}
		\includegraphics[width=\textwidth]{clusters/cluster0_4_.eps}
		\caption{4 communities.}
		\label{fig:cluster0_4_}
	\end{subfigure}
	\begin{subfigure}[t]{0.49\textwidth}
		\includegraphics[width=\textwidth]{clusters/cluster0_3_.eps}
		\caption{3 communities.}
		\label{fig:cluster0_3_}
	\end{subfigure}
	\caption{The relevant clusterings detected at different time scales for $T=1$ year.}
	\label{fig:cluster0}
\end{figure}

%------------------ T = 10 -----------------------------%

\begin{figure}[H]
	\centering
	\includegraphics[width = .7\textwidth]{clusters/stab1.eps}
	\caption{Stability, number of communities and variation of information as a function of the Markov time for $T=10$ years.}
	\label{fig:stab1}
\end{figure}

\begin{figure}[H]
	\centering
	\begin{subfigure}[t]{0.49\textwidth}
		\includegraphics[width=\textwidth]{clusters/cluster1_6_.eps}
		\caption{6 communities.}
		\label{fig:cluster1_6_}
	\end{subfigure}
	\begin{subfigure}[t]{0.49\textwidth}
		\includegraphics[width=\textwidth]{clusters/cluster1_5_num.eps}
		\caption{5 communities.}
		\label{fig:cluster1_5_}
	\end{subfigure}
	\begin{subfigure}[t]{0.49\textwidth}
		\includegraphics[width=\textwidth]{clusters/cluster1_3_.eps}
		\caption{3 communities.}
		\label{fig:cluster1_3_}
	\end{subfigure}
	\begin{subfigure}[t]{0.49\textwidth}
		\includegraphics[width=\textwidth]{clusters/cluster1_2_.eps}
		\caption{2 communities detected by the algorithm which should rather be considered as being 3 communities.}
		\label{fig:cluster1_2_}
	\end{subfigure}
	\caption{The relevant clusterings detected at different time scales for $T=10$ years.}
	\label{fig:cluster1}
\end{figure}

%------------------ T = 50 -----------------------------%
\begin{figure}[H]
	\centering
	\includegraphics[width = .7\textwidth]{clusters/stab5.eps}
	\caption{Stability, number of communities and variation of information as a function of the Markov time for $T=50$ years.}
	\label{fig:stab5}
\end{figure}

\begin{figure}[H]
	\centering
	\begin{subfigure}[t]{0.49\textwidth}
		\includegraphics[width=\textwidth]{clusters/cluster5_6_.eps}
		\caption{6 communities.}
		\label{fig:cluster5_6_}
	\end{subfigure}
	\begin{subfigure}[t]{0.49\textwidth}
		\includegraphics[width=\textwidth]{clusters/cluster5_5_.eps}
		\caption{5 communities.}
		\label{fig:cluster5_5_}
	\end{subfigure}
	\begin{subfigure}[t]{0.49\textwidth}
		\includegraphics[width=\textwidth]{clusters/cluster5_3_.eps}
		\caption{3 communities.}
		\label{fig:cluster5_3_}
	\end{subfigure}
	\begin{subfigure}[t]{0.49\textwidth}
		\includegraphics[width=\textwidth]{clusters/cluster5_2_.eps}
		\caption{2 communities.}
		\label{fig:cluster5_2_}
	\end{subfigure}
	\caption{The relevant clusterings detected at different time scales for $T=50$ years.}
	\label{fig:cluster5}
\end{figure}

%------------------ T = 100 ----------------------------%
\begin{figure}[H]
	\centering
	\includegraphics[width = .7\textwidth]{clusters/stab10.eps}
	\caption{Stability, number of communities and variation of information as a function of the Markov time for $T=100$ years.}
	\label{fig:stab10}
\end{figure}

\begin{figure}[H]
	\centering
	\begin{subfigure}[t]{0.49\textwidth}
		\includegraphics[width=\textwidth]{clusters/cluster10_3_.eps}
		\caption{3 communities.}
		\label{fig:cluster10_3_}
	\end{subfigure}
	\begin{subfigure}[t]{0.49\textwidth}
		\includegraphics[width=\textwidth]{clusters/cluster10_2_.eps}
		\caption{2 communities.}
		\label{fig:cluster10_2_}
	\end{subfigure}
	\caption{The relevant clusterings detected at different time scales for $T=100$ years.}
	\label{fig:cluster10}
\end{figure}


%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex
\section{The code} \label{sec:thecode}
The preceding sections cover all the material needed to implement a Lagrangian code that solves a two-dimensional advection-diffusion problem. For the need of this work, a \Cpp code has been implemented. The choice of \Cpp is motivated by the fact that it is \textit{fast}, and that it comes together with a wide range of \textit{open source} supporting tools. Another reason is that \Cpp is an \textit{object-oriented language}, and it is widely held that writing in an object-oriented style leads to programs which are easier to understand, to extend, to maintain and to refactor \cite{pitt2012guide}.

The code deals with the two-dimensional transport equation
\begin{equation} \label{eq:TEcode}
	\frac{\partial C}{\partial t} = \nabla \cdot (-\b u C + \b K \nabla C)
\end{equation}
on rectangular domains with no-through boundary conditions. It allows to simulate trajectories, to compute the concentration and to build the transition probability matrix for a given partitioning of the domain. The trajectories are simulated using the backward Euler method, applied on the system of backward Itô SDE's~\eqref{eq:bi-TM}.
% The user can choose between the Euler-Maruyama \textcolor{red}{attention implémenter drift gradient term} and backward-Itô method to simulate the trajectories. In view of the preceding sections, the Itô SDE corresponding to~\eqref{eq:TEcode} is
In this work, only the box-counting method is used for the estimation of the concentration (and thus also for the computation of the transition probability matrix) but the density kernel estimation method has also been implemented for the sake of completeness.

In order to use the code on a particular problem meeting the above specifications, a class that defines the problem must be implemented. That class must inherit from the abstract base class \mintinline{c++}{AbstractAdvDiffProblem} (see listing~\ref{listing:abstractadvdiffproblem}), and must at least implement the two pure virtual functions of the abstract base class:
\begin{listing}[ht!]
\caption{The abstract base class \cppcode{AbstractAdvDiffProblem}.}
\label{listing:abstractadvdiffproblem}
\begin{minted}[breaklines,tabsize=4,fontsize=\footnotesize,style=tango,escapeinside=||]{c++}
class AbstractAdvDiffProblem
{
	protected:
		double mH0, mH1; // boundaries of the domain in the z-direction : H0 <= z <= H1
		double mL0, mL1; // boundaries of the domain in the y-direction : L0 <= y <= L1

	public:
		AbstractAdvDiffProblem(double H0, double H1, double L0, double L1);
		virtual ~AbstractAdvDiffProblem(){};
		double getH0() const;
		double getH1() const;
		double getL0() const;
		double getL1() const;
		virtual SymMatrix getK(double y, double z) const=0; // diffusivity tensor
		virtual LowerTriMatrix getB(double y, double z) const; // 2K = BB'
		virtual Vec2 getU(double y, double z) const=0; // velocity vector
		virtual void printInfo(std::ofstream& f) const;
};
\end{minted}
\end{listing}
\begin{itemize}[nosep]
	\item \mintinline[style=tango]{c++}{SymMatrix getK(double y, double z)}: returns the diffusivity tensor $\b K$ evaluated at $(y,z)$. The return value is of type \cppcode{SymMatrix}, a structure intended to store a $2\times 2$ symmetric matrix with only three elements stored in memory. Instantiating an object \cppcode{A} of type \cppcode{SymMatrix} is pretty simple: \cppcode{SymMatrix A(a,b,c)} creates the matrix
	\[
		A = \begin{pmatrix} a & b \\ b & c \end{pmatrix},
	\]
	where \cppcode{a}, \cppcode{b} and \cppcode{c} are of type \cppcode{double}. The elements of \cppcode{A} are then accessed via the syntax \cppcode{A(i,j)} which uses one-based indexing. Hence, \cppcode{A(1,1) = a}, \cppcode{A(1,2) = A(2,1) = b} and \cppcode{A(2,2) = c}. The same syntax can be used to modify the elements of \cppcode{A}.
	\item \mintinline[style=tango]{c++}{Vec2 getU(double y, double z)}: returns the velocity vector $\b u$ evaluated at $(y,z)$. The return value is of type \cppcode{Vec2}, a structure that stores two elements of type \cppcode{double}. The syntax \cppcode{Vec2 v(a,b)} is used to create the two-dimensional vector $v = (a,b)$. The elements of \cppcode{v} are accessed via the syntax \cppcode{v(i)} which also uses one-based indexing: \cppcode{v(1) = a} and \cppcode{v(2) = b}.
\end{itemize}
By default, the code computes the matrix $\b B$ using~\eqref{eq:B} and~\eqref{eq:Bstar}. This is done by the function \cppcode{LowerTriMatrix GetB(double y, double z)}. In some cases, it can be interesting to overload that definition of \cppcode{GetB}, which is possible since this function is virtual. The return value must be of type \cppcode{LowerTriMatrix}, which is a structure similar to \cppcode{SymMatrix} but is intended to store lower triangular $2\times2$ matrices instead of symmetric $2\times2$ matrices.

Notice that the code as such implements the dimensional form of the transport model. However, it can be used to run simulations on the adimensional form of the transport model. To this end, it suffice to define the functions \cppcode{getK} and \cppcode{getU} accordingly: \cppcode{getK} shall return the inverse of the Peclet matrix, and \cppcode{getU} shall return the adimensional velocity vector.

Once a class describing the problem is properly defined, three methods can be used to compute either the trajectories, the normalized concentration or the transition probability matrix. We call those methods the \textit{compute methods}. Their signatures are given in listing~\ref{listing:signature_compute}. Since those functions are well documented in the code, we invite the interested reader to refer to the code for further explanations about those functions.
\begin{listing}[ht!]
\caption{Signatures of the \textit{compute methods}.}
\label{listing:signature_compute}
\begin{minted}[breaklines,tabsize=4,fontsize=\footnotesize,style=tango,escapeinside=||]{c++}
void ComputeTrajectories(const AbstractAdvDiffProblem& prob, std::string model,
						 double dt, double T, int Nloc, double yStart, double zStart);
void ComputeConcentration(const AbstractAdvDiffProblem &prob, std::string model,
						  double dt, double T, std::string estimator, int Nloc,
						  double yStart, double zStart, int nboxy, int nboxz);
void ComputeTransitionProbabilities(const AbstractAdvDiffProblem& prob,
									std::string model, int nboxy, int nboxz, int nyloc,
									int nzloc, double dt, double Times[], int nTimes,
									bool binary, std::string estimator = "box");
\end{minted}
\end{listing}

Test cases with analytical solutions have been built to assess the validity of the implementation. They are presented in appendix~\ref{app:test_case} and the numerical solution is compared to the analytical solution, producing satisfying results.
% \begin{itemize}
% 	\item \mintinline{c++}{LowerTriMatrix getB(double y, double z)}:
% 	\item io
% \end{itemize}
% Le code résout des probleme 2D generaux sur un domaine rectangulaire avec des conditions frontières no trough.
% Choix entre Ito (attention alors il faut implémenter le drift gradient velocity) et backward Ito.
% --> Pour résoudre un problème particulier :
% 	1. Implémenter une class problem qui hérite de abstractadvdiff, et dont les méthode minimales sont : ...
% 	AbstractAdvDiff implémente Cholesky par défaut mais on peut aussi implémenter sa propre méthode getB,
%	ce qui permet d'autre choix de B et dans certains cas une meilleure efficacité. (+ exemple)
%	Si on veut de l'adim il suffit de faire K = 1/Pe et U = ...
%	2. Ensuite les méthodes Compute permette de calculer trajectoire, concentration et matrice de transition de proba.
%	Ces méthodes font entre autre appel aux méthodes de la classe solver et de ses enfant. Par exemple backward ito est implémenté dans
%	biSlver par <CODE>.
%	3. Mettre le code "main" dans un studycase (à voir si c'est vraiment intéressant de parler des studycases)
%
% \begin{listing}[ht!]
% \caption{Implementation of the backward Euler method.}
% \label{listing:updateposition}
% \begin{minted}[breaklines,tabsize=4,fontsize=\footnotesize,style=tango,escapeinside=||]{c++}
% void BISolver::UpdatePosition(const AbstractAdvDiffProblem& prob)
% {
% 	LowerTriMatrix B;
% 	Vec2 U;
% 	double R1, R2, dY, dZ, y, z, ypred, zpred;
% 	double sqrt_dt = sqrt(mdt);
% 	for (int i=0; i<mParticles.mN; i++)
% 	{
% 		// position and speed of particle i at time t
% 		y = mParticles.mY[i];
% 		z = mParticles.mZ[i];
% 		U = prob.getU(y,z);
% 		B = prob.getB(y,z);
% 		// realisations of the noises
% 		R1 = wiener(generator);
% 		R2 = wiener(generator);
% 		// prediction step of the backward-Ito scheme
% 		dY = B(1,1)*sqrt_dt*R1;
% 		dZ = B(2,1)*sqrt_dt*R1 + B(2,2)*sqrt_dt*R2;
% 		// No-through BC also applies on the predictions -> bouncing on the walls
% 		ypred = y+dY;
% 		zpred = z+dZ;
% 		ypred = (ypred < prob.getL0()) ? 2*prob.getL0()-|\color{black}{ypred}| :
% 				(ypred > prob.getL1()) ? 2*prob.getL1()-|\color{black}{ypred}| : ypred;
% 		zpred = (zpred < prob.getH0()) ? 2*prob.getH0()-|\color{black}{zpred}| :
% 				(zpred > prob.getH1()) ? 2*prob.getH1()-|\color{black}{zpred}| : zpred;
% 		// amplitude of the noises
% 		B = prob.getB(ypred,zpred);
% 		/* update particles positions using backward-Ito scheme
% 		* No-flux BC : Bounce on the wall */
% 		ypred = mParticles.mY[i] + U(1)*mdt + B(1,1)*sqrt_dt*R1;
% 		zpred = mParticles.mZ[i] + U(2)*mdt + B(2,1)*sqrt_dt*R1 + B(2,2)*sqrt_dt*R2;
% 		mParticles.mY[i] = (ypred < prob.getL0()) ? 2*prob.getL0()-|\color{black}{ypred}| :
% 						   (ypred > prob.getL1()) ? 2*prob.getL1()-|\color{black}{ypred}| : ypred;
% 		mParticles.mZ[i] = (zpred < prob.getH0()) ? 2*prob.getH0()-|\color{black}{zpred}| :
% 						   (zpred > prob.getH1()) ? 2*prob.getH1()-|\color{black}{zpred}| : zpred;
% 	}
% 	mParticles.mTime += mdt;
% }
% \end{minted}
% \end{listing}


\documentclass[12pt]{cdblatex}
\usepackage{eqtns}

\begin{document}

\section*{PhysRevD.62.044034 equation (15)}

\begin{cadabra}
   from shared import *
   import cdblib

   jsonfile = 'eqtn15.json'
   cdblib.create (jsonfile)

   defG2GBar = cdblib.get ('defG2GBar','gamma.json')

   # --------------------------------------------------------------------------
   # Rphi = the part of Rab from the conformal factor

   Rab := R_{a b}.                                                   # cdb (eq15.101,Rab)

   substitute     (Rab, defRab)                                      # cdb (eq15.102,Rab)
   substitute     (Rab, defRiem)                                     # cdb (eq15.103,Rab)
   substitute     (Rab, defG2GBar)                                   # cdb (eq15.104,Rab)
   distribute     (Rab)                                              # cdb (eq15.105,Rab)
   product_rule   (Rab)                                              # cdb (eq15.106,Rab)
   Rab = product_sort (Rab)                                          # cdb (eq15.107,Rab)
   rename_dummies (Rab)                                              # cdb (eq15.108,Rab)
   canonicalise   (Rab)                                              # cdb (eq15.109,Rab)
   substitute     (Rab, $gBar_{b c} gBar^{c a} -> gBar^{a}_{b}$)
   substitute     (Rab, $\partial_{a}{gBar^{a}_{b}} -> 0$)
   substitute     (Rab, $\partial_{a}{gBar_{b}^{c}} -> 0$)
   substitute     (Rab, $gBar^{a}_{a} -> 3$)
   eliminate_kronecker (Rab)                                         # cdb (eq15.110,Rab)
   Rab = product_sort (Rab)                                          # cdb (eq15.111,Rab)
   rename_dummies (Rab)                                              # cdb (eq15.112,Rab)
   canonicalise   (Rab)                                              # cdb (eq15.113,Rab)
   substitute     (Rab, $gBar_{b c} gBar^{c a} -> gBar^{a}_{b}$)     # cdb (eq15.114,Rab)
   substitute     (Rab, $gBar^{a}_{a} -> 3$)                         # cdb (eq15.115,Rab)
   eliminate_kronecker (Rab)                                         # cdb (eq15.116,Rab)

   # |\clearpage|
   # isolate Rphi from Rab by switching to local RNC

   Rphi := @(Rab).

   substitute (Rphi, $GammaBar^{a}_{b c}->0$)                        # cdb (eq15.117,Rphi)
   substitute (Rphi, $\partial_{a}{gBar_{b c}}->0$)                  # cdb (eq15.118,Rphi)
   substitute (Rphi, $\partial_{a}{gBar^{b c}}->0$)                  # cdb (eq15.119,Rphi)

   substitute (Rphi, $\partial_{a b}{\phi} -> DBar_{a b}{\phi}$)     # cdb (eq15.120,Rphi)
   substitute (Rphi, $\partial_{a}{\phi} -> DBar_{a}{\phi}$)         # cdb (eq15.121,Rphi)

   defRphi := Rphi_{a b} -> @(Rphi).

   cdblib.put ('defRphi',defRphi,jsonfile)
\end{cadabra}

\clearpage

\begin{dgroup*}[spread=5pt]
   \begin{dmath*}
      \cdb{eq15.101}
         = \Cdb*{eq15.102}
         = \Cdb*{eq15.103}
         = \Cdb*[\hskip2.5cm\hfill]{eq15.104}
         = \Cdb*{eq15.105}
         = \Cdb*{eq15.106}
         = \Cdb*{eq15.107}
   \end{dmath*}
\end{dgroup*}

\clearpage

\begin{dgroup*}[spread=5pt]
   \begin{dmath*}
      \cdb{eq15.101}
         = \Cdb*{eq15.108}
         = \Cdb*[\hskip2cm\hfill]{eq15.109}
         = \Cdb*{eq15.110}
         = \Cdb*{eq15.111}
         = \Cdb*{eq15.112}
   \end{dmath*}
\end{dgroup*}

\clearpage

\begin{dgroup*}[spread=5pt]
   \begin{dmath*}
      \cdb{eq15.101}
         = \Cdb*[\hskip2.5cm\hfill]{eq15.113}
         = \Cdb*[\hskip2.5cm\hfill]{eq15.114}
         = \Cdb*{eq15.115}
         = \Cdb*{eq15.116}
   \end{dmath*}
\end{dgroup*}

The above doesn't look much like equation (15). So, what do we do? First note that {\tt (eq15.116)}
represents the full $R_{ab}$, that is, equation (14). To isolate the contributions from $\phi$
we can first set $\bar{\Gamma}$ and its derivatives to zero (which in turn requires setting
$\partial_{a} \bar{g}_{bc}=0$). The result is equation {\tt (eq15.119)} below. Having set
$\bar{\Gamma}$ to zero means that we can replace $\partial$ with $\bar{D}$ leading to equation
{\tt (eq15.121)}. But that is clearly a tensor equation and so by the usual arguments it must be true
in all frames (not just this frame with $\bar{\Gamma}=0$). It's a standard argument and I've
probably overdone the discussion. Anyway, equation {\tt (eq15.121)} is exactly equation $(15)$ from
the paper. Yeah.

\begin{dgroup*}[spread=5pt]
   \begin{dmath*}
      R^{\phi}_{ab}
         = \Cdb*{eq15.117}
         = \Cdb*{eq15.118}
         = \Cdb*{eq15.119}
         = \Cdb*{eq15.120}
         = \Cdb*{eq15.121}
   \end{dmath*}
\end{dgroup*}

\clearpage

\begin{cadabra}
   # --------------------------------------------------------------------------
   # Check against prd62.

   foo := @(Rphi).                                      # cdb(eq15.lcb,foo)
   bah  = cdblib.get('prd62.eq15.rhs','prd62.json')     # cdb(eq15.prd,bah)

   diff := @(foo) - @(bah).

   distribute     (diff)
   diff = product_sort (diff)
   rename_dummies (diff)
   map_sympy      (diff, "simplify")
   canonicalise   (diff)                                # cdb(eq15.chk,diff)
\end{cadabra}

% \clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{eq15.lcb} \end{dmath*}
   \begin{dmath*} \cdb*{eq15.prd} \end{dmath*}
   \begin{dmath*} \cdb*{eq15.chk} \end{dmath*}
\end{dgroup*}

\end{document}


\newcommand{\sigmatwo}{\overline{\sigma}}
The current query evaluation mechanism for \datalogM is a bottom-up naive\cite{Green:2013:DRQ:2688167.2688168} evaluation. It is based on the fixpoint-theoretic semantics, deriving tuples from rules until no new tuples may be derived. The rule evaluation is performed using relational algebra (see e.g. \cite{Abiteboul:1995:FDL:551350}) and a thorough description is given in Appendix A.

\subsection{Mutual Dependencies and Predicate Ordering}
With multiple rules and potentially many mutual dependencies between the predicates, there is a need to find an order in which to apply the rules. Indeed, for mutually dependent predicates, all rules which may derive new facts for those predicates need to be iterated together. \textit{Stratification}\cite{Green:2013:DRQ:2688167.2688168} is the process of clustering the predicates that need to be computed together into so called \textit{strata} as well as to find an optimal order between the strata. The iterative fix-point algorithm is then run over each \textit{stratum} following the computed order. The process is formalized below.

A predicate $P_i$ \textit{directly depends} on predicate $P_j$ iff there exists a rule for which $P_i$ is in the head and $P_j$ is in the body. Let $Dep(P_i)$ be the set of predicates which $P_i$ directly depends on. The dependency graph $G_{DEP}$ has the set of predicate symbols as vertices and there is an edge from $P_i$ to $P_j$ iff $P_j \in DEP(P_i)$. A strongly connected component in $G_{DEP}$ then contains the predicates which are mutually recursive. Such a connected component can be found e.g. using Tarjan's algorithm \cite{Tarjan72depthfirst} and is called a stratum. By merging the vertices of $G_{DEP}$ into such strata we get a graph $G_{STRAT}$ with vertices being the strata of $G_{DEP}$ and edges the collapsed multi-edges from $G_{DEP}$. By construction there exists a total order on $G_{STRAT}$ with $S_1 < S_2$ iff $(S_1, S_2) \in Edge(G_{STRAT})$. The desired order is found by a reverse post-order search of $G_{STRAT}$.
\begin{figure*}[!hbt]
	\includegraphics[scale=0.7]{img/souffleEval.pdf}
	\caption{Souffle Printing Pipeline. \textbf{Yellow}: A Datalog Program. \textbf{Blue}: An evaluation mechanism. \textbf{Green}: A compiler stage. }
	\label{figure:soufflePipeline}
\end{figure*}
\subsection{Cross Compilation}
In addition to internal evaluation, $Datalog^M$ supports cross-compilation, or pretty-printing, to Souffle\cite{SouffleHome}. The compilation pipeline is shown in figure \ref{figure:soufflePipeline}. First, a number of semantic checks are performed. For example, the semantic check ensures that all variables used in the head of a rule also occures in the body of the rule (the range restriction property\cite{Ceri:1989:YAW:627272.627357}). In the next stage, the program is type checked (type-checking is described in more detail in the following section). As was mentioned in the introduction (and will be explained in the next section), \datalogM supports meta-predicates. Souffle however has no such support so naturally it does not recognize the meta-semantics. To this end, a separate pre-process Datalog program is generated to evaluate all meta-predicates and subsequently output them as EDB files. Finally, the program is pretty-printed to a Souffle program $P_{Souffle}$. $P_{Souffle}$ declares the meta-predicates and loads them from the EDB files; the meta-predicates can then be used as ordinary predicates within the Souffle environment.