\section{Results}

\subsection{Topic Models}

The first result of performing LDA is the inferred topic models.
Because LDA is an unsupervised process there are no labels or summaries associated with the topics, only a nominal identifier.
To directly judge the semantics of a topic a human must interpret the terms and their associated frequency and extrapolate shared semantics.
Over several runs of LDA with various parameterization, different quality topics were extracted.
Table~\ref{tab:topics} displays a small selection of topics --- in this run, five hundred topics were inferred across the corpora.
The complete list of inferred topics is available online\footnote{\href{https://employability.rouly.net/web/topics}{employability.rouly.net/web/topics}}.

\begin{table}
  \centering
  \begin{tabular}{l r}
    \multicolumn{2}{c}{\small{\textbf{Topic 16}}} \\
    {\small\textit{Term}} & {\small\textit{Frequency}} \\
    \hline
    test & 0.0132 \\
    data & 0.0128 \\
    software & 0.0115 \\
    design & 0.0107
  \end{tabular}
  \begin{tabular}{l r}
    \multicolumn{2}{c}{\small{\textbf{Topic 273}}} \\
    {\small\textit{Term}} & {\small\textit{Frequency}} \\
    \hline
    market & 0.0250 \\
    product & 0.0113 \\
    strategi & 0.0107 \\
    digit & 0.0103
  \end{tabular}
  \begin{tabular}{l r}
    \multicolumn{2}{c}{\small{\textbf{Topic 418}}} \\
    {\small\textit{Term}} & {\small\textit{Frequency}} \\
    \hline
    branch & 0.0224 \\
    rental & 0.0167 \\
    enterpris & 0.0155 \\
    manageri & 0.0146
  \end{tabular}
  \begin{tabular}{l r}
    \multicolumn{2}{c}{\small{\textbf{Topic 424}}} \\
    {\small\textit{Term}} & {\small\textit{Frequency}} \\
    \hline
    care & 0.0346 \\
    nurs & 0.0179 \\
    health & 0.0168 \\
    clinic & 0.0117
  \end{tabular}
  \caption{Four inferred topics.}~\label{tab:topics}
\end{table}

\subsection{Domain Overlap}

From an LDA run with five hundred topics, ten topics were identified as ``strictly overlapping'' for certain thresholds.
Namely, $|\Omega(\rho=0.02, \theta=0.055)| = 10$.
For a set of five hundred total topics, this produces a Jaccard index of 0.02.
Table~\ref{tab:overlap} displays the ten strictly overlapping topics in $\Omega(\rho=0.02, \theta=0.055)$.
Notice that the topics in Table~\ref{tab:topics} are a subset of the topics rendered in Table~\ref{tab:overlap}.
Figure~\ref{fig:overlap} gives an additional visual reference of the complete strictly overlapping set of topics.
The closer the two bars are to equal for a given topic, the more similar that topic's distribution is within each data set.

\begin{table}
  \centering
  \begin{tabular}{l r r r r}
    & \multicolumn{4}{c}{\small{\textbf{Topic Expression}}} \\
    & \multicolumn{2}{c}{\small{\textbf{Career Data}}} & \multicolumn{2}{c}{\small{\textbf{Curricular Data}}} \\
    {\small\textit{Topic}} & {\small\textit{Count}} & {\small\textit{\%}} & {\small\textit{Count}} & {\small\textit{\%}} \\
    \hline
    16 & 9,274 & 23.43 & 568 & 9.77 \\
    273 & 8,873 & 22.42 & 583 & 10.02 \\
    274 & 2,240 & 5.66 & 1,117 & 19.21 \\
    345 & 2,676 & 6.76 & 543 & 9.34 \\
    390 & 3,130 & 7.91 & 356 & 6.12 \\
    418 & 3,069 & 7.75 & 426 & 7.32 \\
    419 & 2,590 & 6.54 & 553 & 9.51 \\
    424 & 5,561 & 14.05 & 499 & 8.58 \\
    425 & 11,807 & 29.83 & 388 & 6.67 \\
    434 & 3,793 & 9.58 & 349 & 6.00
  \end{tabular}
  \caption{Strictly overlapping topics for $\rho=0.02$ and $\theta=0.055$}~\label{tab:overlap}
\end{table}

\begin{figure}
  \centering
  \includegraphics[width=0.5\textwidth]{figs/strict-overlap}
  \caption{Strictly overlapping topics for $\rho=0.02$ and $\theta=0.055$}~\label{fig:overlap}
\end{figure}


\documentclass{article}

\usepackage[margin=1.0in]{geometry}

\usepackage{array,epsfig}
\usepackage{esint}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsxtra}
\usepackage{amsthm}
\usepackage{mathrsfs}
\usepackage{color}
\usepackage{url}

\title{Electrostatics: Charges and Fields}
\author{Aayush Arya\\ (tomriddle257@gmail.com)}

\begin{document}
	\maketitle

	\section*{Charge: Definition and Properties}
	Charge is a property of elementary particles which causes them to experience electromagnetic force, whose strength depends on the magnitude of the charge itself.It comes in two flavors: positive and negative.\\

	\subsection*{Conservation}
	The amount of charge in an isolated system is a constant \textemdash which means that charge is locally conserved and can't be destroyed.
	$$ \sum_{i=1}^{n} q_i = constant$$
	 Even in case of pair-production, anti-particles have opposite charges (as well as parity and time flow) as their matter counterparts. The opposite charges of an electron and positron are exactly equal. If this weren't the case, the \textit{law of charge conservation} would be violated. \\

	\subsection*{Quantization}

	Electrical charges can only be multiples of $e$ \textemdash the charge of an electron. Up and down quarks have charges with values as fractions of $e$, \textit{quantum chromodynamics} suggests that it is impossible to liberate a single quark from a hadron.\\

	Charge of a proton happens to be equal to that of an electron \\ J.G. King (1960) did an experiment to confirm it. He took ~17 grams of $H_2$ gas \textemdash which consists of 2 protons and 2 electrons \textemdash  compressed into a container electrically insulated from its surroundings. The gas was allowed to escape in a way that ions could not accompany.\\
	If the charge on a proton were to differ even by one part in $10^{20}$, the difference made by the absence of the ~$5\times 10^{24}$ hydrogen molecules would have made a difference of $5\times10^{4}$e which could've been detected. No such difference was observed.

	Also, during a proton decay (which hasn't been observed), one of the possible outcomes can be
		$$ p^+ \rightarrow e^+ + \pi^0 $$
	if the charge of the positron was different from that of the proton, again charge conservation would be violated.

	\section*{Coulomb's Law}
	To study the interaction of between charged  particles, we treat as being point-sized. This is justified as high-energy physics experiments show that the charge of a proton does not extend appreciably over $10^{-15} m$.\\

	The force between two such particles is then given by \textit{Coulomb's law}
	\begin{equation}\textbf{F}_2 = \frac{1}{4\pi\epsilon_0}\frac{q_1q_2\hat{\textbf{r}}_{21}}{r_{21}}
	\end{equation}
	The $\hat{\textbf{r}}_{21}$ suggests that the direction of the force is along the line joining the two charges \textemdash it is a central force.\\

	1 esu or "electrostatic unit" is a Gaussian unit defined in a way that $k$ equals exactly one when  other quantities are measured in cgs. 1 Coulomb = $2.998 \times 10^9$ esu.\\

	Important points to consider:

	\begin{enumerate}
		\item The only way to measure electric charge is to observe the interactions of charged objects.
		\item The force between two charged particles is unaffected by the presence of a third particle.
		\item The principle of superposition doesn't hold at sub-microscopic level (due to quantum effects).
		\item The inverse square ($1/r^2$) law for electric charges has been verified to extreme precision. If instead $1/r^2$ it had to be $1/r^{2+\delta}$, then $\delta$ has to be lower than one part in $10^{16}$
		\item No system of stationary charges can be in equilibrium under the action of electric forces alone.
		\item Coulomb's law doesn't take into account relativistic effects.
	\end{enumerate}

	\section{Electrical Energy}
	If we have a point charge $q_1$  fixed at its position and try to bring another charge $q_2$ close to it, we would have to do some work against the force between the particles. This work is stored as electrical potential energy and becomes the kinetic energy of the particle system when they are left free to move.\\

	We note that electrical potential energy exists for a particular configuration of charges \textemdash it's not the property of an individual charges. Potential energy of the system of N charges is given by

	$$ U = \frac{1}{2}\sum_{i=1}^{N} \sum_{j \neq i} \frac{1}{4\pi\epsilon_0 r_{ij}}q_i q_j $$

	Since each pair occurs twice in this series, we multiply by 1/2 to compensate for it.

	\section*{Electric Field}
	An electric charge influences its surroundings. It assigns a local property to the space around it, assigning a value to each point. We define a vector function, called the charge's \textbf{electric field}. It is defined as the amount of force a particle with unit charge \footnote{Some authors suggest that we consider $q_O$ to be arbitrarily small so that it doesn't affect the field due to our source charge. Firstly, such a definition is not required if we consider just the influence of the source charge alone. Secondly, $q_0$ can't be smaller than $e$.} would experience if placed in a point under its influence.

	$$ \textbf{E} = \frac{\textbf{F}_e}{q_0}$$

	The idea may seem useless but it actually results in a profound simplification. If we know the net electric field at a given point in space, we can predict the behavior of any charge when placed at that point \textit{without} having the knowledge of what caused it.

	\subsection*{Field Singularities} An electric field singularity would be either be a point where the field strength tends to $\infty$ or a region where the field changes its magnitude or direction discontinuously.\\

	For example, as the electric field changes proportionately with $1/r^2$, as r $\rightarrow$ 0, \textbf{E} $\rightarrow$ $\infty$. But since we know that even elementary particles have a finite size, r cannot get arbitrarily small. Therefore, we can ignore this mathematical singuarity.

	\subsection*{Electric Flux}
	For any vector field \textbf{v} and a surface with an areal vector \textbf{a} pointing perpendicular to the surface, \textbf{v.a} is then called the flux of \textbf{v} through the surface \textbf{a}. As a physical analogy: it is a measure of rate of flow of a fluid through a cross-section \textbf{a}.\\

	Consider any closed surface enclosing some electric charge. If we take an infinitesimally small fraction of the surface such that the areal vector has the same direction at each point on itself,
	$$ d\phi = \textbf{E.dA}$$
	gives the electric flux through the infinitesimal surface. If we sum the contributions of all such infinitesimal areas in the limit $dA \rightarrow 0$, the sum becomes a surface integral
	$$ \phi = \oint\limits_{S}\textbf{E.dS}$$

	\subsection*{Gauss's law}
	In the simplest case, let's consider a charge $q$ at the center of an imaginary sphere with radius $r$. The electric field at a point on that surface is

	$$ \textbf{E} = \frac{q}{4\pi\epsilon_0 r^2} \hat{\textbf{r}} $$

	$$ \oint\limits_{S}\textbf{E.dS} = E(4\pi r^2) =  \frac{q(4\pi r^2)}{4 \pi \epsilon_0 r^2}$$

	$$ \oint\limits_{S}\textbf{E.dS} = \frac{q}{\epsilon_0} $$

	We notice that the flux is independent of the size of the sphere. In fact, the flux is independent of the shape as well. I will now summarize some key points.\\

	\begin{itemize}
		\item The law works even for irregular surfaces but we tend to use symmetrical surfaces because the the areal vector points radially outward, making a $0$ degree angle with \textbf{E}. So $\oint\limits_{S}\textbf{E.dS}$ becomes E$\cdot$S Also, it's easier to take a surface integral over them, as compared to irregular surfaces.

		\item Gauss's law and Coulomb's law aren't two independent concepts but different statements of the same thing. Coulomb's law lets us calculate electric field based on the magnitude of the charges while Gauss's law does the converse \textemdash it helps us calculate how much charge is contained, given the electric field over a closed surface
	\end{itemize}

	\subsection{Laplace's and Poisson's Equations}
		Since Gauss's law tells us
		$$ \oint \textbf{E}.\textbf{dS} = \frac{q}{\epsilon_0} $$
		We can rewrite this using Gauss's divergence theorem

		$$ \oiint \textbf{E}.\textbf{dS} = \iiint (\nabla . \textbf{E})dV = \frac{q}{\epsilon_0}$$
		or,
		\begin{equation}
		\label{maxwellfirst}
		\nabla . \textbf{E} = \frac{\rho}{\epsilon_0}
		\end{equation}
		which is Maxwell's first equation. Since electric fields are conservative,
		$$ \nabla \times \textbf{E} = 0 $$
		which implies that it should be possible to find a $\phi$ (potential function) such that,
		$$ \textbf{E} = -\nabla\phi $$

		Then we can rewrite equation (\ref{maxwellfirst}) as
		$$ - \nabla . \nabla\phi = \frac{\rho}{\epsilon_0}$$
		or
		$$\boxed{\nabla^2\phi = -\frac{\rho}{\epsilon_0}}$$
		This is known as \textbf{Poisson's equation}. In a charge-free region, $\rho$ becomes 0 and the equation reduces to \textbf{Laplace's equation}.

		$$\boxed{\nabla^2\phi = 0}$$

\end{document}

Electricity and Magnetism/Charges and fields.tex


\documentclass[11pt]{article}

\usepackage{sectsty}
\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage[backend=biber]{biblatex}
\usepackage{todonotes} % For taking notes while writing

\usepackage{gensymb} % For the degree command
\usepackage{amsmath}

% Margins
\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\title{ Title}
\author{ Author }
\date{\today}

\addbibresource{bibliography.bib}

\begin{document}
	\maketitle
	\pagebreak

	% Optional TOC
	% \tableofcontents
	% \pagebreak

\section{Abstract}

\section{Introduction}
\input{introduction}
\section{Methods}
\subsection{A generative statistical model implementing thermodynamic flux analysis}

This study proposes a new method for incorporating thermodynamic information
into an analysis of a metabolic network. We create a joint generative
statistical model of measurements of four kinds of quantity: metabolic fluxes,
metabolite concentrations, enzyme concentrations and Gibbs energies of
reaction. These are treated as interconnected, allowing for more precise
estimates than would be possible with independent analyses.

% ordering of rref for finding free fluxes determines more transport . Appendix?
\subsection{Generative model}

The system's fluxes are modelled as consisting of transport fluxes
$v_{transport}$ and fluxes $v_{enzyme}$ of enzyme-catalysed
reactions. Transport fluxes are treated as unknown model
parameters. Enzyme-catalysed reactions are treated as determined by Gibbs free
energies of reaction, enzyme concentrations and a latent parameter vector $b$,
which can be interpreted as the amount of flux carried by each enzyme at steady
state. The flux $v_{enzyme[ij]}$ of enzyme $i$ in condition $j$ is as follows:

\[
v_{enzyme[ij]} = -\Delta_rG_{reaction(i)} \cdot e_{ij} \cdot b_{ij}
\]

Gibbs free energies of reaction are treated as determined by metabolite
concentrations and formation energies as follows:

\[
\Delta_rG' = S^T(\Delta_fG' + RT\ln c)
\]

Since, by assumption the system is in a steady state, the unknown parameters
must satisfy the algebraic constraint $Sv = \mathbf{0}$. This is achieved by
fixing the values $\theta_{fixed}$ of $rank(S^T)$ many parameters so that they
solve the equation $Sv(\theta_{fixed}) = \mathbf{0}$.

Standard condition measurements of reaction gibbs free energies (as can be
derived, for example, from the TECRDB database) and metabolic fluxes (as
derived from fluxomics analysis) are represented using a standard linear
regression model:

\begin{align*}
	y_{\Delta_rG} &\sim N(\Delta_rG, \sigma_{\Delta_rG}) \\
	y_{v} &\sim N(v, \sigma_{v})
\end{align*}

Measurements of metabolite and enzyme concentrations, as derived from
metabolomics and proteomics analyses, are represented using a lognormal
generalised linear model:

\begin{align*}
	y_{c} & \sim LN(\ln(c), \sigma_{c}) \\
	y_{e} & \sim LN(\ln(e), \sigma_{e})
\end{align*}

This model is generative in the sense that, given an assignment of values to
the unknown parameters $\Delta_fG$, $c$, $e$, $b$, $\sigma_{\Delta_rG}$,
$\sigma_{v}$, $\sigma_c$ and $\sigma_{e}$ it is possible to simulate new values
for the measured quantities $y_{\Delta_rG}$, $y_v$, $y_c$ and $y_e$. The model
therefore represents a theory as to how the observed data was generated. The
theory can be tested both by comparing its predictions with real data and by
assessing the plausibility of its parameters.

\subsection{Contrast with traditional tfa}

Traditional thermodynamic flux analysis (TFA) seeks to improve analyses of
metabolic networks by taking advantage of information about the thermodynamic
properties of the chemical reactions involved. TFA has historically been
carried out within a constraint-based framework according to which the flux
profile of a biological system is predicted by optimising an objective function
representing the system's goals, subject to constraints imposed by the
available information. For example, according to the mass balance constraint,
metabolic fluxes must leave the system in a steady state.

In this framework thermodynamic information allows extra constraints to be
imposed, representing the fact that the amount and direction of the flux a
reaction carries is partly determined by its thermodynamic properties.

\section{Results and discussion}

\section{Conclusion}

\printbibliography

\end{document}


\section{Outlook}
The implementation discussed in this paper focused on scheduling and placement of Flink jobs with
knowledge about the physical network. Other issues and enhancements remain open to take complete
advantage of network aware job scheduling.

\subsection{Traffic Properties}
Monitoring would enable better scheduling and flow programming by taking latency and network
utilization into account. The OpenFlow specification \cite{openflow} offers port and flow based
packet and byte counters, but neither measures latency, nor bandwidth. Therefore monitoring has to
be somehow implemented.

One approach to determine latency between two switches is to insert additional OpenFlow packets and
measure the duration.  \texttt{PACKET OUT} messages forward additional packages to one or more
ports.  The OpenFlow controller receives a \texttt{PACKET IN} message when a switch could not assign
a packet to a flow of its flow table. The latency can then be easily calculated by subtracting the
time of packet creation and roundtrip times from the time the packet was received via \texttt{PACKET
IN}. \cite{monitoringlatency} \cite{opennetmon}

OpenFlow also supports a \texttt{FLOW REMOVED} message that is received by the controller when a
flow entry of a switch is expired. This message contains information about the duration an entry
was active in the flow table, the amount of traffic matched against an entry and the input port to
determine the source of traffic.  These information enable the computation of utilization between
inter-switch links. This approach does not produce any instrumentation overhead since the
\texttt{FLOW REMOVED} messages are send anyhow. \cite{flowsense}

Another way to measure network utilization is to poll the OpenFlow statistics. The problem is to
find an intelligent polling algorithm to reduce the load on switches. Using the routing information
of a flow is helpful to find an appropriate querying strategy.  A good compromise between accuracy
and load balancing is to query two switches randomly and select the one closer to the destination.
\cite{opentm} \cite{opennetmon}

There are implementations for the OpenFlow Controller POX \cite{opennetmon}, NOX \cite{opentm} and
Floodlight \cite{flowsense}.

\subsection{Load Balancing}
Even using the Bottom-Up approach, the possibility to control data flows in the network still remains.
The notion of balancing data flows of alike source and sink around multiple paths comes to mind.
OpenDaylights' default flow configuration reacts upon activation by a switch clueless to an incoming
packets' destination. The controller then prompts the updating of all switches connected to the controller
so that future packets to said destination host will follow along the shortest path.

This behavior might be sufficient in the case where sources and sinks are not grouped around common
switches but in our case we would have lots of tasks deployed on host groups characterized by single
switch connections due to our scheduling decisions. In the assumed case of all-to-all data-flows
between two or more host groups, we would not want to send all data along a single path. Even with
the switch of each host group posing as a natural bottleneck, we assume better overall load
balancing would stem from using more than a single shortest path which we could determine with Yen's
Algorithm \cite{yens}.


\documentclass{aastex63}
\usepackage[T1]{fontenc}
\usepackage{color}
\usepackage{amsmath}
\usepackage{natbib}
\usepackage{ctable}
\usepackage{bm}
\usepackage{xspace}

\usepackage{graphicx}

% math shih
\newcommand{\setof}[1]{\left\{{#1}\right\}}
\newcommand{\given}{\,|\,}
\newcommand{\lss}{{\small{LSS}}\xspace}

\newcommand{\Om}{\Omega_{\rm m}}
\newcommand{\Ob}{\Omega_{\rm b}}
\newcommand{\OL}{\Omega_\Lambda}
\newcommand{\smnu}{M_\nu}
\newcommand{\sig}{\sigma_8}
\newcommand{\mmin}{M_{\rm min}}
\newcommand{\BOk}{\widehat{B}_0}
\newcommand{\hmpc}{\,h/\mathrm{Mpc}}
\newcommand{\bfi}[1]{\textbf{\textit{#1}}}
\newcommand{\parti}[1]{\frac{\partial #1}{\partial \theta_i}}
\newcommand{\partj}[1]{\frac{\partial #1}{\partial \theta_j}}
\newcommand{\mpc}{{\rm Mpc}}
\newcommand{\eg}{\emph{e.g.}}
\newcommand{\ie}{\emph{i.e.}}

\let\oldAA\AA
\renewcommand{\AA}{\text{\normalfont\oldAA}}
% cmds for this paper
\newcommand{\gr}{g{-}r}
\newcommand{\fnuv}{FUV{-}NUV}
\newcommand{\sfr}{{\rm SFR}}
\newcommand{\ssfr}{{\rm SSFR}}
\newcommand{\mtaum}{m_{\tau,M_*}}
\newcommand{\mtaus}{m_{\tau,{\rm SSFR}}}
\newcommand{\ctau}{c_\tau}
\newcommand{\mdeltam}{m_{\delta,M_*}}
\newcommand{\mdeltas}{m_{\delta,{\rm SFR}}}
\newcommand{\cdelta}{c_\delta}
\newcommand{\eda}{EDA}

\newcommand{\specialcell}[2][c]{%
  \begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
% text shih
\newcommand{\foreign}[1]{\textsl{#1}}
\newcommand{\etal}{\foreign{et~al.}}
\newcommand{\opcit}{\foreign{Op.~cit.}}
\newcommand{\documentname}{\textsl{Article}}
\newcommand{\equationname}{equation}
\newcommand{\bitem}{\begin{itemize}}
\newcommand{\eitem}{\end{itemize}}
\newcommand{\beq}{\begin{equation}}
\newcommand{\eeq}{\end{equation}}

%% collaborating
\newcommand{\todo}[1]{\marginpar{\color{red}TODO}{\color{red}#1}}
\definecolor{orange}{rgb}{1,0.5,0}
\newcommand{\ch}[1]{#1}%{\color{orange}#1}}
\newcommand{\chedit}[1]{{\color{orange}#1}}
\newcommand{\tks}[1]{{\color{blue}#1}}
\newcommand{\tksedit}[1]{{\color{blue}#1}}

\shorttitle{The Empirical Dust Attenuation Framework}
\shortauthors{Hahn et al.}

\begin{document}

\title{IQ Collaboratory III: The Empirical Dust Attenuation Framework ---
Taking Hydrodynamical Simulations with a Grain of Dust}

\author[0000-0003-1197-0902]{ChangHoon Hahn}
\correspondingauthor{ChangHoon Hahn}
\email{changhoon.hahn@princeton.edu}
\affil{Department of Astrophysical Sciences, Princeton University, Peyton Hall, Princeton NJ 08544, USA}

\author{Tjitske K. Starkenburg}
\affil{Center for Interdisciplinary Exploration and Research in Astrophysics (CIERA) and \\Department of Physics and Astronomy, 1800 Sherman Ave, Evanston IL 60201, USA}

\author{Daniel Angl\'es-Alc\'azar}
\affil{Department of Physics, University of Connecticut, 196 Auditorium Road,
U-3046, Storrs, CT 06269-3046, USA}
\affil{Center for Computational Astrophysics, Flatiron Institute, 162 5th Ave,
New York, NY 10010, USA}

\author[0000-0002-8131-6378]{Ena Choi}
\affil{Quantum Universe Center,
        Korea Institute for Advanced Study,
        Hoegiro 85, Seoul 02455, Korea}

\author{Romeel Dav\'e}
\affil{Institute for Astronomy, Royal Observatory, Univ. of Edinburgh, Edinburgh EH9 3HJ, UK}
\affil{University of the Western Cape, Bellville, Cape Town 7535, South Africa}
\affil{South African Astronomical Observatories, Observatory, Cape Town 7925, South Africa}

\author[0000-0002-1081-3991]{Claire Dickey}
\affil{Department of Astronomy, Yale University, New Haven CT 06520 USA}

%\suppressAffiliations
\author[0000-0001-9298-3523]{Kartheik G. Iyer}
\affil{Dunlap Institute for Astronomy and Astrophysics, University of Toronto,
50 St George St, Toronto, ON M5S 3H4, Canada}

\author[0000-0003-2060-8331]{Ariyeh H. Maller}
\affil{Department of Physics, New York City College of Technology, City
University of New York, 300 Jay St., Brooklyn, NY 11201, USA}

\author{Rachel S. Somerville}
\affil{Department of Physics and Astronomy, Rutgers University, 136
Frelinghuysen Road, Piscataway, NJ 08854, USA}
\affil{Center for Computational Astrophysics, Flatiron Institute, 162 5th Ave,
New York, NY 10010, USA}

\author{Jeremy L. Tinker}
\affil{Center for Cosmology and Particle Physics, Department of Physics, New York University, 4 Washington Place, New York, NY 10003}

\author{L. Y. Aaron Yung}
\affil{Astrophysics Science Division, NASA Goddard Space Flight Center, 8800 Greenbelt Rd, Greenbelt, MD 20771, USA}

%\collaboration{2}{IQ Collaboratory}

%\AuthorCallLimit=3

\begin{abstract}
    We present the Empirical Dust Attenuation (\eda) framework --- a flexible
    prescription for
    %for applying dust attenuation to galaxies from theoretical models. \eda~provides a flexible prescription
    assigning realistic dust attenuation to simulated galaxies based on their
    physical properties. % ($M_*$, $\ssfr$). %  and using the \cite{noll2009} attenuation curve parameterization.
    We use the \eda~to forward model synthetic observations for three state-of-the-art large-scale cosmological
    hydrodynamical simulations: SIMBA, IllustrisTNG, and EAGLE.
    We then compare the optical
    and UV color-magnitude relations, $(\gr) - M_r$ and $(\fnuv)-M_r$, of the
    simulations to a $M_r < -20$ and UV complete SDSS galaxy sample using
    likelihood-free inference.
    Without dust, none of the simulations match observations, as expected.
    %As expected, the simulations cannot match observations without dust. % for all three simulations, dust attenuation is {\em necessary} to match the observations.
    With the \eda, however, we can reproduce the observed color-magnitude
    with all three simulations.
    %For SIMBA and TNG, we find an excess of luminous UV-red galaxies that dust cannot fix because the simulations quench star formation too efficiently in the most massive galaxies.
    Furthermore, the attenuation curves predicted by our dust prescription are
    in good agreement with the observed attenuation--slope relations and
    attenuation curves of star-forming galaxies.
    However, the \eda~does not predict star-forming galaxies with low
    $A_V$ since simulated star-forming galaxies are intrinsically much
    brighter than observations.
    Additionally, the \eda~provides, for the first time, predictions
    on the attenuation curves of quiescent galaxies, which are challenging to
    measure observationally.
    Simulated quiescent galaxies require shallower attenuation curves
    with lower amplitude than star-forming galaxies.
    %Overall, we find that more massive galaxies in the simulations require higher dust attenuation, while galaxies with higher specific star formation rates have steeper attenuation curves.
    The \eda, combined with forward modeling, provides an effective
    approach for shedding light on  dust in galaxies and
    probing hydrodynamical simulations.
    This work also illustrates a major limitation in comparing galaxy
    formation models: by adjusting dust attenuation, simulations that predict
    significantly different galaxy populations can reproduce the same UV
    and optical observations.
\end{abstract}

\keywords{
    galaxies: formation -- galaxies: evolution -- galaxies: statistics -- methods: numerical
}
\NewPageAfterKeywords

% --- intro ---
\input{intro}
% --- data ---
\input{sims}
% --- methods ---
\input{dem}

\input{abc}
% --- results ---
\input{results}
% --- summary ---
\input{summary}

\section*{Acknowledgements}
It's a pleasure to thank
    Michael Blanton,
    Nicholas T. Faucher,
    Marla Geha,
    Shy Genel,
    Jenny E. Green,
    Daniel Kelson,
    Mariska Kriek,
    Peter Melchior,
    Desika Narayanan,
    Samir Salim,
    and Katherine Suess for
valuable discussions and comments.
This material is based upon work supported by the U.S. Department of Energy,
Office of Science, Office of High Energy Physics, under contract No.
DE-AC02-05CH11231.
CH is supported by the AI Accelerator program of the Schmidt Futures Foundation.

We thank the Illustris collaboration and the Virgo Consortium for making their
simulation data publicly available, and the SIMBA collaboration for sharing
their data with us.
The EAGLE and SIMBA simulations were performed using the DiRAC-2 facility at
Durham, managed by the ICC, and the PRACE facility Curie based in France at
TGCC, CEA, Bruy\`{e}res-le-Ch\^{a}tel.

This research was supported in part through the computational resources and
staff contributions provided by the Quest high performance computing facility
at Northwestern University, which is jointly supported by the Office of the
Provost, the Office for Research, and Northwestern University Information
Technology.

The data used in this work were, in part, hosted on facilities supported by the
Scientific Computing Core at the Flatiron Institute, a division of the Simons
Foundation, and the analysis was largely done using those facilities.
The IQ~(Isolated \& Quiescent)~Collaboratory thanks the Flatiron Institute for hosting the collaboratory and its meetings.
The Flatiron Institute is supported by the Simons Foundation.
Funding for the Sloan Digital Sky Survey IV has been provided by the Alfred P.
Sloan Foundation, the U.S. Department of Energy Office of Science, and the
Participating Institutions. SDSS acknowledges support and resources from the
Center for High-Performance Computing at the University of Utah. The SDSS web
site is www.sdss.org.
The SDSS is managed by the Astrophysical Research Consortium for the
Participating Institutions.

\appendix
%\input{unc.tex}
%\input{res.tex}
\input{slab.tex}

\bibliographystyle{mnras}
\bibliography{galpopfm}

\end{document}


\subsection{Nullable class fields}
\label{subsec:library_of_transformations:type_level_transformations:nullable_class_fields}

\begin{figure}
    \centering
    \begin{subfigure}{0.95\textwidth}
        \centering
        \includegraphics{images/05_library_of_transformations/02_type_level_transformations/08_nullable_class_fields/nullable_class_field.pdf}
        \caption{$Tm_{NullableClassField}$ to a class type $.\type{TargetExample}$ with $name = \type{field}$}
        \label{fig:library_of_transformations:type_level_transformations:nullable_class_fields:visualisation:ecore}
    \end{subfigure}
    \\
    \begin{subfigure}{0.95\textwidth}
        \centering
        \input{images/05_library_of_transformations/02_type_level_transformations/08_nullable_class_fields/nullable_class_field_as_edge_type.tikz}
        \caption{$TG_{NullableClassField}$ to a class type $\type{TargetExample}$ with $name = \type{field}$}
        \label{fig:library_of_transformations:type_level_transformations:nullable_class_fields:visualisation:groove}
    \end{subfigure}
    \caption{Visualisation of the transformation of a field typed by an optional class type}
    \label{fig:library_of_transformations:type_level_transformations:nullable_class_fields:visualisation}
\end{figure}

The previous sections have shown transformations of fields to attribute types. It has not shown any relations between objects yet. This transformation defines the transformation of a nullable class field.

\begin{defin}[Type model $Tm_{NullableClassField}$]
\label{defin:library_of_transformations:type_level_transformations:nullable_class_fields:tmod_nullable_class_field}
Let $Tm_{NullableClassField}$ be the type model containing a regular class with identifier $classtype$. Then $Tm_{NullableClassField}$ defines a field named $name$ with type $fieldtype$, in which $fieldtype$ is the identifier of another class type in $Tm_{NullableClassField}$. $Tm_{NullableClassField}$ is defined as:
\begin{align*}
Class =\ &\{classtype, fieldtype\} \\
Enum =\ &\{\} \\
UserDataType =\ &\{\} \\
Field =\ &\{(classtype, name)\} \\
\mathrm{FieldSig} =\ &\begin{cases}
    (f, (?fieldtype, 0..1)) &\mathrm{if}\ f \in Field_{Tm_{NullableClassField}}
\end{cases} \\
EnumValue =\ &\{\} \\
Inh =\ &\{\} \\
Prop =\ &\{\} \\
Constant =\ &\{\} \\
\mathrm{ConstType} =\ &\{\}
\end{align*}
\isabellelref{tmod_nullable_class_field}{Ecore-GROOVE-Mapping-Library.NullableClassField}
\end{defin}

\begin{thm}[Correctness of $Tm_{NullableClassField}$]
\label{defin:library_of_transformations:type_level_transformations:nullable_class_fields:tmod_nullable_class_field_correct}
$Tm_{NullableClassField}$ (\cref{defin:library_of_transformations:type_level_transformations:nullable_class_fields:tmod_nullable_class_field}) is a consistent type model in the sense of \cref{defin:formalisations:ecore_formalisation:type_models:type_model_consistency}.
\isabellelref{tmod_nullable_class_field_correct}{Ecore-GROOVE-Mapping-Library.NullableClassField}
\end{thm}

A visual representation of $Tm_{NullableClassField}$ with field name $\type{field}$ on class $.\type{Example}$ can be seen in \cref{fig:library_of_transformations:type_level_transformations:nullable_class_fields:visualisation:ecore}. In this example, $\type{field}$ references a class of $.\type{TargetExample}$. Please note that the lower bound of the multiplicity is 0 as the class is considered nullable. That means that setting a value for $\type{field}$ on class $.\type{Example}$ is optional. The correctness proof of $Tm_{NullableClassField}$ is more involved, it is not included here for conciseness. It can be found within the validated Isabelle proofs.

In order to make composing transformation functions possible, $Tm_{NullableClassField}$ should be compatible with the type model it is combined with.

\begin{thm}[Correctness of $\mathrm{combine}(Tm, Tm_{NullableClassField})$]
\label{defin:library_of_transformations:type_level_transformations:nullable_class_fields:tmod_nullable_class_field_combine_correct}
Assume a type model $Tm$ that is consistent in the sense of \cref{defin:formalisations:ecore_formalisation:type_models:type_model_consistency}. Then $Tm$ is compatible with $Tm_{NullableClassField}$ (in the sense of \cref{defin:transformation_framework:type_models_and_type_graphs:combining_type_models:compatibility}) if:
\begin{itemize}
    \item The class type on which the field is defined, $classtype$, is already an existing class in $Tm$;
    \item The class type which the field targets, $fieldtype$, is already an existing class in $Tm$;
    \item The field named $name$ is not already a field on $classtype$ in $Tm$.
\end{itemize}
\isabellelref{tmod_nullable_class_field_combine_correct}{Ecore-GROOVE-Mapping-Library.NullableClassField}
\end{thm}

\begin{proof}
Use \cref{defin:transformation_framework:type_models_and_type_graphs:combining_type_models:tmod_combine_merge_correct}. It is possible to show that all assumptions hold. Now we have shown that $\mathrm{combine}(Tm, Tm_{NullableClassField})$ is consistent in the sense of \cref{defin:formalisations:ecore_formalisation:type_models:type_model_consistency}.
\end{proof}

The definitions and theorems for defining a data field within Ecore are now complete.

\subsubsection{Encoding as edge type}

Like any field definition so far, an edge type will be used within GROOVE to encode the field. The field is transformed into an edge type from the encoded class type to the encoded target type. The encoding corresponding to $Tm_{NullableClassField}$ can then be represented as $TG_{NullableClassField}$, defined in the following definition:

\begin{defin}[Type graph $TG_{NullableClassField}$]
\label{defin:library_of_transformations:type_level_transformations:nullable_class_fields:tg_nullable_class_field_as_edge_type}
Let $TG_{NullableClassField}$ be the type graph containing a node type which encodes the class type $classtype$. Furthermore, define an edge type from $classtype$ named $name$. This edge type targets a node of $fieldtype$. $TG_{NullableClassField}$ is defined as:
\begin{align*}
NT =\ &\{\mathrm{ns\_\!to\_\!list}(classtype), \mathrm{ns\_\!to\_\!list}(fieldtype)\} \\
ET =\ &\{(\mathrm{ns\_\!to\_\!list}(classtype), \langle name \rangle, \mathrm{ns\_\!to\_\!list}(fieldtype))\} \\
\!\!\sqsubseteq\ =\ &\{( \mathrm{ns\_\!to\_\!list}(classtype), \mathrm{ns\_\!to\_\!list}(classtype) ),\\&( \mathrm{ns\_\!to\_\!list}(fieldtype), \mathrm{ns\_\!to\_\!list}(fieldtype) )\} \\
abs =\ &\{\} \\
\mathrm{mult}(e) =\ &\begin{cases}
    (0..\mstar, 0..1) &\mathrm{if}\ e \in \{(\mathrm{ns\_\!to\_\!list}(classtype), \langle name \rangle, \mathrm{ns\_\!to\_\!list}(fieldtype))\}
\end{cases} \\
contains =\ &\{\}
\end{align*}
\isabellelref{tg_nullable_class_field_as_edge_type}{Ecore-GROOVE-Mapping-Library.NullableClassField}
\end{defin}

\begin{thm}[Correctness of $TG_{NullableClassField}$]
\label{defin:library_of_transformations:type_level_transformations:nullable_class_fields:tg_nullable_class_field_as_edge_type_correct}
$TG_{NullableClassField}$ (\cref{defin:library_of_transformations:type_level_transformations:nullable_class_fields:tg_nullable_class_field_as_edge_type}) is a valid type graph in the sense of \cref{defin:formalisations:groove_formalisation:type_graphs:type_graph_validity}.
\isabellelref{tg_nullable_class_field_as_edge_type_correct}{Ecore-GROOVE-Mapping-Library.NullableClassField}
\end{thm}

A visual representation of $TG_{NullableClassField}$ with edge name $\type{field}$ on node type $\type{Example}$ can be seen in \cref{fig:library_of_transformations:type_level_transformations:nullable_class_fields:visualisation:groove}. Like the previous example, $\type{field}$ references the $.\type{TargetExample}$ class, but in this case the encoded node type of $\type{TargetExample}$. The correctness proof of $TG_{NullableClassField}$ is more involved, it is not included here for conciseness. It can be found within the validated Isabelle proofs.

In order to make composing transformation functions possible, $TG_{NullableClassField}$ should be compatible with the type graph it is combined with.

\begin{thm}[Correctness of $\mathrm{combine}(TG, TG_{NullableClassField})$]
\label{defin:library_of_transformations:type_level_transformations:nullable_class_fields:tg_nullable_class_field_as_edge_type_combine_correct}
Assume a type graph $TG$ that is valid in the sense of \cref{defin:formalisations:groove_formalisation:type_graphs:type_graph_validity}. Then $TG$ is compatible with $TG_{NullableClassField}$ (in the sense of \cref{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:compatibility}) if:
\begin{itemize}
    \item The node types of the encoded class types in $TG_{NullableClassField}$ are already node types in $TG$;
    \item The node type of the encoded class type in $TG_{NullableClassField}$ does not already have an edge type with the same name as the field in $TG$.
\end{itemize}
\isabellelref{tg_nullable_class_field_as_edge_type_combine_correct}{Ecore-GROOVE-Mapping-Library.NullableClassField}
\end{thm}

\begin{proof}
Use \cref{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:tg_combine_merge_correct}. It is possible to show that all assumptions hold. Now we have shown that $\mathrm{combine}(TG, TG_{NullableClassField})$ is valid in the sense of \cref{defin:formalisations:groove_formalisation:type_graphs:type_graph_validity}.
\end{proof}

The next definitions define the transformation function from $Tm_{NullableClassField}$ to $TG_{NullableClassField}$:

\begin{defin}[Transformation function $f_{NullableClassField}$]
\label{defin:library_of_transformations:type_level_transformations:nullable_class_fields:tmod_nullable_class_field_to_tg_nullable_class_field_as_edge_type}
The transformation function $f_{NullableClassField}(Tm)$ is defined as:
\begin{align*}
NT =\ &\{\mathrm{ns\_\!to\_\!list}(c) \mid c \in Class_{Tm}\}\\
ET =\ &\{(\mathrm{ns\_\!to\_\!list}(c), \langle f \rangle, \mathrm{ns\_\!to\_\!list}(fieldtype)) \mid (c, n) \in Field_{Tm} \} \\
\!\!\sqsubseteq\ =\ &\{( \mathrm{ns\_\!to\_\!list}(c), \mathrm{ns\_\!to\_\!list}(c) ) \mid c \in Class_{Tm} \} \\
abs =\ &\{\} \\
\mathrm{mult} =\ &\begin{cases}
    (0..\mstar, 0..1) &\mathrm{if}\ e \in \{(\mathrm{ns\_\!to\_\!list}(c), \langle f \rangle, \mathrm{ns\_\!to\_\!list}(fieldtype)) \mid (c, n) \in Field_{Tm} \}
\end{cases} \\
contains =\ &\{\}
\end{align*}
\isabellelref{tmod_nullable_class_field_to_tg_nullable_class_field_as_edge_type}{Ecore-GROOVE-Mapping-Library.NullableClassField}
\end{defin}

\begin{thm}[Correctness of $f_{NullableClassField}$]
\label{defin:library_of_transformations:type_level_transformations:nullable_class_fields:tmod_nullable_class_field_to_tg_nullable_class_field_as_edge_type_func}
$f_{NullableClassField}(Tm)$ (\cref{defin:library_of_transformations:type_level_transformations:nullable_class_fields:tmod_nullable_class_field_to_tg_nullable_class_field_as_edge_type}) is a valid transformation function in the sense of \cref{defin:transformation_framework:type_models_and_type_graphs:combining_transformation_functions:transformation_function_type_model_type_graph} transforming $Tm_{NullableClassField}$ into $TG_{NullableClassField}$.
\isabellelref{tmod_nullable_class_field_to_tg_nullable_class_field_as_edge_type_func}{Ecore-GROOVE-Mapping-Library.NullableClassField}
\end{thm}

The proof of the correctness of $f_{NullableClassField}$ will not be included here. Instead, it can be found in the validated Isabelle theories.

Finally, to complete the transformation, the transformation function that transforms $TG_{NullableClassField}$ into $Tm_{NullableClassField}$ is defined:

\begin{defin}[Transformation function $f'_{NullableClassField}$]
\label{defin:library_of_transformations:type_level_transformations:nullable_class_fields:tg_nullable_class_field_as_edge_type_to_tmod_nullable_class_field}
The transformation function $f'_{NullableClassField}(TG)$ is defined as:
\begin{align*}
Class =\ &\{\mathrm{list\_\!to\_\!ns}(n) \mid n \in NT_{TG} \} \\
Enum =\ &\{\} \\
UserDataType =\ &\{\} \\
Field =\ &\{(\mathrm{list\_\!to\_\!ns}(\mathrm{src}(e)), l) \mid e \in ET_{TG} \land \langle l \rangle = \mathrm{lab}(e) \} \\
\mathrm{FieldSig} =\ &\begin{cases}
    (f, (?fieldtype, 0..1)) &\mathrm{if}\ f \in \{(\mathrm{list\_\!to\_\!ns}(\mathrm{src}(e)), l) \mid e \in ET_{TG} \land \langle l \rangle = \mathrm{lab}(e) \}
\end{cases} \\
EnumValue =\ &\{\} \\
Inh =\ &\{\} \\
Prop =\ &\{\} \\
Constant =\ &\{\} \\
\mathrm{ConstType} =\ &\{\}
\end{align*}
\isabellelref{tg_nullable_class_field_as_edge_type_to_tmod_nullable_class_field}{Ecore-GROOVE-Mapping-Library.NullableClassField}
\end{defin}

\begin{thm}[Correctness of $f'_{NullableClassField}$]
\label{defin:library_of_transformations:type_level_transformations:nullable_class_fields:tg_nullable_class_field_as_edge_type_to_tmod_nullable_class_field_func}
$f'_{NullableClassField}(TG)$ (\cref{defin:library_of_transformations:type_level_transformations:nullable_class_fields:tg_nullable_class_field_as_edge_type_to_tmod_nullable_class_field}) is a valid transformation function in the sense of \cref{defin:transformation_framework:type_models_and_type_graphs:combining_transformation_functions:transformation_function_type_graph_type_model} transforming $TG_{NullableClassField}$ into $Tm_{NullableClassField}$.
\isabellelref{tg_nullable_class_field_as_edge_type_to_tmod_nullable_class_field_func}{Ecore-GROOVE-Mapping-Library.NullableClassField}
\end{thm}

Once more, the correctness proof is not included here but can be found in the validated Isabelle proofs of this thesis.


\section{Hebelproblem}
The Hebel has a position betreen -2 and 2.
\newpage
\subsection{Asynchron Order}
$
A=
\{\text{Move\_R}(agt,obj,pos) \ | \ agt \in \mathcal{A} \ \& \ obj \in Obj \ \& \ pos \in \{ -2;1\}\} \cup \\
\{\text{Move\_L}(agt,obj,pos) \ | \ agt \in \mathcal{A} \ \& \ obj \in Obj \ \& \ pos \in \{ -1;2\}\} \\
\text{where} \ \forall \ agt \in \mathcal{A}, pos \in \{ -2;2\}, obj \in Obj ,
$
\begin{itemize}
  \item $
    \text{Move\_R}(obj,pos) = \langle \text{At}(obj, pos) , \text{At}(obj, pos+=1) \wedge \neg \text{At}(obj,pos) \rangle
    $
  \item $
    \text{Move\_L}(obj,pos) = \langle \text{At}(obj, pos) , \text{At}(obj, pos-=1) \wedge \neg \text{At}(obj,pos) \rangle
    $
\end{itemize}
$\mathcal{A}= \{Player1, Player2\}$ \\
$\varphi^{Player1}_g = \text{At(Hebel},-2)$ \todo{das g hier muss anders} \\
$\varphi^{Player2}_g = \text{At(Hebel},2)$ \\
Ist dann $\varphi_g = \text{At(Hebel,L}_2) \wedge \text{At(Hebel,R}_2)$ ? \\
$s_0 = \{\text{At(Hebel}, 0) \}$

\todo{Die Spielabfolge und das Problem ausführlich formulieren}

The agents here only have an incentive to move the Hebel in their direction. One possible execution would be that the agents each move the Hebel one step towards their goal and the other agent would move the Hebel back to the starting position. This is a infinite sequence which is not successful.

The solution to this problem could be the introduction of a token, which gives one agent the ability to move multiple times and prevents the other agents from doing any other action.

\newpage

\subsection{Table Token}
In A it is a precondition for all move objectives to have the token. There is another Task to take the token and one to give the token up. In the beginning the Token is lying on a table and an agent can just take it. \\
$
A=
\{\text{Move\_R}(agt,obj,pos,token) \ | \ agt \in \mathcal{A} \ \& \ obj \in Obj \ \& \ pos \in \{ -2;1\}\} \cup \\
\{\text{Move\_L}(agt,obj,pos,token) \ | \ agt \in \mathcal{A} \ \& \ obj \in Obj \ \& \ pos \in \{ -1;2\}\} \\
\{\text{Take\_Token}(agt, token) \ | \ agt \in \mathcal{A} \ \& \ token \in Token \} \\
\{\text{Give\_Token}(agt, token, otheragt) \ | \ agt \in \mathcal{A} \ \& \ token \in Token \ \& \ otheragt \in \mathcal{A}\backslash agt \} \\
\text{where} \ \forall \ agt \in \mathcal{A}, pos \in \{ -2;2\}, obj \in Obj ,
$
\begin{itemize}
  \item $
    \text{Move\_R}(agt,obj,pos) = \langle \text{At}(obj, pos) \wedge \text{Has}(agt, token) , \text{At}(obj, pos+=1) \wedge \neg \text{At}(obj,pos) \rangle
    $
  \item $
    \text{Move\_L}(agt,obj,pos) = \langle \text{At}(obj, pos) \wedge \text{Has}(agt, token) , \text{At}(obj, pos-=1) \wedge \neg \text{At}(obj,pos) \rangle
    $
  \item $
    \text{Take\_Token}(agt, token) = \langle \neg \text{Has}(agt, token) \wedge \text{At}(token, table), \text{Has}(agt, token) \wedge \neg  \text{At}(token, table) \rangle
    $ \todo{Hier fehlt, dass kein Agent das Token haben darf}
  \item $
    \text{Give\_Token}(agt, token, otheragt) = \langle
    \text{Has}(agt, token), \neg \text{Has}(agt, token) \wedge
    \text{Has}(otheragt, token)
    \rangle
  $
\end{itemize}

$s_0=\{\text{At(Hebel, N)}, \text{At(Token, Table)}\}$
\todo{Ausführung dokumentieren}

Here one of the agents will take the token and complete their goal. The other agent will not be able to move until they have the token. This way the game will be able to be completed.

This only works when the agents are eager.
A lazy agent would not even pick up the token from the table because then it would have to do something. But since a lazy agent has a preference agaist its own actions the token will just stay on the table and the game would be lost.

\todo{Spülmaschinenproblem?}

\newpage

\subsection{Asynchron beginning Token}
  In A it is a precondition for all move objectives to have the token. There is another Task to take the token and one to give the token up. In the beginning it is unclear which agent has the token first. \\
  $
  A=
  \{\text{Move\_R}(agt,obj,pos,token) \ | \ agt \in \mathcal{A} \ \& \ obj \in Obj \ \& \ pos \in \{ -2;1\}\} \cup \\
  \{\text{Move\_L}(agt,obj,pos,token) \ | \ agt \in \mathcal{A} \ \& \ obj \in Obj \ \& \ pos \in \{ -1;2\}\} \\
  \{\text{Give\_Token}(agt, token, otheragt) \ | \ agt \in \mathcal{A} \ \& \ token \in Token \ \& \ otheragt \in \mathcal{A}\backslash agt \} \\
  \text{where} \ \forall \ agt \in \mathcal{A}, pos \in \{ -2;2\}, obj \in Obj ,
  $
  \begin{itemize}
    \item $
      \text{Move\_R}(agt,obj,pos) = \langle \text{At}(obj, pos) \wedge \text{Has}(agt, token) , \text{At}(obj, pos+=1) \wedge \neg \text{At}(obj,pos) \rangle
      $
    \item $
      \text{Move\_L}(agt,obj,pos) = \langle \text{At}(obj, pos) \wedge \text{Has}(agt, token) , \text{At}(obj, pos-=1) \wedge \neg \text{At}(obj,pos) \rangle
      $
    \item $
      \text{Give\_Token}(agt, token, otheragt) = \langle
      \text{Has}(agt, token), \neg \text{Has}(agt, token) \wedge
      \text{Has}(otheragt, token)
      \rangle
    $
  \end{itemize}

  $s_0=\{\text{At(Hebel, N)}\}$

  This would work for this Problem. The game is solvable in the first try. \\
  This token strategy is always better than no token strategy because every game that is solvable with the asynchron order is also solvable with this token order. But more games that result in a deadlock like the example above will also be solvable.

  But again there is the problem with lazy agents. Lazy agents would plan on not getting the token and therefore the game will be lost. A way to solve this problem could be to randomly pick an agent to get the token.

  \todo{the agent has to do something before giving up the token? This is not formalized}

\newpage

\subsection{random beginnig Token}
  In A it is a precondition for all move objectives to have the token. There is another Task to take the token and one to give the token up. In the beginning one agent will be choosen at random to have the token first. \\
  $
  A=
  \{\text{Move\_R}(agt,obj,pos,token) \ | \ agt \in \mathcal{A} \ \& \ obj \in Obj \ \& \ pos \in \{ -2;1\}\} \cup \\
  \{\text{Move\_L}(agt,obj,pos,token) \ | \ agt \in \mathcal{A} \ \& \ obj \in Obj \ \& \ pos \in \{ -1;2\}\} \\
  \{\text{Give\_Token}(agt, token, otheragt) \ | \ agt \in \mathcal{A} \ \& \ token \in Token \ \& \ otheragt \in \mathcal{A}\backslash agt \} \\
  \text{where} \ \forall \ agt \in \mathcal{A}, pos \in \{ -2;2\}, obj \in Obj ,
  $
  \begin{itemize}
    \item $
      \text{Move\_R}(agt,obj,pos) = \langle \text{At}(obj, pos) \wedge \text{Has}(agt, token) , \text{At}(obj, pos+=1) \wedge \neg \text{At}(obj,pos) \rangle
      $
    \item $
      \text{Move\_L}(agt,obj,pos) = \langle \text{At}(obj, pos) \wedge \text{Has}(agt, token) , \text{At}(obj, pos-=1) \wedge \neg \text{At}(obj,pos) \rangle
      $
    \item $
      \text{Give\_Token}(agt, token, otheragt) = \langle
      \text{Has}(agt, token), \neg \text{Has}(agt, token) \wedge
      \text{Has}(otheragt, token)
      \rangle
    $
  \end{itemize}

  $s_0=\{\text{At(Hebel, N), Has(randomagent} \in \mathcal{A},\text{Token)}\}$

  This way there will not be a problem with lazy agents not doing anything because they will have to plan with the option to be chosen first and then they would have to complete the game.

  This will not work if the agent that is chosen at random is blocked off by other agents and not able to preform any action at all. To solve this problem we could introduce another question where all agents are first asked if they can preform an useful action.

\subsection{better random beginnig Token}
  The problem with this token form is when no agent is able to do anything useful. Then this way of distributing the token will not work. We could introduce another question that asks who can preform any action at all and then distribute the token at random amongst those agents.

  The problem with the tokens is the allocation of the token in the beginning. Each allocation type brings advantages, but also has some disadvantages. Lets start with the straightforward allocation we used up to now.

  \section{Asynchronous execution order}
    The first execution order is seemingly random. Some undefined agent has the token in the beginning. The advantage is that you do not have to define anything in the beginning, but this is also a disadvantage, since this token is defined, but the agent that has it in the beginning is not.

    There are three other ways to introduce a token to this game.
    \begin{enumerate}
      \item Table token - the token is lying on a table and one of the agents can take the token in the beginning. \\
      The disadvantage becomes clear in the example with the dishwasher. No agent would take the token.
      \item give token - in the specification of the game it is also specified which agent will have the token in the beginning. \\
      The problem with this introduction is that in every new game, this has to be written in the definition of the game. In order for the game to be efficient, it should be given to a player who has found a plan.
      \item random token - the token is given to a random agent in the beginning. If that agent can not preform any action it can pass the token to a player who can. \\
      An agent who knows nothing and has no action will prevent the game from ever reaching a goal state.
    \end{enumerate}

  Each version has its own drawbacks. In every game, you have to know the occurring problem beforehand to know which token allocation is efficient.

  %\section{Token versions}

  %\subsection{table token}
  %  $
  %  A=
  %  \{\text{Move\_R}(agt,obj,pos,token) \ | \ agt \in \mathcal{A} \ \& \ obj \in Obj \ \& \ pos \in \{ -2;1\}\} \cup \\
  %  \{\text{Move\_L}(agt,obj,pos,token) \ | \ agt \in \mathcal{A} \ \& \ obj \in Obj \ \& \ pos \in \{ -1;2\}\} \\
  %  \{\text{Take\_Token}(agt, token) \ | \ agt \in \mathcal{A} \ \& \ token \in Token \} \\
  %  \{\text{Give\_Token}(agt, token, otheragt) \ | \ agt \in \mathcal{A} \ \& \ token \in Token \ \& \ otheragt \in \mathcal{A}\backslash agt \} \\
  %  \text{where} \ \forall \ agt \in \mathcal{A}, pos \in \{ -2;2\}, obj \in Obj , |Token| = 1
  %  $
  %  \begin{itemize}
  %    \item $
  %      \text{Move\_R}(agt,obj,pos,token) = \langle \text{At}(obj, pos) \wedge \text{Has}(agt, token) , \text{At}(obj, pos+1) \wedge \neg \text{At}(obj,pos) \rangle
  %      $
  %    \item $
  %      \text{Move\_L}(agt,obj,pos,token) = \langle \text{At}(obj, pos) \wedge \text{Has}(agt, token) , \text{At}(obj, pos-1) \wedge \neg \text{At}(obj,pos) \rangle
    %    $
  %    \item $
    %    \text{Take\_Token}(agt, token) = \langle \neg \text{Has}(agt, token) \wedge \text{At}(token, table), \text{Has}(agt, token) \wedge \neg  \text{At}(token, table) \rangle
  %      $
  %    \item $
  %      \text{Give\_Token}(agt, token, otheragt) = \langle
  %      \text{Has}(agt, token), \neg \text{Has}(agt, token) \wedge
  %      \text{Has}(otheragt, token)
  %      \rangle
  %    $
  %  \end{itemize}

  %  $s_0=\{\text{At(Hebel, N)}, \text{At(Token, Table)}\}$

  %\subsection{give Token}
  %  $
  %  A=
  %  \{\text{Move\_R}(agt,obj,pos,token) \ | \ agt \in \mathcal{A} \ \& \ obj \in Obj \ \& \ pos \in \{ -2;1\}\} \cup \\
  %  \{\text{Move\_L}(agt,obj,pos,token) \ | \ agt \in \mathcal{A} \ \& \ obj \in Obj \ \& \ pos \in \{ -1;2\}\} \\
  %  \{\text{Give\_Token}(agt, token, otheragt) \ | \ agt \in \mathcal{A} \ \& \ token \in Token \ \& \ otheragt \in \mathcal{A}\backslash agt \} \\
  %  \text{where} \ \forall \ agt \in \mathcal{A}, pos \in \{ -2;2\}, obj \in Obj , |Token| = 1
    %$
    %\begin{itemize}
    %  \item $
      %  \text{Move\_R}(agt,obj,pos,token) = \langle \text{At}(obj, pos) \wedge \text{Has}(agt, token) , \text{At}(obj, pos+1) \wedge \neg \text{At}(obj,pos) \rangle
    %    $
    %  \item $
    %    \text{Move\_L}(agt,obj,pos,token) = \langle \text{At}(obj, pos) \wedge \text{Has}(agt, token) , \text{At}(obj, pos-1) \wedge \neg \text{At}(obj,pos) \rangle
    %    $
    %  \item $
    %    \text{Give\_Token}(agt, token, otheragt) = \langle
    %    \text{Has}(agt, token), \neg \text{Has}(agt, token) \wedge
    %    \text{Has}(otheragt, token)
    %    \rangle
    %  $
    %\end{itemize}

    %$s_0=\{\text{At(Hebel, N), Has(agent} \in \mathcal{A},\text{Token)}\}$

  %\subsection{random token}
  %  $
  %  A=
  %  \{\text{Move\_R}(agt,obj,pos,token) \ | \ agt \in \mathcal{A} \ \& \ obj \in Obj \ \& \ pos \in \{ -2;1\}\} \cup \\
  %  \{\text{Move\_L}(agt,obj,pos,token) \ | \ agt \in \mathcal{A} \ \& \ obj \in Obj \ \& \ pos \in \{ -1;2\}\} \\
  %  \{\text{Give\_Token}(agt, token, otheragt) \ | \ agt \in \mathcal{A} \ \& \ token \in Token \ \& \ otheragt \in \mathcal{A}\backslash agt \} \\
  %  \text{where} \ \forall \ agt \in \mathcal{A}, pos \in \{ -2;2\}, obj \in Obj , |Token| = 1
  %  $
  %  \begin{itemize}
  %    \item $
  %      \text{Move\_R}(agt,obj,pos,token) = \langle \text{At}(obj, pos) \wedge \text{Has}(agt, token) , \text{At}(obj, pos+1) \wedge \neg \text{At}(obj,pos) \rangle
  %      $
  %    \item $
  %      \text{Move\_L}(agt,obj,pos,token) = \langle \text{At}(obj, pos) \wedge \text{Has}(agt, token) , \text{At}(obj, pos-1) \wedge \neg \text{At}(obj,pos) \rangle
    %    $
    %  \item $
    %    \text{Give\_Token}(agt, token, otheragt) = \langle
    %    \text{Has}(agt, token), \neg \text{Has}(agt, token) \wedge
    %    \text{Has}(otheragt, token)
    %    \rangle
    %  $
    %\end{itemize}

    %$s_0=\{\text{At(Hebel, N), Has(randomagent} \in \mathcal{A},\text{Token)}\}$


\documentclass[11pt]{report}

\usepackage{epsf,amsmath,amsfonts}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{color}
\usepackage{natbib}
\usepackage{multirow}
\usepackage{hyperref}

\setlength{\textwidth}{6.5in}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}
\setlength{\textheight}{8in}
\setlength{\topmargin}{0.5in}

\newcommand{\ds}{\displaystyle}
\setlength{\parskip}{1.2ex}
\setlength{\parindent}{0mm}
\newcommand{\bea}{\begin{eqnarray}}
\newcommand{\eea}{\end{eqnarray}}
\newcommand{\nn}{\nonumber}

\def\Mark#1{{\textcolor{red}{\bf \textit{By Mark: } #1}}} % new text
\def\Phillip#1{{\textcolor{cyan}{\bf \textit{By PhilW: } #1}}} % new text
\def\Steven#1{{\textcolor{blue}{\bf \textit{By Steven: } #1}}} % new text
\def\Luke#1{{\textcolor{green}{\bf \textit{By Luke: } #1}}} % new text
\def\Comment#1{{\textcolor{magenta}{\bf \textit{Comment: } #1}}} % new text
\begin{document}

\title{MPAS-O Ocean Tidal Harmonic Decomposition }
\author{Steven Brus, Brian Arbic, Kristin Barton, Nairita Pal, \\ Mark Petersen, Andrew Roberts, Joannes Westerink }

\maketitle
\tableofcontents

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

\chapter{Summary}

%The purpose of this section is to summarize what capability is to be added to the MPAS system through this design process. It should be clear what new code will do that the current code does not. Summarizing the primary challenges with respect to software design and implementation is also appropriate for this section. Finally, this statement should contain general statement with regard to what is ``success.''

\section{MPAS-Ocean contributions}
Decomposing the computed sea surface height into the amplitude and phase of the known tidal constituent frequencies is a common and useful way to visualize and validate tidal model results. These types of global plots are also valuable in assessing how changes in the model (mesh resolution, bathymetry, parameterizations, etc.) effect the tides globally.

In a harmonic decomposition, the sea surface is approximated as a harmonic series with known constituent frequencies. The amplitudes and phases associated with these frequencies must be solved for in a manner that most closely matches the time series of the actual computed sea surface height with the series approximation. Once these amplitudes and phases are known, they can be plotted globally for each tidal constituent and compared with highly accurate data-assimilated tidal models.

This type of analysis is implemented as a new analysis member in MPAS-Ocean. This allows the time interval at which the analysis is computed and written to file to be controlled using existing code infrastructure. It also allows this capability to be easily turned off for simulations which do not include tidal forcing.

The methodology implemented is based on the harmonic least squares method \cite{westerink_lsq} implemented in the ADCIRC model \cite{Luettich1992ADCIRC} and borrows routines from the ADCIRC source code.

\section{Science Questions}
\begin{enumerate}
    \item Assess the accuracy of MPAS-Ocean tidal simulations with observations and highly accurate, data-assimilated tidal models
    \item Identify regions where the computed tidal solution is inaccurate to focus efforts on improving accuracy due to mesh resolution, bathymetry, dissipation parameterizations, etc.
    \item Demonstrate how coupling with other E3SM components effects the computed tidal solution
\end{enumerate}

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

\chapter{Requirements}

\section{Requirement: The harmonic analysis should decompose the computed sea surface height into amplitude and phase values for each major tidal constituent}
The amplitudes and phases associated with the known constituent frequencies must be solved for in a manner that most closely matches the actual computed sea surface height with the series approximation. The method must be able to selectively and accurately separate closely spaced harmonics.

\section{Requirement: Decomposition is calculated on-line during the simulations}
The harmonic analysis capability should not require writing high-frequency global time-series to file. This would result in large storage requirements and require a subsequent step to compute the decomposition.

\section{Requirement: Harmonic analysis should be able to be restarted at any point in the simulation}
The restarted simulation should produce a result that is bit-for-bit with the uninterrupted simulation.

\section{Requirement: The harmonic analysis should allow for general specification of the tidal constituent frequencies included in the analysis}
Each of the major constituents should have namelist options which specify whether a given constituent is used in the analysis.

\section{Requirement: The time period over which the harmonic analysis is performed should be user-specified}
The harmonic analysis should not include the tidal-spin up period used to ramp the tidal forcing at the beginning of the simulation. Also, in some situations, additional time-series information does not improve the results of the decomposition.

\section{Requirement: The interval at which the computed sea surface height is sampled for the harmonic analysis should be user-specified }
This sampling interval can be used to controls the balance of accuracy and efficiency in the harmonic decomposition.
%-----------------------------------------------------------------------

\chapter{Algorithmic Formulations}
Information in sections \ref{sec:astronomical_forcing}-\ref{sec:goverining_eqns} is reproduced here from the Tides Design Document for completeness.

\section{Astronomical forcing}
\label{sec:astronomical_forcing}
The Newtonian equilibrium tidal potential is given by $\eta_{EQ}$.  For the three largest semidiurnal tidal constituents, $\eta_{EQ}$ is given by equation (5) from \citet{chassignet_primer_2018} for $i=$ M$_{2}$, S$_{2}$, N$_{2}$ (applied 3 times and summed together), viz:
\begin{equation}
\eta_{EQ,i} = A_if_i(t_{ref})(1+k_{2,i}-h_{2,i})\cos^2(\phi)\cos\left[\omega_i(t-t_{ref}) + \chi_i(t_{ref}) + \nu_i(t_{ref}) + 2\lambda\right],
\label{eq:Eq5}
\end{equation}

where the tidal amplitude is $A$, $f(t_{ref})$ is the the nodal factor accounting for the small modulations of amplitude (computed about once per year), $f(t_{ref})$ is slow modulation of amplitude (computed about once per year), the Love numbers $k_2$ and $h_2$ respectively account for the deformation of the solid earth due to the astronomical tidal forcing and the perturbation gravitational potential due to this deformation, $\phi$ is latitude, $\omega$ is tidal frequency, $t_{ref}$ is a reference time (often taken to be the beginning of a model run), $\chi(t_{ref})$ is the astronomical argument, and $\nu(t_ref)$ is the nodal factor accounting for the small modulations of phase, and $\lambda$ is longitude.

For the diurnal constituents, the equilibrium tide is given by equation (6) of \citet{chassignet_primer_2018}, applied twice for $j=$ K$_{1}$ and O$_{1}$, viz:

\begin{equation}
\eta_{EQ,j} = A_j f_j(t_{ref}) (1+k_{2,j}-h_{2,j})\sin(2\phi)\cos\left[\omega_j(t-t_{ref}) + \chi_j(t_{ref}) + \nu_j(t_{ref}) + \lambda \right].
\label{eq:Eq6}
\end{equation}

\section{Self-attraction and loading}
\label{sec:SAL}

Self-attraction and loading (SAL) constituent static file maps should be derived for SAL amplitude and phase from FES, for $k=$ M$_2$, S$_2$, N$_2$, K$_1$, and O$_1$.  The maps can be used to compute $\eta_{SAL}$ as a sum, e.g., equation (12) from \citet{chassignet_primer_2018},

\begin{equation}
   \eta_{k,SAL}(\phi,\lambda) = A_m(\phi,\lambda)f(t_{ref})\cos\left[\omega (t-t_{ref}) + \chi(t_{ref}) + \nu(t_{ref}) - \phi_p(\phi,\lambda)\right],
\label{eq:SAL}
\end{equation}
where $A_m(\phi,\lambda)$ is the amplitude of the SAL of the $k$ constituent as a function of latitude ($\lambda$) and longitude ($\phi$) and $\phi_p(\phi,\lambda)$ is the phase of SAL as function of lat/lon.
Equation \ref{eq:SAL} takes amplitude and phase maps that provide a prediction with amplitude and phase using nodal factors and astronomical arguments.

The self-attraction and loading harmonic constituents $A_m$ and $\phi_p$ can be derived from a harmonic analysis of self-attraction and loading maps produced by global tidal models, e.g., TPXO (\url{http://volkov.oce.orst.edu/tides/global.html}) or TUGO-m (\url{http://sirocco.obs-mip.fr/ocean-models/tugo/}).

\section{Incorporation into governing equations}
\label{sec:goverining_eqns}

Once $\eta_{EQ}$ and $\eta_{SAL}$ are obtained, they can be used in an ocean model.  For instance, in a shallow water model, we replace the term $\nabla \eta$ in the momentum equation with a gradient of $\eta$ referenced to the equilibrium tide and self-attraction and loading terms, viz:

\begin{equation}
    \nabla\eta \rightarrow \nabla\left( \eta - \eta_{EQ} - \eta_{SAL}\right)
\end{equation}

In essence, the equilibrium tide and self-attraction and loading terms reset the reference against which pressure gradients are computed.

\begin{table}
\begin{center}
\begin{tabular}{|c|c|c|c|c|}
\hline
Constituent & $\omega\;\left(10^{-4}\,s^{-1}\right)$ & $A\;\left(\textrm{cm}\right)$ & $1+k_{2}-h_{2}$ & Period (solar days)\tabularnewline
\hline
\hline
$\textrm{M}_{m}$ & 0.026392 & 2.2191 & 0.693 & 27.5546\tabularnewline
\hline
$\textrm{M}_{f}$ & 0.053234 & 4.2041 & 0.693 & 13.6608\tabularnewline
\hline
$\textrm{Q}_{1}$ & 0.6495854 & 1.9273 & 0.695 & 1.1195\tabularnewline
\hline
$\textrm{O}_{1}$ & 0.6759774 & 10.0661 & 0.695 & 1.0758\tabularnewline
\hline
$\textrm{P}_{1}$ & 0.7252295 & 4.6848 & 0.706 & 1.0027\tabularnewline
\hline
$\textrm{K}_{1}$ & 0.7292117 & 14.1565 & 0.736 & 0.9973\tabularnewline
\hline
$\textrm{N}_{2}$ & 1.378797 & 4.6397 & 0.693 & 0.5274\tabularnewline
\hline
$\textrm{M}_{2}$ & 1.405189 & 24.2334 & 0.693 & 0.5175\tabularnewline
\hline
$\textrm{S}_{2}$ & 1.454441 & 11.2743 & 0.693 & 0.5000\tabularnewline
\hline
$\textrm{K}_{2}$ & 1.458423 & 3.0684 & 0.693 & 0.4986\tabularnewline
\hline
\end{tabular}
\label{tab:astronimcalFactors}
\caption{Constituent-dependent frequencies $\omega$, astronomical forcing amplitudes A, and Love number combinations $1 + k_2 - h_2$ used to compute equilibrium tide $\eta_{EQ}$. The periods $2\pi/\omega$ are also given. Reproduced from Table 1 of \citet{chassignet_primer_2018, arbic2004accuracy}.}
\end{center}
\end{table}

\section{Harmonic Least Squares Method}
The method outlined here is described in more detail in \cite{westerink_lsq}.
The computed sea-surface height $\eta(t)$ is sampled to obtain values $\eta(t_k)$ at time sampling points $t_k,~k=1,M$. The following harmonic series is used to approximate the sea surface height in the least-squares procedure:
\begin{align}
    g(t) = \sum_{j=1}^N(a_j\cos\omega_j t + b_j\sin\omega_j t).
\end{align}
In this equation, $a_j$ and $b_j$ are the unknown harmonic coefficients and $\omega_j$ are the frequencies associated with the $j=1,N$ tidal constituents. The error at a fiven sampling time between the approximate harmonic series and the computed sea surface height is
\begin{align}
    \varepsilon(t_k) = \sum_{j=1}^N(a_j\cos\omega_j t_k + b_j\sin\omega_j t_k) -\eta(t_k).
\end{align}
The sum of the squared error at all sampling times is
\begin{align}
    E = \sum_{k=1}^M\left(\varepsilon(t_k) \right)^2.
\end{align}
The error minimization between $g(t)$ and $f(t)$ is accomplished by requiring the partial derivatives of $E$with respect to each of the $a_j$ and $b_j$ coefficients to be zero:
\begin{align}
    \frac{\partial E}{\partial a_i} &= 0, \quad i=1,N \\
    \frac{\partial E}{\partial b_i} &= 0, \quad i=1,N
\end{align}
Substituting for $E$:
\begin{align}
    \sum_{k=1}^M \left(2\varepsilon(t_k)\frac{\partial \varepsilon(t_k)}{\partial a_i}\right) &= 0, \quad i=1,N \\
    \sum_{k=1}^M \left(2\varepsilon(t_k)\frac{\partial \varepsilon(t_k)}{\partial b_i}\right) &= 0, \quad i=1,N.
\end{align}
Substituting for the partial derivatives of $\varepsilon$ and dividing through by 2:
\begin{align}
    \sum_{k=1}^M \left(\varepsilon(t_k)\cos\omega_i t_k\right) &= 0, \quad i=1,N \\
    \sum_{k=1}^M \left(\varepsilon(t_k)\sin\omega_i t_k\right) &= 0, \quad i=1,N
\end{align}
Substituting for $\varepsilon$ and rearranging:
\begin{align}
    \sum_{k=1}^M \left(\sum_{j=1}^N(a_j\cos\omega_j t_k + b_j\sin\omega_j t_k)\cos\omega_i t_k\right) &= \sum_{k=1}^M \eta(t_k)\cos\omega_i t_k, \quad i=1,N \\
    \sum_{k=1}^M \left(\sum_{j=1}^N(a_j\cos\omega_j t_k + b_j\sin\omega_j t_k)\sin\omega_i t_k\right) &= \sum_{k=1}^M \eta(t_k)\sin\omega_i t_k, \quad i=1,N
\end{align}
Rearranging further:
\begin{align}
    \sum_{j=1}^N \left(a_j\sum_{k=1}^M(\cos\omega_j t_k\cos\omega_i t_k) + b_j\sum_{k=1}^M(\sin\omega_j t_k\cos\omega_i t_k)\right) &= \sum_{k=1}^M \eta(t_k)\cos\omega_i t_k, \quad i=1,N \\
    \sum_{j=1}^N \left(a_j\sum_{k=1}^M(\cos\omega_j t_k\sin\omega_i t_k) + b_j\sum_{k=1}^M(\sin\omega_j t_k\sin\omega_i t_k)\right) &= \sum_{k=1}^M \eta(t_k)\sin\omega_i t_k, \quad i=1,N
\end{align}
This leads to the system of equations (example for 2 constituents):
\begin{align}
   \underbrace{\sum_{k=1}^M \begin{bmatrix}
        \cos\omega_1 t_k\cos\omega_1 t_k &  \sin\omega_1 t_k\cos\omega_1 t_k &  \cos\omega_2 t_k\cos\omega_1 t_k &  \sin\omega_2 t_k\cos\omega_1 t_k\\
        \cos\omega_1 t_k\sin\omega_1 t_k &  \sin\omega_1 t_k\sin\omega_1 t_k &  \cos\omega_2 t_k\sin\omega_1 t_k &  \sin\omega_2 t_k\sin\omega_1 t_k\\  \cos\omega_1 t_k\cos\omega_2 t_k &  \sin\omega_1 t_k\cos\omega_2 t_k &  \cos\omega_2 t_k\cos\omega_2 t_k &  \sin\omega_2 t_k\cos\omega_2 t_k\\
        \cos\omega_1 t_k\sin\omega_2 t_k &  \sin\omega_1 t_k\sin\omega_2 t_k &  \cos\omega_2 t_k\sin\omega_2 t_k &  \sin\omega_2 t_k\sin\omega_2 t_k\\
    \end{bmatrix}}_{\mathbf{M}}
    \underbrace{\begin{bmatrix}
       a_1 \\ b_1 \\ a_2 \\ b_2
    \end{bmatrix}}_{\mathbf{a}}
    =
    \underbrace{\sum_{k=1}^M\begin{bmatrix}
    \eta(t_k)\cos\omega_1 t_k \\
    \eta(t_k)\sin\omega_1 t_k \\
    \eta(t_k)\cos\omega_2 t_k \\
    \eta(t_k)\sin\omega_2 t_k
    \end{bmatrix}}_{\mathbf{f}}
\end{align}
For each mesh cell $l=1,K$ the linear system for that cell is solved
\begin{align}
    \mathbf{M}\mathbf{a}_l = \mathbf{f}_l.
\end{align}
Note that the LHS matrix $\mathbf{M}$ is the same for each cell. In addition, $\mathbf{M}$ is symmetric and in the code, only the lower triangular part is stored. The upper triangular part is filled out before the matrix is decomposed prior to solving each individual linear system for the mesh cells.
Once the $a_j$ and $b_j$ coefficients are known, the amplitude and phase the the $j^\mathrm{th}$ constituent can be calculated as follows:
\begin{align}
    A_j &= \frac{\sqrt{a_j^2+b_j^2}}{f(t_{ref})}, \\
    \Phi_j &= \arctan2(a_j,b_j) + \chi(t_{ref}) + \nu(t_{ref}),
\end{align}
%-----------------------------------------------------------------------

\chapter{Design and Implementation}

\section{Namelist options}
\begin{verbatim}
&AM_harmonicAnalysis
    config_AM_harmonicAnalysis_enable = .true.
    config_AM_harmonicAnalysis_compute_interval = 00:30:00
    config_AM_harmonicAnalysis_start = 2012-11-01_00:00:00
    config_AM_harmonicAnalysis_end = 2012-12-20_00:00:00
    config_AM_harmonicAnalysis_output_stream = 'harmonicAnalysisOutput'
    config_AM_harmonicAnalysis_restart_stream = 'harmonicAnalysisRestart'
    config_AM_harmonicAnalysis_compute_on_startup = .false.
    config_AM_harmonicAnalysis_write_on_startup = .false.
    config_AM_harmonicAnalysis_use_M2 = .true.
    config_AM_harmonicAnalysis_use_S2 = .true.
    config_AM_harmonicAnalysis_use_N2 = .true.
    config_AM_harmonicAnalysis_use_K2 = .true.
    config_AM_harmonicAnalysis_use_K1 = .true.
    config_AM_harmonicAnalysis_use_O1 = .true.
    config_AM_harmonicAnalysis_use_Q1 = .true.
    config_AM_harmonicAnalysis_use_P1 = .true.
\end{verbatim}
\section{Output stream}
\begin{verbatim}
<stream name="harmonicAnalysisOutput"
        filename_template="harmonicAnalysis.nc"
        type="output"
        mode="forward;analysis"
        output_interval="90_00:00:00"
        packages="harmonicAnalysisAMPKG"
        clobber_mode="truncate"
        runtime_format="single_file">

    <stream name="mesh"/>
    <var name="M2Amplitude"/>
    <var name="M2Phase"/>
    <var name="S2Amplitude"/>
    <var name="S2Phase"/>
    <var name="N2Amplitude"/>
    <var name="N2Phase"/>
    <var name="K2Amplitude"/>
    <var name="K2Phase"/>
    <var name="K1Amplitude"/>
    <var name="K1Phase"/>
    <var name="O1Amplitude"/>
    <var name="O1Phase"/>
    <var name="Q1Amplitude"/>
    <var name="Q1Phase"/>
    <var name="P1Amplitude"/>
    <var name="P1Phase"/>
</stream>
\end{verbatim}

\section{Restart stream}
\begin{verbatim}
<stream name="harmonicAnalysisRestart"
        filename_template="restarts/mpaso.rst.am.harmonicAnalysisRestart.$Y-$M-$D_$h.$m.$s.nc"
        filename_interval="output_interval"
        type="input;output"
        mode="forward;analysis"
        output_interval="stream:restart:output_interval"
        input_interval="initial_only"
        packages="harmonicAnalysisAMPKG"
        clobber_mode="truncate"
        runtime_format="single_file"
        reference_time="0001-01-01_00:00:00">

    <var name="leastSquaresLHSMatrix"/>
    <var name="leastSquaresRHSVector"/>
</stream>
\end{verbatim}

\section{Subroutine calls}
The subroutines involved in computing the harmonic decomposition and how they function based on throughout the harmonic analysis period is summarized in \ref{tab:subroutines}
\begin{table}[ht]
\caption{Subroutine calls for harmonic analysis AM}
\begin{center}
\begin{tabular}{ll}
    \hline
    \multirow{5}{*}{Initialization} &  {\tt ocn\_init\_harmonic\_analysis()} \\
    &~~~~~ determine constituents selected in namelist \\
    &~~~~~ {\tt tidal\_constituent\_factors()} \\
    &~~~~~~~~~~ compute tidal constituent nodal factors \\
    &~~~~~ zero out least squares matrix and vector \\ \cline{2-2}
    \multirow{2}{*}{$t < t_{HAstart}$} & {\tt ocn\_compute\_harmonic\_analysis()} \\
    &~~~~~ return \\ \cline{2-2}
    \multirow{5}{*}{$t > t_{HAstart}$ \& $t < t_{HAend}$} & {\tt ocn\_compute\_harmonic\_analysis()} \\
    &~~~~~ {\tt update\_least\_squares\_LHS\_matrix()} \\
    &~~~~~~~~~~ sum $t_k$ contribution into $\mathbf{M}$ \\
    &~~~~~ {\tt update\_least\_squares\_RHS\_vector()} \\
    &~~~~~~~~~~ sum $t_k$ contribution into each $\mathbf{f}_l$\\ \cline{2-2}
    \multirow{8}{*}{$t > t_{HAend}$ (first time)} & {\tt ocn\_compute\_harmonic\_analysis()} \\
    &~~~~~ {\tt harmonic\_analysis\_solve()}\\
    &~~~~~~~~~~ {\tt least\_squares\_decompose()}\\
    &~~~~~~~~~~~~~~~ decompose $\mathbf{M}$ once\\
    &~~~~~~~~~~ {\tt least\_squares\_solve()}\\
    &~~~~~~~~~~~~~~~ solve each $\mathbf{M}\mathbf{a}_l=\mathbf{f}_l$ system\\
    &~~~~~~~~~~ compute $A$ and $\Phi$ for each mesh cell and constituent\\
    &~~~~~ separate solutions into output arrays \\ \cline{2-2}
    \multirow{2}{*}{$t > t_{HAend}$ (subsequent times)} & {\tt ocn\_compute\_harmonic\_analysis()} \\
    &~~~~~ return \\
    \hline
\end{tabular}
\end{center}
\label{tab:subroutines}
\end{table}

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

\chapter{Testing and Validation}

The test case used is a 3-month global tidal simulation. This includes a 15 day tidal spin-up period. The harmonic analysis begins after the completion of the first 30 days and ends after an additional period of 49 days. The horizontal mesh can be found in Figure \ref{fig:mesh}. Globally, it is a 120km mesh with 30km resolution in the northwest Atlantic Ocean and 10km resolution in the Delaware bay region. The vertical mesh is the {\tt 100layerE3SMv1} configuration. Tidal potential forcing for the 8 major constituents ($M_2$, $S_2$, $N_2$, $K_2$, $K_1$, $O_1$, $Q_1$, $P_1$) is applied. The split explicit time integrator is used with a 5 minute baroclinic time step and a 15 second barotropic time step.

The MPAS-Ocean results are compared with the data-assimilated TPXO8 model. Given the coarse mesh resolution and the lack of tuning, the results are not very accurate. However, the comparison does show that the harmonic analysis is being computed correctly. A direct water level comparison is shown in Figure \ref{fig:water_level}. The amplitude and phase plots are shown in \ref{fig:M2Amplitude}-\ref{fig:K1Phase}

\begin{figure}
    \centering
    \includegraphics[width=4in]{cellWidth.png}
    \caption{USDEQU120at30cr10}
    \label{fig:mesh}
\end{figure}
\begin{figure}
    \centering
    \includegraphics[width=3.5in]{8537121.png}
    \caption{Water level comparison}
    \label{fig:water_level}
\end{figure}
\begin{figure}
    \begin{minipage}{.5\textwidth}
    \centering
    \includegraphics[width=2.75in]{M2Amplitude_comparison_compressed.png}
    \caption{$M_2$ amplitude comparison}
    \label{fig:M2Amplitude}
    \end{minipage}
    \begin{minipage}{.5\textwidth}
    \centering
    \includegraphics[width=2.75in]{M2Phase_comparison_compressed.png}
    \caption{$M_2$ phase comparison}
    \label{fig:M2Phase}
    \end{minipage}
\end{figure}
\begin{figure}
    \begin{minipage}{.5\textwidth}
    \centering
    \includegraphics[width=2.75in]{N2Amplitude_comparison_compressed.png}
    \caption{$N_2$ amplitude comparison}
    \label{fig:N2Amplitude}
    \end{minipage}
    \begin{minipage}{.5\textwidth}
    \centering
    \includegraphics[width=2.75in]{N2Phase_comparison_compressed.png}
    \caption{$N_2$ phase comparison}
    \label{fig:N2Phase}
    \end{minipage}
\end{figure}
\begin{figure}
    \begin{minipage}{.5\textwidth}
    \centering
    \includegraphics[width=2.75in]{S2Amplitude_comparison_compressed.png}
    \caption{$S_2$ amplitude comparison}
    \label{fig:S2Amplitude}
    \end{minipage}
    \begin{minipage}{.5\textwidth}
    \centering
    \includegraphics[width=2.75in]{S2Phase_comparison_compressed.png}
    \caption{$S_2$ phase comparison}
    \label{fig:S2Phase}
    \end{minipage}
\end{figure}
\begin{figure}
    \begin{minipage}{.5\textwidth}
    \centering
    \includegraphics[width=2.75in]{O1Amplitude_comparison_compressed.png}
    \caption{$O_1$ amplitude comparison}
    \label{fig:O1Amplitude}
    \end{minipage}
    \begin{minipage}{.5\textwidth}
    \centering
    \includegraphics[width=2.75in]{O1Phase_comparison_compressed.png}
    \caption{$O_1$ phase comparison}
    \label{fig:O1Phase}
    \end{minipage}
\end{figure}
\begin{figure}
    \begin{minipage}{.5\textwidth}
    \centering
    \includegraphics[width=2.75in]{K1Amplitude_comparison_compressed.png}
    \caption{$K_1$ amplitude comparison}
    \label{fig:K1Amplitude}
    \end{minipage}
    \begin{minipage}{.5\textwidth}
    \centering
    \includegraphics[width=2.75in]{K1Phase_comparison_compressed.png}
    \caption{$K_1$ phase comparison}
    \label{fig:K1Phase}
    \end{minipage}
\end{figure}

%-----------------------------------------------------------------------
\bibliographystyle{unsrtnat}
\bibliography{tides}

\end{document}