\chapter{AHTR Optimization Preliminary Work}
\label{chap:rollo-demo}
This chapter demonstrates the preliminary work completed for \gls{AHTR} optimization.
I used \gls{ROLLO} to apply genetic algorithms to maximize $k_{eff}$ in a single
\gls{AHTR} fuel slab.
Then, I presented spatial and energy homogenizations for applications to
\gls{AHTR} multiphysics simulations.
The \texttt{dissertation-results} Github repository contains all the scripts,
results, and plots shown in this chapter \cite{chee_dissertation_2021}.

\section{ROLLO Optimization: AHTR Fuel Slab}
\label{sec:rollo_opt_ahtr_slab}
This demonstration problem explores how heterogenous fuel distributions impact
$k_{eff}$ compared with homogenous fuel distributions customary in most reactor
designs.
I use OpenMC v0.12.0 \cite{romano_openmc_2013} for these neutronics calculations
with the ENDF/B-VII.1 data library \cite{chadwick_endf/b-vii.1_2011}.

\subsection{Problem Definition}
The reactor core explored is a single fuel slab from the \gls{FHR} benchmark
\gls{AHTR} design.
I modified the fuel slab to be straightened with perpendicular sides, instead
of slanted as in Figure \ref{fig:ahtr-fuel-plank}.
Figure \ref{fig:straightened_slab} illustrates the straightened fuel slab with
periodic boundary conditions in the x-y axis.
The periodic surfaces are: 1-3, 2-4.
\begin{figure}[]
    \centering
    \includegraphics[width=0.85\linewidth]{straightened_slab.png}
    \begin{tikzpicture}
        \draw[ thick,-latex] (0,0) -- (1,0) node[anchor=south west] {$x$};
        \draw[ thick,-latex] (0,0) -- (0,1) node[anchor=south west] {$y$};
        \draw[ thick,-latex] (0,0) -- (1,1) node[anchor=south west] {$z$};
       \tkzText[above](-0.3,-0.7){}
       \end{tikzpicture}
    \raggedright
    \resizebox{0.3\textwidth}{!}{
        \hspace{1cm}
        \fbox{\begin{tabular}{ll}
            \textcolor{fhrblue}{$\blacksquare$} & FLiBe \\
            \textcolor{fhrgrey}{$\blacksquare$} & Graphite (Fuel Plank)\\
            \textcolor{fhrred}{$\blacksquare$} & Graphite (Fuel Stripe) \\
            \textcolor{fhrblack}{$\blacksquare$} & TRISO particle

            \end{tabular}}}
    \caption{Straightened \acrfull{AHTR} fuel slab, with x-y periodic surfaces:
    1-3, 2-4, and reflective z-axis surfaces (out of the page). Original slanted
    fuel slabs can be seen in Figures \ref{fig:ahtr-fuel-assembly}
    and \ref{fig:ahtr-fuel-plank}.}
    \label{fig:straightened_slab}
\end{figure}
The slab has $27.1 \times 3.25 \times 1.85\ cm^3$ dimensions with reflective
top and bottom (along z-axis) boundary conditions.
I use the same materials as in the \gls{FHR} benchmark, except that I homogenized
each \gls{TRISO} particle's four outer layers:
porous carbon buffer, inner pyrolytic carbon, silicon carbide layer, and the
outer pyrolytic carbon.
The \gls{TRISO} particle dimensions remain the same.
Table \ref{tab:keff_triso} reports the $k_{eff}$ for this original straightened
\gls{AHTR} configuration with and without the outer layer \gls{TRISO}
homogenization.
\begin{table}[]
    \centering
    \onehalfspacing
    \caption{Straightened \acrfull{AHTR} fuel slab $k_{eff}$ for case with
    no \gls{TRISO} homogenization and case with homogenization of the four outer
    layers. Both simulations were run on one BlueWaters XE Node.}
	\label{tab:keff_triso}
    \footnotesize
    \begin{tabular}{llc}
    \hline
    \textbf{TRISO Homogenization}& \textbf{$k_{eff}$} & \textbf{Simulation time [s]}  \\
    \hline
    None & $1.38548 \pm 0.00124$ & 233\\
    Four outer layers & $1.38625 \pm 0.00109$ & 168\\
    \hline
    \end{tabular}
\end{table}
The \gls{TRISO} particle outer four-layer homogenization resulted in a $30\%$
speed-up without compromising accuracy with $k_{eff}$ values within each
other's uncertainty.

The \gls{ROLLO} optimization objective aims to maximize the slab $k_{eff}$.
It does so by varying the \gls{TRISO} particle packing fraction across the slab
while keeping the total packing fraction constant at 0.0979.
This total packing fraction is consistent with the original straightened slab with
TRISO particles in fuel stripes (Figure \ref{fig:straightened_slab}).
I divided the slab into ten cells along the x-axis between the \gls{FLiBe} and
graphite buffers, resulting in ten $2.31 \times 2.55 \times 1.85\ cm^3$ cells.
A sine distribution governs the \gls{TRISO} particle packing fraction's
distribution across cells:
\begin{align}
    PF(x) &= \left(a\cdot sin(b\cdot x + c) + 2\right) \cdot NF\\
    \intertext{where}
    PF &= \mbox{packing fraction } [-] \nonumber \\
    a &= \mbox{amplitude, peak deviation of the function from zero } [-] \nonumber \\
    b &= \mbox{angular frequency, rate of change of the function argument } [\frac{radians}{cm}] \nonumber \\
    c &= \mbox{phase, the position in its cycle the oscillation is at t = 0 } [radians]\nonumber \\
    x &= \mbox{midpoint value for each cell } [cm]\nonumber \\
    NF &= \mbox{Normalization factor } [-]\nonumber
\end{align}
The normalization factor ensures a consistent total packing fraction
in the slab regardless the \gls{TRISO} particle distribution.
For example, a packing fraction distribution of
$PF(x) = \left(0.5\cdot sin(\frac{\pi}{3}\cdot x + \pi) + 2\right)  \cdot NF$,
results in the following packing fractions for the ten cells: 0.103, 0.120,
0.049, 0.138, 0.076, 0.081, 0.136, 0.048, 0.125, and 0.098.
Figure \ref{fig:triso_distribution} shows this sine distribution, highlights
the packing fraction at the respective midpoints, and displays the slab's x-y
axis view with packing fraction varying based on this sine distribution.
\begin{figure}[]
    \centering
    \makebox[\textwidth][c]{\includegraphics[width=1.1\linewidth]{triso_distribution_sine.png}}
    \caption{Above: Straightened \acrfull{AHTR} fuel slab with varying \gls{TRISO} particle
    distribution across ten cells based on the sine distribution.
    Below: $PF(x) = (0.5\ sin(\frac{\pi}{3}x + \pi) + 2)  \times NF$
    sine distribution with red points indicating the packing fraction at each cell. }
    \label{fig:triso_distribution}
\end{figure}

In \gls{ROLLO}, a genetic algorithm varies the $a$, $b$, and $c$ variables to
find a combination that produces a packing fraction distribution that maximizes
the slab's $k_{eff}$.
I defined $a$, $b$, and $c$'s upper and lower bounds as:
\begin{align*}
    0 <\ &a < 2 \\
    0 <\ &b < \frac{\pi}{2} \\
    0 <\ &c < 2 \pi
\end{align*}
The bounds of $a$ keep the sine distribution from falling
below zero.
The $b$ and $c$ variable bounds spread wide enough to allow the genetic
algorithm to explore various sine distributions.
The OpenMC evaluator calculates $k_{eff}$.
OpenMC runs each simulation with 80 active cycles, 20 inactive cycles, and
8000 particles to reach $\sim$130pcm uncertainty.
Figure \ref{fig:rollo-input-simple} shows the \gls{ROLLO} input file for this
genetic algorithm optimization problem.
\texttt{ahtr\_slab\_openmc.py} is the template OpenMC straightened \gls{AHTR}
slab script that accepts $a$, $b$ and $c$ from \gls{ROLLO}, calculates packing
fraction distribution, and assigns packing fraction values to each fuel cell.
Subsequently, \gls{ROLLO} runs the templated OpenMC script to generate $k_{eff}$.
\begin{figure}[]
    \begin{minted}[
        frame=lines,
        framesep=2mm,
        baselinestretch=1.2,
        fontsize=\footnotesize,
        linenos
        ]{json}
        {
            "control_variables": {
                "a": {"min": 0.0, "max": 2.0},
                "b": {"min": 0.0, "max": 1.57},
                "c": {"min": 0.0, "max": 6.28},
            },
            "evaluators": {
                "openmc": {
                    "input_script": "ahtr_slab_openmc.py",
                    "inputs": ["a", "b", "c"],
                    "outputs": ["keff"],
                    "keep_files": false,
                }
            },
            "constraints": {"keff": {"operator": [">="], "constrained_val": [1.0]}},
            "algorithm": {
                "objective": "max",
                "optimized_variable": "keff",
                "pop_size": 60,
                "generations": 10,
                "mutation_probability": 0.23,
                "mating_probability": 0.46,
                "selection_operator": {"operator": "selTournament", "inds": 15, "tournsize": 5},
                "mutation_operator": {
                    "operator": "mutPolynomialBounded",
                    "eta": 0.23,
                    "indpb": 0.23,
                },
                "mating_operator": {"operator": "cxBlend", "alpha": 0.46},
            },
        }

    \end{minted}
    \caption{\acrfull{ROLLO} JSON input file to maximize $k_{eff}$ in the
    straightened \acrfull{AHTR} fuel slab by varying packing fraction distribution
    with control variables $a$, $b$, and $c$.}
    \label{fig:rollo-input-simple}
\end{figure}

\subsection{Hyperparameter Search}
\label{sec:hyperparameter_search}
In a \gls{ROLLO} input file, the user defines hyperparameters for the genetic
algorithm.
A good hyperparameter set guides the optimization process by
balancing exploitation and exploration to find an optimal solution quickly
and accurately.
Finding a good hyperparameter set requires a trial-and-error process.

I performed the hyperparameter search with a coarse-to-fine random sampling scheme,
whose advantages I previously discussed in Section \ref{sec:balance}.
The hyperparameters varied included population size, number of generations,
mutation probability, mating probability, selection operator, selection operator's
number of individuals, selection operator's tournament size, mutation operator,
and mating operator.
I started with 25 coarse experiments and fine-tuned the hyperparameters
with 15 more experiments.
For each genetic algorithm experiment, the number of OpenMC evaluations remained
constant at 600.
The number of evaluations correlated the population size and number of generations.
I randomly sampled population size and used the following equation to calculate
the number of generations:
\begin{align}
    \mbox{no. of generations} &= \frac{\mbox{no. of evaluations}}{\mbox{population size} }
\end{align}
Table \ref{tab:hyperparameter_search} shows the lower and upper bounds used
for randomly sampling each hyperparameter.
\begin{table}[]
    \centering
    \onehalfspacing
    \caption{Hyperparameter search is conducted in three phases: \textit{Coarse Search},
    \textit{Fine Search 1}, \textit{Fine Search 2}. Each hyperparameter's lower and
    upper bounds for each search phase are listed.}
	\label{tab:hyperparameter_search}
    \footnotesize
    \makebox[\textwidth][c]{\begin{tabular}{p{4cm}lp{3.4cm}p{3.4cm}p{3.4cm}}
    \hline
    \textbf{Hyperparameter}& \textbf{Type} & \textbf{Coarse Search Bounds} & \textbf{Fine Search 1 Bounds} & \textbf{Fine Search 2 Bounds} \\
    \hline
    Experiments & - & 0 to 24 & 24 to 34 & 35 to 39 \\
    \hline
    Population size (pop) & Continuous & 10 $<$ x $<$ 100 & 20 $<$ x $<$ 60 & 60 \\
    Mutation probability & Continuous & 0.1 $<$ x $<$ 0.4 & 0.2 $<$ x $<$ 0.4& 0.2 $<$ x $<$ 0.3\\
    Mating probability & Continuous & 0.1 $<$ x $<$ 0.6 &  0.1 $<$ x $<$ 0.3 &  0.45 $<$ x $<$ 0.6\\
    Selection operator & Discrete & \texttt{SelTournament}, \texttt{SelBest}, \texttt{SelNSGA2} & \texttt{SelTournament}, \texttt{SelBest}, \texttt{SelNSGA2}& \texttt{SelTournament}\\
    Selection individuals & Continuous & $\frac{1}{3}pop$ $<$ x $<$ $\frac{2}{3}pop$ & $\frac{1}{3}pop$ $<$ x $<$ $\frac{2}{3}pop$ & 15\\
    Selection tournament size (only for SelTournament) & Continuous & 2 $<$ x $<$ 8 &2 $<$ x $<$ 8&5\\
    Mutation operator & Discrete & \texttt{mutPolynomialBounded} &\texttt{mutPolynomialBounded}&\texttt{mutPolynomialBounded}\\
    Mating operator & Discrete& \texttt{cxOnePoint}, \texttt{cxUniform}, \texttt{cxBlend} &\texttt{cxOnePoint}, \texttt{cxUniform}, \texttt{cxBlend}&\texttt{cxOnePoint}, \texttt{cxBlend}\\
    \hline
    \end{tabular}}
\end{table}

The initial 25 coarse experiments' sought to narrow down the hyperparameters
to find a smaller set of hyperparameter bounds that produce higher $k_{eff}$ values.
Figure \ref{fig:hyperparameter_sens} shows the hyperparameters' plotted against
each other with a third color dimension representing the average $k_{eff}$ value
($\overline{k_{eff}}$) in each experiment's final generation.
Lighter scatter points indicate higher final population $\overline{k_{eff}}$ values,
which suggests better hyperparameter sets.
\begin{figure}[]
    \centering
    \makebox[\textwidth][c]{\includegraphics[width=1.3\linewidth]{hyperparameter_sens.png}}
    \caption{Coarse hyperparameters search's results. Hyperparameter values are plotted
    against each other with a third color dimension representing each experiment's
    final population's $\overline{k_{eff}}$.}
    \label{fig:hyperparameter_sens}
\end{figure}
I plotted the hyperparameters against each other to visualize the interdependence
between hyperparameters.
From the coarse hyperparameter search, I noticed the following trends:
\begin{itemize}
    \item Mutation probability has a higher $\overline{k_{eff}}$, between 0.2 and 0.4.
    \item Mating probability has a higher $\overline{k_{eff}}$, between 0.1 and 0.3.
    \item Population size has a higher $\overline{k_{eff}}$, between 20 and 60.
    \item No obvious interdependence between hyperparameters.
\end{itemize}

Next, I proceeded to the fine searches.
From Figure \ref{fig:hyperparameter_sens}, I narrowed down population size,
mutation probability, and mating probability bounds, as shown in Table
\ref{tab:hyperparameter_search}'s \textit{Fine Search 1 Bounds} column.
I found no significant trends in the other hyperparameters, so I left them
as is.
I ran ten more experiments (25 to 34), sampling hyperparameters from
the \textit{Fine Search 1 Bounds}.
From these results, I conducted a second fine search with five experiments
(35 to 39) with further tuned hyperparameter bounds, as shown in Table
\ref{tab:hyperparameter_search}'s \textit{Fine Search 2 Bounds} column.
I determined these new hyperparameter bounds based on these reasons:
\begin{itemize}
    \item Mutation probability has a higher $\overline{k_{eff}}$, between 0.2 and 0.3.
    \item I overlooked $\overline{k_{eff}}$  peaking at mating probability between
    0.45 and 0.6 in the previous \textit{Fine Search 1}, thus shifted the bounds.
    \item The highest $\overline{k_{eff}}$ occurred for \texttt{selTournament}.
    \item I narrowed down mating operator options to \texttt{cxBlend} and
    \texttt{cxOnePoint} since they had higher $\overline{k_{eff}}$.
    \item I selected arbitrary numbers for population size,
    selection individuals, and tournament size since they did not
    correlate with $\overline{k_{eff}}$ values.
\end{itemize}
Figure \ref{fig:input_hyperparameters_sens} shows the relationship between
hyperparameter values and $a$, $b$, $c$ control parameters, final generation
$k_{eff max}$, and final generation $\overline{k_{eff}}$.
The coarse experiments' scatter points are $50\%$ transparent, while the fine
experiments' scatter points are opaque.
\begin{figure}[]
    \centering
    \makebox[\textwidth][c]{\includegraphics[width=1.3\linewidth]{input_hyperparameters_sens.png}}
    \caption{Hyperparameters search's results for all 40 experiments (coarse
    and fine). I plotted the hyperparameters against: a,b,c control parameters,
    each experiment's final generation $k_{eff max}$, and final generation
    $\overline{k_{eff}}$ with a third color dimension representing each experiment's final
    population's $\overline{k_{eff}}$ (color bar representing the $k_{eff}$ values
    provided on the right side of the figure). Coarse experiments' (0 to 24) scatter points
    are $50\%$ transparent, while the fine experiments' (24 to 39) scatter points
    are opaque. }
    \label{fig:input_hyperparameters_sens}
\end{figure}
In Figure \ref{fig:input_hyperparameters_sens}, on average, the fine experiments
(opaque scatter points) have higher $\overline{k_{eff}}$, which indicates that the
hyperparameter search process met its objective of finding hyperparameter
bounds that enable quicker and more accurate optimization.

Table \ref{tab:topfive} shows the hyperparameters for the five experiments
with the highest final generation $\overline{k_{eff}}$.
\begin{table}[]
    \centering
    \onehalfspacing
    \caption{Control Parameters, $k_{eff}$ results, and hyperparameter values for
    the five hyperparameter search experiments with the highest final generation
    $\overline{k_{eff}}$.}
	\label{tab:topfive}
    \footnotesize
    \makebox[\textwidth][c]{\begin{tabular}{p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}}
    \hline
    & \multicolumn{5}{c}{\textbf{Experiment No.}} \\
    \cline{2-6}
    \textbf{Control/Output Parameters} & \textbf{6} & \textbf{15} & \textbf{24} & \textbf{36} & \textbf{39}\\
    \hline
    $\overline{k_{eff}}$ [-] & 1.39876 &1.40155&1.40118&1.39906&1.40165\\
    $k_{eff max}$ [-] & 1.40954 &1.40440&1.40365&1.40590&1.40519\\
    a [-] & 1.993&1.998&1.999&1.997&1.989\\
    b [$\frac{radians}{cm}$] & 0.057&0.367&0.320&0.339&0.354\\
    c [radians] & 3.571&3.022&3.615&3.053&3.143\\
    \hline
    \textbf{Hyperparameter}& &&&&\\
    Population size & 83 & 28&74&60&60\\
    Generations &8&22&9&10&10 \\
    Mutation probability & 0.32 &0.26&0.21&0.23&0.23\\
    Mating probability & 0.17 &0.53&0.48&0.59&0.46\\
    Selection operator & \texttt{selTournament} &\texttt{selTournament}&\texttt{selBest}&\texttt{selTournament}&\texttt{selTournament}\\
    Selection individuals & 38 &14&25&15&15\\
    Selection tournament size & 7 &5&-&5&5\\
    Mutation operator & \texttt{mutPolynomial} \texttt{Bounded}&\texttt{mutPolynomial} \texttt{Bounded}&\texttt{mutPolynomial} \texttt{Bounded}&\texttt{mutPolynomial} \texttt{Bounded}&\texttt{mutPolynomial} \texttt{Bounded}\\
    Mating operator & \texttt{cxOnePoint} &\texttt{cxOnePoint}&\texttt{cxUniform}&\texttt{cxBlend}&\texttt{cxBlend}\\
    \hline
    \end{tabular}}
\end{table}
Figure \ref{fig:topfiveplot} shows the packing fraction distributions that
produced the $k_{eff max}$ from the top five experiments.
\begin{figure}[]
    \centering
    \makebox[\textwidth][c]{\includegraphics[width=1\linewidth]{topfive_plot.png}}
    \caption{Packing fraction distribution across the x-axis of the \acrfull{AHTR}
    slab for the five hyperparameter search experiments with the highest final generation
    $\overline{k_{eff}}$. $k_{eff}$ uncertainty are $\sim$130pcm.}
    \label{fig:topfiveplot}
\end{figure}
Four experiments had similar packing fraction distributions peaking at approximately
0.23 in the slab's center.
In contrast, one experiment had an exponential-like distribution with a peak
packing fraction of 0.31 at the slab's side.
The similar final packing fraction distributions demonstrate genetic algorithms'
robustness to find the optimal global solutions with different hyperparameters.

I ran these simulations on the BlueWaters supercomputer \cite{ncsa_about_2017}.
In each \gls{ROLLO} simulation, each generation runs a population size number
of individual OpenMC simulations.
Each OpenMC simulation takes approximately 13 minutes to run on a single BlueWaters
XE node.
With approximately 600 OpenMC evaluations per \gls{ROLLO} simulation, the
\gls{ROLLO} simulation takes about 130 BlueWaters node-hours.
The hyperparameter search ran 40 \gls{ROLLO} simulations, thus using approximately
5200 node-hours.

\subsection{Results for Best Hyperparameter Set}
\label{sec:best}
I define the best-performing hyperparameter set as the experiment that produces
the highest $\overline{k_{eff}}$ in its final generation.
\textit{Fine Search 2}'s experiment 39 produces the best performing
hyperparameter set, shown in Table \ref{tab:topfive}, with
center-peaking packing fraction distribution of $max(k_{eff}) = 1.40519$.
Experiment 39's $k_{eff max}$ exceeds the original straightened \gls{AHTR}
configuration's $k_{eff}$ by $\sim2000$pcm, demonstrating that optimizing
inhomogenous fuel distributions enables better neutronics.
Figure \ref{fig:triso_distribution_sine_39} shows the packing fraction distribution
that produced $k_{eff max} = 1.40519 \pm 0.00130$.
\begin{figure}[]
    \centering
    \makebox[\textwidth][c]{\includegraphics[width=1.1\linewidth]{triso_distribution_sine_39.png}}
    \caption{Experiment 39 packing distribution that produced $k_{eff max} = 1.40519 \pm 0.00130$.
    Below: $PF(x) = (1.98\ sin(0.35x+3.14)+2)  \times NF$ sine distribution with
    red points indicating the packing fraction at each cell.
    Above: Straightened \acrfull{AHTR} fuel slab with varying \gls{TRISO} particle
    distribution across ten cells based on the sine distribution. }
    \label{fig:triso_distribution_sine_39}
\end{figure}

Figures \ref{fig:keff_conv_39} and \ref{fig:pf_39} show the $k_{eff}$ evolution
and packing fraction distribution through the best performing 39$^{th}$
experiment's generations.
\begin{figure}[]
    \centering
    \begin{subfigure}{\textwidth}
    \makebox[\textwidth][c]{\includegraphics[width=1.1\linewidth]{keff_conv_39.png}}
    \caption{Minimum, average, and maximum $k_{eff}$ value evolution.}
    \label{fig:keff_conv_39}
    \end{subfigure}
    \begin{subfigure}{\textwidth}
        \makebox[\textwidth][c]{\includegraphics[width=1.1\linewidth]{pf_39.png}}
        \caption{$k_{eff max}$ packing fraction distribution evolution.}
        \label{fig:pf_39}
    \end{subfigure}
    \caption{Each generation's results for \gls{ROLLO}'s genetic algorithm
    optimization of the Straightened \acrfull{AHTR} Fuel Slab. The \gls{ROLLO}
    simulation used the 39$^{th}$ experiment's hyperparameter set. $k_{eff}$
    uncertainty are $\sim$130pcm.}
    \label{fig:39}
\end{figure}
The $k_{eff max}$ converged quickly by generation 1; however, this usually
does not occur.
The genetic algorithm optimizes stochastically, resulting in the possibility
that the algorithm randomly samples a control parameter set that maximizes
the objective function early in the optimization process.
The $\overline{k_{eff}}$ demonstrates how each generation's average $k_{eff}$
converges towards a higher value with each generation's improvements.
To demonstrate how the genetic algorithm optimization process usually goes,
Figures \ref{fig:keff_conv_15} and \ref{fig:pf_15} show the $k_{eff}$ evolution
and packing fraction distribution through the second-best performing 15$^{th}$
experiment's generations.
Experiment 15 demonstrates how both maximum and average $k_{eff}$ converge
towards a higher $k_{eff}$ with improvements from each generation.
\begin{figure}[]
    \centering
    \begin{subfigure}{\textwidth}
    \makebox[\textwidth][c]{\includegraphics[width=1.1\linewidth]{keff_conv_15.png}}
    \caption{Minimum, average, and maximum $k_{eff}$ values evolution.}
    \label{fig:keff_conv_15}
    \end{subfigure}
    \begin{subfigure}{\textwidth}
        \makebox[\textwidth][c]{\includegraphics[width=1.1\linewidth]{pf_15.png}}
        \caption{$k_{eff max}$'s packing fraction distribution evolution.}
        \label{fig:pf_15}
    \end{subfigure}
    \caption{ Results for each generation for \gls{ROLLO}'s genetic algorithm optimization
    of the Straightened \acrfull{AHTR} Fuel Slab. The \gls{ROLLO} simulation used
    the 15$^{th}$ experiment's hyperparameter set. $k_{eff}$ uncertainty are $\sim$130pcm.}
    \label{fig:15}
\end{figure}

In both Experiments 39 and 15, packing fractions peaked at approximately
0.23 in the slab center and decreased to zero at the sides.
The amplitude, $a$, for the packing fraction distribution that produced $k_{eff max}$
for Experiment 39 and the other top-five experiments (Table \ref{tab:topfive})
have settled at the upper bound of approximately 2.
A large sine distribution amplitude, $a$, demonstrates that a slab geometry
with larger packing fraction variations results in a higher $k_{eff}$.
These observations about packing fraction distribution for $k_{eff max}$ are
consistent with conclusions from the \gls{FHR} benchmark (Chapter
\ref{chap:fhr-benchmark}): a high $k_{eff}$ occurs with a good balance between
fuel loading and moderation space.
Fission occurs at high \gls{TRISO} particle concentration areas at thermal flux;
however, the neutrons are born at fast flux and require moderation to slow down
to thermal ranges.
Therefore, larger moderation areas ensure higher resonance escape probability for
the fast neutrons resulting in higher thermal flux, leading to more
fission occurring and a higher $k_{eff}$.

I also observed that \gls{TRISO} particle packing fraction peaks in the center
of the slab, showing that if the optimization problem focuses purely on the
slab's neutronics by maximizing $k_{eff}$, the fuel tends to culminate in the
middle.
Center-peaking fuel density is nonideal for other key reactor core
qualities, such as maximal heat transfer and minimal power peaking factor (PPF).
Thus, the \gls{AHTR} slab optimization problem must be extended to include
these key reactor core qualities.

\section{AHTR Multiphysics Model Preliminary Work}
\label{sec:multiphysics_homo}
% compare TRISO particles
In the proposed PhD scope, I will use the open-source simulation tool, Moltres,
to conduct \gls{AHTR} multiphysics simulations.
Moltres, an application built atop the \gls{MOOSE} parallel finite element
framework \cite{gaston_moose:_2009}, contains physics kernels and boundary
conditions to solve arbitrary-group deterministic neutron diffusion and
thermal-hydraulics \glspl{PDE} simultaneously on a single mesh
\cite{lindsay_introduction_2018,park_advancement_2020}.
\gls{AHTR} Moltres simulations will capture thermal feedback effects, absent
from the purely neutronics OpenMC simulations.
The objective of setting up the Moltres \gls{AHTR} simulation is to eventually
couple Moltres with \gls{ROLLO} for \gls{AHTR} multiphysics optimization.

The benefits of Moltres over other multiphysics software, RELAP5 and NESTLE
(used previously for \gls{AHTR} modeling and described in Section
\ref{sec:previous_ahtr}) for the purposes of this work, for coupled neutronics
and thermal-hydraulics simulation are:
\begin{itemize}
  \item Moltres supports up to 3-D meshes, solving neutron diffusion and
  thermal-hydraulics \glspl{PDE} simultaneously on the same mesh
  \cite{park_advancement_2020}. This is much more flexible than
  \gls{NESTLE} and RELAP5, which only support rectangular and hexagonal assembly
  lattices. Therefore, Moltres can explore arbitrary reactor geometries easily.
  \item Moltres tightly couples neutronics and thermal-hydraulics, thus providing
    higher accuracy in some tightly coupled problems.
  \item Moltres, a \gls{MOOSE}-based application, uses MPI for parallel computing,
  and compiles and runs on \glspl{HPC}.
\end{itemize}

To run Moltres simulations, the user provides group constant data from a neutron
transport solver, such as OpenMC, for the Moltres multigroup neutron diffusion
calculations and a mesh file representing the reactor geometry.
A TRISO-level fidelity mesh file is impractical and will result in an extremely
long Moltres runtime.
For successful \gls{AHTR} Moltres simulation, I must establish
suitable spatial and energy homogenization that preserves accuracy while
maintaining an acceptable runtime.

\subsection{Straightened AHTR Fuel Slab Multigroup Simulation}
I use the continuous energy OpenMC simulation to generate
multigroup cross section data defined over discretized energy groups
and spatial segments.
I then use OpenMC's multigroup calculation mode with the previously generated
multigroup cross section data to calculate $k_{eff}$.
Comparison of $k_{eff}$ for the continuous and multigroup simulations
determines if the energy and spatial homogenization used are acceptable.

In this section, the straightened AHTR fuel slab simulations use the \gls{TRISO}
particle distribution that generated $k_{eff max}$ from the best hyperparameter
set (Section \ref{sec:best}).
For spatial homogenization of the straightened \gls{AHTR} fuel slab, I used
OpenMC's \textit{cell} domain type to compute multigroup cross sections for
different \textit{cells}.
I discretized the slab into 13 \textit{cells}: FLiBe, left graphite, right
graphite, and ten fuel cells (each cell has a different packing fraction).
Figure \ref{fig:straightened_slab_mg} illustrates the \gls{AHTR} spatial
homogenization for the OpenMC multigroup calculation.
\begin{figure}[]
    \centering
    \includegraphics[width=\linewidth]{straightened_slab_mg.png}
    \raggedright
    \resizebox{0.5\textwidth}{!}{
        \hspace{1cm}
        \fbox{\begin{tabular}{llll}
            \textcolor{fhrblue}{$\blacksquare$} & FLiBe &
            \textcolor{fhrgrey}{$\blacksquare$} & Left Graphite \\
            \textcolor{fhrred}{$\blacksquare$} & Right Graphite &
            \textcolor{fhrpink}{$\blacksquare$} & Fuel cell 1/6 \\
            \textcolor{fhryellow}{$\blacksquare$} & Fuel cell 2/7 &
            \textcolor{fhrorange}{$\blacksquare$} & Fuel cell 3/8 \\
            \textcolor{fhrgreen}{$\blacksquare$} & Fuel cell 4/9 &
            \textcolor{fhrpurple}{$\blacksquare$} & Fuel cell 5/10 \\
            \end{tabular}}}
    \caption{Straightened \acrfull{AHTR} fuel slab spatially discretized into
    13 \textit{cells} for OpenMC multigroup calculation.}
    \label{fig:straightened_slab_mg}
\end{figure}
I used the four group energy structure derived by Gentry et al.
\cite{gentry_development_2016} for \gls{AHTR} geometries.
Table \ref{tab:energy_structures} defines the group boundaries.
\begin{table}[]
    \centering
    \onehalfspacing
    \caption{4-group energy structures for \acrfull{AHTR} geometry
    derived by \cite{gentry_development_2016}.}
	\label{tab:energy_structures}
    \footnotesize
    \begin{tabular}{lll}
    \hline
    \multicolumn{3}{c}{\textbf{Group Boundaries [MeV]}} \\
    \hline
    \textbf{Group $\#$}& \textbf{Upper Bound} & \textbf{Lower Bound}  \\
    \hline
    1 & $2.0000\times 10^1$ & $9.1188\times 10^{-3}$ \\
    2 & $9.1188\times 10^{-3}$ & $2.9023\times 10^{-5}$\\
    3 & $2.9023\times 10^{-5}$ & $1.8554\times 10^{-6}$\\
    4 & $1.8554\times 10^{-6}$ & $1.0000\times 10^{-12}$\\
    \hline
    \end{tabular}
\end{table}

Table \ref{tab:keff_multigroup} shows the $k_{eff}$ values from the continuous
energy simulation and the spatial and energy homogenized simulation.
The 26pcm difference between $k_{eff}$ values is within both uncertainty values,
assuring that the spatial and energy homogenization used is suitable for generating
group constants for Moltres.
\begin{table}[]
    \centering
    \onehalfspacing
    \caption{Straightened \acrfull{AHTR} fuel slab's $k_{eff}$ for case with
    continuous energy and space and case with spatial and energy homogenization.
    Both simulations were run on one BlueWaters XE Node, with 80 active cycles,
    20 inactive cycles, and 8000 particles.}
	\label{tab:keff_multigroup}
    \footnotesize
    \begin{tabular}{lll}
    \hline
    \textbf{Homogenization}& \textbf{$k_{eff}$} & \textbf{Simulation time [s]}  \\
    \hline
    None & $1.40473 \pm 0.00115$ & 808\\
    Spatial and Energy & $1.40499 \pm 0.00109$ & 50\\
    \hline
    \end{tabular}
\end{table}

\section{Summary}
This chapter demonstrated the preliminary work completed for \gls{AHTR}
optimization.
I conducted a multigroup \gls{AHTR} slab simulation with four-group energy
and spatial homogenization, which resulted in $k_{eff}$ within the uncertainty of
the continuous energy simulation.
The minimal $k_{eff}$ difference assures that I can use these homogenizations
when generating group constants for Moltres.
I also successfully applied \gls{ROLLO} to maximize $k_{eff}$ in a straightened
\acrfull{AHTR} fuel slab by varying the \gls{TRISO} particle packing fraction
distribution.
The optimization process began with a coarse-to-fine random sampling
hyperparameter search to find the genetic algorithm hyperparameters that worked
best.
Experiment 39 performed the best with a hyperparameter set that produced the
highest final generation $\overline{k_{eff}}$ of 1.40165 $\pm$ 0.00130.
The \gls{TRISO} particle packing fraction distribution that produced the final
generation's maximum $k_{eff}$ of 1.40519 peaks at the slab's center with
packing fraction distribution: $PF(x)=1.989\ sin(0.54x+3.143)$.
This demonstration problem had a single objective function of maximizing
$k_{eff}$.
However, many other objectives should be considered, such as maximizing heat
transfer and minimizing power peaking factor.
Thus, in the next chapter, I propose future simulations for optimizing
these objective functions simultaneously.


\chapter{Modeling  the heterogeneity of the Dox-induced GFP (or mCherry) expressions} % Main chapter title

\label{Part3_chapter} % For referencing the chapter elsewhere, use \ref{Chapter1}

\section{The model}
In order to access the heterogeneity of Dox-induced single-cell expressions in both feedback and no-feedback systems, we model the random ﬂuctuation in biochemical reactions, random copy number variation and random epigenetic inheritance in expression systems.

\subsection{Random epigenetic inheritance}

Random epigenetic inheritance also plays an important part of ﬂuctuation in cell population. I incorporate random epigenetic inheritance on single cell level. Epigenetic regulations, including DNA methylation, histone modiﬁcation and others, inﬂuence gene expression by regulating chromatin accessibility and the interaction between DNA and protein. In the model, the reaction constants of each transcription was influenced by a random variable $\mu$ which subscribes to normal distribution.

Where:

\begin{equation}
\begin{aligned}
\centering
% \underset{A}{B}
% \overset{…}{…}
K_{real}   &= K_{deterministic} \times (1+\mu_1) \\
k_{d-real} &= k_{d-deterministic} \times (1+\mu_2) \\
r_{real}   &= r_{deterministic} \times (1+\mu_3) \\
\beta_{real}   &= \beta_{deterministic} \times (1+\mu_4) \\
\end{aligned}
\end{equation}

\subsection{Random copy number variance}

Random copy number variance is an important source of noise in cell population. We incorporate random copy number variation on single cell level. In the modeling, the copy number was considered in the $\alpha$, which was influenced by a random variable $\tau$ which subscribes to normal distribution.

Where:

\begin{equation}
\begin{aligned}
\centering
% \underset{A}{B}
% \overset{…}{…}
\alpha_{real}   &= \alpha_{deterministic} \times (1+\tau) \\
\end{aligned}
\end{equation}

\subsection{Random basal expression level of GFP, mCherry and tetR-dimer}

Random copy number variance is an important source of noise in cell population. We incorporate random copy number variation on single cell level. In the modeling, the basal expression level of GFP, mCherry and free tetR-dimer were influenced by a random variable $\xi$ which subscribes to normal distribution.

Where:

\begin{equation}
\begin{aligned}
\centering
% \underset{A}{B}
% \overset{…}{…}
[GFP]_{0-real}   &= [GFP]_{0-deterministic} \times (1+\xi_1) \\
[mCherry]_{0-real}   &= [mCherry]_{0-deterministic} \times (1+\xi_2) \\
[R^2_0]_{0-real}   &= [R^2_0]_{0-deterministic} \times (1+\xi_3) \\
\end{aligned}
\end{equation}

%----------------------------------------------------------------------------------------
\section{Simulate the flow cytometry data with simulations of 1000 cells}

Combing the factors of random ﬂuctuation in biochemical reactions, random copy number variance and random epigenetic inheritance described above, we establish model to study the heterogeneity of Dox-induced single-cell expressions in both feedback and no-feedback systems. For each doxycycline concentration, we stimulate 1000 single cells.

\subsection{Heterogeneity of Dox-induced single-cell expressions, without feedback}

For the heterogeneity of Dox-induced single-cell expressions of GFP without feedback, the stimulation result is as follows:

\begin{figure}[H]
\centering
\includegraphics[width=1.0\linewidth]{Figures/Q3_1.png}
\caption{Cytometry simulations of Dox-induced GFP expression \\ system without feedback in 1000 cells}
\label{part_3_1}
\end{figure}

From the ﬁgure we can see that for each concentration of doxycycline, the GFP expression in cell population is like a normal distribution. At low concentration of doxycycline, increasing doxycycline concentration would not cause much to distribution of GFP expression, this is because at this stage there is surplus of tetR dimer in addition to binding most of tetO. At higher concentration of doxycycline, increasing doxycycline concentration would not cause much change to the distribution of GFP expression, this is because at this stage the doxycycline is enough to bind most of the tetR dimer.

\subsection{Heterogeneity of Dox-induced single-cell expressions, with feedback}

For the heterogeneity of Dox-induced single-cell expressions of mCherry with feedback, the result is as follows:

\begin{figure}[H]
\centering
\includegraphics[width=1.0\linewidth]{Figures/Q3_2.png}
\caption{Cytometry simulations of Dox-induced mCherry expression \\system with feedback in 1000 cells ($log10 \approx 3.2$)}
\label{part_3_2}
\end{figure}

From the ﬁgure we can see that for each concentration of doxycycline, the mCherry expression in cell population is like a normal distribution. As the concentration of doxycycline increase, the mean of mCherry expression show a steady increase. This is because there is a negative feedback control loop in this system, increasing the concentration of doxycycline will always lead to the system to reach a new equilibrium.

%----------------------------------------------------------------------------------------
\newpage
\section{Discussion}
In this session, we discuss the result and compare our results with the experiment result.

For part1, our result looks very similar to the experiment result, including the initial value, the end value and the turning point. At low concentration of doxycycline, increasing doxycycline concentration would not cause much difference to GFP expression, this is because at this stage there is surplus of tetR dimer in addition to binding most of tetO. At higher concentration of doxycycline, increasing doxycycline concentration would not cause much to GFP expression too, this is because at this stage the doxycycline is enough to bind most of the tetR dimer. This system is responsive to doxycycline only in a narrow range of doxycycline concentration, and the response is ultrasensitive.

For part2, our result also looks very alike to the experiment result, including the initial value and the end value. As the concentration of doxycycline increase, the mean of mCherry expression show a steady increase. This is because there is a negative feedback control loop in this system, increasing the concentration of doxycycline will always lead to the system to reach a new equilibrium. This system is sensitive to a wide range doxycycline and it is easy to tune to achieve precise and quantitate control mCherry expression.

We combine the result of part1 and part2 together, the result is as follows:

\begin{figure}[H]
\centering
\includegraphics[width=0.8\linewidth]{Figures/Q3_3.png}
\caption{The modeling results for GFP without feedback \\ and mCherry with feedback}
\label{part_3_3}
\end{figure}

The system without feedback is ultrasensitive to doxycycline in a narrow concentration range, while the system with feedback is sensitive to a wide range doxycycline and it is easy to tune to achieve precise and quantitate control mCherry expression. The difference is due to the feedback control: It can control the equilibrium of the reaction and stabilize the system, thus the system with feedback is responsive to wider range of doxycycline concentration, and increasing the concentration of doxycycline will lead to gentle change in target gene expression.

For part3, our modeling result of the system without feedback has similar mean value of the distribution comparing with the experiment result. But at higher concentration of doxycycline, the distribution of experiment result has heavier tail than our modeling result. We hypothesis that the difference is due to some unknown biological pathways. For instance, at higher concentration of doxycycline, some other biological pathways are affected thus lead to the heavier tail in the distribution of experiment result. In addition, our modeling result of system with feedback is similar to the experiment result, both in mean value and distribution shape.


When trying to analyze a program, the user sometimes needs to fully understand how the results were calculated. Especially, if he aims to use them to improve his code. Therefore, we will discuss \suaca's most important algorithms in this chapter. We will first explain the individual steps and fit them together in the end.

\section{Dependency Analysis}
\label{sec:depanalysis}

\subsection{Single Iteration}

Here we want to take a look at the algorithm that computes the dependency graph. \\
First we want to discuss a simpler version that ignores the control flow of the program.

\begin{algorithm}[H]
    \SetAlgoLined
    \caption{Dependency analysis without control flow}
    \label{alg:depsingle}
    \SetKwFunction{dep}{dep\_analysis}
    \SetKwProg{Fn}{Function}{:}{\textbf{end}}
    \Fn{\dep{instructionlist inst\_list}}{
        Map $:=$ map from register to line\;
        DG $:=$ Graph that has the same nodes as CFG, but no edges\;
        \ForEach{instruction $i$ in inst\_list} {
             \ForEach{register\_operand $r$ in operands($i$)} {
                 \eIf{is\_read($r$)} {
                     DG.add\_edge(Map[$r$], line\_of($i$))\;
                 }{
                    Map[$r$] = line\_of(i)\;
                }
            }
        }
        \Return DG\;
    }
\end{algorithm}

\newpage

Where
\begin{itemize}
    \item \emph{Map} maps each register to the last line with a write access.
    \item \emph{operands(i)} returns a list of all operands of instruction $i$. A register that is first read then written to will be contained twice. The order will be first read then write access.
    \item \emph{is\_read(r)} returns true if the operand $r$ will be read and false if it will be written to.
    \item \emph{line\_of(i)} returns the line of instruction $i$ in the original program.
\end{itemize}

This algorithm will iterate over all instructions in program order. For each instruction $i$ it will then iterate over all of its operands. For each operand it will check if it is accessed via read or write. If it is written to, the algorithm will map the register to the current line. If it is read, the algorithm will add an edge from the last write access to the current line.\\

The runtime of this algorithm is $\mathcal{O}(n*m)$ where $n$ is the number of instructions and $m$ the maximum number of operands that occur in the program.\\

Note that we consider every operand as a register. In practice, an operand can of course be a memory address. In this case \suaca\ will extract all registers from that address and treat them as read operands. \suaca\ does not support memory dependencies so far as we would need to keep track of the whole memory. As we have seen in \autoref{fig:wloop}, \suaca\ is able to differentiate between the different flags. For readability we ignore the special case of the \emph{RFLAGS} register here.

Now we want to take a look at the control flow sensitive algorithm that \suaca\ actually uses.
\newpage

\begin{algorithm}[H]
    \SetAlgoLined
    \caption{Control flow sensitive dependency analysis}
    \label{alg:dep}
    \SetKwFunction{deps}{dep\_analysis\_start}
    \SetKwFunction{dep}{dep\_analysis}
    \SetKwProg{Fn}{Function}{:}{\textbf{end}}
    \Fn{\deps{CFG}}{
        Map $:=$ map from register to line\;
        DG $:=$ graph that has the same nodes as CFG, but no edges\;
        Node $:=$ startnode of CFG\;
        \dep{CFG, DG, Map, Node}\;
        \Return DG\;
    }
    \SetKwProg{Fn}{Function}{:}{\textbf{end}}
    \Fn{\dep{CFG, DG, Father-Map, Node}}{
        Map $:=$ copy of Father-Map\;
        \While{true} {
            \ForEach{register\_operand $r$ in operands(instruction\_of(Node))} {
                \eIf{is\_read($r$)} {
                    DG.add\_edge(Map[$r$], line\_of($i$))\;
                }{
                    Map[$r$] = line\_of(i)\;
                }
            }
            \If{num\_successors(CFG, Node) = 0}{\Return;}
            Node = successor(CFG, Node, 0)\;
            \If{num\_successors(CFG, Node) $>$ 1} {
                \dep{CFG, DG, Map, successor(CFG, Node, 1)}\;
            }
        }
    }
\end{algorithm}
\vspace{5pt}

Where
\begin{itemize}
    \item \emph{DG} has a Node for every instruction in the program. Just like the CFG.
    \item \emph{instruction\_of(Node)} returns the instruction that Node represents.
    \item \emph{num\_successors(Graph, Node)} returns the number of successors of \emph{Node} in the Graph.
    \item \emph{successor(Graph, Node, i)} returns the $i^{th}$ successor of $Node$ in the Graph.
\end{itemize}

This time we will ``climb along'' the $CFG$. If we never face a branch i.e., \emph{num\_successors()} never returns a value greater than $1$, this algorithm will do exactly the same as the one we have just seen.\\
In the case of \emph{num\_successors()} $> 1$ we will make another call of \emph{dep\_analysis()} on the ``right branch''. From this point on, there will be two analyses, one for every branch in the $CFG$. Each analysis has its own $Map$ since there can be different writes on each branch. Note that we will not join the two analyses as we would need to find the first mutual descendant.\\
In the worst case every instruction is a branch, so we would spawn a new function for each of them. This leads to a runtime of $\mathcal{O}(n^2*m)$.\\

We assume no backbranches i.e., no loops, in the program for the above mentioned algorithm. In practice, \suaca\ will simply check for each branch if it is a backbranch, and should the situation arise ignore it.

\subsection{Multiple Iterations}

When ordering \suaca\ to run the program in multiple loops we need to adjust the dependency analysis algorithm as this can cause some ``loop dependencies''. In order to solve this, we will simply consider the program twice. So we will append a copy of the program to itself, compute the $CFG$ and afterwards run the above mentioned algorithm. Because we know the original length of our program, we can extract all ``loop dependencies'' from the resulting dependency graph.

\section{Simulation of the Front-End}
\label{sec:simfrontend}

Although our main task is to simulate the scheduler we still want to consider the front-end in our analysis. Depending on the microarchitecture, the front-end is able to produce a certain amount of \microops\ each cycle. For example, the Sandy Bridge architecture will produce at most $4$ \microops\ per cycle. However, we still have to acknowledge the capacity of the scheduler since the front-end might be faster than the execution itself. The scheduler of the Sandy Bridge architecture has a maximum capacity of $54$ \microops.\\
We will now briefly discuss how our simulation actually performs those loads.
\newpage

\begin{algorithm}[H]
    \SetAlgoLined
    \caption{Load instructions into scheduler}
    \SetKwFunction{dep}{load\_instructions}
    \SetKwProg{Fn}{Function}{:}{\textbf{end}}
    \Fn{\dep{instruction\_queue queue}}{
        Waiting $:=$ first element of queue that is not fully loaded\;
        Loadable $:= max(Loads\ per\ cycle, remaining\ space\ in\ station)$\;
        \While{Loadable $> 0$} {
            loaded $:=$ load\_\microops(Waiting, Loadable)\;
            Loadable = Loadable $-$ loaded\;
        }
    }
\end{algorithm}
\vspace{5pt}
Where
\begin{itemize}
    \item \emph{queue} is a queue of all instructions that still have to be executed.
    \item \emph{Waiting} is initially set by searching for the first element in queue that has not been loaded into the scheduler by the front-end.
    \item \emph{load\_\microops(Waiting, $x$)} loads $x$ \microops\ of \emph{Waiting} and returns the number of \microops\ that were actually loaded.
\end{itemize}

So it is possible that an instruction is partially (i.e., only some of its \microops) loaded into the scheduler.

\section{Choosing the Ports}
\label{sec:chooseport}

In this section we are going to discuss how exactly the ports which an instruction uses are chosen. As we have seen in \autoref{sec:measurements} we know of how many \microops\ an instruction consists and which ports those \microops\ can use. As seen in \autoref{sec:simfrontend}, an instruction can be loaded partially, which we will have to consider here.\\
The following algorithm contains several crucial details to the simulation. First we will see how \suaca\ tries to distribute all \microops\ equally over all ports. It also demonstrates the exact situations in which we will execute an instruction. Lastly it explains how the \emph{had to wait} and \emph{caused to wait} columns we introduced in \autoref{sec:plain} are computed.
\newpage

\begin{algorithm}[H]
    \SetAlgoLined
    \caption{Choose ports for loaded instructions}
    \label{alg:choose}
    \SetKwFunction{dep}{choose\_ports}
    \SetKwProg{Fn}{Function}{:}{\textbf{end}}
    \Fn{\dep{instruction\_queue queue}}{
        \While{loaded\_\microops(Instruction) $> 0$} {
            \eIf{\textbf{not} all\_dependencies\_resolved(Instruction)} {
                Instruction.has\_to\_wait++\;
                \ForEach{Father $\in$ direct\_predecessors(Instruction)} {
                    Father.caused\_to\_wait++\;
                    Father.caused\_to\_wait\_depedency(Instruction)++\;
                    Instruction.had\_to\_wait\_depedency(Father)++\;
                }
            } {
                Executable $:= true$\;
                \If{\textbf{not} is\_fully\_loaded(Instruction)}{Executable $= false$\;}
                \ForEach{\microop\ $\mu$ $\in$ loaded\microops(Instruction)} {
                    Success $:=$ assign\_to\_ports($\mu$)\;
                    \If{\textbf{not} Success} {
                        Executable $= false$\;
                    }
                }
                \eIf{Executable} {
                    add\_to\_executionlist(Instruction)\; \label{line:if}
                }{
                    Blamed $:=$ Set of instructions\; \label{line:else}
                    \ForEach{p $\in$ blocked\_ports(Instruction)} {
                        \If{\textbf{not} Blamed.contains(p.using\_instruction())} {
                            p.using\_instruction().caused\_to\_wait++\;
                            p.using\_instruction().caused\_to\_wait\_port(p)\;
                            Instruction.had\_to\_wait\_port(p)\;
                            Blamed.add(p.using\_instruction())\;
                        }
                    }
                    Instruction.has\_to\_wait++\;
                }
            }
            Instruction $=$ queue.next(Instruction)\;
        }
    }
\end{algorithm}

~\\[-1em]
\begin{algorithm}[H]
    \SetAlgoLined
    \caption{Assign \microop\ to port}
    \label{alg:assign}
    \SetKwFunction{dep}{assign\_to\_ports}
    \SetKwProg{Fn}{Function}{:}{\textbf{end}}
    \Fn{\dep{\microop\ $\mu$}}{
        \ForEach{p $\in$ port\_queue} {
            \If{$\mu$.can\_use(p) \textbf{and} p.is\_free()} {
                p.uses($\mu$)\;
                \Return $true$\;
            }
        }
        \Return $false$\;
    }
\end{algorithm}
\vspace{5pt}

\autoref{alg:choose} iterates over all instructions in program order as long as the current instruction is at least partially loaded into the scheduler. For each instruction it will first check if all of its dependencies have been resolved i.e., all predecessors in the dependency graph have finished their execution (or at least produced the needed results). If not, it cannot be executed and the delay counters have to be increased. Notice that we have separate counters for the cumulative delays and the special delays (e.g. caused\_to\_wait\_depedency(), caused\_to\_wait\_port(p)), which are only needed for the detailed analysis (\autoref{sec:detail}). We will see the same behavior for the ports and this explains why the special delays will not always sum up to the cumulative ones.\\
If all dependencies have been resolved, \suaca\ will try to assign all \microops\ of the instruction to a port. To achieve this the algorithm will iterate over all \microops\ that have been loaded into the scheduler. Note that this will ignore all \microops\ that have been put into a port already. So if all \microops\ of an instruction are currently in the port pipeline this algorithm will basically just put the instruction into the execution list.\\
The function \emph{assign\_to\_ports(\microop, Instruction)} is described in \autoref{alg:assign}. This function will iterate over all ports in prior usage order and assign the \microop\ if possible. More precisely \emph{port\_queue} contains all ports and is sorted by usage throughout the whole simulation. If possible it will assign the \microop\ to the port and return a success. If no usable port was free it will return a fail.\\
We can observe that this is a greedy algorithm that is obviously not optimal in regards to the distribution of all \microops\ over the ports. However, we assume that this greedy algorithm comes close to what the schedulers are doing in reality.\\
If the assignment or the load of a single \microop\ failed the flag \emph{Executable} will be set to \emph{false}. As we can see in \autoref{line:if} the instruction will only be added to the execution list (which we will further discuss in \autoref{sec:execute}) if this flag is set. This means that an instruction will not be executed as soon as a single port was blocked. Note that an instruction can not block itself i.e., if all blocked ports were blocked by a \microop\ of the same instruction this function will still return \emph{true}. We did not include this special case here for the sake of readability.\\
We have to be this strict, because of our measurements. As we have seen in \autoref{sec:measurements} those will always contain the best case for latency. The biggest problem we face here is the missing information about the \microops. We do not know anything about the dependencies between them and so we do not know if there is an order in which those have to be executed, or if they can be executed simultaneously. So we have to assume a delay as soon as a single \microop\ is denied a port although that might not actually be the case in reality. This means that we will potentially overestimate the latency of a single instruction or the whole program. It is possible though that \suaca\ will actually underestimate the latency of a program as one can note in the following examples.\\

Consider two instructions \emph{X} and \emph{Y}. \emph{X} consists of two \microops\, one of which can use port $0$, and the other can use port $1$. \emph{Y} only consists of one \microop\ which can use port~$1$. \emph{X} is in front of \emph{Y} in program order, both are fully loaded, not dependent on each other and have a latency of $2$ cycles.\\
For this example we assume that the second \microop\ (port $1$) of \emph{X} depends on the first (port $0$). The problem is that \suaca\ does not have this information. So the simulation will do the following: In the first cycle it will assign \emph{X} to ports $0$ and $1$. There is no port left for \emph{Y} so it will not be added to the execution list. This will happen in the second cycle and as \emph{Y}'s latency was two cycles \suaca\ will compute a total latency of three cycles (as \emph{X} was executed in the first and second).\\
However, in reality \emph{X} will not block port $1$ in the first cycle as this particular \microop\ depends on the one that uses port $0$. So in the first cycle \emph{X} will only use port $0$. \emph{Y} can then freely use port $1$. In the second cycle \emph{X} can then use port $1$. No port was ever blocked so there simply will be no delay, both instructions could be executed simultaneously. So the ``real latency'' of our example would be two cycles.\\

Now we will consider the same example but with switched instruction order of \emph{X} and \emph{Y}. In this case \suaca\ will first assign \emph{Y}'s \microop\ to port $1$. It will then try to assign \emph{X}, but it will only be able to assign the first \microop\ to port $0$ as port $1$ is blocked. As discussed before \emph{X} will therefore not be added to the execution list. In the second cycle the leftover of \emph{X} will be assigned to a port and the execution will start. As the latency was two cycles the simulation will stop after the third cycle.\\
Again this is an overestimation of the reality. Due to the dependency of the second \microop\ of \emph{X} it does not matter that \emph{Y} blocks port $1$ in the first cycle. \emph{X} only needs port $0$ in the first cycle and in the second cycle it can then freely use port $1$. Again the ``real latency'' of our example would be two cycles.\\

Finally we will construct an example were our simulation actually underestimates the throughput. We can once more use our two instructions \emph{X} and \emph{Y}. This time we assume that \emph{Y} cannot be executed in the first cycle, because of a dependency on an arbitrary third instruction. Our simulation basically works like in our first case, except for the reason why \emph{Y} cannot be executed. So it will compute a latency of three cycles for those two instructions.\\
In reality \emph{Y} will be denied port $1$ in the second cycle as it will be used by \emph{X}. So the execution will start in the third cycle and end in the fourth.\\

Note that it is still impossible that the latency of a single instruction is underestimated as we will always simulate the execution of at least as many cycles as we measured under a best case scenario. Also an important detail is, that it is impossible for an instruction to block itself. So if multiple \microops\ of a single instruction need to use the same port this will not cause a delay. This is again due to the measurements as the delay caused by ``inner instructional port blockings'' is already included in the best case runtime. We did not include this in the pseudo code above for the sake of readability.\\

Ultimately we will consider the rest of the algorithm starting in \autoref{line:else}. This part will increase the counters similarly to what we have seen at the start of the algorithm. Notable here is the function \emph{blocked\_ports(Instruction)} that will return all ports that have been blocked during the assignment phase as well as the \emph{Blamed} set which ensures that every instructions is held responsible at most once. We need this as we want to count the number of cycles that an instruction caused a delay and not the number of blocked ports in a particular cycle.

\newpage

\section{Executing Applicable Instructions}
\label{sec:execute}

\begin{algorithm}[H]
    \SetAlgoLined
    \caption{Execute applicable instructions}
    \label{alg:execute}
    \SetKwFunction{dep}{execute\_instructions}
    \SetKwProg{Fn}{Function}{:}{\textbf{end}}
    \Fn{\dep{instruction\_queue queue}}{
        \ForEach{I $\in$ Executionlist} {
            I.executed\_cycles$++$\;
            \If{I.executed\_cycles $=$ I.latency} {
                queue.remove(I)\;
            }
            inform\_children\_im\_done(I)\;
        }
        Executionlist.clear()\;
    }
\end{algorithm}

This part is rather simple. Every instruction knows its latency and how many cycles it has been executed. This value gets increased and if the latency is hit it will be removed from the instructionqueue. The most interesting part here is the function \emph{inform\_children\_im\_done(Instruction)}. As we have seen in \autoref{sec:measurements} the children of an instruction do not necessarily have to wait for the instruction to finish. Sometimes they only need part of the results, which are available earlier. So this function will iterate over all children and check if the execution is advanced enough and if so ``release the dependency'' in a way that the \emph{all\_dependencies\_resolved()} function in \autoref{alg:assign} will consider the instruction as finished. Finally we have to clear the execution list as we will fill it again in the next cycle.

\section{Performing a Cycle}

Lastly we want to briefly discuss how a whole cycle is performed. \suaca\ will run each of the three simulation algorithms we explained above. It will then free up all ports that were used during the cycle, in order to enable the port pipelining. It also passes the queue that contains all instructions that still have to be executed to the three functions. A short pseudo code representation can be found below.
\newpage
\begin{algorithm}[H]
    \SetAlgoLined
    \caption{Perform a whole cycle}
    \SetKwFunction{dep}{perform\_cycle}
    \SetKwProg{Fn}{Function}{:}{\textbf{end}}
    \Fn{\dep{instruction\_queue queue}}{
        load\_instructions(queue)\;
        choose\_ports(queue)\;
        execute\_instructions(queue)\;
        \ForEach{p $\in$ Ports} {
            p.clear()\;
        }
    }
\end{algorithm}
\vspace{5pt}
The interesting observation here is that an instruction can actually get loaded, put into a port and then executed within a single cycle, due to the order of the function calls.\\
This function will be executed in a loop as long as there are instructions to be executed. After said loop \suaca\ will generate its output.

\section{The Divider Pipe}
\label{sec:dividerpipe}

Instructions that perform a division of some kind have to use the divider pipe, which is located on port~$0$. \suaca's output will only show the divider pipe if one of the instructions needs it. We have to consider it when choosing the ports for the instructions during \hyperref[alg:assign]{algorithm~\ref*{alg:assign}}, because the division \microops\ cannot be pipelined. More precisely our measurements contain a ``div-cycle'' property for the corresponding instructions, which tells us how many cycles the divider pipe will be blocked. Because the divider pipe is located on port~$0$ each of those instructions has to have at least one \microop\ that uses port $0$ exclusively. \suaca\ will block the divider pipe as soon as this particular \microop\ is assigned to port $0$. As long as it is blocked all future division \microops\ are denied port $0$. After ``div-cycle'' many cycles the divider pipe will be available again.\\
We did not include this in the algorithms above for two reasons. First is readability, as the implementation of this behavior would add some otherwise unnecessary if statements. On the other hand this is a very special case as using a division is definitely not advised when you are trying to write high performance code.


\documentclass{article}
\usepackage[english]{babel}
\usepackage{amsmath,enumerate,bbm}

%%%%%%%%%% Start TeXmacs macros
\catcode`\|=\active \def|{
\fontencoding{T1}\selectfont\symbol{124}\fontencoding{\encodingdefault}}
\newcommand{\assign}{:=}
\newcommand{\mathd}{\mathrm{d}}
\newcommand{\tmop}[1]{\ensuremath{\operatorname{#1}}}
\newenvironment{enumeratenumeric}{\begin{enumerate}[1.] }{\end{enumerate}}
\newenvironment{tmindent}{\begin{tmparmod}{1.5em}{0pt}{0pt} }{\end{tmparmod}}
\newenvironment{tmparmod}[3]{\begin{list}{}{\setlength{\topsep}{0pt}\setlength{\leftmargin}{#1}\setlength{\rightmargin}{#2}\setlength{\parindent}{#3}\setlength{\listparindent}{\parindent}\setlength{\itemindent}{\parindent}\setlength{\parsep}{\parskip}} \item[]}{\end{list}}
\newtheorem{corollary}{Corollary}
\newtheorem{theorem}{Theorem}
%%%%%%%%%% End TeXmacs macros

\begin{document}

\section{Why}

\section{How}

\subsection{Notation}

\subsection{Bayesian Approach}

Let $n \in \mathbbm{N}^{+}$ the number of relavent features of making a good
cup of coffee, e.g. the temperature of water; $x \in \mathbbm{R}^{n}$ the
values of the features. Let $Y$ the taste of coffee under a given $x$, which
is either $0$ (tastes bad) or $1$ (tastes good), thus naturally is a random
variable obeys a Bernoulli distribution with probability (confidence) $\psi$,
i.e. $Y \sim \tmop{Ber} ( \psi )$. Let $f$ the model relates $x$ and $\psi$,
depending also on paramters $w \in \mathbbm{R}^{m}$ for some $m \in
\mathbbm{N}^{+}$, i.e. $\psi =f ( x;w )$.

The Bayesian approach is as follow.

\begin{theorem}
  We have
  \[ p ( Y=1|X=x ) =\mathbbm{E}_{w_{( s )} \sim p ( W )} [  f ( x,w_{( s )} )
     ] , \]
  where $w_{( s )} \sim p ( W )$ means that $\{ w_{( s )} :s=1,2, \ldots \}$
  are sampled from $P ( W )$.
\end{theorem}

\begin{proof}
  By Bayesian formula,
  \[ p ( Y=1|X=x ) = \frac{p ( X=x,Y=1 )}{p ( X=x )} . \]
  Then by total probability formula,
  \[ p ( X=x,Y=1 ) = \int_{\mathbbm{R}^{m}} \mathd w p ( X=x,Y=1,W=w ) , \]
  then Bayesian formula gives
  \[ p ( X=x,Y=1 ) = \int_{\mathbbm{R}^{m}} \mathd w p ( Y=1|X=x,W=w )  p (
     X=x,W=w ) . \]
  Since $x$ and $w$ are independent, $p ( X=x,W=w ) =p ( X=x )  p ( W=w )$.
  Put all together,
  \begin{eqnarray*}
    p ( Y=1|X=x ) & = & \frac{p ( X=x,Y=1 )}{p ( x )}\\
    & = & \frac{\int_{\mathbbm{R}^{m}} \mathd w p ( Y=1|X=x,W=w )  p (
    X=x,W=w )}{p ( X=x )}\\
    & = & \frac{\int_{\mathbbm{R}^{m}} \mathd w p ( Y=1|X=x,W=w )  p ( X=x )
    p ( W=w )}{p ( X=x )}\\
    & = & \int_{\mathbbm{R}^{m}} \mathd w p ( Y=1|X=x,W=w )  p ( W=w ) ,
  \end{eqnarray*}
  or simply,
  \[ p ( Y=1|X=x ) =\mathbbm{E}_{w_{( s )}} [  p ( Y=1|X=x,W=w_{( s )} ) ] .
  \]
  And then insert $f$ as
  \[ p ( Y=1|X=x,W=w ) =f ( x,w ) , \]
  since $Y \sim \tmop{Ber} ( f ( x,w ) )$. So, in one word,
  \[ p ( Y=1|X=x ) =\mathbbm{E}_{w_{( s )} \sim p ( W )} [  f ( x,w_{( s )} )
     ] . \]
\end{proof}

What we want to find is a $x_{\ast}$, s.t. $p ( Y=1|X=x )$
($=\mathbbm{E}_{w_{( s )} \sim p ( W )} [  f ( x,w_{( s )} ) ]$) is maximized.
Or say, we are searching
\[ x_{\ast} = \underset{x}{\tmop{argmax}} \{ \mathbbm{E}_{w_{( s )} \sim p ( W
   )} [  f ( x,w_{( s )} ) ] \} . \]
However, the only thing we have not known yet is the distribution of $W$. We
are so humble that know nothing on how to make a good cup of coffee, so we use
a flatten prior of $W$, i.e. $W \sim \tmop{Uniform}$, with some support wide
enough. We can obtain the posterior of $W$ by inserting the data, i.e. a list
of pairs $( x,y )$, as the value of $Y$ (the taste of a cup of coffee) given
by some $x$. By feeding the data, we iterative gain the prior of $W$, which is
the posterior in the previous iteration, as
\[ p_{i+1} ( W=w ) = \frac{p ( Y=y_{i} ,X=x_{i} |W=w )  p_{i} ( W=w )}{p (
   Y=y_{i} ,X=x_{i} )} . \]
\begin{theorem}
  If define $g ( a,b )$ as $b$ if $a=1$ and as $1-b$ if $a=0$, and if
  initially use flatten prior, i.e. $p_{1} = \tmop{Const}$, then we have, for
  data $D \assign \{ x_{i} ,y_{i} :i=1,2, \ldots ,N \}$,
  \[ p_{N} ( W=w ) =c ( D ) \times \prod_{i=1}^{N} g ( y_{i} ,f ( x_{i} ,w ) )
     , \]
  or say,
  \[ \ln [ p_{N} ( W=w ) ] = \sum_{i=1}^{N}   \ln [ g ( y_{i} ,f ( x_{i} ,w )
     ) ] + \ln [ c ( D ) ] , \]
  where $c ( D )$ can also be seen as the normalization factor of $p_{N} ( W=w
  )$ since Bayesian formula always ensures normalization of probability.
\end{theorem}

\begin{proof}
  By Bayesian formula and the independence between $X$ and $W$,
  \[ p ( Y=y_{i} ,X=x_{i} |W=w ) =p ( Y=y_{i} |X=x_{i} ,W=w )  p ( X=x_{i} )
  \]
  and
  \[ p ( Y=y_{i} ,X=x_{i} ) =p ( Y=y_{i} |X=x_{i} )  p ( X=x_{i} ) , \]
  thus
  \[ p_{i+1} ( W=w ) =p_{i} ( W=w )   \frac{p ( Y=y_{i} |X=x_{i} ,W=w )}{p (
     Y=y_{i} |X=x_{i} )} ; \]
  and since we have known in previous that $p ( Y=1|X=x_{i} )
  =\mathbbm{E}_{w_{( s )} \sim p_{i} ( W )} [  f ( x_{i} ,w_{( s )} ) ]$ and
  likewise $p ( Y=0|X=x_{i} ) =\mathbbm{E}_{w_{( s )} \sim p_{i} ( W )} [ 1- f
  ( x_{i} ,w_{( s )} ) ]$, we finally get, if $y_{i} =1$
  \[ p_{i+1} ( W=w ) =p_{i} ( W=w )   \frac{f ( x_{i} ,w )}{\mathbbm{E}_{w_{(
     s )} \sim p_{i} ( W )} [  f ( x_{i} ,w_{( s )} ) ]} , \]
  else ($y_{i} =0$)
  \[ p_{i+1} ( W=w ) =p_{i} ( W=w )   \frac{1-f ( x_{i} ,w
     )}{\mathbbm{E}_{w_{( s )} \sim p_{i} ( W )} [  1-f ( x_{i} ,w_{( s )} )
     ]} . \]

  After the first iteration, by $x_{1}$ and $y_{1} =1$,
  \[ p_{2} ( W=w ) = \tmop{Const}   \frac{f ( x_{1} ,w )}{\mathbbm{E}_{w_{( s
     )} \sim \tmop{Uniform}} [  f ( x_{1} ,w_{( s )} ) ]} =c ( x_{1} ,y_{1} )
     f ( x_{1} ,w ) . \]
  Then the next iteration, suppose $y_{2} =1$ still,
  \[ p_{3} ( W=w ) = \{ c ( x_{1} ,y_{1} )  f ( x_{1} ,w ) \}   \left\{
     \frac{f ( x_{2} ,w )}{\mathbbm{E}_{w_{( s )} \sim p_{2} ( W )} [  f (
     x_{2} ,w_{( s )} ) ]} \right\} , \]
  and re-define $c ( \{ ( x_{1} ,y_{1} ) , ( x_{2} ,y_{2} ) \} ) \assign c (
  x_{1} ,y_{1} ) /\mathbbm{E}_{w_{( s )} \sim p_{2} ( W )} [  f ( x_{2} ,w_{(
  s )} ) ]$, thus
  \[ p_{3} ( W=w ) =c ( \{ ( x_{1} ,y_{1} ) , ( x_{2} ,y_{2} ) \} )  f ( x_{1}
     ,w )  f ( x_{2} ,w ) . \]
  And if $y_{2} =0$,
  \[ p_{3} ( W=w ) =c ( \{ ( x_{1} ,y_{1} ) , ( x_{2} ,y_{2} ) \} )  f ( x_{1}
     ,w ) [  1-f ( x_{2} ,w ) ] . \]
  So, generally, if define $g ( a,b )$ as $b$ if $a=1$ and as $1-b$ if $a=0$,
  then for data $D \assign \{ x_{i} ,y_{i} :i=1,2, \ldots ,N \}$,
  \[ p_{N} ( W=w ) =c ( D ) \times \prod_{i=1}^{N} g ( y_{i} ,f ( x_{i} ,w ) )
     , \]
  or say,
  \[ \ln [ p_{N} ( W=w ) ] = \sum_{i=1}^{N}   \ln [ g ( y_{i} ,f ( x_{i} ,w )
     ) ] +c ( D ) . \]
\end{proof}

\begin{corollary}
  If data $D= \{ x_{\tmop{BEST}} ,y_{i} =1:i=1,2, \ldots ,N \}$, then
  \[ \lim_{N \rightarrow + \infty}   \underset{x}{\tmop{argmax}} \{
     \mathbbm{E}_{w_{( s )} \sim p_{N} ( W )} [ f ( x,w_{( s )} ) ] \}
     =x_{\tmop{BEST}} . \]
\end{corollary}

\begin{proof}
  XXX $p_{N} ( W=w ) =c ( D )   [ f ( x_{\tmop{BEST}} ,w ) ]^{N}$
\end{proof}

{\algorithm{XXX (init)
\begin{tmindent}
  \begin{enumeratenumeric}
    \item $D \leftarrow D \cup ( x_{i} ,y_{i} )$;

    \item $\ln [ p ( W=w ) ] \leftarrow \ln [ p ( W=w ) ] +  \ln [ g ( y_{i}
    ,f ( x_{i} ,w ) ) ]$;

    \item fit $p ( W )$ by variational inference;

    \item sample $\{ w_{s} :s=1,2, \ldots ,N_{s} \}$ from $p ( W )$;

    \item $x_{\ast} = \underset{x}{\tmop{argmax}} \{ \mathbbm{E}_{w_{s}} [ f (
    x,w_{s} ) ] \}$;

    \item Make a cup of coffee by feature values $x_{\ast}$;

    \item Taste the cupe of coffee;

    \item Return your opinion as $y_{\ast}$;

    \item $( x_{i+1} ,y_{i+1} ) \leftarrow ( x_{\ast} ,y_{\ast} )$.
  \end{enumeratenumeric}
\end{tmindent}}}

\subsection{An Instant Model}

\end{document}


% ========================================================================================
\chapter{Example Section for \texttt{\classname}}\label{ch:ex}
This chapter demonstrates the appearance of the thesis.
% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\section{Demonstration}
This is a Section.
% ........................................................................................
\subsection{Subsection A}
This is a subsection. \kant[1]
\paragraph{Paragraph A}
I am a paragraph.
\paragraph{Paragraph B}
So am I.
% ........................................................................................
\subsection{Subsection B}
This is also a subsection.
% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\section{Citation}
This sections demonstrates how citations looks like.
This is a book \cite{Evans15}. This is an article \cite{Ben02}. This is a
website \cite{FAUreg}.
% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\section{Definitions, Theorems, Remarks}
This sections demonstrates how the different theorem environments look like.
%-----------------------------------------------------------------------------------------
\begin{lemma}{Compactness in metric spaces}{compMet}
Let $X$ be a metric space and $A\subset X$, then the following statements are equivalent:
\begin{enumerate}[label=(\roman*)]
\item $A$ is relatively compact;
\item $A$ is sequentially compact;
\item $A$ is totally bounded and $\overline A$ is complete.
\end{enumerate}
\end{lemma}
This is an equation
\begin{equation}\label{eq:Gauss}
\sum_{i=1}^n=\frac{n~(n+1)}{2}.
\end{equation}
From \ref{eq:Gauss} we see can deduce something very useful.
We can also use \cref{eq:Gauss} or \labelcref{eq:Gauss} to refer to an equation.
%-----------------------------------------------------------------------------------------
\begin{remark}{}{}
If $X$ is a complete metric space, we know that every closed subset $A\subset X$ is
complete and thus the last statement in the above lemma reduces to total boundedness,
see \cite[Lem. I.6.7]{Dunf60}.
\end{remark}
%-----------------------------------------------------------------------------------------
\begin{proof}
See, for example, \cite[Lem. I.6.15]{Dunf60}.
\end{proof}
% ----------------------------------------------------------------------------------------
The main result in the context of the weak$^\ast$ topology is stated below.
\index{topology!weak}
\index{topology!weak*}
\index{topology!strong}
% ----------------------------------------------------------------------------------------
\begin{definition}{}{}
\begin{enumerate}[label=(\roman*)]
\item Given a set $X$ and a family $\mathcal{F}$ of functions $f_i:X\rightarrow \mathcal{Y}_i$
associated with topological spaces $\mathcal{Y}_i$ we denote by $\sigma(X,\mathcal{F})$
the initial topology, i.e., the coarsest topology on $X$ such that each $F_i$ is continuous.
\item Let $X$ be a Banach space, then we denote by $\sigma(X,X^{\ast})$ the
\emph{weak topology} on $X$, while the usual one induced by the norm is referred to as
\emph{strong topology}.
\item Considering the family $\mathcal{F}:=\{X^{\ast}\ni\xi\mapsto\xi(x)\in\R: x\in E\}$
we call $\sigma(X^{\ast}, \mathcal{F}) =:\sigma(X^{\ast},X)$ the weak$^\ast$ topology.
\end{enumerate}
\end{definition}
% ----------------------------------------------------------------------------------------
% ========================================================================================
\chapter{Typeface}
This chapter demonstrates the typeface.
\kant


\documentclass[fontsize=9pt,letter]{scrartcl}

%----------------------------------------------------------------------------------------
%	PACKAGES AND STUFF
%      If you're reading this, don't...just skip to the equations
%----------------------------------------------------------------------------------------

\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
\usepackage[english]{babel} % English language/hyphenation
\usepackage{amsmath,amsfonts,amsthm} % Math packages
\usepackage[pdftex]{graphicx}
\usepackage[margin=0.7in]{geometry}

\usepackage{sectsty} % Allows customizing section commands
\allsectionsfont{\centering}% \normalfont} % Make all sections centered, the default font and small caps

\numberwithin{equation}{section} % Number equations within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)
\numberwithin{figure}{section} % Number figures within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)
\numberwithin{table}{section} % Number tables within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)

%----------------------------------------------------------------------------------------
%	TITLE SECTION
%----------------------------------------------------------------------------------------

\newcommand{\horrule}[1]{\rule{\linewidth}{#1}} % Create horizontal rule command with 1 argument of height

\title{
\horrule{1pt} \\[0.2cm]			% horrule puts a horizontal line
Viral Assembly Equation List
%\horrule{1pt} \\[0.2cm]
}

\author{Waterloo iGEM}
\date{\today}

\begin{document}

\maketitle % Print the title
\vspace{-20pt}

\horrule{1pt} %\\[0.4cm]
\vspace{-20pt}

%-------------------

%----------------------------------------------------------------------------------------
%	THE LIST OF EQUATIONS STARTS HERE
%----------------------------------------------------------------------------------------

\section{Equations}

% By the way, the percent sign is used for comments

\begin{align}

% ----------------------------------
% 0. RNAi Factor
f_{RNAi} &= \frac{L}{(1+exp(-k(P_6 - x_0)))}
% ----------------------------------
% 1. Gapped DNA
\frac{\mathrm{d}}{\mathrm{d} t} DNA_{GAP} &= \text{(out inf pure)} + k_v V (DNA_{max} - DNA_{GAP} - DNA_{gmod} - DNA_{CCC} - DNA_{cmod}) - \alpha_c (DNA_{GAP}) - k_g (DNA_{GAP}) - \gamma_{DNA} DNA_{GAP} \\
%
% ----------------------------------
% 2. cccDNA
\frac{\mathrm{d}}{\mathrm{d} t} DNA_{CCC} &= \alpha_c (DNA_{GAP}) - \gamma_{DNA} (DNA_{CCC}) - k_c (DNA_{CCC}) \\
%
% ----------------------------------
% 3. Modified gapped DNA
\frac{\mathrm{d}}{\mathrm{d} t} DNA_{gmod} &= \text{(out inf mod)} + k_v V_m (DNA_{max} - DNA_{GAP} - DNA_{gmod} - DNA_{CCC} - DNA_{cmod}) - \alpha_c (DNA_{gmod}) + k_g (DNA_{GAP}) - \gamma_{DNA} DNA_{gmod} \\
% ----------------------------------
% 4. Modified cccDNA
\frac{\mathrm{d}}{\mathrm{d} t} DNA_{cmod} &= \alpha_c (DNA_{gmod}) - \gamma_{DNA} (DNA_{cmod}) + k_c (DNA_{CCC}) \\
% ----------------------------------
% 5. 19S RNA
\frac{\mathrm{d}}{\mathrm{d} t} RNA_{19S} &= \alpha_{19S} (DNA_{CCC}) - \gamma_{19S} (RNA_{19S}) - f_{RNAi}\\
%
% ----------------------------------
% 6. Total pure 35S RNA
\frac{\mathrm{d}}{\mathrm{d} t} RNA_{35S} &= \alpha_{35S} (DNA_{CCC}) - \gamma_{35S} (RNA_{35S}) -  k_p P_{4 \text{,sub}} P_5 (RNA_{35Su}) - f_{RNAi}\\
%
% ----------------------------------
% 7. Total modified 35S RNA
\frac{\mathrm{d}}{\mathrm{d} t} RNA_{35Sm} &= \alpha_{35S} (DNA_{cmod}) - \gamma_{35S} (RNA_{35Sm}) -  k_p P_{4 \text{,sub}} P_5 (RNA_{35Smu}) - f_{RNAi}\\
%
% ----------------------------------
% 8. P1
%add in the stuff to latex
\frac{\mathrm{d}}{\mathrm{d} t} P_1 &= \beta_1 (1 + \frac{P_6}{P_6 + E_{p6}}) (((RNA_{35Su}) + (RNA_{35Smu})) - \delta_1 P_1 \\
%
% ----------------------------------
% 9. P2
\frac{\mathrm{d}}{\mathrm{d} t} P_2 &= \beta_2 (1 + \frac{P_6}{P_6 + E_{p6}}) ((RNA_{35Su}) + (RNA_{35Smu}) - \delta_2 P_2 - k_l P_2 \\
%
% ----------------------------------
% 10. P3
\frac{\mathrm{d}}{\mathrm{d} t} P_3 &= \beta_3 (1 + \frac{P_6}{P_6 + E_{p6}})((RNA_{35S}) + (RNA_{35Sm})) - \delta_3 P_3 - k_{anchor} P_3 V_{\text{int} - k_{anchor} P_3 V_{\text{int_m}} \\
%
% ----------------------------------
% 11. P4
\frac{\mathrm{d}}{\mathrm{d} t} P_4 &= \beta_4 (1 + \frac{P_6}{P_6 + E_{p6}}) ((RNA_{35S}) + (RNA_{35Sm})) - \delta_4 P_4 - k_{splice} P_4 \\
%
% ----------------------------------
% 12. P4 subunits
\frac{\mathrm{d}}{\mathrm{d} t} P_{4 \text{,sub}} &= k_{splice} P_4 - \delta_4 P_{4 \text{,sub}} - k_p P_{4 \text{,sub}} P_5 (RNA_{35Su}) - k_p P_{4 \text{,sub}} P_5 (RNA_{35Smu}) \\
%
% ----------------------------------
% 13. P5
\frac{\mathrm{d}}{\mathrm{d} t} P_5 &= \beta_5 (1 + \frac{P_6}{P_6 + E_{p6}}) ((RNA_{35S}) + (RNA_{35Sm})) - \delta_5 P_5 - k_p P_{4 \text{,sub}} P_5 (RNA_{35Su}) - k_p P_{4 \text{,sub}} P_5 (RNA_{35Smu}) \\
%
% ----------------------------------
% 14. P6
\frac{\mathrm{d}}{\mathrm{d} t} P_6 &= \beta_6 (RNA_{19S}) - \delta_6 P_6 \\
%
% ----------------------------------
% 15. Intermediate pure virions
\frac{\mathrm{d}}{\mathrm{d} t} V_{\text{int}} &= k_p P_{4 \text{,sub}} P_5 (RNA_{35Su}) - k_{anchor} P_3 V_{\text{int}} \\
%
% ----------------------------------
% 16. Intermediate impure virions
\frac{\mathrm{d}}{\mathrm{d} t} V_{int_m} &= k_p P_{4 \text{,sub}} P_5 (RNA_{35Smu}) - k_{anchor} P_3 V_{int_m} \\
%
% ----------------------------------
% 17. Pure virions
\frac{\mathrm{d}}{\mathrm{d} t} V &= k_{anchor} P_3 V_{\text{int}} - k_v V (DNA_{max} - DNA_{GAP} - DNA_{gmod} - DNA_{CCC} - DNA_{cmod}) - \delta_v V - v_{exit} V \\
%
% ----------------------------------
% 18. Impure virions
\frac{\mathrm{d}}{\mathrm{d} t} V_m &= k_{anchor} P_3 V_{int_m} - k_v V_m (DNA_{max} - DNA_{GAP} - DNA_{gmod} - DNA_{CCC} - DNA_{cmod}) - \delta_v V_m - v_{exit} V_m
\end{align}

%----------------------------------------------------------------------------------------
%	THE LIST OF EQUATIONS ENDS HERE
%----------------------------------------------------------------------------------------

% template:     \frac{\mathrm{d}}{\mathrm{d} t} &= \text{stuff} \\

%------------------------------------------------

\end{document}

models/viralassembly/mathVA Eqn List PR.tex


% !TEX root=/home/tavant/these/manuscript/src/manuscript.tex

\section{Introduction to plasma models and simulations}
\label{sec-simulations}
% \addcontentsline{toc}{section}{Plasma models and simulations}

\subsection{Describing the plasma} \label{subsec-phy}

Depending on the pressure, energy, and time scale, different models are more suitable to describe the plasma.
There are mainly two distinct models.
The first is the \emph{kinetic} description of the species of the plasma, via the Boltzmann equation.
The second uses a \emph{fluid} description of the species, by means of moments.
%
% \begin{figure}[hbt]
%   \centering
%   \includegraphics[width=\defaultwidth]{Chart}
%   \caption{}
%   \label{fig-chart}
% \end{figure}

\paragraph{Boltzmann equation \\}
The Boltzmann equation in \cref{eq-boltzmann} describes the evolution of the particles (atoms, ions, and electrons) in the phase space.
The phase space is the set of each possible position $\vect{x}$ and velocity $\vect{v}$ that can be attained by a particle.
The evolutions in the phase space are due to forces, diffusion, and collisions.

\begin{equation} \label{eq-boltzmann}
\deriv{f}{t}  + \vect{v} \cdot \grad_{\vect{x}} f + \vect{F} \cdot  \grad_{\vect{v}} f = \deriv{f}{t} \at{\rm coll}
\end{equation}
where $f$ is the distribution function of the particle at $\vect{x}, \vect{v}$, and $\deriv{f}{t}\mid_{\rm coll}$ denotes the effects of the collisions, $\grad$ is the gradient in both the positions (subscript $\vect{x}$) and the velocities (subscript $\vect{v}$)  and $\vect{F}$ is the force applied to the particle.
In the general electromagnetic case,
\begin{equation*} \label{eq-forceEM}
  \vect{F} =  q \vect{E} + q \vect{v} \times \vect{B}
\end{equation*}
with $q$ the particle charge, $\vect{E}$ the electric field, and $\vect{B}$ the magnetic field.
The solution function of the stationary Boltzmann equation without collision, also known as the stationary Vlasov equation, is
\begin{equation} \label{eq-Maxwellian}
  f(\vect{v}) = N (\frac{m}{2 \pi k_B T})^{3/2} \exp \lp - \frac{q \phi + m v^2/2}{k_B T } \rp,
\end{equation}
with $k_B$ the Boltzmann constant, $T$ is the temperature of the particle population, and $\phi$ is the electric potential, defined as $\vect{E} = -\grad \phi$, and $N$ is the density at the position where $\phi = 0$.
\cref{eq-Maxwellian} is the Maxwell-Boltzmann distribution function in velocity.
The unit of the temperature $T$ is the Kelvin, but in plasma physics, it is usual to use ${\rm T}$, defined as
\begin{equation} \label{eq-T_def}
  e {\rm T} = k_B T.
\end{equation}
The unit of ${\rm T}$ is therefore the Volt.
The equivalence is $1 \,\volt \simeq 10^4 \,\kelvin$.
\footnote{It is usual to find in the literature the temperature ${\rm T}$ expressed in electron-Volt (eV).
This is not coherent with the definition \cref{eq-T_def}, but it highlights the fact that the temperature is related to an energy via $k_B$. Therefore, the reader needs not to be confused by the equivalence between the electron-Volt and the Volt.  }
\nomenclature[Q]{\ensuremath{ \rm T}}{Temperature in Volt }
\nomenclature[Q]{\ensuremath{ T}}{Temperature in Kelvin }
We can write \cref{eq-Maxwellian} with the particle kinetic energy $\epsilon = \frac{1}{2} m v^2$ to define the energy distribution function
\begin{equation} \label{eq-Maxwellina_energy}
  f_{\epsilon}(\epsilon) = N \frac{2 \sqrt{\epsilon}}{{k_B T}^{3/2} \sqrt{\pi}} \exp \lp- \frac{q \phi + \epsilon}{k_B T} \rp.
\end{equation}
The factor $\sqrt{\epsilon}$ in \cref{eq-Maxwellina_energy} appears because of the integration of the velocity distribution function $f$ over the three directions.
Thus, it is convenient to use the energy probability function
\begin{equation} \label{eq-EPF}
  f_P(\epsilon) = \frac{f_{\epsilon}}{\sqrt{\epsilon}}.
\end{equation}

We name the Maxwellian distribution function the distribution
\begin{equation} \label{eq-Maxwelliantwo}
  f_{\rm M}(\vect{v}) = n \lp \frac{m}{2 \pi k_B T}\rp^{3/2} \exp \lp - \frac{ m v^2/2}{k_B T } \rp,
\end{equation}
with $n$ the density.
One can show that the Maxwellian distribution function is the solution of the Boltzmann equation with only elastic collisions \citep{lieberman2005}.
In one dimension, the Maxwellian distribution function becomes
\begin{equation}
  f_{\rm M, 1D}(v) =  n \lp\frac{m}{2 \pi k_B T}\rp^{1/2} \exp \lp - \frac{ m v^2/2}{k_B T } \rp,
\end{equation}

\paragraph{Fluid equations \\}
The description of the plasma in 7 dimensions (3 of space, 3 of velocity, and one of time) can make the resolution of the Boltzmann equation complicated.
If the accurate description of $f$ is not needed, we can instead use the first moments of \cref{eq-boltzmann} on the velocity to obtain a set of simpler equations.

The first equation is obtained by integrating \cref{eq-boltzmann} over the velocity space, which gives
\begin{align}
    & \iiint_{\vect{v}}  \deriv{f}{t} d^3v &&+&& \iiint_{\vect{v}}  \vect{v} \cdot \grad_{\vect{x}} f  d^3v &&+&&  \iiint_{\vect{v}}  \vect{F} \cdot  \grad_{\vect{v}} f  d^3v && = && \iiint_{\vect{v}}  \deriv{f}{t} \at{\rm coll} \nonumber  \\
   \iff &  \deriv{n}{t} &&+&&  \grad_{\vect{x}}  \cdot  ( \vect{u} n) &&+&& 0 &&=&& S_{\rm iz}   \label{eq-conc}
\end{align}
where $n=\iiint f d^3v$ is the density, $\vect{u} = \frac{1}{n} \iiint \vect{v} f d^3v$ is the mean velocity, and $S_{\rm iz}$ is the source term of particle due to ionization.
\Cref{eq-conc} is the continuity equation for a given species.
In a similar way, integrating the Boltzmann equation times the velocity or the kinetic energy gives the momentum conservation equation or the energy conservation equation, respectively.
This set of equations is simpler, although it relies on additional hypotheses.

One of them is the closure of the system.
Indeed, the continuity equation describes the evolution of the density $n$ but needs the mean velocity $\vect{u}$.
However, the velocity is described by the momentum conservation equation that needs the temperature $T$, and so on.
To close the system, one has to make a hypothesis on the higher moment of the distribution function.
A usual closure is the isothermal hypothesis, that fixes the temperature.
Hence, the energy conservation equation is not needed.
Other possible closures are the adiabatic hypothesis (no heat flux, the \nth{3} moment of $f$), the polytropic law linking the evolution of $n$ with $T$, or the Fourier law for heat diffusion.

It is important to note that the set of fluid equations can be written without making any assumption on the distribution function $f$, except for the collisions.
%Besides, one may be led to believe that the temperature is defined by the Maxwell-Boltzmann distribution \cref{eq-Maxwellian}, and therefore that the fluid set of equations needs to use the Maxwellian hypothesis $f = f_{\rm M}$.
In this work, the temperature is defined by the second moment of the distribution function
\begin{equation} \label{eq-defTe}
  e {\rm T} = k_B T = \frac{m}{3 n} \iiint (\vect{v} - \vect{u})^2 f(\vect{v}) d^3v.
\end{equation}
It happens that in the case of the Maxwell-Boltzmann distribution, the quantity defined by \cref{eq-defTe} is the denominator of the argument of the exponential in \cref{eq-Maxwellian}.
The integral in \cref{eq-defTe} can be decomposed over the three directions $x,y$, and $z$ as
\begin{equation} \label{eq-3Te}
  e {\rm T} = k_B T = \frac{m}{3 n} \sum_{i=x,y,z} \iiint (v_i - u_i)^2 f(\vect{v}) d^3v = k_B \frac{ T_x + T_y + T_z}{3},
\end{equation}
which defines the directed temperatures.
A distribution is said anisotropic if the three temperatures differ.

\subsection{Plasma simulation models} \label{subsec-simulations}
As there are two different models to describe the plasma, there are two different simulation approaches\string: the fluid simulations and the kinetic simulations.
The fluid simulations solve the moments of the distribution function (the density, mean velocity, and usually the temperature of the species), and the electromagnetic fields.
Depending on the conditions, the system of equations can be simplified before resolution.
For instance, under the electrodynamic conditions, mainly for space plasmas and fusion, the Maxwell equations are coupled to the fluid equations leading to magnetohydrodynamics (MHD).
In the case of electrostatic conditions, as it is usual for Low-Temperature (LT) plasmas, the Poisson equation is coupled to the fluid equations.
In most of LT plasmas the plasma is quasi-neutral except in a limited near-wall region called the plasma sheath.
It is also common to neglect inertia terms and assume a steady-state in the momentum equations, leading to the drift-diffusion approximation.
The fluid equations can be solved in \ac{3D}, \ac{2D}, or \ac{1D} for space.
In a low dimension model, the effects of the missing dimensions are usually included, for instance, in the source terms as done by \citet{barral2003a}.

\vspace{1em}
However, some phenomena can only be described via the knowledge of the distribution function.
An example of such phenomena is the particle-wave interaction, such as the Landau Damping \citep{landau1945,malmberg1964}, or the plasma-beam instability \citep{filippychev1990}, for which the gradient of the distribution function in the velocity space is important.
In contrast to the fluid descriptions, \emph{kinetic} simulations solve the distribution function $f$ for both position and velocities.
Two approaches are usually used for kinetic simulations\string:
\begin{itemize}
  \item The \ac{DK} model, that discretizes \cref{eq-boltzmann} in the full phase space.
  \item The \acl{PIC} (\acs{PIC}) model, which uses an ensemble of particles to discretize the distribution function.
\end{itemize}
While the \ac{DK} simulations use a Eulerian description of the distribution function, we can see the \ac{PIC} simulations as a Lagrangian approach.
The \ac{DK} simulations can theoretically better describe the plasma, mostly because there is less numerical noise and we can model binary collisions more easily, especially Coulomb collisions.
On the other hand, \ac{PIC} simulations are much simpler to develop both on a mathematical and a computational perspective.
For instance, the kinetic effects of electron emission have been recently studied using \ac{DK} simulation by \citet{cagas2019}, while it has been done since the last century in \ac{PIC} simulations \citep{boswell1988}.