These are working notes for the Godunov step in \maestro\
and \varden.

%-----------------------------------------------------------------------------
% Notation
%-----------------------------------------------------------------------------
\section{\maestro\ Notation}
\begin{itemize}
\item For 2D, $\Ub = (u,w)$ and $\Ubt = (\ut,\wt)$.
  Note that $u = \ut$.  We will use the shorthand $\ib = (x,r)$.
\item For 3D plane parallel, $\Ub = (u,v,w)$
  and $\Ubt = (\ut,\vt,\wt)$.  Note that $u = \ut$ and $v = \vt$.
  We will use the shorthand $\ib = (x,y,r)$.
\item For 3D spherical, $\Ub = (u,v,w)$
  and $\Ubt = (\ut,\vt,\wt)$.  We will use the shorthand
  $\ib = (x,y,z)$.
\end{itemize}
\subsection{Computing $\Ub$ From $\Ubt$}
For plane-parallel problems, in order to compute $w$ from
$\wt$, we use simple averaging
\begin{equation}
w_{\ib}^n = \wt_{\ib}^n + \frac{w_{0,r-\half} + w_{0,r+\half}}{2}.
\end{equation}
For spherial problems, in order to compute $\Ub$ from $\Ubt$,
we first map $w_0$ onto $w_0^{\mac}$ using {\tt put\_w0\_on\_edges,}
 where $w_0^{\mac}$ only contains normal velocities at each face.
Then we construct $\Ub$ by using
\begin{equation}
u_{\ib} = \ut_{\ib} + \frac{w_{0,\ib+\half\eb_x}^{\mac} + w_{0,\ib-\half\eb_x}^{\mac}}{2},
\end{equation}
\begin{equation}
v_{\ib} = \vt_{\ib} + \frac{w_{0,\ib+\half\eb_y}^{\mac} + w_{0,\ib-\half\eb_y}^{\mac}}{2},
\end{equation}
\begin{equation}
w_{\ib} = \wt_{\ib} + \frac{w_{0,\ib+\half\eb_z}^{\mac} + w_{0,\ib-\half\eb_z}^{\mac}}{2}.
\end{equation}
To compute full edge-state velocities, simply add $w_0$
(for plane-parallel) or {\tt w0mac} to the perturbational
velocity directly since only edge-based quantities are involved.
\subsection{Computing $\partial w_0/\partial r$}
For plane-parallel problems, the spatial derivatives of $w_0$
are given by the two-point centered difference:
\begin{equation}
\left(\frac{\partial w_0}{\partial r}\right)_{\ib} = \frac{w_{0,r+\half}-w_{0,r-\half}}{h}.
\end{equation}
For spherical problems, we compute the radial bin centered gradient using
\begin{equation}
\left(\frac{\partial w_0}{\partial r}\right)_{r} = \frac{w_{0,r+\half}-w_{0,r-\half}}{\Delta r}.
\end{equation}
Then we put $\partial w_0/\partial r$ onto a Cartesian grid
using {\tt put\_1d\_array\_on\_cart\_3d\_sphr}.

\newpage

%-----------------------------------------------------------------------------
% utrans
%-----------------------------------------------------------------------------
\section{Computing $\Ubt^{\trans}$ in \maestro}
In {\tt advance\_premac}, we call {\tt mkutrans}, to compute
$\Ubt^{\trans}$.  We will only compute the normal
component of velocity at each face.
These transverse velocities do not contain $w_0$, so immediately
following the call to {\tt mkutrans}, we call {\tt addw0} to compute
$\Ub^{\trans}$ from $\Ubt^{\trans}$.\\ \\
The evolution equation for the perturbational velocity is:
\begin{equation}
\frac{\partial\Ubt}{\partial t} = -\Ub\cdot\nabla\Ubt \underbrace{- (\Ubt\cdot\eb_r)\frac{\partial w_0}{\partial r}\eb_r - \frac{1}{\rho}\nabla\pi + \frac{1}{\rho_0}\frac{\partial\pi_0}{\partial r}\eb_r - \frac{(\rho-\rho_0)}{\rho}g\eb_r}_{\hbox{forcing terms}}.\label{Perturbational Velocity Equation}
\end{equation}
We extrapolate each velocity component to edge-centered, time-centered locations.  For example,
\begin{eqnarray}
\ut_{R,\ib-\half\eb_x} &=& \ut_{\ib}^n + \frac{h}{2}\frac{\partial\ut_{\ib}^n}{\partial x} + \frac{\dt}{2}\frac{\partial\ut_{\ib}^n}{\partial t} \nonumber \\
&=& \ut_{\ib}^n + \frac{h}{2}\frac{\partial\ut_{\ib}^n}{\partial x} + \frac{\dt}{2}
\left(-\ut_{\ib}^n\frac{\partial\ut_{\ib}^n}{\partial x} - \wt_{\ib}^n\frac{\partial\ut_{\ib}^n}{\partial r} + \text{forcing terms}\right)
\end{eqnarray}
We are going to use a 1D Taylor series extrapolation in space and time.
By 1D, we mean that we omit any spatial derivatives that are not in the
direction of the extrapolation.  We also omit the underbraced forcing terms.
We also use characteristic tracing.
\begin{equation}
\ut_{R,\ib-\half\eb_x} = \ut_{\ib}^n + \left[\frac{1}{2} - \frac{\dt}{2h}\min(0,\ut_{\ib}^n)\right]\partial\ut_{\ib}^n
\end{equation}

\newpage

\subsection{2D Cartesian Case}
We predict $\ut$ to x-faces using a 1D extrapolation:
\begin{eqnarray}
\ut_{L,\ib-\half\eb_x} &=& \ut_{\ib-\eb_x}^n + \left[\half - \frac{\dt}{2h}\max(0,u_{\ib-\eb_x}^n)\right]\Delta_x \ut_{\ib-\eb_x}^n,\\
\ut_{R,\ib-\half\eb_x} &=& \ut_{\ib}^n - \left[\half + \frac{\dt}{2h}\min(0,u_{\ib}^n)\right]\Delta_x \ut_{\ib}^n.
\end{eqnarray}
We pick the final trans states using a Riemann solver:
\begin{equation}
\ut^{\trans}_{\ib-\half\eb_x} =
\begin{cases}
0, & \left(\ut_{L,\ib-\half\eb_x} \le 0 ~~ {\rm AND} ~~ \ut_{R,\ib-\half\eb_x} \ge 0\right) ~~ {\rm OR} ~~ \left|\ut_{L,\ib-\half\eb_x} + \ut_{R,\ib-\half\eb_x}\right| < \epsilon, \\
\ut_{L,\ib-\half\eb_x}, & \ut_{L,\ib-\half\eb_x} + \ut_{R,\ib-\half\eb_x} > 0, \\
\ut_{R,\ib-\half\eb_x}, & \ut_{L,\ib-\half\eb_x} + \ut_{R,\ib-\half\eb_x} < 0, \\
\end{cases}
\end{equation}
We predict $\wt$ to r-faces using a 1D extrapolation:
\begin{eqnarray}
\wt_{L,\ib-\half\eb_r} &=& \wt_{\ib-\eb_r}^n + \left[\half - \frac{\dt}{2h}\max(0,w_{\ib-\eb_r}^n)\right]\Delta_r \wt_{\ib-\eb_r}^n,\\
\wt_{R,\ib-\half\eb_r} &=& \wt_{\ib}^n - \left[\half + \frac{\dt}{2h}\min(0,w_{\ib}^n)\right]\Delta_r \wt_{\ib}^n.
\end{eqnarray}
We pick the final $\trans$ states using a Riemann solver, noting
that we upwind based on the full velocity.
\begin{equation}
\wt^{\trans}_{\ib-\half\eb_r} =
\begin{cases}
0, & \left(w_{L,\ib-\half\eb_r} \le 0 ~~ {\rm AND} ~~ w_{R,\ib-\half\eb_r} \ge 0\right) ~~ {\rm OR} ~~ \left|w_{L,\ib-\half\eb_r} + w_{R,\ib-\half\eb_r}\right| < \epsilon, \\
\wt_{L,\ib-\half\eb_r}, & w_{L,\ib-\half\eb_r} + w_{R,\ib-\half\eb_r} > 0, \\
\wt_{R,\ib-\half\eb_r}, & w_{L,\ib-\half\eb_r} + w_{R,\ib-\half\eb_r} < 0, \\
\end{cases}
\end{equation}

\newpage

\subsection{3D Cartesian Case}
We use the exact same procedure in 2D and 3D to compute $\ut^{\trans}$ and
$\wt^{\trans}$. The procedure for computing $\vt^{\trans}$ is analogous to
computing $\ut^{\trans}$.  We predict $\vt$ to y-faces using the
1D extrapolation:
\begin{eqnarray}
\vt_{L,\ib-\half\eb_y} &=& \vt_{\ib-\eb_y}^n + \left[\half - \frac{\dt}{2h}\max(0,v_{\ib-\eb_y}^n)\right]\Delta_y \vt_{\ib-\eb_y}^n, \\
\vt_{R,\ib-\half\eb_y} &=& \vt_{\ib}^n - \left[\half + \frac{\dt}{2h}\min(0,v_{\ib}^n)\right]\Delta_y \vt_{\ib}^n,
\end{eqnarray}
\begin{equation}
\vt^{\trans}_{\ib-\half\eb_y} =
\begin{cases}
0, & \left(v_{L,\ib-\half\eb_y} \le 0 ~~ {\rm AND} ~~ v_{R,\ib-\half\eb_y} \ge 0\right) ~~ {\rm OR} ~~ \left|v_{L,\ib-\half\eb_y} + v_{R,\ib-\half\eb_y}\right| < \epsilon, \\
\vt_{L,\ib-\half\eb_y}, & v_{L,\ib-\half\eb_y} + v_{R,\ib-\half\eb_y} > 0, \\
\vt_{R,\ib-\half\eb_y}, & v_{L,\ib-\half\eb_y} + v_{R,\ib-\half\eb_y} < 0. \\
\end{cases}
\end{equation}

\newpage

\subsection{3D Spherical Case}
We predict the normal components of velocity to the normal faces
using a 1D extrapolation.  The equations for all three directions
are identical to those given in the 2D and 3D plane-parallel
sections.  As in the plane-parallel case, make sure
 that the advection velocities, as well as
the upwind velocity, is done with the full velocity, not the
perturbational velocity.

\newpage

%-----------------------------------------------------------------------------
% Umac
%-----------------------------------------------------------------------------
\section{Computing $\Ubt^{\mac,*}$ in \maestro}
In {\tt advance\_premac}, we call {\tt velpred} to compute
$\Ubt^{\mac,*}$.  We will only compute the normal component of
velocity at each face.\\ \\
For reference, here is the perturbational velocity equation from before:
\begin{equation}
\frac{\partial\Ubt}{\partial t} = -\Ub\cdot\nabla\Ubt \underbrace{- (\Ubt\cdot\eb_r)\frac{\partial w_0}{\partial r}\eb_r \underbrace{- \frac{1}{\rho}\nabla\pi + \frac{1}{\rho_0}\frac{\partial\pi_0}{\partial r}\eb_r - \frac{(\rho-\rho_0)}{\rho}g\eb_r}_{\hbox{terms included in $\fb_{\Ubt}$}}}_{\hbox{forcing terms}}.
\end{equation}
Note that the $\partial w_0/\partial r$ term is treated like a forcing
term, but it is not actually part of $\fb_{\Ubt}$.  We make use of the 1D
extrapolations used to compute $\Ubt^{\trans}$
($\ut_{L/R,\ib-\half\eb_x}$, $\vt_{L/R,\ib-\half\eb_y}$,
and $\wt_{L/R,\ib-\half\eb_r}$), as well as the ``$\trans$'' states
($\ut_{\ib-\half\eb_x}^{\trans}$, $\vt_{\ib-\half\eb_y}^{\trans}$,
and $\wt_{\ib-\half\eb_r}^{\trans}$)

\newpage

\subsection{2D Cartesian Case}
\begin{enumerate}
\item Predict $\ut$ to r-faces using a 1D extrapolation.
\item Predict $\ut$ to x-faces using a full-dimensional extrapolation.
\item Predict $\wt$ to x-faces using a 1D extrapolation.
\item Predict $\wt$ to r-faces using a full-dimensional extrapolation.
\end{enumerate}
Predict $\ut$ to r-faces using a 1D extrapolation:
\begin{eqnarray}
\ut_{L,\ib-\half\eb_r} &=& \ut_{\ib-\eb_r}^n + \left[\half - \frac{\dt}{2h}\max(0,w_{\ib-\eb_r}^n)\right]\Delta_r \ut_{\ib-\eb_r}^n, \\
\ut_{R,\ib-\half\eb_r} &=& \ut_{\ib} - \left[\half + \frac{\dt}{2h}\min(0,w_{\ib}^n)\right]\Delta_r \ut_{\ib}^n.
\end{eqnarray}
Upwind based on $w^{\trans}$:
\begin{equation}
\ut_{\ib-\half\eb_r} =
\begin{cases}
\half\left(\ut_{L,\ib-\half\eb_r} + \ut_{R,\ib-\half\eb_r}\right), & \left|w^{\trans}_{\ib-\half\eb_r}\right| < \epsilon \\
\ut_{L,\ib-\half\eb_r}, & w^{\trans}_{\ib-\half\eb_r} > 0, \\
\ut_{R,\ib-\half\eb_r}, & w^{\trans}_{\ib-\half\eb_r} < 0. \\
\end{cases}
\end{equation}
Predict $\ut$ to x-faces using a full-dimensional extrapolation,
\begin{eqnarray}
\ut_{L,\ib-\half\eb_x}^{\mac,*} &=& \ut_{L,\ib-\half\eb_x} - \frac{\dt}{4h}\left(w_{\ib-\eb_x+\half\eb_r}^{\trans}+w_{\ib-\eb_x-\half\eb_r}^{\trans}\right)\left(\ut_{\ib-\eb_x+\half\eb_r} - \ut_{\ib-\eb_x-\half\eb_r}\right) + \frac{\dt}{2}f_{\ut,\ib-\eb_x}, \nonumber \\
&& \\
\ut_{R,\ib-\half\eb_x}^{\mac,*} &=& \ut_{R,\ib-\half\eb_x} - \frac{\dt}{4h}\left(w_{\ib+\half\eb_r}^{\trans}+w_{\ib-\half\eb_r}^{\trans}\right)\left(\ut_{\ib+\half\eb_r} - \ut_{\ib-\half\eb_r}\right) + \frac{\dt}{2}f_{\ut,\ib}.
\end{eqnarray}
Solve a Riemann problem:
\begin{equation}
\ut_{\ib-\half\eb_x}^{\mac,*} =
\begin{cases}
0, & \left(u_{L,\ib-\half\eb_x}^{\mac,*} \le 0 ~~ {\rm AND} ~~ u_{R,\ib-\half\eb_x}^{\mac,*} \ge 0\right) ~~ {\rm OR} ~~ \left|u_{L,\ib-\half\eb_x}^{\mac,*} + u_{R,\ib-\half\eb_x}^{\mac,*}\right| < \epsilon, \\
\ut_{L,\ib-\half\eb_x}^{\mac,*}, & u_{L,\ib-\half\eb_x}^{\mac,*} + u_{R,\ib-\half\eb_x}^{\mac,*} > 0, \\
\ut_{R,\ib-\half\eb_x}^{\mac,*}, & u_{L,\ib-\half\eb_x}^{\mac,*} + u_{R,\ib-\half\eb_x}^{\mac,*} < 0.
\end{cases}
\end{equation}
Predict $\wt$ to x-faces using a 1D extrapolation:
\begin{eqnarray}
\wt_{L,\ib-\half\eb_x} &=& \wt_{\ib-\eb_x}^n + \left[\half - \frac{\dt}{2h}\max(0,u_{\ib-\eb_x}^n)\right]\Delta_x \wt_{\ib-\eb_x}^n, \\
\wt_{R,\ib-\half\eb_x} &=& \wt_{\ib} - \left[\half + \frac{\dt}{2h}\min(0,u_{\ib}^n)\right]\Delta_x \wt_{\ib}^n.
\end{eqnarray}
Upwind based on $u^{\trans}$:
\begin{equation}
\wt_{\ib-\half\eb_x} =
\begin{cases}
\half\left(\wt_{L,\ib-\half\eb_x} + \wt_{R,\ib-\half\eb_x}\right), & \left|u^{\trans}_{\ib-\half\eb_x}\right| < \epsilon \\
\wt_{L,\ib-\half\eb_x}, & u^{\trans}_{\ib-\half\eb_x} > 0, \\
\wt_{R,\ib-\half\eb_x}, & u^{\trans}_{\ib-\half\eb_x} < 0. \\
\end{cases}
\end{equation}
Predict $\wt$ to r-faces using a full-dimensional extrapolation:
\begin{eqnarray}
\wt_{L,\ib-\half\eb_r}^{\mac,*} = \wt_{L,\ib-\half\eb_r} &-& \frac{\dt}{4h}\left(u_{\ib-\eb_r+\half\eb_x}^{\trans}+u_{\ib-\eb_r-\half\eb_x}^{\trans}\right)\left(\wt_{\ib-\eb_r+\half\eb_x} - \wt_{\ib-\eb_r-\half\eb_x}\right) \nonumber \\
&-& \frac{\dt}{4h}\left(\wt_{\ib-\half\eb_r}^{\trans}+\wt_{\ib-\frac{3}{2}\eb_r}^{\trans}\right)\left(w_{0,\ib-\half\eb_r} - w_{0,\ib-\frac{3}{2}\eb_r}\right) + \frac{\dt}{2}f_{\wt,\ib-\eb_r}, \nonumber \\
&& \\
\wt_{R,\ib-\half\eb_r}^{\mac,*} = \wt_{R,\ib-\half\eb_r} &-& \frac{\dt}{4h}\left(u_{\ib+\half\eb_x}^{\trans}+u_{\ib-\half\eb_x}^{\trans}\right)\left(\wt_{\ib+\half\eb_x} - \wt_{\ib-\half\eb_x}\right) \nonumber \\
&-& \frac{\dt}{4h}\left(\wt_{\ib+\half\eb_r}^{\trans}+\wt_{\ib-\half\eb_r}^{\trans}\right)\left(w_{0,\ib+\half\eb_r} - w_{0,\ib-\half\eb_r}\right) + \frac{\dt}{2}f_{\wt,\ib}.
\end{eqnarray}
Solve a Riemann problem:
\begin{equation}
\wt_{\ib-\half\eb_r}^{\mac,*} =
\begin{cases}
0, & \left(w_L^{\mac,*} \le 0 ~~ {\rm AND} ~~ w_R^{\mac,*} \ge 0\right) ~~ {\rm OR} ~~ \left|w_L^{\mac,*} + w_R^{\mac,*}\right| < \epsilon, \\
\wt_{L,\ib-\half\eb_r}^{\mac,*}, & w_L^{\mac,*} + w_R^{\mac,*} > 0, \\
\wt_{R,\ib-\half\eb_r}^{\mac,*}, & w_L^{\mac,*} + w_R^{\mac,*} < 0.
\end{cases}
\end{equation}

\newpage

\subsection{3D Cartesian Case}
This algorithm is more complicated than the 2D case since we include
the effects of corner coupling.

\begin{enumerate}
\item Predict $\ut$ to y-faces using a 1D extrapolation.
\item Predict $\ut$ to r-faces using a 1D extrapolation.
\item Predict $\vt$ to x-faces using a 1D extrapolation.
\item Predict $\vt$ to r-faces using a 1D extrapolation.
\item Predict $\wt$ to x-faces using a 1D extrapolation.
\item Predict $\wt$ to y-faces using a 1D extrapolation.
\item Update prediction of $\ut$ to y-faces by accounting for $r$-derivatives.
\item Update prediction of $\ut$ to r-faces by accounting for $y$-derivatives.
\item Update prediction of $\vt$ to x-faces by accounting for $r$-derivatives.
\item Update prediction of $\vt$ to r-faces by accounting for $x$-derivatives.
\item Update prediction of $\wt$ to x-faces by accounting for $y$-derivatives.
\item Update prediction of $\wt$ to y-faces by accounting for $x$-derivatives.
\item Predict $\ut$ to x-faces using a full-dimensional extrapolation.
\item Predict $\vt$ to y-faces using a full-dimensional extrapolation.
\item Predict $\wt$ to r-faces using a full-dimensional extrapolation.
\end{enumerate}
Predict $\ut$ to y-faces using a 1D extrapolation.
\begin{eqnarray}
\ut_{L,\ib-\half\eb_y} &=& \ut_{\ib-\eb_y}^n + \left[\half - \frac{\dt}{2h}\max(0,v_{\ib-\eb_y}^n)\right]\Delta_y \ut_{\ib-\eb_y}^n, \\
\ut_{R,\ib-\half\eb_y} &=& \ut_{\ib} - \left[\half + \frac{\dt}{2h}\min(0,v_{\ib}^n)\right]\Delta_y \ut_{\ib}^n.
\end{eqnarray}
Upwind based on $v^{\trans}$:
\begin{equation}
\ut_{\ib-\half\eb_y} =
\begin{cases}
\half\left(\ut_{L,\ib-\half\eb_y} + \ut_{R,\ib-\half\eb_y}\right), & \left|v^{\trans}_{\ib-\half\eb_y}\right| < \epsilon \\
\ut_{L,\ib-\half\eb_y}, & v^{\trans}_{\ib-\half\eb_y} > 0, \\
\ut_{R,\ib-\half\eb_y}, & v^{\trans}_{\ib-\half\eb_y} < 0. \\
\end{cases}
\end{equation}
Predict $\ut$ to r-faces using a 1D extrapolation.\\ \\
Predict $\vt$ to x-faces using a 1D extrapolation.\\ \\
Predict $\vt$ to r-faces using a 1D extrapolation.\\ \\
Predict $\wt$ to x-faces using a 1D extrapolation.\\ \\
Predict $\wt$ to y-faces using a 1D extrapolation.\\ \\
Update prediction of $\ut$ to y-faces by accounting for $r$-derivatives.
The notation $\ut_{\ib-\half\eb_y}^{y|r}$ means state $\ut_{\ib-\half\eb_y}$ that has been updated to account for transverse derives in the r-direction.
\begin{eqnarray}
\ut_{L,\ib-\half\eb_y}^{y|r} &=& \ut_{L,\ib-\half\eb_y} - \frac{\dt}{6h}\left(w_{\ib-\eb_y+\half\eb_r}^{\trans}+w_{\ib-\eb_y-\half\eb_r}^{\trans}\right)\left(\ut_{\ib-\eb_y+\half\eb_r}-\ut_{\ib-\eb_y-\half\eb_r}\right), \\
\ut_{R,\ib-\half\eb_y}^{y|r} &=& \ut_{R,\ib-\half\eb_y} - \frac{\dt}{6h}\left(w_{\ib+\half\eb_r}^{\trans}+w_{\ib-\half\eb_r}^{\trans}\right)\left(\ut_{\ib+\half\eb_r}-\ut_{\ib-\half\eb_r}\right).
\end{eqnarray}
Upwind based on $v^{\trans}$:
\begin{equation}
\ut_{\ib-\half\eb_y}^{y|r} =
\begin{cases}
\half\left(\ut_{L,\ib-\half\eb_y}^{y|r} + \ut_{R,\ib-\half\eb_y}^{y|r}\right), & \left|v_{\ib-\half\eb_y}^{\trans}\right| < \epsilon \\
\ut_{L,\ib-\half\eb_y}^{y|r}, & v_{\ib-\half\eb_y}^{\trans} > 0, \\
\ut_{R,\ib-\half\eb_y}^{y|r}, & v_{\ib-\half\eb_y}^{\trans} < 0.
\end{cases}
\end{equation}
Update prediction of $\ut$ to r-faces by accounting for $y$-derivatives. \\ \\
Update prediction of $\vt$ to x-faces by accounting for $r$-derivatives. \\ \\
Update prediction of $\vt$ to r-faces by accounting for $x$-derivatives. \\ \\
Update prediction of $\wt$ to x-faces by accounting for $y$-derivatives. \\ \\
Update prediction of $\wt$ to y-faces by accounting for $x$-derivatives. \\ \\
Predict $\ut$ to x-faces using a full-dimensional extrapolation.
\begin{eqnarray}
\ut_{L,\ib-\half\eb_x}^{\mac,*} = \ut_{L,\ib-\half\eb_x} &-& \frac{\dt}{4h}\left(v_{\ib-\eb_x+\half\eb_y}^{\trans}+v_{\ib-\eb_x-\half\eb_y}^{\trans}\right)\left(\ut_{\ib-\eb_x+\half\eb_y}^{y|r}-\ut_{\ib-\eb_x-\half\eb_y}^{y|r}\right) \nonumber \\
&-& \frac{\dt}{4h}\left(w_{\ib-\eb_x+\half\eb_r}^{\trans}+w_{\ib-\eb_x-\half\eb_r}^{\trans}\right)\left(\ut_{\ib-\eb_x+\half\eb_r}^{r|y}-\ut_{\ib-\eb_x-\half\eb_r}^{r|y}\right) + \frac{\dt}{2}f_{u,\ib-\eb_x}, \nonumber \\
&& \\
\ut_{R,\ib-\half\eb_x}^{\mac,*} = \ut_{R,\ib-\half\eb_x} &-& \frac{\dt}{4h}\left(v_{\ib+\half\eb_y}^{\trans}+v_{\ib-\half\eb_y}^{\trans}\right)\left(\ut_{\ib+\half\eb_y}^{y|r}-\ut_{\ib-\half\eb_y}^{y|r}\right) \nonumber \\
&-& \frac{\dt}{4h}\left(w_{\ib+\half\eb_r}^{\trans}+w_{\ib-\half\eb_r}^{\trans}\right)\left(\ut_{\ib+\half\eb_r}^{r|y}-\ut_{\ib-\half\eb_r}^{r|y}\right) + \frac{\dt}{2}f_{u,\ib}.
\end{eqnarray}
Solve a Riemann problem:
\begin{equation}
\ut_{\ib-\half\eb_x}^{\mac,*} =
\begin{cases}
0, & \left(u_{L,\ib-\half\eb_x}^{\mac,*} \le 0 ~~ {\rm AND} ~~ u_{R,\ib-\half\eb_x}^{\mac,*} \ge 0\right) ~~ {\rm OR} ~~ \left|u_{L,\ib-\half\eb_x}^{\mac,*} + u_{R,\ib-\half\eb_x}^{\mac,*}\right| < \epsilon, \\
\ut_{L,\ib-\half\eb_x}^{\mac,*}, & u_{L,\ib-\half\eb_x}^{\mac,*} + u_{R,\ib-\half\eb_x}^{\mac,*} > 0, \\
\ut_{R,\ib-\half\eb_x}^{\mac,*}, & u_{L,\ib-\half\eb_x}^{\mac,*} + u_{R,\ib-\half\eb_x}^{\mac,*} < 0.
\end{cases}
\end{equation}
Predict $\vt$ to y-faces using a full-dimensional extrapolation.\\ \\
Predict $\wt$ to r-faces using a full-dimensional extrapolation.
In this step, make sure you account for the $\partial w_0/\partial r$
term before solving the Riemann problem:
\begin{eqnarray}
\wt_{L,\ib-\half\eb_r}^{\mac,*} &=& \wt_{L,\ib-\half\eb_r}^{\mac,*} -
\frac{\dt}{4h}\left(\wt^{\trans}_{\ib+\half\eb_r} + \wt^{\trans}_{\ib-\half\eb_r}\right)\left(w_{0,\ib+\half\eb_r}-w_{0,\ib-\half\eb_r}\right) \\
\wt_{R,\ib-\half\eb_r}^{\mac,*} &=& \wt_{R,\ib-\half\eb_r}^{\mac,*} -
\frac{\dt}{4h}\left(\wt^{\trans}_{\ib-\half\eb_r} + \wt^{\trans}_{\ib-\frac{3}{2}\eb_r}\right)\left(w_{0,\ib-\half\eb_r}-w_{0,\ib-\frac{3}{2}\eb_r}\right)
\end{eqnarray}

\newpage

\subsection{3D Spherical Case}
The spherical case is the same as the plane-parallel 3D Cartesian
case, except the $\partial w_0/\partial r$ term enters
in the full dimensional extrapolation for each direction.
As in the plane-parallel case, make sure to upwind using the
full velocity.

\newpage

%-----------------------------------------------------------------------------
% edge states
%-----------------------------------------------------------------------------
\section{Computing $\rho^{'\edge}, X_k^{\edge},(\rho h)^{'\edge}$, and $\Ubt^{\edge}$ in \maestro}\label{Scalar Edge State Prediction in MAESTRO}
We call {\tt make\_edge\_scal} to compute $\rho^{'\edge}, X_k^{\edge},
(\rho h)^{'\edge}$, and $\Ubt^{\edge}$ at each edge.
The procedure is the same for each quantitiy, so we shall simply denote
the scalar as $s$.  We always need to compute $\rho'$ and $X_k$ to faces,
and the choice of energy prediction is as follows:
\begin{itemize}
\item For {\tt enthalpy\_pred\_type} = 1, we predict $(\rho h)'$ to faces.
\item For {\tt enthalpy\_pred\_type} = 2, we predict $h$ to faces.
\item For {\tt enthalpy\_pred\_type} = 3 and 4, we predict $T$ to faces.
\item For {\tt enthalpy\_pred\_type} = 5, we predict $h'$ to faces.
\item For {\tt enthalpy\_pred\_type} = 6, we predict $T'$ to faces.
\end{itemize}
We are using {\tt enthalpy\_pred\_type} = 1 for now.  The equations
of motion are:
\begin{eqnarray}
\frac{\partial \rho'}{\partial t} &=& -\Ub\cdot\nabla\rho' \underbrace{- \rho'\nabla\cdot\Ub - \nabla\cdot\left(\rho_0\Ubt\right)}_{f_{\rho'}}, \\
\frac{\partial X_k}{\partial t} &=& -\Ub\cdot\nabla X_k ~~~ \text{(no forcing)}, \\
\frac{\partial(\rho h)'}{\partial t} &=& -\Ub\cdot\nabla(\rho h)' \underbrace{- (\rho h)'\nabla\cdot\Ub - \nabla\cdot\left[(\rho h)_0\Ubt\right] + \left(\Ubt\cdot\eb_r\right)\frac{\partial p_0}{\partial r} + \nabla\cdot\kth\nabla T}_{f_{(\rho h)'}}, \nonumber \\
&& \\
\frac{\partial\Ubt}{\partial t} &=& -\Ub\cdot\nabla\Ubt \underbrace{- \left(\Ubt\cdot\eb_r\right)\frac{\partial w_0}{\partial r}\eb_r \underbrace{- \frac{1}{\rho}\nabla\pi + \frac{1}{\rho_0}\frac{\partial\pi_0}{\partial r}\eb_r - \frac{(\rho-\rho_0)}{\rho}g\eb_r}_{\hbox{terms included in $\fb_{\Ubt}$}}}_{\hbox{forcing terms}}.
\end{eqnarray}

\newpage

\subsection{2D Cartesian Case}
\begin{enumerate}
\item Predict $s$ to r-faces using a 1D extrapolation.
\item Predict $s$ to x-faces using a full-dimensional extrapolation.
\item Predict $s$ to x-faces using a 1D extrapolation.
\item Predict $s$ to r-faces using a full-dimensional extrapolation.
\end{enumerate}
Predict $s$ to r-faces using a 1D extrapolation:
\begin{eqnarray}
s_{L,\ib-\half\eb_r} &=& s_{\ib-\eb_r}^n + \left(\half - \frac{\dt}{2h}w_{\ib-\half\eb_r}^{\mac}\right)\Delta_r s_{\ib-\eb_r}^n, \\
s_{R,\ib-\half\eb_r} &=& s_{\ib} - \left(\half + \frac{\dt}{2h}w_{\ib-\half\eb_r}^{\mac}\right)\Delta_r s_{\ib}^n.
\end{eqnarray}
Upwind based on $w^{\mac}$:
\begin{equation}
s_{\ib-\half\eb_r} =
\begin{cases}
\half\left(s_{L,\ib-\half\eb_r} + s_{R,\ib-\half\eb_r}\right), & \left|w^{\mac}_{\ib-\half\eb_r}\right| < \epsilon \\
s_{L,\ib-\half\eb_r}, & w^{\mac}_{\ib-\half\eb_r} > 0, \\
s_{R,\ib-\half\eb_r}, & w^{\mac}_{\ib-\half\eb_r} < 0. \\
\end{cases}
\end{equation}
Predict $s$ to x-faces using a full-dimensional extrapolation.  First, the normal derivative and forcing terms:
\begin{eqnarray}
s_{L,\ib-\half\eb_x}^{\edge} &=& s_{\ib-\eb_x}^n + \left(\half - \frac{\dt}{2h}u_{\ib-\half\eb_x}^{\mac}\right)\Delta_x s_{\ib-\eb_x}^n + \frac{\dt}{2}f_{\ib-\eb_x}^n \\
s_{R,\ib-\half\eb_x}^{\edge} &=& s_{\ib}^n - \left(\half + \frac{\dt}{2h}u_{\ib-\half\eb_x}^{\mac}\right)\Delta_x s_{\ib}^n + \frac{\dt}{2}f_{\ib}^n
\end{eqnarray}
Account for the transverse terms:\\ \\
{\bf if} {\tt is\_conservative} {\bf then}
\begin{eqnarray}
s_{L,\ib-\half\eb_x}^{\edge} &=& s_{L,\ib-\half\eb_x}^{\edge} -
\frac{\dt}{2h}\left[\left(w^{\mac}s\right)_{\ib-\eb_x+\half\eb_r} - \left(w^{\mac}s\right)_{\ib-\eb_x-\half\eb_r}\right] - \frac{\dt}{2h}s_{\ib-\eb_x}^{n}\left(u_{\ib-\half\eb_x}^{\mac}-u_{\ib-\frac{3}{2}\eb_x}^{\mac}\right)\nonumber \\
&&\\
s_{R,\ib-\half\eb_x}^{\edge} &=& s_{R,\ib-\half\eb_x}^{\edge} -
\frac{\dt}{2h}\left[\left(w^{\mac}s\right)_{\ib+\half\eb_r} - \left(w^{\mac}s\right)_{\ib-\half\eb_r}\right] - \frac{\dt}{2h}s_{\ib}^{n}\left(u_{\ib+\half\eb_x}^{\mac}-u_{\ib-\half\eb_x}^{\mac}\right)
\end{eqnarray}
{\bf else}
\begin{eqnarray}
s_{L,\ib-\half\eb_x}^{\edge} &=& s_{L,\ib-\half\eb_x}^{\edge} -
\frac{\dt}{4h}\left(w^{\mac}_{\ib-\eb_x+\half\eb_r} + w^{\mac}_{\ib-\eb_x-\half\eb_r}\right)\left(s_{\ib-\eb_x+\half\eb_r} - s_{\ib-\eb_x-\half\eb_r}\right)\\
s_{R,\ib-\half\eb_x}^{\edge} &=& s_{R,\ib-\half\eb_x}^{\edge} -
\frac{\dt}{4h}\left(w^{\mac}_{\ib+\half\eb_r} + w^{\mac}_{\ib-\half\eb_r}\right)\left(s_{\ib+\half\eb_r} - s_{\ib-\half\eb_r}\right)
\end{eqnarray}
{\bf end if}\\ \\
Account for the $\partial w_0/\partial r$ term:\\ \\
{\bf if} {\tt is\_vel} {\bf and} {\tt comp} = 2 {\bf then}
\begin{eqnarray}
s_{L,\ib-\half\eb_x}^{\edge} &=& s_{L,\ib-\half\eb_x}^{\edge} -
\frac{\dt}{4h}\left(\wt^{\mac}_{\ib-\eb_x+\half\eb_r} + \wt^{\mac}_{\ib-\eb_x-\half\eb_r}\right)\left(w_{0,\ib+\half\eb_r}-w_{0,\ib-\half\eb_r}\right) \\
s_{R,\ib-\half\eb_x}^{\edge} &=& s_{R,\ib-\half\eb_x}^{\edge} -
\frac{\dt}{4h}\left(\wt^{\mac}_{\ib+\half\eb_r} + \wt^{\mac}_{\ib-\half\eb_r}\right)\left(w_{0,\ib+\half\eb_r}-w_{0,\ib-\half\eb_r}\right) \\
\end{eqnarray}
{\bf end if}\\ \\
Upwind based on $u^{\mac}$.
\begin{equation}
s_{\ib-\half\eb_x}^{\edge} =
\begin{cases}
\half\left(s_{L,\ib-\half\eb_x}^{\edge} + s_{R,\ib-\half\eb_x}^{\edge}\right), & \left|u^{\mac}_{\ib-\half\eb_x}\right| < \epsilon \\
s_{L,\ib-\half\eb_x}^{\edge}, & u^{\mac}_{\ib-\half\eb_x} > 0, \\
s_{R,\ib-\half\eb_x}^{\edge}, & u^{\mac}_{\ib-\half\eb_x} < 0.
\end{cases}
\end{equation}
Predict $s$ to x-faces using a 1D extrapolation:
\begin{eqnarray}
s_{L,\ib-\half\eb_x} &=& s_{\ib-\eb_x}^n + \left(\half - \frac{\dt}{2h}u_{\ib-\half\eb_x}^{\mac}\right)\Delta_x s_{\ib-\eb_x}^n, \\
s_{R,\ib-\half\eb_x} &=& s_{\ib} - \left(\half + \frac{\dt}{2h}u_{\ib-\half\eb_x}^{\mac}\right)\Delta_x s_{\ib}^n.
\end{eqnarray}
Upwind based on $u^{\mac}$:
\begin{equation}
s_{\ib-\half\eb_x} =
\begin{cases}
\half\left(s_{L,\ib-\half\eb_x} + s_{R,\ib-\half\eb_x}\right), & \left|u^{\mac}_{\ib-\half\eb_x}\right| < \epsilon \\
s_{L,\ib-\half\eb_x}, & u^{\mac}_{\ib-\half\eb_x} > 0, \\
s_{R,\ib-\half\eb_x}, & u^{\mac}_{\ib-\half\eb_x} < 0. \\
\end{cases}
\end{equation}
Predict $s$ to r-faces using a full-dimensional extrapolation.  First, the normal derivative and forcing terms:
\begin{eqnarray}
s_{L,\ib-\half\eb_r}^{\edge} &=&  s_{\ib-\eb_r}^n + \left(\half - \frac{\dt}{2h}w_{\ib-\half\eb_r}^{\mac}\right)\Delta_r s_{\ib-\eb_r}^n + \frac{\dt}{2}f_{\ib-\eb_r}^n \\
s_{R,\ib-\half\eb_r}^{\edge} &=&  s_{\ib}^n - \left(\half + \frac{\dt}{2h}w_{\ib-\half\eb_r}^{\mac}\right)\Delta_r s_{\ib}^n + \frac{\dt}{2}f_{\ib}^n
\end{eqnarray}
Account for the transverse terms:\\ \\
{\bf if} {\tt is\_conservative} {\bf then}
\begin{eqnarray}
s_{L,\ib-\half\eb_r}^{\edge} &=& s_{L,\ib-\half\eb_r}^{\edge} -
\frac{\dt}{2h}\left[\left(u^{\mac}s\right)_{\ib-\eb_r+\half\eb_x} - \left(u^{\mac}s\right)_{\ib-\eb_r-\half\eb_x}\right] - \frac{\dt}{2h}s_{\ib-\eb_r}^{n}\left(w_{\ib-\half\eb_r}^{\mac}-w_{\ib-\frac{3}{2}\eb_r}^{\mac}\right)\nonumber\\
&& \\
s_{R,\ib-\half\eb_r}^{\edge} &=& s_{R,\ib-\half\eb_r}^{\edge} -
\frac{\dt}{2h}\left[\left(u^{\mac}s\right)_{\ib+\half\eb_x} - \left(u^{\mac}s\right)_{\ib-\half\eb_x}\right] - \frac{\dt}{2h}s_{\ib}^{n}\left(w_{\ib+\half\eb_r}^{\mac}-w_{\ib-\half\eb_r}^{\mac}\right)
\end{eqnarray}
{\bf else}
\begin{eqnarray}
s_{L,\ib-\half\eb_r}^{\edge} &=& s_{L,\ib-\half\eb_r}^{\edge} -
\frac{\dt}{4h}\left(u^{\mac}_{\ib-\eb_r+\half\eb_x} + u^{\mac}_{\ib-\eb_r-\half\eb_x}\right)\left(s_{\ib-\eb_r+\half\eb_x} - s_{\ib-\eb_r-\half\eb_x}\right)\\
s_{R,\ib-\half\eb_r}^{\edge} &=& s_{R,\ib-\half\eb_r}^{\edge} -
\frac{\dt}{4h}\left(u^{\mac}_{\ib+\half\eb_x} + u^{\mac}_{\ib-\half\eb_x}\right)\left(s_{\ib+\half\eb_x} - s_{\ib-\half\eb_x}\right)
\end{eqnarray}
{\bf end if}\\ \\
Account for the $\partial w_0/\partial r$ term:\\ \\
{\bf if} {\tt is\_vel} {\bf and} {\tt comp} = 2 {\bf then}
\begin{eqnarray}
s_{L,\ib-\half\eb_r}^{\edge} &=& s_{L,\ib-\half\eb_r}^{\edge} -
\frac{\dt}{4h}\left(\wt^{\mac}_{\ib-\half\eb_r} + \wt^{\mac}_{\ib-\frac{3}{2}\eb_r}\right)\left(w_{0,\ib-\half\eb_r}-w_{0,\ib-\frac{3}{2}\eb_r}\right) \\
s_{R,\ib-\half\eb_r}^{\edge} &=& s_{R,\ib-\half\eb_r}^{\edge} -
\frac{\dt}{4h}\left(\wt^{\mac}_{\ib+\half\eb_r} + \wt^{\mac}_{\ib-\half\eb_r}\right)\left(w_{0,\ib+\half\eb_r}-w_{0,\ib-\half\eb_r}\right) \\
\end{eqnarray}
{\bf end if}\\ \\
Upwind based on $w^{\mac}$:
\begin{equation}
s_{\ib-\half\eb_r} =
\begin{cases}
\half\left(s_{L,\ib-\half\eb_r} + s_{R,\ib-\half\eb_r}\right), & \left|w^{\mac}_{\ib-\half\eb_r}\right| < \epsilon \\
u_{L,\ib-\half\eb_r}, & w^{\mac}_{\ib-\half\eb_r} > 0, \\
u_{R,\ib-\half\eb_r}, & w^{\mac}_{\ib-\half\eb_r} < 0. \\
\end{cases}
\end{equation}

\newpage

\subsection{3D Cartesian Case}
This algorithm is more complicated than the 2D case since we include
the effects of corner coupling.
\begin{enumerate}
\item Predict $s$ to x-faces using a 1D extrapolation.
\item Predict $s$ to y-faces using a 1D extrapolation.
\item Predict $s$ to r-faces using a 1D extrapolation.
\item Update prediction of $s$ to x-faces by accounting for y-derivatives.
\item Update prediction of $s$ to x-faces by accounting for r-derivatives.
\item Update prediction of $s$ to y-faces by accounting for x-derivatives.
\item Update prediction of $s$ to y-faces by accounting for r-derivatives.
\item Update prediction of $s$ to r-faces by accounting for x-derivatives.
\item Update prediction of $s$ to r-faces by accounting for y-derivatives.
\item Predict $s$ to x-faces using a full-dimensional extrapolation.
\item Predict $s$ to y-faces using a full-dimensional extrapolation.
\item Predict $s$ to r-faces using a full-dimensional extrapolation.
\end{enumerate}
Predict $s$ to x-faces using a 1D extrapolation.
\begin{eqnarray}
s_{L,\ib-\half\eb_x} &=& s_{\ib-\eb_x}^n + \left(\half - \frac{\dt}{2h}u_{\ib-\half\eb_x}^{\mac}\right)\Delta_x s_{\ib-\eb_x}^n, \label{3D predict s to left}\\
s_{R,\ib-\half\eb_x} &=& s_{\ib} - \left(\half + \frac{\dt}{2h}u_{\ib-\half\eb_x}^{\mac}\right)\Delta_x s_{\ib}^n.\label{3D predict s to right}
\end{eqnarray}
Upwind based on $u^{\mac}$:
\begin{equation}
s_{\ib-\half\eb_x} =
\begin{cases}
\half\left(s_{L,\ib-\half\eb_x} + s_{R,\ib-\half\eb_x}\right), & \left|u^{\mac}_{\ib-\half\eb_x}\right| < \epsilon \\
s_{L,\ib-\half\eb_x}, & u^{\mac}_{\ib-\half\eb_x} > 0, \\
s_{R,\ib-\half\eb_x}, & u^{\mac}_{\ib-\half\eb_x} < 0. \\
\end{cases}
\end{equation}
Predict $s$ to y-faces using a 1D extrapolation.\\ \\
Predict $s$ to r-faces using a 1D extrapolation.\\ \\
Update prediction of $s$ to x-faces by accounting for y-derivatives.
The notation $s_{\ib-\half\eb_x}^{x|y}$ means ``state $s_{\ib-\half\eb_x}$
that has been updated to account for the transverse derivatives in
the $y$-direction''.\\ \\
{\bf if} {\tt is\_conservative} {\bf then}
\begin{eqnarray}
s_{L,\ib-\half\eb_x}^{x|y} &=& s_{L,\ib-\half\eb_x} - \frac{\dt}{3h}\left[(sv^{\mac})_{\ib-\eb_x+\half\eb_y}-(sv^{\mac})_{\ib-\eb_x-\half\eb_y}\right], \\
s_{R,\ib-\half\eb_x}^{x|y} &=& s_{R,\ib-\half\eb_x} - \frac{\dt}{3h}\left[(sv^{\mac})_{\ib+\half\eb_y}-(sv^{\mac})_{\ib-\half\eb_y}\right].
\end{eqnarray}
{\bf else}
\begin{eqnarray}
s_{L,\ib-\half\eb_x}^{x|y} &=& s_{L,\ib-\half\eb_x} - \frac{\dt}{6h}\left(v_{\ib-\eb_x+\half\eb_y}^{\mac} + v_{\ib-\eb_x-\half\eb_y}^{\mac}\right)\left(s_{\ib-\eb_x+\half\eb_y} - s_{\ib-\eb_x-\half\eb_y}\right), \\
s_{R,\ib-\half\eb_x}^{x|y} &=& s_{R,\ib-\half\eb_x} - \frac{\dt}{6h}\left(v_{\ib+\half\eb_y}^{\mac} + v_{\ib-\half\eb_y}^{\mac}\right)\left(s_{\ib+\half\eb_y} - s_{\ib-\half\eb_y}\right).
\end{eqnarray}
{\bf end if}\\ \\
Upwind based on $u^{\mac}$:
\begin{equation}
s_{\ib-\half\eb_x}^{x|y} =
\begin{cases}
\half\left(s_{L,\ib-\half\eb_x}^{x|y} + s_{R,\ib-\half\eb_x}^{x|y}\right), & \left|u^{\mac}_{\ib-\half\eb_x}\right| < \epsilon \\
s_{L,\ib-\half\eb_x}^{x|y}, & u^{\mac}_{\ib-\half\eb_x} > 0, \\
s_{R,\ib-\half\eb_x}^{x|y}, & u^{\mac}_{\ib-\half\eb_x} < 0.
\end{cases}
\end{equation}
Update prediction of $s$ to x-faces by accounting for r-derivatives.\\ \\
Update prediction of $s$ to y-faces by accounting for x-derivatives.\\ \\
Update prediction of $s$ to y-faces by accounting for r-derivatives.\\ \\
Update prediction of $s$ to r-faces by accounting for x-derivatives.\\ \\
Update prediction of $s$ to r-faces by accounting for y-derivatives.\\ \\
Predict $s$ to x-faces using a full-dimensional extrapolation.\\ \\
{\bf if} {\tt is\_conservative} {\bf then}
\begin{eqnarray}
s_{L,\ib-\half\eb_x}^{\edge} = s_{L,\ib-\half\eb_x} &-& \frac{\dt}{2h}\left[(s^{y|r}v^{\mac})_{\ib-\eb_x+\half\eb_y}-({s^{y|r}v^{\mac})_{\ib-\eb_x-\half\eb_y}}\right] \nonumber \\
&-& \frac{\dt}{2h}\left[(s^{r|y}w^{\mac})_{\ib-\eb_x+\half\eb_r}-({s^{r|y}w^{\mac})_{\ib-\eb_x-\half\eb_r}}\right] \nonumber \\
&-& \frac{\dt}{2h}s_{\ib-\eb_x}\left(u_{\ib-\half\eb_x}^{\mac}-u_{\ib-\frac{3}{2}\eb_x}^{\mac}\right) + \frac{\dt}{2}f_{\ib-\eb_x}, \\
s_{R,\ib-\half\eb_x}^{\edge} = s_{R,\ib-\half\eb_x} &-& \frac{\dt}{2h}\left[(s^{y|r}v^{\mac})_{\ib+\half\eb_y}-({s^{y|r}v^{\mac})_{\ib-\half\eb_y}}\right] \nonumber \\
&-& \frac{\dt}{2h}\left[(s^{r|y}w^{\mac})_{\ib+\half\eb_r}-({s^{r|y}w^{\mac})_{\ib-\half\eb_r}}\right] \nonumber \\
&-& \frac{\dt}{2h}s_{\ib}\left(u_{\ib+\half\eb_x}^{\mac}-u_{\ib-\half\eb_x}^{\mac}\right) + \frac{\dt}{2}f_{\ib}.
\end{eqnarray}
{\bf else}
\begin{eqnarray}
s_{L,\ib-\half\eb_x}^{\edge} = s_{L,\ib-\half\eb_x} &-& \frac{\dt}{4h}\left(v_{\ib-\eb_x+\half\eb_y}^{\mac}+v_{\ib-\eb_x-\half\eb_y}^{\mac}\right)\left(s_{\ib-\eb_x+\half\eb_y}^{y|r}-s_{\ib-\eb_x-\half\eb_y}^{y|r}\right) \nonumber \\
&-& \frac{\dt}{4h}\left(w_{\ib-\eb_x+\half\eb_r}^{\mac}+w_{\ib-\eb_x-\half\eb_r}^{\mac}\right)\left(s_{\ib-\eb_x+\half\eb_r}^{r|y}-s_{\ib-\eb_x-\half\eb_r}^{r|y}\right) + \frac{\dt}{2}f_{\ib-\eb_x}, \nonumber \\
&& \\
s_{R,\ib-\half\eb_x}^{\edge} = s_{R,\ib-\half\eb_x} &-& \frac{\dt}{4h}\left(v_{\ib+\half\eb_y}^{\mac}+v_{\ib-\half\eb_y}^{\mac}\right)\left(s_{\ib+\half\eb_y}^{y|r}-s_{\ib-\half\eb_y}^{y|r}\right) \nonumber \\
&-& \frac{\dt}{4h}\left(w_{\ib+\half\eb_r}^{\mac}+w_{\ib-\half\eb_r}^{\mac}\right)\left(s_{\ib+\half\eb_r}^{r|y}-s_{\ib-\half\eb_r}^{r|y}\right) + \frac{\dt}{2}f_{\ib}.
\end{eqnarray}
{\bf end if}\\ \\
Account for the $\partial w_0/\partial r$ term:\\ \\
{\bf if} {\tt is\_vel} {\bf and} {\tt comp} = 2 {\bf then}
\begin{eqnarray}
s_{L,\ib-\half\eb_x}^{\edge} &=& s_{L,\ib-\half\eb_x}^{\edge} -
\frac{\dt}{4h}\left(\wt^{\mac}_{\ib-\eb_x+\half\eb_r} + \wt^{\mac}_{\ib-\eb_x-\half\eb_r}\right)\left(w_{0,\ib+\half\eb_r}-w_{0,\ib-\half\eb_r}\right) \\
s_{R,\ib-\half\eb_x}^{\edge} &=& s_{R,\ib-\half\eb_x}^{\edge} -
\frac{\dt}{4h}\left(\wt^{\mac}_{\ib+\half\eb_r} + \wt^{\mac}_{\ib-\half\eb_r}\right)\left(w_{0,\ib+\half\eb_r}-w_{0,\ib-\half\eb_r}\right) \\
\end{eqnarray}
{\bf end if}\\ \\
Upwind based on $u^{\mac}$:
\begin{equation}
s_{\ib-\half\eb_x}^{\edge} =
\begin{cases}
\half\left(s_{L,\ib-\half\eb_x}^{\edge} + s_{R,\ib-\half\eb_x}^{\edge}\right), & \left|u^{\mac}_{\ib-\half\eb_x}\right| < \epsilon \\
s_{L,\ib-\half\eb_x}^{\edge}, & u^{\mac}_{\ib-\half\eb_x} > 0, \\
s_{R,\ib-\half\eb_x}^{\edge}, & u^{\mac}_{\ib-\half\eb_x} < 0.
\end{cases}
\end{equation}
Predict $s$ to y-faces using a full-dimensional extrapolation.\\ \\
Predict $s$ to r-faces using a full-dimensional extrapolation.

\newpage

\subsection{3D Spherical Case}
The spherical case is the same as the plane-parallel 3D Cartesian
case, except the $\partial w_0/\partial r$ term enters in the full
dimensional extrapolation for each direction when predicting velocity
to faces.  As in the plane-parallel case, make sure upwind based on
the full velocity.

\newpage

%-----------------------------------------------------------------------------
% Umac in Varden
%-----------------------------------------------------------------------------
\section{Computing $\Ub^{\mac,*}$ in \varden}

\subsection{2D Cartesian Case}
We do a 1D Taylor series extrapolation to get both components of velocity at the x-face:
\begin{eqnarray}
u_{L,\ib-\half\eb_x}^{1D} &=& u_{\ib-\eb_x} + \left[\half - \frac{\dt}{2h}{\rm max}(0,u_{\ib-\eb_x})\right]\Delta_xu_{\ib-\eb_x}, \label{varden U_L^1D} \\
u_{R,\ib-\half\eb_x}^{1D} &=& u_{\ib} + \left[\half - \frac{\dt}{2h}{\rm min}(0,u_{\ib})\right]\Delta_xu_{\ib}.
\end{eqnarray}
\begin{eqnarray}
v_{L,\ib-\half\eb_x}^{1D} &=& v_{\ib-\eb_x} + \left[\half - \frac{\dt}{2h}{\rm max}(0,v_{\ib-\eb_x})\right]\Delta_xv_{\ib-\eb_x}, \\
v_{R,\ib-\half\eb_x}^{1D} &=& v_{\ib} + \left[\half - \frac{\dt}{2h}{\rm min}(0,v_{\ib})\right]\Delta_xv_{\ib}.
\end{eqnarray}
We obtain the normal velocity using the Riemann problem:
\begin{equation}
u_{\ib-\half\eb_x}^{1D} =
\begin{cases}
0, & \left(u_{L,\ib-\half\eb_x}^{1D} \le 0 ~~ {\rm AND} ~~ u_{R,\ib-\half\eb_x}^{1D} \ge 0\right) ~~ {\rm OR} ~~ \left|u_{L,\ib-\half\eb_x}^{1D} + u_{R,\ib-\half\eb_x}^{1D}\right| < \epsilon, \\
u_{L,\ib-\half\eb_x}^{1D}, & u_{L,\ib-\half\eb_x}^{1D} + u_{R,\ib-\half\eb_x}^{1D} > 0, \\
u_{R,\ib-\half\eb_x}^{1D}, & u_{L,\ib-\half\eb_x}^{1D} + u_{R,\ib-\half\eb_x}^{1D} < 0.
\end{cases}
\end{equation}
We obtain the transverse velocity by upwinding based on
$u_{\ib-\half\eb_x}^{1D}$:
\begin{equation}
v_{\ib-\half\eb_x}^{1D} =
\begin{cases}
\half\left(v_{L,\ib-\half\eb_x}^{1D} + v_{R,\ib-\half\eb_x}^{1D}\right), & \left|u_{\ib-\half\eb_x}^{1D}\right| < \epsilon \\
v_{L,\ib-\half\eb_x}^{1D}, & u_{\ib-\half\eb_x}^{1D} > 0, \\
v_{R,\ib-\half\eb_x}^{1D}, & u_{\ib-\half\eb_x}^{1D} < 0.
\end{cases}\label{Transverse Velocity Riemann Problem}
\end{equation}
We perform analogous operations to compute both components of velocity
at the y-faces, $\Ub_{\ib-\half\eb_y}^{1D}$. \\

Now we do a full-dimensional extrapolation to get the MAC velocity at
the x-faces (note that we only compute the normal components):
\begin{eqnarray}
u_{L,\ib-\half\eb_x}^{\mac,*} &=& u_{L,\ib-\half\eb_x}^{1D} - \frac{\dt}{4h}\left(v_{\ib-\eb_x+\half\eb_y}^{1D}+v_{\ib-\eb_x-\half\eb_y}^{1D}\right)\left(u_{\ib-\eb_x+\half\eb_y}^{1D} - u_{\ib-\eb_x-\half\eb_y}^{1D}\right) + \frac{\dt}{2}f_{u,\ib-\eb_x}, \\
u_{R,\ib-\half\eb_x}^{\mac,*} &=& u_{R,\ib-\half\eb_x}^{1D} - \frac{\dt}{4h}\left(v_{\ib+\half\eb_y}^{1D}+v_{\ib-\half\eb_y}^{1D}\right)\left(u_{\ib+\half\eb_y}^{1D} - u_{\ib-\half\eb_y}^{1D}\right) + \frac{\dt}{2}f_{u,\ib}.
\end{eqnarray}
Then we solve a Riemann problem:
\begin{equation}
u_{\ib-\half\eb_x}^{\mac,*} =
\begin{cases}
0, & \left(u_{L,\ib-\half\eb_x}^{\mac,*} \le 0 ~~ {\rm AND} ~~ u_{R,\ib-\half\eb_x}^{\mac,*} \ge 0\right) ~~ {\rm OR} ~~ \left|u_{L,\ib-\half\eb_x}^{\mac,*} + u_{R,\ib-\half\eb_x}^{\mac,*}\right| < \epsilon, \\
u_{L,\ib-\half\eb_x}^{\mac,*}, & u_{L,\ib-\half\eb_x}^{\mac,*} + u_{R,\ib-\half\eb_x}^{\mac,*} > 0, \\
u_{R,\ib-\half\eb_x}^{\mac,*}, & u_{L,\ib-\half\eb_x}^{\mac,*} + u_{R,\ib-\half\eb_x}^{\mac,*} < 0.
\end{cases}\label{umac Riemann Problem}
\end{equation}
We perform analogous operations to compute the normal velocity at the
y-faces, $v^{\mac,*}_{\ib-\half\eb_y}$.

\subsection{3D Cartesian Case}
This is more complicated than the 2D case because we include corner
coupling.  We compute $\Ub_{\ib-\half\eb_x}^{1D},
\Ub_{\ib-\half\eb_y}^{1D}$, and $\Ub_{\ib-\half\eb_z}^{1D}$ in an
analogous manner as equations (\ref{varden U_L^1D})-(\ref{Transverse
  Velocity Riemann Problem}).  Then we compute an intermediate state,
$u_{\ib-\half\eb_y}^{y|z}$, which is described as ``state
$u_{\ib-\half\eb_y}^{1D}$ that has been updated to account for the
transverse derivatives in the z direction'', using:
\begin{eqnarray}
u_{L,\ib-\half\eb_y}^{y|z} &=& u_{L,\ib-\half\eb_y}^{1D} - \frac{\dt}{6h}\left(w_{\ib-\eb_y+\half\eb_z}^{1D}+w_{\ib-\eb_y-\half\eb_z}^{1D}\right)\left(u_{\ib-\eb_y+\half\eb_z}^{1D}-u_{\ib-\eb_y-\half\eb_z}^{1D}\right), \\
u_{R,\ib-\half\eb_y}^{y|z} &=& u_{R,\ib-\half\eb_y}^{1D} - \frac{\dt}{6h}\left(w_{\ib+\half\eb_z}^{1D}+w_{\ib-\half\eb_z}^{1D}\right)\left(u_{\ib+\half\eb_z}^{1D}-u_{\ib-\half\eb_z}^{1D}\right).
\end{eqnarray}
Then upwind based on $v_{\ib-\half\eb_y}^{1D}$:
\begin{equation}
u_{\ib-\half\eb_y}^{y|z} =
\begin{cases}
\half\left(u_{L,\ib-\half\eb_y}^{y|z} + u_{R,\ib-\half\eb_y}^{y|z}\right), & \left|v_{\ib-\half\eb_y}^{1D}\right| < \epsilon \\
u_{L,\ib-\half\eb_y}^{y|z}, & v_{\ib-\half\eb_y}^{1D} > 0, \\
u_{R,\ib-\half\eb_y}^{y|z}, & v_{\ib-\half\eb_y}^{1D} < 0.
\end{cases}
\end{equation}
We use an analogous procedure to compute five more intemediate states,
$u_{\ib-\half\eb_z}^{z|y}, v_{\ib-\half\eb_x}^{x|z},
v_{\ib-\half\eb_z}^{z|x}, w_{\ib-\half\eb_x}^{x|y}$, and
$w_{\ib-\half\eb_y}^{y|x}$.  Then we do a full-dimensional
extrapolation to get the MAC velocities at normal faces:
\begin{eqnarray}
u_{L,\ib-\half\eb_x}^{\mac,*} = u_{L,\ib-\half\eb_x}^{1D} &-& \frac{\dt}{4h}\left(v_{\ib-\eb_x+\half\eb_y}^{1D}+v_{\ib-\eb_x-\half\eb_y}^{1D}\right)\left(u_{\ib-\eb_x+\half\eb_y}^{y|z}-u_{\ib-\eb_x-\half\eb_y}^{y|z}\right) \nonumber \\
&-& \frac{\dt}{4h}\left(w_{\ib-\eb_x+\half\eb_z}^{1D}+w_{\ib-\eb_x-\half\eb_z}^{1D}\right)\left(u_{\ib-\eb_x+\half\eb_z}^{z|y}-u_{\ib-\eb_x-\half\eb_z}^{z|y}\right) + \frac{\dt}{2}f_{u,\ib-\eb_x}, \\
u_{R,\ib-\half\eb_x}^{\mac,*} = u_{R,\ib-\half\eb_x}^{1D} &-& \frac{\dt}{4h}\left(v_{\ib+\half\eb_y}^{1D}+v_{\ib-\half\eb_y}^{1D}\right)\left(u_{\ib+\half\eb_y}^{y|z}-u_{\ib-\half\eb_y}^{y|z}\right) \nonumber \\
&-& \frac{\dt}{4h}\left(w_{\ib+\half\eb_z}^{1D}+w_{\ib-\half\eb_z}^{1D}\right)\left(u_{\ib+\half\eb_z}^{z|y}-u_{\ib-\half\eb_z}^{z|y}\right) + \frac{\dt}{2}f_{u,\ib}.
\end{eqnarray}
Then we use the Riemann solver given above for the 2D case (equation
[\ref{umac Riemann Problem}]) to compute
$u_{\ib-\half\eb_x}^{\mac,*}$.  We use an analogous procedure to
obtain $v_{\ib-\half\eb_y}^{\mac,*}$ and
$w_{\ib-\half\eb_z}^{\mac,*}$.

\newpage

%-----------------------------------------------------------------------------
% Varden edge states
%-----------------------------------------------------------------------------
\section{Computing $\Ub^{\edge}$ and $\rho^{\edge}$ in \varden}
To compute $\Ub^{\edge}$, \varden\ uses the exact same algorithm
as the $s^{\edge}$ case in \maestro.  The algorithm for
$\rho^{\edge}$ in \varden\ is slightly different than the
$s^{\edge}$ case in \maestro\ since it uses a ``conservative''
formulation.  Here, $s$ is used in place of either $\rho, u, v$, or
$w$ (in 3D).

\subsection{2D Cartesian Case}
The 1D extrapolation is:
\begin{eqnarray}
s_{L,\ib-\half\eb_x}^{1D} &=& s_{\ib-\eb_x}^n + \left(\half - \frac{\dt}{2h}u_{\ib-\half\eb_x}^{\mac}\right)\Delta_x s_{\ib-\eb_x}^n, \label{varden s_L^1D}\\
s_{R,\ib-\half\eb_x}^{1D} &=& s_{\ib} - \left(\half + \frac{\dt}{2h}u_{\ib-\half\eb_x}^{\mac}\right)\Delta_x s_{\ib}^n. \label{varden s_R^1D}
\end{eqnarray}
Then we upwind based on $u^{\mac}$:
\begin{equation}
s_{\ib-\half\eb_x}^{1D} =
\begin{cases}
\half\left(s_{L,\ib-\half\eb_x}^{1D} + s_{R,\ib-\half\eb_x}^{1D}\right), & \left|u^{\mac}_{\ib-\half\eb_x}\right| < \epsilon \\
s_{L,\ib-\half\eb_x}^{1D}, & u^{\mac}_{\ib-\half\eb_x} > 0, \\
s_{R,\ib-\half\eb_x}^{1D}, & u^{\mac}_{\ib-\half\eb_x} < 0. \\
\end{cases}
\end{equation}
We use an analogous procedure to obtain $s_{\ib-\half\eb_y}^{1D}$.
Now we do a full-dimensional extrapolation of $s$ to each face.  The
extrapolation of a ``non-conserved'' $s$ to x-faces is:
\begin{eqnarray}
s_{L,\ib-\half\eb_x}^{\edge} &=& s_{L,\ib-\half\eb_x}^{1D} - \frac{\dt}{4h}\left(v_{\ib-\eb_x+\half\eb_y}^{\mac}+v_{\ib-\eb_x-\half\eb_y}^{\mac}\right)\left(s_{\ib-\eb_x+\half\eb_y}^{1D} - s_{\ib-\eb_x-\half\eb_y}^{1D}\right) + \frac{\dt}{2}f_{s,\ib-\eb_x}, \\
s_{R,\ib-\half\eb_x}^{\edge} &=& s_{R,\ib-\half\eb_x}^{1D} - \frac{\dt}{4h}\left(v_{\ib+\half\eb_y}^{\mac}+v_{\ib-\half\eb_y}^{\mac}\right)\left(s_{\ib+\half\eb_y}^{1D} - s_{\ib-\half\eb_y}^{1D}\right) + \frac{\dt}{2}f_{s,\ib}.
\end{eqnarray}
The extrapolation of a ``conserved'' $s$ to x-faces is:
\begin{eqnarray}
s_{L,\ib-\half\eb_x}^{\edge} = s_{L,\ib-\half\eb_x}^{1D} &-& \frac{\dt}{2h}\left[(s^{1D} v^{\mac})_{\ib-\eb_x+\half\eb_y} - (s^{1D} v^{\mac})_{\ib-\eb_x-\half\eb_y}\right] \nonumber \\
&-& \frac{\dt}{2}s_{\ib-\eb_x}(\nabla\cdot\Ub^{\mac})_{\ib-\eb_x} + \frac{\dt}{2h}s_{\ib-\eb_x}\left(v_{\ib-\eb_x+\half\eb_y}^{\mac} - v_{\ib-\eb_x-\half\eb_y}^{\mac}\right) + \frac{\dt}{2}f_{s,\ib-\eb_x}, \\
s_{R,\ib-\half\eb_x}^{\edge} = s_{R,\ib-\half\eb_x}^{1D} &-& \frac{\dt}{2h}\left[(s^{1D} v^{\mac})_{\ib+\half\eb_y} - (s^{1D} v^{\mac})_{\ib-\half\eb_y}\right] \nonumber \\
&-& \frac{\dt}{2}s_{\ib}(\nabla\cdot\Ub^{\mac})_{\ib} + \frac{\dt}{2h}s_{\ib}\left(v_{\ib+\half\eb_y}^{\mac} - v_{\ib-\half\eb_y}^{\mac}\right) + \frac{\dt}{2}f_{s,\ib}.
\end{eqnarray}
Then we upwind based on $u^{\mac}$.
\begin{equation}
s_{\ib-\half\eb_x}^{\edge} =
\begin{cases}
\half\left(s_{L,\ib-\half\eb_x}^{\edge} + s_{R,\ib-\half\eb_x}^{\edge}\right), & \left|u^{\mac}_{\ib-\half\eb_x}\right| < \epsilon \\
s_{L,\ib-\half\eb_x}^{\edge}, & u^{\mac}_{\ib-\half\eb_x} > 0, \\
s_{R,\ib-\half\eb_x}^{\edge}, & u^{\mac}_{\ib-\half\eb_x} < 0.
\end{cases}\label{varden s^edge upwind}
\end{equation}
We use an analogous procedure to compute $s_{\ib-\half\eb_y}^{\edge}$.

\subsection{3D Cartesian Case}
This is more complicated than the 2D case because we include corner
coupling.  We first compute $s_{\ib-\half\eb_x}^{1D}$,
$s_{\ib-\half\eb_y}^{1D}$, and $s_{\ib-\half\eb_z}^{1D}$ in an
analogous manner to equations (\ref{varden s_L^1D}) and
(\ref{varden s_R^1D}).  Then we compute six intermediate states,
$s_{\ib-\half\eb_x}^{x|y}, s_{\ib-\half\eb_x}^{x|z},
s_{\ib-\half\eb_y}^{y|x}, s_{\ib-\half\eb_y}^{y|z},
s_{\ib-\half\eb_z}^{z|x}$, and $s_{\ib-\half\eb_z}^{z|y}$.  For the
``non-conservative case'', we use, for example:
\begin{eqnarray}
s_{L,\ib-\half\eb_x}^{x|y} &=& s_{L,\ib-\half\eb_x}^{1D} - \frac{\dt}{6h}\left(v_{\ib-\eb_x+\half\eb_y}^{\mac} + v_{\ib-\eb_x-\half\eb_y}^{\mac}\right)\left(s_{\ib-\eb_x+\half\eb_y}^{1D} - s_{\ib-\eb_x-\half\eb_y}^{1D}\right), \\
s_{R,\ib-\half\eb_x}^{x|y} &=& s_{R,\ib-\half\eb_x}^{1D} - \frac{\dt}{6h}\left(v_{\ib+\half\eb_y}^{\mac} + v_{\ib-\half\eb_y}^{\mac}\right)\left(s_{\ib+\half\eb_y}^{1D} - s_{\ib-\half\eb_y}^{1D}\right).
\end{eqnarray}
For the ``conservative'' case, we use, for example:
\begin{eqnarray}
s_{L,\ib-\half\eb_x}^{x|y} &=& s_{L,\ib-\half\eb_x}^{1D} - \frac{\dt}{3h}\left[(sv^{\mac})_{\ib-\eb_x+\half\eb_y}-(sv^{\mac})_{\ib-\eb_x-\half\eb_y}\right], \\
s_{R,\ib-\half\eb_x}^{x|y} &=& s_{R,\ib-\half\eb_x}^{1D} - \frac{\dt}{3h}\left[(sv^{\mac})_{\ib+\half\eb_y}-(sv^{\mac})_{\ib-\half\eb_y}\right].
\end{eqnarray}
Then we upwind based on $u^{\mac}$:
\begin{equation}
s_{\ib-\half\eb_x}^{x|y} =
\begin{cases}
\half\left(s_{L,\ib-\half\eb_x}^{x|y} + s_{R,\ib-\half\eb_x}^{x|y}\right), & \left|u^{\mac}_{\ib-\half\eb_x}\right| < \epsilon \\
s_{L,\ib-\half\eb_x}^{x|y}, & u^{\mac}_{\ib-\half\eb_x} > 0, \\
s_{R,\ib-\half\eb_x}^{x|y}, & u^{\mac}_{\ib-\half\eb_x} < 0.
\end{cases}
\end{equation}
We use an analogous procedure to compute the other five intermediate
states.  Now we do a full-dimensional extrapolation of $s$ to each
face.  The extrapolation of a ``non-conserved'' $s$ to x-faces is:
\begin{eqnarray}
s_{L,\ib-\half\eb_x}^{\edge} = s_{L,\ib-\half\eb_x}^{1D} &-& \frac{\dt}{4h}\left(v_{\ib-\eb_x+\half\eb_y}^{\mac}+v_{\ib-\eb_x-\half\eb_y}^{\mac}\right)\left(s_{\ib-\eb_x+\half\eb_y}^{y|z}-s_{\ib-\eb_x-\half\eb_y}^{y|z}\right) \nonumber \\
&-& \frac{\dt}{4h}\left(w_{\ib-\eb_x+\half\eb_z}^{\mac}+w_{\ib-\eb_x-\half\eb_z}^{\mac}\right)\left(s_{\ib-\eb_x+\half\eb_z}^{z|y}-s_{\ib-\eb_x-\half\eb_z}^{z|y}\right) \nonumber \\
&+& \frac{\dt}{2}f_{s,\ib-\eb_x}, \\
s_{R,\ib-\half\eb_x}^{\edge} = s_{R,\ib-\half\eb_x}^{1D} &-& \frac{\dt}{4h}\left(v_{\ib+\half\eb_y}^{\mac}+v_{\ib-\half\eb_y}^{\mac}\right)\left(s_{\ib+\half\eb_y}^{y|z}-s_{\ib-\half\eb_y}^{y|z}\right) \nonumber \\
&-& \frac{\dt}{4h}\left(w_{\ib+\half\eb_z}^{\mac}+w_{\ib-\half\eb_z}^{\mac}\right)\left(s_{\ib+\half\eb_z}^{z|y}-s_{\ib-\half\eb_z}^{z|y}\right) \nonumber \\
&+& \frac{\dt}{2}f_{s,\ib}.
\end{eqnarray}
The extrapolation of a ``conserved'' $s$ to x-faces is:
\begin{eqnarray}
s_{L,\ib-\half\eb_x}^{\edge} = s_{L,\ib-\half\eb_x}^{1D} &-& \frac{\dt}{2h}\left[(s^{y|z}v^{\mac})_{\ib-\eb_x+\half\eb_y}-({s^{y|z}v^{\mac})_{\ib-\eb_x-\half\eb_y}}\right] \nonumber \\
&-& \frac{\dt}{2h}\left[(s^{z|y}w^{\mac})_{\ib-\eb_x+\half\eb_z}-({s^{z|y}w^{\mac})_{\ib-\eb_x-\half\eb_z}}\right] \nonumber \\
&-& \frac{\dt}{2}s_{\ib-\eb_x}(\nabla\cdot\Ub^{\mac})_{\ib-\eb_x} \nonumber \\
&+& \frac{\dt}{2h}s_{\ib-\eb_x}\left(v_{\ib-\eb_x+\half\eb_y}^{\mac}-v_{\ib-\eb_x-\half\eb_y}^{\mac}+w_{\ib-\eb_x+\half\eb_z}^{\mac}-w_{\ib-\eb_x-\half\eb_z}^{\mac}\right) \nonumber \\
&+& \frac{\dt}{2}f_{s,\ib-\eb_x}, \\
s_{R,\ib-\half\eb_x}^{\edge} = s_{R,\ib-\half\eb_x}^{1D} &-& \frac{\dt}{2h}\left[(s^{y|z}v^{\mac})_{\ib+\half\eb_y}-({s^{y|z}v^{\mac})_{\ib-\half\eb_y}}\right] \nonumber \\
&-& \frac{\dt}{2h}\left[(s^{z|y}w^{\mac})_{\ib+\half\eb_z}-({s^{z|y}w^{\mac})_{\ib-\half\eb_z}}\right] \nonumber \\
&-& \frac{\dt}{2}s_{\ib}(\nabla\cdot\Ub^{\mac})_{\ib} \nonumber \\
&+& \frac{\dt}{2h}s_{\ib}\left(v_{\ib+\half\eb_y}^{\mac}-v_{\ib-\half\eb_y}^{\mac}+w_{\ib+\half\eb_z}^{\mac}-w_{\ib-\half\eb_z}^{\mac}\right) \nonumber \\
&+& \frac{\dt}{2}f_{s,\ib}.
\end{eqnarray}
Then we upwind based on $u^{\mac}$, as in equation
(\ref{varden s^edge upwind}).
We use an analogous procedure to compute both
$s_{\ib-\half\eb_y}^{\edge}$ and $s_{\ib-\half\eb_z}$.

\newpage

%-----------------------------------------------------------------------------
% ESTATE_FPU
%-----------------------------------------------------------------------------
\section{ESTATE\_FPU in GODUNOV\_2D/3D.f}
First, the normal predictor.
\begin{eqnarray}
s_L^x &=& s_{\ib-\eb_x} + \left(\half - \frac{\dt}{h_x}\text{UEDGE}_{\ib-\half\eb_x}\right)\Delta^x s_{\ib-\eb_x} + \underbrace{\frac{\dt}{2}\text{TFORCES}_{\ib-\eb_x}}_{\text{IF USE\_MINION}} \\
s_R^x &=& s_{\ib} - \left(\half + \frac{\dt}{h_x}\text{UEDGE}_{\ib-\half\eb_x}\right)\Delta^x s_{\ib} + \underbrace{\frac{\dt}{2}\text{TFORCES}_{\ib}}_{\text{IF USE\_MINION}}
\end{eqnarray}
{\bf If} USE\_MINION {\bf and} ICONSERVE {\bf then:}
\begin{eqnarray}
s_L^x &=& s_L^x - \frac{\dt}{2}s_{\ib-\eb_x}\text{DIVU}_{\ib-\eb_x} \\
s_R^x &=& s_R^x - \frac{\dt}{2}s_{\ib}\text{DIVU}_{\ib}
\end{eqnarray}
Apply boundary conditions on $s_L^x$ and $s_R^x$.  Then,
\begin{equation}
\text{s}_{\ib-\half\eb_x}^x =
\begin{cases}
s_L^x, & \text{UEDGE}_{\ib-\half\eb_x} > 0, \\
s_R^x, & \text{else}. \\
\end{cases}\label{ESTATE_FPU Upwind}
\end{equation}
Then, if $|\text{UEDGE}_{\ib-\half\eb_x}| \le \epsilon$, we set $s_{\ib-\half\eb_x}^x = (s_L^x+s_R^x)/2$.  The procedure to obtain $s_{\ib-\half\eb_y}^y$ is analogous.\\ \\
Now, the transverse terms.\\ \\
{\bf If} ICONSERVE {\bf then:}
\begin{eqnarray}
\text{sedge}_L^x &=& s_{\ib-\eb_x} + \left(\half - \frac{\dt}{h_x}\text{UEDGE}_{\ib-\half\eb_x}\right)\Delta^x s_{\ib-\eb_x} + \frac{\dt}{2}\text{TFORCES}_{\ib-\eb_x} \nonumber\\
&& - \frac{\dt}{2}\left[\frac{\text{VEDGE}_{\ib-\eb_x+\half\eb_y}s_{\ib-\eb_x+\half\eb_y}^y - \text{VEDGE}_{\ib-\eb_x-\half\eb_y}s_{\ib-\eb_x-\half\eb_y}^y}{h_y}\right.\nonumber\\
&& ~~~~~~~~~~ \left. - \frac{s_{\ib-\eb_x}(\text{VEDGE}_{\ib-\eb_x+\half\eb_y}-\text{VEDGE}_{\ib-\eb_x-\half\eb_y})}{h_y}+s_{\ib-\eb_x}\text{DIVU}_{\ib-\eb_x}\right]\\
\text{sedge}_R^x &=& s_{\ib} - \left(\half + \frac{\dt}{h_x}\text{UEDGE}_{\ib-\half\eb_x}\right)\Delta^x s_{\ib} + \frac{\dt}{2}\text{TFORCES}_{\ib} \nonumber\\
&& - \frac{\dt}{2}\left[\frac{\text{VEDGE}_{\ib+\half\eb_y}s_{\ib+\half\eb_y}^y - \text{VEDGE}_{\ib-\half\eb_y}s_{\ib-\half\eb_y}^y}{h_y}\right.\nonumber\\
&& ~~~~~~~~~~ \left. - \frac{s_{\ib}(\text{VEDGE}_{\ib+\half\eb_y}-\text{VEDGE}_{\ib-\half\eb_y})}{h_y}+s_{\ib}\text{DIVU}_{\ib}\right]
\end{eqnarray}
Now, define $\text{VBAR}_{\ib} = (\text{VEDGE}_{\ib+\half\eb_y}+\text{VEDGE}_{\ib-\half\eb_y})/2$.\\ \\
{\bf If} NOT ICONSERVE {\bf and} $\text{VEDGE}_{\ib+\half\eb_y}\cdot\text{VEDGE}_{\ib-\half\eb_y} < 0$ {\bf and} $\text{VBAR}_{\ib} < 0$ {\bf then:}
\begin{eqnarray}
\text{sedge}_L^x = s_{\ib-\eb_x} &+& \left(\half - \frac{\dt}{h_x}\text{UEDGE}_{\ib-\half\eb_x}\right)\Delta^x s_{\ib} + \frac{\dt}{2}\text{TFORCES}_{\ib-\eb_x} \nonumber\\
&& - \frac{\dt}{2}\left[\frac{\text{VBAR}_{\ib-\eb_x}(s_{\ib-\eb_x+\eb_y}-s_{\ib-\eb_x})}{h_y}\right] \label{transverse upwinding 1} \\
\text{sedge}_R^x = s_{\ib} &-& \left(\half + \frac{\dt}{h_x}\text{UEDGE}_{\ib-\half\eb_x}\right)\Delta^x s_{\ib} + \frac{\dt}{2}\text{TFORCES}_{\ib} \nonumber\\
&& - \frac{\dt}{2}\left[\frac{\text{VBAR}_{\ib}(s_{\ib+\eb_y}-s_{\ib})}{h_y}\right]
\end{eqnarray}
{\bf Else If} NOT ICONSERVE {\bf and} $\text{VEDGE}_{\ib+\half\eb_y}\cdot\text{VEDGE}_{\ib-\half\eb_y} < 0$ {\bf and} $\text{VBAR}_{\ib} \ge 0$ {\bf then:}
\begin{eqnarray}
\text{sedge}_L^x = s_{\ib-\eb_x} &+& \left(\half - \frac{\dt}{h_x}\text{UEDGE}_{\ib-\half\eb_x}\right)\Delta^x s_{\ib-\eb_x} + \frac{\dt}{2}\text{TFORCES}_{\ib-\eb_x} \nonumber\\
&& - \frac{\dt}{2}\left[\frac{\text{VBAR}_{\ib-\eb_x}(s_{\ib-\eb_x}-s_{\ib-\eb_x-\eb_y})}{h_y}\right] \\
\text{sedge}_R^x = s_{\ib} &-& \left(\half + \frac{\dt}{h_x}\text{UEDGE}_{\ib-\half\eb_x}\right)\Delta^x s_{\ib} + \frac{\dt}{2}\text{TFORCES}_{\ib} \nonumber\\
&& - \frac{\dt}{2}\left[\frac{\text{VBAR}_{\ib}(s_{\ib}-s_{\ib-\eb_y})}{h_y}\right]
\end{eqnarray}
{\bf Else If} NOT ICONSERVE {\bf and} $\text{VEDGE}_{\ib+\half\eb_y}\cdot\text{VEDGE}_{\ib-\half\eb_y} \ge 0$ {\bf then:}
\begin{eqnarray}
\text{sedge}_L^x &=& s_{\ib-\eb_x} + \left(\half - \frac{\dt}{h_x}\text{UEDGE}_{\ib-\half\eb_x}\right)\Delta^x s_{\ib-\eb_x} + \frac{\dt}{2}\text{TFORCES}_{\ib-\eb_x} \nonumber\\
&& - \frac{\dt}{2}\left[\frac{(\text{VEDGE}_{\ib-\eb_x+\half\eb_y}+\text{VEDGE}_{\ib-\eb_x-\half\eb_y})(s_{\ib-\eb_x+\half\eb_y}-s_{\ib-\eb_x-\half\eb_y})}{2h_y}\right] \\
\text{sedge}_R^x &=& s_{\ib} - \left(\half + \frac{\dt}{h_x}\text{UEDGE}_{\ib-\half\eb_x}\right)\Delta^x s_{\ib} + \frac{\dt}{2}\text{TFORCES}_{\ib} \nonumber\\
&& - \frac{\dt}{2}\left[\frac{(\text{VEDGE}_{\ib+\half\eb_y}+\text{VEDGE}_{\ib-\half\eb_y})(s_{\ib+\half\eb_y}-s_{\ib-\half\eb_y})}{2h_y}\right]\label{transverse upwinding 6}
\end{eqnarray}
Finally, upwind analogous to equation (\ref{ESTATE_FPU Upwind}) to get $\text{sedge}_{\ib-\half\eb_x}$.

\newpage

%-----------------------------------------------------------------------------
% ESTATE
%-----------------------------------------------------------------------------
\section{ESTATE in GODUNOV\_2D/3D.f}
First, the normal predictor.
\begin{eqnarray}
s_L^x &=& s_{\ib-\eb_x} + \left(\half - \frac{\dt}{h_x}u_{\ib-\eb_x}\right)\Delta^x s_{\ib-\eb_x} \\
s_R^x &=& s_{\ib} - \left(\half + \frac{\dt}{h_x}u_{\ib}\right)\Delta^x s_{\ib}
\end{eqnarray}
{\bf If} USE\_MINION {\bf then:}
\begin{eqnarray}
s_L^x &=& s_L^x + \frac{\dt}{2}\text{TFORCES}_{\ib-\eb_x} \\
s_R^x &=& s_R^x + \frac{\dt}{2}\text{TFORCES}_{\ib}
\end{eqnarray}
Apply boundary conditions on $s_L^x$ and $s_R^x$.  Then,
\begin{equation}
\text{s}_{\ib-\half\eb_x}^x =
\begin{cases}
s_L^x, & \text{UAD}_{\ib-\half\eb_x} > 0, \\
s_R^x, & \text{else}. \\
\end{cases}\label{ESTATE Upwind}
\end{equation}
Then, if $|\text{UAD}_{\ib-\half\eb_x}| \le \epsilon$, we set $s_{\ib-\half\eb_x}^x = (s_L^x+s_R^x)/2$.
\begin{eqnarray}
\text{sedge}_L^x = s_{\ib-\eb_x} &+& \left(\half - \frac{\dt}{h_x}u_{\ib-\eb_x}\right)\Delta^x s_{\ib-\eb_x} + \frac{\dt}{2}\text{TFORCES}_{\ib-\eb_x} \nonumber\\
&& - \frac{\dt}{2}\left[\frac{(\text{VAD}_{\ib-\eb_x+\half\eb_y}+\text{VAD}_{\ib-\eb_x-\half\eb_y})(s_{\ib-\eb_x+\half\eb_y}-s_{\ib-\eb_x-\half\eb_y})}{2h_y}\right] \\
\text{sedge}_R^x = s_{\ib} &-& \left(\half + \frac{\dt}{h_x}u_{\ib}\right)\Delta^x s_{\ib} + \frac{\dt}{2}\text{TFORCES}_{\ib} \nonumber\\
&& - \frac{\dt}{2}\left[\frac{(\text{VAD}_{\ib+\half\eb_y}+\text{VAD}_{\ib-\half\eb_y})(s_{\ib+\half\eb_y}-s_{\ib-\half\eb_y})}{2h_y}\right]
\end{eqnarray}
Note that the 2D and 3D algorithms are different - in 3D the transverse
terms use upwinding analogous to equations
(\ref{transverse upwinding 1})-(\ref{transverse upwinding 6}), using UAD
instead of UEDGE.  Finally, upwind analogous to equation (\ref{ESTATE Upwind})
to get $\text{sedge}_{\ib-\half\eb_x}$, but use UEDGE instead of UAD.

\newpage

%-----------------------------------------------------------------------------
% PPM
%-----------------------------------------------------------------------------
\section{Piecewise Parabolic Method (PPM)}
Consider a scalar, $s$, which we wish to predict to time-centered edges.
The PPM method is an improvement over the piecewise-linear method.
Using our notation, we modify equations (\ref{3D predict s to left}) and
(\ref{3D predict s to right}) in Section
\ref{Scalar Edge State Prediction in MAESTRO} to obtain better estimates
for the time-centered 1D edge states, $s_{L/R,\ib-\myhalf\eb_x}$, etc..  Once these states
are obtained, we continue with the full-dimensional extrapolations as
described before.\\ \\
The PPM method is described in a series of papers:
\begin{itemize}
\item Colella and Woodward 1984 - describes the basic method.
\item Miller and Colella 2002 - describes how to apply PPM to a multidimensional
unsplit Godunov method and generalizes the characteristic tracing for more complicated
systems.  Note that we only need to upwind based on the fluid velocity, so we don't
need to use fancy characteristic tracing.
\item Colella and Sekora 2008 - describes new fancy quadratic limiters.  There are
several errors in the printed text, so we have implemented a corrected version from
Phil Colella.
\end{itemize}
Here are the steps for the $x$-direction.  For simplicity, we replace the vector index notation with a simple scalar notation ($\ib+\eb_x \rightarrow i+1$, etc.).

\begin{itemize}
\item {\bf Step 1:} Compute $s_{i,+}$ and $s_{i,-}$, which are spatial interpolations of
$s$ to the hi and lo faces of cell $i$, respectively.  See Sections
\ref{Sec:ColellaWoodward} and \ref{Sec:ColellaSekora} for the two options.
\item {\bf Step 2:} Construct a quadratic profile within each cell.
\begin{equation}
s_i^I(x) = s_{i,-} + \xi\left[s_{i,+} - s_{i,-} + s_{6,i}(1-\xi)\right],\label{Quadratic Interp}
\end{equation}
\begin{equation}
s_{6,i}= 6s_{i} - 3\left(s_{i,-}+s_{i,+}\right),
\end{equation}
\begin{equation}
\xi = \frac{x - (i-\myhalf)h}{h}, ~ 0 \le \xi \le 1.
\end{equation}
\item {\bf Step 3:} Integrate quadratic profiles to get the average value swept over the face
over time.\\ \\
Define the following integrals, where $\sigma = |u|\Delta t/h$:
\begin{eqnarray}
\mathcal{I}_{i,+}(\sigma) &=& \frac{1}{\sigma h}\int_{(i+\myhalf)h-\sigma h}^{(i+\myhalf)h}s_i^I(x)dx \\
\mathcal{I}_{i,-}(\sigma) &=& \frac{1}{\sigma h}\int_{(i-\myhalf)h}^{(i-\myhalf)h+\sigma h}s_i^I(x)dx
\end{eqnarray}
Plugging in (\ref{Quadratic Interp}) gives:
\begin{eqnarray}
\mathcal{I}_{i,+}(\sigma) &=& s_{j,+} - \frac{\sigma}{2}\left[s_{j,+}-s_{j,-}-\left(1-\frac{2}{3}\sigma\right)s_{6,i}\right], \\
\mathcal{I}_{i,-}(\sigma) &=& s_{j,-} + \frac{\sigma}{2}\left[s_{j,+}-s_{j,-}+\left(1-\frac{2}{3}\sigma\right)s_{6,i}\right].
\end{eqnarray}
\item {\bf Step 4:} Obtain 1D edge states.\\ \\
Perform a 1D extrapolation, without source terms, to get
left and right edge states.  Add the source terms later if desired/necessary.\\ \\
\begin{eqnarray}
s_{L,i-\myhalf} &=&
\begin{cases}
\mathcal{I}_{i-1,+}(\sigma), & u_{i-1} ~ \text{or} ~ u_{i-\myhalf}^{\mac} > 0 \\
s_{i-1}, & \text{else}.
\end{cases}\\
s_{R,i-\myhalf} &=&
\begin{cases}
\mathcal{I}_{i,-}(\sigma), & u_{i} ~ \text{or} ~ u_{i-\myhalf}^{\mac} < 0 \\
s_{i}, & \text{else}.
\end{cases}
\end{eqnarray}
\end{itemize}

\subsection{Colella and Woodward Based Approach}\label{Sec:ColellaWoodward}
Spatially interpolate $s$ to edges.
Use a 4th-order interpolation in space with van Leer limiting to obtain edge values:
\begin{equation}
s_{i+\myhalf} = \frac{1}{2}\left(s_{i} + s_{i+1}\right) - \frac{1}{6}\left(\delta s_{i+1}^{vL} - \delta s_{i}^{vL}\right),\label{eq:CW Edge}
\end{equation}
\begin{equation}
\delta s_i =
\frac{1}{2}\left(s_{i+1}-s_{i-1}\right),
\end{equation}
\begin{equation}
\delta s_i^{vL} =
\begin{cases}
\text{sign}(\delta s_i)\min\left(|\delta s_i|, ~ 2|s_{i+1}-s_{i}|, ~ 2|s_i-s_{i-1}|\right), & {\rm if} ~ (s_{i+1}-s_i)(s_i-s_{i-1}) > 0,\\
0, & {\rm otherwise}.
\end{cases}
\end{equation}
A more compact way of writing this is
\begin{equation}
s = \text{sign}(\delta s_i),
\end{equation}
\begin{equation}
\delta s_i^{vL} = s\max\left\{\min\left[s\delta s_i, 2s(s_{i+1}-s_i),2s(s_i-s_{i-1})\right],0\right\}
\end{equation}
Without the limiters, equation (\ref{eq:CW Edge}) is the familiar 4th-order spatial interpolation formula:
\begin{equation}
s_{i+\myhalf} = \frac{7}{12}\left(s_{i+1}+s_i\right) - \frac{1}{12}\left(s_{i+2}+s_{i-1}\right).
\end{equation}
Next, we must ensure that $s_{i+\myhalf}$ lies between the adjacent
cell-centered values:
\begin{equation}
\min\left(s_{i},s_{i+1}\right) \le s_{i+\myhalf} \le \max\left(s_{i},s_{i+1}\right).
\end{equation}
In anticipation of further limiting, we set double-valued face-centered values:
\begin{equation}
s_{i,+} = s_{i+1,-} = s_{i+\myhalf}.
\end{equation}
Modify $s_{i,\pm}$ using a quadratic limiter.
First, we test whether
$s_i$ is a local extreumum with the condition:
\begin{equation}
\left(s_{i,+}-s_i\right)\left(s_i-s_{i,-}\right) \le 0,
\end{equation}
If this condition is true, we constrain $s_{i,\pm}$ by setting
$s_{i,+} = s_{i,-} = s_i$.  If not, we then apply a second test to determine
whether $s_i$ is sufficiently close to $s_{i,\pm}$ so that a quadratic
interpolate would contain a local extremum.  We define
$\alpha_{i,\pm} = s_{i,\pm} - s_i$.  If one of $|\alpha_{i,\pm}| \ge 2|\alpha_{i,\mp}|$
holds, then for that choice of $\pm = +,-$ we set:
\begin{equation}
s_{i,\pm} = 3s_i - 2s_{i,\mp}.
\end{equation}
\subsection{Colella and Sekora Based Approach}\label{Sec:ColellaSekora}
Spatially interpolate $s$ to edges.
Use a 4th-order interpolation in space to obtain edge values:
\begin{equation}
s_{i+\myhalf} = \frac{7}{12}\left(s_{i+1}+s_i\right) - \frac{1}{12}\left(s_{i+2}+s_{i-1}\right).
\end{equation}
Then, if $(s_{i+\myhalf}-s_i)(s_{i+1}-s_{i+\myhalf}) < 0$, we limit $s_{i+\myhalf}$ using
a nonlinear combination of approximations to the second derivative.
First, define:
\begin{eqnarray}
(D^2s)_{i+\myhalf} &=& 3\left(s_{i}-2s_{i+\myhalf}+s_{i+1}\right) \\
(D^2s)_{i+\myhalf,L} &=& s_{i-1}-2s_{i}+s_{i+1} \\
(D^2s)_{i+\myhalf,R} &=& s_{i}-2s_{i+1}+s_{i+2}
\end{eqnarray}
Then, define
\begin{equation}
s = \text{sign}\left[(D^2s)_{i+\myhalf}\right],
\end{equation}
\begin{equation}
(D^2s)_{i+\myhalf,\text{lim}} = s\max\left\{\min\left[Cs(D^2s)_{i+\myhalf,L},Cs(D^2s)_{i+\myhalf,R},s(D^2s)_{i+\myhalf}\right],0\right\},
\end{equation}
where $C=1.25$ was used in Colella and Sekora.  Then,
\begin{equation}
s_{i+\myhalf} = \frac{1}{2}\left(s_{i}+s_{i+1}\right) - \frac{1}{6}(D^2s)_{i+\myhalf,\text{lim}}.
\end{equation}
Now we implement Phil's new version of the algorithm to eliminate sensitivity to roundoff.
First we need to detect whether a particular cell corresponds to an ``extremum''.  There
are two tests.  For the first test, define
\begin{equation}
\alpha_{i,\pm} = s_{i\pm\myhalf} - s_i.
\end{equation}
If $\alpha_{i,+}\alpha_{i,-} \ge 0$, then we are at an extremum.  We apply the second
test if either $|\alpha_{i,\pm}| > 2|\alpha_{i,\mp}|$.  Then, we define:
\begin{eqnarray}
(Ds)_{i,{\rm face},-} &=& s_{i-\myhalf} - s_{i-\sfrac{3}{2}} \\
(Ds)_{i,{\rm face},+} &=& s_{i+\sfrac{3}{2}} - s_{i+\myhalf}
\end{eqnarray}
\begin{equation}
(Ds)_{i,{\rm face,min}} = \min\left[\left|(Ds)_{i,{\rm face},-}\right|,\left|(Ds)_{i,{\rm face},+}\right|\right].
\end{equation}
\begin{eqnarray}
(Ds)_{i,{\rm cc},-} &=& s_{i} - s_{i-1} \\
(Ds)_{i,{\rm cc},+} &=& s_{i+1} - s_{i}
\end{eqnarray}
\begin{equation}
(Ds)_{i,{\rm cc,min}} = \min\left[\left|(Ds)_{i,{\rm cc},-}\right|,\left|(Ds)_{i,{\rm cc},+}\right|\right].
\end{equation}
If $(Ds)_{i,{\rm face,min}} \ge (Ds)_{i,{\rm cc,min}}$, set
$(Ds)_{i,\pm} = (Ds)_{i,{\rm face},\pm}$.  Otherwise, set
$(Ds)_{i,\pm} = (Ds)_{i,{\rm cc},\pm}$.  Finally, we are at an extreumum if
$(Ds)_{i,+}(Ds)_{i,-} \le 0$.\\ \\

Now that we have finished the extremum tests, if we are at an extremum,
we scale $\alpha_{i,\pm}$.  First, we define
\begin{eqnarray}
(D^2s)_{i} &=& 6(\alpha_{i,+}+\alpha_{i,-}) \\
(D^2s)_{i,L} &=& s_{i-2}-2s_{i-1}+s_{i} \\
(D^2s)_{i,R} &=& s_{i}-2s_{i+1}+s_{i+2} \\
(D^2s)_{i,C} &=& s_{i-1}-2s_{i}+s_{i+1}
\end{eqnarray}
Then, define
\begin{equation}
s = \text{sign}\left[(D^2s)_{i}\right],
\end{equation}
\begin{equation}
(D^2s)_{i,\text{lim}} = \max\left\{\min\left[s(D^2s)_{i},Cs(D^2s)_{i,L},Cs(D^2s)_{i,R},Cs(D^2s)_{i,C}\right],0\right\}.
\end{equation}
Then,
\begin{equation}
\alpha_{i,\pm} = \frac{\alpha_{i,\pm}(D^2s)_{i,\text{lim}}}{\max\left[\left|(D^2s)_{i}\right|,1\times 10^{-10}\right]}
\end{equation}
Otherwise, if we are not at an extremum and $|\alpha_{i,\pm}| > 2|\alpha_{i,\mp}|$,
then define
\begin{equation}
s = \text{sign}(\alpha_{i,\mp})
\end{equation}
\begin{equation}
\delta\mathcal{I}_{\text{ext}} = \frac{-\alpha_{i,\pm}^2}{4\left(\alpha_{j,+}+\alpha_{j,-}\right)},
\end{equation}
\begin{equation}
\delta s = s_{i\mp 1} - s_i,
\end{equation}
If $s\delta\mathcal{I}_{\text{ext}} \ge s\delta s$, then we perform the following test.
If $s\delta s - \alpha_{i,\mp} \ge 1\times 10^{-10}$, then
\begin{equation}
\alpha_{i,\pm} =  -2\delta s - 2s\left[(\delta s)^2 - \delta s \alpha_{i,\mp}\right]^{\myhalf}
\end{equation}
otherwise,
\begin{equation}
\alpha_{i,\pm} =  -2\alpha_{i,\mp}
\end{equation}
Finally, $s_{i,\pm} = s_i + \alpha_{i,\pm}$.


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

\section*{Fri Nov 29 2019}

Yesterday we talked about Kruskal diagrams and coordinates.

There is a 1-to-1 map between \(U^2 - V^2\) and \(R = r/2GM\):
%
\begin{align}
  U^2 - V^2 = \qty(R-1) \exp(R)
\,,
\end{align}
%
and if we fix \(V = V_0 \), we can vary \(U, \theta \): each point in the manifold parametrized by \(U, \theta \) is a circle of radius \(r(U^2-V^2) \sin \theta \), parametrized by the coordinate we left out, \(\varphi \).

What if we vary \(V_0 \)? there opens up a ``breach'', but it is only ever spacelike: no timelike curves can cross it.

White holes would have existed ``before'', but they appear as solutions to a stationary problem: real black holes form from the collapse of a star, there is a time after which the BH exists and before which it does not.

There is some more material at the end of the lecture notes on geodesics.

An observer in geodesic motion feels no acceleration: \(a^{\mu } = 0\).

What is the acceleration felt by an observer, \(a^{i}\), moving with \(4\)-acceleration \(a^{\mu }\) in general (non-geodesic) motion?

A noncontroversial fact is \(-1 = \const\): this directly implies \(u^{\mu } a_{\mu } = 0\), since the metric is covariantly constant and \(u^{\mu } u_{\mu } = 0\).

The acceleration felt by \(A\) is his acceleration measured in a LIF defined as having the same \(4\)-velocity as \(A\). There,
%
\begin{align}
  a^{\mu } = u^{\nu } \nabla_{\nu } u^{\mu } = \dv{ u^{\mu }}{\tau } + \cancelto{}{\Gamma^{\mu }_{\alpha \beta } u^{\alpha } u^{\beta }}
\,,
\end{align}
%
but \(t = \tau \), and the 4-velocity in the LIF is \(u^{\mu } = (1, 0,0,0)\): this implies that
%
\begin{align}
  a^{ \mu } = \dv{ u^{\mu }}{t} = \left[\begin{array}{cc}
  0 & a^{i}
  \end{array}\right]^{\top}
\,,
\end{align}
%
and the invariant quantity \(a^{\mu } a_{\mu } = \abs{\vec{a}}^{2}\) is the modulus of the 3-acceleration felt.
Then, we are able to compute the norm of \(a^{i}\) in any frame using \(\sqrt{a^{\mu } a_{\mu }}\).

Let us see this in some examples.

The uniformly accelerating observer in Minkowski spacetime has a law of motion which looks like
%
\begin{align}
  x(t) = \frac{\sqrt{1 + \kappa^2 t^2   }}{\kappa }
\,,
\end{align}
%
and we showed that \(t = \sinh (\kappa \tau ) / \kappa \) and \(x = \cosh( \kappa \tau ) / \kappa \).

The three-velocity is
%
\begin{subequations}
\begin{align}
  u^{\mu } = \dv{x^{\mu }}{\tau } = \left[\begin{array}{c}
  \cosh(\kappa t) \\
  \sinh(\kappa t)
  \end{array}\right]
\,,
\end{align}
\end{subequations}
%
with the metric \(\eta_{\mu \nu } = \left[\begin{array}{cc}
-1 & 0 \\
0 & 1
\end{array}\right]\), so we find \(u^{ \mu } u_{\mu } = -1\); also
%
\begin{subequations}
\begin{align}
  a^{\mu } = \left[\begin{array}{c}
  \kappa \sinh(\kappa \tau ) \\
  \kappa \cosh(\kappa \tau )
  \end{array}\right]
\,,
\end{align}
\end{subequations}
%
which means \(a \cdot u = 0\).
Also, we compute \(a \cdot a = \kappa^2\).

We also consider an observer at rest in the Schwarzschild geometry: \(x^{\mu } = (t, r_0 , \theta_0 , \varphi_0 )\). The 4-velocity is \(u^{\mu } = \qty(1/\sqrt{-g_{00} }, 0, 0, 0)\).

The 4-acceleration is given by
%
\begin{align}
  a^{\mu } = u^{\nu } \qty( \partial_{\nu } u^{\mu } + \Gamma^{\mu }_{\nu \beta } u^{\nu } u^{\beta })
  = \Gamma^{\mu }_{tt} \qty(u^{0})^2
\,,
\end{align}
%
and also \(\Gamma^{\mu }_{tt} = 0\) for any \(\mu \neq r\), while
%
\begin{align}
    \Gamma^{r}_{tt} =  \frac{1}{2} \qty(1 - \frac{2GM}{r}   ) (-1) \pdv{}{r} \qty(-1 + \frac{2GM}{r})
    = \frac{1}{2} \qty(1 - \frac{2GM}{r}) \frac{2GM}{r^2}
\,.
\end{align}

So,
%
\begin{align}
  a^{r} = \qty(1 - \frac{2GM}{r}) \frac{GM}{r^2} \qty(1 - \frac{2GM}{r})^{-1} = \frac{GM}{r^2}
\,.
\end{align}

We have recovered the 4-acceleration felt by an observer: its modulus is
%
\begin{align}
  \abs{\vec{a}} = \sqrt{g_{rr} a^{r} a^{r}} = \frac{GM}{r^2} \qty(1 - \frac{2GM}{r})^{-1/2} \overset{r \gg 2GM}{\rightarrow} \frac{GM}{r^2}
\,,
\end{align}
%
while if we are at \(r = 2GM + \epsilon \), the acceleration looks like
%
\begin{align}
  \abs{\vec{a}} \sim \frac{1}{\sqrt{ \epsilon }}
\,.
\end{align}

\section{Rotation and the Kerr solution}

The object \(u^{\nu } \nabla_{\nu } u^{\mu  } = a^{\mu } \) describes only the variation of the velocity \emph{along} the four-momentum.

Let us consider a gyroscope: an object which has net angular momentum.

In the rest frame of the object, we introduce the spin four-vector \(s^{\mu } = (0, \vec{s})\).
In the rest frame \(s \cdot u = 0\), so this holds in any frame.

A free object in Minkowski spacetime in its own rest frame has a constant \(\vec{s}\): so \(\dv{s^{\mu }}{t} = 0\).
So in a LIF, for a moving object,
%
\begin{align}
  \dv{s^{\mu }}{\tau } = u^{\nu } \partial_{\nu } s^{\mu } = 0
\,,
\end{align}
%
so in a general frame
%
\begin{align}
  u^{\nu } \nabla_{\nu } s^{\mu } = 0
\,.
\end{align}

We can also do the following computation: \( u^{\nu } \nabla_{\nu } \qty(s \cdot s )= 2 s_{\mu } u^{\nu } \nabla_{\nu } s^{\mu } = 0\).

Also, the product of two different spins is conserved by the same reasoning.

Now we consider three specific examples: first, a gyroscope moving around a Schwarzschild mass.
This effect is called \emph{geodetic precession}.
The other effect we will treat is a gyroscope in a slowly rotating geometry: we will use the gyroscope as a probe for the rotating geometry.
This effect is called \emph{frame dragging} or \emph{Lense Thirring precession}.
Then, we will discuss a generic rotating black hole: the \emph{Kerr} metric.

\subsection{Geodesic precession}

We consider a slice of Schwarzschild geometry: we will have \(r , \varphi \) coordinates for space and \(t\) coordinate for time, while \(\theta = \pi / 2\).

We will consider an observer moving along a geodesic orbit.

The 4-velocity is given by
%
\begin{align}
  u^{\mu } = \dv{t}{\tau } \qty(1, 0, 0, \dv{\varphi }{t})
\,,
\end{align}
%
and if we have the temporal and azimuthal Killing vectors we have previously shown (equation \eqref{eq:omega-geodesic}) that for geodesic motion the following holds:
%
\begin{align}
  \dv{\varphi }{t} = \Omega = \sqrt{\frac{GM}{r^3}}
\,,
\end{align}
%
so we can write
%
\begin{align}
-1 = u^{\mu } u_{\mu }  =  - \qty(u^{t})^2 \qty(g_{00} - r^2\Omega^2)
 = - \qty(u^{t})^2 \qty(1 - \frac{2GM}{r} - \frac{GM}{r})
\,,
\end{align}
%
so we have
%
\begin{align}
  u^{t} = \frac{1}{\sqrt{1 - \frac{3GM}{r}}}
\,.
\end{align}
%

Initially we have a vector \(s^{\mu } = \qty(s^{t}, s^{r }, s^{\theta }, s^{\varphi })\). \(s^{\theta }\) starts out zero in our coordinates, and it remains so by symmetry.

We know that \(0= g_{\mu \nu } s^{\mu } u^{\nu }\), but the metric is diagonal so this is
%
\begin{align}
  0= g_{00} s^{t} u^{t} + g_{33 } s^{\varphi } u^{\varphi }
\,,
\end{align}
%
which is
%
\begin{align}
  0= u^{t} \qty(-\qty(1 - \frac{2GM}{r} ) s^{t} + r^2 s^{\varphi } \Omega )
\,,
\end{align}
%
so
%
\begin{align}
  s^{t} = \qty(1 - \frac{2GM}{r})^{-1} r^2 \Omega s^{\varphi }
\,.
\end{align}

Consistently with our assumptions, as \(r \rightarrow \infty \) we have \(s^{t} \rightarrow 0\).

The evolution of the spin is described by
%
\begin{align}
  \dv{s^{\alpha }}{\tau } + \Gamma^{\alpha }_{\beta \gamma } u^{\beta } s^{\gamma } =0
\,.
\end{align}

One can start by \(\alpha = r\): then we must look at the symbols \(\Gamma^{r}_{\beta \gamma }\): potentially, by the nonzero components of \(u\) and \(s\), we should compute the symbols with \(\beta = 0, 3 \) and \(\gamma = 0, 1, 3\).

Since the metric is diagonal, the Christoffel symbols with three different indices are automatically zero.
Also, if two components are the same and one is different the different one has to be the one with respect to which one computes the derivatives.

So our equation is
%
\begin{align}
  \dv{s^{1}}{\tau } + \Gamma^{1}_{00} u^{0} s^{0}
  + \Gamma^{1}_{33} u^{3} s^{3} = 0
\,,
\end{align}
%
and the relavant Christoffel symbols are:
%
\begin{align}
  \Gamma^{1}_{00} = \qty(1 - \frac{2GM}{r}) \frac{GM}{r^2}
\,
\end{align}
%
and
%
\begin{align}
  \Gamma^{1}_{33} = - \qty(1 - \frac{2GM}{r})r
\,.
\end{align}

We find that the equation is
%
\begin{align}
  \dv{s^{1}}{\tau } + \Gamma^{1}_{00} \dv{t}{\tau } s^{t}
  + \Gamma^{1}_{33} \dv{t}{\tau } \Omega s^{\varphi } = 0
\,,
\end{align}
%
which becomes, changing variable in the derivative from \(\tau \) to \(t\) everywhere:
%
\begin{align}
\dv{s^{1}}{t} + \Gamma^{1}_{00}  s^{t}
+ \Gamma^{1}_{33}  \Omega s^{\varphi } = 0
  \,,
\end{align}
%
which means
%
\begin{align}
  \dv{s^{r}}{t} + \qty(3GM - r)\Omega s^{\varphi }= 0
\,.
\end{align}

\end{document}


\documentclass{beamer}
\usefonttheme[onlymath]{serif}
\usepackage[english]{babel}							%For internationalization
\usepackage[utf8]{inputenc}							%For character encoding
\usepackage{amsmath}								%For mathematical typesetting
\usepackage{amssymb}								%For mathematical typesetting
\usepackage{graphicx}								%For handling graphics

\newcommand{\be}{\begin{equation}}
\newcommand{\ben}[1]{\begin{equation}\label{#1}}
\newcommand{\ee}{\end{equation}}

\title
{An Introduction to Discontinuous Galerkin Methods}
\subtitle{Module 1: What is DG?}
\author[Bevan] % (optional, for multiple authors)
{J.~Bevan}
\institute[UMass Lowell] % (optional)
{
  Department of Mechanical Engineering, Grad Student\\
  University of Massachusetts at Lowell
}
\date[Fall 2014] % (optional)
{}
\subject{Discontinuous Galerkin}

\begin{document}
\frame{\titlepage}
\frame{\frametitle{Module 1: What is DG?}\tableofcontents}
%NEW SECTION
\section{Overall Content Structure}
\subsection{Assumed Prerequisite Knowledge}
\frame{\frametitle{\textbf{\secname}: \subsecname}
\begin{itemize}
\item It is assumed the interested viewer is an advanced undergrad or graduate student with the typical STEM background of Calculus, Linear Algebra, and ODEs/PDEs.
\item Additionally, it is assumed the viewer has at least a basic background in a programming language of their choice (Matlab etc.)
\item Finally it is assumed the viewer has taken a general Numerical Methods course as well a Solution of PDEs course.
\item Not intended to teach common underlying techniques (interpolation etc.), but we may [Recall] important features of them.
\end{itemize}
}

\subsection{Numerical Methods Prerequisites}
\frame[shrink]{\frametitle{\subsecname}
\begin{itemize}
\item Linear algebra
	\begin{itemize}
	\item Vector spaces, bases, properties, etc.
	\item Orthogonality
	\item maybe some useful spaces (Hilbert, square integrable, etc)?
	\end{itemize}
\item Polynomial interpolation(1 and 2D)
	\begin{itemize}
	\item Lagrange, Hermite
	\item monomial basis (and ill-conditioned nature)
	\item Orthogonal basis (Legendre, Chebyshev)
	\item L2 projection
	\item choice of interpolation points (equispaced, GL, LGL, etc)
	\item Runge phenomenon
	\item Vandermonde matrix (transformation from modal to nodal spaces)
	\end{itemize}
\item Quadrature (1 and 2D)
	\begin{itemize}
		\item Newton-Cotes
	\item Gauss/Hermite(Legendre)
	\item relation to interpolation

	\end{itemize}
\item Solution of ODEs
	\begin{itemize}
	\item Forward Euler
	\item RK4
	\item Implicit schemes (e.g. Backward Euler)
	\item Stability, Convergence
	\end{itemize}
\end{itemize}
}

\subsection{Solution of PDEs Prerequisites}
\frame[shrink]{\frametitle{\subsecname}
\begin{itemize}
\item Domain representation
	\begin{itemize}
	\item meshing
	\item BCs (Neumann and Dirichlet)
	\end{itemize}
\item Finite difference methods (FDM)
	\begin{itemize}
	\item Pointwise spatial derivatives
	\item Computational vs Physical domains
	\item Basic mapping (bilinear)
	\end{itemize}
\item Finite volume methods (FVM)
	\begin{itemize}
	\item Flux functions
	\item Artificial viscosity
	\item Linear vs nonlinear fluxes
	\end{itemize}
\item Finite element methods (FEM)
	\begin{itemize}
	\item Weak and strong form formulation
	\item Piecewise linear solution approximation
	\item Galerkin style test functions
	\item local support
	\end{itemize}
\end{itemize}
}

\subsection{Lecture Goals}
\frame[shrink]{\frametitle{\subsecname}
\begin{itemize}
\item Understand DG spatial discretization (advective)
\begin{itemize}
\item DG weak form (test function to minimize residual or test function orthogonal)
\item solution approximation (and initial conditions)
\item mapping physical to computation domain (for curvilinear domains)
\item DG Galerkin formulation
\item Integration by parts $\rightarrow$ flux functions (solution smoothness requirements): differences from FEM
\item linear vs non-linear flux: ramifications for semi-discrete system
\item hyperbolic vs parabolic
\item applying BCs (include periodic BCs)
\end{itemize}
\item  Understand time discretization
\begin{itemize}
\item Method of lines style semi-discrete form
\item Types: e.g. Forward Euler, RK4
\item CFL condition and stability
\end{itemize}
\item Learn how to apply DG to arbitrary PDEs and realm of applicability
\begin{itemize}
\item intuitive understanding of methodology
\item conceptualization of process (not tied down to specific examples)
\item understand pros/cons
\item understand how DG “simplifies” to FVM and FEM
\end{itemize}
\item Generate runnable code of your own
\begin{itemize}
\item Self-contained set of knowledge and algorithms to be able to write a full solver
\end{itemize}
\end{itemize}
}

\subsection{Topics Layout}
\frame{\frametitle{\subsecname}
\textbf{Module 1: What is DG?}\\
DG motivation (why vs FEM, FVM, FDM)\\
Scalar conservation law (linear) PDE\\
Weak form derivation\\
Global domain vs local element\\
Multiple-valued element boundaries\\
Recall: Flux functions\\
}

\frame{\frametitle{\subsecname (cont.)}
\textbf{Module 2: A Simple 1D DG Solver}\\
Linear solution approximation\\
Test function choice (Galerkin)\\
Upwind flux\\
Mass Matrix\\
Stiffness Matrix\\
Putting it all together (linear system)\\
Semi-discrete system\\
Forward Euler\\
Investigate h-convergence\\
Investigate t-convergence\\
Investigate stability (CFL)\\
}

\frame{\frametitle{\subsecname (cont.)}
\textbf{Module 3: To Higher-Orders (nodal) }\\
\textbf{3A: Sol’n Approximation}\\
Revisit weak form\\
-Approx. space\\
-L2 Projection minimizes residual norm\\
-Test space $\rightarrow$ orthogonal\\
Monomial basis?\\
Ill-conditioning of monomials\\
Recall: Lagrange interpolation (code)\\
Derive Lagrange spatial approximation\\
Equispaced interp points?\\
Runge phenomenon\\
Why: Bernstein/Markov inequality\\
Roots of Leg instead\\
}

\frame{\frametitle{\subsecname (cont.)}
\textbf{Module 3: To Higher-Orders (nodal) }\\
\textbf{3B: Discrete System}\\
Numerical Quadrature (Gauss)\\
Hermite interpolation (2N+1 quad)\\
Truncation error/exact quadrature\\
GL Lagrange orthogonality\\
Local Mapping Fun\\
Mass Integral ->diagonal/inversion\\
Log differentiation\\
Flux interpolation\\
Stiffness Integral\\
Numerical Flux (interpolated)\\
Assembly of system\\
RK4 time discretization\\
Investigate p-convergence (smoothness reqs)\\
}

\subsection{A Pedagogical Comment}
\frame{\frametitle{\subsecname}
\begin{itemize}
\item Take advantage of format: replay, pause, speed up, slow down
\item Each section may have subsections, but the overall section is intended to be a self-contained concept. The first slide of a new section has the title format \textbf{Section}: Subsection
\item Easy to "zone-out", before the start of a new section try and put what you learned into action. Make a code snippet to test your understanding or verify a claimed result etc.
\item Each Module has a larger self-contained concept. You should be able to put together a script that accomplishes something substantial.
\end{itemize}
}

%NEW SECTION
\section{DG Motivation: Why DG?}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item Overall purpose: PDE models physical system, solve PDE numerically
\item Compare to common techniques FDM, FEM, FVM:
\item Increasing order of solution can be more efficient, smooth functions especially. Most comm. packages low order (LO)
\item FDM not explicitly conservative, extended stencil for high order (HO) a problem for unstructured grids
\item FEM not good for hyperbolic problems, discontinuities in sol'n troublesome
\item FVM constant solution of volume necessitates extended stencil for HO, ruins flexibility for unstructured grids
\item DG is explicitly conservative, well-suited for hyperbolic problems, able to handle discontinuities, and can still use unstructured grids at HO
\item Local nature of solution permits good parallelizability
\item Can use numerical flux functions to capture physical behavior
\end{itemize}
}

%NEW SECTION
\section{Example PDE: Scalar Conservation Law}
\subsection{A brief motivating example}
\frame[shrink]{\frametitle{\textbf{\secname}: \subsecname}
Imagine some scalar quantity that is subject to a conservation law
\begin{figure}
\centering
\includegraphics[width=.5\textwidth]{square.PNG}
\end{figure}
}
\subsection{General Approach}
\frame{\frametitle{\subsecname}
\begin{itemize}
\item As worked out, PDE for system in 1D is
\be \frac{\partial q}{\partial t} + \frac{\partial f(q)}{\partial x} = S(x) \ee
\item We will need to decide how we solve this system, and we will need to discretize in space and time
\item The first term will be discretized with a Forward Euler approach, the second term will be handled by DG
\item For simplicity we assume no sources, and a linear flux with an externally prescribed velocity field
\end{itemize}
}

%NEW SECTION
\section{The Weak Form of the PDE}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item We will discuss the finer points of this in Module 3, for now permit the following; the weak form solution of the PDE is the integral (over the global domain $\Omega$) of our solution times some test function $\phi$:
\be \int_{\Omega} \frac{\partial q}{\partial t} \phi \,dx + \int_{\Omega} \frac{\partial f(q)}{\partial x} \phi \,dx = 0 \ee
\item In DG the global domain is split into K elements, where the local sol'n is defined for a particular element. The global sol'n is then the direct sum of each of these local polynomials, a piecewise polynomial
\item This is similar to a FEM approach, however continuity is not enforced across elements
\end{itemize}
}

%NEW SECTION
\section{Domain Decomposition: Global vs Local}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item The integration domain is now over the element instead of the whole domain such that $\{x|x \in k, x_L \leq x \leq x_R\}$
\item To reduce smoothness requirements on the flux we integrate the second term by parts to get
\be \int_k\! \frac{\partial q}{\partial t} \,\phi \,dx +
	[f(q)\phi] \Big\rvert_{x_L}^{x_{R}} -
	\int_k\! f(q) \,\frac{d\phi}{dx} \,dx = 0 \ee
\item Notice that we include the endpoints of our domain $k$
\item Endpoints of neighboring elements are coincident, so $q$ is multiply defined, what ramifications does this have? Also, we now have K independent local solutions, how do we recover the global solution?
\end{itemize}
}

%NEW SECTION
\section{Element Boundaries: Multiply Defined?}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item If $q$ is multiply defined at endpoints, what should $f(q)$ be?
\item In order to ensure conservation flux between elements should be equal $-f_{k-1}(q(x_R)) = f_{k}(q(x_L))$
\item Take a FVM approach and permit a \textit{numerical flux} denoted $\hat{f}(q)$
\item The numerical flux function permits communication between elements, allowing recovery of global sol'n
\end{itemize}
}

%NEW SECTION
\section{[Recall] Flux Functions}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item Flux functions describe the "flow" of some quantity depending on the quantity itself and possibly other factors
\item Permits insertion of problem specific knowledge into an otherwise agnostic PDE
\item Many choices, Lax-Friedrichs, Richtmyer, Godunov, Osher, Roe, etc.
\item For simplicity we will use the upwind flux where $\hat{f}(q^+,q^-)=cq^-$ if $c>0$ and $cq^+$ if $c<0$
\end{itemize}
\begin{figure}
\centering
\includegraphics[width=.35\textwidth]{qBoundary.PNG}
\end{figure}

}

\end{document}


\section{Summary}

\begin{frame}{A Dank Meme}
    \begin{block}{Henri Poincaré}
        \emph{``[L]a mathématique est l'art de donner le même nom à des choses différentes,'' \cite{HP1908}.}
    \end{block}

\begin{figure}
\centering
\begin{minipage}{.5\textwidth}
  \centering
  \includegraphics[width=.5\linewidth]{resources/poincare.jpg}
  \captionof{figure}{H. Poincaré, 1887.}
  \label{fig:test1}
\end{minipage}%
\begin{minipage}{.5\textwidth}
  \centering
  \includegraphics[height=.6\linewidth]{resources/meme.jpg}
  \captionof{figure}{H. Poincaré, colourised.}
  \label{fig:test2}
\end{minipage}
\end{figure}

\end{frame}

\begin{frame}

The solution to the salmon conjecture is equivalent to \cite{BS2009}:
    \begin{itemize}
        \item the mixture of four models for three independent variables;
        \item the fourth secant variety of the Segre variety $\PP^{3} \times \PP^{3} \times \PP^{3}$;
        \item the set of $(4 \times 4 \times 4)$-tables of tensor rank $\leq 4$;
        \item the naive Bayes model with four classes and three features;
        \item the conditional independence model $[ X_{1} \indep X_{2} \indep X_{3} | Y ]$;
        \item the general Markov model for the phylogenetic tree, $K_{1,3}$;
        \item the superposition of four pure states in a quantum system, \cite{DBLH2001, HH2006}.
    \end{itemize}

\end{frame}

\begin{frame}

    \begin{block}{A `Statistics to Algebraic Geometry' Lexicon, \cite{BSLP2005}}

    \begin{table}[]
    \begin{tabular}{lll}
    Statistics                &   & Algebra/Geometry \\ \hline
                              &   &                  \\
    independence              & $\sim$ & Segre variety    \\
    exponential family        & $\sim$ & toric variety    \\
    (log-linear models)       &   &                  \\
    curved exponential family & $\sim$ & manifold         \\
    mixture model             & $\sim$ & secant variety   \\
    inference                 & $\sim$ & tropicalisation  \\
                              & $\vdots$ &
    \end{tabular}
    \end{table}

    \end{block}

\end{frame}

\begin{frame}{Applications}

We finish by mentioning that algebraic statistics thus has at least a few important \& interesting applications:

\begin{itemize}
    \item It can win you salmon;
    \item It can win you 100 Swiss francs\footnote{The \emph{$100$ Swiss Francs Conjecture} was on maximising the likelihood function over the space of $4 \times 4$ stochastic matrices, of $\rank \leq 2$ \cite{BS2009}, and was solved in \cite{MZGJSG20011}.} (CHF $100 \sim$ £$85$);
    \item One gets to learn lots of big words;
    \item It can provide one with a topic for an (excellent) colloquium talk;
    \item Algebraists \& statisticians may try to talk to one other (this may be a con rather than a pro).
\end{itemize}

\end{frame}


\documentclass[12pt]{article}

\usepackage{amsmath, graphicx}
\usepackage[margin=1in]{geometry}
\usepackage[font=footnotesize]{caption}

\begin{document}
\nocite{*}

\title{Progress Report - Super Mario Bros with Deep Reinforcement Learning}

\author{
  Matthew Chen
  \and
  Isabel Bush
}
\date{}
\maketitle

\section{Abstract}

For this project we are implementing various reinforcement learning algorithms to create learning agents to effectively play a variant of the classic Super Mario Bros game. The game is challenging from an AI standpoint as the environment is stochastic with randomly generated levels, and the state space is large. To address these challenges we will use Q-learning with various Q-function approximations ranging from simplistic feature extractors to deep learning implementations.

\section{Models}

\begin{figure}
\centering
\includegraphics[scale=0.5]{imgs/mario_grid}
\caption{A component of the game state is a small grid centered around Mario indicating objects nearby. In the actual simulation, the grid is 22 x 22 cells, where each cell is the size of a single block \cite{karakovskiy}.}
\label{mario_grid}
\end{figure}

We are running several variants of the Q learning algorithm with differing function approximations. All variants use an epsilon-greedy policy to choose an action at each state.

Our state is defined as a vector of all observed attributes of the game. This can be divided into two components. In the first component are meta data features which include distance to the finish, time left, and Mario state. These features describe the progression of the game. The second component is a 22 x 22 grid which is provided by the simulator at each time step, as shown in Figure \ref{mario_grid}. The grid can be thought of as a low detail/resolution view of the game. The entire grid is centered around Mario and each cell corresponds to objects in that relative position to Mario (blocks, mushrooms, monsters, gap, etc).

Actions correspond to combinations of the original buttons which could be pressed for the player to interact with the game. The game uses a set of six buttons which can be toggled on and off during a given time-step to make Mario move forward, jump, throw a fireball, etc. Since combinations of buttons are possible, we have defined our set of possible actions as all binary combinations of the six buttons leading to $2^6 = 64$ distinct actions.

The reward at each time-step is calculated as the change in fitness score over that time-step due to the action taken at the previous state. The fitness score takes into account distance passed and coins collected.

\subsection{Identity Function}

Our first learning agent maps the full state representation vector to the best action to take from that state. Since the state space is very large (the state vector has length $733$, which yields upwards of $2^{733}$ distinct states) and many states are unlikely to be seen (creating a sparse feature vector), we stored the state-action mapping in a hashmap to allow for quick access and efficient space usage.

While this is a simple model, it has a few shortcomings. First, since this simple Q learning model maps directly from states to actions, no generalization may be made to unseen states. The best action to take from each state must be learned independently, and the agent will choose a random action for any new state (even if very similar to a past state). This makes learning slow and inefficient. Second, an implementation shortcoming of this model is that the large feature vector consisting of all possible states can overflow memory. This limits the number of learning trials that may be run as the memory-usage grows with each new state.

\subsection{Linear Approximation}

To overcome the shortcomings of the identity function model, we implemented a linear approximation model. Rather than map directly from states to actions, this model defines a feature vector over the states and actions and calculates the optimal Q value at each time-step as the dot product of the current state/action feature vector and learned weights.

The feature vector consists of indicator values for each element of the state vector and every possible action. This yields a feature vector of length $stateVectorLength * possibleActions = 733 * 64 = 46,912$. While still large, this is much less than the identity feature vector and can easily fit in memory. And more importantly, this allows the agent to generalize to unseen states and learn more quickly.

\subsection{Neural Network}

We will try two neural network representations for approximating the Q function. In this representation we will use several fully-connected layers, with either logistic units or rectifier units. This network will take as input the state vector described above and output a Q score approximation.

Additionally, we will use playback memory as defined in \cite{mnih}. We will store the previous N observations from the game. We then sample from these observations during a single update to perform mini-batch gradient descent. This method should help mitigate the problem of correlated features from time windows and aid in the convergence of the weights.

\section{Initial Results}

\begin{figure}
\includegraphics[scale=0.5]{imgs/dist_bar.pdf}
\includegraphics[scale=0.5]{imgs/dist_line.pdf}
\caption{Learning statistics showing comparison between different agents by mean progress before end of game}
\label{agent_comp}
\end{figure}

We implemented initial versions of the Identity and Linear Approximation Agents, as well as a baseline random agent that chooses a random action at each step. Preliminary results show that both models are able to learn some of the game's goals and outperform the random agent by a large margin as shown in Figure \ref{agent_comp}.

The Identity Agent was able to run for about 200 trials before running out of memory (where each trial is a full game and consists of about 1000 time-steps). At the start of learning, Mario jumps around aimlessly performing random actions. By the end of the 200 trials, the agent has learned to move forward from some states and thus makes progress. However, since there is no generalization, the agent still performs random actions from some states and the game usually ends due to time-out.

The distance travelled over the trials for the agents can be seen in the Learning Convergence graph in Figure \ref{agent_comp}. While there is much variability, the trend is positive for the Identity Agent. Over the last 50 trials, the Identity Agent travelled an average distance of 710 with an average fitness score of 1,561. This is significantly better than the baseline random agent, which travels an average distance of 127 with an average fitness score of 257.

Due to generalization of state features, the Linear Agent learns much faster than the Identity Agent, as can be seen by the higher distance travelled even during the first few training epochs. The rate is faster despite a much lower learning rate (step-size), which was needed to keep the weights from diverging. The Linear Agent is able to progress farther on average than the Identity Agent (generalizing the desire to move forward to many different states) and thus usually completes the level or dies from a monster rather than hitting the timeout. The Linear Agent travels an average distance of 2,360 with an average fitness score of 5,140, far outperforming both the random agent and Identity Agent.

\section{Future Work}

The following are next steps in our project:

\begin{enumerate}
\item Implement Neural Network Agent
\item Record training statistics for all agents
\item Compare performance and run times of all agents
\item Benchmark our results against competition results
\end{enumerate}

\begin{thebibliography}{1}

\bibitem{karakovskiy} S. Karakovskiy, J. Togelius {\em The Mario AI Benchmark and Competitions} 2012.

\bibitem{mnih} V. Mnih, K. Kavukcuoglu, D. Silver, A. Graves, I. Antonoglou, D. Wierstra, M. Riedmiller {\em Playing Atari with Deep Reinforcement Learning} 2013.

\end{thebibliography}

\end{document}